/** * 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 = $this->pdoTools->idx; $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->pdoTools->makeUrl(intval(trim($row['content'], '[]~ ')), $row) : $row['content']; } else { $row['link'] = $this->pdoTools->makeUrl($row['id'], $row); } $row['title'] = !empty($this->pdoTools->config['titleOfLinks']) ? $row[$this->pdoTools->config['titleOfLinks']] : $row['pagetitle']; $tpl = $this->getTpl($row); $row = $this->addWayFinderPlaceholders($row); return $this->pdoTools->getChunk($tpl, $row, $this->pdoTools->config['fastMode']); }