94 lines
3.2 KiB
PHP
94 lines
3.2 KiB
PHP
<?php namespace Tps\Shops\Models;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Model;
|
|
use October\Rain\Exception\ApplicationException;
|
|
use October\Rain\Support\Facades\Input;
|
|
use ZipArchive;
|
|
|
|
/**
|
|
* Model
|
|
*/
|
|
class Report extends Model
|
|
{
|
|
use \October\Rain\Database\Traits\Validation;
|
|
|
|
|
|
public $implement = ['RainLab.Translate.Behaviors.TranslatableModel'];
|
|
/*
|
|
* Disable timestamps by default.
|
|
* Remove this line if timestamps are defined in the database table.
|
|
*/
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* @var string The database table used by the model.
|
|
*/
|
|
public $table = 'tps_shops_reports';
|
|
|
|
/**
|
|
* @var array Validation rules
|
|
*/
|
|
public $rules = [];
|
|
|
|
public $attachOne = [
|
|
'file' => 'System\Models\File',
|
|
// 'file' => 'Tps\Shops\Classes\FileAttachment',
|
|
];
|
|
|
|
public $translatable = ['name'];
|
|
|
|
// public function afterSave()
|
|
// public function beforeSave()
|
|
public function formAfterSave($model)
|
|
{
|
|
// $this->name = $this->file;
|
|
$filePath = \System\Models\File::find($model->id)->getLocalPath();
|
|
|
|
// $filePath = Input::file('file')->getPath();
|
|
Log::error("FILE PATH IS ------------------------".$filePath);
|
|
|
|
// throw new ApplicationException("FILE PATH IS ------------------------".$filePath);
|
|
// App::abort(403, "FILE PATH IS ------------------------".$filePath);
|
|
// $fileRecord = Input::file('file');
|
|
// $fileRecord = \System\Models\File::find($model->id);
|
|
// $files = \System\Models\File::find($model->file);
|
|
// $new = $this->file()->withDeferred($this->sessionKey)->first()->getPath();;
|
|
// $fileRecord = \October\Rain\Database\Models\DeferredBinding::where([
|
|
// 'master_type' => 'Tps\Shops\Models\Report', // <- REPLACE WITH YOUR MODEL(ModelName)
|
|
// "master_field" => "file", // <- REPLACE WITH ATTACHEMNT MODEL (gallery)
|
|
// "slave_type" => "System\Models\File",
|
|
// "session_key" => post('_session_key')
|
|
// ])->get()->first();
|
|
|
|
// $fileRecord = (new \System\Models\File)->fromData($model->file, 'logo.png');
|
|
// $fileRecord = $model->file->getPath();;
|
|
// $fileRecord = $model->file->getLocalPath();;
|
|
// if($fileRecord){
|
|
// echo "<script>console.log('Debug Objects: " . $fileRecord . "' );</script>";
|
|
// dd($fileRecord);
|
|
|
|
// $zip = new ZipArchive();
|
|
// $status = $zip->open($fileRecord);
|
|
// if ($status !== true) {
|
|
// throw new \Exception($status);
|
|
// }
|
|
// else{
|
|
// $storageDestinationPath= storage_path("app/uploads/unzip/");
|
|
|
|
// if (!\File::exists( $storageDestinationPath)) {
|
|
// \File::makeDirectory($storageDestinationPath, 0755, true);
|
|
// }
|
|
// $zip->extractTo($storageDestinationPath);
|
|
// $zip->close();
|
|
// // return back()
|
|
// // ->with('success','You have successfully extracted zip.');
|
|
// }
|
|
// }else{
|
|
// // dd("aaa");
|
|
// }
|
|
|
|
}
|
|
}
|