/** * Delete a record * @param \Sebk\SmallOrmBundle\Dao\Model $model * @return \Sebk\SmallOrmBundle\Dao\AbstractDao * @throws DaoException */ public function delete(Model $model) { if (!$model->fromDb) { throw new DaoException("Try delete a record not from db from '{$this->modelBundle}' '{$this->modelName}' model"); } $parms = array(); $sql = "DELETE FROM " . $this->connection->getDatabase() . "." . $this->dbTableName . " "; if ($model->getOriginalPrimaryKeys() === null) { $model->setOriginalPrimaryKeys(); } $sql .= " WHERE "; $conds = array(); foreach ($model->getOriginalPrimaryKeys() as $originalPk => $originalValue) { $conds[] = $this->getDbNameFromModelName($originalPk) . " = :" . $originalPk . "OriginalPk"; $parms[$originalPk . "OriginalPk"] = $originalValue; } $sql .= implode(" AND ", $conds); if (method_exists($model, "beforeDelete")) { $model->beforeDelete(); } $this->connection->execute($sql, $parms); if (method_exists($model, "afterDelete")) { $model->afterDelete(); } $model->fromDb = true; $model->altered = false; return $this; }
/** * Get validator of a model * @param type $bundle * @param type $model * @return type * @throws ConfigurationException * @throws DaoNotFoundException */ public function get(Model $model) { if (!isset($this->config[$model->getBundle()])) { throw new ConfigurationException("Bundle '" . $model->getBundle() . "' is not configured"); } foreach ($this->config[$model->getBundle()]["connections"] as $connectionName => $connectionsParams) { $className = $connectionsParams["validator_namespace"] . '\\' . $model->getModelName(); if (class_exists($className)) { return new $className($this->daoFactory, $model); } } throw new DaoNotFoundException("Validator of model " . $model->getModelName() . " of bundle " . $model->getBundle() . " not found"); }
/** * @return string */ public function getSalt() { return parent::getSalt(); }