public function executeProgress() { // determine active lesson if the user has added cards in order, // otherwise set to FALSE $cur_frame = ReviewsPeer::getHeisigProgressCount($this->getUser()->getUserId()); $this->currentLesson = $cur_frame ? rtkBook::getLessonForFramenum($cur_frame + 1) : false; // find the success/fail flashcard count per lesson $progress = ReviewsPeer::getProgressStatus($this->getUser()->getUserId()); // rtk lesson data $rtkLessons = rtkBook::getLessons(); // how many lessons have been started $this->activeLessons = 0; $lessons = array(); for ($i = 1; $i <= 56; $i++) { $lessons[$i] = array('label' => 'Lesson ' . $i, 'passValue' => 0, 'failValue' => 0, 'testedCards' => 0, 'totalCards' => 0, 'maxValue' => $rtkLessons[$i]); } foreach ($progress as $p) { if ($p->lessonId <= 0) { throw new coreException('Bad lesson id'); } // fixme: only RtK1 for now if ($p->lessonId > 56) { break; } $lessons[$p->lessonId] = array('label' => 'Lesson ' . $p->lessonId, 'passValue' => $p->pass, 'failValue' => $p->fail, 'testedCards' => $p->pass + $p->fail, 'totalCards' => $p->total, 'maxValue' => $rtkLessons[$p->lessonId]); $this->activeLessons++; } $this->lessons = $lessons; }
/** * Home page. * * @return */ public function executeIndex() { if ($this->getUser()->isAuthenticated()) { //echo $this->getUser()->sqlLocalTime(); exit; // get member stats for quick summary $this->curFrameNum = ReviewsPeer::getHeisigProgressCount($this->getUser()->getUserId()); $this->progress = rtkBook::getProgressSummary($this->curFrameNum); $this->countExpired = ReviewsPeer::getCountExpired($this->getUser()->getUserId()); $this->countFailed = ReviewsPeer::getCountFailed($this->getUser()->getUserId()); return 'Member'; } // prepare unique homepage design return 'Guest'; }
<?php use_helper('Form', 'Validation', 'Widgets'); echo form_tag('manage/RemoveCustomProcess', array('class' => 'main-form')); ?> <?php echo form_errors(); ?> <p> The following <strong><?php echo $count; ?> </strong> kanji flashcard(s) have been removed:</p> <div style="background:#E7F5CD;color:#000;padding:5px;margin:0 0 1em;"> <?php $kanjis = array(); foreach ($cards as $id) { $kanjis[] = rtkBook::getKanjiForIndex($id); } echo implode(', ', $kanjis); ?> </div> <p><a href="#" class="proceed" onclick="return ManageFlashcards.load(this,{'reset':true});">Remove more cards</a></p> </form>
<p> All kanji in the selection are already present in your flashcards.</p> <?php } else { ?> <p> <strong><?php echo $countNewCards; ?> </strong> new card(s) will be added:</p> <div style="background:#F3F1DC;color:#000;padding:5px;margin:0 0 1em;"> <?php $cards = array(); foreach ($newCards as $id) { $cards[] = rtkBook::getKanjiForIndex($id); } echo implode(', ', $cards); ?> </div> <?php } ?> <p> <?php if ($countNewCards) { echo submit_tag('Add Cards') . ' '; } ?>
/** * Takes a string of Japanese text and returns the kanji with links to * the Study page, and the title attribute contains the RTK keyword. * * @param string $compound * * @return string Html markup */ public static function getKeywordizedCompound($compound) { $chars = CJK::splitU($compound); //DBG::out(print_r($chars, true)); $s = ''; coreToolkit::loadHelpers(array('Tag', 'Url')); foreach ($chars as $c) { if (false !== ($framenum = rtkBook::getIndexForKanji($c))) { $keyword = KanjisPeer::getKeyword($framenum); // FIXME - internal uri should be '@study_edit?id=' once it goes to production site.. $url = link_to($c, 'http://kanji.koohii.com/study/kanji/' . $c, array('title' => $keyword)); $s = $s . $url; } else { $s = $s . $c; } } //DBG::out($s);exit; return $s; }
/** * Add cards in Heisig order. * * Selection should be a frame number to add up to, * or a number of cards to add "+10", filling in all missing cards in the RTK range. * * @param string $selection "56" (add up to 56), or "+20" (add 20 cards) * * @return int Number of cards in selection (also 0), or false if error */ public function addHeisigRange($userId, $selection) { $this->itemIds = array(); // get user's existing flashcard ids in RTK range $userCards = ReviewsPeer::getFlashcardIds($userId, 'rtk1+3'); // map in an array, 1 means card exists, 0 it doesn't $inDeck = array(); foreach ($userCards as $id) { $inDeck[(int) $id] = true; } // add a number of cards, or up to frame number, fill in the missing cards if (preg_match('/^\\+([0-9]+)$/', $selection, $matches)) { $range = $matches[1]; if ($range < 1) { $this->request->setError('x', 'Invalid range of cards'); return false; } for ($i = 1, $n = 0; $n < $range && $i <= rtkBook::MAXKANJI_VOL3; $i++) { if (!isset($inDeck[$i])) { $this->itemIds[] = $i; $n++; } } } else { $addTo = intval($selection); if (!rtkBook::isValidRtkFrameNum($addTo)) { $this->request->setError('x', sprintf('Invalid index number: "%s"', $selection)); return false; } for ($i = 1; $i <= $addTo; $i++) { if (!isset($inDeck[$i])) { $this->itemIds[] = $i; } } } return $this->getNumCards(); }
/** * Takes a string of Japanese text and returns the kanji with links to * the Study page, and the title attribute contains the RTK keyword. * * @param string $compound * * @return string Html markup */ public static function getKeywordizedCompound($compound) { $chars = CJK::splitU($compound); //DBG::out(print_r($chars, true)); $s = ''; coreToolkit::loadHelpers(array('Tag', 'Url')); foreach ($chars as $c) { if (false !== ($framenum = rtkBook::getIndexForKanji($c))) { $keyword = KanjisPeer::getKeyword($framenum); $url = link_to($c, '@study_edit?id=' . $c, array('title' => $keyword)); $s = $s . $url; } else { $s = $s . $c; } } //DBG::out($s);exit; return $s; }