· 8 years ago · Jun 06, 2018, 06:26 PM
1<?php
2
3/**#@+
4 * @version 0.0.1
5 */
6
7/**
8 * @package POT
9 * @version 0.1.5
10 * @author Wrzasq <wrzasq@gmail.com>
11 * @copyright 2007 - 2008 (C) by Wrzasq
12 * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
13 */
14
15/**
16 * OTServ account abstraction.
17 *
18 * @package POT
19 * @version 0.1.5
20 * @property string $name Account name.
21 * @property string $password Password.
22 * @property string $eMail Email address.
23 * @property int $premiumEnd Timestamp of PACC end.
24 * @property bool $blocked Blocked flag state.
25 * @property bool $deleted Deleted flag state.
26 * @property bool $warned Warned flag state.
27 * @property bool $banned Ban state.
28 * @property-read int $id Account number.
29 * @property-read bool $loaded Loaded state.
30 * @property-read OTS_Players_List $playersList Characters of this account.
31 * @property-read int $access Access level.
32 * @tutorial POT/Accounts.pkg
33 */
34class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
35{
36/**
37 * Account data.
38 *
39 * @var array
40 * @version 0.1.5
41 */
42 private $data = array('email' => '', 'rkey' => '', 'blocked' => false, 'warned' => false, 'rlname' => '', 'location' => '', 'page_access' => 0, 'lastday' => 0, 'premdays' => 0, 'created' => 0);
43
44
45/**
46 * Creates new account.
47 *
48 * <p>
49 * Create new account in given range (1 - 9999999 by default).
50 * </p>
51 *
52 * <p>
53 * Note: If account name won't be speciffied random will be created.
54 * </p>
55 *
56 * <p>
57 * Note: Since 0.0.3 version this method doesn't require buffered queries.
58 * </p>
59 *
60 * <p>
61 * Note: Since 0.1.5 version you should use {@link OTS_Account::createNamed() createNamed() method} since OTServ now uses account names.
62 * </p>
63 *
64 * <p>
65 * Note: Since 0.1.1 version this method throws {@link E_OTS_Generic E_OTS_Generic} exceptions instead of general Exception class objects. Since all exception classes are child classes of Exception class so your old code will still handle all exceptions.
66 * </p>
67 *
68 * <p>
69 * Note: Since 0.1.5 version this method no longer creates account as blocked.
70 * </p>
71 *
72 * @version 0.1.5
73 * @param int $min Minimum number.
74 * @param int $max Maximum number.
75 * @param string $name Account name.
76 * @return int Created account number.
77 * @throws E_OTS_Generic When there are no free account numbers.
78 * @throws PDOException On PDO operation error.
79 * @deprecated 0.1.5 Use createNamed().
80 */
81 public function create($min = 1, $max = 999999)
82 {
83 // generates random account number
84 $random = rand($min, $max);
85 $id = $random;
86 $exist = array();
87
88
89 // reads already existing accounts
90 foreach( $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('accounts') )->fetchAll() as $account)
91 {
92 $exist[] = $account['id'];
93 }
94
95 // finds unused number
96 while(true)
97 {
98 // unused - found
99 if( !in_array($id, $exist) )
100 {
101 break;
102 }
103
104 // used - next one
105 $id++;
106
107 // we need to re-set
108 if($id > $max)
109 {
110 $id = $min;
111 }
112
113 // we checked all possibilities
114 if($id == $random)
115 {
116 throw new Exception('No free account number are available.');
117 }
118 }
119
120 // saves blank account info
121 $this->data['id'] = $id;
122
123 $this->db->query('INSERT INTO ' . $this->db->tableName('accounts') . ' (' . $this->db->fieldName('id') . ', ' . $this->db->fieldName('password') . ', ' . $this->db->fieldName('email') . ') VALUES (' . $id . ', \'\', \'\')');
124
125 return $id;
126 }
127
128/**
129 * @version 0.0.6
130 * @since 0.0.4
131 * @param OTS_Group $group Group to be assigned to account.
132 * @param int $min Minimum number.
133 * @param int $max Maximum number.
134 * @return int Created account number.
135 * @deprecated 0.0.6 There is no more group_id field in database, use create().
136 */
137 public function createEx(OTS_Group $group, $min = 1, $max = 9999999)
138 {
139 return $this->create($min, $max);
140 }
141
142/**
143 * Loads account with given number.
144 *
145 * @version 0.0.6
146 * @param int $id Account number.
147 * @throws PDOException On PDO operation error.
148 */
149 public function load($id)
150 {
151 // SELECT query on database
152 $this->data = $this->db->query('SELECT ' . $this->db->fieldName('id') . ', ' . $this->db->fieldName('password') . ', ' . $this->db->fieldName('email') . ', ' . $this->db->fieldName('blocked') . ', ' . $this->db->fieldName('rlname') . ', ' . $this->db->fieldName('location') . ', ' . $this->db->fieldName('rkey') . ', ' . $this->db->fieldName('page_access') . ', ' . $this->db->fieldName('premdays') . ', ' . $this->db->fieldName('created') . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . (int) $id)->fetch();
153 }
154
155
156
157/**
158 * Loads account by it's name.
159 *
160 * <p>
161 * Note: Since 0.1.5 version this method loads account by it's name not by e-mail address. To find account by it's e-mail address use {@link OTS_Account::findByEMail() findByEMail() method}.
162 * </p>
163 *
164 * @version 0.1.5
165 * @since 0.0.2
166 * @param string $name Account's name.
167 * @throws PDOException On PDO operation error.
168 */
169 public function find($id)
170 {
171 // finds player's ID
172 $name = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . (int) $id )->fetch();
173
174 // if anything was found
175 if( isset($name['id']) )
176 {
177 $this->load($name['id']);
178 }
179 }
180
181/**
182 * Loads account by it's e-mail address.
183 *
184 * @version 0.1.5
185 * @since 0.1.5
186 * @param string $email Account's e-mail address.
187 * @throws PDOException On PDO operation error.
188 */
189 public function findByEMail($email)
190 {
191 // finds player's ID
192 $id = $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('email') . ' = ' . $this->db->quote($email) )->fetch();
193
194 // if anything was found
195 if( isset($id['id']) )
196 {
197 $this->load($id['id']);
198 }
199 }
200
201/**
202 * Checks if object is loaded.
203 *
204 * @return bool Load state.
205 */
206 public function isLoaded()
207 {
208 return isset($this->data['id']);
209 }
210
211/**
212 * Updates account in database.
213 *
214 * <p>
215 * Unlike other DAO objects account can't be saved without ID being set. It means that you can't just save unexisting account to automaticly create it. First you have to create record by using {@link OTS_Account::createName() createNamed() method}
216 * </p>
217 *
218 * <p>
219 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded exception} instead of triggering E_USER_WARNING.
220 * </p>
221 *
222 * @version 0.1.5
223 * @throws E_OTS_NotLoaded If account doesn't have ID assigned.
224 * @throws PDOException On PDO operation error.
225 */
226 public function save()
227 {
228 if( !isset($this->data['id']) )
229 {
230 throw new E_OTS_NotLoaded();
231 }
232
233 // UPDATE query on database
234 $this->db->query('UPDATE ' . $this->db->tableName('accounts') . ' SET ' . $this->db->fieldName('password') . ' = ' . $this->db->quote($this->data['password']) . ', ' . $this->db->fieldName('email') . ' = ' . $this->db->quote($this->data['email']) . ', ' . $this->db->fieldName('rlname') . ' = ' . $this->db->quote($this->data['rlname']) . ', ' . $this->db->fieldName('rkey') . ' = ' . $this->db->quote($this->data['rkey']) . ', ' . $this->db->fieldName('location') . ' = ' . $this->db->quote($this->data['location']) . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
235 }
236
237/**
238 * Account number.
239 *
240 * <p>
241 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
242 * </p>
243 *
244 * @version 0.0.3
245 * @return int Account number.
246 * @throws E_OTS_NotLoaded If account is not loaded.
247 */
248 public function getId()
249 {
250 if( !isset($this->data['id']) )
251 {
252 throw new E_OTS_NotLoaded();
253 }
254
255 return $this->data['id'];
256 }
257
258/**
259 * Other Account Information.
260 *
261 * <p>
262 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
263 * </p>
264 *
265 * @version 0.0.3
266 * @return int Account Information.
267 * @throws E_OTS_NotLoaded If account is not loaded.
268 */
269
270 public function getRLName()
271 {
272 if( !isset($this->data['rlname']) )
273 {
274 throw new E_OTS_NotLoaded();
275 }
276
277 return $this->data['rlname'];
278 }
279
280 public function getLocation()
281 {
282 if( !isset($this->data['location']) )
283 {
284 throw new E_OTS_NotLoaded();
285 }
286
287 return $this->data['location'];
288 }
289
290 public function getPageAccess()
291 {
292 if( !isset($this->data['page_access']) )
293 {
294 throw new E_OTS_NotLoaded();
295 }
296
297 return $this->data['page_access'];
298 }
299
300 public function getPremDays()
301 {
302 if( !isset($this->data['premdays']) || !isset($this->data['lastday']) )
303 {
304 throw new E_OTS_NotLoaded();
305 }
306
307 return $this->data['premdays'] - (date("z", time()) + (365 * (date("Y", time()) - date("Y", $this->data['lastday']))) - date("z", $this->data['lastday']));
308 }
309
310 public function getLastLogin()
311 {
312 if( !isset($this->data['lastday']) )
313 {
314 throw new E_OTS_NotLoaded();
315 }
316
317 return $this->data['lastday'];
318 }
319
320 public function isPremium()
321 {
322 return ($this->data['premdays'] - (date("z", time()) + (365 * (date("Y", time()) - date("Y", $this->data['lastday']))) - date("z", $this->data['lastday'])) > 0);
323 }
324
325 public function getCreated()
326 {
327 if( !isset($this->data['created']) )
328 {
329 throw new E_OTS_NotLoaded();
330 }
331
332 return $this->data['created'];
333 }
334
335 public function getRecoveryKey()
336 {
337 if( !isset($this->data['rkey']) )
338 {
339 throw new E_OTS_NotLoaded();
340 }
341
342 return $this->data['rkey'];
343 }
344
345 public function setRLName($rlname)
346 {
347 $this->data['rlname'] = (string) $rlname;
348 }
349
350 public function setLocation($loc)
351 {
352 $this->data['location'] = (string) $loc;
353 }
354
355 public function setRecoveryKey($rec_key)
356 {
357 $this->data['rkey'] = (string) $rec_key;
358 }
359/**
360 * Account's password.
361 *
362 * <p>
363 * Doesn't matter what password hashing mechanism is used by OTServ - this method will just return RAW database content. It is not possible to "decrypt" hashed strings, so it even wouldn't be possible to return real password string.
364 * </p>
365 *
366 * <p>
367 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
368 * </p>
369 *
370 * @version 0.0.3
371 * @return string Password.
372 * @throws E_OTS_NotLoaded If account is not loaded.
373 */
374 public function getPassword()
375 {
376 if( !isset($this->data['password']) )
377 {
378 throw new E_OTS_NotLoaded();
379 }
380
381 return $this->data['password'];
382 }
383
384/**
385 * Sets account's password.
386 *
387 * <p>
388 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
389 * </p>
390 *
391 * <p>
392 * Remember that this method just sets database field's content. It doesn't apply any hashing/encryption so if OTServ uses hashing for passwords you have to apply it by yourself before passing string to this method.
393 * </p>
394 *
395 * @param string $password Password.
396 */
397 public function setPassword($password)
398 {
399 $this->data['password'] = (string) $password;
400 }
401
402/**
403 * E-mail address.
404 *
405 * <p>
406 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
407 * </p>
408 *
409 * @version 0.0.3
410 * @return string E-mail.
411 * @throws E_OTS_NotLoaded If account is not loaded.
412 */
413 public function getEMail()
414 {
415 if( !isset($this->data['email']) )
416 {
417 throw new E_OTS_NotLoaded();
418 }
419
420 return $this->data['email'];
421 }
422
423/**
424 * Sets account's email.
425 *
426 * <p>
427 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
428 * </p>
429 *
430 * @param string $email E-mail address.
431 */
432 public function setEMail($email)
433 {
434 $this->data['email'] = (string) $email;
435 }
436
437
438/**
439 * Checks if account is blocked.
440 *
441 * <p>
442 * Note: Since 0.0.3 version this method throws {@link E_OTS_NotLoaded E_OTS_NotLoaded} exception instead of triggering E_USER_WARNING.
443 * </p>
444 *
445 * @version 0.0.3
446 * @return bool Blocked state.
447 * @throws E_OTS_NotLoaded If account is not loaded.
448 */
449 public function isBlocked()
450 {
451 if( !isset($this->data['blocked']) )
452 {
453 throw new E_OTS_NotLoaded();
454 }
455
456 return $this->data['blocked'];
457 }
458
459/**
460 * Unblocks account.
461 *
462 * <p>
463 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
464 * </p>
465 */
466 public function unblock()
467 {
468 $this->data['blocked'] = false;
469 }
470
471/**
472 * Blocks account.
473 *
474 * <p>
475 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
476 * </p>
477 */
478 public function block()
479 {
480 $this->data['blocked'] = true;
481 }
482
483/**
484 * Checks if account is deleted (by flag setting).
485 *
486 * @version 0.1.5
487 * @since 0.1.5
488 * @return bool Flag state.
489 * @throws E_OTS_NotLoaded If account is not loaded.
490 */
491 public function isDeleted()
492 {
493 if( !isset($this->data['deleted']) )
494 {
495 throw new E_OTS_NotLoaded();
496 }
497
498 return $this->data['blocked'];
499 }
500
501/**
502 * Unsets account's deleted flag.
503 *
504 * <p>
505 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
506 * </p>
507 *
508 * @version 0.1.5
509 * @since 0.1.5
510 */
511 public function unsetDeleted()
512 {
513 $this->data['deleted'] = false;
514 }
515
516/**
517 * Deletes account (only by setting flag state, not physicly).
518 *
519 * <p>
520 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
521 * </p>
522 *
523 * @version 0.1.5
524 * @since 0.1.5
525 */
526 public function setDeleted()
527 {
528 $this->data['deleted'] = true;
529 }
530
531/**
532 * Checks if account is warned.
533 *
534 * @version 0.1.5
535 * @since 0.1.5
536 * @return bool Flag state.
537 * @throws E_OTS_NotLoaded If account is not loaded.
538 */
539 public function isWarned()
540 {
541 if( !isset($this->data['warned']) )
542 {
543 throw new E_OTS_NotLoaded();
544 }
545
546 return $this->data['warned'];
547 }
548
549/**
550 * Unwarns account.
551 *
552 * <p>
553 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
554 * </p>
555 *
556 * @version 0.1.5
557 * @since 0.1.5
558 */
559 public function unwarn()
560 {
561 $this->data['warned'] = false;
562 }
563
564/**
565 * Warns account.
566 *
567 * <p>
568 * This method only updates object state. To save changes in database you need to use {@link OTS_Account::save() save() method} to flush changed to database.
569 * </p>
570 *
571 * @version 0.1.5
572 * @since 0.1.5
573 */
574 public function warn()
575 {
576 $this->data['warned'] = true;
577 }
578
579/**
580 * @version 0.0.4
581 * @return int PACC days.
582 * @throws E_OTS_NotLoaded If account is not loaded.
583 * @deprecated 0.0.3 There is no more premdays field in accounts table.
584 */
585 public function getPACCDays()
586 {
587 if( !isset($this->data['id']) )
588 {
589 throw new E_OTS_NotLoaded();
590 }
591
592 return 0;
593 }
594
595/**
596 * @version 0.0.4
597 * @param int $pacc PACC days.
598 * @deprecated 0.0.3 There is no more premdays field in accounts table.
599 */
600 public function setPACCDays($premdays)
601 {
602 }
603
604/**
605 * Reads custom field.
606 *
607 * <p>
608 * Reads field by it's name. Can read any field of given record that exists in database.
609 * </p>
610 *
611 * <p>
612 * Note: You should use this method only for fields that are not provided in standard setters/getters (SVN fields). This method runs SQL query each time you call it so it highly overloads used resources.
613 * </p>
614 *
615 * @version 0.0.5
616 * @since 0.0.3
617 * @param string $field Field name.
618 * @return string Field value.
619 * @throws E_OTS_NotLoaded If account is not loaded.
620 * @throws PDOException On PDO operation error.
621 */
622 public function getCustomField($field)
623 {
624 if( !isset($this->data['id']) )
625 {
626 throw new E_OTS_NotLoaded();
627 }
628
629 $value = $this->db->query('SELECT ' . $this->db->fieldName($field) . ' FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id'])->fetch();
630 return $value[$field];
631 }
632
633/**
634 * Writes custom field.
635 *
636 * <p>
637 * Write field by it's name. Can write any field of given record that exists in database.
638 * </p>
639 *
640 * <p>
641 * Note: You should use this method only for fields that are not provided in standard setters/getters (SVN fields). This method runs SQL query each time you call it so it highly overloads used resources.
642 * </p>
643 *
644 * <p>
645 * Note: Make sure that you pass $value argument of correct type. This method determinates whether to quote field name. It is safe - it makes you sure that no unproper queries that could lead to SQL injection will be executed, but it can make your code working wrong way. For example: $object->setCustomField('foo', '1'); will quote 1 as as string ('1') instead of passing it as a integer.
646 * </p>
647 *
648 * @version 0.0.5
649 * @since 0.0.3
650 * @param string $field Field name.
651 * @param mixed $value Field value.
652 * @throws E_OTS_NotLoaded If account is not loaded.
653 * @throws PDOException On PDO operation error.
654 */
655 public function setCustomField($field, $value)
656 {
657 if( !isset($this->data['id']) )
658 {
659 throw new E_OTS_NotLoaded();
660 }
661
662 // quotes value for SQL query
663 if(!( is_int($value) || is_float($value) ))
664 {
665 $value = $this->db->quote($value);
666 }
667
668 $this->db->query('UPDATE ' . $this->db->tableName('accounts') . ' SET ' . $this->db->fieldName($field) . ' = ' . $value . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
669 }
670
671/**
672 * @version 0.1.0
673 * @return array Array of OTS_Player objects from given account.
674 * @throws E_OTS_NotLoaded If account is not loaded.
675 * @deprecated 0.0.5 Use getPlayersList().
676 */
677 public function getPlayers()
678 {
679 if( !isset($this->data['id']) )
680 {
681 throw new E_OTS_NotLoaded();
682 }
683
684 $players = array();
685
686 foreach( $this->db->query('SELECT ' . $this->db->fieldName('id') . ' FROM ' . $this->db->tableName('players') . ' WHERE ' . $this->db->fieldName('account_id') . ' = ' . $this->data['id'])->fetchAll() as $player)
687 {
688 // creates new object
689 $object = new OTS_Player();
690 $object->load($player['id']);
691 $players[] = $object;
692 }
693
694 return $players;
695 }
696
697/**
698 * List of characters on account.
699 *
700 * <p>
701 * In difference to {@link OTS_Account::getPlayers() getPlayers() method} this method returns filtered {@link OTS_Players_List OTS_Players_List} object instead of array of {@link OTS_Player OTS_Player} objects. It is more effective since OTS_Player_List doesn't perform all rows loading at once.
702 * </p>
703 *
704 * <p>
705 * Note: Returned object is only prepared, but not initialised. When using as parameter in foreach loop it doesn't matter since it will return it's iterator, but if you will wan't to execute direct operation on that object you will need to call {@link OTS_Base_List::rewind() rewind() method} first.
706 * </p>
707 *
708 * @version 0.1.4
709 * @since 0.0.5
710 * @return OTS_Players_List List of players from current account.
711 * @throws E_OTS_NotLoaded If account is not loaded.
712 */
713 public function getPlayersList()
714 {
715 if( !isset($this->data['id']) )
716 {
717 throw new E_OTS_NotLoaded();
718 }
719
720 // creates filter
721 $filter = new OTS_SQLFilter();
722 $filter->compareField('account_id', (int) $this->data['id']);
723
724 // creates list object
725 $list = new OTS_Players_List();
726 $list->setFilter($filter);
727
728 return $list;
729 }
730
731/**
732 * Deletes account.
733 *
734 * <p>
735 * This method physicly deletes account from database! To set <i>deleted</i> flag use {@link OTS_Account::setDeleted() setDeleted() method}.
736 * </p>
737 *
738 * @version 0.0.5
739 * @since 0.0.5
740 * @throws E_OTS_NotLoaded If account is not loaded.
741 * @throws PDOException On PDO operation error.
742 */
743 public function delete()
744 {
745 if( !isset($this->data['id']) )
746 {
747 throw new E_OTS_NotLoaded();
748 }
749
750 // deletes row from database
751 $this->db->query('DELETE FROM ' . $this->db->tableName('accounts') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
752
753 // resets object handle
754 unset($this->data['id']);
755 }
756
757/**
758 * Checks highest access level of account.
759 *
760 * @return int Access level (highest access level of all characters).
761 * @throws PDOException On PDO operation error.
762 */
763 public function getAccess()
764 {
765 // by default
766 $access = 0;
767
768 // finds groups of all characters
769 foreach( $this->getPlayersList() as $player)
770 {
771 $group = $player->getGroup();
772
773 // checks if group's access level is higher then previouls found highest
774 if( $group->getAccess() > $access)
775 {
776 $access = $group->getAccess();
777 }
778 }
779
780 return $access;
781 }
782
783/**
784 * Checks highest access level of account in given guild.
785 *
786 * @param OTS_Guild $guild Guild in which access should be checked.
787 * @return int Access level (highest access level of all characters).
788 * @throws PDOException On PDO operation error.
789 */
790 public function getGuildAccess(OTS_Guild $guild)
791 {
792 // by default
793 $access = 0;
794
795 // finds ranks of all characters
796 foreach( $this->getPlayersList() as $player)
797 {
798 $rank = $player->getRank();
799
800 // checks if rank's access level is higher then previouls found highest
801 if( isset($rank) && $rank->getGuild()->getId() == $guild->getId() && $rank->getLevel() > $access)
802 {
803 $access = $rank->getLevel();
804 }
805 }
806
807 return $access;
808 }
809
810/**
811 * Returns players iterator.
812 *
813 * <p>
814 * There is no need to implement entire Iterator interface since we have {@link OTS_Players_List players list class} for it.
815 * </p>
816 *
817 * @version 0.0.5
818 * @since 0.0.5
819 * @throws E_OTS_NotLoaded If account is not loaded.
820 * @throws PDOException On PDO operation error.
821 * @return Iterator List of players.
822 */
823 public function getIterator()
824 {
825 return $this->getPlayersList();
826 }
827
828/**
829 * Returns number of player within.
830 *
831 * @version 0.0.5
832 * @since 0.0.5
833 * @throws E_OTS_NotLoaded If account is not loaded.
834 * @throws PDOException On PDO operation error.
835 * @return int Count of players.
836 */
837 public function count()
838 {
839 return $this->getPlayersList()->count();
840 }
841
842/**
843 * Magic PHP5 method.
844 *
845 * @version 0.1.5
846 * @since 0.1.0
847 * @param string $name Property name.
848 * @return mixed Property value.
849 * @throws E_OTS_NotLoaded If account is not loaded.
850 * @throws OutOfBoundsException For non-supported properties.
851 * @throws PDOException On PDO operation error.
852 */
853 public function __get($name)
854 {
855 switch($name)
856 {
857 case 'id':
858 return $this->getId();
859
860 case 'password':
861 return $this->getPassword();
862
863 case 'eMail':
864 return $this->getEMail();
865
866 case 'premiumEnd':
867 return $this->getPremiumEnd();
868
869 case 'loaded':
870 return $this->isLoaded();
871
872 case 'playersList':
873 return $this->getPlayersList();
874
875 case 'blocked':
876 return $this->isBlocked();
877
878 case 'deleted':
879 return $this->isDeleted();
880
881 case 'warned':
882 return $this->isWarned();
883
884 case 'access':
885 return $this->getAccess();
886
887 default:
888 throw new OutOfBoundsException();
889 }
890 }
891
892/**
893 * Magic PHP5 method.
894 *
895 * @version 0.1.5
896 * @since 0.1.0
897 * @param string $name Property name.
898 * @param mixed $value Property value.
899 * @throws E_OTS_NotLoaded If account is not loaded.
900 * @throws OutOfBoundsException For non-supported properties.
901 * @throws PDOException On PDO operation error.
902 */
903 public function __set($name, $value)
904 {
905 switch($name)
906 {
907 case 'password':
908 $this->setPassword($value);
909 break;
910
911 case 'eMail':
912 $this->setEMail($value);
913 break;
914
915 case 'premiumEnd':
916 $this->setPremiumEnd($value);
917 break;
918
919 case 'blocked':
920 if($value)
921 {
922 $this->block();
923 }
924 else
925 {
926 $this->unblock();
927 }
928 break;
929
930 case 'deleted':
931 if($value)
932 {
933 $this->setDeleted();
934 }
935 else
936 {
937 $this->unsetDeleted();
938 }
939 break;
940
941 case 'warned':
942 if($value)
943 {
944 $this->warn();
945 }
946 else
947 {
948 $this->unwarn();
949 }
950 break;
951
952 default:
953 throw new OutOfBoundsException();
954 }
955 }
956
957/**
958 * Returns string representation of object.
959 *
960 * <p>
961 * If any display driver is currently loaded then it uses it's method. Otherwise just returns account number.
962 * </p>
963 *
964 * @version 0.1.3
965 * @since 0.1.0
966 * @return string String representation of object.
967 */
968 public function __toString()
969 {
970 $ots = POT::getInstance();
971
972 // checks if display driver is loaded
973 if( $ots->isDisplayDriverLoaded() )
974 {
975 return $ots->getDisplayDriver()->displayAccount($this);
976 }
977
978 return $this->getId();
979 }
980}
981
982/**#@-*/
983
984?>