Example #1
0
 function testPad()
 {
     $result = CoreUtils::pad(1);
     self::assertEquals('01', $result);
     $result = CoreUtils::pad(10);
     self::assertEquals('10', $result);
 }
Example #2
0
 /**
  * @param array $o
  *
  * @return string
  */
 public function getID($o = array()) : string
 {
     if ($this->isMovie) {
         return 'Movie' . (!empty($o['append_num']) ? '#' . $this->episode : '');
     }
     $episode = $this->episode;
     $season = $this->season;
     if (empty($o['pad'])) {
         if ($this->twoparter) {
             $episode = $episode . '-' . ($episode + 1);
         }
         return "S{$season}E{$episode}";
     }
     $episode = CoreUtils::pad($episode) . ($this->twoparter ? '-' . CoreUtils::pad($episode + 1) : '');
     $season = CoreUtils::pad($season);
     return "S{$season} E{$episode}";
 }
Example #3
0
 /**
  * Get a list of IDs for tags related to the episode
  *
  * @param Episode $Episode
  *
  * @return int[]
  */
 static function getTagIDs(Episode $Episode) : array
 {
     global $CGDb;
     if ($Episode->isMovie) {
         $MovieTagIDs = [];
         $MovieTag = $CGDb->where('name', "movie#{$Episode->episode}")->where('type', 'ep')->getOne('tags', 'tid');
         if (!empty($MovieTag['tid'])) {
             $MovieTagIDs[] = $MovieTag['tid'];
         }
         return $MovieTagIDs;
     } else {
         $sn = CoreUtils::pad($Episode->season);
         $en = CoreUtils::pad($Episode->episode);
         $EpTagIDs = array();
         $EpTagPt1 = $CGDb->where('name', "s{$sn}e{$en}")->where('type', 'ep')->getOne('tags', 'tid');
         if (!empty($EpTagPt1)) {
             $EpTagIDs[] = $EpTagPt1['tid'];
         }
         if ($Episode->twoparter) {
             $next_en = CoreUtils::pad($Episode->episode + 1);
             $EpTagPt2 = $CGDb->rawQuery("SELECT tid FROM tags WHERE name IN ('s{$sn}e{$next_en}', 's{$sn}e{$en}-{$next_en}') && type = 'ep'");
             foreach ($EpTagPt2 as $t) {
                 $EpTagIDs[] = $t['tid'];
             }
         }
         return $EpTagIDs;
     }
 }
Example #4
0
 /**
  * Turns "S#E#" into "S0# E0#"
  *
  * @param string $tagname
  *
  * @return string
  */
 static function expandEpisodeTagName(string $tagname) : string
 {
     global $EPISODE_ID_REGEX, $MOVIE_ID_REGEX;
     if (preg_match($EPISODE_ID_REGEX, $tagname, $_match)) {
         return 'S' . CoreUtils::pad($_match[1]) . ' E' . CoreUtils::pad($_match[2]);
     }
     if (preg_match($MOVIE_ID_REGEX, $tagname, $_match)) {
         return "Movie #{$_match[1]}";
     }
     return $tagname;
 }