Upload Files Booking, Mails, Attachments,
This commit is contained in:
parent
5daea268f7
commit
68b9d1ff88
92 changed files with 2837 additions and 1778 deletions
|
|
@ -42,10 +42,19 @@ class CMSContent extends Model
|
|||
protected static $fields = [
|
||||
'text' => 'Text (190 Zeichen)',
|
||||
'full_text' => 'Full Text (50K Zeichen)',
|
||||
'file' => 'Datei (PDF/JPG/PNG)',
|
||||
'integer' => 'Zahl (10 Stellen)',
|
||||
'decimal' => 'Kommazahl (10,2 Stellen)',
|
||||
];
|
||||
|
||||
public static $icon_ext = [
|
||||
'default' => 'fa fa-file',
|
||||
'pdf'=> 'fa fa-file-pdf',
|
||||
'jpg'=> 'fa fa-file-image',
|
||||
'png'=> 'fa fa-file-image',
|
||||
|
||||
];
|
||||
|
||||
protected $connection = 'mysql_stern';
|
||||
protected $table = 'c_m_s_contents';
|
||||
|
||||
|
|
@ -78,13 +87,88 @@ class CMSContent extends Model
|
|||
|
||||
public function getPreviewContent(){
|
||||
|
||||
$content = $this->{$this->field};
|
||||
if(strlen($content) > 40){
|
||||
return substr($content, 0, 40)." ...";
|
||||
if($this->isFile()){
|
||||
$content = '<i class="'.$this->getIconExt().'"></i> <a href="'.$this->getURL().'" target="_blank">Vorschau | '.$this->formatBytes().'</a>';
|
||||
}else{
|
||||
$content = $this->{$this->field};
|
||||
if(strlen($content) > 40){
|
||||
return substr($content, 0, 40)." ...";
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getContent(){
|
||||
switch ($this->field){
|
||||
case 'text':
|
||||
return $this->text;
|
||||
break;
|
||||
case 'full_text':
|
||||
return $this->full_text;
|
||||
break;
|
||||
case 'file':
|
||||
return \GuzzleHttp\json_decode($this->full_text);
|
||||
break;
|
||||
case 'integer':
|
||||
return $this->integer;
|
||||
|
||||
break;
|
||||
case 'decimal':
|
||||
return $this->decimal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FILE ------------------------
|
||||
public function isFile(){
|
||||
return $this->field === 'file' ? true : false;
|
||||
}
|
||||
/*'identifier', 'filename', 'dir', 'original_name', 'ext', 'mine', 'size'*/
|
||||
public function getFileContent($key= false){
|
||||
if($key && $this->isFile()){
|
||||
$file = \GuzzleHttp\json_decode($this->full_text);
|
||||
return isset($file->{$key}) ? $file->{$key} : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getIconExt(){
|
||||
$ext = $this->getFileContent('ext');
|
||||
return isset(self::$icon_ext[$ext]) ? self::$icon_ext[$ext] : self::$icon_ext['default'];
|
||||
}
|
||||
|
||||
public function getURL($do = false){
|
||||
return route('storage_file', [$this->id, 'cms_file', $do]);
|
||||
}
|
||||
|
||||
public function getPath(){
|
||||
$dir = $this->getFileContent('dir');
|
||||
$filename = $this->getFileContent('filename');
|
||||
return \Storage::disk('public')->path($dir.$filename);
|
||||
}
|
||||
|
||||
public function formatBytes($precision = 2)
|
||||
{
|
||||
$size = $this->getFileContent('size');
|
||||
if ($size > 0) {
|
||||
$size = (int) $size;
|
||||
$base = log($size) / log(1024);
|
||||
$suffixes = array(' bytes', ' KB', ' MB', ' GB', ' TB');
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||
}
|
||||
return $size;
|
||||
|
||||
}
|
||||
|
||||
public function deleteFile(){
|
||||
$dir = $this->getFileContent('dir');
|
||||
$filename = $this->getFileContent('filename');
|
||||
return \Storage::disk('public')->delete($dir.$filename);
|
||||
|
||||
}
|
||||
//end FILE ------------------------
|
||||
|
||||
public function _format_number($value){
|
||||
return preg_replace("/[^0-9,]/", "", $value);
|
||||
|
|
@ -124,6 +208,9 @@ class CMSContent extends Model
|
|||
case 'full_text':
|
||||
return $CMSContent->full_text;
|
||||
break;
|
||||
case 'file':
|
||||
return \GuzzleHttp\json_decode($CMSContent->full_text);
|
||||
break;
|
||||
case 'integer':
|
||||
return $CMSContent->integer;
|
||||
|
||||
|
|
@ -131,10 +218,12 @@ class CMSContent extends Model
|
|||
case 'decimal':
|
||||
return $CMSContent->decimal;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getModelBySlug($slug){
|
||||
return CMSContent::whereSlug(trim($slug))->first();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue