More Laravel/AdminLTE updates
This commit is contained in:
@@ -10,12 +10,14 @@ use App\Models\{Person,Tag};
|
||||
|
||||
abstract class Catalog extends Model
|
||||
{
|
||||
public function People()
|
||||
protected $dates = ['date_created'];
|
||||
|
||||
public function people()
|
||||
{
|
||||
return $this->belongsToMany(Person::class);
|
||||
}
|
||||
|
||||
public function Tags()
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany(Tag::class);
|
||||
}
|
||||
@@ -29,7 +31,7 @@ abstract class Catalog extends Model
|
||||
{
|
||||
return $query->where(function($query)
|
||||
{
|
||||
$query->where('duplicate','!=',TRUE)
|
||||
$query->where('duplicate','<>',TRUE)
|
||||
->orWhere('duplicate','=',NULL);
|
||||
});
|
||||
}
|
||||
@@ -43,7 +45,7 @@ abstract class Catalog extends Model
|
||||
{
|
||||
return $query->where(function($query)
|
||||
{
|
||||
$query->where('remove','!=',TRUE)
|
||||
$query->where('remove','<>',TRUE)
|
||||
->orWhere('remove','=',NULL);
|
||||
});
|
||||
}
|
||||
@@ -57,7 +59,7 @@ abstract class Catalog extends Model
|
||||
{
|
||||
return $query->where(function($query)
|
||||
{
|
||||
$query->where('scanned','!=',TRUE)
|
||||
$query->where('scanned','<>',TRUE)
|
||||
->orWhere('scanned','=',NULL);
|
||||
});
|
||||
}
|
||||
@@ -72,14 +74,16 @@ abstract class Catalog extends Model
|
||||
|
||||
/**
|
||||
* Date the multimedia was created
|
||||
* @todo return Carbon date or NULL
|
||||
*/
|
||||
public function date_taken()
|
||||
public function date_taken(): string
|
||||
{
|
||||
return $this->date_created ? date('Y-m-d H:i:s',$this->date_created) : 'UNKNOWN';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the date of the file
|
||||
* @todo return Carbon date or NULL
|
||||
*/
|
||||
public function file_date($type,$format=FALSE)
|
||||
{
|
||||
@@ -101,6 +105,7 @@ abstract class Catalog extends Model
|
||||
|
||||
/**
|
||||
* Determine the new name for the image
|
||||
* @todo Make Generic for Photo and Video
|
||||
*/
|
||||
public function file_path($short=FALSE,$new=FALSE)
|
||||
{
|
||||
@@ -117,7 +122,7 @@ abstract class Catalog extends Model
|
||||
/**
|
||||
* Calculate a file path ID based on the id of the file
|
||||
*/
|
||||
public function file_path_id($sep=3,$depth=9)
|
||||
public function file_path_id($sep=3,$depth=9): string
|
||||
{
|
||||
return trim(chunk_split(sprintf("%0{$depth}s",$this->id),$sep,'/'),'/');
|
||||
}
|
||||
@@ -131,37 +136,18 @@ abstract class Catalog extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the photo size
|
||||
* Return the file size
|
||||
* @deprecated
|
||||
*/
|
||||
public function file_size()
|
||||
{
|
||||
return (! is_readable($this->file_path())) ? NULL : filesize($this->file_path());
|
||||
}
|
||||
public function getFileSizeAttribute()
|
||||
{
|
||||
return (! is_readable($this->file_path())) ? NULL : filesize($this->file_path());
|
||||
}
|
||||
|
||||
public function getDateCreatedTextAttribute()
|
||||
{
|
||||
if ($this->date_created)
|
||||
return date('d-m-Y H:i:s',$this->date_created);
|
||||
}
|
||||
|
||||
public function getDuplicateTextAttribute()
|
||||
{
|
||||
return $this->TextTrueFalse($this->duplicate);
|
||||
}
|
||||
|
||||
public function getFlagTextAttribute()
|
||||
{
|
||||
return $this->TextTrueFalse($this->flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return item dimensions
|
||||
*/
|
||||
public function getDimensionsAttribute()
|
||||
public function getDimensionsAttribute(): string
|
||||
{
|
||||
return $this->width.'x'.$this->height;
|
||||
}
|
||||
@@ -174,6 +160,16 @@ abstract class Catalog extends Model
|
||||
return $this->HTMLCheckbox('duplicate',$this->id,$this->duplicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file size
|
||||
*
|
||||
* @return false|int|null
|
||||
*/
|
||||
public function getFileSizeAttribute()
|
||||
{
|
||||
return (! is_readable($this->file_path())) ? NULL : filesize($this->file_path());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML Checkbox for flagged
|
||||
*/
|
||||
@@ -182,6 +178,22 @@ abstract class Catalog extends Model
|
||||
return $this->HTMLCheckbox('flag',$this->id,$this->flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function getDuplicateTextAttribute()
|
||||
{
|
||||
return $this->TextTrueFalse($this->duplicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function getFlagTextAttribute()
|
||||
{
|
||||
return $this->TextTrueFalse($this->flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML Checkbox for remove
|
||||
*/
|
||||
@@ -193,11 +205,19 @@ abstract class Catalog extends Model
|
||||
/**
|
||||
* Display the GPS coordinates
|
||||
*/
|
||||
public function gps()
|
||||
public function gps(): string
|
||||
{
|
||||
return ($this->gps_lat AND $this->gps_lon) ? sprintf('%s/%s',$this->gps_lat,$this->gps_lon) : 'UNKNOWN';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an HTML checkbox
|
||||
*/
|
||||
protected function HTMLCheckbox($name,$id,$value)
|
||||
{
|
||||
return sprintf('<input type="checkbox" name="%s[%s]" value="1"%s>',$name,$id,$value ? ' checked="checked"' : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ID Info link
|
||||
*/
|
||||
@@ -207,19 +227,19 @@ abstract class Catalog extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an HTML checkbox
|
||||
* Determine if the parent dir is writable
|
||||
*
|
||||
* @param $dir
|
||||
* @return bool
|
||||
*/
|
||||
protected function HTMLCheckbox($name,$id,$value)
|
||||
{
|
||||
return sprintf('<input type="checkbox" name="%s[%s]" value="1"%s>',$name,$id,$value ? ' checked="checked"' : '');
|
||||
}
|
||||
|
||||
public function isParentWritable($dir)
|
||||
public function isParentWritable($dir): bool
|
||||
{
|
||||
if (file_exists($dir) AND is_writable($dir) AND is_dir($dir))
|
||||
return TRUE;
|
||||
|
||||
elseif ($dir == dirname($dir) OR file_exists($dir))
|
||||
return FALSE;
|
||||
|
||||
else
|
||||
return ($this->isParentWritable(dirname($dir)));
|
||||
}
|
||||
@@ -228,6 +248,7 @@ abstract class Catalog extends Model
|
||||
* Determine if a file is moveable
|
||||
*
|
||||
* useID boolean Determine if the path is based on the the ID or date
|
||||
* @todo Change to boolean and rename isMoveable() Log any FALSE reason.
|
||||
*/
|
||||
public function moveable()
|
||||
{
|
||||
@@ -270,7 +291,7 @@ abstract class Catalog extends Model
|
||||
/**
|
||||
* Return my class shortname
|
||||
*/
|
||||
public function objectType()
|
||||
public function objectType(): string
|
||||
{
|
||||
return (new \ReflectionClass($this))->getShortName();
|
||||
}
|
||||
@@ -301,24 +322,49 @@ abstract class Catalog extends Model
|
||||
return $short ? static::signaturetrim($this->signature) : $this->signature;
|
||||
}
|
||||
|
||||
public static function signaturetrim($signature,$chars=6)
|
||||
/**
|
||||
* Trim a string
|
||||
*
|
||||
* @todo rename stringtrim
|
||||
* @param string $string
|
||||
* @param int $chrs
|
||||
* @return string
|
||||
*/
|
||||
public static function stringtrim(string $string,int $chrs=6)
|
||||
{
|
||||
return sprintf('%s...%s',substr($signature,0,$chars),substr($signature,-1*$chars));
|
||||
return sprintf('%s...%s',substr($string,0,$chrs),substr($string,-1*$chrs));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param string $string
|
||||
* @param int $chrs
|
||||
* @return string
|
||||
*/
|
||||
public static function signaturetrim(string $string,int $chrs=6)
|
||||
{
|
||||
return static::stringtrim($string,$chrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the image should be moved
|
||||
*/
|
||||
public function shouldMove()
|
||||
public function shouldMove(): boolean
|
||||
{
|
||||
return ($this->filename != $this->file_path(TRUE,TRUE));
|
||||
}
|
||||
|
||||
protected function TextTrueFalse($value)
|
||||
protected function TextTrueFalse($value): string
|
||||
{
|
||||
return $value ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Check if this is redundant
|
||||
*
|
||||
* @param bool $includeme
|
||||
* @return mixed
|
||||
*/
|
||||
public function list_duplicate($includeme=FALSE)
|
||||
{
|
||||
return $this->list_duplicates($includeme)->pluck('id');
|
||||
@@ -326,6 +372,7 @@ abstract class Catalog extends Model
|
||||
|
||||
/**
|
||||
* Find duplicate images based on some attributes of the current image
|
||||
* @todo Optimise this query
|
||||
*/
|
||||
public function list_duplicates($includeme=FALSE)
|
||||
{
|
||||
@@ -338,7 +385,7 @@ abstract class Catalog extends Model
|
||||
if (! $includeme)
|
||||
$o->where(function($query)
|
||||
{
|
||||
$query->where('remove','!=',TRUE)
|
||||
$query->where('remove','<>',TRUE)
|
||||
->orWhere('remove','=',NULL);
|
||||
});
|
||||
|
||||
|
@@ -22,13 +22,14 @@ class Photo extends Abstracted\Catalog
|
||||
/**
|
||||
* Date the photo was taken
|
||||
*/
|
||||
public function date_taken()
|
||||
public function date_taken(): string
|
||||
{
|
||||
return $this->date_created ? (date('Y-m-d H:i:s',$this->date_created).($this->subsectime ? '.'.$this->subsectime : '')) : 'UNKNOWN';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the new name for the image
|
||||
* @todo Implement in Parent
|
||||
*/
|
||||
public function file_path($short=FALSE,$new=FALSE)
|
||||
{
|
||||
|
Reference in New Issue
Block a user