PluginProbe
User Access Manager / 2.1.4
User Access Manager v2.1.4
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / UserGroup / UserGroup.php

UserGroup.php in User Access Manager 2.1.4, at src/UserGroup/UserGroup.php

205 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UserGroup.php
4 *
5 * The UserGroup class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15 namespace UserAccessManager\UserGroup;
16
17 use UserAccessManager\Config\MainConfig;
18 use UserAccessManager\Database\Database;
19 use UserAccessManager\Object\ObjectHandler;
20 use UserAccessManager\Util\Util;
21 use UserAccessManager\Wrapper\Php;
22 use UserAccessManager\Wrapper\Wordpress;
23
24 /**
25 * Class UserGroup
26 *
27 * @package UserAccessManager\UserGroup
28 */
29 class UserGroup extends AbstractUserGroup
30 {
31 const USER_GROUP_TYPE = 'UserGroup';
32
33 /**
34 * @var string
35 */
36 protected $type = self::USER_GROUP_TYPE;
37
38 /**
39 * @var string
40 */
41 protected $ipRange = null;
42
43 /**
44 * UserGroup constructor.
45 *
46 * @param Php $php
47 * @param Wordpress $wordpress
48 * @param Database $database
49 * @param MainConfig $config
50 * @param Util $util
51 * @param ObjectHandler $objectHandler
52 * @param AssignmentInformationFactory $assignmentInformationFactory
53 * @param null|string $id
54 */
55 public function __construct(
56 Php $php,
57 Wordpress $wordpress,
58 Database $database,
59 MainConfig $config,
60 Util $util,
61 ObjectHandler $objectHandler,
62 AssignmentInformationFactory $assignmentInformationFactory,
63 $id = null
64 ) {
65 parent::__construct(
66 $php,
67 $wordpress,
68 $database,
69 $config,
70 $util,
71 $objectHandler,
72 $assignmentInformationFactory
73 );
74
75 if ($id !== null) {
76 $this->load((int)$id);
77 }
78 }
79
80 /**
81 * Returns the ip range.
82 *
83 * @return array|string
84 */
85 public function getIpRange()
86 {
87 return $this->ipRange;
88 }
89
90 /**
91 * Returns the ip range as array
92 *
93 * @return array
94 */
95 public function getIpRangeArray()
96 {
97 return explode(';', $this->ipRange);
98 }
99
100 /**
101 * Sets the ip range.
102 *
103 * @param string|array $ipRange The new ip range.
104 */
105 public function setIpRange($ipRange)
106 {
107 $this->ipRange = (is_array($ipRange) === true) ? implode(';', $ipRange) : $ipRange;
108 }
109
110 /**
111 * Loads the user group.
112 *
113 * @param string $id
114 *
115 * @return bool
116 */
117 public function load($id)
118 {
119 $query = $this->database->prepare(
120 "SELECT *
121 FROM {$this->database->getUserGroupTable()}
122 WHERE ID = %d
123 LIMIT 1",
124 $id
125 );
126
127 $dbUserGroup = $this->database->getRow($query);
128
129 if ($dbUserGroup !== null) {
130 $this->id = $id;
131 $this->name = $dbUserGroup->groupname;
132 $this->description = $dbUserGroup->groupdesc;
133 $this->readAccess = $dbUserGroup->read_access;
134 $this->writeAccess = $dbUserGroup->write_access;
135 $this->ipRange = $dbUserGroup->ip_range;
136
137 return true;
138 }
139
140 return false;
141 }
142
143 /**
144 * Saves the user group.
145 *
146 * @return bool
147 */
148 public function save()
149 {
150 if ($this->id === null) {
151 $return = $this->database->insert(
152 $this->database->getUserGroupTable(),
153 [
154 'groupname' => $this->name,
155 'groupdesc' => $this->description,
156 'read_access' => $this->readAccess,
157 'write_access' => $this->writeAccess,
158 'ip_range' => $this->ipRange
159 ]
160 );
161
162 if ($return !== false) {
163 $this->id = (string)$this->database->getLastInsertId();
164 }
165 } else {
166 $return = $this->database->update(
167 $this->database->getUserGroupTable(),
168 [
169 'groupname' => $this->name,
170 'groupdesc' => $this->description,
171 'read_access' => $this->readAccess,
172 'write_access' => $this->writeAccess,
173 'ip_range' => $this->ipRange
174 ],
175 ['ID' => $this->id]
176 );
177 }
178
179 return ($return !== false);
180 }
181
182 /**
183 * Deletes the user group.
184 *
185 * @return bool
186 */
187 public function delete()
188 {
189 if ($this->id === null) {
190 return false;
191 }
192
193 $success = $this->database->delete(
194 $this->database->getUserGroupTable(),
195 ['ID' => $this->id]
196 );
197
198 if ($success !== false) {
199 $success = parent::delete();
200 }
201
202 return $success;
203 }
204 }
205