Example #1
0
 /**
  * Sets up the permissions for the plugin. It sets up permissions for every show that's in the database.
  *
  * @return array The permissions array.
  */
 public function registerPermissions()
 {
     $permissions = ['cosmicradiotv.podcast.access_release_types' => ['tab' => 'cosmicradiotv.podcast::lang.permissions.tab_labels.general', 'label' => 'cosmicradiotv.podcast::lang.permissions.labels.access_release_types'], 'cosmicradiotv.podcast.access_tags' => ['tab' => 'cosmicradiotv.podcast::lang.permissions.tab_labels.general', 'label' => 'cosmicradiotv.podcast::lang.permissions.labels.access_tags'], 'cosmicradiotv.podcast.access_shows_all' => ['tab' => 'cosmicradiotv.podcast::lang.permissions.tab_labels.general', 'label' => 'cosmicradiotv.podcast::lang.permissions.labels.access_shows_all'], 'cosmicradiotv.podcast.access_shows' => ['tab' => 'cosmicradiotv.podcast::lang.permissions.tab_labels.general', 'label' => 'cosmicradiotv.podcast::lang.permissions.labels.access_shows'], 'cosmicradiotv.podcast.access_episodes_all' => ['tab' => 'cosmicradiotv.podcast::lang.permissions.tab_labels.general', 'label' => 'cosmicradiotv.podcast::lang.permissions.labels.access_episodes_all'], 'cosmicradiotv.podcast.access_episodes' => ['tab' => 'cosmicradiotv.podcast::lang.permissions.tab_labels.general', 'label' => 'cosmicradiotv.podcast::lang.permissions.labels.access_episodes']];
     // Add the permissions for individual shows
     $shows = Show::all();
     foreach ($shows as $show) {
         $permissions['cosmicradiotv.podcast.access_show_' . $show->slug] = ['tab' => 'cosmicradiotv.podcast::lang.permissions.tab_labels.shows', 'label' => e(trans('cosmicradiotv.podcast::lang.permissions.labels.access_show')) . ' ' . $show->name];
     }
     return $permissions;
 }
Example #2
0
 public function listExtendQuery($query, $definition = null)
 {
     $user = BackendAuth::getUser();
     if (!$user->hasAccess(['cosmicradiotv.podcast.access_episodes_all'])) {
         $shows = Show::all();
         $show_ids_allowed = [];
         foreach ($shows as $show) {
             if ($user->hasAccess(['cosmicradiotv.podcast.access_show_' . $show->slug])) {
                 $show_ids_allowed[] = $show->id;
             }
         }
         $query->whereIn('show_id', $show_ids_allowed);
     }
 }
 /**
  * Set components state based on parameters
  *
  * @throws ModelNotFoundException
  */
 public function setState()
 {
     $showSlugFilter = $this->property('showSlugFilter');
     if (!empty($showSlugFilter)) {
         $this->show = Show::query()->where('slug', $showSlugFilter)->firstOrFail();
         $this->episode = $this->show->episodes()->getQuery()->where('published', true)->orderBy('release', 'desc')->with(['releases', 'releases.release_type', 'image', 'tags', 'show'])->firstOrFail();
     } else {
         $this->episode = Episode::query()->where('published', true)->orderBy('release', 'desc')->with(['releases', 'releases.release_type', 'image', 'tags', 'show'])->firstOrFail();
     }
     $this->releases = Collection::make($this->episode->releases);
     // Creates a copy
     $this->releases->sort(function (Release $a, Release $b) {
         // Order by the sort_order column
         $aRating = $a->release_type->sort_order;
         $bRating = $b->release_type->sort_order;
         return $aRating - $bRating;
     });
 }
 /**
  * If a show is requested by slug loads it, or null if all shows (left blank)
  *
  * @throws ModelNotFoundException
  * @return Show|null
  */
 protected function loadShow()
 {
     $slug = $this->property('showSlug');
     if ($slug) {
         return Show::query()->where('slug', $this->property('showSlug'))->firstOrFail();
     } else {
         return null;
     }
 }
 /**
  * Set components state based on parameters
  *
  * @throws ModelNotFoundException
  */
 public function setState()
 {
     $this->show = $show = Show::query()->where('slug', $this->property('showSlug'))->firstOrFail();
     $this->releaseType = $releaseType = ReleaseType::query()->where('slug', $this->property('releaseTypeSlug'))->firstOrFail();
     $this->episodes = $this->show->episodes()->with(['releases' => function (Relation $query) use($releaseType) {
         /** @var Relation|Builder $query */
         $query->where('release_type_id', $releaseType->id);
     }])->where('published', true)->whereHas('releases', function (Builder $query) use($releaseType) {
         $query->where('release_type_id', $releaseType->id);
     })->orderBy('release', 'desc')->take(intval($this->property('itemLimit')))->get();
     $this->episodes->map(function (Episode $episode) use($show) {
         $episode->setRelation('show', $show);
     });
 }