/** * 批量删除试卷中的试题 * * @param int $paper_id 试卷id * @param int $ids 试卷中的试题id * @return void */ public function batch_delete() { if (!$this->check_power('exam_manage')) { return; } $paper_id = (int) $this->input->post('paper_id'); $ids = $this->input->post('ids'); if (empty($ids) or !is_array($ids)) { message('请选择要操作的项目!'); return; } $paper = PaperModel::get_paper_by_id($paper_id); if (!$paper) { message('试卷不存在'); return; } $exam_pid = ExamModel::get_exam($paper['exam_id'], 'exam_pid'); $is_mini_test = ExamModel::is_mini_test($exam_pid); //判断该试卷已经被考试过 或 正在被考 $count_fail = 0; $count_success = 0; $tmp_ids = array(); foreach ($ids as $ques_id) { if (!$is_mini_test) { $be_tested = QuestionModel::paper_question_has_been_tested($paper_id, $ques_id); if ($be_tested) { $count_fail++; continue; } } $tmp_ids[] = $ques_id; $count_success++; } $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/exam_question/index/' . $paper_id; $this->db->where_in('id', $tmp_ids)->delete('exam_question'); ExamPaperModel::renew($paper_id); if ($is_mini_test && $count_success) { SummaryModel::summary_paper($exam_pid, 0, $paper_id, true); } message("批量操作完成(成功 {$count_success}个,失败 {$count_fail} 个)", $back_url); }