/**
  * Tests to see if an alias is a duplicate.
  *
  * @param string $aliasPath The current full alias path. If none is passed,
  * will build it from the Resource's currently set alias.
  * @param string $contextKey The context to search for a duplicate alias in.
  * @return mixed The ID of the Resource using the alias, if a duplicate, otherwise false.
  */
 public function isDuplicateAlias($aliasPath = '', $contextKey = '')
 {
     if (empty($aliasPath)) {
         $aliasPath = $this->getAliasPath($this->get('alias'));
     }
     $criteria = $this->xpdo->newQuery('modResource');
     $where = array('id:!=' => $this->get('id'), 'uri' => $aliasPath, 'deleted' => false, 'published' => true);
     if (!empty($contextKey)) {
         $where['context_key'] = $contextKey;
     }
     $criteria->select('id');
     $criteria->where($where);
     $criteria->prepare();
     $duplicate = $this->xpdo->getValue($criteria->stmt);
     return $duplicate > 0 ? (int) $duplicate : false;
 }
Exemple #2
0
}
if (!defined('MODX_API_MODE')) {
    define('MODX_API_MODE', true);
}
$resource_id = !empty($_GET['page_id']) && is_numeric($_GET['page_id']) ? $_GET['page_id'] : 1;
$output = array('prod_list' => '', 'pages' => '', 'total' => 0, 'pageCount' => 1, 'onPageLimit' => 1);
require_once '../../../config.core.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx = new modX();
//get resourse context_key
$context_key = 'web';
$query = $modx->newQuery('modResource', array('id' => $resource_id, 'published' => true, 'deleted' => false));
$query->select($modx->getSelectColumns('modResource', '', '', array('context_key')));
$stmt = $query->prepare();
if ($stmt) {
    if ($value = $modx->getValue($stmt)) {
        $context_key = $value;
    }
}
$modx->initialize($context_key);
//get resource
$criteria = $modx->newQuery('modResource');
$criteria->select(array($modx->escape('modResource') . '.*'));
$criteria->where(array('id' => $resource_id, 'deleted' => false, 'published' => true));
$modx->resource = $modx->getObject('modResource', $criteria);
if (!is_object($modx->resource) || !$modx->resource->checkPolicy('view')) {
    echo json_encode($output);
    exit;
}
$modx->resourceIdentifier = $modx->resource->get('id');
$modx->getService('error', 'error.modError');