1 <?php
2 /**
3 * XLRstats : Real Time Player Stats (http://www.xlrstats.com)
4 * (CC) BY-NC-SA 2005-2013, Mark Weirath, Özgür Uysal
5 *
6 * Licensed under the Creative Commons BY-NC-SA 3.0 License
7 * Redistributions of files must retain the above copyright notice.
8 *
9 * @link http://www.xlrstats.com
10 * @license Creative Commons BY-NC-SA 3.0 License (http://creativecommons.org/licenses/by-nc-sa/3.0/)
11 * @package app.Plugin.Dashboard.Model
12 * @since XLRstats v3.0
13 * @version 0.1
14 */
15
16 App::uses('User', 'Users.Model');
17
18 /**
19 * Class AppUser
20 */
21 class AppUser extends User {
22
23 /**
24 * Database table
25 * @var string
26 */
27 public $useTable = 'users';
28
29 /**
30 * Alias
31 *
32 * @var string
33 */
34 public $alias = 'User';
35
36 /**
37 * Database associations
38 *
39 * @var array
40 */
41 public $belongsTo = array(
42 'Group' => array(
43 'className' => 'Dashboard.Group'
44 )
45 );
46
47 /**
48 * hasAndBelongsToMany associations
49 *
50 * @var array
51 */
52 public $hasAndBelongsToMany = array(
53 'ServerGroup' => array(
54 'className' => 'Dashboard.ServerGroup',
55 'joinTable' => 'server_groups_users',
56 'foreignKey' => 'user_id',
57 'associationForeignKey' => 'server_group_id',
58 'unique' => true,
59 )
60 );
61
62 /**
63 * Add ACL behaviour and set 'enabled' to false to avoid the afterSave to be called.
64 * This will prevent users being added to 'aros' table.
65 *
66 * @var array
67 */
68 public $actsAs = array('Acl' => array('type' => 'requester', 'enabled' => false));
69
70 //-------------------------------------------------------------------
71
72 /**
73 * This is used by the AclBehavior to determine parent->child relationships.
74 * Returns null as we're using Group Only ACL
75 *
76 * @return array|null
77 */
78 public function parentNode() {
79 return null;
80 }
81
82 //-------------------------------------------------------------------
83
84 /**
85 * Required for group only ACL
86 *
87 * @param $user
88 * @return array
89 */
90 public function bindNode($user) {
91 return array('model' => 'Group', 'foreign_key' => $user['AppUser']['group_id']);
92 }
93
94 //-------------------------------------------------------------------
95
96 /**
97 * Returns an array of user data
98 *
99 * @param null $id
100 * @return array
101 */
102 public function getUserData($id = null) {
103 $userData = $this->find('first', array(
104 'conditions' => array(
105 'User.id' => $id,
106 )
107 ));
108 return $userData;
109 }
110
111 }