Exemplo n.º 1
0
 /**
  * 删除图度
  */
 public function deleteAction()
 {
     // 删除图度权限
     if (!$this->_user->getAccess()->isAllowed(Tudu_Access::PERM_DELETE_TUDU)) {
         return $this->json(false, $this->lang['perm_deny_delete_tudu']);
     }
     $tuduIds = (array) $this->_request->getParam('tid');
     // 参数:图度ID必须存在
     if (!count($tuduIds)) {
         return $this->json(false, $this->lang['invalid_tuduid']);
     }
     // 获得图度数据
     $tudus = $this->manager->getTudusByIds($tuduIds);
     $boards = $this->getBoards(false);
     $trueTuduIds = array();
     //用于记录删除成功的图度ID
     foreach ($tudus as $tudu) {
         if (!$boards[$tudu->boardId]) {
             continue;
         }
         // 版主与超级版主的权限检测
         $isModerator = array_key_exists($this->_user->userId, $boards[$tudu->boardId]['moderators']);
         $isSuperModerator = false;
         if (!empty($boards[$tudu->boardId]['parentid'])) {
             $parentId = $boards[$tudu->boardId]['parentid'];
             $isSuperModerator = array_key_exists($this->_user->userId, $boards[$parentId]['moderators']);
         }
         if ($tudu->sender == $this->_user->userName || $isModerator || $isSuperModerator) {
             // 当删除的事图度组的时候,判断图度组下是否有子图度
             if ($tudu->isTuduGroup && $this->manager->getChildrenCount($tudu->tuduId) > 0) {
                 return $this->json(false, sprintf($this->lang['delete_not_null_tudugroup'], $tudu->subject));
             }
             // 删除操作
             $ret = $this->manager->deleteTudu($tudu->tuduId);
             if ($ret) {
                 // 记录删除成功的图度ID
                 $trueTuduIds[] = $tudu->tuduId;
                 if ($tudu->parentId) {
                     // 计算父级图度的进度
                     $this->manager->calParentsProgress($tudu->parentId);
                     // 更新节点信息
                     if ($this->manager->getChildrenCount($tudu->parentId) <= 0) {
                         $this->manager->updateNode($tudu->parentId, array('type' => Dao_Td_Tudu_Group::TYPE_LEAF));
                     }
                 }
                 // 添加操作日志
                 $this->_writeLog(Dao_Td_Log_Log::TYPE_TUDU, $tudu->tuduId, Dao_Td_Log_Log::ACTION_DELETE);
             }
         }
     }
     if (!count($trueTuduIds)) {
         return $this->json(false, $this->lang['tudu_delete_failure']);
     }
     return $this->json(true, $this->lang['tudu_delete_success'], $trueTuduIds);
 }