12
12
use Xibo\Helper\ObjectVars;
13
use Xibo\Service\LogServiceInterface;
14
use Xibo\Storage\StorageServiceInterface;
13
use Xibo\Helper\Sanitize;
18
* used by all entities
19
* @package Xibo\Entity
23
17
private $hash = null;
24
18
private $loaded = false;
25
private $permissionsClass = null;
26
private $canChangeOwner = true;
19
private $deleting = false;
28
21
public $buttons = [];
29
private $jsonExclude = ['buttons', 'jsonExclude', 'originalValues'];
31
/** @var array Original values hydrated */
32
protected $originalValues = [];
35
* @var StorageServiceInterface
40
* @var LogServiceInterface
45
* Set common dependencies.
46
* @param StorageServiceInterface $store
47
* @param LogServiceInterface $log
50
protected function setCommonDependencies($store, $log)
52
$this->store = $store;
59
* @return StorageServiceInterface
61
protected function getStore()
68
* @return LogServiceInterface
70
protected function getLog()
22
private $jsonExclude = ['buttons', 'jsonExclude'];
76
25
* Hydrate an entity with properties
89
38
foreach ($properties as $prop => $val) {
90
39
if (property_exists($this, $prop)) {
92
if ((stripos(strrev($prop), 'dI') === 0 || in_array($prop, $intProperties)) && !in_array($prop, $stringProperties))
41
if (stripos(strrev($prop), 'dI') === 0 || in_array($prop, $intProperties))
93
42
$val = intval($val);
94
43
else if (in_array($prop, $stringProperties))
95
$val = filter_var($val, FILTER_SANITIZE_STRING);
44
$val = Sanitize::string($val);
96
45
else if (in_array($prop, $htmlStringProperties))
97
46
$val = htmlentities($val);
99
48
$this->{$prop} = $val;
100
$this->originalValues[$prop] = $val;
108
* Reset originals to current values
110
public function setOriginals()
112
foreach ($this->jsonSerialize() as $key => $value) {
113
$this->originalValues[$key] = $value;
118
* Get the original value of a property
119
* @param string $property
122
public function getOriginalValue($property)
124
return (isset($this->originalValues[$property])) ? $this->originalValues[$property] : null;
128
* Has the provided property been changed from its original value
129
* @param string $property
132
public function hasPropertyChanged($property)
134
if (!property_exists($this, $property))
137
return $this->getOriginalValue($property) != $this->{$property};
144
public function propertyOriginallyExisted($property)
146
return array_key_exists($property, $this->originalValues);
150
* Get all changed properties for this entity
152
public function getChangedProperties()
154
$changedProperties = [];
156
foreach ($this->jsonSerialize() as $key => $value) {
157
if (!is_array($value) && !is_object($value) && $this->propertyOriginallyExisted($key) && $this->hasPropertyChanged($key)) {
158
$changedProperties[$key] = $this->getOriginalValue($key) . ' > ' . $value;
162
return $changedProperties;
207
88
$this->jsonExclude = array_diff($this->jsonExclude, [$property]);
211
* Get the Permissions Class
214
public function permissionsClass()
216
return ($this->permissionsClass == null) ? get_class($this) : $this->permissionsClass;
220
* Set the Permissions Class
221
* @param string $class
223
protected function setPermissionsClass($class)
225
$this->permissionsClass = $class;
229
* Can the owner change?
232
public function canChangeOwner()
234
return $this->canChangeOwner && method_exists($this, 'setOwner');
238
* @param bool $bool Can the owner be changed?
240
protected function setCanChangeOwner($bool)
242
$this->canChangeOwner = $bool;
248
* @param array[Optional] $changedProperties
250
protected function audit($entityId, $message, $changedProperties = null)
252
if ($changedProperties === null) {
253
// No properties provided, so we should work them out
254
// If we have originals, then get changed, otherwise get the current object state
255
$changedProperties = (count($this->originalValues) <= 0) ? $this->toArray() : $this->getChangedProperties();
258
$class = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
260
if (count($changedProperties) > 0)
261
$this->getLog()->audit($class, $entityId, $message, $changedProperties);
b'\\ No newline at end of file'