| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace UserAccessManager\ObjectMembership; |
| 6 |
|
| 7 |
use Exception; |
| 8 |
use UserAccessManager\Object\ObjectHandler; |
| 9 |
use UserAccessManager\Object\ObjectMapHandler; |
| 10 |
use UserAccessManager\UserGroup\AbstractUserGroup; |
| 11 |
use UserAccessManager\UserGroup\AssignmentInformation; |
| 12 |
use UserAccessManager\UserGroup\AssignmentInformationFactory; |
| 13 |
use UserAccessManager\Wrapper\Wordpress; |
| 14 |
|
| 15 |
class TermMembershipHandler extends ObjectMembershipWithMapHandler |
| 16 |
{ |
| 17 |
protected ?string $generalObjectType = ObjectHandler::GENERAL_TERM_OBJECT_TYPE; |
| 18 |
|
| 19 |
public function __construct( |
| 20 |
AssignmentInformationFactory $assignmentInformationFactory, |
| 21 |
private Wordpress $wordpress, |
| 22 |
private ObjectHandler $objectHandler, |
| 23 |
private ObjectMapHandler $objectMapHandler |
| 24 |
) { |
| 25 |
parent::__construct($assignmentInformationFactory); |
| 26 |
} |
| 27 |
|
| 28 |
public function getObjectName(int|string $objectId, string &$typeName = ''): int|string |
| 29 |
{ |
| 30 |
$term = $this->objectHandler->getTerm($objectId); |
| 31 |
|
| 32 |
if ($term !== false) { |
| 33 |
$taxonomy = $this->wordpress->getTaxonomy($term->taxonomy); |
| 34 |
$typeName = ($taxonomy !== false) ? $taxonomy->labels->name : $typeName; |
| 35 |
return $term->name; |
| 36 |
} |
| 37 |
|
| 38 |
return $objectId; |
| 39 |
} |
| 40 |
|
| 41 |
public function getHandledObjects(): array |
| 42 |
{ |
| 43 |
$keys = array_keys($this->objectHandler->getTaxonomies()); |
| 44 |
return array_merge(parent::getHandledObjects(), array_combine($keys, $keys)); |
| 45 |
} |
| 46 |
|
| 47 |
protected function getMap(): array |
| 48 |
{ |
| 49 |
return $this->objectMapHandler->getTermTreeMap(); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* @throws Exception |
| 54 |
*/ |
| 55 |
public function isMember( |
| 56 |
AbstractUserGroup $userGroup, |
| 57 |
bool $lockRecursive, |
| 58 |
int|string $objectId, |
| 59 |
?AssignmentInformation &$assignmentInformation = null |
| 60 |
): bool { |
| 61 |
return $this->getMembershipByMap($userGroup, $lockRecursive, $objectId, $assignmentInformation); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @throws Exception |
| 66 |
*/ |
| 67 |
public function getFullObjects(AbstractUserGroup $userGroup, bool $lockRecursive, $objectType = null): array |
| 68 |
{ |
| 69 |
$objectType = ($objectType === null) ? $this->generalObjectType : $objectType; |
| 70 |
return $this->getFullObjectsByMap($userGroup, $lockRecursive, $objectType); |
| 71 |
} |
| 72 |
} |
| 73 |
|