2017-09-10 09:07:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2017-09-10 14:01:20 +01:00
|
|
|
use App\Helpers\DbHelper;
|
2017-09-10 11:24:44 +01:00
|
|
|
use App\Helpers\MiscHelper;
|
2017-09-10 09:07:56 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Label extends Model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2017-09-10 11:24:44 +01:00
|
|
|
'name', 'url_alias'
|
2017-09-10 09:07:56 +01:00
|
|
|
];
|
|
|
|
|
2017-09-10 11:24:44 +01:00
|
|
|
public function generateAlias()
|
|
|
|
{
|
|
|
|
$this->url_alias = preg_replace('/[^a-z0-9\-]/', '-', strtolower($this->name));
|
|
|
|
}
|
|
|
|
|
2017-09-10 14:01:20 +01:00
|
|
|
public function photoCount()
|
|
|
|
{
|
|
|
|
return $this->photos()->whereIn('album_id', DbHelper::getAlbumIDsForCurrentUser())->count();
|
|
|
|
}
|
|
|
|
|
2017-09-10 09:07:56 +01:00
|
|
|
public function photos()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Photo::class, 'photo_labels');
|
|
|
|
}
|
2017-09-10 12:52:41 +01:00
|
|
|
|
2017-09-10 13:21:45 +01:00
|
|
|
public function thumbnailUrl($thumbnailName)
|
|
|
|
{
|
|
|
|
$photo = $this->photos()
|
2017-09-10 14:01:20 +01:00
|
|
|
->whereIn('album_id', DbHelper::getAlbumIDsForCurrentUser())
|
2017-09-10 13:21:45 +01:00
|
|
|
->inRandomOrder()
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if (!is_null($photo))
|
|
|
|
{
|
|
|
|
return $photo->album->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)];
|
|
|
|
}
|
|
|
|
|
2017-09-10 12:52:41 +01:00
|
|
|
public function url()
|
|
|
|
{
|
|
|
|
return route('viewLabel', $this->url_alias);
|
|
|
|
}
|
2017-09-10 09:07:56 +01:00
|
|
|
}
|