PluginProbe
User Access Manager / 2.3.17
User Access Manager v2.3.17
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
← All changes | src/UserGroup/UserGroup.php +52 -31 trunk2.3.17 View file →
@@ -7,8 +7,10 @@
7 7 use Exception;
8 8 use UserAccessManager\Config\MainConfig;
9 9 use UserAccessManager\Database\Database;
10 10 use UserAccessManager\Object\ObjectHandler;
11 +use UserAccessManager\Util\Util;
12 +use UserAccessManager\Wrapper\Php;
11 13 use UserAccessManager\Wrapper\Wordpress;
12 14
13 15 class UserGroup extends AbstractUserGroup
14 16 {
@@ -20,16 +22,26 @@
20 22 /**
21 23 * @throws UserGroupTypeException
22 24 */
23 25 public function __construct(
26 + Php $php,
24 27 Wordpress $wordpress,
25 28 Database $database,
26 29 MainConfig $config,
30 + Util $util,
27 31 ObjectHandler $objectHandler,
28 32 AssignedObjectsLoader $assignedObjectsLoader,
29 33 int|string|null $id = null
30 34 ) {
31 - parent::__construct($wordpress, $database, $config, $objectHandler, $assignedObjectsLoader);
35 + parent::__construct(
36 + $php,
37 + $wordpress,
38 + $database,
39 + $config,
40 + $util,
41 + $objectHandler,
42 + $assignedObjectsLoader
43 + );
32 44
33 45 if ($id !== null) {
34 46 $this->load($id);
35 47 }
@@ -34,9 +46,9 @@
34 46 $this->load($id);
35 47 }
36 48 }
37 49
38 - public function getIpRange(): ?string
50 + public function getIpRange(): array|string|null
39 51 {
40 52 return $this->ipRange;
41 53 }
42 54
@@ -53,10 +65,10 @@
53 65 public function load(int|string $id): bool
54 66 {
55 67 $query = $this->database->prepare(
56 68 "SELECT *
57 - FROM `{$this->database->getUserGroupTable()}`
58 - WHERE `ID` = %d
69 + FROM {$this->database->getUserGroupTable()}
70 + WHERE ID = %d
59 71 LIMIT 1",
60 72 $id
61 73 );
62 74
@@ -61,15 +73,15 @@
61 73 );
62 74
63 75 $databaseUserGroup = $this->database->getRow($query);
64 76
65 - if ($databaseUserGroup === null) {
66 - return false;
77 + if ($databaseUserGroup !== null) {
78 + $this->assignDatabaseValues($databaseUserGroup);
79 +
80 + return true;
67 81 }
68 82
69 - $this->assignDatabaseValues($databaseUserGroup);
70 -
71 - return true;
83 + return false;
72 84 }
73 85
74 86 public function assignDatabaseValues(object $databaseUserGroup): void
75 87 {
@@ -82,33 +94,38 @@
82 94 }
83 95
84 96 public function save(): bool
85 97 {
86 - $columns = [
87 - 'groupname' => $this->name,
88 - 'groupdesc' => $this->description,
89 - 'read_access' => $this->readAccess,
90 - 'write_access' => $this->writeAccess,
91 - 'ip_range' => $this->ipRange
92 - ];
98 + if ($this->id === null) {
99 + $return = $this->database->insert(
100 + $this->database->getUserGroupTable(),
101 + [
102 + 'groupname' => $this->name,
103 + 'groupdesc' => $this->description,
104 + 'read_access' => $this->readAccess,
105 + 'write_access' => $this->writeAccess,
106 + 'ip_range' => $this->ipRange
107 + ]
108 + );
93 109
94 - if ($this->id !== null) {
95 - return $this->database->update(
110 + if ($return !== false) {
111 + $this->id = (string) $this->database->getLastInsertId();
112 + }
113 + } else {
114 + $return = $this->database->update(
96 115 $this->database->getUserGroupTable(),
97 - $columns,
116 + [
117 + 'groupname' => $this->name,
118 + 'groupdesc' => $this->description,
119 + 'read_access' => $this->readAccess,
120 + 'write_access' => $this->writeAccess,
121 + 'ip_range' => $this->ipRange
122 + ],
98 123 ['ID' => $this->id]
99 - ) !== false;
124 + );
100 125 }
101 126
102 - $return = $this->database->insert($this->database->getUserGroupTable(), $columns);
103 -
104 - if ($return === false) {
105 - return false;
106 - }
107 -
108 - $this->id = (string) $this->database->getLastInsertId();
109 -
110 - return true;
127 + return ($return !== false);
111 128 }
112 129
113 130 /**
114 131 * @throws Exception
@@ -118,12 +135,16 @@
118 135 if ($this->id === null) {
119 136 return false;
120 137 }
121 138
122 - $deleted = $this->database->delete(
139 + $success = $this->database->delete(
123 140 $this->database->getUserGroupTable(),
124 141 ['ID' => $this->id]
125 142 );
126 143
127 - return ($deleted !== false) && parent::delete();
144 + if ($success !== false) {
145 + $success = parent::delete();
146 + }
147 +
148 + return $success;
128 149 }
129 150 }