示例#1
0
 /**
  * Recursive template of branch of menu
  *
  * @param array $row
  *
  * @return mixed|string
  */
 public function templateBranch($row = array())
 {
     $children = '';
     $row['level'] = $this->level;
     if (!empty($row['children']) && ($this->isHere($row['id']) || empty($this->pdoTools->config['hideSubMenus'])) && $this->checkResource($row['id'])) {
         $idx = 1;
         $this->level++;
         $count = count($row['children']);
         foreach ($row['children'] as $v) {
             $v['idx'] = $idx++;
             $v['last'] = (int) $v['idx'] == $count;
             $children .= $this->templateBranch($v);
         }
         $this->level--;
         $row['children'] = $count;
     } else {
         $row['children'] = isset($row['children']) ? count($row['children']) : 0;
     }
     if (!empty($this->pdoTools->config['countChildren'])) {
         if ($ids = $this->modx->getChildIds($row['id'])) {
             $tstart = microtime(true);
             $count = $this->modx->getCount('modResource', array('id:IN' => $ids, 'published' => true, 'deleted' => false));
             $this->modx->queryTime += microtime(true) - $tstart;
             $this->modx->executedQueries++;
             $this->pdoTools->addTime('Got the number of active children for resource "' . $row['id'] . '": ' . $count);
         } else {
             $count = 0;
         }
         $row['children'] = $count;
     }
     if (!empty($children)) {
         $pls = $this->addWayFinderPlaceholders(array('wrapper' => $children, 'classes' => ' class="' . $this->pdoTools->config['innerClass'] . '"', 'classNames' => $this->pdoTools->config['innerClass'], 'classnames' => $this->pdoTools->config['innerClass'], 'level' => $this->level));
         $row['wrapper'] = $this->pdoTools->parseChunk($this->pdoTools->config['tplInner'], $pls);
     } else {
         $row['wrapper'] = '';
     }
     if (empty($row['menutitle']) && !empty($row['pagetitle'])) {
         $row['menutitle'] = $row['pagetitle'];
     }
     $classes = $this->getClasses($row);
     if (!empty($classes)) {
         $row['classNames'] = $row['classnames'] = $classes;
         $row['classes'] = ' class="' . $classes . '"';
     } else {
         $row['classNames'] = $row['classnames'] = $row['classes'] = '';
     }
     if (!empty($this->pdoTools->config['useWeblinkUrl']) && $row['class_key'] == 'modWebLink') {
         $row['link'] = is_numeric(trim($row['content'], '[]~ ')) ? $this->modx->makeUrl(intval(trim($row['content'], '[]~ ')), '', '', $this->pdoTools->config['scheme']) : $row['content'];
     } else {
         $row['link'] = $this->modx->makeUrl($row['id'], $row['context_key'], '', $this->pdoTools->config['scheme']);
     }
     $row['title'] = !empty($this->pdoTools->config['titleOfLinks']) ? $row[$this->pdoTools->config['titleOfLinks']] : '';
     $tpl = $this->getTpl($row);
     $row = $this->addWayFinderPlaceholders($row);
     return $this->pdoTools->getChunk($tpl, $row, $this->pdoTools->config['fastMode']);
 }
 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;
 }
 public function __construct(modX &$modx, $scriptProperties = array())
 {
     $this->modx =& $modx;
     $modx->addPackage('msrevaluation', MODX_BASE_PATH . 'core/components/msrevaluation/model/');
     $this->config = $scriptProperties;
     $this->config['assets_path'] = $modx->getOption('assets_path') . 'components/msrevaluation/';
     $this->config['core_path'] = $modx->getOption('core_path') . 'components/msrevaluation/';
     $this->config['assets_url'] = $modx->getOption('assets_url') . 'components/msrevaluation/';
     $this->config['core_url'] = $modx->getOption('base_url') . 'core/components/msrevaluation/';
     $this->config['connectorUrl'] = $this->config['assets_url'] . 'connector.php';
     $protectedResources = array_merge(explode(',', $modx->getOption('protected_parents')), explode(',', $modx->getOption('protect_from_revaluation')));
     $this->config['protected'] = array();
     foreach ($protectedResources as $parent) {
         if (!($parent = (int) trim($parent))) {
             continue;
         }
         $childs = $modx->getChildIds($parent, 5, array('context' => 'web'));
         $this->config['protected'] = array_merge($this->config['protected'], $childs, array($parent));
     }
     return true;
 }
示例#4
0
 /**
  * @param null $id
  * @param int $depth
  * @param array $options
  *
  * @return array
  */
 public function getChildIds($id = null, $depth = 10, array $options = array())
 {
     return $this->modx->getChildIds($id, $depth, $options);
 }