示例#1
0
 /**
  * Get a selection of flashcards for review, as an array of flashcard ids.
  * 
  * Orders flashcards by expiredate (longest expired first), and then
  * randomize cards that expire on the same date.
  * 
  * Only works for current user (sqlLocalTime).
  * 
  * @param  mixed    $box    'all' or a Leitner box number starting from 1
  * @param  string   $type   'expired', 'untested', 'relearned', anything else means 'fresh' (non-expired)
  * @param  string   $filt   'rtk1', 'rkt3', '' for all kanji
  * @param  boolean  $merge  True to merge flashcards from given box with higher boxes
  * 
  * @return array    Flashcard ids (framenum).
  */
 public static function getFlashcards($box, $type, $filt, $merge)
 {
     $user = coreContext::getInstance()->getUser();
     $userId = $user->getUserId();
     $sqlLocalTime = new coreDbExpr($user->sqlLocalTime());
     if ($type === 'relearned') {
         // select cards from relearned kanji selection
         $select = LearnedKanjiPeer::getInstance()->select('framenum');
         $select->where('userid = ?', $userId);
     } else {
         $select = self::getInstance()->select('framenum');
         $select = self::filterByUserId($select, $userId);
         $select = self::filterByRtk($select, $filt);
     }
     switch ($type) {
         case 'untested':
             $select->where('totalreviews = 0');
             $select->order('expiredate, RAND()');
             break;
         case 'relearned':
             $select->order('RAND()');
             break;
         default:
             // expired or non-expired (orange or green stacks)
             if ($type == 'expired') {
                 $select->where('totalreviews > 0 AND expiredate <= ?', $sqlLocalTime);
             } else {
                 $select->where('totalreviews > 0 AND expiredate > ?', $sqlLocalTime);
             }
             if ($box == 'all') {
                 $select->where('leitnerbox > 1');
             } elseif ($merge) {
                 $select->where('leitnerbox >= ?', $box);
             } else {
                 $select->where('leitnerbox = ?', $box);
             }
             $select->order('expiredate, RAND()');
             break;
     }
     //DBG::out($select);exit;
     return self::$db->fetchCol($select);
 }