public function saveBook()
 {
     $book = Input::get('book');
     $chapters = Input::get('chapters');
     $bookMdl = Book::find($book['id']);
     $bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']);
     $bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']));
     $bookMdl->save();
     foreach ($chapters as $key => $chapter) {
         if ($chapter['id']) {
             $chapMdl = Chapter::find($chapter['id']);
         } else {
             $chapMdl = new Chapter();
         }
         if ($chapter['id'] && $chapter['isDeleted']) {
             $chapMdl->delete();
         } else {
             $chapMdl->book_id = $chapter['book_id'];
             $chapMdl->title = $chapter['title'];
             $chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null;
             $chapMdl->order = $chapter['order'];
             $chapMdl->save();
             if (count($chapter['elements'])) {
                 foreach ($chapter['elements'] as $key => $element) {
                     if ($element['id']) {
                         $elementMdl = Element::find($element['id']);
                     } else {
                         $elementMdl = new Element();
                     }
                     if ($element['id'] && $element['isDeleted']) {
                         $elementMdl->delete();
                     } else {
                         $elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id'];
                         $elementMdl->order = $element['order'];
                         $elementMdl->type = $element['type'];
                         if ($element['type'] == 4 || $element['type'] == 5) {
                             $elementMdl->content = json_encode($element['content']);
                         } else {
                             $elementMdl->content = $element['content'];
                         }
                         $elementMdl->note = $element['note'];
                         $elementMdl->save();
                     }
                 }
             }
         }
     }
     echo json_encode(['ok']);
 }
Beispiel #2
0
 /**
  * 添加课程
  * @param unknown_type $id
  */
 public function actionCreate($courseId)
 {
     $course = Course::model()->findByPk($courseId);
     $model = new Chapter();
     if (isset($_POST['Chapter'])) {
         $model->attributes = $_POST['Chapter'];
         $model->userId = Yii::app()->user->id;
         if ($model->save()) {
             Yii::app()->user->setFlash('success', Yii::t('app', '添加成功!'));
         } else {
             Yii::app()->user->setFlash('error', Yii::t('app', '添加失败!'));
         }
         $this->redirect(array('lesson/index', 'courseId' => $model->courseId));
     }
     $model->courseId = $courseId;
     $this->layout = "/layouts/nonav_column1";
     $this->renderPartial('create_fancy', array('course' => $course, 'model' => $model), false, true);
 }
 public function executeAddchapter()
 {
     $c = new Criteria();
     $c->add(ChapterPeer::NAME, $this->getRequestParameter('chapter'));
     $exchapter = ChapterPeer::doSelectOne($c);
     if ($exchapter) {
         $this->setFlash('notice', 'Chapter could not be added. A chapter with this name already exists.');
     } else {
         $chapter = new Chapter();
         $chapter->setName($this->getRequestParameter('chapter'));
         $chapter->save();
         $cr = new Chapterregion();
         $cr->setChapterId($chapter->getId());
         $cr->setRegionId($this->getRequestParameter('region'));
         $cr->save();
         $this->setFlash('notice', 'Chapter <b>' . $chapter->getName() . '</b> has been created successfully.');
     }
     $this->redirect('admin/chapters');
 }
 public function post()
 {
     //message-notification
     $messages = array();
     //handle navigation
     $admin_navigation = new AdminNavigation();
     if ($admin_navigation->isNavigate()) {
         return $admin_navigation->goToN();
     }
     //chapters-change
     //delete-chapter
     if (Input::has('delete_chapter')) {
         $chapter = Chapter::find(Input::get('chapter_id'));
         $questions = $chapter->getQuestions;
         if (count($questions) > 0) {
             $messages['delete_chapter'] = 'chapter-' . $chapter->id . ':has questions';
         } else {
             $chapter->delete();
             $messages['delete_chapter'] = 'chapter-' . $chapter->id . ':deleted';
         }
     }
     //new-chapter
     if (Input::has('new_chapter')) {
         $chapter = new Chapter();
         //delete +  auto_increment >>> modidify chapter-id not continuous
         //manually change chapter-id
         $last_chapter = Chapter::all()->last();
         $chapter->id = $last_chapter->id + 1;
         $chapter->text = Input::get('chapter_text');
         $chapter->rate = 0;
         $chapter->save();
         //messages-notification
         $messages['new_chapter'] = 'chapter-' . $chapter->id . '-' . $chapter->text . ':saved';
     }
     $this->messageController->send($messages, $this::MESSAGE_KEY);
     return Redirect::back();
 }
Beispiel #5
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     // Fetch all request data.
     $data = Input::only('chapter_title', 'book', 'public');
     // Build the validation constraint set.
     $rules = array('chapter_title' => array('required'), 'book' => array('numeric'), 'public' => array('integer'));
     // Create a new validator instance.
     $validator = Validator::make($data, $rules);
     if ($validator->passes()) {
         $chapter = new Chapter();
         $chapter->author_id = Sentry::getUser()->id;
         $title = Input::get('chapter_title');
         //$date = new DateTime();
         //$time = $date->format('Y-m-d-H-i-s');
         //$chapter->slug = $time.'-'.Str::slug($title, '-');
         $uniqid = str_shuffle(uniqid());
         $chapter->slug = Str::slug($title, '-') . '-' . $uniqid;
         $chapter->title = $title;
         $chapter->secret_link = str_shuffle(uniqid());
         if (Input::get('book') == true) {
             $chapter->book_id = Input::get('book');
         }
         $chapter->public_state = Input::get('public_state') ? 1 : 0;
         //Chapter cover file handle
         /*
         $file = Input::file('chapter_cover');
         $destinationPath = 'img/';
         $extension = $file->getClientOriginalExtension(); 
         $filename = $title.'.'.$extension;
         Input::file('chapter_cover')->move($destinationPath, $filename);
         */
         $chapter->save();
         return Redirect::to('/chapter/edit/' . $chapter->id)->with('global_success', 'Chapter added successfuly!');
     }
     return Redirect::to('/dashboard')->withInput()->withErrors($validator)->with('message', 'Validation Errors!');
 }
 /**
  * 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');
 }
 public function actionEdit($book_id, $chap_id)
 {
     $chap_id = (int) $chap_id;
     $book_id = (int) $book_id;
     $ajax = $_GET["ajax"] == 1;
     if ($chap_id != 0) {
         $chap = $this->loadChapter($book_id, $chap_id, false);
         if (!$chap->book->can("read")) {
             throw new CHttpException(403, "Доступ в перевод закрыт его владельцем.");
         }
     } else {
         $chap = new Chapter();
         $chap->book = Book::model()->with("membership")->findByPk($book_id);
         if (!$chap->book) {
             throw new CHttpException(404, "Вы пытаетесь создать новую главу в несуществующем переводе.");
         }
         $chap->book_id = $book_id;
     }
     if (!$chap->book->can("chap_edit")) {
         throw new CHttpException(403, "Вы не можете редактировать оглавление в этом переводе.");
     }
     // $overridedId - ID главы с особыми правами в этом переводе
     if ($chap->isNewRecord && $chap->book->n_chapters == 0 || !$chap->isNewRecord && $chap->book->n_chapters <= 1) {
         $overridedId = -1;
     } elseif ($chap->hasOverride) {
         $overridedId = $chap->id;
     } else {
         $overridedId = Yii::app()->db->createCommand("SELECT id FROM chapters WHERE book_id = :book_id AND (ac_read != '' OR ac_trread != '' OR ac_gen != '' OR ac_rate != '' OR ac_comment != '' OR ac_tr != '')")->queryScalar(array(":book_id" => $chap->book_id));
     }
     if (count($_POST["Chapter"]) > 0) {
         if ($chap_id == 0) {
             // Будущий ord
             if ($_GET["placement"] == -1) {
                 $chap->ord = Yii::app()->db->createCommand("SELECT MIN(ord) FROM chapters WHERE book_id = :book_id")->queryScalar(array(":book_id" => $book_id)) - 1;
             } else {
                 $chap->ord = Yii::app()->db->createCommand("SELECT MAX(ord) FROM chapters WHERE book_id = :book_id")->queryScalar(array(":book_id" => $book_id)) + 1;
             }
         }
         $old_status = $chap->status;
         $chap->setAttributes($_POST["Chapter"]);
         if ($chap->save()) {
             $chap->setModified();
             if ($chap_id == 0 || $old_status != $chap->status) {
                 $notify = User::model()->watchers($chap->book_id)->findAll();
                 foreach ($notify as $u) {
                     if ($chap_id == 0) {
                         $u->Notify(Notice::CHAPTER_ADDED, $chap->book, $chap);
                     } elseif ($old_status != $chap->status) {
                         $u->Notify(Notice::CHAPTER_STATUS, $chap->book, $chap, Yii::app()->params["translation_statuses"][$chap->status]);
                     }
                 }
             }
             $this->redirect($chap->book->url);
         } else {
             Yii::app()->user->setFlash("error", $chap->getErrorsString());
             $this->redirect($chap->book->url . "#ed={$chap->id}");
         }
     }
     $p = array("chap" => $chap, "ajax" => $ajax, "overridedId" => $overridedId);
     if ($ajax) {
         $this->renderPartial("edit", $p);
     } else {
         $this->render("edit", $p);
     }
 }
Beispiel #8
0
 /**
  * Creates or updates the chapter in database getting data from file.
  * Used in /anime/actions/executeRefreshAnime
  *
  * @param Saga $saga_object ex: Saga(2)
  * @param Array $chapter_info[] ex: [12, Luffy y Zorro, 1080p, 25 fps, 2300 kbps, 1920x800, [Spa,Jap], [Spa]]
  * @return Chapter
  */
 public static function createChapter($saga_object, $chapter_info)
 {
     //looking for this episode in db
     $chapter_object = NULL;
     foreach ($saga_object['Chapters'] as $chapter) {
         if ($chapter->title == $chapter_info['title']) {
             $chapter_object = $chapter;
         }
     }
     //if there is no episode
     if ($chapter_object == NULL) {
         $chapter_object = new Chapter();
         $chapter_object->title = $chapter_info['title'];
         $chapter_object->num_chapter = $chapter_info['num_chapter'];
     }
     $chapter_object->duration = $chapter_info['duration'];
     $chapter_object->framerate = $chapter_info['framerate'];
     $chapter_object->bitrate = $chapter_info['bitrate'];
     $chapter_object->filesize = $chapter_info['filesize'];
     $chapter_object->dimensions = $chapter_info['dimensions'];
     $chapter_object->file_abs = $chapter_info['file_abs'];
     $chapter_object->file_rel = $chapter_info['file_rel'];
     /***********************************   FORMAT   ***********************************/
     if ($chapter_info['format'] != NULL) {
         $format_object = Doctrine::getTable('Format')->findOneByName($chapter_info['format']);
         if ($format_object == NULL) {
             $format_object = Util::createFormat($chapter_info['format']);
         }
         $chapter_object->Format = $format_object;
     }
     /**********************************   LANGUAGES   **********************************/
     //First remove previous audio tracks
     foreach ($chapter_object['AudioTracks'] as $track) {
         $q = Doctrine_Query::create()->delete('AudioTrack')->where('id = ?', $track['id'])->execute();
     }
     //Adding the new ones
     foreach ($chapter_info['audio_tracks'] as $track) {
         $audio_track = Util::createAudioTrack($track['codec'], $track['code']);
         $chapter_object->AudioTracks[] = $audio_track;
     }
     /**********************************   SUBTITLES   **********************************/
     //First remove previous sub tracks
     foreach ($chapter_object['SubTracks'] as $track) {
         $q = Doctrine_Query::create()->delete('SubTrack')->where('id = ?', $track['id'])->execute();
     }
     //Adding the new ones
     foreach ($chapter_info['sub_tracks'] as $track) {
         $sub_track = Util::createSubTrack($track['label'], $track['code']);
         $chapter_object->SubTracks[] = $sub_track;
     }
     $chapter_object->save();
     $saga_object->Chapters[] = $chapter_object;
     $saga_object->save();
     return $chapter_object;
 }
Beispiel #9
0
    echo json_encode($comic->toArray());
}
// Only logged in users have access to POST and DELETE
if (!current_user_can('upload_files')) {
    return;
}
if ($requestMethod == 'DELETE') {
    $page = Page::findById($_GET['page_id']);
    if (!$page) {
        return;
    }
    $page->delete();
}
if ($requestMethod == 'POST') {
    $data = $_POST;
    $resourceType = $data['resource'];
    if ($resourceType == 'page') {
        $resource = new Page($data['page_name'], $data['page_number'], $data['chapter_id'], $_FILES['page_image']['name']);
        // Upload the image
        $filePath = $_FILES['page_image']['tmp_name'];
        $newFilePath = getcwd() . '/../../../wp-content/uploads/live/' . $_FILES['page_image']['name'];
        rename($filePath, $newFilePath);
        chmod($newFilePath, 0644);
        header("Location: " . $_SERVER['HTTP_REFERER']);
    }
    if ($resourceType == 'chapter') {
        $resource = new Chapter($data['chapter_number'], $data['chapter_title']);
    }
    $resource->save();
}
return '';