/** * @param $item * @return \Dibi\Result|int */ public function save($item) { if ($item->{$this->primaryKey}() === NULL) { $data = $this->itemToArray($item); try { $this->db->insert($this->tableName, $data)->execute(); return $this->db->insertId(); } catch (Exception $e) { Debugger::log(printf("An error has occurred: %s\n", $e->getMessage()), ILogger::ERROR); return NULL; } } else { $data = $this->itemToArray($item); try { $this->db->update($this->tableName, $data)->where($this->primaryKey . ' = %i', $item->{$this->primaryKey}())->execute(); return $item->{$this->primaryKey}(); } catch (ForeignKeyConstraintViolationException $e) { Debugger::log($e->getMessage(), ILogger::ERROR); return NULL; } } }