hasMany(VideoAlias::class, 'videos_id'); } public function release(): HasMany { return $this->hasMany(Release::class, 'videos_id'); } public function episode(): HasMany { return $this->hasMany(TvEpisode::class, 'videos_id'); } public function tvInfo(): HasOne { return $this->hasOne(TvInfo::class, 'videos_id'); } /** * Get info from tables for the provided ID. * * * @return Model|null|static */ public static function getByVideoID($id) { return self::query() ->select(['videos.*', 'tv_info.summary', 'tv_info.publisher', 'tv_info.image']) ->where('videos.id', $id) ->join('tv_info', 'videos.id', '=', 'tv_info.videos_id') ->first(); } /** * Retrieves a range of all shows for the show-edit admin list. */ public static function getRange(string $showname = ''): LengthAwarePaginator { $sql = self::query() ->select(['videos.*', 'tv_info.summary', 'tv_info.publisher', 'tv_info.image']) ->join('tv_info', 'videos.id', '=', 'tv_info.videos_id'); if ($showname !== '') { $sql->where('videos.title', 'like', '%'.$showname.'%'); } return $sql->paginate(config('nntmux.items_per_page')); } /** * Returns a count of all shows -- usually used by pager. */ public static function getCount(string $showname = ''): int { $res = self::query()->join('tv_info', 'videos.id', '=', 'tv_info.videos_id'); if ($showname !== '') { $res->where('videos.title', 'like', '%'.$showname.'%'); } return $res->count('videos.id'); } /** * Retrieves and returns a list of shows with eligible releases. */ public static function getSeriesList($uid, string $letter = '', string $showname = ''): array { if (($letter !== '') && $letter === '0-9') { $letter = '[0-9]'; } $qry = self::query() ->select(['videos.*', 'tve.firstaired as prevdate', 'tve.title as previnfo', 'tvi.publisher', 'us.id as userseriesid']) ->join('tv_info as tvi', 'videos.id', '=', 'tvi.videos_id') ->join('tv_episodes as tve', 'videos.id', '=', 'tve.videos_id') ->leftJoin('user_series as us', function ($join) use ($uid) { $join->on('videos.id', '=', 'us.videos_id')->where('us.users_id', '=', $uid); }) ->whereBetween('r.categories_id', [Category::TV_ROOT, Category::TV_OTHER]) ->where('tve.firstaired', '<', now()) ->leftJoin('releases as r', 'r.videos_id', '=', 'videos.id') ->orderBy('videos.title') ->orderByDesc('tve.firstaired') ->groupBy(['videos.id']); if ($letter !== '') { $qry->whereRaw('videos.title REGEXP ?', ['^'.$letter]); } if ($showname !== '') { $qry->where('videos.title', 'like', '%'.$showname.'%'); } return $qry->get()->toArray(); } }