/** * save state for grid view of the browser * @return Ext.Direct responce */ public function saveGridViewState($p) { $rez = array('success' => true); $guid = false; /* incomming params example p: {params:{id:251, view:grid, path:1/114/101/251, query:null, start:0},…} params: {id:251, view:grid, path:1/114/101/251, query:null, start:0} id: 251 path: "1/114/101/251" query: null start: 0 view: "grid" state: {columns:{nid:{id:0, width:80, hidden:true, sortable:true}, name:{id:1, width:160, sortable:true},…}} columns: {nid:{id:0, width:80, hidden:true, sortable:true}, name:{id:1, width:160, sortable:true},…} case: {id:3, width:150, sortable:true} cdate: {id:8, width:120, hidden:true, sortable:true} cid: {id:6, width:200, hidden:true, sortable:true} date: {id:4, width:120, sortable:true} name: {id:1, width:160, sortable:true} nid: {id:0, width:80, hidden:true, sortable:true} oid: {id:7, width:200, sortable:true} path: {id:2, width:150, hidden:true, sortable:true} size: {id:5, width:80, sortable:true} udate: {id:9, width:120, hidden:true, sortable:true} */ if (!empty($p['params']['search']['template_id'])) { $guid = 'template_' . $p['params']['search']['template_id']; } else { $path = empty($p['params']['path']) ? $p['params']['id'] : $p['params']['path']; if (!empty($path)) { $treeNodeConfigs = Config::get('treeNodes', array('Dbnode' => array())); $treeNodeClasses = Path::getNodeClasses($treeNodeConfigs); $treeNodeGUIDConfigs = array(); foreach ($treeNodeClasses as $nodeClass) { $cfg = $nodeClass->getConfig(); $treeNodeGUIDConfigs[$cfg['guid']] = $cfg; } $nodesPath = Path::createNodesPath($path, $treeNodeGUIDConfigs); if (!empty($nodesPath)) { $lastNode = array_pop($nodesPath); $DCConfig = $lastNode->getNodeParam('DC'); $guid = empty($DCConfig['from']) ? 'default' : $DCConfig['from']; } } } if ($guid) { DB\dbQuery('INSERT INTO tree_user_config (guid, user_id, cfg) VALUES($1, $2, $3) ON DUPLICATE KEY UPDATE cfg = $3', array($guid, $_SESSION['user']['id'], Util\jsonEncode($p['state']))) or die(DB\dbQueryError()); } return $rez; }
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; }