Example #1
0
 public function buildSqlWhere()
 {
     $where = $this->config->filter();
     $depth = Status::depth($this->statusVariables);
     if ($depth > 1) {
         if (!$this->config->connectionField()) {
             throw new \Ip\Exception("Nested GRID require 'connectionField' setting to be set.");
         }
         $where .= ' and (' . $where . ') and ' . $this->config->tableName() . '.`' . $this->config->connectionField() . '` = ' . ipDb()->getConnection()->quote($this->statusVariables['gridParentId' . ($depth - 1)]);
     }
     $searchVariables = array();
     foreach ($this->statusVariables as $key => $value) {
         if (preg_match('/^s_/', $key)) {
             $searchVariables[substr($key, 2)] = $value;
         }
     }
     if (!empty($searchVariables)) {
         foreach ($this->config->fields() as $fieldData) {
             if (!empty($fieldData['type']) && $fieldData['type'] == 'Tab') {
                 continue;
             }
             $fieldObject = $this->config->fieldObject($fieldData);
             $fieldQuery = $fieldObject->searchQuery($searchVariables);
             if ($fieldQuery) {
                 if ($where != ' ') {
                     $where .= ' and ';
                 }
                 $where .= $fieldQuery;
             }
         }
     }
     return $where;
 }
Example #2
0
 public function searchForm($searchVariables)
 {
     $form = new \Ip\Form();
     $form->setMethod('get');
     $form->addAttribute('autocomplete', 'off');
     $form->removeCsrfCheck();
     foreach ($this->subgridConfig->fields() as $key => $fieldData) {
         if (isset($fieldData['allowSearch']) && !$fieldData['allowSearch']) {
             continue;
         }
         if (!empty($fieldData['type']) && $fieldData['type'] == 'Tab') {
             //tabs (fieldsets)
             $title = '';
             if (!empty($fieldData['label'])) {
                 $title = $fieldData['label'];
             }
             if ($key == 0) {
                 $fieldsets = $form->getFieldsets();
                 $fieldset = $fieldsets[0];
                 $fieldset->setLabel($title);
             } else {
                 $fieldset = new \Ip\Form\Fieldset($title);
                 $form->addFieldset($fieldset);
             }
             $fieldset->addAttribute('id', 'autoGridTabId' . rand(0, 100000000000));
             if ($key == 0) {
                 $fieldset->addAttribute('class', 'tab-pane active');
             } else {
                 $fieldset->addAttribute('class', 'tab-pane');
             }
         } else {
             $fieldObject = $this->subgridConfig->fieldObject($fieldData);
             $field = $fieldObject->searchField($searchVariables);
             if ($field) {
                 $form->addField($field);
             }
         }
     }
     $field = new \Ip\Form\Field\Hidden(array('name' => 'method', 'value' => 'search'));
     $form->addField($field);
     $field = new \Ip\Form\Field\HiddenSubmit();
     $form->addField($field);
     if (count($form->getFieldsets()) > 1) {
         $form->addClass('tab-content');
     }
     return $form;
 }