1 |
bareface |
1.1 |
<?php |
2 |
|
|
/* |
3 |
|
|
|
4 |
|
|
YakkaPage |
5 |
|
|
|
6 |
|
|
Class representing a page of yakka. |
7 |
|
|
|
8 |
|
|
TODO: DESCRIPTION |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
require_once("YakkaSerialize.php"); |
12 |
|
|
require_once("YakkaPermitableObject.php"); |
13 |
|
|
require_once("YakkaUser.php"); |
14 |
|
|
require_once("YakkaXml.php"); |
15 |
|
|
|
16 |
|
|
class YakkaPage extends YakkaPermitableObject { |
17 |
|
|
var $pageStorage; |
18 |
|
|
|
19 |
|
|
var $exists; |
20 |
|
|
|
21 |
|
|
var $id; |
22 |
|
|
var $name; |
23 |
|
|
var $source; |
24 |
|
|
var $comment; |
25 |
|
|
|
26 |
|
|
var $version; |
27 |
|
|
var $isLatest; |
28 |
|
|
|
29 |
|
|
var $createUserId; |
30 |
|
|
var $createUser; |
31 |
|
|
|
32 |
|
|
var $modifyUserId; |
33 |
|
|
var $modifyUser; |
34 |
|
|
|
35 |
|
|
var $createTimestamp; |
36 |
|
|
var $modifyTimestamp; |
37 |
|
|
|
38 |
|
|
function YakkaPage($id = null, $version = null) { |
39 |
|
|
$$singleton = YAKKA_GLOBAL_SINGLETON; |
40 |
|
|
global $singleton; |
41 |
|
|
$this->pageStorage = &$singleton->pageStorage; |
42 |
|
|
|
43 |
|
|
if ($id) |
44 |
|
|
$this->exists = $this->load($id, $version); |
45 |
|
|
else |
46 |
|
|
$this->exists = false; |
47 |
|
|
|
48 |
|
|
$this->YakkaPermitableObject($id); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
function load($id, $version = null) { |
52 |
|
|
if ($data = $this->pageStorage->loadPage($id, $version)) { |
53 |
|
|
$this->id = $data["id"]; |
54 |
|
|
$this->name = $data["name"]; |
55 |
|
|
$this->source = $data["source"]; |
56 |
|
|
$this->version = $data["version"]; |
57 |
|
|
$this->isLatest = $data["islatest"]; |
58 |
|
|
|
59 |
|
|
$this->createUser = new YakkaUser(); |
60 |
|
|
if ($this->createUserId = $data["createuserid"]) |
61 |
|
|
$this->createUser->load($this->createUserId); |
62 |
|
|
|
63 |
|
|
$this->modifyUser = new YakkaUser(); |
64 |
|
|
if ($this->modifyUserId = $data["modifyuserid"]) |
65 |
|
|
$this->modifyUser->load($this->modifyUserId); |
66 |
|
|
|
67 |
|
|
$this->createTimestamp = $data["createtimestamp"]; |
68 |
|
|
$this->modifyTimestamp = $data["modifytimestamp"]; |
69 |
|
|
$this->exists = true; |
70 |
|
|
} else { |
71 |
|
|
$this->id = $this->name = $id; |
72 |
|
|
$this->exists = false; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
return $this->exists; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
function save() { |
79 |
|
|
/* check if page is being created now, if so, modifier is creator */ |
80 |
|
|
if (!$this->createUser && $this->modifyUser) { |
81 |
|
|
$this->createUser = &$this->modifyUser; |
82 |
|
|
$this->createTimestamp = $this->modifyTimestamp = time(); |
83 |
|
|
} else |
84 |
|
|
$this->modifyTimestamp = time(); |
85 |
|
|
|
86 |
|
|
/* save page */ |
87 |
|
|
return $this->pageStorage->savePage( |
88 |
|
|
$this->id, |
89 |
|
|
$this->name, |
90 |
|
|
$this->source, |
91 |
|
|
$this->version, |
92 |
|
|
$this->comment, |
93 |
|
|
($this->createUser ? $this->createUser->getId() : null), |
94 |
|
|
($this->modifyUser ? $this->modifyUser->getId() : null), |
95 |
|
|
$this->createTimestamp, |
96 |
|
|
$this->modifyTimestamp |
97 |
|
|
); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
function isExisting() { |
101 |
|
|
return $this->exists; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
function isLatestVersion() { |
105 |
|
|
return $this->isLatest; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
function getName() { |
109 |
|
|
return $this->name; |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
function setName($name) { |
113 |
|
|
$this->name = $name; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
function getSource() { |
117 |
|
|
return $this->source; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
function setSource($source) { |
121 |
|
|
$this->source = $source; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
function getVersion() { |
125 |
|
|
return $this->revision; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
function setVersion($version) { |
129 |
|
|
$this->version = $version; |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
function &getCreateUser() { |
133 |
|
|
return $this->createUser; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
function setCreateUser(&$user) { |
137 |
|
|
$this->createUser = &$user; |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
function &getModifyUser() { |
141 |
|
|
return $this->modifyUser; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
function setModifyUser(&$user) { |
145 |
|
|
$this->modifyUser = &$user; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
function toXml() { |
149 |
|
|
$xml = "<page id='$this->id' name='$this->name' islatest='".YakkaSerialize::boolToString($this->isLatest)."' createdate='".date("Y-m-d H:i:s", $this->createTimestamp)."' modifydate='".date("Y-m-d H:i:s", $this->modifyTimestamp)."'"; |
150 |
|
|
if ($this->createUser) |
151 |
|
|
$xml .= " create-user-id='".$this->createUser->getId()."'"; |
152 |
|
|
if ($this->modifyUser) |
153 |
|
|
$xml .= " modify-user-id='".$this->modifyUser->getId()."'"; |
154 |
|
|
$xml .= ">"; |
155 |
|
|
$xml .= "<users>"; |
156 |
|
|
if ($this->createUser) |
157 |
|
|
$xml .= $this->createUser->toXml(); |
158 |
|
|
if ($this->modifyUser && ($this->createUser->getId() != $this->modifyUser->getId())) |
159 |
|
|
$xml .=$this->modifyUser->toXml(); |
160 |
|
|
$xml .= "</users>"; |
161 |
|
|
|
162 |
|
|
/* |
163 |
|
|
<permissions> |
164 |
|
|
<permission type='read'> |
165 |
|
|
<allow/> |
166 |
|
|
<deny role='#roleid#'/> |
167 |
|
|
</permission> |
168 |
|
|
<permission type='write'> |
169 |
|
|
<allow role='#roleid#'/> |
170 |
|
|
<allow user='#userid#'/> |
171 |
|
|
<deny/> |
172 |
|
|
</permission> |
173 |
|
|
<permission type='delete'> |
174 |
|
|
<deny/> |
175 |
|
|
</permission> |
176 |
|
|
</permissions> |
177 |
|
|
*/ |
178 |
|
|
|
179 |
|
|
$xml .= "<source><![CDATA[$this->source]]></source>"; |
180 |
|
|
$xml .= "<comment><![CDATA[$this->comment]]></comment>"; |
181 |
|
|
$xml .= "</page>"; |
182 |
|
|
|
183 |
|
|
return $xml; |
184 |
|
|
} |
185 |
|
|
} |
186 |
|
|
|
187 |
|
|
?> |