summaryrefslogtreecommitdiff
path: root/backend/php/src/objects/class.user.php
Unidiff
Diffstat (limited to 'backend/php/src/objects/class.user.php') (more/less context) (ignore whitespace changes)
-rw-r--r--backend/php/src/objects/class.user.php502
1 files changed, 502 insertions, 0 deletions
diff --git a/backend/php/src/objects/class.user.php b/backend/php/src/objects/class.user.php
new file mode 100644
index 0000000..f92c7ac
--- a/dev/null
+++ b/backend/php/src/objects/class.user.php
@@ -0,0 +1,502 @@
1<?php
2/*
3 This SQL query will create the table to store your object.
4
5 CREATE TABLE `user` (
6 `userid` int(11) NOT NULL auto_increment,
7 `username` VARCHAR(255) NOT NULL,
8 `srp_s` VARCHAR(255) NOT NULL,
9 `srp_v` VARCHAR(255) NOT NULL,
10 `header` LONGTEXT NOT NULL,
11 `statistics` LONGTEXT NOT NULL,
12 `auth_version` VARCHAR(255) NOT NULL,
13 `version` VARCHAR(255) NOT NULL,
14 `lock` VARCHAR(255) NOT NULL, PRIMARY KEY (`userid`)) ENGINE=MyISAM;
15*/
16
17/**
18* <b>user</b> class with integrated CRUD methods.
19* @author Php Object Generator
20* @version POG 3.0e / PHP5.1 MYSQL
21* @see http://www.phpobjectgenerator.com/plog/tutorials/45/pdo-mysql
22* @copyright Free for personal & commercial use. (Offered under the BSD license)
23* @link http://www.phpobjectgenerator.com/?language=php5.1&wrapper=pdo&pdoDriver=mysql&objectName=user&attributeList=array+%28%0A++0+%3D%3E+%27username%27%2C%0A++1+%3D%3E+%27srp_s%27%2C%0A++2+%3D%3E+%27srp_v%27%2C%0A++3+%3D%3E+%27header%27%2C%0A++4+%3D%3E+%27statistics%27%2C%0A++5+%3D%3E+%27auth_version%27%2C%0A++6+%3D%3E+%27version%27%2C%0A++7+%3D%3E+%27lock%27%2C%0A++8+%3D%3E+%27record%27%2C%0A++9+%3D%3E+%27onetimepassword%27%2C%0A%29&typeList=array%2B%2528%250A%2B%2B0%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B1%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B2%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B3%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B4%2B%253D%253E%2B%2527LONGTEXT%2527%252C%250A%2B%2B5%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B6%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B7%2B%253D%253E%2B%2527VARCHAR%2528255%2529%2527%252C%250A%2B%2B8%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2B%2B9%2B%253D%253E%2B%2527HASMANY%2527%252C%250A%2529
24*/
25include_once('class.pog_base.php');
26class user extends POG_Base
27{
28 public $userId = '';
29
30 /**
31 * @var VARCHAR(255)
32 */
33 public $username;
34
35 /**
36 * @var VARCHAR(255)
37 */
38 public $srp_s;
39
40 /**
41 * @var VARCHAR(255)
42 */
43 public $srp_v;
44
45 /**
46 * @var LONGTEXT
47 */
48 public $header;
49
50 /**
51 * @var LONGTEXT
52 */
53 public $statistics;
54
55 /**
56 * @var VARCHAR(255)
57 */
58 public $auth_version;
59
60 /**
61 * @var VARCHAR(255)
62 */
63 public $version;
64
65 /**
66 * @var VARCHAR(255)
67 */
68 public $lock;
69
70 /**
71 * @var private array of record objects
72 */
73 private $_recordList = array();
74
75 /**
76 * @var private array of onetimepassword objects
77 */
78 private $_onetimepasswordList = array();
79
80 public $pog_attribute_type = array(
81 "userId" => array('db_attributes' => array("NUMERIC", "INT")),
82 "username" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
83 "srp_s" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
84 "srp_v" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
85 "header" => array('db_attributes' => array("TEXT", "LONGTEXT")),
86 "statistics" => array('db_attributes' => array("TEXT", "LONGTEXT")),
87 "auth_version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
88 "version" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
89 "lock" => array('db_attributes' => array("TEXT", "VARCHAR", "255")),
90 "record" => array('db_attributes' => array("OBJECT", "HASMANY")),
91 "onetimepassword" => array('db_attributes' => array("OBJECT", "HASMANY")),
92 );
93 public $pog_query;
94
95
96 /**
97 * Getter for some private attributes
98 * @return mixed $attribute
99 */
100 public function __get($attribute)
101 {
102 if (isset($this->{"_".$attribute}))
103 {
104 return $this->{"_".$attribute};
105 }
106 else
107 {
108 return false;
109 }
110 }
111
112 function user($username='', $srp_s='', $srp_v='', $header='', $statistics='', $auth_version='', $version='', $lock='')
113 {
114 $this->username = $username;
115 $this->srp_s = $srp_s;
116 $this->srp_v = $srp_v;
117 $this->header = $header;
118 $this->statistics = $statistics;
119 $this->auth_version = $auth_version;
120 $this->version = $version;
121 $this->lock = $lock;
122 $this->_recordList = array();
123 $this->_onetimepasswordList = array();
124 }
125
126
127 /**
128 * Gets object from database
129 * @param integer $userId
130 * @return object $user
131 */
132 function Get($userId)
133 {
134 $connection = Database::Connect();
135 $this->pog_query = "select * from `user` where `userid`='".intval($userId)."' LIMIT 1";
136 $cursor = Database::Reader($this->pog_query, $connection);
137 while ($row = Database::Read($cursor))
138 {
139 $this->userId = $row['userid'];
140 $this->username = $this->Unescape($row['username']);
141 $this->srp_s = $this->Unescape($row['srp_s']);
142 $this->srp_v = $this->Unescape($row['srp_v']);
143 $this->header = $this->Unescape($row['header']);
144 $this->statistics = $this->Unescape($row['statistics']);
145 $this->auth_version = $this->Unescape($row['auth_version']);
146 $this->version = $this->Unescape($row['version']);
147 $this->lock = $this->Unescape($row['lock']);
148 }
149 return $this;
150 }
151
152
153 /**
154 * Returns a sorted array of objects that match given conditions
155 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
156 * @param string $sortBy
157 * @param boolean $ascending
158 * @param int limit
159 * @return array $userList
160 */
161 function GetList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
162 {
163 $connection = Database::Connect();
164 $sqlLimit = ($limit != '' ? "LIMIT $limit" : '');
165 $this->pog_query = "select * from `user` ";
166 $userList = Array();
167 if (sizeof($fcv_array) > 0)
168 {
169 $this->pog_query .= " where ";
170 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
171 {
172 if (sizeof($fcv_array[$i]) == 1)
173 {
174 $this->pog_query .= " ".$fcv_array[$i][0]." ";
175 continue;
176 }
177 else
178 {
179 if ($i > 0 && sizeof($fcv_array[$i-1]) != 1)
180 {
181 $this->pog_query .= " AND ";
182 }
183 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
184 {
185 if ($GLOBALS['configuration']['db_encoding'] == 1)
186 {
187 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? "BASE64_DECODE(".$fcv_array[$i][2].")" : "'".$fcv_array[$i][2]."'";
188 $this->pog_query .= "BASE64_DECODE(`".$fcv_array[$i][0]."`) ".$fcv_array[$i][1]." ".$value;
189 }
190 else
191 {
192 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$this->Escape($fcv_array[$i][2])."'";
193 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
194 }
195 }
196 else
197 {
198 $value = POG_Base::IsColumn($fcv_array[$i][2]) ? $fcv_array[$i][2] : "'".$fcv_array[$i][2]."'";
199 $this->pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." ".$value;
200 }
201 }
202 }
203 }
204 if ($sortBy != '')
205 {
206 if (isset($this->pog_attribute_type[$sortBy]['db_attributes']) && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$sortBy]['db_attributes'][0] != 'SET')
207 {
208 if ($GLOBALS['configuration']['db_encoding'] == 1)
209 {
210 $sortBy = "BASE64_DECODE($sortBy) ";
211 }
212 else
213 {
214 $sortBy = "$sortBy ";
215 }
216 }
217 else
218 {
219 $sortBy = "$sortBy ";
220 }
221 }
222 else
223 {
224 $sortBy = "userid";
225 }
226 $this->pog_query .= " order by ".$sortBy." ".($ascending ? "asc" : "desc")." $sqlLimit";
227 $thisObjectName = get_class($this);
228 $cursor = Database::Reader($this->pog_query, $connection);
229 while ($row = Database::Read($cursor))
230 {
231 $user = new $thisObjectName();
232 $user->userId = $row['userid'];
233 $user->username = $this->Unescape($row['username']);
234 $user->srp_s = $this->Unescape($row['srp_s']);
235 $user->srp_v = $this->Unescape($row['srp_v']);
236 $user->header = $this->Unescape($row['header']);
237 $user->statistics = $this->Unescape($row['statistics']);
238 $user->auth_version = $this->Unescape($row['auth_version']);
239 $user->version = $this->Unescape($row['version']);
240 $user->lock = $this->Unescape($row['lock']);
241 $userList[] = $user;
242 }
243 return $userList;
244 }
245
246
247 /**
248 * Saves the object to the database
249 * @return integer $userId
250 */
251 function Save($deep = true)
252 {
253 $connection = Database::Connect();
254 $this->pog_query = "select `userid` from `user` where `userid`='".$this->userId."' LIMIT 1";
255 $rows = Database::Query($this->pog_query, $connection);
256 if ($rows > 0)
257 {
258 $this->pog_query = "update `user` set
259 `username`='".$this->Escape($this->username)."',
260 `srp_s`='".$this->Escape($this->srp_s)."',
261 `srp_v`='".$this->Escape($this->srp_v)."',
262 `header`='".$this->Escape($this->header)."',
263 `statistics`='".$this->Escape($this->statistics)."',
264 `auth_version`='".$this->Escape($this->auth_version)."',
265 `version`='".$this->Escape($this->version)."',
266 `lock`='".$this->Escape($this->lock)."'where `userid`='".$this->userId."'";
267 }
268 else
269 {
270 $this->pog_query = "insert into `user` (`username`, `srp_s`, `srp_v`, `header`, `statistics`, `auth_version`, `version`, `lock`) values (
271 '".$this->Escape($this->username)."',
272 '".$this->Escape($this->srp_s)."',
273 '".$this->Escape($this->srp_v)."',
274 '".$this->Escape($this->header)."',
275 '".$this->Escape($this->statistics)."',
276 '".$this->Escape($this->auth_version)."',
277 '".$this->Escape($this->version)."',
278 '".$this->Escape($this->lock)."')";
279 }
280 $insertId = Database::InsertOrUpdate($this->pog_query, $connection);
281 if ($this->userId == "")
282 {
283 $this->userId = $insertId;
284 }
285 if ($deep)
286 {
287 foreach ($this->_recordList as $record)
288 {
289 $record->userId = $this->userId;
290 $record->Save($deep);
291 }
292 foreach ($this->_onetimepasswordList as $onetimepassword)
293 {
294 $onetimepassword->userId = $this->userId;
295 $onetimepassword->Save($deep);
296 }
297 }
298 return $this->userId;
299 }
300
301
302 /**
303 * Clones the object and saves it to the database
304 * @return integer $userId
305 */
306 function SaveNew($deep = false)
307 {
308 $this->userId = '';
309 return $this->Save($deep);
310 }
311
312
313 /**
314 * Deletes the object from the database
315 * @return boolean
316 */
317 function Delete($deep = false, $across = false)
318 {
319 if ($deep)
320 {
321 $recordList = $this->GetRecordList();
322 foreach ($recordList as $record)
323 {
324 $record->Delete($deep, $across);
325 }
326 $onetimepasswordList = $this->GetOnetimepasswordList();
327 foreach ($onetimepasswordList as $onetimepassword)
328 {
329 $onetimepassword->Delete($deep, $across);
330 }
331 }
332 $connection = Database::Connect();
333 $this->pog_query = "delete from `user` where `userid`='".$this->userId."'";
334 return Database::NonQuery($this->pog_query, $connection);
335 }
336
337
338 /**
339 * Deletes a list of objects that match given conditions
340 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
341 * @param bool $deep
342 * @return
343 */
344 function DeleteList($fcv_array, $deep = false, $across = false)
345 {
346 if (sizeof($fcv_array) > 0)
347 {
348 if ($deep || $across)
349 {
350 $objectList = $this->GetList($fcv_array);
351 foreach ($objectList as $object)
352 {
353 $object->Delete($deep, $across);
354 }
355 }
356 else
357 {
358 $connection = Database::Connect();
359 $pog_query = "delete from `user` where ";
360 for ($i=0, $c=sizeof($fcv_array); $i<$c; $i++)
361 {
362 if (sizeof($fcv_array[$i]) == 1)
363 {
364 $pog_query .= " ".$fcv_array[$i][0]." ";
365 continue;
366 }
367 else
368 {
369 if ($i > 0 && sizeof($fcv_array[$i-1]) !== 1)
370 {
371 $pog_query .= " AND ";
372 }
373 if (isset($this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes']) && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'NUMERIC' && $this->pog_attribute_type[$fcv_array[$i][0]]['db_attributes'][0] != 'SET')
374 {
375 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$this->Escape($fcv_array[$i][2])."'";
376 }
377 else
378 {
379 $pog_query .= "`".$fcv_array[$i][0]."` ".$fcv_array[$i][1]." '".$fcv_array[$i][2]."'";
380 }
381 }
382 }
383 return Database::NonQuery($pog_query, $connection);
384 }
385 }
386 }
387
388
389 /**
390 * Gets a list of record objects associated to this one
391 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
392 * @param string $sortBy
393 * @param boolean $ascending
394 * @param int limit
395 * @return array of record objects
396 */
397 function GetRecordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
398 {
399 $record = new record();
400 $fcv_array[] = array("userId", "=", $this->userId);
401 $dbObjects = $record->GetList($fcv_array, $sortBy, $ascending, $limit);
402 return $dbObjects;
403 }
404
405
406 /**
407 * Makes this the parent of all record objects in the record List array. Any existing record will become orphan(s)
408 * @return null
409 */
410 function SetRecordList(&$list)
411 {
412 $this->_recordList = array();
413 $existingRecordList = $this->GetRecordList();
414 foreach ($existingRecordList as $record)
415 {
416 $record->userId = '';
417 $record->Save(false);
418 }
419 $this->_recordList = $list;
420 }
421
422
423 /**
424 * Associates the record object to this one
425 * @return
426 */
427 function AddRecord(&$record)
428 {
429 $record->userId = $this->userId;
430 $found = false;
431 foreach($this->_recordList as $record2)
432 {
433 if ($record->recordId > 0 && $record->recordId == $record2->recordId)
434 {
435 $found = true;
436 break;
437 }
438 }
439 if (!$found)
440 {
441 $this->_recordList[] = $record;
442 }
443 }
444
445
446 /**
447 * Gets a list of onetimepassword objects associated to this one
448 * @param multidimensional array {("field", "comparator", "value"), ("field", "comparator", "value"), ...}
449 * @param string $sortBy
450 * @param boolean $ascending
451 * @param int limit
452 * @return array of onetimepassword objects
453 */
454 function GetOnetimepasswordList($fcv_array = array(), $sortBy='', $ascending=true, $limit='')
455 {
456 $onetimepassword = new onetimepassword();
457 $fcv_array[] = array("userId", "=", $this->userId);
458 $dbObjects = $onetimepassword->GetList($fcv_array, $sortBy, $ascending, $limit);
459 return $dbObjects;
460 }
461
462
463 /**
464 * Makes this the parent of all onetimepassword objects in the onetimepassword List array. Any existing onetimepassword will become orphan(s)
465 * @return null
466 */
467 function SetOnetimepasswordList(&$list)
468 {
469 $this->_onetimepasswordList = array();
470 $existingOnetimepasswordList = $this->GetOnetimepasswordList();
471 foreach ($existingOnetimepasswordList as $onetimepassword)
472 {
473 $onetimepassword->userId = '';
474 $onetimepassword->Save(false);
475 }
476 $this->_onetimepasswordList = $list;
477 }
478
479
480 /**
481 * Associates the onetimepassword object to this one
482 * @return
483 */
484 function AddOnetimepassword(&$onetimepassword)
485 {
486 $onetimepassword->userId = $this->userId;
487 $found = false;
488 foreach($this->_onetimepasswordList as $onetimepassword2)
489 {
490 if ($onetimepassword->onetimepasswordId > 0 && $onetimepassword->onetimepasswordId == $onetimepassword2->onetimepasswordId)
491 {
492 $found = true;
493 break;
494 }
495 }
496 if (!$found)
497 {
498 $this->_onetimepasswordList[] = $onetimepassword;
499 }
500 }
501}
502?> \ No newline at end of file