本文整理匯總了PHP中DataObjectCollection::update方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataObjectCollection::update方法的具體用法?PHP DataObjectCollection::update怎麽用?PHP DataObjectCollection::update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DataObjectCollection
的用法示例。
在下文中一共展示了DataObjectCollection::update方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sendBack
function save_field()
{
if (!isset($this->_data['DatasetField'])) {
$this->dataError();
sendBack();
}
$dataset = $this->_uses[$this->modeltype];
$data = $this->_data['DatasetField'];
$data['old_name'] = $data['name'];
$data['name'] = strtolower(str_replace(' ', '_', $data['title']));
if (!empty($data['module_component_id'])) {
$data['name'] .= '_id';
$data['type'] = $dataset::get_fk_field_type();
}
$booleans = array('mandatory', 'searchable', 'display_in_list');
foreach ($booleans as $field) {
if (!isset($data[$field])) {
$data[$field] = FALSE;
} else {
$data[$field] = TRUE;
}
}
$db = DB::Instance();
$flash = Flash::Instance();
$errors = array();
if (empty($data['id'])) {
$action = 'add';
} else {
$action = 'alter';
$current_field = DataObjectFactory::Factory('DatasetField');
$current_field->load($data['id']);
}
$db->StartTrans();
$dataset->load($data['dataset_id']);
if ($data['mandatory']) {
$model = $this->newModel($dataset);
$cc = new ConstraintChain();
if ($action == 'alter') {
$cc->add(new Constraint($data['name'], 'IS', 'NULL'));
}
if ($model->getCount($cc) > 0) {
if (!$action == 'alter') {
$errors[] = 'Data exists so first add the field then make it mandatory';
} elseif ($data['default_value'] == '') {
$errors[] = 'Default Value required to make this field mandatory';
} else {
$collection = new DataObjectCollection($model);
$sh = new SearchHandler($collection);
$sh->addConstraintChain($cc);
if (!$collection->update($data['name'], $data['default_value'], $sh)) {
$errors[] = 'Error updating existing data for ' . $data['title'] . ' with default value';
}
}
}
}
$datasetfield = DataObject::Factory($data, $errors, 'DatasetField');
// TODO: if this is an update, only change table if field details have changed
// otherwise do the change table to add the new field
if (count($errors) > 0 || !$datasetfield || !$datasetfield->save() || !$this->change_table($data, $action)) {
$errors[] = 'Error ' . (action == 'alter' ? 'updating' : 'inserting') . ' ' . $data['title'] . ' field definition : ' . $db->ErrorMsg();
$db->FailTrans();
$db->CompleteTrans();
} else {
$db->CompleteTrans();
$this->createOverview($dataset, $errors);
}
if (count($errors) > 0) {
$flash->addErrors($errors);
} else {
$flash->addMessage('"' . $data['title'] . '" field saved OK');
}
sendTo($this->name, 'view', $this->_modules, array($dataset->idField => $data['dataset_id']));
}