Add report details and fix relations

This commit is contained in:
Amanmyrat 2023-08-04 13:35:28 +05:00
parent f0a3bf43e8
commit f2b99b29a6
18 changed files with 342 additions and 164 deletions

View File

@ -1,5 +1,7 @@
<?php namespace Tps\Shops\Classes; <?php namespace Tps\Shops\Classes;
use Illuminate\Support\Facades\Log;
/** /**
* Class Extractor * Class Extractor
* *
@ -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,7 +44,8 @@
* @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.');
@ -51,7 +55,7 @@
$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);
@ -74,7 +78,8 @@
* @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.');
@ -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();
@ -136,6 +142,4 @@
return false; return false;
} }
} }
} }
?>

View File

@ -28,16 +28,16 @@ class Report extends Controller
$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) {
@ -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");
}
} }
} }
} }

View File

@ -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');
}
}

View File

@ -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>

View File

@ -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

View File

@ -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'

View File

@ -0,0 +1 @@
<?= $this->listRender() ?>

View File

@ -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>

View File

@ -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 ?>

View File

@ -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;
}
} }

View File

@ -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'];

View File

@ -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;
}
} }

View File

@ -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;
}
} }

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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