本文整理汇总了PHP中Model::saveField方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::saveField方法的具体用法?PHP Model::saveField怎么用?PHP Model::saveField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::saveField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: changeStatus
public function changeStatus(Model $Model, $status, $id = null, $force = false)
{
if ($id === null) {
$id = $Model->getID();
}
if ($id === false) {
return false;
}
$force = true;
$Model->id = $id;
if (!$Model->exists()) {
throw new NotFoundException();
}
if ($force !== true) {
$modelData = $Model->read();
if ($modelData[$Model->alias]['status'] === $status) {
CakeLog::write(LOG_WARNING, __d('webshop', 'The status of %1$s with id %2$d is already set to %3$s. Not making a change', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
return false;
}
} else {
CakeLog::write(LOG_WARNING, __d('webshop', 'Status change of %1$s with id %2$d is being forced to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
}
$Model->saveField('status', $status);
CakeLog::write(LOG_INFO, __d('webshop', 'Changed status of %1$s with id %2$d to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
$eventData = array();
$eventData[Inflector::underscore($Model->name)]['id'] = $id;
$eventData[Inflector::underscore($Model->name)]['status'] = $status;
$overallEvent = new CakeEvent($Model->name . '.statusChanged', $this, $eventData);
$specificEvent = new CakeEvent($Model->name . '.statusChangedTo' . Inflector::camelize($status), $this, $eventData);
CakeEventManager::instance()->dispatch($overallEvent);
CakeEventManager::instance()->dispatch($specificEvent);
return true;
}
示例2: fixOrder
public function fixOrder(Model $model, $conditions)
{
$count = $model->find('count', array('conditions' => $conditions));
if ($count > 0) {
$list = $model->find('list', array('conditions' => $conditions, 'order' => array($model->alias . '.order')));
$order = 1;
foreach ($list as $id => $name) {
$model->id = $id;
$model->saveField('order', $order++);
}
}
}
示例3: afterSave
public function afterSave(Model $Model, $created, $options = array())
{
$isTree = in_array('Tree', array_map('strtolower', $Model->Behaviors->attached()));
if ($Model->brwConfig['sortable'] and $created and !$isTree) {
$data = $Model->data;
$Model->saveField($Model->brwConfig['sortable']['field'], $Model->id);
$Model->data = $data;
}
if ($isTree) {
$Model->recover();
}
}
示例4: afterSave
/**
* afterSave callback
*
* @param Model $Model Model using this behavior
* @param boolean $created True if this save created a new record
* @return void
*/
public function afterSave(Model $Model, $created)
{
if ($created) {
$default = $Model->getDefaultRole();
$role_id = $default[$this->roleModel]['id'];
$Model->saveField('role_id', $role_id);
$this->syncAclRole($Model, array('model' => $this->roleModel, 'foreign_key' => $role_id));
} else {
$new_role = array('model' => $this->roleModel, 'foreign_key' => $Model->field('role_id'));
$this->syncAclRole($Model, $new_role, $this->oldRole[$Model->alias]);
}
return true;
}
示例5: afterSave
public function afterSave(Model $model, $created, $options = array())
{
if (!empty($model->data[$model->name]['thumb']['name'])) {
$file = $model->data[$model->name]['thumb'];
// Current thumb
$media_id = $model->field('media_id');
if ($media_id != 0) {
$model->Media->delete($media_id);
}
// Update thumb
$model->Media->save(array('ref_id' => $model->id, 'ref' => $model->name, 'file' => $file));
$model->saveField('media_id', $model->Media->id);
}
}
示例6: deactivate
/**
* @param Model $Model
* @param $id
*
* @return bool
*/
public function deactivate(Model $Model, $id)
{
if (empty($id)) {
return false;
}
$Model->id = $id;
if (!$Model->exists()) {
return false;
}
if ($Model->saveField('active', false)) {
return true;
}
return false;
}
示例7: increment
public function increment(Model $Model, $id = null, $field = null)
{
if (!$field && key($this->settings[$Model->alias]['fields'])) {
$field = key($this->settings[$Model->alias]['fields']);
}
if (!$field) {
return false;
}
if ($id === null) {
$id = $Model->getID();
}
if ($id === false) {
return false;
}
$Model->id = $id;
$currentValue = $Model->field($field, array($Model->alias . '.id' => $id));
$result = $Model->saveField($field, $currentValue + 1);
if (!$result) {
return false;
}
return $currentValue + 1;
}
示例8: afterSave
/**
* Save each file to folder and update db
*
* @param Model $Model
* @param boolean $created
*/
public function afterSave(Model $Model, $created)
{
if ($this->_saving) {
return true;
}
$this->_saving = true;
if (!empty($this->_uploadLater)) {
foreach ($this->_uploadLater as $key => $fields) {
foreach ($fields as $name => $file) {
if (!is_uploaded_file($file['tmp_name'])) {
continue;
}
$ext = strtolower(strrchr($file['name'], '.'));
$filename = md5($file['name'] . $file['size']) . $ext;
$dest = $this->settings['uploadLocation'] . Inflector::tableize($Model->alias) . DS;
if (!file_exists($dest)) {
new Folder($dest, true);
}
move_uploaded_file($file['tmp_name'], $dest . $filename);
$Model->saveField($name, $filename);
}
}
$this->_uploadLater = array();
}
$this->_saving = false;
$Model->data = $Model->findById($Model->id);
return true;
}
示例9: afterSave
/**
* Updates the model's state when a $model->save() call is performed
*
* @param Model $model The model being acted on
* @param boolean $created Whether or not the model was created
* @param array $options Options passed to save
* @return boolean
*/
public function afterSave(Model $model, $created, $options = array())
{
if ($created) {
$model->read();
$model->saveField('state', $model->initialState);
}
return true;
}
示例10: array
/**
* Gets the current schema version from the DB. If schema_info doesn't exist - it tries to create it.
*
* @access protected
* @return int Current schema version
*/
function _getMigrationVersion()
{
//load tables and see if schema_info already exists. If not, create it
$sTables = $this->oMigrations->oDb->listSources();
if (!in_array($this->oMigrations->oDb->config['prefix'] . 'schema_info', $sTables)) {
$this->oMigrations->oDb->query($this->oMigrations->create_table('schema_info', array(0 => 'no_id', 1 => 'no_dates', 'version' => array('type' => 'int', 'length' => 3, 'default' => '0'))));
//feed it with some data
App::import('model');
$oTemp_model = new Model(false, 'schema_info');
$oTemp_model->saveField('version', '0');
$this->iCurrent_version = 0;
} else {
App::import('model');
$oTemp_model = new Model(false, 'schema_info');
$this->iCurrent_version = $oTemp_model->field('version');
}
}
示例11: afterSave
public function afterSave(Model $model, $created, $options = array())
{
$allowed = true;
if (empty($model->data)) {
$model->data = $model->read();
}
if (!empty($this->settings[$model->alias]['scope'])) {
foreach ($this->settings[$model->alias]['scope'] as $field => $value) {
if ($model->data[$model->alias][$field] != $value) {
$allowed = false;
}
}
}
if (!$this->settings[$model->alias]['calendarId']) {
$allowed = false;
}
if (empty($model->data[$model->alias]['title'])) {
$allowed = false;
}
$startTime = false;
$endTime = false;
if ($allowed && !empty($model->data[$model->alias]['date'])) {
$startDate = strtotime($model->data[$model->alias]['date']);
$startDate = date('Y-m-d', $startDate);
if (!empty($model->data[$model->alias]['date_to'])) {
$endDate = strtotime($model->data[$model->alias]['date_to']) + 24 * 3600;
$endDate = date('Y-m-d', $endDate);
} else {
$endDate = strtotime($model->data[$model->alias]['date']) + 24 * 3600;
$endDate = date('Y-m-d', $endDate);
}
}
if ($allowed && !empty($model->data[$model->alias]['days'])) {
date_default_timezone_set('UTC');
$until = gmdate("Ymd\\THis\\Z", strtotime($model->data[$model->alias]['date_to']));
$byDay = implode(',', $model->data[$model->alias]['days']);
$recurrence = array(sprintf('RRULE:FREQ=WEEKLY;UNTIL=%s;BYDAY=%s', $until, $byDay));
$endDate = $startDate;
}
if (empty($startDate) || empty($endDate)) {
$allowed = false;
}
if ($allowed) {
$calendarId = $this->settings[$model->alias]['calendarId'];
$data = array('summary' => $model->data[$model->alias]['title'], 'start' => array('date' => $startDate), 'end' => array('date' => $endDate));
if (!empty($recurrence)) {
$data['recurrence'] = $recurrence;
}
if (!empty($model->data[$model->alias]['content'])) {
$description = $model->data[$model->alias]['content'];
$description = str_replace('<br />', PHP_EOL, $description);
$description = strip_tags($description);
$data['description'] = $description;
}
if (!empty($model->data[$model->alias]['location'])) {
$location = $model->data[$model->alias]['location'];
$location = strip_tags($location);
$data['location'] = $location;
}
if (!empty($model->data[$model->alias]['color_id'])) {
$data['colorId'] = $model->data[$model->alias]['color_id'];
}
$Events = ClassRegistry::init('Google.GoogleCalendarEvents');
if (empty($model->data[$model->alias]['google_event_id'])) {
$saved = $Events->insert($calendarId, $data);
$model->id = $model->data[$model->alias]['id'];
return $model->saveField('google_event_id', $saved['id']);
} else {
$eventId = $model->data['Event']['google_event_id'];
$data['sequence'] = $model->data['Event']['google_event_sequence'] + 1;
$saved = $Events->update($calendarId, $eventId, $data);
if ($saved) {
$model->id = $model->data[$model->alias]['id'];
$model->Behaviors->disable('GoogleCalendarEvent');
return $model->saveField('google_event_sequence', $data['sequence']);
}
}
} else {
if (!$allowed && !empty($model->data[$model->alias]['google_event_id'])) {
$deleteAllowed = true;
if (!$this->settings[$model->alias]['calendarId']) {
$deleteAllowed = false;
}
if (empty($model->data[$model->alias]['google_event_id'])) {
$deleteAllowed = false;
}
if ($deleteAllowed) {
$Events = ClassRegistry::init('Google.GoogleCalendarEvents');
$calendarId = $this->settings[$model->alias]['calendarId'];
$eventId = $model->data[$model->alias]['google_event_id'];
$Events->delete($calendarId, $eventId);
}
}
}
return true;
}
示例12: saveField
public function saveField($name, $value, $validate = false)
{
$this->useMasterDb();
return parent::saveField($name, $value, $validate);
}
示例13: fieldToggle
/**
* Toggle field status
*
* @param $model Model instance
* @param $id integer Model id
* @param $status integer current status
* @param $field string field name to toggle
* @throws CakeException
*/
public function fieldToggle(Model $model, $id, $status, $field = 'status')
{
if (empty($id) || $status === null) {
throw new CakeException(__d('croogo', 'Invalid content'));
}
$model->id = $id;
$status = (int) (!$status);
$this->_controller->layout = 'ajax';
if ($model->saveField($field, $status)) {
$this->_controller->set(compact('id', 'status'));
$this->_controller->render('Common/admin_toggle');
} else {
throw new CakeException(__d('croogo', 'Failed toggling field %s to %s', $field, $status));
}
}
示例14: unDelete
/**
* Método para "desdeletar" uma entrada do modelo.
*
* @param Model $Model
* @param int $id
*/
public function unDelete(&$Model, $id)
{
$Model->id = $id;
return $Model->saveField($this->settings[$Model->alias]['field'], false) !== false;
}
示例15: _moveUpDown
/**
* @param Model $Model
* @param string $direction
* @param int $steps Steps to jump. Defaults to 1.
* @return bool Success
*/
protected function _moveUpDown(Model $Model, $direction, $id, $steps = 1)
{
// FIXME: Sort over more than one placement.
if ($direction === 'down' && empty($this->settings[$Model->alias]['reverse'])) {
$order = '<=';
$findOrder = 'DESC';
} else {
$order = '>=';
$findOrder = 'ASC';
}
$sort = $Model->find('list', array('fields' => array($this->settings[$Model->alias]['field']), 'conditions' => array('id' => $id)));
if (empty($sort)) {
return false;
}
list($sort) = array_values($sort);
$data = $Model->find('list', array('fields' => array('id', $this->settings[$Model->alias]['field']), 'conditions' => array($this->settings[$Model->alias]['field'] . ' ' . $order => $sort), 'order' => array($this->settings[$Model->alias]['field'] => $findOrder), 'limit' => $steps + 1));
$value = end($data);
$key = key($data);
if ($key == $id) {
return;
}
$lastId = $Model->id;
if ($sort == $value) {
if ($direction === 'down' && empty($this->settings[$Model->alias]['reverse'])) {
$value++;
} else {
$value--;
}
}
$Model->id = $key;
$Model->saveField($this->settings[$Model->alias]['field'], $sort);
$Model->id = $id;
$Model->saveField($this->settings[$Model->alias]['field'], $value);
$Model->id = $lastId;
return true;
}