コード例 #1
0
 /**
  * 丢弃草稿
  */
 public function discardAction()
 {
     $tuduIds = (array) $this->_request->getParam('tid');
     // 参数:图度ID必须存在
     if (!count($tuduIds)) {
         return $this->json(false, $this->lang['invalid_tuduid']);
     }
     // 获得图度数据
     $tudus = $this->manager->getTudusByIds($tuduIds)->toArray();
     $trueTuduIds = array();
     //用于记录删除成功的图度ID
     foreach ($tudus as $tudu) {
         // 当前图度必须是草稿,且操作人必须图度的发起人
         if ($tudu['isdraft'] && strcasecmp($tudu['sender'], $this->_user->userName) == 0) {
             // 当前图度是图度组
             if ($tudu['istudugroup']) {
                 $children = $this->manager->getTudus(array('parentid' => $tudu['tuduid']))->toArray();
                 foreach ($children as $child) {
                     // 执行删除子图度操作
                     $this->manager->deleteTudu($child['tuduid']);
                 }
             }
             // 执行删除操作
             $this->manager->deleteTudu($tudu['tuduid']);
             $trueTuduIds[] = $tudu['tuduid'];
         }
     }
     if (!count($trueTuduIds)) {
         return $this->json(false, $this->lang['tudu_delete_failure']);
     }
     return $this->json(true, null, $trueTuduIds);
 }