/** * Return EditStory component based on GET or POST request. * * PARAMS * framenum Valid kanji id (frame number) * kanjiData Kanji data for kanji id * reviewMode True if called from the Review page * * POST requests to update the story for current user. * * character Current kanji (utf8) * chkPublic Public story * txtStory Story * * * @return * @param object $request */ public function execute($request) { if ($request->getMethod() !== coreRequest::POST) { // get user's story $story = StoriesPeer::getStory($this->getUser()->getUserId(), $this->framenum); if ($story) { $request->getParameterHolder()->add(array('txtStory' => $story->text, 'chkPublic' => $story->public)); } } else { $validator = new coreValidator($this->getActionName()); if ($validator->validate($request->getParameterHolder()->getAll())) { if ($request->hasParameter('doUpdate')) { $txtStory = trim($request->getParameter('txtStory', '')); $txtStory = strip_tags($txtStory); // delete empty story if (empty($txtStory)) { StoriesPeer::deleteStory($this->getUser()->getUserId(), $this->framenum); } else { StoriesPeer::updateStory($this->getUser()->getUserId(), $this->framenum, array('text' => $txtStory, 'public' => $request->hasParameter('chkPublic') ? 1 : 0)); } $request->setParameter('txtStory', $txtStory); } } } // set state $request->setParameter('framenum', $this->framenum); if (!$request->hasParameter('reviewMode')) { $this->isRestudyKanji = ReviewsPeer::isRestudyKanji($this->getUser()->getUserId(), $this->framenum); $this->isRelearnedKanji = LearnedKanjiPeer::hasKanji($this->getUser()->getUserId(), $this->framenum); } $this->formatted_story = StoriesPeer::getFormattedStory($request->getParameter('txtStory', ''), $this->kanjiData->keyword, true); return coreView::SUCCESS; }
/** * Update the flashcard review status (uiFlashcardReview callback) * * Note: uiFlashcardReview callback, must sanitize data! * * Flashcard answer data is set by the front end code (review.js): * * id Flashcard id = framenum * r Answer (1=No 2=Yes 3=Easy)` * * @param mixed $id Flashcard id * @param object $oData Flashcard answer data * @return boolean True if update went succesfully */ public static function putFlashcardData($id, $oData) { // sanitize JSON data if (!preg_match('/^[0-9]+$/', $id) || ($id < 1 || $id > rtkBook::MAXKANJI_VOL3) || !isset($oData->r) || !preg_match('/^[1-3]$/', $oData->r)) { throw new coreException('updateFlashcard :: invalid data'); } $user = coreContext::getInstance()->getUser(); $userId = $user->getUserId(); // get current review status $select = self::getInstance()->select(array('totalreviews', 'leitnerbox', 'failurecount', 'successcount', 'lastreview'))->where('framenum = ?', $id); self::filterByUserId($select, $userId)->query(); $curData = self::$db->fetchObject(); if (!$curData) { throw new coreException('updateFlashcard :: no record for id'); } $oUpdateData = LeitnerSRS::rateCard($curData, $oData->r); //echo '<p>UPDATE framenum '.$id.' with '.print_r($oUpdateData, true); //return true; $result = self::getInstance()->update($oUpdateData, 'userid = ? AND framenum = ?', array($userId, $id)); if ($result && $oData->r > 1) { // clear relearned kanji if successfull answer LearnedKanjiPeer::clearKanji($userId, $id); } return $result; }
/** * Clear the restudied kanji selection. * * @return */ public function executeClear($request) { LearnedKanjiPeer::clearAll($this->getUser()->getUserId()); }
include_partial('study/StudySearch', array('framenum' => $framenum)); ?> </div> <div class="col-box col-tbar"> <h2>My Stories</h2> <span class="q">»</span> <?php echo link_to('All my stories', 'study/mystories'); ?> </div> <div class="col-box col-tbar study-restudy"> <h2>Restudy Kanji</h2> <?php if ($learnedCount = LearnedKanjiPeer::getCount($_user->getUserId())) { ?> <p class="set"> <em><?php echo $learnedCount; ?> </em> learned<br/> <span class="btn"> <?php echo link_to('<img src="/images/2.0/study/review-small.gif" alt="Review" width="56" height="19" />', '@review', array('query_string' => 'type=relearned')); ?> <?php echo link_to('Clear', 'study/clear', array('class' => 'cancel')); ?> </span>