-
-
Save Fi1osof/0270fc42847badc8fa41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function findPolicy($context = '') { | |
$policy = array(); | |
$enabled = true; | |
$context = !empty($context) ? $context : $this->xpdo->context->get('key'); | |
if ($context === $this->xpdo->context->get('key')) { | |
$enabled = (boolean) $this->xpdo->getOption('access_resource_group_enabled', null, true); | |
} elseif ($this->xpdo->getContext($context)) { | |
$enabled = (boolean) $this->xpdo->contexts[$context]->getOption('access_resource_group_enabled', true); | |
} | |
if ($enabled) { | |
if (empty($this->_policies) || !isset($this->_policies[$context])) { | |
$accessTable = $this->xpdo->getTableName('modAccessResourceGroup'); | |
$policyTable = $this->xpdo->getTableName('modAccessPolicy'); | |
$resourceGroupTable = $this->xpdo->getTableName('modResourceGroupResource'); | |
$sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " . | |
"LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " . | |
"JOIN {$resourceGroupTable} ResourceGroup ON Acl.principal_class = 'modUserGroup' " . | |
"AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " . | |
"AND ResourceGroup.document = :resource " . | |
"AND ResourceGroup.document_group = Acl.target " . | |
"GROUP BY Acl.target, Acl.principal, Acl.authority, Acl.policy"; | |
$bindings = array( | |
':resource' => $this->get('id'), | |
':context' => $context | |
); | |
$query = new xPDOCriteria($this->xpdo, $sql, $bindings); | |
if ($query->stmt && $query->stmt->execute()) { | |
while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) { | |
$policy['modAccessResourceGroup'][$row['target']][] = array( | |
'principal' => $row['principal'], | |
'authority' => $row['authority'], | |
'policy' => $row['data'] ? $this->xpdo->fromJSON($row['data'], true) : array(), | |
); | |
} | |
} | |
$this->_policies[$context] = $policy; | |
} else { | |
$policy = $this->_policies[$context]; | |
} | |
} | |
return $policy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment