belongsToMany(Permission::class, 'album_anonymous_permissions'); } public function doesAnonymousHavePermission(Permission $permission) { return $this->anonymousPermissions()->where(['permission_id' => $permission->id])->count() > 0; } public function doesGroupHavePermission(Group $group, Permission $permission) { return $this->groupPermissions()->where([ 'group_id' => $group->id, 'permission_id' => $permission->id ])->count() > 0; } public function generateAlias() { $this->url_alias = ucfirst(preg_replace('/[^a-z0-9\-]/', '-', strtolower($this->name))); } /** * @return IAlbumSource */ public function getAlbumSource() { $fullClassName = sprintf('App\AlbumSources\%s', $this->storage->source); /** @var IAlbumSource $source */ $source = new $fullClassName; $source->setAlbum($this); $source->setConfiguration($this->storage); return $source; } public function groupPermissions() { return $this->belongsToMany(Permission::class, 'album_group_permissions'); } public function photos() { return $this->hasMany(Photo::class); } public function storage() { return $this->belongsTo(Storage::class); } public function thumbnailUrl($thumbnailName) { $photo = $this->photos() ->inRandomOrder() ->first(); if (!is_null($photo)) { return $this->getAlbumSource()->getUrlToPhoto($photo, $thumbnailName); } // Rotate standard images $images = [ asset('themes/base/images/empty-album-1.jpg'), asset('themes/base/images/empty-album-2.jpg'), asset('themes/base/images/empty-album-3.jpg') ]; return $images[rand(0, count($images) - 1)]; } public function url() { return route('viewAlbum', $this->url_alias); } }