public function offsetSet($offset, $value)
 {
     if ($offset) {
         $this->add($this->_getFilterFromArray($offset, $value));
     } else {
         parent::offsetSet($offset, $value);
     }
 }
 public function __construct($name = null, $defaultClass = null)
 {
     $this->_formName = $name;
     parent::__construct($defaultClass);
 }
Example #3
0
 public function preDispatch()
 {
     parent::preDispatch();
     $addColumns = array();
     if (is_array($this->_columns)) {
         $addColumns = $this->_columns;
     }
     $this->_columns = new Kwf_Collection();
     foreach ($addColumns as $k => $column) {
         if (is_array($column)) {
             $columnObject = new Kwf_Grid_Column();
             foreach ($column as $propName => $propValue) {
                 $columnObject->setProperty($propName, $propValue);
             }
             $this->_columns[] = $columnObject;
         } else {
             $this->_columns[] = $column;
         }
     }
     if (!isset($this->_model) && isset($this->_tableName)) {
         $this->setTable(new $this->_tableName());
     }
     if (!isset($this->_model) && isset($this->_table)) {
         $this->setTable($this->_table);
     }
     if (!isset($this->_model) && isset($this->_modelName)) {
         $this->_model = Kwf_Model_Abstract::getInstance($this->_modelName);
     } else {
         if (isset($this->_model) && is_string($this->_model)) {
             $this->_model = Kwf_Model_Abstract::getInstance($this->_model);
         }
     }
     $filters = new Kwf_Controller_Action_Auto_FilterCollection();
     // Abwärtskompatibilität für Filterarray
     if (is_array($this->_filters)) {
         foreach ($this->_filters as $field => $config) {
             $filters->offsetSet($field, $config);
         }
     }
     $this->_filters = $filters;
     $this->_initColumns();
     // Abwärtskompatibilität falls Filterarray in initColumns gesetzt wurden
     if (is_array($this->_filters)) {
         $filters = new Kwf_Controller_Action_Auto_FilterCollection();
         foreach ($this->_filters as $field => $config) {
             $filters->offsetSet($field, $config);
         }
         $this->_filters = $filters;
     }
     $filters = is_array($this->_filters) ? $this->_filters : array();
     if ($this->_getParam('query') && !isset($this->_filters['text'])) {
         $this->_filters['text'] = true;
     }
     foreach ($this->_filters as $filter) {
         if ($this->_model) {
             $filter->setModel($this->_model);
         }
         // Abwärtskompatibilität für Textfilter mit queryFields und querySeparator
         if (!$filter instanceof Kwf_Controller_Action_Auto_Filter_Text) {
             continue;
         }
         if (!$filter->getProperty('queryFields', true)) {
             $queryFields = $this->_queryFields;
             if (!$queryFields) {
                 $queryFields = array();
                 foreach ($this->_columns as $column) {
                     $index = $column->getDataIndex();
                     if (isset($this->_model) && !in_array($index, $this->_model->getColumns())) {
                         continue;
                     }
                     $queryFields[] = $index;
                 }
             }
             $info = $this->_getTableInfo();
             if ($info && $this->_primaryKey && !in_array($this->_primaryKey, $queryFields) && !in_array($info['name'] . '.' . $this->_primaryKey, $queryFields)) {
                 $queryFields[] = $this->_primaryKey;
             }
             $filter->setQueryFields($queryFields);
         }
         if ($this->_querySeparator) {
             $filter->setQuerySeparator($this->_querySeparator);
         }
     }
     if (isset($this->_model) && !isset($this->_primaryKey)) {
         $this->_primaryKey = $this->_model->getPrimaryKey();
     }
     if (isset($this->_model) && $this->_position && !isset($this->_columns[$this->_position]) && in_array($this->_position, $this->_model->getColumns())) {
         $columnObject = new Kwf_Grid_Column($this->_position);
         $columnObject->setHeader(' ')->setWidth(35)->setType('int');
         if (isset($this->_permissions['save']) && $this->_permissions['save']) {
             $columnObject->setEditor('PosField');
         }
         $this->_columns->prepend($columnObject);
         $this->_sortable = false;
         $this->_defaultOrder = $this->_position;
     }
     if (isset($this->_model) && ($info = $this->_getTableInfo())) {
         foreach ($this->_columns as $column) {
             if (!$column->getType()) {
                 $column->setType((string) $this->_model->getColumnType($column->getDataIndex()));
             }
         }
     }
     if ($this->_primaryKey) {
         $primaryFound = false;
         foreach ($this->_columns as $column) {
             if ($column->getDataIndex() == $this->_primaryKey) {
                 $primaryFound = true;
             }
         }
         if (!$primaryFound) {
             //primary key hinzufügen falls er noch nicht in gridColumns existiert
             $columnObject = new Kwf_Grid_Column($this->_primaryKey);
             if (isset($this->_model)) {
                 $columnObject->setType((string) $this->_model->getColumnType($this->_primaryKey));
             } else {
                 // fallback
                 $columnObject->setType('string');
             }
             $this->_columns[] = $columnObject;
         }
     }
     if (!isset($this->_defaultOrder)) {
         $this->_defaultOrder = $this->_columns->first()->getDataIndex();
     }
     if (is_string($this->_defaultOrder)) {
         $this->_defaultOrder = array('field' => $this->_defaultOrder, 'direction' => 'ASC');
     }
     if (method_exists($this, '_getWhereQuery')) {
         throw new Kwf_Exception("_getWhereQuery doesn't exist anymore");
     }
     // Falls Filter einen Default-Wert hat:
     // - GET query-Parameter setzen,
     // - Im JavaScript nach rechts verschieben und Defaultwert setzen
     foreach ($this->_filters as $filter) {
         if ($filter instanceof Kwf_Controller_Action_Auto_Filter_Text) {
             continue;
         }
         $param = $filter->getParamName();
         if ($filter->getDefault() && !$this->_getParam($param)) {
             $this->_setParam($param, $filter->getDefault());
         }
     }
 }