コード例 #1
0
ファイル: nMovie.php プロジェクト: nathanharper/glibreviews
 /**
  * Generate alternate titles for the film using RhymeBrain.
  * @param int $name_count, the number of names to generate
  **/
 public function generate_names($names_per_word = 5, $rhymes_per_word = 10)
 {
     if (!$this->name) {
         return false;
     }
     $names = nRhyme::process_title($this->name, $names_per_word, $rhymes_per_word);
     $db = nSQL::connect();
     if ($names) {
         foreach ($names as $data) {
             if (nGlibName::load_one(array('name' => $data['title'], 'movie_id' => $this->get_id()))) {
                 # glib title already exists
                 continue;
             }
             $glib = new nGlibName(array('name' => $data['title'], 'movie_id' => $this->get_id()));
             if ($glib->save()) {
                 $word = nWord::load_one(array('word' => $data['rhyme']));
                 if (!$word) {
                     $word = new nWord(array('word' => $data['rhyme']));
                     $word->save();
                 }
                 if ($word_id = $word->get_id()) {
                     $db->query(sprintf("INSERT INTO glib_name_word (glib_name_id, word_id) VALUES (%d, %d)", $glib->get_id(), $word_id));
                 }
             }
         }
     }
 }
コード例 #2
0
 public function get_words()
 {
     if (!$this->get_id()) {
         return false;
     }
     return nWord::load(sprintf("SELECT w.* FROM word w\n            INNER JOIN glib_name_word gnw ON gnw.word_id = w.id\n            WHERE gnw.glib_name_id = %d", $this->get_id()));
 }