public function getClientData() { $rez = array('f' => $this->field, 'title' => $this->getTitle(), 'items' => array()); $dbnode = new TreeNode\Dbnode(); foreach ($this->solrData as $k => $v) { $rez['items'][$k] = array('name' => $dbnode->getName($k), 'count' => $v); } //check if have default sorting set in cofig if (!empty($this->config['sort'])) { $sp = $this->getSortParams(); Util\sortRecordsArray($rez['items'], $sp['property'], $sp['direction'], $sp['type'], true); //add sort param for client side $rez['sort'] = $sp; } return $rez; }
public function getClientData($options = array()) { $rez = array('f' => $this->field, 'title' => $this->getTitle(), 'items' => $this->solrData); //check if have default sorting set in cofig if (!empty($this->config['sort'])) { //convert items to suitable sortable array $rez['items'] = array(); foreach ($this->solrData as $k => $v) { $rez['items'][$k] = array('name' => $k, 'count' => $v); } $sp = $this->getSortParams(); Util\sortRecordsArray($rez['items'], $sp['property'], $sp['direction'], $sp['type'], true); //add sort param for client side $rez['sort'] = $sp; } return $rez; }
/** * method used to implement custom logic on solr query * @param array $p search params * @return void */ public function onSolrQuery(&$p) { $this->params =& $p; $ip =& $p['inputParams']; if (@$ip['view']['type'] !== $this->fromParam) { return; } // $sp = &$p['params']; $result =& $p['result']; $view =& $result['view']; $data =& $result['data']; $rez = array(); $displayColumns = $this->getDC(); //This if remains as backward compatible, but will be removed in future commits if (!empty($displayColumns['sort'])) { $view['sort'] = $displayColumns['sort']; } //get state $stateFrom = empty($displayColumns['from']) ? 'default' : $displayColumns['from']; $state = $this->getState($stateFrom); $customColumns = $this->prepareColumnsConfig($displayColumns); //set custom display columns data if (!empty($displayColumns['data'])) { // fill custom columns data foreach ($data as &$doc) { if (!is_numeric($doc['id'])) { continue; } $obj = \CB\Objects::getCachedObject($doc['id']); if (!is_object($obj)) { \CB\debug('DisplayColumns object not found: ' . $doc['id']); continue; } $template = $obj->getTemplate(); foreach ($customColumns as $fieldName => &$col) { $templateField = $template->getField($col['fieldName']); $values = array(); if (!empty($col['solr_column_name'])) { if (isset($doc[$col['solr_column_name']]) && $col['solr_column_name'] !== $col['fieldName']) { $v = $doc[$col['solr_column_name']]; $doc[$col['fieldName']] = $v; unset($doc[$col['solr_column_name']]); $values = array($v); } if (empty($templateField)) { $templateField = array('type' => empty($col['fieldType']) ? 'varchar' : $col['fieldType'], 'name' => $col['solr_column_name'], 'title' => Util\detectTitle($col)); } } elseif (!empty($col['lookup'])) { //lookup field $values = $obj->getLookupValues($col['lookup'], $templateField); } else { //default $values = isset($doc[$col['fieldName']]) ? array($doc[$col['fieldName']]) : $obj->getFieldValue($col['fieldName']); } //populate column properties if empty if (empty($col['title'])) { $col['title'] = $templateField['title']; } if (empty($col['sortType']) && empty($col['solr_column_name'])) { switch ($templateField['type']) { case 'date': case 'datetime': $col['sortType'] = 'asDate'; break; case 'float': $col['sortType'] = 'asFloat'; break; case 'checkbox': case 'int': $col['sortType'] = 'asInt'; break; case 'html': case 'memo': case 'text': $col['sortType'] = 'asUCText'; break; case '_objects': default: $col['sortType'] = 'asUCString'; break; } } //update value from document if empty from solr query if (empty($doc[$fieldName]) || in_array($templateField['type'], array('_objects', 'time'))) { $dv = array(); foreach ($values as $value) { $value = is_array($value) ? @$value['value'] : $value; $dv[] = $template->formatValueForDisplay($templateField, $value, false); } $doc[$fieldName] = implode(', ', $dv); } } } /* remove columns without title */ foreach ($customColumns as $fieldName => &$col) { if (empty($col['title'])) { unset($customColumns[$fieldName]); } } $rez = $customColumns; } /* merge the state with display columns */ $defaultColumns = array_keys(Config::getDefaultGridViewColumns()); if (!empty($state['columns'])) { $rez = array(); foreach ($state['columns'] as $k => $c) { if (!empty($customColumns[$k])) { unset($customColumns[$k]['hidden']); $c = array_merge($customColumns[$k], $c); unset($customColumns[$k]); $rez[$k] = $c; } elseif (in_array($k, $defaultColumns)) { $rez[$k] = $c; } } if (!empty($customColumns)) { $rez = array_merge($rez, $customColumns); } } /* user clicked a column to sort by */ if (!empty($ip['userSort'])) { $view['sort'] = array('property' => $ip['sort'][0]['property'], 'direction' => $ip['sort'][0]['direction']); } elseif (!empty($state['sort'])) { $view['sort'] = $state['sort']; } /* end of get user state and merge the state with display columns */ //check grouping params if (!empty($ip['userGroup']) && !empty($ip['group'])) { $view['group'] = array('property' => $ip['sourceGroupField'], 'direction' => $ip['group']['direction']); } elseif (isset($state['group'])) { $view['group'] = $state['group']; } elseif (isset($displayColumns['group'])) { $view['group'] = $displayColumns['group']; } //analize grouping $this->analizeGrouping($p); if (!empty($rez)) { $result['DC'] = $rez; } /* check if we need to sort records using php (in case sort field is not from solr)*/ if (!empty($view['sort']) && !empty($rez[$view['sort']['property']]['localSort']) && !in_array($view['sort']['property'], $defaultColumns)) { $s =& $view['sort']; Util\sortRecordsArray($data, $s['property'], $s['direction'], empty($rez[$s['property']]['sortType']) ? 'asString' : $rez[$s['property']]['sortType']); } }