示例#1
0
 /**
  * 批量删除留言
  */
 public function batch_delete()
 {
     //初始化返回数据
     $return_data = array();
     //请求结构体
     $request_data = array();
     /* 可管理的站点ID列表 */
     $loginfo = Role::get_manager();
     try {
         if ($this->manager_is_admin != 1) {
             remind::set(Kohana::lang('o_global.permission_enough'), 'manage/message');
         }
         $message_ids = $this->input->post('message_id');
         if (is_array($message_ids) && count($message_ids) > 0) {
             $message_service = MessageService::get_instance();
             /* 删除失败的 */
             $failed_message_names = '';
             foreach ($message_ids as $message_id) {
                 if (!$message_service->remove($message_id)) {
                     $failed_message_names .= ',' . $message_id;
                 }
             }
             if (empty($failed_message_names)) {
                 $return_struct['action'] = array('type' => 'location', 'url' => url::base() . 'manage/message/');
                 throw new MyRuntimeException(Kohana::lang('o_manage.delete_message_success'), 403);
             } else {
                 /* 中转提示页面的停留时间 */
                 $return_struct['action']['time'] = 10;
                 $failed_message_names = trim($failed_message_names, ',');
                 throw new MyRuntimeException(Kohana::lang('o_manage.delete_message_error', $failed_message_names), 403);
             }
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.data_load_error'), 403);
         }
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->is_ajax_request()) {
             $this->template = new View('layout/empty_html');
             $this->template->content = $return_struct['msg'];
         } else {
             $this->template->return_struct = $return_struct;
             $content = new View('info');
             $this->template->content = $content;
             /* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             /* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
     }
 }