Updated photo viewing

This commit is contained in:
Deon George
2019-12-14 22:29:54 +11:00
parent 8f093f50b7
commit ebfdf3f7d5
10 changed files with 232 additions and 188 deletions

View File

@@ -10,7 +10,7 @@ use App\Models\{Person,Tag};
abstract class Catalog extends Model
{
protected $dates = ['date_created'];
protected static $includeSubSecTime = FALSE;
public function people()
{
@@ -22,6 +22,38 @@ abstract class Catalog extends Model
return $this->belongsToMany(Tag::class);
}
public function scopeDuplicates($query) {
if (! $this->exists)
return $query;
// Exclude this record
$query->where('id','<>',$this->attributes['id']);
// Exclude those marked as remove
$query->where(function ($q) {
$q->where('remove','<>',TRUE)
->orWhere('remove','=',NULL);
});
$query->where(function ($q) {
$q->where('signature','=',$this->attributes['signature'])
->orWhere('file_signature','=',$this->attributes['file_signature'])
// Where the signature is the same
->orWhere(function($q) {
// Or they have the same time taken with the same camera
if ($this->attributes['date_created'] AND $this->software_id) {
$q->where('date_created','=',$this->attributes['date_created'] ?: NULL);
if (static::$includeSubSecTime)
$q->where('subsectime','=',$this->attributes['subsectime'] ?: NULL);
$q->where('software_id','=',$this->attributes['software_id']);
}
});
});
}
/**
* Multimedia NOT duplicate.
*
@@ -66,21 +98,35 @@ abstract class Catalog extends Model
abstract public function setDateCreated();
abstract public function setLocation();
abstract public function setMakeModel();
abstract public function setSignature();
abstract public function setSubSecTime();
abstract public function setThumbnail();
abstract public function view();
abstract public function getHtmlImageURL();
/**
* Date the multimedia was created
* @todo return Carbon date or NULL
*/
public function date_taken(): string
{
return $this->date_created ? date('Y-m-d H:i:s',$this->date_created) : 'UNKNOWN';
}
public function device(): string
{
$result = '';
if ($this->software->model->make)
$result .= $this->software->model->make->name;
if ($this->software->model)
$result .= ($result ? ' ' : '').$this->software->model->name;
if ($this->software)
$result .= ($result ? ' ' : '').$this->software->name;
return $result;
}
/**
* Return the date of the file
* @todo return Carbon date or NULL
@@ -130,9 +176,9 @@ abstract class Catalog extends Model
/**
* Display the file signature
*/
public function file_signature($short=FALSE)
public function file_signature($short=FALSE): string
{
return $short ? static::signaturetrim($this->file_signature) : $this->file_signature;
return $short ? static::stringtrim($this->file_signature) : $this->file_signature;
}
/**
@@ -349,7 +395,7 @@ abstract class Catalog extends Model
/**
* Determine if the image should be moved
*/
public function shouldMove(): boolean
public function shouldMove(): bool
{
return ($this->filename != $this->file_path(TRUE,TRUE));
}
@@ -372,7 +418,7 @@ abstract class Catalog extends Model
/**
* Find duplicate images based on some attributes of the current image
* @todo Optimise this query
* @deprecate Use static::duplicates()
*/
public function list_duplicates($includeme=FALSE)
{