예제 #1
0
 public function refreshAllNumbers($courseId)
 {
     $chapters = Chapter::model()->findAllByAttributes(array('courseId' => intval($courseId)), array('order' => 'weight asc'));
     $count = count($chapters);
     for ($i = 0; $i < $count; $i++) {
         //$chapters[$i]->update(array('number'=>$i+1));
         $chapters[$i]->number = $i + 1;
         $chapters[$i]->save();
     }
 }
예제 #2
0
 /**
  * @param integer $book_id
  * @param integer $chap_id
  * @param bool $check_can_read
  * @throws CHttpException
  * @internal param string $class
  * @return Chapter
  */
 protected function loadChapter($book_id, $chap_id, $check_can_read = true)
 {
     $book_id = (int) $book_id;
     $chap_id = (int) $chap_id;
     $chap = Chapter::model()->with("book.membership")->findByPk((int) $chap_id);
     if (!$chap) {
         throw new CHttpException(404, "Главы не существует. Возможно, она была удалена. <a href='/book/{$book_id}/'>Вернуться к оглавлению перевода</a>.");
     }
     if ($chap->book->id != $book_id) {
         $this->redirect($chap->book->getUrl($chap_id));
     }
     // ac_read для всего перевода. Если нельзя в весь перевод, редиректим в оглавление перевода, пусть контроллер Book объясняет, почему да как.
     if (!$chap->book->can("read")) {
         $this->redirect($chap->book->url);
     }
     if ($chap->book->opts_get(Book::OPTS_BAN_COPYRIGHT)) {
         $chap->book->facecontrol = Book::FC_INVITE;
         foreach (Yii::app()->params["ac_areas"] as $ac => $title) {
             if ($chap->book->{$ac} == "a") {
                 $chap->book->{$ac} = "g";
             }
         }
         $reason = BookBanReason::model()->findByPk($chap->book->id);
         if (!$reason) {
             $reason = new BookBanReason();
         }
         if (!$chap->book->can("read")) {
             throw new CHttpException(403, "Сожалеем, но этот перевод заблокирован по заявке правообладателей.");
         }
     }
     // ac_read для этой главы
     if ($check_can_read && !$chap->can("read")) {
         $msg = $chap->deniedWhy;
         $msg .= "<br /><br /><a href='{$chap->book->url}'>Вернуться к оглавлению</a>.";
         throw new CHttpException(403, $msg);
     }
     return $chap;
 }
예제 #3
0
 /**
  * @param integer $book_id
  * @param integer $chap_id
  * @return Chapter
  * @throws CHttpException
  */
 protected function loadChapter($book_id, $chap_id)
 {
     $book_id = (int) $book_id;
     $chap_id = (int) $chap_id;
     /** @var Chapter $chap */
     $chap = Chapter::model()->with("book.membership")->findByPk($chap_id);
     if (!$chap) {
         throw new CHttpException(404, "Главы не существует. Возможно, она была удалена. <a href='/book/{$book_id}/'>Вернуться к оглавлению перевода</a>.");
     }
     if ($chap->book->id != $book_id) {
         $this->redirect($chap->book->getUrl($chap_id));
     }
     // ac_read для всего перевода. Если нельзя в весь перевод, редиректим в оглавление перевода, пусть контроллер Book объясняет, почему да как.
     if (!$chap->book->can("read")) {
         $this->redirect($chap->book->url);
     }
     // ac_read для этой главы
     if (!$chap->can("read")) {
         $msg = $chap->deniedWhy;
         $msg .= "<br /><br /><a href='{$chap->book->url}'>Вернуться к оглавлению</a>.";
         throw new CHttpException(403, $msg);
     }
     return $chap;
 }
예제 #4
0
 public function loadModel($id)
 {
     $model = Chapter::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #5
0
파일: Lesson.php 프로젝트: stan5621/eduwind
 public function refreshAllChapterIds($courseId)
 {
     $lessons = Lesson::model()->findAllByAttributes(array('courseId' => intval($courseId)), array('order' => 'weight asc'));
     foreach ($lessons as $lesson) {
         $criteria = new CDbCriteria();
         $criteria->select = "id";
         $criteria->condition = "courseId=:courseId and weight<:weight";
         $criteria->params = array(':courseId' => $courseId, ':weight' => $lesson->weight);
         $criteria->order = "weight desc";
         $criteria->limit = 1;
         $chapter = Chapter::model()->find($criteria);
         if ($chapter) {
             $lesson->chapterId = $chapter->id;
         } else {
             $lesson->chapterId = 0;
         }
         $lesson->save();
     }
 }
 /**
  * Note: This test assumes default Yii::t() fallback behavior
  * @test
  */
 public function furtherFallbackBehaviorTests()
 {
     $books = Book::model()->findAll();
     $book = $books[0];
     $this->assertEquals(2, count($books));
     $fooText = "Lean on me";
     Yii::app()->language = Yii::app()->sourceLanguage;
     $this->assertEquals($fooText, Yii::t('app', $fooText));
     Yii::app()->language = 'ch';
     $this->assertEquals($fooText, Yii::t('app', $fooText));
     $chapter = new Chapter();
     $chapter->_book_id = $book->id;
     $chapter->_title = $fooText;
     Yii::app()->language = 'en_us';
     $this->assertEquals($fooText, $chapter->title);
     Yii::app()->language = 'de';
     $this->assertEquals($fooText, $chapter->title);
     $saveResult = $chapter->save();
     $this->assertTrue($saveResult);
     $chapters = Chapter::model()->findAll();
     $chapter = $chapters[0];
     $this->assertEquals(1, count($chapters));
     $this->assertEquals($fooText, $chapter->title);
     $this->assertEquals($fooText, $chapter->title_de);
     $this->assertEquals($fooText, $chapter->title_ch);
     Yii::app()->language = 'ch';
     $this->assertEquals($book->title_en_us, $book->title_ch);
     $this->assertEquals($book->title_pt, 'O Diabo Veste Prada');
     $this->assertEquals($book->title_sv, 'Djävulen bär Prada');
     $this->assertEquals($book->title_en_us, 'The Devil Wears Prada');
     $this->assertEquals($book->title_en, 'The Devil Wears Prada');
 }
예제 #7
0
 public function actionProgress($id, $userId = 0)
 {
     $course = $this->loadModel($id);
     if (!$userId) {
         $userId = Yii::app()->user->id;
     }
     $user = UserInfo::model()->findByPk($userId);
     if (!$user) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     $criteria = new CDbCriteria();
     $criteria->condition = "courseId=:courseId and status=:status and chapterId=0";
     $criteria->params = array(':courseId' => $course->id, ':status' => Lesson::STATUS_PUBLIC);
     $criteria->order = "weight asc";
     $lessons = Lesson::model()->findAll($criteria);
     $criteria->condition = "courseId=:courseId";
     $criteria->params = array(':courseId' => $course->id);
     $chapters = Chapter::model()->findAll($criteria);
     $lessonsAndChapters = array_merge($lessons, $chapters);
     usort($lessonsAndChapters, array(new LessonSorter(), 'sortByWeight'));
     if ($userId) {
         $member = CourseMember::model()->findByAttributes(array('courseId' => $course->id, 'userId' => $userId));
     } else {
         $member = new CourseMember();
     }
     $lessonTotalCount = $course->lessonCount;
     $lessonLearnedCount = LessonLearn::model()->lessonCount($userId, $course->id);
     $nextLesson = LessonLearn::model()->nextLesson($course->id, $userId);
     $this->render('progress', array('lessonsAndChapters' => $lessonsAndChapters, 'course' => $course, 'member' => $member, 'lessonTotalCount' => $lessonTotalCount, 'lessonLearnedCount' => $lessonLearnedCount, 'user' => $user, 'percent' => $lessonTotalCount > 0 ? 100 * $lessonLearnedCount / $lessonTotalCount : 0, 'nextLesson' => $nextLesson));
 }
예제 #8
0
 public function actionOrder($courseId)
 {
     $course = $this->loadCourse($courseId);
     if (isset($_POST['order'])) {
         //			$course->orderLessons($_POST['order']);
         $ids = explode(",", $_POST['order']);
         for ($i = 0; $i < count($ids); $i++) {
             if (DxdUtil::startWith($ids[$i], 'lesson-')) {
                 $id = substr($ids[$i], 7);
                 $lesson = Lesson::model()->findbyPk($id);
                 $lesson->updateByPk($id, array("weight" => $i + 1));
             } else {
                 $id = substr($ids[$i], 8);
                 $chapter = Chapter::model()->findbyPk($id);
                 $chapter->updateByPk($id, array("weight" => $i + 1));
             }
         }
         Chapter::model()->refreshAllNumbers($courseId);
         Lesson::model()->refreshAllNumbers($courseId);
         Lesson::model()->refreshAllChapterIds($courseId);
         Yii::app()->end();
     }
 }
예제 #9
0
 public function actionBookmark_set()
 {
     if (!is_array($_POST["B"])) {
         throw new CHttpException(500, "Неверный запрос.");
     }
     // Есть ли уже такая закладка?
     $bookmark = Bookmark::model()->findByAttributes(array("user_id" => Yii::app()->user->id, "typ" => substr($_POST["B"]["typ"], 0, 1), "obj_id" => (int) $_POST["B"]["obj_id"]));
     if (!$bookmark) {
         $bookmark = new Bookmark();
         $bookmark->user_id = Yii::app()->user->id;
     }
     $bookmark->setAttributes($_POST["B"]);
     if ($bookmark->typ == "o") {
         $orig = Orig::model()->with("chap.book")->findByPk($bookmark->obj_id);
         if (!$orig) {
             throw new CHttpException(404, "Фрагмент оригинала удалён.");
         }
         $bookmark->url = $orig->url;
     } elseif ($bookmark->typ == "c") {
         $chap = Chapter::model()->with("book")->findByPk($bookmark->obj_id);
         if (!$chap) {
             throw new CHttpException(404, "Глава удалена");
         }
         $bookmark->url = $chap->url;
     } elseif ($bookmark->typ == "b") {
         $book = Book::model()->findByPk($bookmark->obj_id);
         if (!$book) {
             throw new CHttpException(404, "Глава удалена");
         }
         $bookmark->url = $book->url;
     } else {
         throw new CHttpException(500, "Неверный запрос. Если вам интересны грязные подробности, то я не знаю, что такое тип закладки '{$bookmark->typ}'.");
     }
     if ($bookmark->isNewRecord) {
         $bookmark->ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM bookmarks WHERE typ = :typ AND user_id = :user_id")->queryScalar(array(":typ" => $bookmark->typ, ":user_id" => Yii::app()->user->id)) + 1;
     }
     if (!$bookmark->save()) {
         throw new CHttpException(500, $bookmark->getErrorsString());
     }
     $json = array("id" => $bookmark->id, "title" => $bookmark->title);
     echo json_encode($json);
 }