| @@ -37,9 +37,9 @@ | ||
| 37 | 37 | protected Database $database, |
| 38 | 38 | protected MainConfig $config, |
| 39 | 39 | protected Util $util, |
| 40 | 40 | protected ObjectHandler $objectHandler, |
| 41 | - protected AssignedObjectsLoader $assignedObjectsLoader, | |
| 41 | + protected AssignmentInformationFactory $assignmentInformationFactory, | |
| 42 | 42 | protected int|string|null $id = null |
| 43 | 43 | ) { |
| 44 | 44 | if ($this->type === null) { |
| 45 | 45 | throw new UserGroupTypeException('User group type must not null.'); |
| @@ -116,14 +116,8 @@ | ||
| 116 | 116 | $this->objectMembership = []; |
| 117 | 117 | $this->fullObjectMembership = []; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - private function resetObjectsAfterAssignmentChange(): void | |
| 121 | - { | |
| 122 | - $this->assignedObjectsLoader->flush(); | |
| 123 | - $this->resetObjects(); | |
| 124 | - } | |
| 125 | - | |
| 126 | 120 | /** |
| 127 | 121 | * @throws Exception |
| 128 | 122 | */ |
| 129 | 123 | public function delete(): bool |
| @@ -139,9 +133,9 @@ | ||
| 139 | 133 | |
| 140 | 134 | /** |
| 141 | 135 | * @throws Exception |
| 142 | 136 | */ |
| 143 | - public function addObject(string $objectType, int|string|null $objectId, $fromDate = null, $toDate = null): bool | |
| 137 | + public function addObject(string $objectType, int|string $objectId, $fromDate = null, $toDate = null): bool | |
| 144 | 138 | { |
| 145 | 139 | $generalObjectType = $this->objectHandler->getGeneralObjectType($objectType); |
| 146 | 140 | |
| 147 | 141 | if ($generalObjectType === null |
| @@ -172,9 +166,9 @@ | ||
| 172 | 166 | ] |
| 173 | 167 | ); |
| 174 | 168 | |
| 175 | 169 | if ($return !== false) { |
| 176 | - $this->resetObjectsAfterAssignmentChange(); | |
| 170 | + $this->resetObjects(); | |
| 177 | 171 | return true; |
| 178 | 172 | } |
| 179 | 173 | |
| 180 | 174 | return false; |
| @@ -218,9 +212,9 @@ | ||
| 218 | 212 | $query = $this->database->prepare($query, $values); |
| 219 | 213 | $success = ($this->database->query($query) !== false); |
| 220 | 214 | |
| 221 | 215 | if ($success === true) { |
| 222 | - $this->resetObjectsAfterAssignmentChange(); | |
| 216 | + $this->resetObjects(); | |
| 223 | 217 | } |
| 224 | 218 | |
| 225 | 219 | return $success; |
| 226 | 220 | } |
| @@ -230,14 +224,36 @@ | ||
| 230 | 224 | */ |
| 231 | 225 | public function getAssignedObjects(string $objectType): array |
| 232 | 226 | { |
| 233 | 227 | if (isset($this->assignedObjects[$objectType]) === false) { |
| 234 | - $this->assignedObjects[$objectType] = $this->assignedObjectsLoader->getAssignedObjects( | |
| 228 | + $query = "SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate | |
| 229 | + FROM {$this->database->getUserGroupToObjectTable()} | |
| 230 | + WHERE group_id = '%s' | |
| 231 | + AND group_type = '%s' | |
| 232 | + AND object_id != '' | |
| 233 | + AND (general_object_type = '%s' OR object_type = '%s')"; | |
| 234 | + | |
| 235 | + $parameters = [ | |
| 236 | + $this->id, | |
| 235 | 237 | $this->type, |
| 236 | - $this->id, | |
| 237 | 238 | $objectType, |
| 238 | - $this->ignoreDates | |
| 239 | - ); | |
| 239 | + $objectType | |
| 240 | + ]; | |
| 241 | + | |
| 242 | + if ($this->ignoreDates === false) { | |
| 243 | + $query .= " AND (from_date IS NULL OR from_date <= '%s') AND (to_date IS NULL OR to_date >= '%s')"; | |
| 244 | + $time = $this->wordpress->currentTime('mysql'); | |
| 245 | + $parameters = array_merge($parameters, [$time, $time]); | |
| 246 | + } | |
| 247 | + | |
| 248 | + $query = $this->database->prepare($query, $parameters); | |
| 249 | + $results = (array) $this->database->getResults($query); | |
| 250 | + $this->assignedObjects[$objectType] = []; | |
| 251 | + | |
| 252 | + foreach ($results as $result) { | |
| 253 | + $this->assignedObjects[$objectType][$result->id] = $this->assignmentInformationFactory | |
| 254 | + ->createAssignmentInformation($result->objectType, $result->fromDate, $result->toDate); | |
| 255 | + } | |
| 240 | 256 | } |
| 241 | 257 | |
| 242 | 258 | return $this->assignedObjects[$objectType]; |
| 243 | 259 | } |
| @@ -294,9 +310,9 @@ | ||
| 294 | 310 | |
| 295 | 311 | return $this->defaultTypes; |
| 296 | 312 | } |
| 297 | 313 | |
| 298 | - public function isDefaultGroupForObjectType(string $objectType, ?int &$fromTime = null, ?int &$toTime = null): bool | |
| 314 | + public function isDefaultGroupForObjectType(string $objectType, int &$fromTime = null, int &$toTime = null): bool | |
| 299 | 315 | { |
| 300 | 316 | $defaultGroupForObjectTypes = $this->getDefaultGroupForObjectTypes(); |
| 301 | 317 | |
| 302 | 318 | // Reset reference values anyway |
| @@ -316,10 +332,10 @@ | ||
| 316 | 332 | } |
| 317 | 333 | |
| 318 | 334 | public function isObjectAssignedToGroup( |
| 319 | 335 | string $objectType, |
| 320 | - int|string|null $objectId, | |
| 321 | - ?AssignmentInformation &$assignmentInformation = null | |
| 336 | + int|string $objectId, | |
| 337 | + AssignmentInformation &$assignmentInformation = null | |
| 322 | 338 | ): bool { |
| 323 | 339 | $assignmentInformation = null; |
| 324 | 340 | $assignedObjects = $this->getAssignedObjects($objectType); |
| 325 | 341 | |
| @@ -336,9 +352,9 @@ | ||
| 336 | 352 | */ |
| 337 | 353 | public function isObjectMember( |
| 338 | 354 | string $objectType, |
| 339 | 355 | int|string|null $objectId, |
| 340 | - ?AssignmentInformation &$assignmentInformation = null | |
| 356 | + AssignmentInformation &$assignmentInformation = null | |
| 341 | 357 | ): bool { |
| 342 | 358 | if (isset($this->objectMembership[$objectType][$objectId]) === false) { |
| 343 | 359 | try { |
| 344 | 360 | $isMember = $this->objectHandler->getObjectMembershipHandler($objectType)->isMember( |
| @@ -363,9 +379,9 @@ | ||
| 363 | 379 | |
| 364 | 380 | /** |
| 365 | 381 | * @throws Exception |
| 366 | 382 | */ |
| 367 | - public function isRoleMember(int|string|null $roleId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 383 | + public function isRoleMember(int|string $roleId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 368 | 384 | { |
| 369 | 385 | return $this->isObjectMember(ObjectHandler::GENERAL_ROLE_OBJECT_TYPE, $roleId, $assignmentInformation); |
| 370 | 386 | } |
| 371 | 387 | |
| @@ -371,9 +387,9 @@ | ||
| 371 | 387 | |
| 372 | 388 | /** |
| 373 | 389 | * @throws Exception |
| 374 | 390 | */ |
| 375 | - public function isUserMember(int|string|null $userId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 391 | + public function isUserMember(int|string $userId, AssignmentInformation &$assignmentInformation = null): bool | |
| 376 | 392 | { |
| 377 | 393 | return $this->isObjectMember(ObjectHandler::GENERAL_USER_OBJECT_TYPE, $userId, $assignmentInformation); |
| 378 | 394 | } |
| 379 | 395 | |
| @@ -379,9 +395,9 @@ | ||
| 379 | 395 | |
| 380 | 396 | /** |
| 381 | 397 | * @throws Exception |
| 382 | 398 | */ |
| 383 | - public function isTermMember(int|string|null $termId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 399 | + public function isTermMember(int|string $termId, AssignmentInformation &$assignmentInformation = null): bool | |
| 384 | 400 | { |
| 385 | 401 | return $this->isObjectMember(ObjectHandler::GENERAL_TERM_OBJECT_TYPE, $termId, $assignmentInformation); |
| 386 | 402 | } |
| 387 | 403 | |
| @@ -387,9 +403,9 @@ | ||
| 387 | 403 | |
| 388 | 404 | /** |
| 389 | 405 | * @throws Exception |
| 390 | 406 | */ |
| 391 | - public function isPostMember(int|string|null $postId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 407 | + public function isPostMember(int|string $postId, AssignmentInformation &$assignmentInformation = null): bool | |
| 392 | 408 | { |
| 393 | 409 | return $this->isObjectMember(ObjectHandler::GENERAL_POST_OBJECT_TYPE, $postId, $assignmentInformation); |
| 394 | 410 | } |
| 395 | 411 | |