Beispiel #1
0
 /**
  * @return bool
  */
 public function run()
 {
     $database = new Database();
     if ($this->getMethod() == self::_edit || $this->getMethod() == self::_new) {
         $this->syncTable();
     }
     if ($this->getMethod() == self::_list) {
         $listData = [];
         $dbColumns = [];
         $joinColumns = [];
         $dataObjects = $this->getData()->getColumns();
         foreach ($dataObjects as $dataObject) {
             $column = [];
             if ($dataObject::fieldType == "select") {
                 $joinColumns[$dataObject::fieldType]['objects'][] = $dataObject;
             }
             $dbColumns[] = $dataObject->getName();
             $column['label'] = $dataObject->getLabel();
             $column['isLink'] = $dataObject->isLink();
             $listData['columns'][$dataObject->getName()] = $column;
         }
         $rows = $database->select($dbColumns, $this->getName(), [], 'ID', 'DESC');
         if (isset($joinColumns['select']) && count($joinColumns['select']) > 0) {
             foreach ($joinColumns['select'] as $joinColumn) {
                 $newJoinData = [];
                 foreach ($joinColumn as $object) {
                     $select = $object->getValueColumns();
                     array_push($select, $object->getSourceColumn());
                     $joinData = $database->select($select, $object->getSourceTable());
                     foreach ($joinData as $row) {
                         $sourceColumnData = $row[$object->getSourceColumn()];
                         unset($row[$object->getSourceColumn()]);
                         $newJoinData[$object->getName()][$sourceColumnData] = implode(' ', $row);
                     }
                 }
             }
             foreach ($rows as $key => $row) {
                 foreach ($newJoinData as $fieldName => $joinRows) {
                     $rows[$key][$fieldName] = $rows[$key][$fieldName] ? $newJoinData[$fieldName][$row[$fieldName]] : '';
                 }
             }
         }
         $listData['rows'] = $rows;
         $this->setListData($listData);
         return true;
     }
     if ($this->getMethod() == self::_edit) {
         $rows = $database->select(['*'], $this->getName(), ['ID' => $this->getID()], null, null, 1);
         if (count($rows) > 0) {
             foreach ($rows[0] as $column => $value) {
                 foreach ($this->getForm()->getFields() as $field) {
                     if ($column == $field->getName()) {
                         $field->setValue($value);
                     }
                 }
             }
         }
     }
     if ($this->getMethod() == self::_edit || $this->getMethod() == self::_new) {
         $fields = [];
         foreach ($this->getForm()->getFields() as $fieldObject) {
             $data = [];
             $data['name'] = $fieldObject->getName();
             $data['description'] = $fieldObject->getDescription();
             $data['label'] = $fieldObject->getLabel();
             $data['html'] = $fieldObject->getHtml();
             $data['required'] = $fieldObject->isRequired();
             $fields[] = $data;
         }
         $this->setFormData($fields);
         return true;
     }
 }
Beispiel #2
0
 /**
  * @return array
  */
 private function fetch()
 {
     $database = new Database();
     return $database->select([$this->getSourceColumn(), $this->getValueColumn()], $this->getSourceTable());
 }