当前位置: 首页>>代码示例>>PHP>>正文


PHP DataObjectCollection::update方法代码示例

本文整理汇总了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']));
 }
开发者ID:uzerpllp,项目名称:uzerp,代码行数:73,代码来源:DatasetsController.php


注:本文中的DataObjectCollection::update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。