/** * 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']; } elseif (!empty($p['params']['query'])) { $guid = 'search'; } 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->getDC(); $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, User::getId(), Util\jsonEncode($p['state']))); } 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; }
/** * analize and adjust view config if needed * @param array $viewConfig * @param array $rp * @return array */ public function adjustViewConfig($viewConfig, &$rp) { if (empty($viewConfig)) { return array(); } $rez = $viewConfig; $cfg =& $this->config; if (!empty($cfg['views'][$rez['type']])) { $rez = array_merge($rez, $cfg['views'][$rez['type']]); } elseif ($rez['type'] == 'activityStream' && !empty($cfg['views']['stream'])) { $rez = array_merge($rez, $cfg['views']['stream']); } //dashboards extention check if (!empty($rez['extends'])) { $rez = Config::extend('dashboards', $rez); } switch ($rez['type']) { //backward compatibility check case 'pivot': case 'charts': if (!empty($cfg['stats'])) { $stats = array(); foreach ($cfg['stats'] as $item) { $stats[] = array('title' => Util\detectTitle($item), 'field' => $item['field']); } $rez['stats'] = $stats; } $rez['sort'] = null; //check renamed options if (isset($rez['chart_type']) && empty($rez['chartType'])) { $rez['chartType'] = $rez['chart_type']; unset($rez['chart_type']); } if (isset($rez['pivot_type']) && empty($rez['pivotType'])) { $rez['pivotType'] = $rez['pivot_type']; unset($rez['pivot_type']); } break; case 'dashboard': //analize dashboard items and merge referenced config if any if (empty($rez['items'])) { $rez['items'] = array(); } $this->subClasses = array(); $copyConfigProperties = ['title', 'cellCls', 'rowspan', 'colspan', 'width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight']; foreach ($rez['items'] as $k => $v) { if (!empty($v['extends'])) { $rez['items'][$k] = Config::extend('treeNodes', $v); } $clsArr = Path::getNodeClasses($rez['items']); if (!empty($clsArr)) { $class = current($clsArr); if (isset($v['pid'])) { $class->id = $v['pid']; } $this->subClasses[$k] = $class; $path = array($class); $customRp = $rp; unset($customRp['userViewChange']); $vc = $class->getViewConfig($path, $customRp); $rez['items'][$k] = array_merge($vc, array_intersect_key($v, array_flip($copyConfigProperties))); } } break; default: // grid // if (!empty($cfg['view']['group'])) { // $rez['group'] = $cfg['view']['group']; // } } return $rez; }