/**
  * Gets database column value.
  * 
  * @return mixed
  */
 public function getDbValue()
 {
     if (!$this->_record->isUpdated()) {
         $this->_record->fetch();
     }
     return $this->_dbValue;
 }
 /**
  * @param string $className
  * @return ArticleAttachment
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 /**
  * Saves the record and updates the column index.
  * 
  * @return void
  */
 public function save()
 {
     $this->_record->save();
     $pk = $this->_record->getPrimaryKey();
     $this->_column->setValue($pk->getValue());
 }
Exemple #4
0
 /**
  * Insert or update row
  * @throws Exception
  * @return System\DbRecord\DbRecord
  */
 public function delete(DbRecord $record)
 {
     if (!$record->isRecordExisting()) {
         throw new \Nette\InvalidStateException("Only existing row can be deleted.");
     }
     $engine = $this->getConnection();
     $table = $record::table();
     $topicIndex = $record::topicIndex();
     if (!$engine->inTransaction()) {
         $doCommit = true;
         $engine->begin();
     }
     $res = $engine->select('sx, dx, ' . $topicIndex . ' AS topic')->from($record::table())->where('%and', $record->getPrimaryCondition())->fetchAll();
     //	Zadny zaznam?
     if (!isset($res[0])) {
         throw new NotFoundException('Item pk(' . implode(', ', $record->getPrimaryCondition()) . ') not found.', 1);
     }
     $res = $res[0];
     //	Odstraneni zaznamu.
     $ret = $engine->delete($table)->where('%and', $record->getPrimaryCondition())->execute();
     //	Zadny zaznam?
     if (!$ret) {
         throw new NotFoundException('Item pk(' . implode(', ', $record->getPrimaryCondition()) . ') not found: (' . $ret . ')', 2);
     }
     // update left
     $engine->update($table, array('sx%sql' => "sx - " . ($res->dx - $res->sx + 1)))->where("sx >= %i", $res->sx)->and($topicIndex . "=%i", $res->topic)->execute();
     // update right
     $engine->update($table, array('dx%sql' => "dx - " . ($res->dx - $res->sx + 1)))->where("dx >= %i", $res->dx)->and($topicIndex . "=%i", $res->topic)->execute();
     //	Upravit poradi. ord.
     if (isset($doCommit)) {
         $engine->commit();
     }
     // set state
     $record->setState($record::STATE_DELETED);
     return $ret;
 }
Exemple #5
0
 /**
  * Delete row
  * @throws Exception
  * @return void
  */
 public function delete(DbRecord $record)
 {
     if (!$record->isRecordExisting()) {
         throw new \Nette\InvalidStateException("Only existing row can be deleted.");
     }
     $engine = $this->getConnection();
     if (!$engine->inTransaction()) {
         $doCommit = true;
         $engine->begin();
     }
     $this->onBeforeDelete($record);
     $engine->delete($record::table())->where('%and', $record->getPrimaryCondition())->execute();
     $this->onAfterDelete($record);
     if (isset($doCommit)) {
         $engine->commit();
     }
     // set state
     $record->setState($record::STATE_DELETED);
     // set action / pravdepodobne probehla v poradku
     $record->lastAction('d');
 }