本文整理汇总了PHP中modX::fromJSON方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::fromJSON方法的具体用法?PHP modX::fromJSON怎么用?PHP modX::fromJSON使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::fromJSON方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadAttributes
/**
* Load the attributes for the ACLs for the context
*
* @static
* @param modX $modx A reference to the modX instance
* @param string $context The context to load from. If empty, will use the current context.
* @param int $userId The ID of the user to grab ACL records for.
* @return array An array of loaded attributes
*/
public static function loadAttributes(&$modx, $context = '', $userId = 0)
{
$attributes = array();
$accessTable = $modx->getTableName('modAccessNamespace');
$policyTable = $modx->getTableName('modAccessPolicy');
$memberTable = $modx->getTableName('modUserGroupMember');
$memberRoleTable = $modx->getTableName('modUserGroupRole');
if ($userId > 0) {
$sql = "SELECT acl.target, acl.principal, mr.authority, acl.policy, p.data FROM {$accessTable} acl " . "LEFT JOIN {$policyTable} p ON p.id = acl.policy " . "JOIN {$memberTable} mug ON acl.principal_class = 'modUserGroup' " . "AND mug.member = :principal " . "AND mug.user_group = acl.principal " . "JOIN {$memberRoleTable} mr ON mr.id = mug.role " . "AND mr.authority <= acl.authority " . "ORDER BY acl.target, acl.principal, mr.authority, acl.policy";
$bindings = array(':principal' => $userId);
$query = new xPDOCriteria($modx, $sql, $bindings);
if ($query->stmt && $query->stmt->execute()) {
while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
$attributes[$row['target']][] = array('principal' => $row['principal'], 'authority' => $row['authority'], 'policy' => $row['data'] ? $modx->fromJSON($row['data'], true) : array());
}
}
} else {
$sql = "SELECT acl.target, acl.principal, 0 AS authority, acl.policy, p.data FROM {$accessTable} acl " . "LEFT JOIN {$policyTable} p ON p.id = acl.policy " . "WHERE acl.principal_class = 'modUserGroup' " . "AND acl.principal = 0 " . "ORDER BY acl.target, acl.principal, acl.authority, acl.policy";
$query = new xPDOCriteria($modx, $sql);
if ($query->stmt && $query->stmt->execute()) {
while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
$attributes[$row['target']][] = array('principal' => 0, 'authority' => $row['authority'], 'policy' => $row['data'] ? $modx->fromJSON($row['data'], true) : array());
}
}
}
return $attributes;
}
示例2: install
protected function install($packagesDir, $dir, $packagesBaseUrl, OutputInterface $output)
{
$configContent = $this->modx->fromJSON(file_get_contents($packagesDir . $dir . '/_build/config.json'));
$this->config = new Config($this->modx, $dir);
$this->config->parseConfig($configContent);
$this->packageCorePath = $packagesDir . $dir . "/core/components/" . $this->config->getLowCaseName() . "/";
$this->packageCorePath = str_replace('\\', '/', $this->packageCorePath);
$this->packageAssetsPath = $packagesDir . $dir . "/assets/components/" . $this->config->getLowCaseName() . "/";
$this->packageAssetsPath = str_replace('\\', '/', $this->packageAssetsPath);
$this->packageAssetsUrl = $packagesBaseUrl . $dir . '/assets/components/' . $this->config->getLowCaseName() . '/';
$this->createNamespace();
$this->createMenusAndActions();
$this->createSystemSettings($packagesDir, $packagesBaseUrl);
$this->createTables();
$this->clearCache();
/** @var \GitPackage $packageObject */
$packageObject = $this->modx->newObject('GitPackage');
$packageObject->set('version', $this->config->getVersion());
$packageObject->set('description', $this->config->getDescription());
$packageObject->set('author', $this->config->getAuthor());
$packageObject->set('name', $this->config->getName());
$packageObject->set('dir_name', $dir);
$packageObject->set('config', $this->modx->toJSON($configContent));
$packageObject->save();
}
示例3: prepareRow
/**
* Allow user to prepare single row by custom snippet before render chunk
* This method was developed in cooperation with Agel_Nash
*
* @param array $row
*
* @return array
*/
public function prepareRow($row = array())
{
if ($this->preparing) {
return $row;
}
if (!empty($this->config['prepareSnippet'])) {
$this->preparing = true;
$name = trim($this->config['prepareSnippet']);
array_walk_recursive($row, function (&$value) {
$value = str_replace(array('[', ']', '{', '}'), array('*(*(*(*(*(*', '*)*)*)*)*)*', '~(~(~(~(~(~', '~)~)~)~)~)~'), $value);
});
$tmp = $this->runSnippet($name, array('pdoTools' => $this, 'pdoFetch' => $this, 'row' => $row));
$tmp = $tmp[0] == '[' || $tmp[0] == '{' ? $this->modx->fromJSON($tmp, 1) : unserialize($tmp);
if (!is_array($tmp)) {
$this->addTime('Preparation snippet must return an array, instead of "' . gettype($tmp) . '"');
} else {
$row = array_merge($row, $tmp);
}
$this->preparing = false;
array_walk_recursive($row, function (&$value) {
$value = str_replace(array('*(*(*(*(*(*', '*)*)*)*)*)*', '~(~(~(~(~(~', '~)~)~)~)~)~'), array('[', ']', '{', '}'), $value);
});
}
return $row;
}
示例4: prepareRow
/**
* Allow user to prepare single row by custom snippet before render chunk
* This method was developed in cooperation with Agel_Nash
*
* @param array $row
*
* @return array
*/
public function prepareRow($row = array())
{
if ($this->preparing) {
return $row;
}
if (!empty($this->config['prepareSnippet'])) {
$this->preparing = true;
$name = trim($this->config['prepareSnippet']);
/** @var modSnippet $snippet */
if (!($snippet = $this->getStore($name, 'snippet'))) {
if ($snippet = $this->modx->getObject('modSnippet', array('name' => $name))) {
$this->setStore($name, $snippet, 'snippet');
} else {
$this->addTime('Could not load snippet "' . $name . '" for preparation of row.');
return '';
}
}
$snippet->_cacheable = false;
$snippet->_processed = false;
$tmp = $snippet->process(array('pdoTools' => $this, 'pdoFetch' => $this, 'row' => $row));
$tmp = $tmp[0] == '[' || $tmp[0] == '{' ? $this->modx->fromJSON($tmp, 1) : unserialize($tmp);
if (!is_array($tmp)) {
$this->addTime('Preparation snippet must return an array, instead of "' . gettype($tmp) . '"');
} else {
$row = array_merge($row, $tmp);
}
$this->preparing = false;
}
return $row;
}
示例5: redirect
/**
* Redirect to a specified URL.
*
* Properties needed:
* - redirectTo - the ID of the Resource to redirect to.
*
* @param array $fields An array of cleaned POST fields
* @return boolean False if unsuccessful.
*/
public function redirect(array $fields = array())
{
if (empty($this->formit->config['redirectTo'])) {
return false;
}
$redirectParams = !empty($this->formit->config['redirectParams']) ? $this->formit->config['redirectParams'] : '';
if (!empty($redirectParams)) {
$prefix = $this->modx->getOption('placeholderPrefix', $this->formit->config, 'fi.');
$this->modx->setPlaceholders($fields, $prefix);
$this->modx->parser->processElementTags('', $redirectParams, true, true);
$redirectParams = $this->modx->fromJSON($redirectParams);
if (empty($redirectParams)) {
$redirectParams = '';
}
}
$contextKey = $this->modx->context->get('key');
$resource = $this->modx->getObject('modResource', $this->formit->config['redirectTo']);
if ($resource) {
$contextKey = $resource->get('context_key');
}
if (!is_numeric($this->formit->config['redirectTo']) && isset($fields[$this->formit->config['redirectTo']]) && is_numeric($fields[$this->formit->config['redirectTo']])) {
$url = $this->modx->makeUrl($fields[$this->formit->config['redirectTo']], $contextKey, $redirectParams, 'full');
} elseif (!is_numeric($this->formit->config['redirectTo']) && substr($this->formit->config['redirectTo'], 0, 4) === "http") {
$url = $this->formit->config['redirectTo'];
} else {
$url = $this->modx->makeUrl($this->formit->config['redirectTo'], $contextKey, $redirectParams, 'full');
}
$this->setRedirectUrl($url);
return true;
}
示例6: getContainerSettings
/**
* Get an array of settings for the container.
* @return array
*/
public function getContainerSettings()
{
$settings = $this->getProperties('articles');
if (!empty($settings)) {
$settings = is_array($settings) ? $settings : $this->xpdo->fromJSON($settings);
}
return !empty($settings) ? $settings : array();
}
示例7: array
/**
* PDFresource constructor
*
* @param modX $modx A reference to the modX instance.
* @param array $options An array of options. Optional.
*/
function __construct(modX &$modx, array $options = array())
{
$this->modx =& $modx;
$corePath = $this->getOption('core_path', $options, $this->modx->getOption('core_path') . 'components/' . $this->namespace . '/');
$assetsPath = $this->getOption('assets_path', $options, $this->modx->getOption('assets_path') . 'components/' . $this->namespace . '/');
$assetsUrl = $this->getOption('assets_url', $options, $this->modx->getOption('assets_url') . 'components/' . $this->namespace . '/');
$pdfPath = $this->getOption('pdf_path', $options, $this->modx->getOption('assets_path') . 'pdf/');
$pdfUrl = $this->getOption('pdf_url', $options, $this->modx->getOption('assets_url') . 'pdf/');
// Load some default paths for easier management
$this->options = array_merge(array('namespace' => $this->namespace, 'version' => $this->version, 'assetsPath' => $assetsPath, 'assetsUrl' => $assetsUrl, 'cssUrl' => $assetsUrl . 'css/', 'jsUrl' => $assetsUrl . 'js/', 'imagesUrl' => $assetsUrl . 'images/', 'corePath' => $corePath, 'modelPath' => $corePath . 'model/', 'vendorPath' => $corePath . 'vendor/', 'chunksPath' => $corePath . 'elements/chunks/', 'pagesPath' => $corePath . 'elements/pages/', 'snippetsPath' => $corePath . 'elements/snippets/', 'pluginsPath' => $corePath . 'elements/plugins/', 'controllersPath' => $corePath . 'controllers/', 'processorsPath' => $corePath . 'processors/', 'templatesPath' => $corePath . 'templates/', 'connectorUrl' => $assetsUrl . 'connector.php', 'pdfPath' => $pdfPath, 'pdfUrl' => $pdfUrl), $options);
// Init mPDF options
$mode = $this->modx->getOption('mode', $options, '');
$format = $this->modx->getOption('format', $options, 'A4');
$default_font_size = intval($this->modx->getOption('defaultFontSize', $options, 0));
$default_font = $this->modx->getOption('defaultFont', $options, '');
$mgl = intval($this->modx->getOption('mgl', $options, 15));
$mgr = intval($this->modx->getOption('mgr', $options, 15));
$mgt = intval($this->modx->getOption('mgt', $options, 16));
$mgb = intval($this->modx->getOption('mgb', $options, 16));
$mgh = intval($this->modx->getOption('mgb', $options, 9));
$mgf = intval($this->modx->getOption('mgf', $options, 9));
$orientation = $this->modx->getOption('orientation', $options, 'P');
parent::mPDF($mode, $format, $default_font_size, $default_font, $mgl, $mgr, $mgt, $mgb, $mgh, $mgf, $orientation);
$customFonts = $this->modx->fromJSON($this->modx->getOption('customFonts', $options, ''));
if (is_array($customFonts)) {
foreach ($customFonts as $f => $fs) {
$this->fontdata[$f] = $fs;
if (isset($fs['R']) && $fs['R']) {
$this->available_unifonts[] = $f;
}
if (isset($fs['B']) && $fs['B']) {
$this->available_unifonts[] = $f . 'B';
}
if (isset($fs['I']) && $fs['I']) {
$this->available_unifonts[] = $f . 'I';
}
if (isset($fs['BI']) && $fs['BI']) {
$this->available_unifonts[] = $f . 'BI';
}
}
} else {
$this->modx->log(modX::LOG_LEVEL_ERROR, 'customFonts does not contain an array.', '', 'PDFresource');
}
$this->default_available_fonts = $this->available_unifonts;
}
示例8: getInstance
public static function getInstance(modX &$modx, $className, $properties = array())
{
if (isset($properties['data'])) {
$data = (array) $modx->fromJSON($properties['data']);
$properties = array_merge($properties, $data);
unset($properties['data'], $data);
}
return parent::getInstance($modx, $className, $properties);
}
示例9: loadAttributes
/**
* Load the attributes for the ACLs for the Resource Group
*
* @static
* @param modX $modx A reference to the modX instance
* @param string $context The context to load from. If empty, will use the current context.
* @param int $userId The ID of the user to grab ACL records for.
* @return array An array of loaded attributes
*/
public static function loadAttributes(&$modx, $context = '', $userId = 0)
{
$attributes = array();
if (empty($context)) {
$context = $modx->context->get('key');
}
$enabled = (bool) $modx->getOption('access_resource_group_enabled', null, true);
if ($context !== $modx->context->get('key') && $modx->getContext($context)) {
$enabled = (bool) $modx->contexts[$context]->getOption('access_resource_group_enabled', $enabled);
}
if ($enabled) {
$accessTable = $modx->getTableName('modAccessResourceGroup');
$policyTable = $modx->getTableName('modAccessPolicy');
$memberTable = $modx->getTableName('modUserGroupMember');
$memberRoleTable = $modx->getTableName('modUserGroupRole');
$legacyDocGroups = array();
if ($userId > 0) {
$sql = "SELECT acl.target, acl.principal, mr.authority, acl.policy, p.data FROM {$accessTable} acl " . "LEFT JOIN {$policyTable} p ON p.id = acl.policy " . "JOIN {$memberTable} mug ON acl.principal_class = 'modUserGroup' " . "AND (acl.context_key = :context OR acl.context_key IS NULL OR acl.context_key = '') " . "AND mug.member = :principal " . "AND mug.user_group = acl.principal " . "JOIN {$memberRoleTable} mr ON mr.id = mug.role " . "AND mr.authority <= acl.authority " . "ORDER BY acl.target, acl.principal, mr.authority, acl.policy";
$bindings = array(':principal' => $userId, ':context' => $context);
$query = new xPDOCriteria($modx, $sql, $bindings);
if ($query->stmt && $query->stmt->execute()) {
while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
$attributes[$row['target']][] = array('principal' => $row['principal'], 'authority' => $row['authority'], 'policy' => $row['data'] ? $modx->fromJSON($row['data'], true) : array());
$legacyDocGroups[$row['target']] = $row['target'];
}
}
} else {
$sql = "SELECT acl.target, acl.principal, 0 AS authority, acl.policy, p.data FROM {$accessTable} acl " . "LEFT JOIN {$policyTable} p ON p.id = acl.policy " . "WHERE acl.principal_class = 'modUserGroup' " . "AND acl.principal = 0 " . "AND (acl.context_key = :context OR acl.context_key IS NULL OR acl.context_key = '') " . "ORDER BY acl.target, acl.principal, acl.authority, acl.policy";
$bindings = array(':context' => $context);
$query = new xPDOCriteria($modx, $sql, $bindings);
if ($query->stmt && $query->stmt->execute()) {
while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
$attributes[$row['target']][] = array('principal' => 0, 'authority' => $row['authority'], 'policy' => $row['data'] ? $modx->fromJSON($row['data'], true) : array());
$legacyDocGroups[$row['target']] = $row['target'];
}
}
}
$_SESSION['modx.user.' . ($userId > 0 ? (string) $userId : '0') . '.resourceGroups'] = array($context => array_values($legacyDocGroups));
}
return $attributes;
}
示例10: getOptions
/**
* Get options for reCaptcha from snippet
*
* @param array $scriptProperties
* @return array|void
*/
public function getOptions(array $scriptProperties = array())
{
$opt = $this->modx->getOption('recaptchaJs', $scriptProperties, '{}');
$opt = $this->modx->fromJSON($opt);
if (empty($opt)) {
$opt = array();
}
/* backwards compat */
$backwardOpt = array('theme' => $this->modx->getOption('recaptchaTheme', $scriptProperties, 'clean'), 'width' => $this->modx->getOption('recaptchaWidth', $scriptProperties, 500), 'height' => $this->modx->getOption('recaptchaHeight', $scriptProperties, 300), 'lang' => $this->modx->getOption('cultureKey', null, 'en'));
$opt = array_merge($backwardOpt, $opt);
return $opt;
}
示例11: translate
/**
* Translate a string using a named transliteration table.
*
* @param string $string The string to transliterate.
*
* @return string The translated string.
*/
public function translate($string)
{
$exclude = $this->modx->getOption('friendly_alias_ytranslit_exclude', '', '/^[_-a-zA-z\\d\\s\\:\\(\\)]+$/i', true);
if (empty($string) || preg_match($exclude, $string)) {
return $string;
}
$extension = '';
if (preg_match('#\\.[0-9a-z]+$#i', $string, $matches)) {
$extension = $matches[0];
$string = preg_replace('#' . $extension . '$#', '', $string);
}
$trim = $this->modx->getOption('friendly_alias_trim_chars', null, '/.-_', true);
$string = str_replace(str_split($trim), ' ', $string);
$service = $this->modx->getOption('friendly_alias_ytranslit_url', null, 'https://translate.yandex.net/api/v1.5/tr.json/translate?key=[[+key]]&lang=ru-en&text=', true);
$key = trim($this->modx->getOption('friendly_alias_ytranslit_key', null, ''));
if (empty($key)) {
$this->modx->log(modX::LOG_LEVEL_ERROR, '[yTranslit] You must specify the API key! Please, get it from http://api.yandex.ru/key/form.xml?service=trnsl.');
return $string;
} else {
$request = str_replace('[[+key]]', $key, $service) . urlencode($string);
if (function_exists('curl_init')) {
$url = parse_url($request);
parse_str($url['query'], $params);
/** @var modRestCurlClient $client */
$client = $this->modx->getService('rest.modRestCurlClient');
$result = $client->request($url['scheme'] . '://' . $url['host'], $url['path'], 'GET', $params, array('curlopt_timeout' => $this->modx->getOption('friendly_alias_ytranslit_timeout', null, 1, true), 'curlopt_returntransfer' => 1));
} else {
$result = file_get_contents($request);
}
$arr = $this->modx->fromJSON($result);
if (!is_array($arr)) {
$this->modx->log(modX::LOG_LEVEL_ERROR, "[yTranslit] Service unavailable.\nRequest: {$request}.\nResponse: {$result}");
} elseif ($arr['code'] != 200 || empty($arr['text'][0])) {
$this->modx->log(modX::LOG_LEVEL_ERROR, '[yTranslit] Service returned an error. ' . print_r($arr, true));
} else {
$string = $arr['text'][0];
}
return $string . strtolower($extension);
}
}
示例12: __construct
/**
* Constructor
*/
public function __construct(modX &$modx)
{
$this->modx = $modx;
// require original phpconsole class
$phpconsole_file = dirname(__FILE__) . '/vendor/phpconsole.php';
if (file_exists($phpconsole_file)) {
require_once $phpconsole_file;
} else {
return false;
}
// make sure phpconsole should be enabled
if (!$this->modx->getOption('phpconsole.enabled', null, false)) {
return false;
}
// load config
$this->config = new \Phpconsole\Config();
// set default project
$this->project = $this->modx->getOption('phpconsole.project', null, 'default');
$configSetting = $this->modx->fromJSON($this->modx->getOption('phpconsole.config', null, ''));
if (!empty($configSetting)) {
// load config from system setting
$this->config->loadFromArray($configSetting);
} else {
if (file_exists(MODX_CORE_PATH . 'config/phpconsole-config.inc.php')) {
// load config from file
$this->config->loadFromLocation(MODX_CORE_PATH . 'config/phpconsole-config.inc.php');
} else {
// if no config exists, switch back to the FILE logTarget
$this->modx->setLogTarget('FILE');
return false;
}
}
// initialize phpconsole
$this->phpconsole = new \Phpconsole\Phpconsole($this->config);
// set logTarget to ARRAY_EXTENDED to store all log() calls in an array
$this->modx->setLogTarget(array('target' => 'ARRAY_EXTENDED', 'options' => array('var' => &$this->logArray)));
// register a shoutdown function to log fatal errors in phpconsole
register_shutdown_function('phpconsoleFatalLogger');
}
示例13: formatPrice
/**
* Function for formatting price
*
* @param string $price
*
* @return string $price
*/
public function formatPrice($price = '0')
{
$pf = $this->modx->fromJSON($this->modx->getOption('ms2_price_format', null, '[2, ".", " "]'));
if (is_array($pf)) {
$price = number_format($price, $pf[0], $pf[1], $pf[2]);
}
if ($this->modx->getOption('ms2_price_format_no_zeros', null, true)) {
if (preg_match('/\\..*$/', $price, $matches)) {
$tmp = rtrim($matches[0], '.0');
$price = str_replace($matches[0], $tmp, $price);
}
}
return $price;
}
示例14: getQuery
public function getQuery($currentParent)
{
/* build query */
$c = $this->modx->newQuery('modResource');
$c->leftJoin('modResource', 'Children');
$c->select($this->modx->getSelectColumns('modResource', 'modResource'));
$c->select(array('COUNT(Children.id) AS children'));
$c->where(array('parent' => $currentParent));
/* if restricting to contexts */
if (!empty($this->config['context'])) {
$ctxs = $this->prepareForIn($this->config['context']);
$c->where(array('modResource.context_key:IN' => $ctxs));
} else {
$c->where(array('modResource.context_key' => $this->modx->context->get('key')));
}
/* if excluding resources */
if (!empty($this->config['excludeResources'])) {
$ex = $this->prepareForIn($this->config['excludeResources']);
$c->where(array('modResource.id:NOT IN' => $ex));
}
/* if excluding all children of certain resources */
if (!empty($this->config['excludeChildrenOf'])) {
$excludingParents = is_array($this->config['excludeChildrenOf']) ? $this->config['excludeChildrenOf'] : explode(',', $this->config['excludeChildrenOf']);
$excludedChildren = array();
foreach ($excludingParents as $excludingParent) {
$childrenIds = $this->modx->getChildIds($excludingParent, 10);
$excludedChildren = array_merge($excludedChildren, $childrenIds);
}
$excludedChildren = array_unique($excludedChildren);
$c->where(array('modResource.id:NOT IN' => $excludedChildren));
}
/* if restricting to templates */
if (!empty($this->config['allowedtemplates'])) {
$tpls = $this->prepareForIn($this->config['allowedtemplates']);
$c->innerJoin('modTemplate', 'Template');
$c->where(array('Template.' . $this->config['templateFilter'] . ':IN' => $tpls));
}
/* where filtering */
if (!empty($this->config['where'])) {
$where = is_array($this->config['where']) ? $this->config['where'] : $this->modx->fromJSON($this->config['where']);
$c->where($where);
}
/* sorting/grouping */
$c->sortby($this->config['sortBy'], $this->config['sortDir']);
$c->groupby('modResource.id');
return $c;
}
示例15: findPolicy
/**
* Loads the access control policies applicable to this template variable.
*
* {@inheritdoc}
*/
public function findPolicy($context = '')
{
$policy = array();
$context = !empty($context) ? $context : $this->xpdo->context->get('key');
if ($context === $this->xpdo->context->get('key')) {
$catEnabled = (bool) $this->xpdo->getOption('access_category_enabled', null, true);
$rgEnabled = (bool) $this->xpdo->getOption('access_resource_group_enabled', null, true);
} elseif ($this->xpdo->getContext($context)) {
$catEnabled = (bool) $this->xpdo->contexts[$context]->getOption('access_category_enabled', true);
$rgEnabled = (bool) $this->xpdo->contexts[$context]->getOption('access_resource_group_enabled', true);
}
$enabled = $catEnabled || $rgEnabled;
if ($enabled) {
if (empty($this->_policies) || !isset($this->_policies[$context])) {
if ($rgEnabled) {
$accessTable = $this->xpdo->getTableName('modAccessResourceGroup');
$policyTable = $this->xpdo->getTableName('modAccessPolicy');
$resourceGroupTable = $this->xpdo->getTableName('modTemplateVarResourceGroup');
$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.tmplvarid = :element " . "AND ResourceGroup.documentgroup = Acl.target " . "ORDER BY Acl.target, Acl.principal, Acl.authority";
$bindings = array(':element' => $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());
}
}
}
if ($catEnabled) {
$accessTable = $this->xpdo->getTableName('modAccessCategory');
$categoryClosureTable = $this->xpdo->getTableName('modCategoryClosure');
$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 {$categoryClosureTable} CategoryClosure ON CategoryClosure.descendant = :category " . "AND Acl.principal_class = 'modUserGroup' " . "AND CategoryClosure.ancestor = Acl.target " . "AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " . "ORDER BY CategoryClosure.depth DESC, target, principal, authority ASC";
$bindings = array(':category' => $this->get('category'), ':context' => $context);
$query = new xPDOCriteria($this->xpdo, $sql, $bindings);
if ($query->stmt && $query->stmt->execute()) {
while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
$policy['modAccessCategory'][$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;
}