Exemplo n.º 1
0
 /**
  * build an array of html data that gets inserted into the advanced search popup view
  * @return array html lists/fields
  */
 public function getAdvancedSearchRows()
 {
     if (isset($this->advancedSearchRows)) {
         return $this->advancedSearchRows;
     }
     $statements = $this->getStatementsOpts();
     $rows = array();
     $first = false;
     $elementModels =& $this->getElements();
     list($fieldNames, $firstFilter) = $this->getAdvancedSearchElementList();
     $type = "<input type=\"hidden\" name=\"fabrik___filter[list_{$this->getId()}][search_type][]\" value=\"advanced\" />";
     $grouped = "<input type=\"hidden\" name=\"fabrik___filter[list_{$this->getId()}][grouped_to_previous][]\" value=\"0\" />";
     $filters =& $this->getAdvancedFilterValues();
     $counter = 0;
     if (array_key_exists('key', $filters)) {
         foreach ($filters['key'] as $key) {
             foreach ($elementModels as $elementModel) {
                 $testkey = FabrikString::safeColName($elementModel->getFullName(false, false, false));
                 if ($testkey == $key) {
                     break;
                 }
             }
             $join = $filters['join'][$counter];
             $condition = $filters['condition'][$counter];
             $value = $filters['origvalue'][$counter];
             $v2 = $filters['value'][$counter];
             switch ($condition) {
                 case "<>":
                     $jsSel = '<>';
                     break;
                 case "=":
                     $jsSel = 'EQUALS';
                     break;
                 case "<":
                     $jsSel = '<';
                     break;
                 case ">":
                     $jsSel = '>';
                     break;
                 default:
                     $firstChar = substr($v2, 1, 1);
                     $lastChar = substr($v2, -2, 1);
                     switch ($firstChar) {
                         case "%":
                             $jsSel = $lastChar == "%" ? 'CONTAINS' : ($jsSel = 'ENDS WITH');
                             break;
                         default:
                             if ($lastChar == "%") {
                                 $jsSel = 'BEGINS WITH';
                             }
                             break;
                     }
                     break;
             }
             $value = trim(trim($value, '"'), "%");
             if ($counter == 0) {
                 $join = JText::_('COM_FABRIK_WHERE') . "<input type=\"hidden\" value=\"WHERE\" name=\"fabrik___filter[list_{$this->getState('list.id')}][join][]\" />";
             } else {
                 $join = FabrikHelperHTML::conditonList($this->getId(), $join);
             }
             $lineElname = FabrikString::safeColName($elementModel->getFullName(false, true, false));
             $orig = JRequest::getVar($lineElname);
             JRequest::setVar($lineElname, array('value' => $value));
             $filter =& $elementModel->getFilter($counter, false);
             JRequest::setVar($lineElname, $orig);
             $key = JHTML::_('select.genericlist', $fieldNames, 'fabrik___filter[list_' . $this->getId() . '][key][]', "class=\"inputbox key\" size=\"1\" ", 'value', 'text', $key);
             $jsSel = JHTML::_('select.genericlist', $statements, 'fabrik___filter[list_' . $this->getId() . '][condition][]', "class=\"inputbox\" size=\"1\" ", 'value', 'text', $jsSel);
             $rows[] = array('join' => $join, 'element' => $key, 'condition' => $jsSel, 'filter' => $filter, 'type' => $type, 'grouped' => $grouped);
             $counter++;
         }
     }
     if ($counter == 0) {
         $join = JText::_('COM_FABRIK_WHERE') . "<input type=\"hidden\" name=\"fabrik___filter[list_{$this->getId()}][join][]\" value=\"WHERE\" />";
         $key = JHTML::_('select.genericlist', $fieldNames, 'fabrik___filter[list_' . $this->getId() . '][key][]', "class=\"inputbox key\" size=\"1\" ", 'value', 'text', '');
         $jsSel = JHTML::_('select.genericlist', $statements, 'fabrik___filter[list_' . $this->getId() . '][condition][]', "class=\"inputbox\" size=\"1\" ", 'value', 'text', '');
         $rows[] = array('join' => $join, 'element' => $key, 'condition' => $jsSel, 'filter' => $firstFilter, 'type' => $type, 'grouped' => $grouped);
     }
     $this->advancedSearchRows =& $rows;
     return $rows;
 }