Add report details and fix relations
This commit is contained in:
parent
f0a3bf43e8
commit
f2b99b29a6
|
|
@ -1,6 +1,8 @@
|
||||||
<?php namespace Tps\Shops\Classes;
|
<?php namespace Tps\Shops\Classes;
|
||||||
|
|
||||||
/**
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
/**
|
||||||
* Class Extractor
|
* Class Extractor
|
||||||
*
|
*
|
||||||
* Extract a archive (zip/gzip/rar) file.
|
* Extract a archive (zip/gzip/rar) file.
|
||||||
|
|
@ -8,7 +10,8 @@
|
||||||
* @author niceshipest
|
* @author niceshipest
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Extractor{
|
class Extractor
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks file extension and calls suitable extractor functions.
|
* Checks file extension and calls suitable extractor functions.
|
||||||
|
|
@ -16,18 +19,18 @@
|
||||||
* @param $archive
|
* @param $archive
|
||||||
* @param $destination
|
* @param $destination
|
||||||
*/
|
*/
|
||||||
public static function extract($archive, $destination){
|
public static function extract($archive, $destination)
|
||||||
|
{
|
||||||
$ext = pathinfo($archive, PATHINFO_EXTENSION);
|
$ext = pathinfo($archive, PATHINFO_EXTENSION);
|
||||||
switch ($ext){
|
|
||||||
|
switch ($ext) {
|
||||||
case 'zip':
|
case 'zip':
|
||||||
$res = self::extractZipArchive($archive, $destination);
|
$res = self::extractZipArchive($archive, $destination);
|
||||||
break;
|
break;
|
||||||
case 'gz':
|
case 'gz':
|
||||||
|
|
||||||
$res = self::extractGzipFile($archive, $destination);
|
$res = self::extractGzipFile($archive, $destination);
|
||||||
break;
|
break;
|
||||||
case 'rar':
|
case 'rar':
|
||||||
|
|
||||||
$res = self::extractRarArchive($archive, $destination);
|
$res = self::extractRarArchive($archive, $destination);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -41,9 +44,10 @@
|
||||||
* @param $archive
|
* @param $archive
|
||||||
* @param $destination
|
* @param $destination
|
||||||
*/
|
*/
|
||||||
public static function extractZipArchive($archive, $destination){
|
public static function extractZipArchive($archive, $destination)
|
||||||
|
{
|
||||||
// Check if webserver supports unzipping.
|
// Check if webserver supports unzipping.
|
||||||
if(!class_exists('ZipArchive')){
|
if (!class_exists('ZipArchive')) {
|
||||||
$GLOBALS['status'] = array('error' => 'Your PHP version does not support unzip functionality.');
|
$GLOBALS['status'] = array('error' => 'Your PHP version does not support unzip functionality.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -51,18 +55,18 @@
|
||||||
$zip = new \ZipArchive;
|
$zip = new \ZipArchive;
|
||||||
|
|
||||||
// Check if archive is readable.
|
// Check if archive is readable.
|
||||||
if($zip->open($archive) === TRUE){
|
if ($zip->open($archive) === true) {
|
||||||
// Check if destination is writable
|
// Check if destination is writable
|
||||||
if(is_writeable($destination . '/')){
|
if (is_writeable($destination . '/')) {
|
||||||
$zip->extractTo($destination);
|
$zip->extractTo($destination);
|
||||||
$zip->close();
|
$zip->close();
|
||||||
$GLOBALS['status'] = array('success' => 'Files unzipped successfully');
|
$GLOBALS['status'] = array('success' => 'Files unzipped successfully');
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else {
|
||||||
$GLOBALS['status'] = array('error' => 'Directory not writeable by webserver.');
|
$GLOBALS['status'] = array('error' => 'Directory not writeable by webserver.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}else{
|
}else {
|
||||||
$GLOBALS['status'] = array('error' => 'Cannot read .zip archive.');
|
$GLOBALS['status'] = array('error' => 'Cannot read .zip archive.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -74,9 +78,10 @@
|
||||||
* @param $archive
|
* @param $archive
|
||||||
* @param $destination
|
* @param $destination
|
||||||
*/
|
*/
|
||||||
public static function extractGzipFile($archive, $destination){
|
public static function extractGzipFile($archive, $destination)
|
||||||
|
{
|
||||||
// Check if zlib is enabled
|
// Check if zlib is enabled
|
||||||
if(!function_exists('gzopen')){
|
if (!function_exists('gzopen')) {
|
||||||
$GLOBALS['status'] = array('error' => 'Error: Your PHP has no zlib support enabled.');
|
$GLOBALS['status'] = array('error' => 'Error: Your PHP has no zlib support enabled.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -94,10 +99,10 @@
|
||||||
fclose($file);
|
fclose($file);
|
||||||
|
|
||||||
// Check if file was extracted.
|
// Check if file was extracted.
|
||||||
if(file_exists($destination.'/'.$filename)){
|
if (file_exists($destination.'/'.$filename)) {
|
||||||
$GLOBALS['status'] = array('success' => 'File unzipped successfully.');
|
$GLOBALS['status'] = array('success' => 'File unzipped successfully.');
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else {
|
||||||
$GLOBALS['status'] = array('error' => 'Error unzipping file.');
|
$GLOBALS['status'] = array('error' => 'Error unzipping file.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -109,15 +114,16 @@
|
||||||
* @param $archive
|
* @param $archive
|
||||||
* @param $destination
|
* @param $destination
|
||||||
*/
|
*/
|
||||||
public static function extractRarArchive($archive, $destination){
|
public static function extractRarArchive($archive, $destination)
|
||||||
|
{
|
||||||
// Check if webserver supports unzipping.
|
// Check if webserver supports unzipping.
|
||||||
if(!class_exists('RarArchive')){
|
if (!class_exists('RarArchive')) {
|
||||||
|
Log::info('Your PHP version does not support .rar archive functionality.');
|
||||||
$GLOBALS['status'] = array('error' => 'Your PHP version does not support .rar archive functionality.');
|
$GLOBALS['status'] = array('error' => 'Your PHP version does not support .rar archive functionality.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check if archive is readable.
|
// Check if archive is readable.
|
||||||
if($rar = \RarArchive::open($archive)){
|
if ($rar = \RarArchive::open($archive)) {
|
||||||
|
|
||||||
// Check if destination is writable
|
// Check if destination is writable
|
||||||
if (is_writeable($destination . '/')) {
|
if (is_writeable($destination . '/')) {
|
||||||
$entries = $rar->getEntries();
|
$entries = $rar->getEntries();
|
||||||
|
|
@ -127,15 +133,13 @@
|
||||||
$rar->close();
|
$rar->close();
|
||||||
$GLOBALS['status'] = array('success' => 'File extracted successfully.');
|
$GLOBALS['status'] = array('success' => 'File extracted successfully.');
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else {
|
||||||
$GLOBALS['status'] = array('error' => 'Directory not writeable by webserver.');
|
$GLOBALS['status'] = array('error' => 'Directory not writeable by webserver.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}else{
|
}else {
|
||||||
$GLOBALS['status'] = array('error' => 'Cannot read .rar archive.');
|
$GLOBALS['status'] = array('error' => 'Cannot read .rar archive.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
?>
|
|
||||||
|
|
|
||||||
|
|
@ -23,30 +23,30 @@ class Report extends Controller
|
||||||
|
|
||||||
public function onExtractReports($id)
|
public function onExtractReports($id)
|
||||||
{
|
{
|
||||||
$post = ModelsReport::where("id",$id)->get()->first();
|
$post = ModelsReport::where("id", $id)->get()->first();
|
||||||
|
|
||||||
$sessionKey = uniqid('session_key', true);
|
$sessionKey = uniqid('session_key', true);
|
||||||
$path = $post->file()->withDeferred($sessionKey)->get()->first()->getPath();
|
$path = $post->file()->withDeferred($sessionKey)->get()->first()->getPath();
|
||||||
|
|
||||||
$diviedPath = explode('storage/app', $path);
|
$dividedPath = explode('storage/app', $path);
|
||||||
|
|
||||||
$extractor = new Extractor();
|
|
||||||
|
|
||||||
$storageDestinationPath= storage_path("app/extract/".hash('ripemd160', $post->name).'-'.$post->date);
|
$storageDestinationPath= storage_path("app/extract/".hash('ripemd160', $post->name).'-'.$post->date);
|
||||||
if (!\File::exists( $storageDestinationPath)) {
|
|
||||||
|
if (!\File::exists($storageDestinationPath)) {
|
||||||
\File::makeDirectory($storageDestinationPath, 0755, true);
|
\File::makeDirectory($storageDestinationPath, 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$extractor->extract(storage_path('app/'. $diviedPath[1]), $storageDestinationPath);
|
$extractor = new Extractor();
|
||||||
|
$extractor->extract(storage_path('app/'. $dividedPath[1]), $storageDestinationPath);
|
||||||
|
|
||||||
$filenames = array_diff(scandir($storageDestinationPath), array('.', '..'));
|
$filenames = array_diff(scandir($storageDestinationPath), array('.', '..'));
|
||||||
foreach($filenames as $item){
|
foreach ($filenames as $item) {
|
||||||
$shop_number = explode(".", $item)[0];
|
$shop_number = explode(".", $item)[0];
|
||||||
$shop = Shop::where("shop_number", $shop_number)->get()->first();
|
$shop = Shop::where("shop_number", $shop_number)->get()->first();
|
||||||
|
|
||||||
if($shop){
|
if ($shop) {
|
||||||
$exist = ReportDetail::where('report_id', $id)->where("shop_id", $shop->id)->get();
|
$exist = ReportDetail::where('report_id', $id)->where("shop_id", $shop->id)->get();
|
||||||
if($exist->isEmpty()){
|
if ($exist->isEmpty()) {
|
||||||
$report_detail = new ReportDetail();
|
$report_detail = new ReportDetail();
|
||||||
$report_detail->report_id = $id;
|
$report_detail->report_id = $id;
|
||||||
$report_detail->shop_id = $shop->id;
|
$report_detail->shop_id = $shop->id;
|
||||||
|
|
@ -54,9 +54,12 @@ class Report extends Controller
|
||||||
Log::info(explode('storage\app', $storageDestinationPath)[1].'/'.$item);
|
Log::info(explode('storage\app', $storageDestinationPath)[1].'/'.$item);
|
||||||
$report_detail->save();
|
$report_detail->save();
|
||||||
Log::info("saved succesfully");
|
Log::info("saved succesfully");
|
||||||
}else Log::info("Record exist");
|
}else {
|
||||||
}else Log::info("Shop not found");
|
Log::info("Record exist");
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
Log::info("Shop not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php namespace Tps\Shops\Controllers;
|
||||||
|
|
||||||
|
use Backend\Classes\Controller;
|
||||||
|
use BackendMenu;
|
||||||
|
|
||||||
|
class ReportDetails extends Controller
|
||||||
|
{
|
||||||
|
public $implement = [ 'Backend\Behaviors\ListController', 'Backend\Behaviors\FormController' ];
|
||||||
|
|
||||||
|
public $listConfig = 'config_list.yaml';
|
||||||
|
public $formConfig = 'config_form.yaml';
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
BackendMenu::setContext('Tps.Shops', 'main-menu-item', 'side-menu-item7');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<div data-control="toolbar">
|
||||||
|
<button
|
||||||
|
class="btn btn-default oc-icon-trash-o"
|
||||||
|
disabled="disabled"
|
||||||
|
onclick="$(this).data('request-data', {
|
||||||
|
checked: $('.control-list').listWidget('getChecked')
|
||||||
|
})"
|
||||||
|
data-request="onDelete"
|
||||||
|
data-request-confirm="<?= e(trans('backend::lang.list.delete_selected_confirm')) ?>"
|
||||||
|
data-trigger-action="enable"
|
||||||
|
data-trigger=".control-list input[type=checkbox]"
|
||||||
|
data-trigger-condition="checked"
|
||||||
|
data-request-success="$(this).prop('disabled', true)"
|
||||||
|
data-stripe-load-indicator>
|
||||||
|
<?= e(trans('backend::lang.list.delete_selected')) ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
name: ReportDetails
|
||||||
|
form: $/tps/shops/models/reportdetail/fields.yaml
|
||||||
|
modelClass: Tps\Shops\Models\ReportDetail
|
||||||
|
defaultRedirect: tps/shops/reportdetails
|
||||||
|
create:
|
||||||
|
redirect: 'tps/shops/reportdetails/update/:id'
|
||||||
|
redirectClose: tps/shops/reportdetails
|
||||||
|
update:
|
||||||
|
redirect: tps/shops/reportdetails
|
||||||
|
redirectClose: tps/shops/reportdetails
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
list: $/tps/shops/models/reportdetail/columns.yaml
|
||||||
|
modelClass: Tps\Shops\Models\ReportDetail
|
||||||
|
title: ReportDetails
|
||||||
|
noRecordsMessage: 'backend::lang.list.no_records'
|
||||||
|
showSetup: true
|
||||||
|
showCheckboxes: true
|
||||||
|
recordsPerPage: 20
|
||||||
|
toolbar:
|
||||||
|
buttons: list_toolbar
|
||||||
|
search:
|
||||||
|
prompt: 'backend::lang.list.search_prompt'
|
||||||
|
recordUrl: 'tps/shops/reportdetails/update/:id'
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<?= $this->listRender() ?>
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php Block::put('breadcrumb') ?>
|
||||||
|
<ul>
|
||||||
|
<li><a href="<?= Backend::url('tps/shops/reportdetails') ?>">ReportDetails</a></li>
|
||||||
|
<li><?= e($this->pageTitle) ?></li>
|
||||||
|
</ul>
|
||||||
|
<?php Block::endPut() ?>
|
||||||
|
|
||||||
|
<?php if (!$this->fatalError): ?>
|
||||||
|
|
||||||
|
<div class="form-preview">
|
||||||
|
<?= $this->formRenderPreview() ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<p class="flash-message static error"><?= e($this->fatalError) ?></p>
|
||||||
|
<?php endif ?>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="<?= Backend::url('tps/shops/reportdetails') ?>" class="btn btn-default oc-icon-chevron-left">
|
||||||
|
<?= e(trans('backend::lang.form.return_to_list')) ?>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php Block::put('breadcrumb') ?>
|
||||||
|
<ul>
|
||||||
|
<li><a href="<?= Backend::url('tps/shops/reportdetails') ?>">ReportDetails</a></li>
|
||||||
|
<li><?= e($this->pageTitle) ?></li>
|
||||||
|
</ul>
|
||||||
|
<?php Block::endPut() ?>
|
||||||
|
|
||||||
|
<?php if (!$this->fatalError): ?>
|
||||||
|
|
||||||
|
<?= Form::open(['class' => 'layout']) ?>
|
||||||
|
|
||||||
|
<div class="layout-row">
|
||||||
|
<?= $this->formRender() ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-buttons">
|
||||||
|
<div class="loading-indicator-container">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
data-request="onSave"
|
||||||
|
data-request-data="redirect:0"
|
||||||
|
data-hotkey="ctrl+s, cmd+s"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
|
||||||
|
class="btn btn-primary">
|
||||||
|
<?= e(trans('backend::lang.form.save')) ?>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-request="onSave"
|
||||||
|
data-request-data="close:1"
|
||||||
|
data-hotkey="ctrl+enter, cmd+enter"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
|
||||||
|
class="btn btn-default">
|
||||||
|
<?= e(trans('backend::lang.form.save_and_close')) ?>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="oc-icon-trash-o btn-icon danger pull-right"
|
||||||
|
data-request="onDelete"
|
||||||
|
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
|
||||||
|
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<span class="btn-text">
|
||||||
|
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/shops/reportdetails') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?= Form::close() ?>
|
||||||
|
|
||||||
|
<?php else: ?>
|
||||||
|
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
|
||||||
|
<p><a href="<?= Backend::url('tps/shops/reportdetails') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
|
||||||
|
<?php endif ?>
|
||||||
|
|
@ -46,4 +46,9 @@ class Category extends Model
|
||||||
public function getShops(){
|
public function getShops(){
|
||||||
return Shop::where('category_id', $this->id)->limit(6)->get();
|
return Shop::where('category_id', $this->id)->limit(6)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTopCategoryFieldAttribute() {
|
||||||
|
return $this->top_category->name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ class Report extends Model
|
||||||
|
|
||||||
public $attachOne = [
|
public $attachOne = [
|
||||||
'file' => 'System\Models\File',
|
'file' => 'System\Models\File',
|
||||||
// 'file' => 'Tps\Shops\Classes\FileAttachment',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public $translatable = ['name'];
|
public $translatable = ['name'];
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,15 @@ class ReportDetail extends Model
|
||||||
'Tps\Shops\Models\Report'
|
'Tps\Shops\Models\Report'
|
||||||
],
|
],
|
||||||
'shop' => [
|
'shop' => [
|
||||||
'RainLab\User\Models\Shop'
|
'Tps\Shops\Models\Shop'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function getShopFieldAttribute() {
|
||||||
|
return $this->shop->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getReportFieldAttribute() {
|
||||||
|
return $this->report->name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,4 +48,8 @@ class Shop extends Model
|
||||||
];
|
];
|
||||||
|
|
||||||
public $translatable = ['name','description','open_time'];
|
public $translatable = ['name','description','open_time'];
|
||||||
|
|
||||||
|
public function getCategoryFieldAttribute() {
|
||||||
|
return $this->category->name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ columns:
|
||||||
name:
|
name:
|
||||||
label: ' Name'
|
label: ' Name'
|
||||||
type: text
|
type: text
|
||||||
top_category_id:
|
top_category_field:
|
||||||
label: 'Top Category'
|
label: 'Top Category'
|
||||||
type: text
|
disabled: true
|
||||||
sort_order:
|
sort_order:
|
||||||
label: sort_order
|
label: sort_order
|
||||||
type: number
|
type: number
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ columns:
|
||||||
id:
|
id:
|
||||||
label: id
|
label: id
|
||||||
type: number
|
type: number
|
||||||
report_id:
|
report_field:
|
||||||
label: report_id
|
label: report
|
||||||
type: number
|
disabled: true
|
||||||
shop_id:
|
shop_field:
|
||||||
label: shop_id
|
label: shop
|
||||||
type: number
|
disabled: true
|
||||||
file:
|
file:
|
||||||
label: file
|
label: file
|
||||||
type: text
|
type: text
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
fields:
|
||||||
|
shop:
|
||||||
|
label: Shop
|
||||||
|
nameFrom: name
|
||||||
|
descriptionFrom: description
|
||||||
|
span: auto
|
||||||
|
type: relation
|
||||||
|
report:
|
||||||
|
label: Report
|
||||||
|
nameFrom: name
|
||||||
|
descriptionFrom: description
|
||||||
|
span: auto
|
||||||
|
type: relation
|
||||||
|
file:
|
||||||
|
label: File
|
||||||
|
span: auto
|
||||||
|
type: text
|
||||||
|
|
@ -17,10 +17,9 @@ columns:
|
||||||
instagram_link:
|
instagram_link:
|
||||||
label: instagram_link
|
label: instagram_link
|
||||||
type: text
|
type: text
|
||||||
category_id:
|
category_field:
|
||||||
label: category
|
label: category
|
||||||
type: number
|
disabled: true
|
||||||
relation: category
|
|
||||||
created_at:
|
created_at:
|
||||||
label: created_at
|
label: created_at
|
||||||
type: datetime
|
type: datetime
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,7 @@ navigation:
|
||||||
label: Report
|
label: Report
|
||||||
url: tps/shops/report
|
url: tps/shops/report
|
||||||
icon: icon-file-pdf-o
|
icon: icon-file-pdf-o
|
||||||
|
side-menu-item7:
|
||||||
|
label: 'Shop reports'
|
||||||
|
url: tps/shops/reportdetails
|
||||||
|
icon: icon-sitemap
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue