Beispiel #1
0
 /**
  * 回答
  */
 function answerAction()
 {
     $practiseModel = new PractiseModel();
     $rs = $practiseModel->isUserPractiseFinished($this->uid, $this->sectionId);
     //不能重复答题
     if ($rs) {
         $this->displayJson(Common_Error::ERROR_PRACTISE_HAS_BEEN_DONE);
     }
     //回答的时候一定要按题目的排序插入.!!!!
     $answerList = $this->post("answer", 0);
     $spendTime = (int) $this->post("spend_time", 0);
     if (!$answerList || !$spendTime) {
         $this->displayJson(Common_Error::ERROR_PARAM);
     }
     $answerList = explode(",", $answerList);
     $result = array();
     foreach ($answerList as $answer) {
         list($practiseId, $optionId) = explode("_", $answer);
         $result[$practiseId] = $optionId;
     }
     $practiseModel = new PractiseModel();
     $practiseList = $practiseModel->getSectionPractiseList($this->sectionId);
     $full = array();
     foreach ($practiseList as $practise) {
         $full[$practise['practise_id']] = isset($result[$practise['practise_id']]) ? $result[$practise['practise_id']] : 0;
     }
     $correctNum = 0;
     foreach ($full as $practiseId => $optionId) {
         //正确答案
         $answerId = $practiseModel->getPractiseAnswerId($practiseId);
         $id = $practiseModel->insertAnswer($this->sectionId, $this->uid, (int) $practiseId, (int) $optionId, $answerId);
         if ($optionId != 0 && $practiseModel->check($practiseId, $optionId)) {
             $correctNum++;
         }
     }
     $practiseModel->insertUserPractise($this->uid, $this->course['id'], $this->sectionId, $spendTime, $correctNum);
     $this->displayJson(Common_Error::ERROR_SUCCESS);
 }
Beispiel #2
0
 /**
  * 发表评论
  * curl -d "course_id=1&comment_id=1&video_id=0&content=helloaaaaaaaaaa" http://182.92.110.119/comment/publish
  */
 function publishAction()
 {
     $courseId = (int) $this->post("course_id", 0);
     $commentId = (int) $this->post("comment_id", 0);
     $videoId = (int) $this->post("video_id", 0);
     $content = $this->post("content", "");
     $time = time();
     $comment = array("uid" => $this->uid, "comment_id" => $commentId, "course_id" => $courseId, "video_id" => $videoId, "content" => $content, "create_time" => $time);
     $commentModel = new CommentModel();
     $id = $commentModel->insertComment($comment);
     if ($id) {
         $userModel = new UserModel();
         $videoModel = new VideoModel();
         $courseModel = new CourseModel();
         $author = $userModel->getUser($comment['uid']);
         $comment['create_time_fmt'] = Common_Time::flow($comment['create_time']);
         $comment['author_uid'] = $author['stuff_id'];
         $comment['author_name'] = $author['stuff_name'];
         $comment['author_avator'] = $author['avator'];
         if ($comment['comment_id']) {
             $parentComment = $commentModel->getComment($comment['comment_id']);
             $beReplyAuthor = $userModel->getUser($parentComment['uid']);
             $parentComment['author_uid'] = $beReplyAuthor['stuff_id'];
             $parentComment['author_name'] = $beReplyAuthor['stuff_name'];
             $parentComment['author_avator'] = $beReplyAuthor['avator'];
             $parentComment['create_time_fmt'] = Common_Time::flow($parentComment['create_time']);
             $comment['parent_comment'] = $parentComment;
         }
         if ($comment['video_id']) {
             $section = $videoModel->getVideoBelongSection($comment['video_id']);
             if (!$section) {
                 $practiseModel = new PractiseModel();
                 $practise = $practiseModel->getVideoBelongPractise($comment['video_id'], $courseId);
                 $comment['practise_seq'] = $practise['seq'];
                 $section = $courseModel->getSection($practise['section_id']);
             }
             $chapter = $courseModel->getSection($section["parent_id"]);
             $comment["chapter_id"] = $chapter["id"];
             $comment["chapter_name"] = $chapter["name"];
             $comment["chapter_seq"] = $chapter["seq"];
             $comment["section_id"] = $section["id"];
             $comment["section_name"] = $section["name"];
             $comment["section_seq"] = $section["seq"];
             $userVideo = $videoModel->getUserVideoVote($comment['uid'], $comment['video_id']);
             $comment["video_like"] = isset($userVideo['like_type']) ? $userVideo['like_type'] : 0;
         }
         $this->displayJson(Common_Error::ERROR_SUCCESS, array($comment));
     }
     $this->displayJson(Common_Error::ERROR_MYSQL_EXECUTE);
 }
Beispiel #3
0
 /**
  * web专用
  */
 function examAction()
 {
     $seq = (int) $this->get('seq', 1);
     $practiseModel = new PractiseModel();
     $practise = $practiseModel->getPractiseBySeq($this->sectionId, $seq);
     //需要验证是否有错题
     if (!$practise) {
         $this->redirect("/error/?errno=" . Common_Error::ERROR_PRACTISE_NOT_EXISTS);
     }
     $id = $practiseModel->insertAnswer($this->sectionId, $this->uid, $practise['practise_id'], 0, 0);
     $tree = $practise['nested_node_tree'];
     $data = array("subject_id" => $practise["item_id"], "subject_seq" => $seq, "answer" => $practise['answer'], "parse" => $practise['parse'], "video_id" => $practise['video_id'], "type_name" => $practise['type_name']);
     $data["subject_title"] = in_array($practise['type_name'], Common_Config::$practiseChoice) ? $practise["nested_content_raw"][0]['content'] : $practiseModel->getSubject($practise["nested_content_raw"]);
     $practiseNum = $practiseModel->getSectionPractiseNum($this->sectionId);
     $data["subject_num"] = $practiseNum;
     $data["section_id"] = $this->sectionId;
     if (in_array($practise['type_name'], Common_Config::$practiseChoice)) {
         foreach ($tree['nested_node_children'] as $option) {
             $letter = chr(320 + $option["node_index"]);
             $data['option_list'][] = array("id" => $option["node_index"], "letter_seq" => $letter, "content" => $option["node_content"]);
         }
     }
     if ($this->ajax) {
         $this->displayJson(Common_Error::ERROR_SUCCESS, $data);
     }
     $this->assign("practise", $data);
     $this->assign("section", $this->section);
     if ($this->platform == 'ios' || $this->platform == 'android') {
         $this->getView()->display("practise/exam-app.phtml");
         exit;
     }
 }
Beispiel #4
0
 /**
  * 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);
     }
 }