示例#1
0
 protected function reviewAction($request)
 {
     $db = $this->getContext()->getDatabase();
     $options = array('fn_get_flashcard' => array('rtkLabs', 'getFlashcardData'));
     if ($request->getMethod() !== coreRequest::POST) {
         $options['items'] = rtkLabs::iVocabShuffleBegin();
         $this->uiFR = new uiFlashcardReview($options);
     } else {
         // handle Ajax requests
         $oJson = coreJson::decode($request->getParameter('json', '{}'));
         if (!empty($oJson)) {
             $flashcardReview = new uiFlashcardReview($options);
             return $this->renderText($flashcardReview->handleJsonRequest($oJson));
         }
         throw new rtkAjaxException('Empty JSON Request.');
     }
 }
示例#2
0
文件: actions.php 项目: kc5nra/RevTK
 /**
  * Kanji Flashcard review page with uiFlashcardReview
  * 
  * GET request = review page
  * 
  * 	 type = 'expired'|'untested'|'relearned'|'fresh'
  *   box  = 'all'|[1-5]
  *   filt = ''|'rtk1'|'rtk3'
  *   
  * POST request = ajax request during review
  * 
  * @param object $request
  */
 protected function reviewAction($request)
 {
     $reviewBox = $request->getParameter('box', 'all');
     $reviewType = $request->getParameter('type', 'expired');
     $reviewFilt = $request->getParameter('filt', '');
     $reviewMerge = $request->getParameter('merge') ? true : false;
     // validate
     $this->forward404Unless(preg_match('/^(all|[1-9]+)$/', $reviewBox));
     $this->forward404Unless(preg_match('/^(expired|untested|relearned|fresh)$/', $reviewType));
     $this->forward404Unless($reviewFilt == '' || preg_match('/(rtk1|rtk3)/', $reviewFilt));
     // pick title
     $this->setReviewTitle($reviewType, $reviewFilt);
     //
     $sAjaxUrl = $this->getController()->genUrl('@review');
     $options = array('partial_name' => 'review/ReviewKanji', 'ajax_url' => $sAjaxUrl, 'ts_start' => ReviewsPeer::getLocalizedTimestamp(), 'fn_get_flashcard' => array('KanjisPeer', 'getFlashcardData'), 'fn_put_flashcard' => array('ReviewsPeer', 'putFlashcardData'));
     if ($request->getMethod() !== coreRequest::POST) {
         $options['items'] = ReviewsPeer::getFlashcards($reviewBox, $reviewType, $reviewFilt, $reviewMerge);
         $this->uiFR = new uiFlashcardReview($options);
     } else {
         /*
         			if (rand(1,10) < 3)
         			{
         				sleep(6);
         			}*/
         // handle Ajax request (or throws exception)
         $oJson = coreJson::decode($request->getParameter('json', '{}'));
         if (!empty($oJson)) {
             $flashcardReview = new uiFlashcardReview($options);
             return $this->renderText($flashcardReview->handleJsonRequest($oJson));
         }
         throw new rtkAjaxException('Empty JSON Request.');
     }
     return coreView::SUCCESS;
 }