PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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/ObjectMembership/PostMembershipHandler.php +102 -21 2.3.16 → 2.1.11 View file →
@@ -1,11 +1,20 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * PostMembershipHandler.php
4 + *
5 + * The PostMembershipHandler 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\Object\ObjectMapHandler;
10 19 use UserAccessManager\UserGroup\AbstractUserGroup;
11 20 use UserAccessManager\UserGroup\AssignmentInformation;
@@ -11,22 +20,67 @@
11 20 use UserAccessManager\UserGroup\AssignmentInformation;
12 21 use UserAccessManager\UserGroup\AssignmentInformationFactory;
13 22 use UserAccessManager\Wrapper\Wordpress;
14 23
24 +/**
25 + * Class PostMembershipHandler
26 + *
27 + * @package UserAccessManager\UserGroup
28 + */
15 29 class PostMembershipHandler extends ObjectMembershipWithMapHandler
16 30 {
17 - protected ?string $generalObjectType = ObjectHandler::GENERAL_POST_OBJECT_TYPE;
31 + /**
32 + * @var string
33 + */
34 + protected $generalObjectType = ObjectHandler::GENERAL_POST_OBJECT_TYPE;
18 35
36 + /**
37 + * @var Wordpress
38 + */
39 + private $wordpress;
40 +
41 + /**
42 + * @var ObjectHandler
43 + */
44 + private $objectHandler;
45 +
46 + /**
47 + * @var ObjectMapHandler
48 + */
49 + private $objectMapHandler;
50 +
51 + /**
52 + * PostMembershipHandler constructor.
53 + *
54 + * @param AssignmentInformationFactory $assignmentInformationFactory
55 + * @param Wordpress $wordpress
56 + * @param ObjectHandler $objectHandler
57 + * @param ObjectMapHandler $objectMapHandler
58 + *
59 + * @throws \Exception
60 + */
19 61 public function __construct(
20 62 AssignmentInformationFactory $assignmentInformationFactory,
21 - private Wordpress $wordpress,
22 - private ObjectHandler $objectHandler,
23 - private ObjectMapHandler $objectMapHandler
63 + Wordpress $wordpress,
64 + ObjectHandler $objectHandler,
65 + ObjectMapHandler $objectMapHandler
24 66 ) {
25 67 parent::__construct($assignmentInformationFactory);
68 +
69 + $this->wordpress = $wordpress;
70 + $this->objectHandler = $objectHandler;
71 + $this->objectMapHandler = $objectMapHandler;
26 72 }
27 73
28 - public function getObjectName(int|string|null $objectId, string &$typeName = ''): int|string
74 + /**
75 + * Returns the object and type name.
76 + *
77 + * @param string $objectId
78 + * @param string $typeName
79 + *
80 + * @return string
81 + */
82 + public function getObjectName($objectId, &$typeName = '')
29 83 {
30 84 $post = $this->objectHandler->getPost($objectId);
31 85
32 86 if ($post !== false) {
@@ -37,27 +91,41 @@
37 91
38 92 return $objectId;
39 93 }
40 94
41 - public function getHandledObjects(): array
95 + /**
96 + * Returns the handled objects.
97 + *
98 + * @return array
99 + */
100 + public function getHandledObjects()
42 101 {
43 102 $keys = array_keys($this->objectHandler->getPostTypes());
44 103 return array_merge(parent::getHandledObjects(), array_combine($keys, $keys));
45 104 }
46 105
47 - protected function getMap(): array
106 + /**
107 + * Returns the map.
108 + *
109 + * @return array
110 + */
111 + protected function getMap()
48 112 {
49 113 return $this->objectMapHandler->getPostTreeMap();
50 114 }
51 115
52 116 /**
53 - * @throws Exception
117 + * Assigns the recursive member ship by the group terms.
118 + *
119 + * @param AbstractUserGroup $userGroup
120 + * @param string $objectId
121 + * @param array $recursiveMembership
54 122 */
55 123 private function assignRecursiveMembershipByTerm(
56 124 AbstractUserGroup $userGroup,
57 - int|string|null $objectId,
125 + $objectId,
58 126 array &$recursiveMembership
59 - ): void {
127 + ) {
60 128 $postTermMap = $this->objectMapHandler->getPostTermMap();
61 129
62 130 if (isset($postTermMap[$objectId]) === true) {
63 131 foreach ($postTermMap[$objectId] as $termId => $type) {
@@ -68,16 +136,23 @@
68 136 }
69 137 }
70 138
71 139 /**
72 - * @throws Exception
140 + * Checks if the post is a member of the user group.
141 + *
142 + * @param AbstractUserGroup $userGroup
143 + * @param bool $lockRecursive
144 + * @param string $objectId
145 + * @param null|AssignmentInformation $assignmentInformation
146 + *
147 + * @return bool
73 148 */
74 149 public function isMember(
75 150 AbstractUserGroup $userGroup,
76 - bool $lockRecursive,
77 - int|string|null $objectId,
78 - ?AssignmentInformation &$assignmentInformation = null
79 - ): bool {
151 + $lockRecursive,
152 + $objectId,
153 + &$assignmentInformation = null
154 + ) {
80 155 $isMember = $this->getMembershipByMap($userGroup, $lockRecursive, $objectId, $assignmentInformation);
81 156
82 157 if ($lockRecursive === true) {
83 158 $recursiveMembership = ($assignmentInformation !== null) ?
@@ -91,11 +166,17 @@
91 166 return $isMember;
92 167 }
93 168
94 169 /**
95 - * @throws Exception
170 + * Returns the full post objects.
171 + *
172 + * @param AbstractUserGroup $userGroup
173 + * @param bool $lockRecursive
174 + * @param null|string $objectType
175 + *
176 + * @return array
96 177 */
97 - public function getFullObjects(AbstractUserGroup $userGroup, bool $lockRecursive, ?string $objectType = null): array
178 + public function getFullObjects(AbstractUserGroup $userGroup, $lockRecursive, $objectType = null)
98 179 {
99 180 $objectType = ($objectType === null) ? $this->generalObjectType : $objectType;
100 181 $posts = $this->getFullObjectsByMap($userGroup, $lockRecursive, $objectType);
101 182