示例#1
0
 /**
  * insert
  * Insert a new tv show episode and related entities.
  */
 public static function insert(array $data, $gtypes = array(), $options = array())
 {
     if (empty($data['tvshow'])) {
         $data['tvshow'] = T_('Unknown');
     }
     $tags = $data['genre'];
     $tvshow = TVShow::check($data['tvshow'], $data['year']);
     if ($options['gather_art'] && $tvshow && $data['tvshow_art'] && !Art::has_db($tvshow, 'tvshow')) {
         $art = new Art($tvshow, 'tvshow');
         $art->insert_url($data['tvshow_art']);
     }
     $tvshow_season = TVShow_Season::check($tvshow, $data['tvshow_season']);
     if ($options['gather_art'] && $tvshow_season && $data['tvshow_season_art'] && !Art::has_db($tvshow_season, 'tvshow_season')) {
         $art = new Art($tvshow_season, 'tvshow_season');
         $art->insert_url($data['tvshow_season_art']);
     }
     if (is_array($tags)) {
         foreach ($tags as $tag) {
             $tag = trim($tag);
             if (!empty($tag)) {
                 Tag::add('tvshow_season', $tvshow_season, $tag, false);
                 Tag::add('tvshow', $tvshow, $tag, false);
             }
         }
     }
     $sdata = $data;
     // Replace relation name with db ids
     $sdata['tvshow'] = $tvshow;
     $sdata['tvshow_season'] = $tvshow_season;
     return self::create($sdata);
 }