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