function render() { if (!$this->_application->isAdmin()) { if ($this->_content['result']) { org_glizy_helpers_Array::arrayMultisortByLabel($this->_content['result'], '__weight__'); } if (!$this->getAttribute('skipFormTag')) { parent::render_html_onStart(); } parent::render(); if (!$this->getAttribute('skipFormTag')) { parent::render_html_onEnd(); } } }
function render_html_onStart() { if ($this->getAttribute('wrapDiv')) { $this->addOutputCode('<div' . $this->_renderAttributes(array('class' => $this->getAttribute('cssClass'))) . '>'); $this->setAttribute('cssClass', ''); } parent::render_html_onStart(); if ($this->getAttribute('fieldset')) { $this->addOutputCode('<fieldset>'); } }
function render_html_onStart() { parent::render_html_onStart(); $folderPath = __Paths::get('CORE') . 'classes/org/glizycms/js/visualsearch/'; $output = <<<EOD <script src="{$folderPath}dependencies.js" type="text/javascript"></script> <script src="{$folderPath}visualsearch.js" type="text/javascript"></script> <!--[if (!IE)|(gte IE 8)]><!--> <link href="{$folderPath}visualsearch-datauri.css" media="screen" rel="stylesheet" type="text/css" /> <!--<![endif]--> <!--[if lte IE 7]><!--> <link href="{$folderPath}visualsearch.css" media="screen" rel="stylesheet" type="text/css" /> <!--<![endif]--> EOD; $this->addOutputCode($output, 'head'); $id = $this->getId(); $query = ''; $callback = array(); $valuesMapping = array(); $valuesMappingRev = array(); $valueMatches = ''; foreach ($this->criteria as $v) { $callback[] = array('label' => $v->label, 'id' => $v->id); if ('facet' == $v->type) { $it = org_glizy_objectFactory::createModelIterator($this->getAttribute('model')); $it->where($v->id, '', '<>')->orderBy($v->id); $foundValues = array(); foreach ($it as $ar) { if (is_array($ar->{$v->id})) { foreach ($ar->{$v->id} as $value) { if (!in_array($value, $foundValues)) { $foundValues[] = $value; } } } else { if (!in_array($ar->{$v->id}, $foundValues)) { $foundValues[] = $ar->{$v->id}; } } } $valueMatches .= 'case "' . $v->label . '":callback(' . json_encode($foundValues) . ');break;'; } else { if ('static' == $v->type) { $foundValues = array(); $valuesMapping[$v->label] = array(); $values = json_decode($v->values); foreach ($values as $kk => $vv) { $label = __T($vv); $foundValues[] = $label; $valuesMapping[$v->label][$label] = $kk; $valuesMappingRev[$v->label][$kk] = $label; } $valueMatches .= 'case "' . $v->label . '":callback(' . json_encode($foundValues) . ');break;'; } else { if ('dictionary' == $v->type) { $dataProvider = $this->getComponentById($v->dataProvider); if (!is_null($dataProvider)) { $foundValues = array(); $valuesMapping[$v->label] = array(); $values = $dataProvider->getItems(); foreach ($values as $vv) { $foundValues[] = $vv['value']; $valuesMapping[$v->label][$vv['value']] = $vv['key']; $valuesMappingRev[$v->label][$vv['key']] = $vv['value']; } $valueMatches .= 'case "' . $v->label . '":callback(' . json_encode($foundValues) . ');break;'; } } } } } foreach ($this->filters as $item) { foreach ($item as $k => $v) { if (isset($valuesMappingRev[$k]) && isset($valuesMappingRev[$k][$v])) { $v = $valuesMappingRev[$k][$v]; } $query .= '"' . $k . '": "' . addslashes($v) . '" '; } } $callback = json_encode($callback); $valuesMapping = json_encode($valuesMapping); $output = <<<EOD <input name="{$id}_filters" id="{$id}_filters" type="hidden" value=""> <div id="{$id}_visualsearch"></div> <script type="text/javascript" charset="utf-8"> \$(document).ready(function() { var valuesMapping = {$valuesMapping}; var visualSearch = VS.init({ container : \$('#{$id}_visualsearch'), query : '{$query}', remainder: '', callbacks : { facetMatches : function(callback) { callback({$callback}) }, valueMatches : function(facet, searchTerm, callback) { switch (facet) { {$valueMatches} } } } }); \$('#{$id}').submit(function(){ var e = jQuery.Event("keydown"); e.which = 13 _.each(visualSearch.searchBox.inputViews, function(inputView, i) { inputView.box.trigger("focus"); inputView.box.trigger(e); }); var values = []; _.each(visualSearch.searchQuery.facets(), function(el, i){ _.each(el, function(el2, i2){ if (valuesMapping[i2]) { var temp = {}; temp[i2] = valuesMapping[i2][el2] values.push(temp); } else { values.push(el); } }); }); \$('#{$id}_filters').val(JSON.stringify(values)); return true; }) }); </script> EOD; $this->addOutputCode($output); }