public function beforeSave(Atomik_Model_Builder $builder, Atomik_Model $model) { $now = date('Y-m-d H:i:s'); if ($model->isNew()) { $model->created = $now; } $model->updated = $now; }
/** * 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; }
protected function _initData() { $reference = $this->getOption('reference'); $rows = Atomik_Model::findAll($reference->target); $this->_data = array(0 => '--'); foreach ($rows as $row) { $this->_data[$row->getPrimaryKey()] = (string) $row; } }
public function getFilteredData($query, $value) { $query->setParam(0, $value . '%'); $rows = Atomik_Model::query($query); $data = array(); foreach ($rows as $row) { $data[$row->getPrimaryKey()] = $row->{$this->field}; } return $data; }
public function afterDelete(Atomik_Model_Builder $builder, Atomik_Model $model) { $key = $builder->name . ':' . $model->getPrimaryKey(); $this->_memcache->delete($key); }
<?php if (!Atomik::has('request/name') || !Atomik::has('request/id')) { Atomik::redirect('index'); } $modelName = Atomik::get('request/name'); $returnUrl = Atomik::get('request/returnUrl', Atomik::url('models/list', array('name' => $modelName))); $model = Atomik_Model::find($modelName, Atomik::get('request/id')); $title = (string) $model; if (!$model->delete()) { Atomik::flash(__('An error occured while deleting %s %s', strtolower($modelName), $title), 'error'); } else { Atomik::flash(__('%s %s successfully deleted', $modelName, $title), 'success'); Backend_Activity::create('Models', __('%s %s has been deleted', $modelName, $title), __('Deleted by') . ' %s'); } Atomik::redirect($returnUrl, false);
/** * 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; }
if (!Atomik::has('request/name')) { Atomik::redirect('models'); } $modelName = Atomik::get('request/name'); $returnUrl = Atomik::get('request/returnUrl', Atomik::url('models/list', array('name' => $modelName))); $builder = Atomik_Backend_Models::getModelBuilder($modelName); $actionString = 'created'; $title = __('Create a new') . ' %s'; $message = __('A %s has been created', strtolower($modelName)); $model = $modelName; if (Atomik::has('request/id')) { $model = Atomik_Model::find($builder, Atomik::get('request/id')); $actionString = 'modified'; $title = __('Edit') . ' %s: ' . $model; $message = __('%s %s has been modified', $modelName, $model); } $form = new Atomik_Model_Form($model, array('form-', 'admin-form-')); $form->setAction(Atomik::url()); $form->setOption('cancel-url', $returnUrl); if ($form->hasData()) { if ($form->isValid()) { $model = $form->getModel(); $model->save(); Backend_Activity::create('Models', $message, __(ucfirst($actionString) . ' by') . ' %s'); Atomik::redirect($returnUrl, false);
public function afterDelete(Atomik_Model_Builder $builder, Atomik_Model $model) { $primaryKey = $model->getPrimaryKey(); $db = $builder->getManager()->getDbInstance(); $tableName = $builder->tableName; $foreignFieldName = $this->_prefix($tableName) . '_' . $builder->getPrimaryKeyField()->name; $tableName = $this->_suffix($tableName); $db->delete($tableName, array($foreignFieldName => $primaryKey)); }
/** * Saves the current model * * @see Atomik_Model::save() * @return bool */ public function save() { return $this->_model->save(); }