Пример #1
0
 function listAction()
 {
     $pagesize = 15;
     $courseId = (int) $this->get('course_id', 0);
     $type = (int) $this->get('type', 0);
     $page = (int) $this->get('page', 1);
     $schoolId = (int) $this->get('school_id', 0);
     if ($schoolId < 1) {
         $this->redirect("/error/?errno=" . Common_Error::ERROR_PARAM);
     }
     //查询学校
     $schoolModel = new SchoolModel();
     $school = $schoolModel->getSchool($schoolId);
     if (empty($school)) {
         $this->redirect("/error/?errno=" . Common_Error::ERROR_SCHOOL_NOT_EXISTS);
     }
     $courseModel = new CourseModel();
     if ($this->isMobile) {
         $list = $courseModel->getCourseListById($schoolId, $courseId, $type, $pagesize, $this->uid);
     } else {
         $data = $courseModel->getList($schoolId, $page, $pagesize, $this->uid);
         $list = $data['list'];
     }
     if ($this->uid && $list) {
         $courseIds = array();
         foreach ($list as $course) {
             $courseIds[] = $course['id'];
         }
         $lastLearn = $courseModel->getUserCourseLastSection($this->uid, $courseIds);
         foreach ($list as &$course) {
             $course['last_section_id'] = (int) @$lastLearn[$course['id']]['last_section_id'];
             $course['last_section_name'] = (string) @$lastLearn[$course['id']]['last_section_name'];
             $course['last_section_seq'] = (int) @$lastLearn[$course['id']]['last_section_seq'];
             $course['last_chapter_id'] = (int) @$lastLearn[$course['id']]['last_chapter_id'];
             $course['last_chapter_name'] = (string) @$lastLearn[$course['id']]['last_chapter_name'];
             $course['last_chapter_seq'] = (int) @$lastLearn[$course['id']]['last_chapter_seq'];
         }
         unset($course);
     }
     if ($this->isMobile) {
         $this->displayJson(Common_Error::ERROR_SUCCESS, $list);
     }
     $this->assign('school', $school['name']);
     $this->assign('course_list', $list);
     $this->assign('course_count', $data['count']);
     $this->assign('page_count', ceil($data['count'] / $pagesize));
 }