public function getChildren($p) { $rez = array(); //unset restricted query params from user input unset($p['fq']); /* prepare params */ $path = '/'; if (!isset($p['path']) || strlen($p['path']) < 1) { if (!empty($p['pid'])) { $path = $p['pid']; } } else { $path = $p['path']; } $p['path'] = $path; //check if user have changed the row limit in grid if (!empty($p['setMaxRows']) && !empty($p['rows'])) { User::setGridMaxRows($p['rows']); } //the navigation goes from search results. We should get the real path of the node if (!empty($p['lastQuery']) && empty($p['query'])) { while (substr($path, -1) == '/') { $path = substr($path, 0, strlen($path) - 1); } $a = explode('/', $path); if (!empty($a) && is_numeric($a[sizeof($a) - 1])) { $p['path'] = @Path::getPath(array_pop($a))['path']; } } $this->showFoldersContent = isset($p['showFoldersContent']) ? $p['showFoldersContent'] : false; $this->requestParams = $p; /* end of prepare params */ /* we should: 1. load available plugins for the tree with their configs 2. fire the on treeInitialize event 3. call each plugin with received params 4. join and sort received data */ //detect tree nodes config, //but leave only SearchResults plugin when searching if (empty($p['search'])) { if (empty($p['query'])) { $this->treeNodeConfigs = Config::get('treeNodes'); } // default is only DBNode if nothing defined in cofig if (empty($this->treeNodeConfigs)) { $this->treeNodeConfigs = array('Dbnode' => array()); } } else { $this->treeNodeConfigs = array('SearchResults' => $p['search']); $path = Path::getGUID('SearchResults') . '-'; } $params = array('params' => &$p, 'plugins' => &$this->treeNodeConfigs); fireEvent('treeInitialize', $params); // array of all available classes defined in treeNodes // used to check if any class should add its nodes based // on last node from current path $this->treeNodeClasses = Path::getNodeClasses($this->treeNodeConfigs); foreach ($this->treeNodeClasses as &$nodeClass) { $cfg = $nodeClass->getConfig(); $this->treeNodeGUIDConfigs[$cfg['guid']] = $cfg; } $this->path = Path::createNodesPath($path, $this->treeNodeGUIDConfigs); //set path and input params for last node //because iterating each class and requesting children can //invoke a search that will use last node to get facets and DC if (!empty($this->path)) { $lastNode = $this->path[sizeof($path) - 1]; $lastNode->path = $this->path; $lastNode->requestParams = $this->requestParams; } Cache::set('current_path', $this->path); $this->result = array('data' => array(), 'facets' => array(), 'pivot' => array(), 'search' => array(), 'view' => array(), 'sort' => array(), 'group' => array(), 'stats' => array(), 'DC' => array(), 'total' => 0); //get view config and apply to request params and for result $viewConfig = $this->detectViewConfig(); $this->requestParams = array_merge($this->requestParams, $viewConfig); $this->result = array_merge($this->result, $viewConfig); $this->requestParams['facets'] = $this->detectFacets(); $this->collectAllChildren(); $this->prepareResult(); $rez = array('success' => true, 'pathtext' => $this->getPathText($p), 'folderProperties' => $this->getPathProperties($p), 'page' => @$p['page'], 'data' => array()); foreach ($this->result as $k => &$v) { if (!empty($this->result[$k])) { $rez[$k] =& $v; } } return $rez; }
/** * get the menu config for a given path or id * @param varchar | int $path path string or node id * @return [type] [description] */ public static function getMenuForPath($path) { $rez = ''; //get item path if id specified if (is_numeric($path)) { $tmp = \CB\Path::getPath($path); $path = '/' . $tmp['path']; } if (is_string($path)) { $path = explode('/', $path); } $path = array_reverse(array_filter($path, 'is_numeric')); $path = Util\toNumericArray($path); // get templates for each path elements $nodeTemplate = array(); $recs = DM\Tree::readByIds($path); foreach ($recs as $r) { $nodeTemplate[$r['id']] = $r['template_id']; } //get db menu into variable $menu = static::getMenuRules(); $ugids = isset($_SESSION['user']['groups']) ? $_SESSION['user']['groups'] : array(); $ugids[] = $_SESSION['user']['id']; // we have 3 main criterias for detecting needed menu: // - user_group_ids - records for specific users or groups // - node_ids // - template_ids // // we'll iterate the path from the end and detect the menu $lastWeight = 0; for ($i = 0; $i < sizeof($path); $i++) { //firstly we'll check if we find a menu row with id or template of the node foreach ($menu as $m) { $weight = 0; if (in_array($path[$i], $m['nids'])) { $weight += 50; } elseif (empty($m['nids'])) { $weight += 1; } else { //skip this record because it contain nids and not contain this node id continue; } if (in_array($nodeTemplate[$path[$i]], $m['ntids'])) { $weight += 50; } elseif (empty($m['ntids'])) { $weight += 1; } else { //skip this record because it has ntids specified and not contain this node template id continue; } if (empty($m['ugids'])) { $weight += 1; } else { $int = array_intersect($ugids, $m['ugids']); if (empty($int)) { continue; } else { $weight += 10; } } if ($weight > $lastWeight) { $lastWeight = $weight; $rez = $m['menu']; } } //if nid matched or template matched then dont iterate further if ($lastWeight > 50) { return $rez; } } return $rez; }
/** * get the menu config for a given path or id * @param varchar | int $path path string or node id * @return [type] [description] */ public static function getMenuForPath($path) { $rez = ''; //get item path if id specified if (is_numeric($path)) { $tmp = \CB\Path::getPath($path); $path = '/' . $tmp['path']; } if (is_string($path)) { $path = explode('/', $path); } $path = array_reverse(array_filter($path, 'is_numeric')); $path = Util\toNumericArray($path); // get templates for each path elements $nodeTemplate = array(); $res = DB\dbQuery('SELECT id, template_id FROM tree WHERE id in (0' . implode(',', $path) . ')') or die(DB\dbQueryError()); while ($r = $res->fetch_assoc()) { $nodeTemplate[$r['id']] = $r['template_id']; } $res->close(); //get db menu into variable $menu = array(); $res = DB\dbQuery('SELECT node_ids `nids` ,node_template_ids `ntids` ,user_group_ids `ugids` ,menu FROM menu') or die(DB\dbQueryError()); while ($r = $res->fetch_assoc()) { $r['nids'] = Util\toNumericArray($r['nids']); $r['ntids'] = Util\toNumericArray($r['ntids']); $r['ugids'] = Util\toNumericArray($r['ugids']); $menu[] = $r; } $res->close(); $ugids = $_SESSION['user']['groups']; $ugids[] = $_SESSION['user']['id']; // we have 3 main criterias for detecting needed menu: // - user_group_ids - records for specific users or groups // - node_ids // - template_ids // // we'll iterate the path from the end and detect the menu $lastWeight = 0; for ($i = 0; $i < sizeof($path); $i++) { //firstly we'll check if we find a menu row with id or template of the node foreach ($menu as $m) { $weight = 0; if (in_array($path[$i], $m['nids'])) { $weight += 50; } elseif (empty($m['nids'])) { $weight += 1; } else { //skip this record because it contain nids and not contain this node id continue; } if (in_array($nodeTemplate[$path[$i]], $m['ntids'])) { $weight += 50; } elseif (empty($m['ntids'])) { $weight += 1; } else { //skip this record because it has ntids specified and not contain this node template id continue; } if (empty($m['ugids'])) { $weight += 1; } else { $int = array_intersect($ugids, $m['ugids']); if (empty($int)) { continue; } else { $weight += 10; } } if ($weight > $lastWeight) { $lastWeight = $weight; $rez = $m['menu']; } } //if nid matched or template matched then dont iterate further if ($lastWeight > 50) { return $rez; } } return $rez; }