Esempio n. 1
0
 /**
  * 标记为
  */
 public function markAction()
 {
     $tuduIds = (array) $this->_request->getParam('tid');
     $alias = (array) $this->_request->getParam('label');
     $isRead = $this->_request->getParam('read');
     $fun = $this->_request->getParam('fun');
     $uniqueId = $this->_user->uniqueId;
     $data = null;
     switch ($fun) {
         case 'read':
         case 'unread':
             // 参数:图度ID必须存在
             if (!count($tuduIds)) {
                 return $this->json(false, $this->lang['invalid_tuduid']);
             }
             foreach ($tuduIds as $tuduId) {
                 $this->manager->markRead($tuduId, $uniqueId, 'read' == $fun);
             }
             break;
         case 'allread':
             // 参数:标签ID必须存在
             if (!count($alias)) {
                 return $this->json(false, $this->lang['invalid_labelid']);
             }
             $labelIds = array();
             $labels = $this->getLabels();
             foreach ($alias as $a) {
                 if (isset($labels[$a]) && (!$labels[$a]['issystem'] || $fun == 'allread')) {
                     $labelIds[] = $labels[$a]['labelid'];
                 }
             }
             // 设置标签下所有图度为已读
             foreach ($labelIds as $labelId) {
                 $this->manager->markLabelRead($labelId, $uniqueId, $isRead);
             }
             // 统计标签图度数
             foreach ($labels as $label) {
                 $this->manager->calculateLabel($uniqueId, $label['labelid']);
             }
             break;
         default:
             break;
     }
     $data = null;
     if ($fun != 'allread') {
         $this->_labels = null;
         $labels = $this->getLabels(null);
         $data = array();
         foreach ($labels as $index => $label) {
             // 过滤“所有图度”与“已审批”标签
             if ($labels[$index]['labelalias'] == 'all' || $labels[$index]['labelalias'] == 'reviewed') {
                 continue;
             }
             $labels[$index]['labelname'] = $labels[$index]['issystem'] ? $this->lang['label_' . $labels[$index]['labelalias']] : $labels[$index]['labelalias'];
             $data[] = $labels[$index];
         }
     }
     return $this->json(true, $this->lang['mark_success'], $data);
 }