/** * 试卷列表 */ function listAction() { $pagesize = 15; $courseId = (int) $this->get('course_id', 0); $paperId = (int) $this->get('paper_id', 0); $type = (int) $this->get('type', 0); $courseModel = new CourseModel(); $course = $courseModel->getCourse($courseId); if (!$course) { $this->redirect("/error/?errno=" . Common_Error::ERROR_COURSE_NOT_EXISTS); } $schoolModel = new SchoolModel(); $school = $schoolModel->getSchool($course['school_id']); if (!$school) { $this->redirect("/error/?errno=" . Common_Error::ERROR_SCHOOL_NOT_EXISTS); } $paperModel = new PaperModel(); //$list = $paperModel -> getList($courseId, $paperId, $type, $pagesize); $list = $paperModel->getAll($courseId); if (!$list) { $this->redirect("/error/?errno=" . Common_Error::ERROR_COURSE_NOT_EXISTS); } $courseModel = new CourseModel(); $practiseList = $courseModel->getCoursePractiseList($courseId); $uSecList = $courseModel->getUserCourseSection($this->uid, $courseId); $uSectionIds = $uSecList ? array_keys($uSecList) : array(); foreach ($list as $k => $section) { $list[$k] = array('id' => $section['id'], "name" => $section['name']); $list[$k]['last'] = isset($uSectionIds[0]) && $section['id'] == $uSectionIds[0] ? 1 : 0; $list[$k]['practise_video_list'] = isset($practiseList[$section['id']]) ? $practiseList[$section['id']] : array(); if (empty($list[$k]['practise_video_list'])) { $list[$k]['practise_video_list_for_android'] = array(); continue; } foreach ($list[$k]['practise_video_list'] as $seq => $videoId) { $list[$k]['practise_video_list_for_android'][] = array("practise_seq" => $seq, "practise_video_id" => $videoId); } } if ($this->isMobile) { $this->displayJson(Common_Error::ERROR_SUCCESS, $list); } $course['practise_num'] = $courseModel->getCoursePractiseNum($courseId); $course['user_practise_num'] = $courseModel->getUserCoursePractiseNum($this->uid, $courseId); $course['duration_minute'] = round($paperModel->getPaperDuration($courseId) / 60, 0); $course['user_spend_minute'] = round($paperModel->getUserPaperDuration($this->uid, $courseId) / 60, 0); $course['teachers'] = $courseModel->getCourseTeachers($courseId); $this->assign("school", $school); $this->assign("course", $course); $this->assign('paper_list', $list); }
/** * android版课程章节列表 */ function infoForAndroidAction() { $courseId = (int) $this->get('course_id', 0); if (!$courseId) { $this->displayJson(Common_Error::ERROR_PARAM); } $practiseModel = new PractiseModel(); $courseModel = new CourseModel(); $noteModel = new NoteModel(); $course = $courseModel->getCourse($courseId); if (!$course) { $this->displayJson(Common_Error::ERROR_PARAM); } $chapterList = $courseModel->getChapterList($course['id']); $sectionList = $courseModel->getSectionList($course['id']); if ($this->uid) { //用户已学节 $uSecList = $courseModel->getUserCourseSection($this->uid, $courseId); $uPracList = $courseModel->hasCoursePractiseFinished($this->uid, $courseId); $userSpendTime = 0; if ($uSecList) { $uSectionIds = array_keys($uSecList); //sectionList是一个1:N的章节关系 foreach ($sectionList as &$chapter) { foreach ($chapter as &$section) { //各章节的状态 $section['type'] = 2; $section['practise_num'] = $practiseModel->getSectionPractiseNum($section['id']); $section['note_num'] = $noteModel->getSectionNoteNum($section['id']); $section['finished'] = isset($uSecList[$section['id']]) ? 1 : 0; $section['practise_finished'] = isset($uPracList[$section['id']]) ? 1 : 0; $section['last'] = $section['id'] == @$uSectionIds[0] ? 1 : 0; $userSpendTime += isset($uSecList[$section['id']]) ? $section['duration'] : 0; } } unset($chapter); unset($section); } //用户习题 $course['user_practise_num'] = $courseModel->getUserCoursePractiseNum($this->uid, $course['id']); //学习时长 $course['user_spend_time'] = $userSpendTime; } //章节合并 $data = array(); foreach ($chapterList as $chapter) { $chapter['practise_num'] = $practiseModel->getSectionPractiseNum($chapter['id']); $chapter['practise_finished'] = isset($uPracList[$chapter['id']]) ? 1 : 0; $chapter['type'] = 1; $data[] = $chapter; foreach ($sectionList[$chapter['id']] as &$sec) { $sec['open_time_remain'] = $chapter['open_time_remain']; } unset($sec); $data = array_merge($data, $sectionList[$chapter['id']]); } if ($this->isMobile) { $this->displayJson(Common_Error::ERROR_SUCCESS, $data); } }