139 lines
3.3 KiB
PHP
139 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\AlbumSources\IAlbumSource;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
class Photo extends Model
|
|
{
|
|
use Notifiable;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'album_id',
|
|
'user_id',
|
|
'name',
|
|
'description',
|
|
'file_name',
|
|
'storage_file_name',
|
|
'mime_type',
|
|
'file_size',
|
|
'metadata_version',
|
|
'taken_at',
|
|
'camera_make',
|
|
'camera_model',
|
|
'camera_software',
|
|
'width',
|
|
'height',
|
|
'is_analysed',
|
|
'raw_exif_data',
|
|
'aperture_fnumber',
|
|
'iso_number',
|
|
'shutter_speed',
|
|
'created_at',
|
|
'updated_at'
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for arrays.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
];
|
|
|
|
public function album()
|
|
{
|
|
return $this->belongsTo(Album::class);
|
|
}
|
|
|
|
public function comments()
|
|
{
|
|
return $this->hasMany(PhotoComment::class);
|
|
}
|
|
|
|
public function exifUrl()
|
|
{
|
|
return route('viewExifData', [
|
|
'albumUrlAlias' => $this->album->url_path,
|
|
'photoFilename' => $this->storage_file_name
|
|
]);
|
|
}
|
|
|
|
public function labelIDs()
|
|
{
|
|
$labelIDs = [];
|
|
|
|
foreach ($this->labels()->orderBy('name')->get() as $label)
|
|
{
|
|
$labelIDs[] = $label->id;
|
|
}
|
|
|
|
return implode(',', $labelIDs);
|
|
}
|
|
|
|
public function labels()
|
|
{
|
|
return $this->belongsToMany(Label::class, 'photo_labels');
|
|
}
|
|
|
|
public function moderateCommentUrl($commentID = -1)
|
|
{
|
|
return route('moderatePhotoComment', [
|
|
'albumUrlAlias' => $this->album->url_path,
|
|
'photoFilename' => $this->storage_file_name,
|
|
'commentID' => $commentID
|
|
]);
|
|
}
|
|
|
|
public function postCommentUrl()
|
|
{
|
|
return route('postPhotoComment', [
|
|
'albumUrlAlias' => $this->album->url_path,
|
|
'photoFilename' => $this->storage_file_name
|
|
]);
|
|
}
|
|
|
|
public function replyToCommentFormUrl($commentID = -1)
|
|
{
|
|
return route('replyPhotoComment', [
|
|
'albumUrlAlias' => $this->album->url_path,
|
|
'photoFilename' => $this->storage_file_name,
|
|
'commentID' => $commentID
|
|
]);
|
|
}
|
|
|
|
public function thumbnailUrl($thumbnailName = null, $cacheBust = true)
|
|
{
|
|
/** @var IAlbumSource $source */
|
|
$source = $this->album->getAlbumSource();
|
|
$sourceConfiguration = $source->getConfiguration();
|
|
|
|
$url = $source->getUrlToPhoto($this, $thumbnailName);
|
|
|
|
// Cache busting doesn't work with S3 signed URLs
|
|
if ($cacheBust && !$sourceConfiguration->s3_signed_urls)
|
|
{
|
|
// Append the timestamp of the last update to avoid browser caching
|
|
$theDate = is_null($this->updated_at) ? $this->created_at : $this->updated_at;
|
|
$url .= sprintf('%s_=%d', (strpos($url, '?') === false ? '?' : '&'), $theDate->format('U'));
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
|
|
public function url()
|
|
{
|
|
return route('viewPhoto', [
|
|
'albumUrlAlias' => $this->album->url_path,
|
|
'photoFilename' => $this->storage_file_name
|
|
]);
|
|
}
|
|
}
|