Commit | Line | Data |
---|---|---|
ef195f0e | 1 | <?php |
a9229942 | 2 | |
ef195f0e AE |
3 | namespace wcf\system\version; |
4 | ||
5 | /** | |
6 | * Generic data holder for version tracker entries. | |
a9229942 TD |
7 | * |
8 | * @author Alexander Ebert | |
9 | * @copyright 2001-2019 WoltLab GmbH | |
10 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
11 | * @package WoltLabSuite\Core\System\Version | |
12 | * @since 3.1 | |
13 | * | |
14 | * @property-read int $versionID unique id of the tracked version entry | |
15 | * @property-read int $objectID id of the edited object | |
16 | * @property-read int|null $userID id of the user who has created the previous version of the object or `null` if the user does not exist anymore or if the previous version has been created by a guest | |
17 | * @property-read string $username name of the user who has created the previous version of the object | |
18 | * @property-read int $time timestamp at which the original version has been created | |
ef195f0e | 19 | */ |
a9229942 TD |
20 | class VersionTrackerEntry |
21 | { | |
22 | /** | |
23 | * object data | |
24 | * @var array | |
25 | */ | |
26 | protected $data = []; | |
27 | ||
28 | /** | |
29 | * list of stored properties and their values | |
30 | * @var array | |
31 | */ | |
32 | protected $payload = []; | |
33 | ||
34 | /** | |
35 | * VersionTrackerEntry constructor. | |
36 | * | |
37 | * @param int $id id | |
38 | * @param array $data version data | |
39 | */ | |
40 | public function __construct($id, array $data) | |
41 | { | |
42 | if ($id !== null) { | |
43 | throw new \InvalidArgumentException("Accessing tracked versions by id is not supported."); | |
44 | } | |
45 | ||
46 | if (isset($data['data'])) { | |
47 | $payload = (\is_array($data['data'])) ? $data['data'] : @\unserialize($data['data']); | |
48 | if ($payload !== false && \is_array($payload)) { | |
49 | $this->payload = $payload; | |
50 | } | |
51 | ||
52 | unset($data['data']); | |
53 | } | |
54 | ||
55 | $this->data = $data; | |
56 | } | |
57 | ||
58 | /** | |
59 | * Returns the value of a object data variable with the given name or `null` if no | |
60 | * such data variable exists. | |
61 | * | |
62 | * @param string $name | |
63 | * @return mixed | |
64 | */ | |
65 | public function __get($name) | |
66 | { | |
67 | if (isset($this->data[$name])) { | |
68 | return $this->data[$name]; | |
69 | } else { | |
70 | return; | |
71 | } | |
72 | } | |
73 | ||
74 | /** | |
75 | * Determines if the object data variable with the given name is set and | |
76 | * is not NULL. | |
77 | * | |
78 | * @param string $name | |
79 | * @return bool | |
80 | */ | |
81 | public function __isset($name) | |
82 | { | |
83 | return isset($this->data[$name]); | |
84 | } | |
85 | ||
86 | /** | |
87 | * Returns the stored value of a property or null if unknown. | |
88 | * | |
89 | * @param string $property property name | |
90 | * @param int $languageID language id | |
91 | * @return string | |
92 | */ | |
93 | public function getPayload($property, $languageID) | |
94 | { | |
95 | if (isset($this->payload[$languageID])) { | |
96 | return (isset($this->payload[$languageID][$property])) ? $this->payload[$languageID][$property] : ''; | |
97 | } | |
98 | ||
99 | return ''; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Returns the stored values for all given properties. Unknown or missing | |
104 | * properties will be set to an empty string. | |
105 | * | |
106 | * @param string[] $properties list of property names | |
107 | * @param int $languageID language id | |
108 | * @return string[] | |
109 | */ | |
110 | public function getPayloadForProperties(array $properties, $languageID) | |
111 | { | |
112 | $payload = []; | |
113 | foreach ($properties as $property) { | |
114 | $payload[$property] = ''; | |
115 | ||
116 | if (isset($this->payload[$languageID]) && isset($this->payload[$languageID][$property])) { | |
117 | $payload[$property] = $this->payload[$languageID][$property]; | |
118 | } | |
119 | } | |
120 | ||
121 | return $payload; | |
122 | } | |
123 | ||
124 | /** | |
125 | * Returns the list of language ids. | |
126 | * | |
127 | * @return int[] | |
128 | */ | |
129 | public function getLanguageIDs() | |
130 | { | |
131 | return \array_keys($this->payload); | |
132 | } | |
bb7bec6d | 133 | } |