main
This commit is contained in:
Executable
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\DB\Te;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\BeforeExport;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
|
||||
class ExcelCollection implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* TableEngineExport constructor.
|
||||
*/
|
||||
public function __construct($export, $cols)
|
||||
{
|
||||
$this->export = $export;
|
||||
$this->show = array_keys($cols);
|
||||
$this->head = array_values($cols);
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
|
||||
return $this->export->map(function ($value, $key) {
|
||||
|
||||
$exp = [];
|
||||
$all = $value->toArray();
|
||||
foreach ($this->show as $val) {
|
||||
$exp[$val] = Arr::get($all, $val);
|
||||
}
|
||||
return collect($exp);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$event->sheet->getDelegate()->setRightToLeft(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function headings(): array
|
||||
{
|
||||
return $this->head;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+303
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
namespace App\DB\Te;
|
||||
|
||||
use App\DB\Model;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: AraNote
|
||||
* Date: 12/04/2018
|
||||
* Time: 10:32 PM
|
||||
*/
|
||||
class Filter
|
||||
{
|
||||
|
||||
protected $type, $value, $crt, $name, $opt, $nl, $fn = ['where'], $args;
|
||||
/** @var Builder */
|
||||
public $query;
|
||||
|
||||
public $isArrayJson;
|
||||
|
||||
/**
|
||||
* Filter constructor.
|
||||
* @param $type
|
||||
* @param $text
|
||||
* @param $critical
|
||||
* @param $scope
|
||||
* @param $gt
|
||||
*/
|
||||
public function __construct(Builder $query, $data, $isFirst = false)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->isFirst = $isFirst;
|
||||
|
||||
foreach ($data as $key => $dt) {
|
||||
$this->{$key} = $dt;
|
||||
}
|
||||
if (isset($this->key) && starts_with($this->key, 'array')) {
|
||||
$this->isArrayJson = true;
|
||||
$this->key = str_replace_first('array@', '', $this->key);
|
||||
}
|
||||
|
||||
if (isset($this->key) && starts_with($this->key, 'object@')) {
|
||||
$this->key = str_replace_first('object@', '', $this->key);
|
||||
$this->key = str_replace('.', '->', $this->key);
|
||||
}
|
||||
// $this->field = $query->getModel()->convertColumns($this->field);
|
||||
$this->type = $data['type'] ?? 'text';
|
||||
$this->field = $data['field'] ?? null;
|
||||
$this->master = $data['master'] ?? null;
|
||||
$this->op = $data['op'] ?? null;
|
||||
$this->crt = $data['crt'] ?? null;
|
||||
$this->field = explode('.', $this->field);
|
||||
if (!is_null($this->master)) {
|
||||
$this->master = explode('.', $this->master);
|
||||
}
|
||||
$this->initFilter();
|
||||
}
|
||||
|
||||
public static function init($query, $data, $isFirst)
|
||||
{
|
||||
|
||||
return new Filter($query, $data, $isFirst);
|
||||
}
|
||||
|
||||
|
||||
public function getWhereHas()
|
||||
{
|
||||
if ($this->cr == 'or' && !$this->isFirst) return 'orWhereHas';
|
||||
return 'whereHas';
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
|
||||
if (sizeof($this->getNativeField()) > 1 && !Str::startsWith($this->getField(0), 'meta')) {
|
||||
$this->query->{$this->getWhereHas()}($this->snakeToCamelCase($this->getField(0)), function ($q) {
|
||||
if (sizeof($this->getNativeField()) > 2) {
|
||||
$q->whereHas($this->getField(1), function ($q2) {
|
||||
return $q2->{$this->getFn()}(...$this->args);
|
||||
});
|
||||
} else {
|
||||
return $q->{$this->getFn()}(...$this->args);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$this->query->{$this->getFn()}(...$this->args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function snakeToCamelCase($string, $capitalizeFirstCharacter = false)
|
||||
{
|
||||
|
||||
$str = str_replace('_', '', ucwords($string, '_'));
|
||||
|
||||
if (!$capitalizeFirstCharacter) {
|
||||
$str = lcfirst($str);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
public
|
||||
function getOpt()
|
||||
{
|
||||
return [
|
||||
'eq' => ($this->nl == 0) ? '=' : '<>',
|
||||
'gt' => ($this->nl == 0) ? '<' : '>',
|
||||
'lt' => ($this->nl == 0) ? '>' : '<',
|
||||
'bt' => ($this->nl == 0) ? '<>' : '='
|
||||
][$this->opt];
|
||||
}
|
||||
|
||||
public function dashesToCamelCase($string, $capitalizeFirstCharacter = false)
|
||||
{
|
||||
|
||||
$str = str_replace('-', '', ucwords($string, '-'));
|
||||
|
||||
if (!$capitalizeFirstCharacter) {
|
||||
$str = lcfirst($str);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getFn()
|
||||
{
|
||||
return $this->dashesToCamelCase(join('-', $this->fn));
|
||||
}
|
||||
|
||||
|
||||
public function getField($index= null)
|
||||
{
|
||||
if(is_null($index))
|
||||
return last($this->getNativeField());
|
||||
return $this->getNativeField()[$index];
|
||||
}
|
||||
|
||||
|
||||
public function getNativeField()
|
||||
{
|
||||
if (is_array($this->master)) {
|
||||
return $this->master;
|
||||
}
|
||||
return $this->field;
|
||||
}
|
||||
|
||||
|
||||
public function autoCorrectFieldName()
|
||||
{
|
||||
$map = config('maptable.convert_fields', []);
|
||||
if (Arr::has($map, $this->getNativeField())) {
|
||||
|
||||
$this->getNativeField()[sizeof($this->getNativeField()) - 1] = $map[Arr::last($this->getNativeField())];
|
||||
}
|
||||
|
||||
|
||||
$dc = config('maptable.convert_date', []);
|
||||
if ($this->type == 'date' && in_array($this->getField(), $dc)) {
|
||||
$this->value = Verta::parse($this->value)->datetime();
|
||||
}
|
||||
}
|
||||
|
||||
public function initFilter()
|
||||
{
|
||||
$this->autoCorrectFieldName();
|
||||
|
||||
if ($this->isArrayJson) {
|
||||
return ['and' => 'whereRaw', 'or' => 'orWhereRaw'][$this->crt];
|
||||
}
|
||||
if (is_null($this->args)) {
|
||||
$this->args = [];
|
||||
}
|
||||
|
||||
switch ($this->type) {
|
||||
case "date":
|
||||
$this->fn[] = 'date';
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($this->op) {
|
||||
case "gt" :
|
||||
$this->args = [$this->getField(), '>', $this->value];
|
||||
break;
|
||||
case "lt" :
|
||||
$this->args = [$this->getField(), '<', $this->value];
|
||||
break;
|
||||
case "eq" :
|
||||
$this->args = [$this->getField(), $this->value];
|
||||
break;
|
||||
case "gte" :
|
||||
$this->args = [$this->getField(), '>=', $this->value];
|
||||
break;
|
||||
case "lte" :
|
||||
$this->args = [$this->getField(), '<=', $this->value];
|
||||
break;
|
||||
case "bet" :
|
||||
$this->fn[] = 'between';
|
||||
break;
|
||||
case "not" :
|
||||
$this->args = [$this->getField(), '<>', $this->value];
|
||||
break;
|
||||
case "nn" :
|
||||
$this->fn[] = 'not';
|
||||
$this->fn[] = 'null';
|
||||
$this->args = [$this->getField()];
|
||||
break;
|
||||
case "null" :
|
||||
$this->fn[] = 'null';
|
||||
// if (sizeof($this->field) > 1) {
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
$this->args = [$this->getField()];
|
||||
break;
|
||||
case "sw" :
|
||||
$this->args = [$this->getField(), 'like', $this->value . '%'];
|
||||
break;
|
||||
case "ew" :
|
||||
$this->args = [$this->getField(), 'like', '%' . $this->value];
|
||||
break;
|
||||
case "has" :
|
||||
$this->args = [$this->getField(), 'like', '%' . $this->value . '%'];
|
||||
break;
|
||||
case "in" :
|
||||
$this->fn[] = ['in'];
|
||||
break;
|
||||
|
||||
}
|
||||
if (sizeof($this->args) == 0) {
|
||||
$this->args = [$this->getField(), $this->value];
|
||||
}
|
||||
|
||||
if ($this->cr == 'or' && !$this->isFirst) {
|
||||
array_unshift($this->fn, 'or');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function getArgs()
|
||||
{
|
||||
if ($this->isArrayJson) {
|
||||
if ($this->nl == 1) {
|
||||
return ["JSON_CONTAINS($this->key, '$this->value') = 0"];
|
||||
} elseif ($this->nl == 0) {
|
||||
return ["JSON_CONTAINS($this->key, '$this->value')"];
|
||||
}
|
||||
}
|
||||
|
||||
switch ($this->type) {
|
||||
case 'number':
|
||||
case 'date':
|
||||
$t = isset($this->key) ? [$this->key] : [$this->getLastField()];
|
||||
if ($this->nl < 2) {
|
||||
$t[] = $this->getOp();
|
||||
$t[] = $this->value;
|
||||
}
|
||||
return $t;
|
||||
break;
|
||||
case 'text':
|
||||
$t = isset($this->key) ? [$this->key] : [$this->getLastField()];
|
||||
|
||||
if ($this->nl == 0) {
|
||||
$t[] = 'LIKE';
|
||||
$t[] = '%' . $this->value . '%';
|
||||
} elseif ($this->nl == 1) {
|
||||
$t[] = 'NOT LIKE';
|
||||
$t[] = '%' . $this->value . '%';
|
||||
}
|
||||
return $t;
|
||||
break;
|
||||
case 'select':
|
||||
case 'switch':
|
||||
$t = isset($this->key) ? [$this->key] : [$this->getLastField()];
|
||||
if ($this->nl == 0) {
|
||||
$t[] = '=';
|
||||
$t[] = $this->value;
|
||||
} elseif ($this->nl == 1) {
|
||||
$t[] = '<>';
|
||||
$t[] = $this->value;
|
||||
}
|
||||
return $t;
|
||||
break;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getLastField()
|
||||
{
|
||||
return Arr::last($this->getNativeField());
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\DB\Te;
|
||||
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
|
||||
class QuerySelector
|
||||
{
|
||||
public static function run(Request $request)
|
||||
{
|
||||
|
||||
if (!$request->has('action')) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
$input = $request->all();
|
||||
if (!isset($input['query']) && !isset($input['default'])) {
|
||||
return response()->json(null);
|
||||
}
|
||||
$result = QuerySelector::searchQuery($request->all());
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
public static function searchQuery($input)
|
||||
{
|
||||
|
||||
$conf = Arr::get(config('query'), $input['action'], null);
|
||||
// dd($conf);
|
||||
if (is_null($conf)) {
|
||||
return null;
|
||||
}
|
||||
$conf = (object)$conf;
|
||||
if (isset($conf->fn) && isset($input['query'])) {
|
||||
return call_user_func($conf->fn, $input['query'], $input['extra'] ?? null);
|
||||
}
|
||||
$cols = explode(',', $conf->cols);
|
||||
if (isset($input['query'])) {
|
||||
$query = $conf->model::where($cols[0], 'like', '%' . $input['query'] . '%');
|
||||
}
|
||||
|
||||
|
||||
if (isset($input['default'])) {
|
||||
if (is_array($input['default'])) {
|
||||
$query = $conf->model::whereIn('id', $input['default']);
|
||||
} else {
|
||||
$query = $conf->model::whereId($input['default']);
|
||||
}
|
||||
}
|
||||
if (isset($conf->where)) {
|
||||
foreach ($conf->where as $ww) {
|
||||
$query->where(...$ww);
|
||||
}
|
||||
}
|
||||
if (isset($conf->select)) {
|
||||
$select = (is_callable($conf->select)) ? call_user_func($conf->select) : $conf->select;
|
||||
return $query->select($select)->limit(20)->get()->toArray();
|
||||
} else {
|
||||
return $query->select(array_merge(['id'], $cols))->limit(20)->get()->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\DB\Te;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: AraNote
|
||||
* Date: 12/04/2018
|
||||
* Time: 10:34 PM
|
||||
*/
|
||||
class Scope
|
||||
{
|
||||
public $items, $query;
|
||||
|
||||
/**
|
||||
* Scope constructor.
|
||||
* @param $items
|
||||
*/
|
||||
public function __construct($query, $items)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
|
||||
public static function init($query, $items)
|
||||
{
|
||||
return new Scope($query, $items);
|
||||
}
|
||||
|
||||
|
||||
public function run()
|
||||
{
|
||||
foreach ($this->items as $index => $item) {
|
||||
Filter::init($this->query, $item, $index == 0)->run();
|
||||
}
|
||||
// dd($this->query->toSql());
|
||||
return $this->query;
|
||||
}
|
||||
}
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace App\DB\Te;
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: AraNote
|
||||
* Date: 12/04/2018
|
||||
* Time: 10:32 PM
|
||||
*/
|
||||
class Search
|
||||
{
|
||||
|
||||
protected $cols, $text, $query;
|
||||
|
||||
public static function query(&$query, $cols, $search)
|
||||
{
|
||||
$query->where(function ($q) use ($cols, $search) {
|
||||
$first = true;
|
||||
foreach ($cols as $col) {
|
||||
if (self::hasJoin($col)) {
|
||||
$exp = explode('.', $col);
|
||||
if (sizeof($exp) > 2) {
|
||||
if ($first){
|
||||
$whereHas = 'whereHas';
|
||||
}else{
|
||||
$whereHas = 'orWhereHas';
|
||||
}
|
||||
$q->$whereHas
|
||||
($exp[0], function ($q) use ($exp, $search) {
|
||||
return $q->whereHas($exp[1], function ($q2) use ($exp, $search) {
|
||||
|
||||
// return $q2->where($exp[2], 'LIKE', '%' . $search . '%');
|
||||
return $q2->whereRaw('lower(`'.$exp[2].'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if ($first){
|
||||
$whereHas1 = 'whereHas';
|
||||
}else{
|
||||
$whereHas1 = 'orWhereHas';
|
||||
}
|
||||
$q->$whereHas1
|
||||
// $q->{($first) ? 'whereHas' : 'orWhereHas'}
|
||||
($exp[0], function ($q) use ($exp, $search) {
|
||||
return $q->whereRaw('lower(`'.$exp[1].'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
// return $q->where($exp[1], 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if ($first){
|
||||
$where = 'whereRaw';
|
||||
}else{
|
||||
$where = 'orWhereRaw';
|
||||
}
|
||||
// return $q->whereRaw('lower(`'.$col.'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
$q->$where('lower(`'.$col.'`) like ?', ['%' . strtolower($search) . '%']);
|
||||
// $q->{($first) ? 'where' : 'orWhere'}($col, 'LIKE', '%' . $search . '%');
|
||||
// $q->{($first) ? 'whereRaw ' : 'orWhereRaw '}($col, 'LIKE', '%' . $search . '%');
|
||||
}
|
||||
if ($first) {
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static function hasJoin($col)
|
||||
{
|
||||
return sizeof(explode('.', $col)) > 1;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+217
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace App\DB\Te;
|
||||
|
||||
use App\DB\Model;
|
||||
use App\Excel\TableExport;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Str;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class TableEngine
|
||||
{
|
||||
/////////
|
||||
protected $max = 5000, $cols, $type, $selection, $selectionHidden;
|
||||
|
||||
/** @var Search */
|
||||
protected $search;
|
||||
|
||||
/** @var Scope */
|
||||
protected $scope;
|
||||
|
||||
/** @var Model */
|
||||
protected $query;
|
||||
|
||||
|
||||
/** @var TableEngineInput */
|
||||
protected $input;
|
||||
|
||||
/**
|
||||
* TableEngine constructor.
|
||||
* @param $filters
|
||||
*/
|
||||
public function __construct(&$query, $inp, $i18nPrefix)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->i18nPrefix = $i18nPrefix;
|
||||
$this->input = TableEngineInput::create($inp);
|
||||
$this->filterQuery();
|
||||
|
||||
}
|
||||
|
||||
public static function create(&$query, $inp, $i18nPrefix = '')
|
||||
{
|
||||
return new TableEngine($query, $inp, $i18nPrefix);
|
||||
}
|
||||
|
||||
|
||||
public static function viewPrint($id)
|
||||
{
|
||||
view()->addNamespace('TE', app_path('DB/Te'));
|
||||
$json = json_decode(Storage::disk('public')->get($id . '.json', ""));
|
||||
return view('TE::views.print', ['records' => $json->records, 'meta' => $json->meta, 'Arr' => Arr::class]);
|
||||
}
|
||||
|
||||
public function initSearch($cols)
|
||||
{
|
||||
if ($this->input->hasSearch()) {
|
||||
Search::query($this->query, $cols, $this->input->search);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function hidden($cols)
|
||||
{
|
||||
$this->selection = $cols;
|
||||
$this->selectionHidden = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function select($cols)
|
||||
{
|
||||
$this->selection = $cols;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function batchOperation($func)
|
||||
{
|
||||
if ($this->input->hasSelectCommand() && $this->input->hasSelectItems()) {
|
||||
call_user_func($func,
|
||||
(object)['command' => $this->input->selectCommand,
|
||||
'items' => $this->input->selectItems]
|
||||
);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->query->get();
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function total()
|
||||
{
|
||||
$this->query->get();
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function export(&$export = null)
|
||||
{
|
||||
|
||||
|
||||
$ret = [
|
||||
'query' => [
|
||||
'limit' => $this->input->limit,
|
||||
'filters' => $this->input->filters,
|
||||
'filtersOpt' => $this->input->filtersOpt,
|
||||
'search' => $this->input->search,
|
||||
'key' => $this->input->key,
|
||||
'select' => $this->input->columns,
|
||||
'total' => $this->query->count(),
|
||||
'sort' => $this->input->sort,
|
||||
'page' => $this->input->page
|
||||
]
|
||||
];
|
||||
$this->sortQuery();
|
||||
|
||||
if (!($this->input->op == 'excel' || $this->input->op == 'json' || $this->input->op == 'print')) {
|
||||
$this->query
|
||||
->limit($this->input->limit)
|
||||
->offset(($this->input->page - 1) * $this->input->limit);
|
||||
}
|
||||
|
||||
|
||||
if (is_null($this->selectionHidden)) {
|
||||
$ret['rows'] = $this->query->select($this->selection)->get();
|
||||
|
||||
} else {
|
||||
$e = $this->query->get();
|
||||
foreach ($e as $model) {
|
||||
$model->addHidden($this->selection);
|
||||
};
|
||||
|
||||
|
||||
$ret['rows'] = $e->toArray();
|
||||
}
|
||||
if ($this->input->op == 'excel' || $this->input->op == 'json' || $this->input->op == 'print') {
|
||||
if ($this->input->op == 'excel') {
|
||||
$time = md5(time()) . '.xlsx';
|
||||
$ret['url'] = url('storage/excel/' . $time);
|
||||
Excel::store(new ExcelCollection($ret['rows'], $this->input->getShowColumns($this->i18nPrefix)), 'excel/' . $time);
|
||||
} else if ($this->input->op == 'json' || $this->input->op == 'print') {
|
||||
$json = new ExcelCollection($ret['rows'], $this->input->getShowColumns($this->i18nPrefix));
|
||||
$time = md5(time()) . '.json';
|
||||
$exp = [
|
||||
'records' => $json->collection()->toArray(),
|
||||
'meta' => [
|
||||
'title' => $this->input->reportTitle,
|
||||
'columns' => $this->input->columnTitles,
|
||||
'created_at' => Verta::now()->formatJalaliDatetime()
|
||||
]
|
||||
];
|
||||
Storage::disk('public')->put($time, json_encode($exp));
|
||||
if ($this->input->op == 'print') {
|
||||
$ret['url'] = url('site/te/print/' . Str::before($time, '.json'));
|
||||
} else {
|
||||
$ret['url'] = url('storage/' . $time);
|
||||
}
|
||||
}
|
||||
unset($ret['rows']);
|
||||
}
|
||||
if (is_null($export)) {
|
||||
return $ret;
|
||||
}
|
||||
$export = $ret;
|
||||
}
|
||||
|
||||
|
||||
protected function sortQuery()
|
||||
{
|
||||
|
||||
if ($this->input->hasSort()) {
|
||||
|
||||
$r = explode('.', $this->input->sort->key);
|
||||
if (sizeof($r) > 1) {
|
||||
$inp = $this->input->sort->order;
|
||||
$this->query->with([$r[0] => function ($q) use ($r, $inp) {
|
||||
return $q->orderBy($r[1], ($this->input->sort->order == 'descending') ? 'DESC' : 'ASC');
|
||||
}]);
|
||||
} else {
|
||||
$this->query->orderBy(
|
||||
$this->input->sort->key,
|
||||
($this->input->sort->order == 'descending') ? 'DESC' : 'ASC');
|
||||
}
|
||||
} else {
|
||||
$this->query->orderBy('id', 'DESC');
|
||||
}
|
||||
}
|
||||
|
||||
protected function filterQuery()
|
||||
{
|
||||
if ($this->input->hasFilters()) {
|
||||
$this->query->where(function ($q) {
|
||||
return Scope::init($q, $this->input->filters)->run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected function getWhere($op)
|
||||
{
|
||||
return Arr::get(['or' => 'orWhere', 'and' => 'where'], $op, 'where');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Executable
+160
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: AraNote
|
||||
* Date: 18/04/2018
|
||||
* Time: 06:27 PM
|
||||
*/
|
||||
|
||||
namespace App\DB\Te;
|
||||
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class TableEngineInput
|
||||
{
|
||||
|
||||
public $columns;
|
||||
public $columnTitles;
|
||||
public $reportTitle;
|
||||
public $filters;
|
||||
public $filtersOpt;
|
||||
public $selectCommand;
|
||||
public $selectItems;
|
||||
public $limit = 1000;
|
||||
public $page;
|
||||
public $key;
|
||||
public $sort;
|
||||
public $search;
|
||||
public $op;
|
||||
|
||||
/**
|
||||
* TableEngineInput constructor.
|
||||
*/
|
||||
public function __construct($input)
|
||||
{
|
||||
if (isset($input['select'])) {
|
||||
$this->columns = array_filter($input['select'], function ($item) {
|
||||
return $item != 'opt';
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($input['titles'])) {
|
||||
$this->columnTitles = $input['titles'];
|
||||
}
|
||||
if (isset($input['report_title'])) {
|
||||
$this->reportTitle = $input['report_title'];
|
||||
}
|
||||
|
||||
if (isset($input['filters'])) {
|
||||
$this->filters = $input['filters'];
|
||||
}
|
||||
|
||||
if (isset($input['limit'])) {
|
||||
$this->limit = $input['limit'];
|
||||
}
|
||||
|
||||
if (isset($input['page'])) {
|
||||
$this->page = $input['page'];
|
||||
}
|
||||
|
||||
if (isset($input['search'])) {
|
||||
$this->search = $input['search'];
|
||||
}
|
||||
|
||||
if (isset($input['text_search'])) {
|
||||
$this->search = $input['text_search'];
|
||||
}
|
||||
|
||||
if (isset($input['order'])) {
|
||||
$e = substr($input['order'], 0, 1);
|
||||
$col = substr($input['order'], 1);
|
||||
|
||||
$this->sort = (object)[
|
||||
'key' => $col,
|
||||
'order' => $e == '-' ? 'descending' : 'asc'
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($input['filtersOpt'])) {
|
||||
$this->filtersOpt = $input['filtersOpt'];
|
||||
}
|
||||
|
||||
if (isset($input['selectCommand'])) {
|
||||
$this->selectCommand = $input['selectCommand'];
|
||||
}
|
||||
|
||||
if (isset($input['selectItems'])) {
|
||||
$this->selectItems = $input['selectItems'];
|
||||
}
|
||||
|
||||
if (isset($input['key'])) {
|
||||
$this->key = $input['key'];
|
||||
}
|
||||
if (isset($input['op'])) {
|
||||
$this->op = $input['op'];
|
||||
$this->page = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function create($input)
|
||||
{
|
||||
if (is_null($input)) {
|
||||
return null;
|
||||
}
|
||||
return new TableEngineInput($input);
|
||||
}
|
||||
|
||||
|
||||
public function hasSearch()
|
||||
{
|
||||
return !is_null($this->search);
|
||||
}
|
||||
|
||||
|
||||
public function hasFilters()
|
||||
{
|
||||
return !is_null($this->filters);
|
||||
}
|
||||
|
||||
public function hasCols()
|
||||
{
|
||||
return !is_null($this->columns);
|
||||
}
|
||||
|
||||
public function hasLimit()
|
||||
{
|
||||
return !is_null($this->limit);
|
||||
}
|
||||
|
||||
public function hasSort()
|
||||
{
|
||||
return !is_null($this->sort);
|
||||
}
|
||||
|
||||
|
||||
public function hasSelectCommand()
|
||||
{
|
||||
return !is_null($this->selectCommand);
|
||||
}
|
||||
|
||||
public function hasSelectItems()
|
||||
{
|
||||
return !is_null($this->selectItems);
|
||||
}
|
||||
|
||||
|
||||
public function getShowColumns($i18nPrefix)
|
||||
{
|
||||
$exp = [];
|
||||
foreach ($this->columns as $col) {
|
||||
if (isset($this->columnTitles[$col])) {
|
||||
$exp[$col] = $this->columnTitles[$col];
|
||||
} else {
|
||||
$exp[$col] = trans('field.' . $i18nPrefix . $col);
|
||||
}
|
||||
}
|
||||
return $exp;
|
||||
}
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
@font-face {
|
||||
font-family: 'Vazir', sans-serif;
|
||||
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Vazir', sans-serif;
|
||||
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
body, *:not(i) {
|
||||
font-family: 'Vazir', sans-serif;
|
||||
}
|
||||
Executable
+1
@@ -0,0 +1 @@
|
||||
.container{max-width:980px;margin:auto;padding:10px}.body,header{border:1px solid #8080806e;padding:10px;border-radius:4px}.body{margin-top:10px}table{width:100%}table td,table th{text-align:right}table td:not(:last-child),table th:not(:last-child){border-left:1px solid #d6d6d6}table td:not(:first-child),table th:not(:first-child){padding-right:10px}table th{border-bottom:2px solid grey}table tr:not(:last-child) td{border-bottom:1px solid #d6d6d6}table tr:not(:last-child):nth-child(odd) td{background-color:#f7f7f7}.flex{display:flex}.fl-50{flex:50}.item .key{font-size:.9em}.item .key::after{content:" : "}.item .value{font-weight:800}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
.container {
|
||||
max-width: 980px;
|
||||
margin: auto;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
header, .body {
|
||||
border: 1px solid #8080806e;
|
||||
padding: 10px;
|
||||
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.body {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
|
||||
th, td {
|
||||
text-align: right;
|
||||
&:not(:last-child) {
|
||||
border-left: 1px solid #d6d6d6;
|
||||
}
|
||||
&:not(:first-child) {
|
||||
padding-right: 10px;
|
||||
}
|
||||
}
|
||||
th {
|
||||
border-bottom: 2px solid grey;
|
||||
}
|
||||
|
||||
tr:not(:last-child) {
|
||||
td {
|
||||
border-bottom: 1px solid #d6d6d6;
|
||||
}
|
||||
&:nth-child(odd) {
|
||||
td {
|
||||
background-color: #f7f7f7;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.fl-50 {
|
||||
flex: 50;
|
||||
}
|
||||
|
||||
.item {
|
||||
.key {
|
||||
font-size: 0.9em;
|
||||
&::after {
|
||||
content: " : ";
|
||||
}
|
||||
}
|
||||
.value {
|
||||
font-weight: 800;
|
||||
}
|
||||
}
|
||||
Executable
+4
@@ -0,0 +1,4 @@
|
||||
[10-Jun-2024 12:44:03 UTC] PHP Fatal error: Uncaught Error: Interface 'Maatwebsite\Excel\Concerns\FromCollection' not found in /home/montechi/public_html/server_app/app/DB/Te/ExcelCollection.php:13
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in /home/montechi/public_html/server_app/app/DB/Te/ExcelCollection.php on line 13
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
|
||||
return [
|
||||
'convert_fields' => [
|
||||
'caj' => 'created_at',
|
||||
'type_str' => 'type',
|
||||
'sts_str' => 'sts',
|
||||
'uaj' => 'updated_at',
|
||||
],
|
||||
'convert_date' => [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at'
|
||||
]
|
||||
|
||||
];
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
<!doctype html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ env('APP_NAME') }}</title>
|
||||
<link rel="stylesheet" href="{{url('assets/fonts/fonts.css')}}">
|
||||
<link rel="stylesheet" href="{{url('assets/css/print.css')}}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<div style="text-align: center;font-size: 1.2em">{{config('app.name')}}</div>
|
||||
<hr>
|
||||
<div class="flex">
|
||||
<div class="item fl-50">
|
||||
<span class="key">عنوان گزارش</span>
|
||||
<span class="value">{{$title}}</span>
|
||||
</div>
|
||||
<div class="item fl-50">
|
||||
<span class="key">تاریخ گزارش</span>
|
||||
<span class="value">{{\Morilog\Jalali\Facades\jDate::forge()->format('Y/m/d-H:m')}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<div class="item fl-50">
|
||||
<span class="key">گزارش گیرنده</span>
|
||||
<span class="value">{{\Illuminate\Support\Facades\Auth::user()->name}}</span>
|
||||
</div>
|
||||
<div class="item fl-50">
|
||||
<span class="key">تعداد رکورد ها</span>
|
||||
<span class="value">{{sizeof($data['rows'])}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="body">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach($data['cols'] as $col)
|
||||
<th>@lang('cols.'.str_replace('.','_',$col))</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($data['rows'] as $row)
|
||||
<tr>
|
||||
@foreach($data['cols'] as $col)
|
||||
@if(!is_array(array_get($row, $col, '')))
|
||||
<td>{{array_get($row, $col, '')}}</td>
|
||||
@else
|
||||
<td>{{join(',' , array_get($row, $col, ''))}}</td>
|
||||
@endif
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
return [
|
||||
'sample_one' => [
|
||||
'model' => \App\MyModel::class,
|
||||
'cols' => "name,code",
|
||||
'select' => ['id as value', 'name as label']
|
||||
],
|
||||
'sample_two' => [
|
||||
'fn' => function ($query) {
|
||||
return \App\DB\MyModel::whereHas('cls', function ($q) {
|
||||
return $q->where('term_id', 2)->where('teacher_id', 1);
|
||||
})
|
||||
->select(['id as value', 'title as label'])
|
||||
->where('title', 'LIKE', '%' . $query . '%')
|
||||
->orWhere('code', 'LIKE', '%' . $query . '%')
|
||||
->get()
|
||||
->toArray();
|
||||
},
|
||||
],
|
||||
'sample_three' => [
|
||||
'model' => \App\DB\MyModel::class,
|
||||
'cols' => "title",
|
||||
'where' => [['sts', '>', '0']],
|
||||
'select' => ['id as value', 'title as label']
|
||||
],
|
||||
'sample_four' => [
|
||||
'model' => \App\DB\MyModel::class,
|
||||
'cols' => "title",
|
||||
'where' => [['w', 'course_level']],
|
||||
'select' => ['id as value', 'title as label']
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
<!doctype html>
|
||||
<html lang="fa" dir="rtl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{ config('app.name') }}</title>
|
||||
<link href="https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font@v29.0.1/dist/font-face.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<style>
|
||||
<?php echo file_get_contents(app_path('DB/Te/assets/font.css'))?>
|
||||
</style>
|
||||
<style>
|
||||
<?php echo file_get_contents(app_path('DB/Te/assets/print.css'))?>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<div style="text-align: center;font-size: 1.2em">{{config('app.name')}}</div>
|
||||
<hr>
|
||||
<div class="flex">
|
||||
<div class="item fl-50">
|
||||
<span class="key">عنوان گزارش</span>
|
||||
<span class="value">{{$meta->title}}</span>
|
||||
</div>
|
||||
<div class="item fl-50">
|
||||
<span class="key">تاریخ گزارش</span>
|
||||
<span class="value">{{$meta->created_at}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<div class="item fl-50">
|
||||
<span class="key">تعداد رکورد ها</span>
|
||||
<span class="value">{{sizeof($records)}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="body">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach($meta->columns as $col)
|
||||
<th>{{$col}}</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($records as $row)
|
||||
<tr>
|
||||
@foreach($meta->columns as $key=>$val)
|
||||
@if(!is_array($Arr::get((array)$row, $key, '')))
|
||||
<td>{{$Arr::get((array)$row, $key, '')}}</td>
|
||||
@else
|
||||
<td>{{join(',' , $Arr::get((array)$row, $key, ''))}}</td>
|
||||
@endif
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
window.print();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user