Beispiel #1
0
	/**
	 * Returns the filename of a model associated file
	 * 
	 * @param 	Atomik_Model	$model
	 * @return 	string
	 */
	public static function getFilenameFromModel(Atomik_Model $model)
	{
		$dir = self::getDirectoryFromBuilder($model->getBuilder());
		$filename = self::getFilenameFromBuilder($model->getBuilder(), $model->toArray());
		
		if (preg_match('/:[a-zA-Z0-9]+/', $filename)) {
			require_once 'Atomik/Model/Exception.php';
			throw new Atomik_Model_Exception('Some fields are missing for the filename to be complete in ' . get_class($model));
		}
		
		return $dir . $filename;
	}
Beispiel #2
0
	/**
	 * Deletes a model
	 *
	 * @param 	Atomik_Model $model
	 * @return 	bool
	 */
	public function delete(Atomik_Model $model)
	{
		if ($model->isNew()) {
			return false;
		}
		
		$builder = $model->getBuilder();
		$this->_notify($builder, 'BeforeDelete', array($model));
		
		$where = array($builder->getPrimaryKeyField()->name => $model->getPrimaryKey());
		if ($this->_dbInstance->delete($builder->tableName, $where) === false) {
			$this->_notify($builder, 'FailDelete', array($model));
			return false;
		}
		$this->_notify($builder, 'AfterDelete', array($model));
		return true;
	}
Beispiel #3
0
	/**
	 * Sets the model associated to this form
	 *
	 * @param Atomik_Model $model
	 */
	public function setModel(Atomik_Model $model, $updateData = true)
	{
		if ($model !== null && $model->getBuilder() !== $this->_builder) {
			require_once 'Atomik/Model/Exception.php';
			throw new Atomik_Model_Exception('Only models using builder ' . $this->_builder->name . ' can be used with the form');
		}
		
		$this->_model = $model;
		
		if ($model !== null && $updateData) {
			$this->setData($model->toArray(), false);
		}
	}