added product and post query setting

master
A1Gard 3 days ago
parent 01c1438eee
commit cf081b24fa

@ -872,12 +872,12 @@ function getGroupPostsBySetting($key, $limit = 10, $order = 'id', $dir = "DESC")
} }
/** /**
* get group's posts by setting key * get category's products by setting key
* @param $key * @param $key
* @param integer $limit * @param integer $limit
* @param string $order * @param string $order
* @param string $dir * @param string $dir
* @return \App\Models\Post[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C * @return \App\Models\Category[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C
*/ */
function getCategoryProductBySetting($key, $limit = 10, $order = 'id', $dir = "DESC") function getCategoryProductBySetting($key, $limit = 10, $order = 'id', $dir = "DESC")
{ {
@ -885,6 +885,24 @@ function getCategoryProductBySetting($key, $limit = 10, $order = 'id', $dir = "D
->products()->where('status', 1)->orderBy($order, $dir)->limit($limit)->get(); ->products()->where('status', 1)->orderBy($order, $dir)->limit($limit)->get();
} }
/**
* get products by setting key
* @param $key
* @param integer $limit
* @return \App\Models\Product[]|\Illuminate\Database\Eloquent\Collection|\LaravelIdea\Helper\App\Models\_IH_Post_C
*/
function getProductsQueryBySetting($key, $limit = 10)
{
$data = explode(',', getSetting($key) ?? '1,id,DESC');
if ($data[0] == 0) {
$q = Product::where('status', 1);
}else{
$q = Category::where('id', $data[0])->first()
->products()->where('status', 1);
}
return $q->orderBy($data[1], $data[2])->limit($limit)->get();
}
/** /**
* get group's posts by setting key * get group's posts by setting key
* @param $key * @param $key

@ -22,11 +22,13 @@ class SettingController extends Controller
// //
$settings = Setting::where('active', true) $settings = Setting::where('active', true)
->orderBy('section')->get(); //ESH// just active setting`s show ->orderBy('section')->get(); //ESH// just active setting`s show
$cats = Category::all(['id','name']); $cats = Category::all(['id', 'name'])->toArray();
$menus = Menu::all(['id', 'name']); $menus = Menu::all(['id', 'name']);
$groups = Group::all(['id','name']); $groups = Group::all(['id', 'name'])->toArray();
$catz = array_merge([['id' => 0, 'name' => __('All')]], $cats);
$groupz = array_merge([['id' => 0, 'name' => __('All')]], $groups);
return view('admin.commons.setting', return view('admin.commons.setting',
compact('settings', 'cats','groups','menus')); compact('settings', 'cats', 'groups', 'menus', 'catz', 'groupz'));
} }
/** /**
@ -78,7 +80,14 @@ class SettingController extends Controller
$all = $request->all(); $all = $request->all();
foreach ($all as $key => $val) { foreach ($all as $key => $val) {
$set = Setting::where('key', $key)->first(); $set = Setting::where('key', $key)->first();
if ($set != null && !$request->hasFile($key)) { if ($set == null) {
continue;
}
if ($set->type == 'PRODUCT_QUERY' || $set->type == 'POST_QUERY') {
$set->value = implode(',', $val);
$set->raw = implode(',', $val);
$set->save();
} elseif ($set != null && !$request->hasFile($key)) {
$set->value = validateSettingRequest($set, $val); $set->value = validateSettingRequest($set, $val);
$set->raw = validateSettingRequest($set, $val); $set->raw = validateSettingRequest($set, $val);
@ -129,7 +138,8 @@ class SettingController extends Controller
// //
} }
public function cacheClear(){ public function cacheClear()
{
$f = Setting::where('key', 'cache_number')->first(); $f = Setting::where('key', 'cache_number')->first();
$f->value += 1; $f->value += 1;
$f->save(); $f->save();
@ -140,13 +150,16 @@ class SettingController extends Controller
return redirect()->back()->with(['message' => __('Cache cleared')]); return redirect()->back()->with(['message' => __('Cache cleared')]);
} }
public function liveEdit($slug){ public function liveEdit($slug)
{
$settings = Setting::where('active', true)->where('key', 'LIKE', $slug . '%') $settings = Setting::where('active', true)->where('key', 'LIKE', $slug . '%')
->orderBy('section')->get(); ->orderBy('section')->get();
$cats = Category::all(['id','name']); $cats = Category::all(['id', 'name'])->toArray();
$catz = array_merge([['id' => 0, 'name' => __('All')]], $cats);
$menus = Menu::all(['id', 'name']); $menus = Menu::all(['id', 'name']);
$groups = Group::all(['id','name']); $groups = Group::all(['id', 'name'])->toArray();
$groupz = array_merge([['id' => 0, 'name' => __('All')]], $groups);
return view('admin.commons.live', return view('admin.commons.live',
compact('settings', 'cats','groups','menus')); compact('settings', 'cats', 'groups', 'menus', 'catz', 'groupz'));
} }
} }

@ -14,7 +14,7 @@ class Setting extends Model
public static $settingTypes = ['TEXT', 'NUMBER', 'LONGTEXT', 'CODE', 'EDITOR', public static $settingTypes = ['TEXT', 'NUMBER', 'LONGTEXT', 'CODE', 'EDITOR',
'CATEGORY', 'GROUP', 'CHECKBOX', 'FILE', 'COLOR', 'SELECT', 'MENU', 'LOCATION', 'CATEGORY', 'GROUP', 'CHECKBOX', 'FILE', 'COLOR', 'SELECT', 'MENU', 'LOCATION',
'ICON','DATE','DATETIME','TIME']; 'ICON','DATE','DATETIME','TIME','PRODUCT_QUERY','POST_QUERY'];
public function getData() public function getData()
{ {

@ -87,6 +87,7 @@
"As you wished restored successfully": "همانطور که شما مایل بودید بازیافت شد", "As you wished restored successfully": "همانطور که شما مایل بودید بازیافت شد",
"As you wished sort saved": "همانطور که شما مایل بودید مرتب شدند", "As you wished sort saved": "همانطور که شما مایل بودید مرتب شدند",
"As you wished updated successfully": "همانطور که شما مایل بودید به روز شد", "As you wished updated successfully": "همانطور که شما مایل بودید به روز شد",
"Ascending": "صعودی",
"Assets build failed": "دارایی‌ها ساخته نشده‌اند", "Assets build failed": "دارایی‌ها ساخته نشده‌اند",
"Assets build successfully": "دارایی‌ها با موفقیت ساخته شدن", "Assets build successfully": "دارایی‌ها با موفقیت ساخته شدن",
"Attaching": "پیوست کردن", "Attaching": "پیوست کردن",
@ -173,6 +174,7 @@
"Default admin email is :E1 (developer) or :E2 (admin) and default password is: :P": "در نگارش آزمایشی رایانامه توسعه دهنده :E1 است و رایانامه مدیر عادی :E2 و گذرواژه هر دو :P است", "Default admin email is :E1 (developer) or :E2 (admin) and default password is: :P": "در نگارش آزمایشی رایانامه توسعه دهنده :E1 است و رایانامه مدیر عادی :E2 و گذرواژه هر دو :P است",
"DefaultFooter": "فوتر پیش‌فرض", "DefaultFooter": "فوتر پیش‌فرض",
"DefaultHeader": "هدر پیش‌فرض", "DefaultHeader": "هدر پیش‌فرض",
"Descending": "نزولی",
"Description": "توضیحات", "Description": "توضیحات",
"Description Table": "جدول توضیحات", "Description Table": "جدول توضیحات",
"Description Text": "نوشته توضیحات", "Description Text": "نوشته توضیحات",
@ -369,6 +371,7 @@
"Please, Login or complete information to pay": "لطفا وارد شوید یا اطلاعات خود را تکمیل کنید تا اجازه پرداخت داشته باشید", "Please, Login or complete information to pay": "لطفا وارد شوید یا اطلاعات خود را تکمیل کنید تا اجازه پرداخت داشته باشید",
"Poor": "ضعیف", "Poor": "ضعیف",
"Post": "نوشته", "Post": "نوشته",
"Post RSS Feed": " RSS Feed نوشته",
"Post Text": "متن نوشته", "Post Text": "متن نوشته",
"Post code": "کد پستی", "Post code": "کد پستی",
"Post reply": "پاسخ نوشته", "Post reply": "پاسخ نوشته",
@ -381,6 +384,7 @@
"Price": "مبلغ", "Price": "مبلغ",
"Print": "چاپ", "Print": "چاپ",
"Product": "محصول", "Product": "محصول",
"Product RSS Feed": " RSS Feed محصولات",
"Product added to compare": "محصول به فهرست مقایسه افزوده شد", "Product added to compare": "محصول به فهرست مقایسه افزوده شد",
"Product added to favorites": "محصول به علاقه‌مندی شما افزوده شد", "Product added to favorites": "محصول به علاقه‌مندی شما افزوده شد",
"Product grid": "کاشی محصول", "Product grid": "کاشی محصول",
@ -443,6 +447,7 @@
"Searchable": "قابل جستجو", "Searchable": "قابل جستجو",
"Section": "بخش", "Section": "بخش",
"Sections": "بخش‌ها", "Sections": "بخش‌ها",
"Sell": "فروش",
"Send": "ارسال", "Send": "ارسال",
"Send Answer": "ارسال پاسخ", "Send Answer": "ارسال پاسخ",
"Send Answer and close": "ارسال پاسخ و بستن", "Send Answer and close": "ارسال پاسخ و بستن",
@ -481,7 +486,7 @@
"States": "استان‌ها", "States": "استان‌ها",
"States list": "فهرست استان‌ها", "States list": "فهرست استان‌ها",
"Status": "وضعیت", "Status": "وضعیت",
"Stock quantity": "موجود انبار", "Stock quantity": "موجودی انبار",
"Sub categories": "زیر دسته", "Sub categories": "زیر دسته",
"Sub groups": "زیر سرفصل", "Sub groups": "زیر سرفصل",
"Subject": "عنوان", "Subject": "عنوان",
@ -534,6 +539,7 @@
"Unavailable": "ناموجود", "Unavailable": "ناموجود",
"Unit": "واحد", "Unit": "واحد",
"Unknown bulk action : :ACTION": "کار دسته جمعی تعریف نشده :ACTION", "Unknown bulk action : :ACTION": "کار دسته جمعی تعریف نشده :ACTION",
"Update": "به روز شدن",
"Upload file": "به روز کردن پرونده", "Upload file": "به روز کردن پرونده",
"Upload images": "بارگزاری تصاویر", "Upload images": "بارگزاری تصاویر",
"Upload new images": "بارگزاری تصاویر جدید", "Upload new images": "بارگزاری تصاویر جدید",

@ -31,23 +31,29 @@
@break @break
@case('DATE') @case('DATE')
<vue-datetime-picker-input <vue-datetime-picker-input
xid="{{$setting->key}}" xname="{{$setting->key}}" @if(app()->getLocale() == 'fa') xshow="pdate" @else xshow="date" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1" @endif xid="{{$setting->key}}" xname="{{$setting->key}}" @if(app()->getLocale() == 'fa') xshow="pdate"
@else xshow="date" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1"
@endif
:xvalue="{{$setting->value}}" :xvalue="{{$setting->value}}"
></vue-datetime-picker-input> ></vue-datetime-picker-input>
@break @break
@case('DATETIME') @case('DATETIME')
<vue-datetime-picker-input <vue-datetime-picker-input
xid="{{$setting->key}}" xname="{{$setting->key}}" @if(app()->getLocale() == 'fa') xshow="pdatetime" @else xshow="datetime" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1" @endif xid="{{$setting->key}}" xname="{{$setting->key}}" @if(app()->getLocale() == 'fa') xshow="pdatetime"
@else xshow="datetime" @endif xtitle="{{$setting->title}}" @if(app()->getLocale() != 'fa') def-tab="1"
@endif
:xvalue="{{$setting->value}}" :xvalue="{{$setting->value}}"
:timepicker="true" :timepicker="true"
></vue-datetime-picker-input> ></vue-datetime-picker-input>
@break @break
@case('ICON') @case('ICON')
<remix-icon-picker xname="{{$setting->key}}" xvalue="{{old($setting->key, $setting->value)}}"></remix-icon-picker> <remix-icon-picker xname="{{$setting->key}}"
xvalue="{{old($setting->key, $setting->value)}}"></remix-icon-picker>
@break @break
@case('LOCATION') @case('LOCATION')
@php($latlng = explode(',',old($setting->key, $setting->value))) @php($latlng = explode(',',old($setting->key, $setting->value)))
<lat-lng xname="{{$setting->key}}" :ilat="{{$latlng[0]}}" :ilng="{{$latlng[1]}}" :izoom="{{$latlng[2]}}" :dark-mode="true"></lat-lng> <lat-lng xname="{{$setting->key}}" :ilat="{{$latlng[0]}}" :ilng="{{$latlng[1]}}" :izoom="{{$latlng[2]}}"
:dark-mode="true"></lat-lng>
@break @break
@case('EDITOR') @case('EDITOR')
<textarea name="{{$setting->key}}" id="{{$setting->key}}" <textarea name="{{$setting->key}}" id="{{$setting->key}}"
@ -65,7 +71,7 @@
@break @break
@case('CATEGORY') @case('CATEGORY')
<searchable-select <searchable-select
@error('category_id') :err="true" @enderror @error($setting->key) :err="true" @enderror
:items='@json($cats)' :items='@json($cats)'
title-field="name" title-field="name"
value-field="id" value-field="id"
@ -78,7 +84,7 @@
@break @break
@case('GROUP') @case('GROUP')
<searchable-select <searchable-select
@error('category_id') :err="true" @enderror @error($setting->key) :err="true" @enderror
:items='@json($groups)' :items='@json($groups)'
title-field="name" title-field="name"
value-field="id" value-field="id"
@ -89,9 +95,101 @@
xvalue='{{old($setting->key,$setting->value??null)}}' xvalue='{{old($setting->key,$setting->value??null)}}'
:close-on-Select="true"></searchable-select> :close-on-Select="true"></searchable-select>
@break @break
@case('MENU') @case('PRODUCT_QUERY')
<div class="row">
@php($vals = explode(',',old($setting->key,$setting->value??null)))
<div class="col-md">
<span>
{{__("Category")}}
</span>
<searchable-select
@error($setting->key) :err="true" @enderror
:items='@json($catz)'
title-field="name"
value-field="id"
xlang="{{config('app.locale')}}"
xid="{{$setting->key}}"
xname="{{$setting->key}}[category]"
@error('category_id') :err="true" @enderror
xvalue='{{$vals[0]}}'
:close-on-Select="true"></searchable-select>
</div>
<div class="col-md">
<label id="{{$setting->key}}i">
{{__("Item")}}
</label>
<select name="{{$setting->key}}[item]" id="{{$setting->key}}i" class="form-control">
<option value="id"> {{__("ID")}} </option>
<option value="view" @if($vals[1] == 'view') selected @endif> {{__("View")}} </option>
<option value="sell" @if($vals[1] == 'sell') selected @endif> {{__("Sell")}} </option>
<option value="average_rating" @if($vals[1] == 'average_rating') selected @endif> {{__("Rate")}} </option>
<option value="price" @if($vals[1] == 'price') selected @endif> {{__("Price")}} </option>
<option value="stock_quantity" @if($vals[1] == 'stock_quantity') selected @endif> {{__("Stock quantity")}} </option>
<option value="updated_at" @if($vals[1] == 'updated_at') selected @endif> {{__("Update")}} </option>
</select>
</div>
<div class="col-md">
<label id="{{$setting->key}}s">
{{__("Sort")}}
</label>
<select name="{{$setting->key}}[sort]" id="{{$setting->key}}s" class="form-control">
<option value="DESC"> {{__("Descending")}} </option>
<option value="ASC" @if($vals[2] == 'ASC') selected @endif> {{__("Ascending")}} </option>
</select>
</div>
</div>
@break
@case('POST_QUERY')
<div class="row">
@php($vals = explode(',',old($setting->key,$setting->value??null)))
<div class="col-md">
<span>
{{__("Group")}}
</span>
<searchable-select <searchable-select
@error($setting->key) :err="true" @enderror
:items='@json($groups)'
title-field="name"
value-field="id"
xlang="{{config('app.locale')}}"
xid="{{$setting->key}}"
xname="{{$setting->key}}[group]"
@error('category_id') :err="true" @enderror @error('category_id') :err="true" @enderror
xvalue='{{$vals[0]}}'
:close-on-Select="true"></searchable-select>
</div>
<div class="col-md">
<label id="{{$setting->key}}i">
{{__("Item")}}
</label>
<select name="{{$setting->key}}[item]" id="{{$setting->key}}i" class="form-control">
<option value="id"> {{__("ID")}} </option>
<option value="view" @if($vals[1] == 'view') selected @endif> {{__("View")}} </option>
<option value="sell" @if($vals[1] == 'sell') selected @endif> {{__("Sell")}} </option>
<option value="average_rating" @if($vals[1] == 'average_rating') selected @endif> {{__("Rate")}} </option>
<option value="price" @if($vals[1] == 'price') selected @endif> {{__("Price")}} </option>
<option value="stock_quantity" @if($vals[1] == 'stock_quantity') selected @endif> {{__("Stock quantity")}} </option>
<option value="updated_at" @if($vals[1] == 'updated_at') selected @endif> {{__("Update")}} </option>
</select>
</div>
<div class="col-md">
<label id="{{$setting->key}}s">
{{__("Sort")}}
</label>
<select name="{{$setting->key}}[sort]" id="{{$setting->key}}s" class="form-control">
<option value="DESC"> {{__("Descending")}} </option>
<option value="ASC" @if($vals[2] == 'ASC') selected @endif> {{__("Ascending")}} </option>
</select>
</div>
</div>
@break
@case('MENU')
<searchable-select
@error($setting->key) :err="true" @enderror
:items='@json($menus)' :items='@json($menus)'
title-field="name" title-field="name"
value-field="id" value-field="id"
@ -112,27 +210,34 @@
{{-- <input type="number" id="{{$setting->key}}"--}} {{-- <input type="number" id="{{$setting->key}}"--}}
{{-- name="" class="form-control"--}} {{-- name="" class="form-control"--}}
{{-- value="" @if($setting->ltr) dir="ltr" @endif>--}} {{-- value="" @if($setting->ltr) dir="ltr" @endif>--}}
<increment xname="{{$setting->key}}" xvalue="{{old($setting->key, $setting->value)}}" @foreach($setting->getData() as $k => $v) {{$k}}="{{$v}}" @endforeach ></increment> <increment xname="{{$setting->key}}"
xvalue="{{old($setting->key, $setting->value)}}" @foreach($setting->getData() as $k => $v)
{{$k}}="{{$v}}"
@endforeach ></increment>
@break @break
@case('FILE') @case('FILE')
<div class="row"> <div class="row">
@php($ext = strtolower(pathinfo(str_replace('_','.',$setting->key), PATHINFO_EXTENSION))) @php($ext = strtolower(pathinfo(str_replace('_','.',$setting->key), PATHINFO_EXTENSION)))
<div class="col-md-5 "> <div class="col-md-5 ">
<input type="file" accept=".{{pathinfo(str_replace('_','.',$setting->key), PATHINFO_EXTENSION)}}" class="form-control" name="file[{{$setting->key}}]" id="{{$setting->key}}"> <input type="file" accept=".{{pathinfo(str_replace('_','.',$setting->key), PATHINFO_EXTENSION)}}"
class="form-control" name="file[{{$setting->key}}]" id="{{$setting->key}}">
</div> </div>
@if(!in_array($ext, ['svg','jpg','png','gif','webp'] ) ) @if(!in_array($ext, ['svg','jpg','png','gif','webp'] ) )
<div class="col-md-2"> <div class="col-md-2">
<a class="btn btn-primary w-100" href="{{asset('upload/file/'.str_replace('_','.',$setting->key))}}?{{time()}}"> <a class="btn btn-primary w-100"
href="{{asset('upload/file/'.str_replace('_','.',$setting->key))}}?{{time()}}">
<i class="ri-download-2-line"></i> <i class="ri-download-2-line"></i>
</a> </a>
</div> </div>
@endif @endif
<div class="col-md-5 text-center"> <div class="col-md-5 text-center">
@if($ext == 'mp4') @if($ext == 'mp4')
<video controls src="{{asset('upload/media/'.str_replace('_','.',$setting->key))}}?{{time()}}" style="max-height: 150px;max-width: 45%" ></video> <video controls src="{{asset('upload/media/'.str_replace('_','.',$setting->key))}}?{{time()}}"
style="max-height: 150px;max-width: 45%"></video>
<br> <br>
@elseif($ext == 'mp3') @elseif($ext == 'mp3')
<audio controls src="{{asset('upload/media/'.str_replace('_','.',$setting->key))}}?{{time()}}" class="img-fluid" style="max-height: 150px;max-width: 45%" ></audio> <audio controls src="{{asset('upload/media/'.str_replace('_','.',$setting->key))}}?{{time()}}"
class="img-fluid" style="max-height: 150px;max-width: 45%"></audio>
<br> <br>
@elseif(in_array($ext, ['svg','jpg','png','gif','webp'] ) ) @elseif(in_array($ext, ['svg','jpg','png','gif','webp'] ) )
<img src="{{asset('upload/images/'.str_replace('_','.',$setting->key))}}?{{time()}}" <img src="{{asset('upload/images/'.str_replace('_','.',$setting->key))}}?{{time()}}"

Loading…
Cancel
Save