public function edit($id) { if (IS_POST) { //获取数据 if ($this->model->create() !== false) { //判断数据是否正确 if ($this->model->save() !== false) { $this->success('修改成功', cookie('__forward__')); return; //防止后面代码执行 } } $this->error('修改失败'); } else { //调用钩子函数 $this->_before_edit_view(); //给页面分配树的数据 $row = $this->model->find($id); //页面分配数据 $this->assign('meta_title', '编辑' . $this->meta_title); $this->assign('row', $row); $this->assign('id', $id); //加载视图 $this->display('add'); } }
/** * Set current version for given type * * @param integer $version Current version * @param string $type Can be 'app' or a plugin name * @param boolean $migrated If true, will add the record to the database * If false, will remove the record from the database * @return boolean */ public function setVersion($version, $type, $migrated = true) { if ($migrated) { $this->Version->create(); return $this->Version->save(array('version' => $version, 'type' => $type)); } else { $conditions = array($this->Version->alias . '.version' => $version, $this->Version->alias . '.type' => $type); return $this->Version->deleteAll($conditions); } }
/** * Implements writing to log table. * * @param string $type The type of log you are making. * @param string $content The message you want to log. * @return boolean success of write. */ public function write($type, $content, $module = 'system', $foreign_key = 0) { $data = compact('type', 'content', 'module', 'foreign_key'); $user = AuthComponent::user(); if (!empty($user)) { $data['user_id'] = $user['id']; $data['username'] = $user['name']; } self::$_model->create(); return self::$_model->save($data); }
/** * Create new model for user * * @param array $input * @return Model */ public function create($input) { if (!$this->isValid($input, $this->model->getRules())) { return false; } if ($response = $this->model->create($input)) { return $response; } else { array_push($this->errors, 'Could not create new record.'); return false; } }
public function testMultipleUploadSaveReadDelete() { // setup $this->Model->Behaviors->load('Media.Attachable', array()); $this->Model->configureAttachment(array('files' => array('baseDir' => $this->attachmentDir, 'multiple' => true, 'removeOnOverwrite' => true)), true); $data = array($this->Model->alias => array('title' => 'My Upload', 'files_upload' => array($this->upload1, $this->upload2))); // save $this->Model->create(); $result = $this->Model->save($data); $this->assertTrue(isset($this->Model->id)); $this->assertEqual($result[$this->Model->alias]['files_upload'], ''); $this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1); $this->assertTrue(isset($result['Attachment']['files'][0]['path'])); $this->assertTrue(file_exists($result['Attachment']['files'][0]['path'])); $this->assertTrue(isset($result['Attachment']['files'][1]['path'])); $this->assertTrue(file_exists($result['Attachment']['files'][1]['path'])); // read $modelId = $this->Model->id; $this->Model->create(); $result = $this->Model->read(null, $modelId); $this->assertTrue(isset($result[$this->Model->alias]['files'])); $this->assertTrue(!isset($result[$this->Model->alias]['files_upload'])); $this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1); $this->assertTrue(isset($result['Attachment']['files'][0]['path'])); $this->assertTrue(file_exists($result['Attachment']['files'][0]['path'])); $this->assertTrue(isset($result['Attachment']['files'][1]['path'])); $this->assertTrue(file_exists($result['Attachment']['files'][1]['path'])); //delete $deleted = $this->Model->delete($this->Model->id); $this->assertTrue($deleted, 'Failed to delete Attachment'); $this->assertTrue(!file_exists($result['Attachment']['files'][0]['path']), 'Attachment not deleted'); $this->assertTrue(!file_exists($result['Attachment']['files'][1]['path']), 'Attachment not deleted'); }
public function testMain() { $model = Model::create()->set('array', $this->array); $data = array('array' => $this->array); $callback = 'myFunc'; //setup $view = JsonPView::create(); try { // empty js callback function name $view->toString($model); $this->fail('empty callback javascript function name expected!'); } catch (WrongArgumentException $e) { } try { $view->setCallback('34_callback'); // invalid javascript function name $this->fail('invalid javascript function name expected!'); } catch (WrongArgumentException $e) { } $view->setCallback($callback); $this->assertEquals($this->makeString($callback, $data), $view->toString($model)); $simpleStringableObject = SimpleStringableObject::create()->setString($callback); $view->setCallback($simpleStringableObject); $this->assertEquals($this->makeString($callback, $data), $view->toString($model)); }
public function testToString() { $renderView = self::$resolver->resolveViewName('testView'); $toStringView = self::$resolver->resolveViewName('testViewToString'); $model = Model::create(); $this->assertTrue($toStringView->toString($model) == $renderView->toString($model)); }
/** * Create and save a new token, automatically setting the * expiration if none is given in $data * * @param array $data * @return User */ public static function create(array $data) { if (empty($data['expires_at'])) { $data['expires_at'] = date('Y-m-d H:i:s', strtotime('+1 week')); } return parent::create($data); }
public static function create($params) { if (self::checkReverseComplement($params)) { throw new Exception('Food Complement already exists'); } return parent::create($params); }
/** * Create and save a new comment * @param array $data * @param bool $notify * @return Comment */ public static function create(array $data, $notify = true) { // Normalize data if (isset($data["hours"])) { $data["hours_total"] = $data["hours"]; $data["hours_remaining"] = $data["hours"]; unset($data["hours"]); } if (!empty($data["due_date"])) { if (!preg_match("/[0-9]{4}(-[0-9]{2}){2}/", $data["due_date"])) { $data["due_date"] = date("Y-m-d", strtotime($data["due_date"])); } if (empty($data["sprint_id"])) { $sprint = new Sprint(); $sprint->load(array("DATE(?) BETWEEN start_date AND end_date", $issue->due_date)); $data["sprint_id"] = $sprint->id; } } if (empty($data["author_id"]) && ($user_id = \Base::instance()->get("user.id"))) { $data["author_id"] = $user_id; } // Create issue $item = parent::create($data); // Send creation notifications if ($notify) { $notification = \Helper\Notification::instance(); $notification->issue_create($item->id); } // Return instance return $item; }
public function create() { $result = parent::create(); if (!isset($_POST['begin_time'])) { $this->begin_time = ''; } if (!isset($_POST['end_time'])) { $this->end_time = ''; } if (!isset($_POST['user_id'])) { $this->user_id = user('user_id'); } if (!isset($_POST['create_time'])) { $this->create_time = date('Y-m-d H:i:s'); } $this->edit_time = date('Y-m-d H:i:s'); if (user('is_admin') || user('is_vip')) { $event_model->is_checked = 1; } else { $event_model->is_checked = 0; } if (!isset($_POST['type'])) { $this->type = user('type'); } return $result; }
/** * Store a new resource. * * @param mixed $request * @return mixed */ public function store($request) { $this->fireEvent('creating', [$request]); $created = $this->model->create($request); $this->fireEvent('created', [$created]); return $created; }
public static function create($params) { if (self::checkReverseAlternate($params)) { throw new Exception('Food alternate already exists'); } return parent::create($params); }
public static function create($params) { // Check if we need to re-order existing steps if (isset($params["reorder"]) && $params["reorder"] == TRUE) { // Connect to database $mysqli = FoodAppDatabase::connect(); // Get insert position $insertPosition = $params["data"][0]["stepNumber"]; // Update current data - increment step numbers above insert position $queryString = "SELECT * FROM recipe_step WHERE food_id='" . $params["data"][0]["foodId"] . "' " . "ORDER BY step_number DESC"; if ($result = $mysqli->query($queryString)) { while ($row = $result->fetch_assoc()) { // Update current data if ($row["step_number"] >= $insertPosition) { $queryStringUpdate = "UPDATE recipe_step SET step_number='" . ($row["step_number"] + 1) . "' WHERE id='" . $row["id"] . "'"; if (!$mysqli->query($queryStringUpdate)) { throw new Exception($mysqli->error); } } } } } // Create new recipe step return parent::create($params); }
/** * Save user data * * @param type $userInfo * @return int userId */ public function save($userInfo) { if (isset($userInfo["id"]) && (int) $userInfo["id"] > 0) { return parent::update($userInfo, array('id' => $userInfo["id"])); } else { return parent::create($userInfo); } }
public function salvar(Model $Model, $dados) { $Model->create(); if ($Model->saveAll($dados)) { return true; } return $Model->validationErrors; }
/** * Create and save a new file, optionally sending notifications * @param array $data * @param bool $notify * @return Comment */ public static function create(array $data, $notify = true) { $item = parent::create($data); if ($notify) { $notification = \Helper\Notification::instance(); $notification->issue_file($item->issue_id, $item->id); } return $item; }
/** * create() should set the model's id and return self if model does not have id */ public function test_create_returnsSelf_ifModelDoesNotHaveId() { $client = new Api\Client(); $model = new Model($client); $model->foo = 'bar'; $model->create(); $this->assertEquals(1, $model->id); return; }
public function testRender() { $model = Model::create()->set('array', $this->array); $data = array('array' => $this->array); ob_start(); JsonView::create()->setHexQuot(true)->setHexTag(true)->setHexAmp(true)->setHexApos(true)->setNumericCheck(true)->setHexQuot(false)->setHexQuot(false)->render($model); $result = ob_get_clean(); //with all flags $this->assertEquals(json_encode($data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_NUMERIC_CHECK), $result); }
/** * Create and save a new user and related keys * @param array $data * @return User */ public static function create(array $data) { // Create user $user = parent::create($data); // Create keys $private = User\Key::create(['user_id' => $user->id, 'type' => 'private', 'fingerprint' => $data['fingerprint'], 'key' => $data['private_key']]); $public = User\Key::create(['user_id' => $user->id, 'type' => 'public', 'fingerprint' => $data['fingerprint'], 'key' => $data['public_key']]); $symmetric = User\Key::create(['user_id' => $user->id, 'buddy_id' => $user->id, 'type' => 'symmetric', 'key' => $data['symmetric_key']]); return $user; }
/** * Log the query if required * @param $alias string model alias * @param $action string * @param $details string * @param $foreign_key string (uuid) */ function __log($alias, $action, $details, $foreign_key = null) { if ($this->__isLogRequired($action)) { $this->__UserLog->create(); $this->__UserLog->data = array('user_id' => User::get('id'), 'resource' => $alias, 'resource_type' => 'model', 'action' => $action, 'foreign_key' => $foreign_key, 'details' => $this->__isLogDetailsRequired($alias, $action) ? $details : null); if (!$this->__deferred) { $this->__saveLog(); } } }
public function create() { $data = parent::create(); // add http to links $this->url = addhttp($this->url); // detect video types and fill in swffile if ($this->type == 'video') { $this->swffile = $this->getFlashImage($this->url); } return $data; }
/** * Create and save a new comment * @param array $data * @param bool $notify * @return Comment */ public static function create(array $data, $notify = true) { if (empty($data['text'])) { throw new \Exception("Comment text cannot be empty."); } $item = parent::create($data); if ($notify) { $notification = \Helper\Notification::instance(); $notification->issue_comment($item->issue_id, $item->id); } return $item; }
public function getDraftId(Model $model, $conditions = array()) { $conditions = array_merge($this->options[$model->alias]['conditions'], $conditions); $result = $model->find('first', array('fields' => $model->primaryKey, 'conditions' => $conditions)); if (!empty($result)) { return $result[$model->alias][$model->primaryKey]; } else { $model->create($conditions); $model->save(null, false); return $model->id; } }
public static function create($data) { // stdClass の場合は json データとして扱う $media = parent::create(); if ($data instanceof \stdClass) { $media->download($data->media_url); } else { $media->set($data); } $media->registration_at = time(); return $media; }
/** * Convenience method allowing to validate data and return the result * * @param Model $Model Model being tested * @param array $data Profile data * @param array $validationErrors Validation errors: this variable will be updated with validationErrors (sorted by key) in case of validation fail * @return boolean Return value of Model::validate() */ protected function _validData(Model $Model, $data, &$validationErrors = array()) { $valid = true; $Model->create($data); if (!$Model->validates()) { $validationErrors = $Model->validationErrors; ksort($validationErrors); $valid = false; } else { $validationErrors = array(); } return $valid; }
function create() { // clear all null keys (use array_filter?) foreach ($this->rs as $k => $v) { if (is_null($v)) { unset($this->rs[$k]); } } // timestamp $this->rs['created'] = time('now'); $this->rs['updated'] = time('now'); return parent::create(); }
protected function _create() { $this->_Model->create(); $result = $this->_Model->save($this->_Record); if ($result) { $this->_Record = $result[$this->_Model->alias]; ActiveRecordManager::add($this); $this->_resetState(); foreach ($this->_foreignKeys as $foreignKey) { $foreignKey['Association']->setForeignKey($foreignKey['Record']); } return true; } else { return false; } }
public function testMain() { $prefix = 'window.'; $callback = 'name'; $model = Model::create()->set('array', $this->array); $data = array('array' => $this->array); //setup $view = JsonXssView::create(); $defaultString = $view->toString($model); $this->assertEquals($defaultString, $this->makeString($prefix, $callback, $data)); $prefix = 'window2.'; $callback = 'name2'; $view->setCallback($callback); $view->setPrefix($prefix); $customString = $view->toString($model); $this->assertEquals($customString, $this->makeString($prefix, $callback, $data)); }
/** * afterSave * * @param Model $model * @param Model $created * @return void * @access public */ function afterSave(&$model, $created) { // コンテンツIDを取得 if ($created) { $contentId = $model->getLastInsertId(); } else { $contentId = $model->data[$model->alias]['id']; } $pluginContent = $this->_generatePluginContentData($model, $contentId); /*** データを保存 ***/ if (isset($pluginContent['PluginContent']['id'])) { $this->PluginContent->set($pluginContent); } else { $this->PluginContent->create($pluginContent); } $this->PluginContent->save(); }