/[cvs]/bareface/yakka/library/YakkaPage.php
ViewVC logotype

Contents of /bareface/yakka/library/YakkaPage.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Jan 6 13:31:56 2003 UTC (21 years, 6 months ago) by bareface
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +22 -1 lines
added versioning methods;

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 increaseReleaseVersion() {
133 if (preg_match("/^(\d)?\..*/", $this->version, $matches)) {
134 $buildNumber = (int)$matches[1] + 1;
135 $this->version = $buildNumber.".0.0";
136 }
137 }
138
139 function increaseMajorVersion() {
140 if (preg_match("/^(.*)\.(\d)?\./", $this->version, $matches)) {
141 $buildNumber = (int)$matches[2] + 1;
142 $this->version = $matches[1].".".$buildNumber.".0";
143 }
144 }
145
146 function increaseMinorVersion() {
147 if (preg_match("/(.*)\.(\d)?$/", $this->version, $matches)) {
148 $buildNumber = (int)$matches[2] + 1;
149 $this->version = $matches[1].".".$buildNumber;
150 }
151 }
152
153 function &getCreateUser() {
154 return $this->createUser;
155 }
156
157 function setCreateUser(&$user) {
158 $this->createUser = &$user;
159 }
160
161 function &getModifyUser() {
162 return $this->modifyUser;
163 }
164
165 function setModifyUser(&$user) {
166 $this->modifyUser = &$user;
167 }
168
169 function toXml() {
170 $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)."' version='$this->version'";
171 if ($this->createUser)
172 $xml .= " create-user-id='".$this->createUser->getId()."'";
173 if ($this->modifyUser)
174 $xml .= " modify-user-id='".$this->modifyUser->getId()."'";
175 $xml .= ">";
176 $xml .= "<users>";
177 if ($this->createUser)
178 $xml .= $this->createUser->toXml();
179 if ($this->modifyUser && ($this->createUser->getId() != $this->modifyUser->getId()))
180 $xml .=$this->modifyUser->toXml();
181 $xml .= "</users>";
182
183 /*
184 <permissions>
185 <permission type='read'>
186 <allow/>
187 <deny role='#roleid#'/>
188 </permission>
189 <permission type='write'>
190 <allow role='#roleid#'/>
191 <allow user='#userid#'/>
192 <deny/>
193 </permission>
194 <permission type='delete'>
195 <deny/>
196 </permission>
197 </permissions>
198 */
199
200 $xml .= "<source><![CDATA[$this->source]]></source>";
201 $xml .= "<comment><![CDATA[$this->comment]]></comment>";
202 $xml .= "</page>";
203
204 return $xml;
205 }
206 }
207
208 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed