本文整理汇总了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']));
}