Exemplo n.º 1
0
 /**
  * getChildNodes description
  * @return json responce
  */
 protected function getChildNodes()
 {
     $rez = array('data' => array());
     $cffc = $this->getCurrentFacetFieldConfig();
     $lfc = $this->getLevelFieldConfigs();
     $isLastFacetField = $this->lastNodeDepth >= sizeOf($lfc);
     if (empty($cffc) || @$this->requestParams['from'] !== 'tree') {
         return $this->getItems();
     }
     $facetName = $cffc['name'];
     $facetField = $cffc['field'];
     $fq = empty($this->config['fq']) ? array() : $this->config['fq'];
     $fq = array_merge($fq, $this->getParentNodeFilters());
     $this->replaceFilterVars($fq);
     $s = new \CB\Search();
     $sr = $s->query(array('rows' => 0, 'fq' => $fq, 'facet' => true, 'facet.field' => array('{!ex=' . $facetField . ' key=' . $facetName . '}' . $facetField)));
     if (!empty($sr['facets']->facet_fields->{$facetName})) {
         $facetClass = Facets::getFacetObject($cffc);
         $facetClass->loadSolrResult($sr['facets']);
         $facetData = $facetClass->getClientData();
         $showChilds = !$isLastFacetField || !empty($this->config['show_in_tree']);
         foreach ($facetData['items'] as $k => $v) {
             if (is_numeric($v)) {
                 $name = $k;
                 $count = $v;
             } else {
                 $name = $v['name'];
                 $count = $v['count'];
             }
             if (!empty($this->config['show_count']) && !empty($count)) {
                 // $name .= ' (' . $count . ')';
                 $name .= ' <span style="color: #AAA; font-size: 12px">' . $count . '</span>';
             }
             $r = array('name' => $name, 'id' => $this->getId($k), 'iconCls' => 'icon-folder');
             if ($showChilds) {
                 $r['has_childs'] = true;
             }
             $rez['data'][] = $r;
         }
     }
     return $rez;
 }
Exemplo n.º 2
0
 /**
  * get list of facets classes that should be available for this node
  * @param  array &$rp request params
  * @return array
  */
 public function getFacets(&$rp)
 {
     $facets = array();
     $cfg = $this->getNodeParam('facets');
     if (empty($cfg['data'])) {
         return $facets;
     }
     //creating facets
     $facetsDefinitions = \CB\Config::get('facet_configs');
     foreach ($cfg['data'] as $k => $v) {
         $name = $k;
         $config = null;
         if (!empty($v)) {
             $config = $v;
             if (is_scalar($v)) {
                 if (!empty($facetsDefinitions[$v])) {
                     $config = $facetsDefinitions[$v];
                 } else {
                     $config = array('type' => $v);
                 }
                 $name = $v;
                 $config['name'] = $v;
             }
         } else {
             $config = array('name' => $k, 'type' => $k);
         }
         $facets[$name] = \CB\Facets::getFacetObject($config);
     }
     if (!empty($rp['view']['type'])) {
         $v =& $rp['view'];
         $rows = false;
         $cols = false;
         if (!empty($v['rows']['facet']) && !empty($facets[$v['rows']['facet']])) {
             $rows = $facets[$v['rows']['facet']];
         }
         if (!empty($v['cols']['facet']) && !empty($facets[$v['cols']['facet']])) {
             $cols = $facets[$v['cols']['facet']];
         }
         if ($rp['view']['type'] == 'pivot' && sizeof($facets) > 1) {
             if (!empty($rp['selectedFacets']) && is_array($rp['selectedFacets']) && sizeof($rp['selectedFacets'] > 1)) {
                 $rows = $rp['selectedFacets'][0];
                 $cols = $rp['selectedFacets'][1];
             }
             reset($facets);
             if (empty($rows)) {
                 $rows = current($facets);
                 next($facets);
             }
             if (empty($cols)) {
                 $cols = current($facets);
             }
             if (is_scalar($rows) || is_scalar($cols)) {
                 foreach ($facets as $facet) {
                     if (is_scalar($rows) && $facet->field == $rows) {
                         $rows = $facet;
                     }
                     if (is_scalar($cols) && $facet->field == $cols) {
                         $cols = $facet;
                     }
                 }
             }
             $config = array('type' => 'pivot', 'name' => 'pivot', 'facet1' => $rows, 'facet2' => $cols);
             if (!empty($rp['selectedStat'])) {
                 $config['stats'] = $rp['selectedStat'];
             } elseif (!empty($cfg['view']['stats'])) {
                 $config['stats'] = $cfg['view']['stats'];
             }
             $facets[] = \CB\Facets::getFacetObject($config);
         }
     }
     return $facets;
 }