Refactor Catalog Model

This commit is contained in:
Deon George 2024-09-16 23:26:54 +10:00
parent 2caff58f73
commit 32e2dcf347

View File

@ -101,7 +101,8 @@ abstract class Catalog extends Model
$query->where('id','<>',$this->attributes['id']);
// Skip ignore dups
$query->where(fn($q)=>$q->whereNull('ignore_duplicate')->orWhere('ignore_duplicate',FALSE));
$query->where(fn($q)=>$q->whereNull('ignore_duplicate')
->orWhere('ignore_duplicate',FALSE));
// Exclude those marked as remove
$query->where(fn($q)=>$q->where('remove','<>',TRUE));
@ -113,16 +114,18 @@ abstract class Catalog extends Model
// Where the signature is the same
->orWhere(function($q) {
// Or they have the same time taken with the same camera
if ($this->attributes['created'] AND $this->software_id) {
$q->where(fn($q)=>$q->where('created','=',$this->attributes['created'])->orWhere('created_manual','=',$this->attributes['created']));
if ($this->attributes['created'] && $this->software_id) {
$q->where(fn($q)=>$q->where('created','=',$this->attributes['created'])
->orWhere('created_manual','=',$this->attributes['created']));
if (static::$includeSubSecTime)
$q->where('subsectime','=',Arr::get($this->attributes,'subsectime'));
$q->where('software_id','=',$this->attributes['software_id']);
} elseif ($this->attributes['created_manual'] AND $this->software_id) {
$q->where(fn($q)=>$q->where('created','=',$this->attributes['created_manual'])->orWhere('created_manual','=',$this->attributes['created_manual']));
} elseif ($this->attributes['created_manual'] && $this->software_id) {
$q->where(fn($q)=>$q->where('created','=',$this->attributes['created_manual'])
->orWhere('created_manual','=',$this->attributes['created_manual']));
if (static::$includeSubSecTime)
$q->where('subsectime','=',Arr::get($this->attributes,'subsectime'));
@ -364,15 +367,6 @@ abstract class Catalog extends Model
return sprintf('<input type="checkbox" name="%s[%s]" value="1"%s>',$name,$id,$value ? ' checked="checked"' : '');
}
/**
* Get ID Info link
* @deprecated use a component
*/
protected function HTMLLinkAttribute($id,$url)
{
return sprintf('<a href="%s" target="%s">%s</a>',url($url,$id),$id,$id);
}
/**
* Set values from the media object
*
@ -424,6 +418,8 @@ abstract class Catalog extends Model
$this->software_id = $so->id;
break;
case 'subsectime':
$this->subsectime = $this->getObjectOriginal($item);
break;
@ -479,7 +475,7 @@ abstract class Catalog extends Model
public function isMoveableReason(): ?string
{
return isset($this->move_reason) ? $this->move_reason : NULL;
return $this->move_reason ?? NULL;
}
/**
@ -564,20 +560,8 @@ abstract class Catalog extends Model
return $value ? 'TRUE' : 'FALSE';
}
/**
* @todo Check if this is redundant
*
* @param bool $includeme
* @return mixed
*/
private function list_duplicate($includeme=FALSE)
{
return $this->list_duplicates($includeme)->pluck('id');
}
/**
* Find duplicate images based on some attributes of the current image
* @deprecate Use static::duplicates()
*/
private function list_duplicates($includeme=FALSE)
{
@ -606,7 +590,7 @@ abstract class Catalog extends Model
{
$query->where('date_created','=',$this->date_created ? $this->date_created : NULL);
if (Schema::hasColumn($this->getTable(),'subsectime'))
$query->where('subsectime','=',$this->subsectime ? $this->subsectime : NULL);
$query->where('subsectime','=',$this->subsectime ?: NULL);
if (! is_null($this->model))
$query->where('model','=',$this->model);