PluginProbe
User Access Manager / 2.2.11
User Access Manager v2.2.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
user-access-manager / src / ObjectMembership / TermMembershipHandler.php

TermMembershipHandler.php in User Access Manager 2.2.11, at src/ObjectMembership/TermMembershipHandler.php

146 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * TermMembershipHandler.php
4 *
5 * The TermMembershipHandler 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 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\ObjectMembership;
19
20 use Exception;
21 use UserAccessManager\Object\ObjectHandler;
22 use UserAccessManager\Object\ObjectMapHandler;
23 use UserAccessManager\UserGroup\AbstractUserGroup;
24 use UserAccessManager\UserGroup\AssignmentInformation;
25 use UserAccessManager\UserGroup\AssignmentInformationFactory;
26 use UserAccessManager\Wrapper\Wordpress;
27
28 /**
29 * Class TermMembershipHandler
30 *
31 * @package UserAccessManager\UserGroup
32 */
33 class TermMembershipHandler extends ObjectMembershipWithMapHandler
34 {
35 /**
36 * @var string
37 */
38 protected $generalObjectType = ObjectHandler::GENERAL_TERM_OBJECT_TYPE;
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 * TermMembershipHandler constructor.
57 * @param AssignmentInformationFactory $assignmentInformationFactory
58 * @param Wordpress $wordpress
59 * @param ObjectHandler $objectHandler
60 * @param ObjectMapHandler $objectMapHandler
61 * @throws Exception
62 */
63 public function __construct(
64 AssignmentInformationFactory $assignmentInformationFactory,
65 Wordpress $wordpress,
66 ObjectHandler $objectHandler,
67 ObjectMapHandler $objectMapHandler
68 ) {
69 parent::__construct($assignmentInformationFactory);
70
71 $this->wordpress = $wordpress;
72 $this->objectHandler = $objectHandler;
73 $this->objectMapHandler = $objectMapHandler;
74 }
75
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 = '')
83 {
84 $term = $this->objectHandler->getTerm($objectId);
85
86 if ($term !== false) {
87 $taxonomy = $this->wordpress->getTaxonomy($term->taxonomy);
88 $typeName = ($taxonomy !== false) ? $taxonomy->labels->name : $typeName;
89 return $term->name;
90 }
91
92 return $objectId;
93 }
94
95 /**
96 * Returns the handled objects.
97 * @return array
98 */
99 public function getHandledObjects(): array
100 {
101 $keys = array_keys($this->objectHandler->getTaxonomies());
102 return array_merge(parent::getHandledObjects(), array_combine($keys, $keys));
103 }
104
105 /**
106 * Returns the map.
107 * @return array
108 */
109 protected function getMap(): array
110 {
111 return $this->objectMapHandler->getTermTreeMap();
112 }
113
114 /**
115 * Checks if the term is a member of the user group.
116 * @param AbstractUserGroup $userGroup
117 * @param bool $lockRecursive
118 * @param int|string $objectId
119 * @param null|AssignmentInformation $assignmentInformation
120 * @return bool
121 * @throws Exception
122 */
123 public function isMember(
124 AbstractUserGroup $userGroup,
125 bool $lockRecursive,
126 $objectId,
127 ?AssignmentInformation &$assignmentInformation = null
128 ): bool {
129 return $this->getMembershipByMap($userGroup, $lockRecursive, $objectId, $assignmentInformation);
130 }
131
132 /**
133 * Returns the term role objects.
134 * @param AbstractUserGroup $userGroup
135 * @param bool $lockRecursive
136 * @param null $objectType
137 * @return array
138 * @throws Exception
139 */
140 public function getFullObjects(AbstractUserGroup $userGroup, bool $lockRecursive, $objectType = null): array
141 {
142 $objectType = ($objectType === null) ? $this->generalObjectType : $objectType;
143 return $this->getFullObjectsByMap($userGroup, $lockRecursive, $objectType);
144 }
145 }
146