function question_model_test($delete) { include_once "page_model.php"; $qa_pairs = array("question" => "where would you like to go?", "answers" => array("1" => "left", "2" => "right", "3" => "south")); $question = new QuestionModel(PageModel::first()->id, serialize($qa_pairs), date("Y-m-d H:i:s")); $question->save(); $question->print_fields(); $qa_pairs = array("question" => "Will you open the door?", "answers" => array("1" => "yes", "2" => "no")); $question->set("q_and_a", serialize($qa_pairs)); $question->save(); $question->print_fields(); if ($delete) { $question->delete(); } $qm = QuestionModel::find(QuestionModel::last()->id); $qm->print_fields(); QuestionModel::find(999); }
public function batch_delete() { $ids = $this->input->post('ids'); if (empty($ids) or !is_array($ids)) { message('请选择要删除的项目!'); return; } $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/question_external/index'; $success = $fail = 0; foreach ($ids as $id) { //判断该试题已经被考试过 或 正在被考 $be_tested = QuestionModel::question_has_test_action($id); $this->examine_permission($id); if ($be_tested) { $fail++; continue; } if (QuestionModel::delete($id) === true) { $success++; } else { $fail++; } } message('批量操作完成,成功删除:' . $success . ' 个,失败:' . $fail . ' 个(可能原因:试题已经被考试过 或 正在被考 或 删除失败)。', $back_url); }
public function DeleteAction() { $request = Project::getRequest(); $user_id = (int) Project::getUser()->getDbUser()->id; $question_model = new QuestionModel(); $question_model->load($request->getKeyByNumber(0)); if ($question_model->user_id == $user_id) { $question_model->delete($request->getKeyByNumber(0)); } Project::getResponse()->redirect($request->createUrl('QuestionAnswer', 'UserQuestions')); }
public function deleteAction() { $questionid = $this->getRequest()->getParam('questionid', '0'); //删除问题 $questiontable = new QuestionModel(); $db = $questiontable->getAdapter(); $where = $db->quoteInto('id = ?', $questionid); $flag0 = $questiontable->delete($where); //删除回复 $answertable = new AnswerModel(); $db1 = $answertable->getAdapter(); $where = $db1->quoteInto('questionid = ?', $questionid); $answertable->delete($where); //查看是否删除干净 $flag1 = count($db1->query('SELECT * FROM answer WHERE questionid = ?', $questionid)->fetchAll()); if ($flag0 > 0 && $flag1 == 0) { $this->view->info = 'success'; } else { $this->view->info = 'fail'; } $this->_forward('result4', 'globals'); }
public function DeleteQuestionAction() { $request = Project::getRequest(); if ($request->getKeyByNumber(0) > 0) { $model = new QuestionModel(); $model->delete((int) $request->getKeyByNumber(0)); } Project::getResponse()->Redirect($request->createUrl('AdminQuestionAnswer', 'QuestionList')); }
public function batch_delete() { if (!$this->check_power('question_delete')) { return; } $ids = $this->input->post('ids'); if (empty($ids) or !is_array($ids)) { message('请选择要删除的项目!'); return; } $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/question/index'; $success = $fail = 0; foreach ($ids as $id) { $has_edit_power = QuestionModel::check_question_power($id, 'w', false); //判断该试题已经被考试过 或 正在被考 $be_tested = QuestionModel::question_has_test_action($id); if ($be_tested || !$has_edit_power) { $fail++; continue; } if (QuestionModel::delete($id) === true) { $success++; } else { $fail++; } } message('批量操作完成,成功删除:' . $success . ' 个,失败:' . $fail . ' 个(可能原因:试题已经被考试过 或 正在被考 或 删除失败)。', $back_url); }