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