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


PHP DataObjectCollection::delete方法代码示例

本文整理汇总了PHP中DataObjectCollection::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectCollection::delete方法的具体用法?PHP DataObjectCollection::delete怎么用?PHP DataObjectCollection::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataObjectCollection的用法示例。


在下文中一共展示了DataObjectCollection::delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save_selection

 public function save_selection()
 {
     $flash = Flash::Instance();
     $db = DB::Instance();
     $errors = array();
     $db->StartTrans();
     $type = $this->_data['type'];
     $output_details = $this->output_types[$type];
     $selected = empty($_SESSION['selected_output'][$type]) ? array() : $_SESSION['selected_output'][$type];
     $header_data = array();
     $header_data = $this->_data;
     if (!empty($this->_data['output_header_id'])) {
         $header_id = $this->_data['output_header_id'];
         $detail = new DataObjectCollection(DataObjectFactory::Factory('OutputDetail'));
         $sh = new SearchHandler($detail, FALSE);
         $sh->addConstraintChain(new Constraint('output_header_id', '=', $header_id));
         $detail->delete($this->_data['output_header_id']);
         $header_data['id'] = $header_id;
     }
     $header_data['class'] = $this->modeltype;
     $header_data['process'] = $output_details['printaction'];
     $header = DataObject::Factory($header_data, $errors, 'OutputHeader');
     if ($header && $header->save() && count($errors) == 0) {
         $header_id = $header->id;
         $lines_data = array();
         foreach ($selected as $id => $value) {
             if ($value['select'] == 'true') {
                 $value['output_header_id'] = $header_id;
                 $value['select_id'] = $id;
                 $lines_data[] = $value;
             }
         }
         foreach ($lines_data as $line_data) {
             $line = DataObject::Factory($line_data, $errors, 'OutputDetail');
             if (!$line || count($errors) > 0 || !$line->save()) {
                 $errors[] = 'Error saving output detail';
                 break;
             }
         }
     } else {
         $errors[] = 'Error saving output header';
     }
     if (count($errors) > 0) {
         $flash->addErrors($errors);
         $db->FailTrans();
         $db->CompleteTrans();
         $this->refresh();
     } else {
         $db->CompleteTrans();
         $_SESSION['selected_output'][$type] = array();
         sendTo($this->name, 'output_summary', $this->_modules, array('type' => $type));
     }
 }
开发者ID:uzerpllp,项目名称:uzerp,代码行数:53,代码来源:printController.php

示例2: save_relationships

 public function save_relationships()
 {
     $flash = Flash::Instance();
     $errors = array();
     $itemlink = array();
     $selectedlinks = array();
     $db = DB::Instance();
     $db->StartTrans();
     $selected_items = $_SESSION['selected_items']['data'];
     $deleted_items = $_SESSION['selected_items']['delete'];
     $selected_targets = $_SESSION['selected_targets']['data'];
     $deleted_targets = $_SESSION['selected_targets']['delete'];
     if (!empty($deleted_targets) || !empty($deleted_items)) {
         // Need to delete any relationship that are just about to be saved
         $do = new DataObject($this->linkTableName);
         $doc = new DataObjectCollection($do);
         $sh = new SearchHandler($doc, false);
         $cc1 = new ConstraintChain();
         if (!empty($deleted_targets)) {
             $cc1->add(new Constraint('item_id', 'IN', '(' . implode(',', array_keys($selected_items)) . ')'));
             $cc1->add(new Constraint('target_id', 'IN', '(' . implode(',', array_keys($deleted_targets)) . ')'));
         }
         $cc2 = new ConstraintChain();
         if (!empty($deleted_items)) {
             $cc2->add(new Constraint('item_id', 'IN', '(' . implode(',', array_keys($deleted_items)) . ')'));
             $cc2->add(new Constraint('target_id', 'IN', '(' . implode(',', array_keys($selected_targets)) . ')'));
         }
         $sh->addConstraint($cc1);
         $sh->addConstraint($cc2, 'OR');
         $deleted = $doc->delete($sh);
         if ($deleted > 0) {
             $flash->addWarning($deleted . ' relationships deleted');
         }
     }
     $selectedlinks = array();
     foreach ($selected_items as $item_key => $item_data) {
         foreach ($selected_targets as $target_key => $target_data) {
             $do = new DataObject($this->linkTableName);
             $cc = new ConstraintChain();
             $cc->add(new Constraint('item_id', '=', $item_key));
             $cc->add(new Constraint('target_id', '=', $target_key));
             $do->loadBy($cc);
             if (!$do->isLoaded()) {
                 // Only save links that do not exist
                 $selectedlinks[] = array('item_id' => $item_key, 'target_id' => $target_key);
             }
         }
     }
     if (count($selectedlinks) > 0) {
         $result = SelectorCollection::saveAssociations($selectedlinks, $this->linkTableName, $errors);
     } else {
         $flash->addWarning('These relationships already exist - no data saved');
         $result = true;
     }
     if ($result) {
         $db->CompleteTrans();
         unset($_SESSION['selected_items']);
         unset($_SESSION['selected_targets']);
         $flash->addMessage(count($selectedlinks) . " relationships saved successfully");
         sendTo($this->name, 'index', $this->_modules);
     } else {
         $db->FailTrans();
         $db->CompleteTrans();
         $flash->addErrors($errors);
         $flash->addError("Error saving relationships");
         sendTo($this->name, 'confirm_relationships', $this->_modules);
     }
 }
开发者ID:uzerpllp,项目名称:uzerp,代码行数:68,代码来源:SelectorController.php


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