Fixed date formatting in document list

This commit is contained in:
Hillel Coren 2016-05-26 18:28:36 +03:00
parent 94331c2858
commit 7599edbc8c

View File

@ -61,31 +61,31 @@ class DocumentRepository extends BaseRepository
{ {
$extension = strtolower($uploaded->getClientOriginalExtension()); $extension = strtolower($uploaded->getClientOriginalExtension());
if(empty(Document::$types[$extension]) && !empty(Document::$extraExtensions[$extension])){ if(empty(Document::$types[$extension]) && !empty(Document::$extraExtensions[$extension])){
$documentType = Document::$extraExtensions[$extension]; $documentType = Document::$extraExtensions[$extension];
} }
else{ else{
$documentType = $extension; $documentType = $extension;
} }
if(empty(Document::$types[$documentType])){ if(empty(Document::$types[$documentType])){
return 'Unsupported file type'; return 'Unsupported file type';
} }
$documentTypeData = Document::$types[$documentType]; $documentTypeData = Document::$types[$documentType];
$filePath = $uploaded->path(); $filePath = $uploaded->path();
$name = $uploaded->getClientOriginalName(); $name = $uploaded->getClientOriginalName();
$size = filesize($filePath); $size = filesize($filePath);
if($size/1000 > MAX_DOCUMENT_SIZE){ if($size/1000 > MAX_DOCUMENT_SIZE){
return 'File too large'; return 'File too large';
} }
$hash = sha1_file($filePath); $hash = sha1_file($filePath);
$filename = \Auth::user()->account->account_key.'/'.$hash.'.'.$documentType; $filename = \Auth::user()->account->account_key.'/'.$hash.'.'.$documentType;
$document = Document::createNew(); $document = Document::createNew();
$disk = $document->getDisk(); $disk = $document->getDisk();
if(!$disk->exists($filename)){// Have we already stored the same file if(!$disk->exists($filename)){// Have we already stored the same file
@ -93,7 +93,7 @@ class DocumentRepository extends BaseRepository
$disk->getDriver()->putStream($filename, $stream, ['mimetype'=>$documentTypeData['mime']]); $disk->getDriver()->putStream($filename, $stream, ['mimetype'=>$documentTypeData['mime']]);
fclose($stream); fclose($stream);
} }
// This is an image; check if we need to create a preview // This is an image; check if we need to create a preview
if(in_array($documentType, array('jpeg','png','gif','bmp','tiff','psd'))){ if(in_array($documentType, array('jpeg','png','gif','bmp','tiff','psd'))){
$makePreview = false; $makePreview = false;
@ -105,32 +105,32 @@ class DocumentRepository extends BaseRepository
// Needs to be converted // Needs to be converted
$makePreview = true; $makePreview = true;
} else if($width > DOCUMENT_PREVIEW_SIZE || $height > DOCUMENT_PREVIEW_SIZE){ } else if($width > DOCUMENT_PREVIEW_SIZE || $height > DOCUMENT_PREVIEW_SIZE){
$makePreview = true; $makePreview = true;
} }
if(in_array($documentType,array('bmp','tiff','psd'))){ if(in_array($documentType,array('bmp','tiff','psd'))){
if(!class_exists('Imagick')){ if(!class_exists('Imagick')){
// Cant't read this // Cant't read this
$makePreview = false; $makePreview = false;
} else { } else {
$imgManagerConfig['driver'] = 'imagick'; $imgManagerConfig['driver'] = 'imagick';
} }
} }
if($makePreview){ if($makePreview){
$previewType = 'jpeg'; $previewType = 'jpeg';
if(in_array($documentType, array('png','gif','tiff','psd'))){ if(in_array($documentType, array('png','gif','tiff','psd'))){
// Has transparency // Has transparency
$previewType = 'png'; $previewType = 'png';
} }
$document->preview = \Auth::user()->account->account_key.'/'.$hash.'.'.$documentType.'.x'.DOCUMENT_PREVIEW_SIZE.'.'.$previewType; $document->preview = \Auth::user()->account->account_key.'/'.$hash.'.'.$documentType.'.x'.DOCUMENT_PREVIEW_SIZE.'.'.$previewType;
if(!$disk->exists($document->preview)){ if(!$disk->exists($document->preview)){
// We haven't created a preview yet // We haven't created a preview yet
$imgManager = new ImageManager($imgManagerConfig); $imgManager = new ImageManager($imgManagerConfig);
$img = $imgManager->make($filePath); $img = $imgManager->make($filePath);
if($width <= DOCUMENT_PREVIEW_SIZE && $height <= DOCUMENT_PREVIEW_SIZE){ if($width <= DOCUMENT_PREVIEW_SIZE && $height <= DOCUMENT_PREVIEW_SIZE){
$previewWidth = $width; $previewWidth = $width;
$previewHeight = $height; $previewHeight = $height;
@ -141,9 +141,9 @@ class DocumentRepository extends BaseRepository
$previewHeight = DOCUMENT_PREVIEW_SIZE; $previewHeight = DOCUMENT_PREVIEW_SIZE;
$previewWidth = $width * DOCUMENT_PREVIEW_SIZE / $height; $previewWidth = $width * DOCUMENT_PREVIEW_SIZE / $height;
} }
$img->resize($previewWidth, $previewHeight); $img->resize($previewWidth, $previewHeight);
$previewContent = (string) $img->encode($previewType); $previewContent = (string) $img->encode($previewType);
$disk->put($document->preview, $previewContent); $disk->put($document->preview, $previewContent);
$base64 = base64_encode($previewContent); $base64 = base64_encode($previewContent);
@ -153,23 +153,23 @@ class DocumentRepository extends BaseRepository
} }
}else{ }else{
$base64 = base64_encode(file_get_contents($filePath)); $base64 = base64_encode(file_get_contents($filePath));
} }
} }
$document->path = $filename; $document->path = $filename;
$document->type = $documentType; $document->type = $documentType;
$document->size = $size; $document->size = $size;
$document->hash = $hash; $document->hash = $hash;
$document->name = substr($name, -255); $document->name = substr($name, -255);
if(!empty($imageSize)){ if(!empty($imageSize)){
$document->width = $imageSize[0]; $document->width = $imageSize[0];
$document->height = $imageSize[1]; $document->height = $imageSize[1];
} }
$document->save(); $document->save();
$doc_array = $document->toArray(); $doc_array = $document->toArray();
if(!empty($base64)){ if(!empty($base64)){
$mime = Document::$types[!empty($previewType)?$previewType:$documentType]['mime']; $mime = Document::$types[!empty($previewType)?$previewType:$documentType]['mime'];
$doc_array['base64'] = 'data:'.$mime.';base64,'.$base64; $doc_array['base64'] = 'data:'.$mime.';base64,'.$base64;
@ -177,10 +177,10 @@ class DocumentRepository extends BaseRepository
return $document; return $document;
} }
public function getClientDatatable($contactId, $entityType, $search) public function getClientDatatable($contactId, $entityType, $search)
{ {
$query = DB::table('invitations') $query = DB::table('invitations')
->join('accounts', 'accounts.id', '=', 'invitations.account_id') ->join('accounts', 'accounts.id', '=', 'invitations.account_id')
->join('invoices', 'invoices.id', '=', 'invitations.invoice_id') ->join('invoices', 'invoices.id', '=', 'invitations.invoice_id')
@ -192,7 +192,7 @@ class DocumentRepository extends BaseRepository
->where('clients.deleted_at', '=', null) ->where('clients.deleted_at', '=', null)
->where('invoices.is_recurring', '=', false) ->where('invoices.is_recurring', '=', false)
// This needs to be a setting to also hide the activity on the dashboard page // This needs to be a setting to also hide the activity on the dashboard page
//->where('invoices.invoice_status_id', '>=', INVOICE_STATUS_SENT) //->where('invoices.invoice_status_id', '>=', INVOICE_STATUS_SENT)
->select( ->select(
'invitations.invitation_key', 'invitations.invitation_key',
'invoices.invoice_number', 'invoices.invoice_number',
@ -205,22 +205,22 @@ class DocumentRepository extends BaseRepository
$table = \Datatable::query($query) $table = \Datatable::query($query)
->addColumn('invoice_number', function ($model) { ->addColumn('invoice_number', function ($model) {
return link_to( return link_to(
'/view/'.$model->invitation_key, '/view/'.$model->invitation_key,
$model->invoice_number $model->invoice_number
)->toHtml(); )->toHtml();
}) })
->addColumn('name', function ($model) { ->addColumn('name', function ($model) {
return link_to( return link_to(
'/client/documents/'.$model->invitation_key.'/'.$model->public_id.'/'.$model->name, '/client/documents/'.$model->invitation_key.'/'.$model->public_id.'/'.$model->name,
$model->name, $model->name,
['target'=>'_blank'] ['target'=>'_blank']
)->toHtml(); )->toHtml();
}) })
->addColumn('document_date', function ($model) { ->addColumn('document_date', function ($model) {
return Utils::fromSqlDate($model->created_at); return Utils::dateToString($model->created_at);
}) })
->addColumn('document_size', function ($model) { ->addColumn('document_size', function ($model) {
return Form::human_filesize($model->size); return Form::human_filesize($model->size);
}); });
return $table->make(); return $table->make();