/** * 获得新的知识点的编号 * @param int $exam_type_id * @param int $subject_id * @return string编号 */ public function createNewCode($exam_type_id, $subject_id) { // $dbal = DBAL::insert('knowledge_point_id'); // $dbal->set('primary_exam_type', $exam_type_id); // $dbal->set('subject_id', $subject_id); // $dbal->set('id', '@COUNT:=(1)'); // $dbal->setRawDuplicate('id = @COUNT:=(id + 1)'); // $dbal->execute(); // $dao = $dbal->getDao(); $subjectLoader = new Subject(); $subjects = $subjectLoader->getAllSubjects(); if (!isset($subjects[$subject_id])) { return false; } $subject_code = $subjects[$subject_id]['code']; $examTypeLoader = new ExamType(); $types = $examTypeLoader->getAllTypes(); if (!isset($types[$exam_type_id])) { return false; } $exam_type_code = $types[$exam_type_id]['code']; $dao = DaoFactory::get(); $dao->query("INSERT INTO knowledge_point_id (primary_exam_type, subject_id, id) VALUES ({$exam_type_id}, {$subject_id}, @COUNT:=(1)) ON DUPLICATE KEY UPDATE id = @COUNT:=(id + 1)"); $dao->query('SELECT @COUNT'); $data = $dao->fetch(Dao::FETCH_NUM); $id = $data[0]; if ($id < 1) { throw new SystemException('生成知识点编号失败', $dao); } return sprintf('%s-%s-ZSD-%d', $exam_type_code, $subject_code, $id); }
private function getSubject() { if (!isset($this->subject)) { $subject_id = $this->get('subject_id'); $subjectLoader = new Subject(); $this->subject = $subjectLoader->getTree()->get($subject_id); if (!$this->subject instanceof \APP\Module\Subject\Node) { throw new RuntimeException('不正确的科目id'); } } return $this->subject; }
public function execute() { $request = $this->getRequest(); $action = $request->get(0); switch ($action) { case 'get': $subjectLoader = new Subject(); $subjects = $subjectLoader->getAllSubjects(true); $sub_subjects = $subjectLoader->getSubSubjects(false, true); return $this->send(array('subjects' => $subjects, 'sub_subjects' => $sub_subjects)); break; default: throw new Exception('未知的动作', Exception::CODE_ACTION_NOTFOUND); } }