2016-09-02 21:27:50 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
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 = [
|
2016-09-02 22:18:40 +01:00
|
|
|
'album_id',
|
2016-09-11 07:19:11 +01:00
|
|
|
'user_id',
|
2016-09-02 22:18:40 +01:00
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'file_name',
|
2016-09-06 19:47:25 +01:00
|
|
|
'storage_file_name',
|
2016-09-02 22:18:40 +01:00
|
|
|
'mime_type',
|
|
|
|
'file_size',
|
|
|
|
'metadata_version',
|
|
|
|
'taken_at',
|
|
|
|
'camera_make',
|
|
|
|
'camera_model',
|
2016-09-03 17:09:49 +01:00
|
|
|
'camera_software',
|
|
|
|
'width',
|
2016-09-08 23:22:29 +01:00
|
|
|
'height',
|
2016-10-05 14:49:44 +01:00
|
|
|
'is_analysed',
|
2017-09-16 08:26:05 +01:00
|
|
|
'raw_exif_data',
|
2017-09-17 09:20:35 +01:00
|
|
|
'aperture_fnumber',
|
|
|
|
'iso_number',
|
|
|
|
'shutter_speed',
|
2016-10-05 14:49:44 +01:00
|
|
|
'created_at',
|
|
|
|
'updated_at'
|
2016-09-02 21:27:50 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes that should be hidden for arrays.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = [
|
|
|
|
];
|
|
|
|
|
|
|
|
public function album()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Album::class);
|
|
|
|
}
|
2016-09-04 21:59:32 +01:00
|
|
|
|
2017-09-16 08:26:05 +01:00
|
|
|
public function exifUrl()
|
|
|
|
{
|
|
|
|
return route('viewExifData', [
|
|
|
|
'albumUrlAlias' => $this->album->url_path,
|
|
|
|
'photoFilename' => $this->storage_file_name
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2017-09-10 10:24:15 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2018-09-17 14:15:06 +01:00
|
|
|
public function postCommentUrl()
|
|
|
|
{
|
|
|
|
return route('postPhotoComment', [
|
|
|
|
'albumUrlAlias' => $this->album->url_path,
|
|
|
|
'photoFilename' => $this->storage_file_name
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-10-05 14:49:44 +01:00
|
|
|
public function thumbnailUrl($thumbnailName = null, $cacheBust = true)
|
2016-09-04 21:59:32 +01:00
|
|
|
{
|
2016-10-05 14:49:44 +01:00
|
|
|
$url = $this->album->getAlbumSource()->getUrlToPhoto($this, $thumbnailName);
|
|
|
|
|
|
|
|
if ($cacheBust)
|
|
|
|
{
|
|
|
|
// 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;
|
2016-09-04 21:59:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function url()
|
|
|
|
{
|
|
|
|
return route('viewPhoto', [
|
2017-04-17 21:31:45 +01:00
|
|
|
'albumUrlAlias' => $this->album->url_path,
|
2016-09-06 19:47:25 +01:00
|
|
|
'photoFilename' => $this->storage_file_name
|
2016-09-04 21:59:32 +01:00
|
|
|
]);
|
|
|
|
}
|
2016-09-02 21:27:50 +01:00
|
|
|
}
|