Esempio n. 1
0
 public function facetSearchOptions($includeAlternateFacets = false)
 {
     $this->prepareFacets();
     $facetSearchOptions = array('currentSelection' => $this->dieselSearchHelper->getSelectedAttributeQueries($this->attributeId), 'allowMultipleSelection' => $this->options[self::OPT_ALLOW_MULTIPLE_SELECTION], 'queryBase' => $this->dieselSearchHelper->getQueryState($this->attributeId), 'hasMoreFacets' => false, 'facets' => array());
     if (gettype($this->generatedFacetData) === 'object') {
         $Array = new JavaClass("java.lang.reflect.Array");
         if ($this->options[self::OPT_MAX_ROWS] != self::MAX_ROWS_UNLIMITED and $Array->getLength($this->generatedFacetData) == $this->options[self::OPT_MAX_ROWS]) {
             $facetSearchOptions['hasMoreFacets'] = true;
         } else {
             if ($this->options[self::OPT_MAX_ROWS] == self::MAX_ROWS_UNLIMITED and $Array->getLength($this->generatedFacetData) == $this->options[self::OPT_MAX_ROWS]) {
                 $facetSearchOptions['hasMoreFacets'] = true;
             }
         }
     }
     // actual facet data
     if (count($facetSearchOptions['currentSelection']) == 0) {
         $facetSearchOptions['facets'] = $this->facets();
     } else {
         if ($includeAlternateFacets) {
             $facetSearchOptions['facets'] = 'coming soon';
             // set up a new search w/o this attribute and just get facets for this one.
             $subDpSearch = new WFDieselSearch();
             $subDpSearch->setIndex($this->dieselSearch->index());
             $subDpSearchHelper = new WFDieselSearchHelper();
             $subDpSearchHelper->setDieselSearch($subDpSearch);
             $subDpSearchHelper->setQueryState($facetSearchOptions['queryBase']);
             $subFacet = new WFDieselSearch_FacetedAttribute($this->attributeId, $subDpSearchHelper, $this->options);
             $subFacetInfo = $subFacet->facetSearchOptions();
             // copy data over from sub-query
             $facetSearchOptions['facets'] = $subFacetInfo['facets'];
             $facetSearchOptions['hasMoreFacets'] = $subFacetInfo['hasMoreFacets'];
         } else {
             $facetSearchOptions['facets'] = 'query for more';
         }
     }
     return $facetSearchOptions;
 }
Esempio n. 2
0
 function render($blockContent = NULL)
 {
     if ($this->hidden or $this->dieselSearchHelper->isFilteringOnAttribute($this->attributeID)) {
         return NULL;
     } else {
         // set up stuff we'll use while rendering
         if ($this->class) {
             $classHTML = " class=\"{$this->class}\" ";
         }
         // output facet nav
         try {
             $Array = new JavaClass("java.lang.reflect.Array");
             $facets = $this->prepareFacets();
             if (gettype($facets) == 'array') {
                 if ($this->facetStyle == WFDieselFacet::STYLE_TREE and $this->treeDataPath) {
                     // no items, but means specifically "no kids" thus need to deal with this for the Tree callback
                     // ajax callback -- send data
                     WFYAHOO_widget_TreeView::sendTree(array());
                 }
                 return NULL;
             }
             if (gettype($facets) == 'object' and $Array->getLength($facets) == 0) {
                 return NULL;
             }
             // also no items
             // sanity check
             if ($this->facetStyle == WFDieselFacet::STYLE_MENU and $this->isTaxonomyAttribute()) {
                 throw new Exception("STYLE_MENU does not support taxonomy attributes.");
             }
             if ($this->facetStyle == WFDieselFacet::STYLE_MENU and $this->rangeCount) {
                 throw new Exception("STYLE_MENU does not support range display.");
             }
             // output!
             $html = '';
             if ($this->label) {
                 $html .= "<span style=\"font-weight: bold; white-space: nowrap;\">{$this->label}</span><br />\n";
             }
             $width = $this->width ? "width: {$this->width};" : NULL;
             $height = $this->isPopup ? '300px' : ($this->height ? $this->height : $this->parent()->facetNavHeight());
             // NOTE: Safari seems to have a bug where even tho the content fits within the width, it still puts a scroll bar. Works in FF, not sure about IE yet.
             $html .= '<div style="max-height: ' . $height . '; overflow: auto; padding-right: 4px;' . $width . '">' . "\n";
             // actual facets
             switch ($this->facetStyle) {
                 case WFDieselFacet::STYLE_MENU:
                     $html .= $this->facetMenuHTML($facets);
                     break;
                 case WFDieselFacet::STYLE_TREE:
                     // set up "root" YUITree
                     $tree = new WFYAHOO_widget_TreeView('tree_' . $this->id(), $this->page);
                     $items = array();
                     foreach ($facets as $facet) {
                         $label = str_replace("\n", '', $this->facetHTML($facet));
                         $item = new WFYAHOO_widget_TreeViewNode(java_values($facet->getAttributeValue()), $label);
                         $fkids = $facet->getChildren();
                         if ($fkids === null) {
                             $item->setCouldHaveChildren(false);
                         }
                         $items[] = $item;
                     }
                     $tree->setValue($items);
                     $tree->setDynamicCallback($this->parent()->baseURL() . '/' . urlencode($this->dieselSearchHelper->getQueryState($this->attributeID())) . '//' . $this->id() . '|');
                     if ($this->treeDataPath) {
                         // ajax callback -- send data
                         WFYAHOO_widget_TreeView::sendTree($items);
                     } else {
                         // initial display of first row of items
                         $html .= $tree->render();
                     }
                     break;
                 default:
                     foreach ($facets as $facet) {
                         $html .= $this->facetHTML($facet);
                     }
                     if ($this->maxRows != WFDieselFacet::UNLIMITED_ROWS and $Array->getLength($facets) == $this->maxRows) {
                         $html .= $this->editFacetLink('More...', $this->class);
                     } else {
                         if ($this->maxRows == WFDieselFacet::UNLIMITED_ROWS and $Array->getLength($facets) == $this->maxRows) {
                             $html .= "<p>There are too many choices to dislpay at this time. Please narrow your search by other criteria and try again.</p>";
                         }
                     }
                     break;
             }
             $html .= '</div>';
             return $html;
         } catch (JavaException $e) {
             $trace = new java("java.io.ByteArrayOutputStream");
             $e->printStackTrace(new java("java.io.PrintStream", $trace));
             throw new Exception("java stack trace:<pre> {$trace} </pre>\n");
         }
     }
 }