| @@ -1,11 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -declare(strict_types=1); | |
| 4 | - | |
| 2 | +/** | |
| 3 | + * RoleMembershipHandler.php | |
| 4 | + * | |
| 5 | + * The RoleMembershipHandler 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\ObjectMembership; |
| 6 | 16 | |
| 7 | -use Exception; | |
| 8 | 17 | use UserAccessManager\Object\ObjectHandler; |
| 9 | 18 | use UserAccessManager\UserGroup\AbstractUserGroup; |
| 10 | 19 | use UserAccessManager\UserGroup\AssignmentInformation; |
| 11 | 20 | use UserAccessManager\UserGroup\AssignmentInformationFactory; |
| @@ -10,23 +19,48 @@ | ||
| 10 | 19 | use UserAccessManager\UserGroup\AssignmentInformation; |
| 11 | 20 | use UserAccessManager\UserGroup\AssignmentInformationFactory; |
| 12 | 21 | use UserAccessManager\Wrapper\Wordpress; |
| 13 | 22 | |
| 23 | +/** | |
| 24 | + * Class RoleMembershipHandler | |
| 25 | + * | |
| 26 | + * @package UserAccessManager\UserGroup | |
| 27 | + */ | |
| 14 | 28 | class RoleMembershipHandler extends ObjectMembershipHandler |
| 15 | 29 | { |
| 16 | - protected ?string $generalObjectType = ObjectHandler::GENERAL_ROLE_OBJECT_TYPE; | |
| 30 | + /** | |
| 31 | + * @var Wordpress | |
| 32 | + */ | |
| 33 | + private $wordpress; | |
| 17 | 34 | |
| 18 | 35 | /** |
| 19 | - * @throws Exception | |
| 36 | + * @var string | |
| 20 | 37 | */ |
| 21 | - public function __construct( | |
| 22 | - AssignmentInformationFactory $assignmentInformationFactory, | |
| 23 | - private Wordpress $wordpress | |
| 24 | - ) { | |
| 38 | + protected $generalObjectType = ObjectHandler::GENERAL_ROLE_OBJECT_TYPE; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * RoleMembershipHandler constructor. | |
| 42 | + * | |
| 43 | + * @param AssignmentInformationFactory $assignmentInformationFactory | |
| 44 | + * @param Wordpress $wordpress | |
| 45 | + * | |
| 46 | + * @throws \Exception | |
| 47 | + */ | |
| 48 | + public function __construct(AssignmentInformationFactory $assignmentInformationFactory, Wordpress $wordpress) | |
| 49 | + { | |
| 25 | 50 | parent::__construct($assignmentInformationFactory); |
| 51 | + $this->wordpress = $wordpress; | |
| 26 | 52 | } |
| 27 | 53 | |
| 28 | - public function getObjectName(int|string|null $objectId, string &$typeName = ''): int|string | |
| 54 | + /** | |
| 55 | + * Returns the object and type name. | |
| 56 | + * | |
| 57 | + * @param string $objectId | |
| 58 | + * @param string $typeName | |
| 59 | + * | |
| 60 | + * @return string | |
| 61 | + */ | |
| 62 | + public function getObjectName($objectId, &$typeName = '') | |
| 29 | 63 | { |
| 30 | 64 | $typeName = $this->generalObjectType; |
| 31 | 65 | $roles = $this->wordpress->getRoles()->role_names; |
| 32 | 66 | return (isset($roles[$objectId]) === true) ? $roles[$objectId] : $objectId; |
| @@ -31,14 +65,20 @@ | ||
| 31 | 65 | $roles = $this->wordpress->getRoles()->role_names; |
| 32 | 66 | return (isset($roles[$objectId]) === true) ? $roles[$objectId] : $objectId; |
| 33 | 67 | } |
| 34 | 68 | |
| 35 | - public function isMember( | |
| 36 | - AbstractUserGroup $userGroup, | |
| 37 | - bool $lockRecursive, | |
| 38 | - int|string|null $objectId, | |
| 39 | - ?AssignmentInformation &$assignmentInformation = null | |
| 40 | - ): bool { | |
| 69 | + /** | |
| 70 | + * Checks if the role is a member of the user group. | |
| 71 | + * | |
| 72 | + * @param AbstractUserGroup $userGroup | |
| 73 | + * @param bool $lockRecursive | |
| 74 | + * @param string $objectId | |
| 75 | + * @param null|AssignmentInformation $assignmentInformation | |
| 76 | + * | |
| 77 | + * @return bool | |
| 78 | + */ | |
| 79 | + public function isMember(AbstractUserGroup $userGroup, $lockRecursive, $objectId, &$assignmentInformation = null) | |
| 80 | + { | |
| 41 | 81 | $isMember = $userGroup->isObjectAssignedToGroup( |
| 42 | 82 | $this->generalObjectType, |
| 43 | 83 | $objectId, |
| 44 | 84 | $assignmentInformation |
| @@ -47,9 +87,18 @@ | ||
| 47 | 87 | |
| 48 | 88 | return $isMember; |
| 49 | 89 | } |
| 50 | 90 | |
| 51 | - public function getFullObjects(AbstractUserGroup $userGroup, bool $lockRecursive, $objectType = null): array | |
| 91 | + /** | |
| 92 | + * Returns the full role objects. | |
| 93 | + * | |
| 94 | + * @param AbstractUserGroup $userGroup | |
| 95 | + * @param bool $lockRecursive | |
| 96 | + * @param null $objectType | |
| 97 | + * | |
| 98 | + * @return array | |
| 99 | + */ | |
| 100 | + public function getFullObjects(AbstractUserGroup $userGroup, $lockRecursive, $objectType = null) | |
| 52 | 101 | { |
| 53 | 102 | $objectType = ($objectType === null) ? $this->generalObjectType : $objectType; |
| 54 | 103 | |
| 55 | 104 | return $this->getSimpleAssignedObjects($userGroup, $objectType); |