示例#1
0
 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;
 }
示例#2
0
 public function getWords()
 {
     $words = new Dase_DBO_Word($this->db);
     $words->lesson_id = $this->id;
     foreach ($words->findAll(1) as $word) {
         if (!$word->sub_lesson) {
             $word->sub_lesson = '0';
         }
         if (!isset($this->words[$word->sub_lesson])) {
             $this->words[$word->sub_lesson] = array();
         }
         $this->words[$word->sub_lesson][] = $word;
         $this->word_idents[] = $word->word_index . '.' . $word->sub_lesson;
     }
     return $this->words;
 }
<?php

include 'config.php';
setlocale(LC_ALL, 'en_US.UTF8');
function clearUTF($s)
{
    $r = '';
    $s1 = iconv('UTF-8', 'ASCII//TRANSLIT', $s);
    for ($i = 0; $i < strlen($s1); $i++) {
        $ch1 = $s1[$i];
        $ch2 = mb_substr($s, $i, 1);
        $r .= $ch1 == '?' ? $ch2 : $ch1;
    }
    return $r;
}
$words = new Dase_DBO_Word($db);
foreach ($words->findAll(1) as $word) {
    $sub = array();
    $sub[] = $word->simplified;
    $sub[] = $word->traditional;
    $sub[] = $word->pinyin;
    $sub[] = clearUTF($word->pinyin);
    $word->search_bag = join(' ', $sub);
    print $word;
    $word->update();
}
 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;
             $word->pinyin = $pinyin;
             $word->sub_lesson = $sub_lesson;
             if (!$word->findOne()) {
                 print $i++;
                 if (isset($it['media']['mp3'])) {
                     $audio_ident = substr($it['metadata']['title'][0], -5, 1);
                     if ('b' == $audio_ident) {
                         $word->audio_file_b = $it['app_root'] . $it['media']['mp3'];
                     } else {