Exemplo n.º 1
0
 /**
  * @return array
  */
 public function toArray()
 {
     $return = parent::toArray();
     if ($this->intervention !== null) {
         if (!$this->intervention instanceof Intervention) {
             throw new \Bixev\InterventionSdk\Exception('invalid intervention instance (must be instanceof \\Bixev\\InterventionSdk\\Intervention');
         }
         $return['intervention'] = $this->intervention->toArray();
     }
     if ($this->custom_fields !== null) {
         if (!$this->custom_fields instanceof InterventionReportCustomFields) {
             throw new \Bixev\InterventionSdk\Exception('invalid custom_fields instance (must be instanceof \\Bixev\\InterventionSdk\\InterventionReportCustomFields');
         }
         $return['custom_fields'] = $this->custom_fields->toArray();
     }
     return $return;
 }
Exemplo n.º 2
0
 private function processSave(AbstractModel $model)
 {
     $model->callback('onSaveBegin');
     $model_props = $model->toArray();
     $table_name = $model->getTableName();
     $keys = array();
     $values = array();
     $primaryKey = $model->getPrimaryKey();
     foreach ($model_props as $key => $value) {
         if ($key !== $primaryKey && $key !== 'childs') {
             if (is_object($value) || is_array($value)) {
                 continue;
             }
             $keys[] = '`' . $key . '`';
             if ($value == 'CURRENT_TIMESTAMP' || $value == 'NOW()') {
                 $values[] = "{$value}";
             } else {
                 $values[] = "'{$value}'";
             }
         }
     }
     $columns = implode(', ', $keys);
     $vals = implode(', ', $values);
     $query = "INSERT INTO  `{$table_name}`({$columns}) VALUES({$vals})";
     $this->dump($query);
     $result = $this->db->exec($query);
     if ($result) {
         $id = $this->db->getLastId();
         $model->setId($id);
         $model->callback('onSaveEnd');
         return true;
     } else {
         return false;
     }
 }
 /**
  * Takes object and transforms it to array
  * @return [type] [description]
  */
 public function toArray()
 {
     $data = parent::toArray();
     if (isset($data['address'])) {
         $data['address'] = $data['address']->toArray();
     }
     if (isset($data['candidates'])) {
         $zipcodeCandidates = array();
         foreach ($data['candidates'] as $zipcode) {
             $zipcodeCandidates[] = $zipcode->toArray();
         }
         $data['candidates'] = $zipcodeCandidates;
     }
     return $data;
 }