Example #1
0
 /**
  * Prepare $this->inputData for inserting into DB, cleans data
  * according to existing columns in table and flatten nested arrays
  * @param \Nette\Database\Table\ActiveRow $row
  */
 protected function harmonizeInputData($row = NULL)
 {
     if (!$row) {
         $res = $this->table->limit(1)->fetchAll();
         $row = reset($res);
     }
     $array = $row ? $row->toArray() : NULL;
     foreach ($this->inputData as $key => &$value) {
         if ($row && !array_key_exists($key, $array)) {
             unset($this->inputData[$key]);
         } else {
             if (is_array($value)) {
                 if ($this->isValidId($value['id'])) {
                     $value = (int) $value['id'];
                 } else {
                     unset($this->inputData[$key]);
                 }
             }
         }
     }
 }