コード例 #1
0
 public function preDispatch()
 {
     parent::preDispatch();
     if (is_string($this->_model)) {
         $this->_model = new $this->_model();
     }
     // PrimaryKey setzen
     if (!isset($this->_primaryKey)) {
         $this->_primaryKey = $this->_model->getPrimaryKey();
     }
     if (is_string($this->_defaultOrder)) {
         $this->_defaultOrder = array('field' => $this->_defaultOrder, 'direction' => 'ASC');
     }
     if (!$this->_imageRule) {
         $this->_imageRule = $this->_model->getReferenceRuleByModelClass('Kwf_Uploads_Model');
     }
 }
コード例 #2
0
 public function preDispatch()
 {
     parent::preDispatch();
     if (isset($this->_tableName)) {
         $this->_table = new $this->_tableName();
     } else {
         if (isset($this->_modelName)) {
             $this->_model = new $this->_modelName();
         }
     }
     if (isset($this->_table)) {
         $this->_model = new Kwf_Model_Db(array('table' => $this->_table));
     }
     if (!isset($this->_model)) {
         throw new Kwf_Exception('$_model oder $_modelName not set');
     }
     if (is_string($this->_model)) {
         $this->_model = Kwf_Model_Abstract::getInstance($this->_model);
     }
     $this->_filters = new Kwf_Collection();
     $this->_init();
     foreach ($this->_filters as $filter) {
         $filter->setModel($this->_model);
     }
     // PrimaryKey setzen
     if (!isset($this->_primaryKey)) {
         $this->_primaryKey = $this->_model->getPrimaryKey();
         if (is_array($this->_primaryKey)) {
             $this->_primaryKey = $this->_primaryKey[1];
         }
     }
     $cols = $this->_model->getColumns();
     // Invisible-Button hinzufügen falls nicht überschrieben und in DB
     if (array_key_exists('invisible', $this->_buttons) && is_null($this->_buttons['invisible']) && in_array('visible', $cols)) {
         $this->_buttons['invisible'] = true;
     }
     // Pos-Feld
     if (!isset($this->_hasPosition)) {
         $this->_hasPosition = in_array('pos', $cols);
     }
     if ($this->_hasPosition && !in_array('pos', $cols)) {
         throw new Kwf_Exception("_hasPosition is true, but 'pos' does not exist in database");
     }
     foreach ($this->_icons as $k => $i) {
         if (is_string($i)) {
             $this->_icons[$k] = new Kwf_Asset($i);
         }
     }
     if (is_string($this->_defaultOrder)) {
         $this->_defaultOrder = array('field' => $this->_defaultOrder, 'direction' => 'ASC');
     }
     // 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->getConfig('default') && !$this->_getParam($param)) {
             $this->_setParam($param, $filter->getConfig('default'));
         }
     }
 }
コード例 #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());
         }
     }
 }
コード例 #4
0
ファイル: Form.php プロジェクト: nsams/koala-framework
 public function preDispatch()
 {
     parent::preDispatch();
     $t = microtime(true);
     if (!isset($this->_form)) {
         if (isset($this->_formName)) {
             $this->_form = new $this->_formName();
         } else {
             $this->_form = new Kwf_Form();
         }
     }
     foreach ($this->_fields as $k => $field) {
         if (!isset($field['type'])) {
             throw new Kwf_Exception("no type for field no {$k} specified");
         }
         $cls = 'Kwf_Form_Field_' . $field['type'];
         if (!class_exists($cls)) {
             throw new Kwf_Exception("Invalid type: Form-Field-Class {$cls} does not exist.");
         }
         $fieldObject = new $cls();
         unset($field['type']);
         foreach ($field as $propName => $propValue) {
             $fieldObject->setProperty($propName, $propValue);
         }
         $this->_form->fields[] = $fieldObject;
     }
     if (!$this->_form->getModel()) {
         if (isset($this->_table)) {
             $this->_form->setTable($this->_table);
         } else {
             if (isset($this->_tableName)) {
                 $this->_form->setTable(new $this->_tableName());
             } else {
                 if (isset($this->_modelName)) {
                     $this->_form->setModel(new $this->_modelName());
                 } else {
                     if (isset($this->_model)) {
                         if (is_string($this->_model)) {
                             $this->_form->setModel(Kwf_Model_Abstract::getInstance($this->_model));
                         } else {
                             $this->_form->setModel($this->_model);
                         }
                     }
                 }
             }
         }
     }
     $this->_initFields();
     $this->_form->initFields();
     $this->_form->trlStaticExecute();
     if (!$this->_form->fields->first() instanceof Kwf_Form_Container_Tabs) {
         $this->_form->setBodyStyle('padding: 10px;');
     }
     if (!$this->_form->getId()) {
         if (is_array($this->_form->getPrimaryKey())) {
             foreach ($this->_form->getPrimaryKey() as $key) {
                 $id[$key] = $this->_getParam($key);
             }
             $this->_form->setId($id);
         } else {
             $this->_form->setId($this->_getParam($this->_form->getPrimaryKey()));
         }
     }
     Kwf_Benchmark::subCheckpoint('init form', microtime(true) - $t);
 }