| 1 |
<?php |
| 2 |
/** |
| 3 |
* MembershipWithMapHandler.php |
| 4 |
* |
| 5 |
* The MembershipWithMapHandler 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\ObjectMapHandler; |
| 18 |
use UserAccessManager\UserGroup\AbstractUserGroup; |
| 19 |
use UserAccessManager\UserGroup\AssignmentInformation; |
| 20 |
|
| 21 |
/** |
| 22 |
* Class MembershipWithMapHandler |
| 23 |
* |
| 24 |
* @package UserAccessManager\UserGroup |
| 25 |
*/ |
| 26 |
abstract class ObjectMembershipWithMapHandler extends ObjectMembershipHandler |
| 27 |
{ |
| 28 |
/** |
| 29 |
* Returns the map. |
| 30 |
* |
| 31 |
* @return array |
| 32 |
*/ |
| 33 |
abstract protected function getMap(); |
| 34 |
|
| 35 |
/** |
| 36 |
* Uses a map function to resolve the recursive membership. |
| 37 |
* |
| 38 |
* @param AbstractUserGroup $userGroup |
| 39 |
* @param bool $lockRecursive |
| 40 |
* @param string $objectId |
| 41 |
* @param null|AssignmentInformation $assignmentInformation |
| 42 |
* |
| 43 |
* @return bool |
| 44 |
*/ |
| 45 |
protected function getMembershipByMap( |
| 46 |
AbstractUserGroup $userGroup, |
| 47 |
$lockRecursive, |
| 48 |
$objectId, |
| 49 |
&$assignmentInformation = null |
| 50 |
) { |
| 51 |
// Reset value to prevent errors |
| 52 |
$recursiveMembership = []; |
| 53 |
|
| 54 |
if ($lockRecursive === true) { |
| 55 |
$map = $this->getMap(); |
| 56 |
$generalMap = isset($map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType]) ? |
| 57 |
$map[ObjectMapHandler::TREE_MAP_PARENTS][$this->generalObjectType] : []; |
| 58 |
|
| 59 |
if (isset($generalMap[$objectId]) === true) { |
| 60 |
foreach ($generalMap[$objectId] as $parentId => $type) { |
| 61 |
$isAssignedToGroup = $userGroup->isObjectAssignedToGroup( |
| 62 |
$this->generalObjectType, |
| 63 |
$parentId, |
| 64 |
$rmAssignmentInformation |
| 65 |
); |
| 66 |
|
| 67 |
if ($isAssignedToGroup === true) { |
| 68 |
$recursiveMembership[$this->generalObjectType][$parentId] = $rmAssignmentInformation; |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
$isMember = $userGroup->isObjectAssignedToGroup($this->generalObjectType, $objectId, $assignmentInformation); |
| 75 |
return $this->checkAccessWithRecursiveMembership($isMember, $recursiveMembership, $assignmentInformation); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Returns the objects by the given type including the children. |
| 80 |
* |
| 81 |
* @param AbstractUserGroup $userGroup |
| 82 |
* @param bool $lockRecursive |
| 83 |
* @param string $objectType |
| 84 |
* |
| 85 |
* @return array |
| 86 |
*/ |
| 87 |
protected function getFullObjectsByMap(AbstractUserGroup $userGroup, $lockRecursive, $objectType) |
| 88 |
{ |
| 89 |
$objects = $this->getSimpleAssignedObjects($userGroup, $objectType); |
| 90 |
|
| 91 |
if ($lockRecursive === true) { |
| 92 |
$map = $this->getMap(); |
| 93 |
$map = isset($map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType]) ? |
| 94 |
$map[ObjectMapHandler::TREE_MAP_CHILDREN][$objectType] : []; |
| 95 |
$map = array_intersect_key($map, $objects); |
| 96 |
|
| 97 |
foreach ($map as $childrenIds) { |
| 98 |
foreach ($childrenIds as $parentId => $type) { |
| 99 |
if ($userGroup->isObjectMember($objectType, $parentId) === true) { |
| 100 |
$objects[$parentId] = $type; |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
return $objects; |
| 107 |
} |
| 108 |
} |
| 109 |
|