| @@ -1,103 +1,281 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 2 | +/** | |
| 3 | + * AbstractUserGroup.php | |
| 4 | + * | |
| 5 | + * The AbstractUserGroup class file. | |
| 6 | + * | |
| 7 | + * PHP versions 5 | |
| 8 | + * | |
| 9 | + * @author Alexander Schneider <[email protected]> | |
| 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 | + */ | |
| 5 | 15 | namespace UserAccessManager\UserGroup; |
| 6 | 16 | |
| 7 | -use Exception; | |
| 8 | 17 | use UserAccessManager\Config\MainConfig; |
| 9 | 18 | use UserAccessManager\Database\Database; |
| 10 | 19 | use UserAccessManager\Object\ObjectHandler; |
| 11 | 20 | use UserAccessManager\ObjectMembership\MissingObjectMembershipHandlerException; |
| 21 | +use UserAccessManager\ObjectMembership\ObjectMembershipHandlerFactory; | |
| 12 | 22 | use UserAccessManager\Util\Util; |
| 13 | 23 | use UserAccessManager\Wrapper\Php; |
| 14 | 24 | use UserAccessManager\Wrapper\Wordpress; |
| 15 | 25 | |
| 26 | +/** | |
| 27 | + * Class AbstractUserGroup | |
| 28 | + * | |
| 29 | + * @package UserAccessManager\UserGroup | |
| 30 | + */ | |
| 16 | 31 | abstract class AbstractUserGroup |
| 17 | 32 | { |
| 18 | - public const NONE_ROLE = '_none-role_'; | |
| 33 | + const NONE_ROLE = '_none-role_'; | |
| 19 | 34 | |
| 20 | - protected ?string $type = null; | |
| 21 | - protected ?string $name = null; | |
| 22 | - protected ?string $description = null; | |
| 23 | - protected string $readAccess = 'group'; | |
| 24 | - protected string $writeAccess = 'group'; | |
| 25 | - protected bool $ignoreDates = false; | |
| 26 | - protected array $assignedObjects = []; | |
| 27 | - protected array $objectMembership = []; | |
| 28 | - protected array $fullObjectMembership = []; | |
| 29 | - protected ?array $defaultTypes = null; | |
| 35 | + /** | |
| 36 | + * @var Php | |
| 37 | + */ | |
| 38 | + protected $php; | |
| 30 | 39 | |
| 31 | 40 | /** |
| 41 | + * @var Wordpress | |
| 42 | + */ | |
| 43 | + protected $wordpress; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @var Database | |
| 47 | + */ | |
| 48 | + protected $database; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @var MainConfig | |
| 52 | + */ | |
| 53 | + protected $config; | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * @var Util | |
| 57 | + */ | |
| 58 | + protected $util; | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * @var ObjectHandler | |
| 62 | + */ | |
| 63 | + protected $objectHandler; | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * @var ObjectMembershipHandlerFactory | |
| 67 | + */ | |
| 68 | + protected $membershipHandlerFactory; | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * @var AssignmentInformationFactory | |
| 72 | + */ | |
| 73 | + protected $assignmentInformationFactory; | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * @var string | |
| 77 | + */ | |
| 78 | + protected $id = null; | |
| 79 | + | |
| 80 | + /** | |
| 81 | + * @var string | |
| 82 | + */ | |
| 83 | + protected $type = null; | |
| 84 | + | |
| 85 | + /** | |
| 86 | + * @var string | |
| 87 | + */ | |
| 88 | + protected $name = null; | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * @var string | |
| 92 | + */ | |
| 93 | + protected $description = null; | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * @var string | |
| 97 | + */ | |
| 98 | + protected $readAccess = 'group'; | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * @var string | |
| 102 | + */ | |
| 103 | + protected $writeAccess = 'group'; | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * @var bool | |
| 107 | + */ | |
| 108 | + protected $ignoreDates = false; | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * @var array | |
| 112 | + */ | |
| 113 | + protected $assignedObjects = []; | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * @var array | |
| 117 | + */ | |
| 118 | + protected $objectMembership = []; | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * @var array | |
| 122 | + */ | |
| 123 | + protected $fullObjectMembership = []; | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * @var array|null | |
| 127 | + */ | |
| 128 | + protected $defaultTypes = null; | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * AbstractUserGroup constructor. | |
| 132 | + * | |
| 133 | + * @param Php $php | |
| 134 | + * @param Wordpress $wordpress | |
| 135 | + * @param Database $database | |
| 136 | + * @param MainConfig $config | |
| 137 | + * @param Util $util | |
| 138 | + * @param ObjectHandler $objectHandler | |
| 139 | + * @param AssignmentInformationFactory $assignmentInformationFactory | |
| 140 | + * @param null|string $id | |
| 141 | + * | |
| 32 | 142 | * @throws UserGroupTypeException |
| 33 | 143 | */ |
| 34 | 144 | public function __construct( |
| 35 | - protected Php $php, | |
| 36 | - protected Wordpress $wordpress, | |
| 37 | - protected Database $database, | |
| 38 | - protected MainConfig $config, | |
| 39 | - protected Util $util, | |
| 40 | - protected ObjectHandler $objectHandler, | |
| 41 | - protected AssignedObjectsLoader $assignedObjectsLoader, | |
| 42 | - protected int|string|null $id = null | |
| 145 | + Php $php, | |
| 146 | + Wordpress $wordpress, | |
| 147 | + Database $database, | |
| 148 | + MainConfig $config, | |
| 149 | + Util $util, | |
| 150 | + ObjectHandler $objectHandler, | |
| 151 | + AssignmentInformationFactory $assignmentInformationFactory, | |
| 152 | + $id = null | |
| 43 | 153 | ) { |
| 44 | 154 | if ($this->type === null) { |
| 45 | 155 | throw new UserGroupTypeException('User group type must not null.'); |
| 46 | 156 | } |
| 157 | + | |
| 158 | + $this->php = $php; | |
| 159 | + $this->wordpress = $wordpress; | |
| 160 | + $this->database = $database; | |
| 161 | + $this->config = $config; | |
| 162 | + $this->util = $util; | |
| 163 | + $this->objectHandler = $objectHandler; | |
| 164 | + $this->assignmentInformationFactory = $assignmentInformationFactory; | |
| 165 | + $this->id = $id; | |
| 47 | 166 | } |
| 48 | 167 | |
| 49 | - public function getId(): int|string|null | |
| 168 | + /* | |
| 169 | + * Primary values. | |
| 170 | + */ | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * Returns the group _iId. | |
| 174 | + * | |
| 175 | + * @return string | |
| 176 | + */ | |
| 177 | + public function getId() | |
| 50 | 178 | { |
| 51 | 179 | return $this->id; |
| 52 | 180 | } |
| 53 | 181 | |
| 54 | - public function getType(): ?string | |
| 182 | + /** | |
| 183 | + * Returns the user group type. | |
| 184 | + * | |
| 185 | + * @return string | |
| 186 | + */ | |
| 187 | + public function getType() | |
| 55 | 188 | { |
| 56 | 189 | return $this->type; |
| 57 | 190 | } |
| 58 | 191 | |
| 59 | - public function getName(): ?string | |
| 192 | + /** | |
| 193 | + * Returns the group name. | |
| 194 | + * | |
| 195 | + * @return string | |
| 196 | + */ | |
| 197 | + public function getName() | |
| 60 | 198 | { |
| 61 | 199 | return $this->name; |
| 62 | 200 | } |
| 63 | 201 | |
| 64 | - public function setName(string $name): void | |
| 202 | + /** | |
| 203 | + * Sets the group name. | |
| 204 | + * | |
| 205 | + * @param string $name The new group name. | |
| 206 | + */ | |
| 207 | + public function setName($name) | |
| 65 | 208 | { |
| 66 | 209 | $this->name = $name; |
| 67 | 210 | } |
| 68 | 211 | |
| 69 | - public function getDescription(): ?string | |
| 212 | + /** | |
| 213 | + * Returns the group description. | |
| 214 | + * | |
| 215 | + * @return string | |
| 216 | + */ | |
| 217 | + public function getDescription() | |
| 70 | 218 | { |
| 71 | 219 | return $this->description; |
| 72 | 220 | } |
| 73 | 221 | |
| 74 | - public function setDescription(string $description): void | |
| 222 | + /** | |
| 223 | + * Sets the group description. | |
| 224 | + * | |
| 225 | + * @param string $description The new group description. | |
| 226 | + */ | |
| 227 | + public function setDescription($description) | |
| 75 | 228 | { |
| 76 | 229 | $this->description = $description; |
| 77 | 230 | } |
| 78 | 231 | |
| 79 | - public function getReadAccess(): string | |
| 232 | + /** | |
| 233 | + * Returns the read access. | |
| 234 | + * | |
| 235 | + * @return string | |
| 236 | + */ | |
| 237 | + public function getReadAccess() | |
| 80 | 238 | { |
| 81 | 239 | return $this->readAccess; |
| 82 | 240 | } |
| 83 | 241 | |
| 84 | - public function setReadAccess(string $readAccess): void | |
| 242 | + /** | |
| 243 | + * Sets the read access. | |
| 244 | + * | |
| 245 | + * @param string $readAccess The read access. | |
| 246 | + */ | |
| 247 | + public function setReadAccess($readAccess) | |
| 85 | 248 | { |
| 86 | 249 | $this->readAccess = $readAccess; |
| 87 | 250 | } |
| 88 | 251 | |
| 89 | - public function getWriteAccess(): string | |
| 252 | + /** | |
| 253 | + * Returns the write access. | |
| 254 | + * | |
| 255 | + * @return string | |
| 256 | + */ | |
| 257 | + public function getWriteAccess() | |
| 90 | 258 | { |
| 91 | 259 | return $this->writeAccess; |
| 92 | 260 | } |
| 93 | 261 | |
| 94 | - public function setWriteAccess(string $writeAccess): void | |
| 262 | + /** | |
| 263 | + * Sets the write access. | |
| 264 | + * | |
| 265 | + * @param string $writeAccess The write access. | |
| 266 | + */ | |
| 267 | + public function setWriteAccess($writeAccess) | |
| 95 | 268 | { |
| 96 | 269 | $this->writeAccess = $writeAccess; |
| 97 | 270 | } |
| 98 | 271 | |
| 99 | - public function setIgnoreDates(bool $ignoreDates): void | |
| 272 | + /** | |
| 273 | + * Sets the ignore dates flag. | |
| 274 | + * | |
| 275 | + * @param bool $ignoreDates | |
| 276 | + */ | |
| 277 | + public function setIgnoreDates($ignoreDates) | |
| 100 | 278 | { |
| 101 | 279 | if ($this->ignoreDates !== $ignoreDates) { |
| 102 | 280 | $this->resetObjects(); |
| 103 | 281 | } |
| @@ -104,30 +282,24 @@ | ||
| 104 | 282 | |
| 105 | 283 | $this->ignoreDates = $ignoreDates; |
| 106 | 284 | } |
| 107 | 285 | |
| 108 | - public function getIgnoreDates(): bool | |
| 286 | + /** | |
| 287 | + * Resets the objects | |
| 288 | + */ | |
| 289 | + protected function resetObjects() | |
| 109 | 290 | { |
| 110 | - return $this->ignoreDates; | |
| 111 | - } | |
| 112 | - | |
| 113 | - protected function resetObjects(): void | |
| 114 | - { | |
| 115 | 291 | $this->assignedObjects = []; |
| 116 | 292 | $this->objectMembership = []; |
| 117 | 293 | $this->fullObjectMembership = []; |
| 118 | 294 | } |
| 119 | 295 | |
| 120 | - private function resetObjectsAfterAssignmentChange(): void | |
| 121 | - { | |
| 122 | - $this->assignedObjectsLoader->flush(); | |
| 123 | - $this->resetObjects(); | |
| 124 | - } | |
| 125 | - | |
| 126 | 296 | /** |
| 127 | - * @throws Exception | |
| 297 | + * Deletes the user group. | |
| 298 | + * | |
| 299 | + * @return bool | |
| 128 | 300 | */ |
| 129 | - public function delete(): bool | |
| 301 | + public function delete() | |
| 130 | 302 | { |
| 131 | 303 | $allObjectTypes = $this->objectHandler->getAllObjectTypes(); |
| 132 | 304 | |
| 133 | 305 | foreach ($allObjectTypes as $objectType) { |
| @@ -137,11 +309,18 @@ | ||
| 137 | 309 | return true; |
| 138 | 310 | } |
| 139 | 311 | |
| 140 | 312 | /** |
| 141 | - * @throws Exception | |
| 313 | + * Adds a object of the given type. | |
| 314 | + * | |
| 315 | + * @param string $objectType The object type. | |
| 316 | + * @param string $objectId The object id. | |
| 317 | + * @param string $fromDate From date. | |
| 318 | + * @param string $toDate To date. | |
| 319 | + * | |
| 320 | + * @return bool | |
| 142 | 321 | */ |
| 143 | - public function addObject(string $objectType, int|string|null $objectId, $fromDate = null, $toDate = null): bool | |
| 322 | + public function addObject($objectType, $objectId, $fromDate = null, $toDate = null) | |
| 144 | 323 | { |
| 145 | 324 | $generalObjectType = $this->objectHandler->getGeneralObjectType($objectType); |
| 146 | 325 | |
| 147 | 326 | if ($generalObjectType === null |
| @@ -172,9 +351,9 @@ | ||
| 172 | 351 | ] |
| 173 | 352 | ); |
| 174 | 353 | |
| 175 | 354 | if ($return !== false) { |
| 176 | - $this->resetObjectsAfterAssignmentChange(); | |
| 355 | + $this->resetObjects(); | |
| 177 | 356 | return true; |
| 178 | 357 | } |
| 179 | 358 | |
| 180 | 359 | return false; |
| @@ -180,11 +359,17 @@ | ||
| 180 | 359 | return false; |
| 181 | 360 | } |
| 182 | 361 | |
| 183 | 362 | /** |
| 184 | - * @throws Exception | |
| 363 | + * Removes a object of the given type. | |
| 364 | + * | |
| 365 | + * @param string $objectType The object type. | |
| 366 | + * @param string $objectId The object id. | |
| 367 | + * @param bool $ignoreGeneralType | |
| 368 | + * | |
| 369 | + * @return bool | |
| 185 | 370 | */ |
| 186 | - public function removeObject(string $objectType, $objectId = null, bool $ignoreGeneralType = false): bool | |
| 371 | + public function removeObject($objectType, $objectId = null, $ignoreGeneralType = false) | |
| 187 | 372 | { |
| 188 | 373 | $generalObjectType = $this->objectHandler->getGeneralObjectType($objectType); |
| 189 | 374 | |
| 190 | 375 | if ($generalObjectType === null |
| @@ -207,9 +392,9 @@ | ||
| 207 | 392 | |
| 208 | 393 | $query = "DELETE FROM {$this->database->getUserGroupToObjectTable()} |
| 209 | 394 | WHERE group_id = %d |
| 210 | 395 | AND group_type = '%s' |
| 211 | - $objectTypeQuery"; | |
| 396 | + {$objectTypeQuery}"; | |
| 212 | 397 | |
| 213 | 398 | if ($objectId !== null) { |
| 214 | 399 | $query .= ' AND object_id = %d'; |
| 215 | 400 | $values[] = $objectId; |
| @@ -218,9 +403,9 @@ | ||
| 218 | 403 | $query = $this->database->prepare($query, $values); |
| 219 | 404 | $success = ($this->database->query($query) !== false); |
| 220 | 405 | |
| 221 | 406 | if ($success === true) { |
| 222 | - $this->resetObjectsAfterAssignmentChange(); | |
| 407 | + $this->resetObjects(); | |
| 223 | 408 | } |
| 224 | 409 | |
| 225 | 410 | return $success; |
| 226 | 411 | } |
| @@ -225,19 +410,45 @@ | ||
| 225 | 410 | return $success; |
| 226 | 411 | } |
| 227 | 412 | |
| 228 | 413 | /** |
| 414 | + * Returns the assigned objects. | |
| 415 | + * | |
| 416 | + * @param string $objectType The object type. | |
| 417 | + * | |
| 229 | 418 | * @return AssignmentInformation[] |
| 230 | 419 | */ |
| 231 | - public function getAssignedObjects(string $objectType): array | |
| 420 | + public function getAssignedObjects($objectType) | |
| 232 | 421 | { |
| 233 | 422 | if (isset($this->assignedObjects[$objectType]) === false) { |
| 234 | - $this->assignedObjects[$objectType] = $this->assignedObjectsLoader->getAssignedObjects( | |
| 423 | + $query = "SELECT object_id AS id, object_type AS objectType, from_date AS fromDate, to_date AS toDate | |
| 424 | + FROM {$this->database->getUserGroupToObjectTable()} | |
| 425 | + WHERE group_id = '%s' | |
| 426 | + AND group_type = '%s' | |
| 427 | + AND object_id != '' | |
| 428 | + AND (general_object_type = '%s' OR object_type = '%s')"; | |
| 429 | + | |
| 430 | + $parameters = [ | |
| 431 | + $this->id, | |
| 235 | 432 | $this->type, |
| 236 | - $this->id, | |
| 237 | 433 | $objectType, |
| 238 | - $this->ignoreDates | |
| 239 | - ); | |
| 434 | + $objectType | |
| 435 | + ]; | |
| 436 | + | |
| 437 | + if ($this->ignoreDates === false) { | |
| 438 | + $query .= " AND (from_date IS NULL OR from_date <= '%s') AND (to_date IS NULL OR to_date >= '%s')"; | |
| 439 | + $time = $this->wordpress->currentTime('mysql'); | |
| 440 | + $parameters = array_merge($parameters, [$time, $time]); | |
| 441 | + } | |
| 442 | + | |
| 443 | + $query = $this->database->prepare($query, $parameters); | |
| 444 | + $results = (array)$this->database->getResults($query); | |
| 445 | + $this->assignedObjects[$objectType] = []; | |
| 446 | + | |
| 447 | + foreach ($results as $result) { | |
| 448 | + $this->assignedObjects[$objectType][$result->id] = $this->assignmentInformationFactory | |
| 449 | + ->createAssignmentInformation($result->objectType, $result->fromDate, $result->toDate); | |
| 450 | + } | |
| 240 | 451 | } |
| 241 | 452 | |
| 242 | 453 | return $this->assignedObjects[$objectType]; |
| 243 | 454 | } |
| @@ -242,15 +453,18 @@ | ||
| 242 | 453 | return $this->assignedObjects[$objectType]; |
| 243 | 454 | } |
| 244 | 455 | |
| 245 | 456 | /** |
| 246 | - * @throws Exception | |
| 457 | + * Marks the group as default for the object type. | |
| 458 | + * | |
| 459 | + * @param string $objectType | |
| 460 | + * @param null|int $fromTime | |
| 461 | + * @param null|int $toTime | |
| 462 | + * | |
| 463 | + * @return bool | |
| 247 | 464 | */ |
| 248 | - public function addDefaultType( | |
| 249 | - string $objectType, | |
| 250 | - int|string|null $fromTime = null, | |
| 251 | - int|string|null $toTime = null | |
| 252 | - ): bool { | |
| 465 | + public function addDefaultType($objectType, $fromTime = null, $toTime = null) | |
| 466 | + { | |
| 253 | 467 | $fromDate = ($fromTime !== null) ? gmdate('Y-m-d H:i:s', $fromTime) : null; |
| 254 | 468 | $toTime = ($toTime !== null && $toTime <= $fromTime) ? $fromTime + 1 : $toTime; |
| 255 | 469 | $toDate = ($toTime !== null) ? gmdate('Y-m-d H:i:s', $toTime) : null; |
| 256 | 470 | |
| @@ -257,16 +471,25 @@ | ||
| 257 | 471 | return $this->addObject($objectType, '', $fromDate, $toDate); |
| 258 | 472 | } |
| 259 | 473 | |
| 260 | 474 | /** |
| 261 | - * @throws Exception | |
| 475 | + * Removes the group as default for object type. | |
| 476 | + * | |
| 477 | + * @param string $objectType | |
| 478 | + * | |
| 479 | + * @return bool | |
| 262 | 480 | */ |
| 263 | - public function removeDefaultType(string $objectType): bool | |
| 481 | + public function removeDefaultType($objectType) | |
| 264 | 482 | { |
| 265 | 483 | return $this->removeObject($objectType, '', true); |
| 266 | 484 | } |
| 267 | 485 | |
| 268 | - public function getDefaultGroupForObjectTypes(): ?array | |
| 486 | + /** | |
| 487 | + * Returns the object type for which the user group is the default group. | |
| 488 | + * | |
| 489 | + * @return array | |
| 490 | + */ | |
| 491 | + public function getDefaultGroupForObjectTypes() | |
| 269 | 492 | { |
| 270 | 493 | if ($this->defaultTypes === null) { |
| 271 | 494 | $this->defaultTypes = []; |
| 272 | 495 | |
| @@ -281,9 +504,9 @@ | ||
| 281 | 504 | $this->type |
| 282 | 505 | ]; |
| 283 | 506 | |
| 284 | 507 | $query = $this->database->prepare($query, $parameters); |
| 285 | - $results = (array) $this->database->getResults($query); | |
| 508 | + $results = (array)$this->database->getResults($query); | |
| 286 | 509 | |
| 287 | 510 | foreach ($results as $result) { |
| 288 | 511 | $this->defaultTypes[$result->objectType] = [ |
| 289 | 512 | ($result->fromDate !== null) ? strtotime($result->fromDate) : null, |
| @@ -294,9 +517,18 @@ | ||
| 294 | 517 | |
| 295 | 518 | return $this->defaultTypes; |
| 296 | 519 | } |
| 297 | 520 | |
| 298 | - public function isDefaultGroupForObjectType(string $objectType, ?int &$fromTime = null, ?int &$toTime = null): bool | |
| 521 | + /** | |
| 522 | + * Checks if the group is the default one for the given object type. | |
| 523 | + * | |
| 524 | + * @param string $objectType | |
| 525 | + * @param null|int $fromTime | |
| 526 | + * @param null|int $toTime | |
| 527 | + * | |
| 528 | + * @return bool | |
| 529 | + */ | |
| 530 | + public function isDefaultGroupForObjectType($objectType, &$fromTime = null, &$toTime = null) | |
| 299 | 531 | { |
| 300 | 532 | $defaultGroupForObjectTypes = $this->getDefaultGroupForObjectTypes(); |
| 301 | 533 | |
| 302 | 534 | // Reset reference values anyway |
| @@ -304,11 +536,11 @@ | ||
| 304 | 536 | $toTime = null; |
| 305 | 537 | |
| 306 | 538 | if (isset($defaultGroupForObjectTypes[$objectType])) { |
| 307 | 539 | $fromTime = $defaultGroupForObjectTypes[$objectType][0] !== null ? |
| 308 | - (int) $defaultGroupForObjectTypes[$objectType][0] : null; | |
| 540 | + (int)$defaultGroupForObjectTypes[$objectType][0] : null; | |
| 309 | 541 | $toTime = $defaultGroupForObjectTypes[$objectType][1] !== null ? |
| 310 | - (int) $defaultGroupForObjectTypes[$objectType][1] : null; | |
| 542 | + (int)$defaultGroupForObjectTypes[$objectType][1] : null; | |
| 311 | 543 | |
| 312 | 544 | return true; |
| 313 | 545 | } |
| 314 | 546 | |
| @@ -314,13 +546,22 @@ | ||
| 314 | 546 | |
| 315 | 547 | return false; |
| 316 | 548 | } |
| 317 | 549 | |
| 550 | + /** | |
| 551 | + * Checks if the object is assigned to the group. | |
| 552 | + * | |
| 553 | + * @param string $objectType The object type. | |
| 554 | + * @param string $objectId The object id. | |
| 555 | + * @param AssignmentInformation|null $assignmentInformation The assignment information object. | |
| 556 | + * | |
| 557 | + * @return bool | |
| 558 | + */ | |
| 318 | 559 | public function isObjectAssignedToGroup( |
| 319 | - string $objectType, | |
| 320 | - int|string|null $objectId, | |
| 321 | - ?AssignmentInformation &$assignmentInformation = null | |
| 322 | - ): bool { | |
| 560 | + $objectType, | |
| 561 | + $objectId, | |
| 562 | + &$assignmentInformation = null | |
| 563 | + ) { | |
| 323 | 564 | $assignmentInformation = null; |
| 324 | 565 | $assignedObjects = $this->getAssignedObjects($objectType); |
| 325 | 566 | |
| 326 | 567 | if (isset($assignedObjects[$objectId]) === true) { |
| @@ -331,15 +572,21 @@ | ||
| 331 | 572 | return false; |
| 332 | 573 | } |
| 333 | 574 | |
| 334 | 575 | /** |
| 335 | - * @throws Exception | |
| 576 | + * Returns a single object. | |
| 577 | + * | |
| 578 | + * @param string $objectType The object type. | |
| 579 | + * @param string $objectId The id of the object which should be checked. | |
| 580 | + * @param AssignmentInformation $assignmentInformation The assignment information | |
| 581 | + * | |
| 582 | + * @return bool | |
| 336 | 583 | */ |
| 337 | 584 | public function isObjectMember( |
| 338 | - string $objectType, | |
| 339 | - int|string|null $objectId, | |
| 340 | - ?AssignmentInformation &$assignmentInformation = null | |
| 341 | - ): bool { | |
| 585 | + $objectType, | |
| 586 | + $objectId, | |
| 587 | + &$assignmentInformation = null | |
| 588 | + ) { | |
| 342 | 589 | if (isset($this->objectMembership[$objectType][$objectId]) === false) { |
| 343 | 590 | try { |
| 344 | 591 | $isMember = $this->objectHandler->getObjectMembershipHandler($objectType)->isMember( |
| 345 | 592 | $this, |
| @@ -346,9 +593,9 @@ | ||
| 346 | 593 | $this->config->lockRecursive(), |
| 347 | 594 | $objectId, |
| 348 | 595 | $assignmentInformation |
| 349 | 596 | ); |
| 350 | - } catch (MissingObjectMembershipHandlerException) { | |
| 597 | + } catch (MissingObjectMembershipHandlerException $exception) { | |
| 351 | 598 | $isMember = false; |
| 352 | 599 | } |
| 353 | 600 | |
| 354 | 601 | $this->objectMembership[$objectType][$objectId] = ($isMember === true) ? |
| @@ -361,43 +608,68 @@ | ||
| 361 | 608 | return ($this->objectMembership[$objectType][$objectId] !== false); |
| 362 | 609 | } |
| 363 | 610 | |
| 364 | 611 | /** |
| 365 | - * @throws Exception | |
| 612 | + * Checks if the role is a group member. | |
| 613 | + * | |
| 614 | + * @param string $roleId | |
| 615 | + * @param AssignmentInformation $assignmentInformation | |
| 616 | + * | |
| 617 | + * @return bool | |
| 366 | 618 | */ |
| 367 | - public function isRoleMember(int|string|null $roleId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 619 | + public function isRoleMember($roleId, &$assignmentInformation = null) | |
| 368 | 620 | { |
| 369 | 621 | return $this->isObjectMember(ObjectHandler::GENERAL_ROLE_OBJECT_TYPE, $roleId, $assignmentInformation); |
| 370 | 622 | } |
| 371 | 623 | |
| 372 | 624 | /** |
| 373 | - * @throws Exception | |
| 625 | + * Checks if the user is a group member. | |
| 626 | + * | |
| 627 | + * @param int $userId The user id. | |
| 628 | + * @param AssignmentInformation $assignmentInformation The assignment information. | |
| 629 | + * | |
| 630 | + * @return bool | |
| 374 | 631 | */ |
| 375 | - public function isUserMember(int|string|null $userId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 632 | + public function isUserMember($userId, &$assignmentInformation = null) | |
| 376 | 633 | { |
| 377 | 634 | return $this->isObjectMember(ObjectHandler::GENERAL_USER_OBJECT_TYPE, $userId, $assignmentInformation); |
| 378 | 635 | } |
| 379 | 636 | |
| 380 | 637 | /** |
| 381 | - * @throws Exception | |
| 638 | + * Checks if the term is a group member. | |
| 639 | + * | |
| 640 | + * @param int $termId | |
| 641 | + * @param AssignmentInformation $assignmentInformation | |
| 642 | + * | |
| 643 | + * @return bool | |
| 382 | 644 | */ |
| 383 | - public function isTermMember(int|string|null $termId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 645 | + public function isTermMember($termId, &$assignmentInformation = null) | |
| 384 | 646 | { |
| 385 | 647 | return $this->isObjectMember(ObjectHandler::GENERAL_TERM_OBJECT_TYPE, $termId, $assignmentInformation); |
| 386 | 648 | } |
| 387 | 649 | |
| 388 | 650 | /** |
| 389 | - * @throws Exception | |
| 651 | + * Checks if the post is a group member | |
| 652 | + * | |
| 653 | + * @param int $postId | |
| 654 | + * @param AssignmentInformation $assignmentInformation | |
| 655 | + * | |
| 656 | + * @return bool | |
| 390 | 657 | */ |
| 391 | - public function isPostMember(int|string|null $postId, ?AssignmentInformation &$assignmentInformation = null): bool | |
| 658 | + public function isPostMember($postId, &$assignmentInformation = null) | |
| 392 | 659 | { |
| 393 | 660 | return $this->isObjectMember(ObjectHandler::GENERAL_POST_OBJECT_TYPE, $postId, $assignmentInformation); |
| 394 | 661 | } |
| 395 | 662 | |
| 396 | 663 | /** |
| 397 | - * @throws Exception | |
| 664 | + * Returns the recursive membership. | |
| 665 | + * | |
| 666 | + * @param string $objectType The object type. | |
| 667 | + * @param string $objectId The object id. | |
| 668 | + * | |
| 669 | + * @return array | |
| 398 | 670 | */ |
| 399 | - public function getRecursiveMembershipForObject(string $objectType, int|string|null $objectId): array | |
| 671 | + public function getRecursiveMembershipForObject($objectType, $objectId) | |
| 400 | 672 | { |
| 401 | 673 | /** |
| 402 | 674 | * @var AssignmentInformation $assignmentInformation |
| 403 | 675 | */ |
| @@ -408,11 +680,16 @@ | ||
| 408 | 680 | return []; |
| 409 | 681 | } |
| 410 | 682 | |
| 411 | 683 | /** |
| 412 | - * @throws Exception | |
| 684 | + * Returns true if the requested object is locked recursive. | |
| 685 | + * | |
| 686 | + * @param string $objectType The object type. | |
| 687 | + * @param string $objectId The object id. | |
| 688 | + * | |
| 689 | + * @return bool | |
| 413 | 690 | */ |
| 414 | - public function isLockedRecursive(string $objectType, int|string|null $objectId): bool | |
| 691 | + public function isLockedRecursive($objectType, $objectId) | |
| 415 | 692 | { |
| 416 | 693 | /** |
| 417 | 694 | * @var AssignmentInformation $assignmentInformation |
| 418 | 695 | */ |
| @@ -423,11 +700,15 @@ | ||
| 423 | 700 | return false; |
| 424 | 701 | } |
| 425 | 702 | |
| 426 | 703 | /** |
| 427 | - * @throws Exception | |
| 704 | + * Returns all objects of the given type. | |
| 705 | + * | |
| 706 | + * @param string $objectType The object type. | |
| 707 | + * | |
| 708 | + * @return array | |
| 428 | 709 | */ |
| 429 | - public function getAssignedObjectsByType(string $objectType): array | |
| 710 | + public function getAssignedObjectsByType($objectType) | |
| 430 | 711 | { |
| 431 | 712 | if (isset($this->fullObjectMembership[$objectType]) === false) { |
| 432 | 713 | try { |
| 433 | 714 | $handler = $this->objectHandler->getObjectMembershipHandler($objectType); |
| @@ -435,9 +716,9 @@ | ||
| 435 | 716 | $this, |
| 436 | 717 | $this->config->lockRecursive(), |
| 437 | 718 | ($objectType === $this->objectHandler->getGeneralObjectType($objectType)) ? null : $objectType |
| 438 | 719 | ); |
| 439 | - } catch (MissingObjectMembershipHandlerException) { | |
| 720 | + } catch (MissingObjectMembershipHandlerException $exception) { | |
| 440 | 721 | $this->fullObjectMembership[$objectType] = []; |
| 441 | 722 | } |
| 442 | 723 | } |
| 443 | 724 | |
| @@ -444,11 +725,13 @@ | ||
| 444 | 725 | return $this->fullObjectMembership[$objectType]; |
| 445 | 726 | } |
| 446 | 727 | |
| 447 | 728 | /** |
| 448 | - * @throws Exception | |
| 729 | + * Returns the roles assigned to the group. | |
| 730 | + * | |
| 731 | + * @return array | |
| 449 | 732 | */ |
| 450 | - public function getFullRoles(): array | |
| 733 | + public function getFullRoles() | |
| 451 | 734 | { |
| 452 | 735 | return $this->getAssignedObjectsByType(ObjectHandler::GENERAL_ROLE_OBJECT_TYPE); |
| 453 | 736 | } |
| 454 | 737 | |
| @@ -453,27 +736,33 @@ | ||
| 453 | 736 | } |
| 454 | 737 | |
| 455 | 738 | |
| 456 | 739 | /** |
| 457 | - * @throws Exception | |
| 740 | + * Returns the users assigned to the group. | |
| 741 | + * | |
| 742 | + * @return array | |
| 458 | 743 | */ |
| 459 | - public function getFullUsers(): array | |
| 744 | + public function getFullUsers() | |
| 460 | 745 | { |
| 461 | 746 | return $this->getAssignedObjectsByType(ObjectHandler::GENERAL_USER_OBJECT_TYPE); |
| 462 | 747 | } |
| 463 | 748 | |
| 464 | 749 | /** |
| 465 | - * @throws Exception | |
| 750 | + * Returns the terms assigned to the group. | |
| 751 | + * | |
| 752 | + * @return array | |
| 466 | 753 | */ |
| 467 | - public function getFullTerms(): array | |
| 754 | + public function getFullTerms() | |
| 468 | 755 | { |
| 469 | 756 | return $this->getAssignedObjectsByType(ObjectHandler::GENERAL_TERM_OBJECT_TYPE); |
| 470 | 757 | } |
| 471 | 758 | |
| 472 | 759 | /** |
| 473 | - * @throws Exception | |
| 760 | + * Returns the posts assigned to the group. | |
| 761 | + * | |
| 762 | + * @return array | |
| 474 | 763 | */ |
| 475 | - public function getFullPosts(): array | |
| 764 | + public function getFullPosts() | |
| 476 | 765 | { |
| 477 | 766 | return $this->getAssignedObjectsByType(ObjectHandler::GENERAL_POST_OBJECT_TYPE); |
| 478 | 767 | } |
| 479 | 768 | } |