public function update()
 {
     /* 检查文档类型是否符合要求 */
     $Model = new \Admin\Model\DocumentModel();
     $res = $Model->checkDocumentType(I('type'), I('pid'));
     if (!$res['status']) {
         $this->error = $res['info'];
         return false;
     }
     /* 获取数据对象 */
     $data = $this->field('pos,display', true)->create();
     if (empty($data)) {
         return false;
     }
     /* 添加或新增基础内容 */
     if (empty($data['id'])) {
         //新增数据
         $id = $this->add();
         //添加基础内容
         if (!$id) {
             $this->error = '添加基础内容出错!';
             return false;
         }
         $data['id'] = $id;
     } else {
         //更新数据
         $status = $this->save();
         //更新基础内容
         if (false === $status) {
             $this->error = '更新基础内容出错!';
             return false;
         }
     }
     /* 添加或新增扩展内容 */
     $logic = $this->logic($data['model_id']);
     if (!$logic->update($data['id'])) {
         if (isset($id)) {
             //新增失败,删除基础数据
             $this->delete($data['id']);
         }
         $this->error = $logic->getError();
         return false;
     }
     //内容添加或更新完成
     return $data;
 }
Пример #2
0
 public function update($data = null)
 {
     /* 检查文档类型是否符合要求 */
     $Model = new \Admin\Model\DocumentModel();
     $res = $Model->checkDocumentType(I('type', 2), I('pid'));
     if (!$res['status']) {
         $this->error = $res['info'];
         return false;
     }
     /* 获取数据对象 */
     $data = $this->create($data);
     if (empty($data)) {
         return false;
     }
     /* 添加或新增基础内容 */
     if (empty($data['id'])) {
         //新增数据
         $id = $this->add();
         //添加基础内容
         if (!$id) {
             $this->error = '新增基础内容出错!';
             return false;
         }
     } else {
         //更新数据
         $status = $this->save();
         //更新基础内容
         if (false === $status) {
             $this->error = '更新基础内容出错!';
             return false;
         }
     }
     /* 添加或新增扩展内容 */
     $logic = $this->logic($data['model_id']);
     if (!$logic->update($id)) {
         if (isset($id)) {
             //新增失败,删除基础数据
             $this->delete($id);
         }
         $this->error = $logic->getError();
         return false;
     }
     hook('documentSaveComplete', array('model_id' => $data['model_id']));
     //行为记录
     if ($id) {
         action_log('add_document', 'document', $id, UID);
     }
     //内容添加或更新完成
     return $data;
 }