コード例 #1
0
ファイル: TvShow.php プロジェクト: martinlindhe/core_dev
 public static function get($id)
 {
     if (!$id || !is_numeric($id)) {
         return false;
     }
     $db = SqlHandler::getInstance();
     $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE id = ?';
     $row = $db->pSelectRow($q, 'i', $id);
     $obj = SqlObject::loadObject($row, __CLASS__);
     if (!$obj) {
         throw new \Exception('bad id ' . $id);
     }
     $obj->episodes = TvEpisode::getAllByOwner($id);
     return $obj;
 }
コード例 #2
0
 function getShow($id)
 {
     if (!$id || !is_numeric($id)) {
         throw new \Exception('bad id: ' . $id);
     }
     $url = 'http://services.tvrage.com/feeds/full_show_info.php?sid=' . $id;
     $this->setUrl($url);
     if ($this->api_key) {
         $this->Url->setParam('key', $this->api_key);
     }
     $data = $this->getBody();
     $xml = simplexml_load_string($data);
     if (!$xml) {
         echo "ERROR: getShow( " . $id . " ) failed<br/>";
         return false;
     }
     $show = new TvShow();
     $show->id = $id;
     $show->info_url = strval($xml->showlink);
     $show->name = strval($xml->name);
     $show->country = strval($xml->origin_country);
     $show->thumb_url = strval($xml->image);
     $show->started = sql_date(self::parseDate(strval($xml->started)));
     $show->ended = sql_date(self::parseDate(strval($xml->ended)));
     $show->status = self::parseStatus($xml->status, $show->started, $show->ended);
     $show->time_updated = sql_datetime(time());
     $show->store();
     if (!$xml->Episodelist) {
         return $show;
     }
     foreach ($xml->Episodelist->Season as $season) {
         $attrs = $season->attributes();
         foreach ($season as $e) {
             $ep = new TvEpisode();
             $ep->owner = $show->id;
             $ep->title = strval($e->title);
             $ep->link = strval($e->link);
             $ep->setDate(strval($e->airdate));
             $ep->setEpisode($attrs['no'] . 'x' . $e->seasonnum);
             $ep->store();
             //only include episodes in period if it is set
             if (!$this->period_from && !$this->period_to || $ep->getDate() >= $this->period_from && $ep->getDate() <= $this->period_to) {
                 $show->addEpisode($ep);
             }
         }
     }
     return $show;
 }