public function getBooks($r) { $t = new Dase_Template($r); $books = new Dase_DBO_Book($this->db); $t->assign("books", $books->findAll()); $r->renderResponse($t->fetch('chinese_flashcards/books.tpl')); }
public function getBook() { $book = new Dase_DBO_Book($this->db); $book->load($this->book_id); $this->book = $book; return $this->book; }
public function getLesson($r) { $book = new Dase_DBO_Book($this->db); $book->short_name = $r->get('short_name'); $book->findOne(); $lesson = new Dase_DBO_Lesson($this->db); $lesson->name = $r->get('lesson_name'); $lesson->book_id = $book->id; $lesson->findOne(); $lesson->getBook(); $lesson->getWords(); $t = new Dase_Template($r); //Simplified or Traditional Pref if (isset($_COOKIE['user_pref'])) { $pref = $_COOKIE['user_pref']; $t->assign('user_pref', $pref); } else { $t->assign('user_pref', 'simplified'); setcookie('user_pref', 'simplified', time() + 60 * 60 * 24 * 14, '/'); } //Card Preferences if (isset($_COOKIE['card_pref'])) { $pref = $_COOKIE['card_pref']; $t->assign('card_pref', $pref); } else { $t->assign('card_pref', 'pin-chi-eng'); setcookie('card_pref', 'pin-chi-eng', time() + 60 * 60 * 24 * 14, '/'); } $t->assign("book", $book); $t->assign("lesson", $lesson); $r->renderResponse($t->fetch('chinese_flashcards/lesson.tpl')); }
public static function search($db, $str) { $books = new Dase_DBO_Book($db); $book_set = array(); foreach ($books->findAll(1) as $b) { $book_set[$b->id] = $b; } $result = array(); $result['books'] = array(); $words = new Dase_DBO_Word($db); $words->addWhere('search_bag', '%' . $str . '%', 'like'); foreach ($words->findAll(1) as $word) { $book = $book_set[$word->book_id]; if (!isset($result['books'][$book->id])) { $result['books'][$book->id] = array(); $result['books'][$book->id]['id'] = $book->id; $result['books'][$book->id]['name'] = $book->name; $result['books'][$book->id]['lessons'] = array(); } if (!isset($result['books'][$book->id]['lessons'][$word->lesson_id])) { $result['books'][$book->id]['lessons'][$word->lesson_id] = array(); $result['books'][$book->id]['lessons'][$word->lesson_id]['id'] = $word->lesson_id; $result['books'][$book->id]['lessons'][$word->lesson_id]['words'] = array(); } if (!isset($result['books'][$book->id]['lessons'][$word->lesson_id]['words'][$word->id])) { $result['books'][$book->id]['lessons'][$word->lesson_id]['words'][$word->id] = array(); $result['books'][$book->id]['lessons'][$word->lesson_id]['words'][$word->id]['id'] = $word->id; $result['books'][$book->id]['lessons'][$word->lesson_id]['words'][$word->id]['traditional'] = $word->traditional; $result['books'][$book->id]['lessons'][$word->lesson_id]['words'][$word->id]['simplified'] = $word->simplified; $result['books'][$book->id]['lessons'][$word->lesson_id]['words'][$word->id]['pinyin'] = $word->pinyin; } } return $result; }
<?php include 'config.php'; $data = json_decode(file_get_contents('dump.json'), 1); $books = new Dase_DBO_Book($db); $i = 0; foreach ($books->findAll(1) as $book) { $lesson = new Dase_DBO_Lesson($db); $lesson->book_id = $book->id; foreach ($lesson->findAll(1) as $less) { foreach ($data['items'] as $it) { $filename_prefix = $it['metadata']['filename_prefix'][0]; $lesson_ident = $it['metadata']['lesson'][0]; $english = $it['metadata']['english'][0]; $simplified = $it['metadata']['simplified'][0]; $traditional = $it['metadata']['traditional'][0]; $word_index = $it['metadata']['word_index'][0]; $pinyin = $it['metadata']['pinyin'][0]; $sub_lesson = ''; if (isset($it['metadata']['sub_lesson'])) { $sub_lesson = $it['metadata']['sub_lesson'][0]; print $sub_lesson . "\n"; } if ($filename_prefix == $book->ident && $less->name == $lesson_ident) { $word = new Dase_DBO_Word($db); $word->lesson_id = $less->id; $word->book_id = $lesson->book_id; $word->word_index = $word_index; $word->english = $english; $word->simplified = $simplified; $word->traditional = $traditional;