Add report details and fix relations
This commit is contained in:
parent
f0a3bf43e8
commit
f2b99b29a6
|
|
@ -1,5 +1,7 @@
|
|||
<?php namespace Tps\Shops\Classes;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class Extractor
|
||||
*
|
||||
|
|
@ -8,7 +10,8 @@
|
|||
* @author niceshipest
|
||||
*
|
||||
*/
|
||||
class Extractor{
|
||||
class Extractor
|
||||
{
|
||||
|
||||
/**
|
||||
* Checks file extension and calls suitable extractor functions.
|
||||
|
|
@ -16,18 +19,18 @@
|
|||
* @param $archive
|
||||
* @param $destination
|
||||
*/
|
||||
public static function extract($archive, $destination){
|
||||
public static function extract($archive, $destination)
|
||||
{
|
||||
$ext = pathinfo($archive, PATHINFO_EXTENSION);
|
||||
|
||||
switch ($ext) {
|
||||
case 'zip':
|
||||
$res = self::extractZipArchive($archive, $destination);
|
||||
break;
|
||||
case 'gz':
|
||||
|
||||
$res = self::extractGzipFile($archive, $destination);
|
||||
break;
|
||||
case 'rar':
|
||||
|
||||
$res = self::extractRarArchive($archive, $destination);
|
||||
break;
|
||||
}
|
||||
|
|
@ -41,7 +44,8 @@
|
|||
* @param $archive
|
||||
* @param $destination
|
||||
*/
|
||||
public static function extractZipArchive($archive, $destination){
|
||||
public static function extractZipArchive($archive, $destination)
|
||||
{
|
||||
// Check if webserver supports unzipping.
|
||||
if (!class_exists('ZipArchive')) {
|
||||
$GLOBALS['status'] = array('error' => 'Your PHP version does not support unzip functionality.');
|
||||
|
|
@ -51,7 +55,7 @@
|
|||
$zip = new \ZipArchive;
|
||||
|
||||
// Check if archive is readable.
|
||||
if($zip->open($archive) === TRUE){
|
||||
if ($zip->open($archive) === true) {
|
||||
// Check if destination is writable
|
||||
if (is_writeable($destination . '/')) {
|
||||
$zip->extractTo($destination);
|
||||
|
|
@ -74,7 +78,8 @@
|
|||
* @param $archive
|
||||
* @param $destination
|
||||
*/
|
||||
public static function extractGzipFile($archive, $destination){
|
||||
public static function extractGzipFile($archive, $destination)
|
||||
{
|
||||
// Check if zlib is enabled
|
||||
if (!function_exists('gzopen')) {
|
||||
$GLOBALS['status'] = array('error' => 'Error: Your PHP has no zlib support enabled.');
|
||||
|
|
@ -109,15 +114,16 @@
|
|||
* @param $archive
|
||||
* @param $destination
|
||||
*/
|
||||
public static function extractRarArchive($archive, $destination){
|
||||
public static function extractRarArchive($archive, $destination)
|
||||
{
|
||||
// Check if webserver supports unzipping.
|
||||
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.');
|
||||
return false;
|
||||
}
|
||||
// Check if archive is readable.
|
||||
if ($rar = \RarArchive::open($archive)) {
|
||||
|
||||
// Check if destination is writable
|
||||
if (is_writeable($destination . '/')) {
|
||||
$entries = $rar->getEntries();
|
||||
|
|
@ -136,6 +142,4 @@
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
@ -28,16 +28,16 @@ class Report extends Controller
|
|||
$sessionKey = uniqid('session_key', true);
|
||||
$path = $post->file()->withDeferred($sessionKey)->get()->first()->getPath();
|
||||
|
||||
$diviedPath = explode('storage/app', $path);
|
||||
|
||||
$extractor = new Extractor();
|
||||
$dividedPath = explode('storage/app', $path);
|
||||
|
||||
$storageDestinationPath= storage_path("app/extract/".hash('ripemd160', $post->name).'-'.$post->date);
|
||||
|
||||
if (!\File::exists($storageDestinationPath)) {
|
||||
\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('.', '..'));
|
||||
foreach ($filenames as $item) {
|
||||
|
|
@ -54,9 +54,12 @@ class Report extends Controller
|
|||
Log::info(explode('storage\app', $storageDestinationPath)[1].'/'.$item);
|
||||
$report_detail->save();
|
||||
Log::info("saved succesfully");
|
||||
}else Log::info("Record exist");
|
||||
}else Log::info("Shop not found");
|
||||
}else {
|
||||
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(){
|
||||
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 = [
|
||||
'file' => 'System\Models\File',
|
||||
// 'file' => 'Tps\Shops\Classes\FileAttachment',
|
||||
];
|
||||
|
||||
public $translatable = ['name'];
|
||||
|
|
|
|||
|
|
@ -31,7 +31,15 @@ class ReportDetail extends Model
|
|||
'Tps\Shops\Models\Report'
|
||||
],
|
||||
'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 function getCategoryFieldAttribute() {
|
||||
return $this->category->name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ columns:
|
|||
name:
|
||||
label: ' Name'
|
||||
type: text
|
||||
top_category_id:
|
||||
top_category_field:
|
||||
label: 'Top Category'
|
||||
type: text
|
||||
disabled: true
|
||||
sort_order:
|
||||
label: sort_order
|
||||
type: number
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ columns:
|
|||
id:
|
||||
label: id
|
||||
type: number
|
||||
report_id:
|
||||
label: report_id
|
||||
type: number
|
||||
shop_id:
|
||||
label: shop_id
|
||||
type: number
|
||||
report_field:
|
||||
label: report
|
||||
disabled: true
|
||||
shop_field:
|
||||
label: shop
|
||||
disabled: true
|
||||
file:
|
||||
label: file
|
||||
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:
|
||||
label: instagram_link
|
||||
type: text
|
||||
category_id:
|
||||
category_field:
|
||||
label: category
|
||||
type: number
|
||||
relation: category
|
||||
disabled: true
|
||||
created_at:
|
||||
label: created_at
|
||||
type: datetime
|
||||
|
|
|
|||
|
|
@ -34,3 +34,7 @@ navigation:
|
|||
label: Report
|
||||
url: tps/shops/report
|
||||
icon: icon-file-pdf-o
|
||||
side-menu-item7:
|
||||
label: 'Shop reports'
|
||||
url: tps/shops/reportdetails
|
||||
icon: icon-sitemap
|
||||
|
|
|
|||
Loading…
Reference in New Issue