Code Duplication    Length = 17-25 lines in 2 locations

controllers/Episodes.php 1 location

@@ 49-65 (lines=17) @@
46
        return $this->listRefresh();
47
    }
48
49
    public function listExtendQuery($query, $definition = null) {
50
        $user = BackendAuth::getUser();
51
52
        if (!$user->hasAccess(['cosmicradiotv.podcast.access_episodes_all'])) {
53
            $shows = Show::all();
54
            $show_ids_allowed = [];
55
56
            foreach ($shows as $show) {
57
                if ($user->hasAccess(['cosmicradiotv.podcast.access_show_'.$show->slug])) {
58
                    $show_ids_allowed[] = $show->id;
59
                }
60
            }
61
62
            $query->whereIn('show_id',$show_ids_allowed);
63
        }
64
65
    }
66
}

Plugin.php 1 location

@@ 58-82 (lines=25) @@
55
    /**
56
     * Called right before the request route.
57
     */
58
    public function boot()
59
    {
60
61
        // Extends the list query for shows so that it is restricted to shows the user has permission to access.
62
        Event::listen('backend.list.extendQueryBefore', function (Lists $list, $query) {
63
            /** @var \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query */
64
65
            if ($list->model instanceof \CosmicRadioTV\Podcast\Models\Show) {
66
                $user = BackendAuth::getUser();
67
                if (!$user->hasAccess(['cosmicradiotv.podcast.access_shows_all'])) {
68
                    $shows = Show::all();
69
                    $show_ids_allowed = [];
70
71
                    // Fills the list of allowed show ids.
72
                    foreach ($shows as $show) {
73
                        if ($user->hasAccess(['cosmicradiotv.podcast.access_show_' . $show->slug])) {
74
                            $show_ids_allowed[] = $show->id;
75
                        }
76
                    }
77
78
                    $query->whereIn('id', $show_ids_allowed);
79
                }
80
            }
81
        });
82
    }
83
84
    /**
85
     * Sets up the permissions for the plugin. It sets up permissions for every show that's in the database.