Skip to content

Commit

Permalink
added rate list to panel
Browse files Browse the repository at this point in the history
added last rate history
improved security of rates
  • Loading branch information
A1Gard committed Sep 23, 2024
1 parent c49bfe7 commit d518446
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 4 deletions.
28 changes: 28 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Part;
use App\Models\Menu;
use App\Models\Product;
use App\Models\Rate;
use Illuminate\Support\Facades\Route;
use GuzzleHttp\Client;

Expand Down Expand Up @@ -1366,3 +1367,30 @@ function buildTOC($items) {
$html .= '</ul>';
return $html;
}


/**
* detect last rate of customer
* @param $type
* @param $id
* @param $evaluation
* @return int|mixed
*/
function detectRateCustomer($type,$id,$evaluation)
{
if (!auth('customer')->check()){
return 0;
}
$rate = Rate::where('rater_id',auth('customer')->id())
->where('rater_type', \App\Models\Customer::class)
->where('rateable_type',$type)
->where('rateable_id',$id)
->where('evaluation_id',$evaluation);

if ($rate->count() == 0){
return 0;
}else{
return $rate->first()->rate;
}

}
108 changes: 108 additions & 0 deletions app/Http/Controllers/Admin/RateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Controllers\XController;
use App\Http\Requests\RateSaveRequest;
use App\Models\Access;
use App\Models\Rate;
use Illuminate\Http\Request;
use App\Helper;
use function App\Helpers\hasCreateRoute;

class RateController extends XController
{

// protected $_MODEL_ = Rate::class;
// protected $SAVE_REQUEST = RateSaveRequest::class;

protected $cols = ['rateable_type', 'rateable_id', 'rater_type', 'rater_id', 'rate','evaluation_id'];
protected $extra_cols = ['id'];

protected $searchable = ['rate','rateable_type','rateable_id', 'rater_type', 'rater_id'];

protected $listView = 'admin.rates.rate-list';
protected $formView = 'admin.rates.rate-form';


protected $buttons = [
// 'edit' =>
// ['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'],
// 'show' =>
// ['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'],
// 'destroy' =>
// ['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'],
];


public function __construct()
{
parent::__construct(Rate::class, RateSaveRequest::class);
}

/**
* @param $rate Rate
* @param $request RateSaveRequest
* @return Rate
*/
public function save($rate, $request)
{

$rate->save();
return $rate;

}


/**
* Show the form for creating a new resource.
*/
public function create()
{
//
return view($this->formView);
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Rate $item)
{
//
return view($this->formView, compact('item'));
}

public function bulk(Request $request)
{

// dd($request->all());
$data = explode('.', $request->input('action'));
$action = $data[0];
$ids = $request->input('id');
switch ($action) {
case 'delete':
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]);
$this->_MODEL_::destroy($ids);
break;

default:
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]);
}

return $this->do_bulk($msg, $action, $ids);
}

public function destroy(Rate $item)
{
return parent::delete($item);
}


public function update(Request $request, Rate $item)
{
return $this->bringUp($request, $item);
}


}
2 changes: 1 addition & 1 deletion app/Http/Controllers/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public function rate(Request $request)
} else {
$rate = new Rate();
}
if ($rt != 0) {
if ($rt > 0 && $rt < 5) {
$rate->rater_type = Customer::class;
$rate->rater_id = auth('customer')->id();
$rate->rateable_type = $request->rateable_type;
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Requests/RateSaveRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RateSaveRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return false;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}
4 changes: 4 additions & 0 deletions app/Models/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
class Rate extends Model
{
use HasFactory;

public function evaluation(){
return $this->belongsTo(Evaluation::class);
}
}
3 changes: 3 additions & 0 deletions resources/lang/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@
"Questions": "سوالات",
"Questions list": "فهرست سوالات",
"RTL": "راست به چپ",
"Rate": "امتیاز",
"Read more": "اطلاعات بیشتر",
"Recent posts": "واپسین نوشته‌ها",
"Recommends": "توصیه‌ها",
Expand Down Expand Up @@ -514,6 +515,8 @@
"Your message for this order...": "پیام شما ویژه این سفارش ...",
"Your message has been successfully sent.": "پیام شما با موفقیت ارسال شد",
"Your message...": "پیام شما...",
"Your rate registered": "امتیاز شما ثبت شد",
"Your rate updated": "امتیاز شما به‌روز شد",
"a minute ago": "یک دقیقه پیش",
"action": "فعالیت",
"address updated": "نشانی به روز شد",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class="form-control @error('title') is-invalid @enderror"
<label for="mid">
{{__("Model ID")}}
</label>
<input name="evaluationable_id" type="text"
<input name="evaluationable_id" type="text"
id="mid"
class="form-control @error('evaluationable_id') is-invalid @enderror"
placeholder="{{__('Model ID')}}" value="{{old('evaluationable_id',$item->evaluationable_id??null)}}"/>
Expand Down
42 changes: 42 additions & 0 deletions resources/views/admin/rates/rate-form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@extends('admin.templates.panel-form-template')
@section('title')
@if(isset($item))
{{__("Edit rate")}} [{{$item->id}}]
@else
{{__("Add new rate")}}
@endif -
@endsection
@section('form')

<div class="row">
<div class="col-lg-3">

@include('components.err')
<div class="item-list mb-3">
<h3 class="p-3">
<i class="ri-message-3-line"></i>
{{__("Tips")}}
</h3>
<ul>
<li>
{{__("Recommends")}}
</li>
</ul>
</div>

</div>
<div class="col-lg-9 ps-xl-1 ps-xxl-1">
<div class="general-form ">

<h1>
@if(isset($item))
{{__("Edit rate")}} [{{$item->id}}]
@else
{{__("Add new rate")}}
@endif
</h1>

</div>
</div>
</div>
@endsection
15 changes: 15 additions & 0 deletions resources/views/admin/rates/rate-list.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@extends('admin.templates.panel-list-template')

@section('list-title')
<i class="ri-user-3-line"></i>
{{__("Rates list")}}
@endsection
@section('title')
{{__("Rates list")}} -
@endsection
@section('filter')
{{-- Other filters --}}
@endsection
@section('bulk')
{{-- <option value="-"> - </option> --}}
@endsection
11 changes: 11 additions & 0 deletions resources/views/admin/templates/panel-list-template.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ class="form-check form-switch mt-1 mx-2">
{{__("Removed")}}
@endif
@break
@case('evaluation_id')
@if($item->evaluation != null)
<a href="{{route('admin.evaluation.edit',$item->evaluation_id)}}">
{{ $item->evaluation?->title??'-' }}
</a>
@else
{{__("Removed")}}
@endif
@break
@case('expire')
@case('created_at')
@case('updated_at')
Expand All @@ -244,6 +253,8 @@ class="form-check form-switch mt-1 mx-2">
@endif
@elseif(gettype($item->$col) == 'integer')
{{number_format($item->$col)}}
@elseif(strpos($col,'_type'))
{{str_replace('App\\Models\\', '' , $item->$col)}}
@else
{{$item->$col}}
@endif
Expand Down
10 changes: 9 additions & 1 deletion resources/views/components/panel-side-navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<i class="ri-home-smile-fill"></i>
</a>
</li>
@if( auth()->user()->hasAnyAccesses(['customer','invoice','discount']) )
@if( auth()->user()->hasAnyAccesses(['customer','invoice','discount','rate']) )
<li data-bs-toggle="tooltip" data-bs-placement="auto" data-bs-custom-class="custom-tooltip"
data-bs-title="{{__("Shopping card")}}">
<a href="#card">
Expand Down Expand Up @@ -38,6 +38,14 @@
</a>
</li>
@endif
@if( auth()->user()->hasAnyAccess( 'rate' ))
<li>
<a href="{{ route('admin.rate.index') }}">
<i class="ri-star-half-line"></i>
{{__('Rate')}}
</a>
</li>
@endif
</ul>
</li>
@endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class="btn btn-outline-primary add-to-card btn-lg">
<input type="hidden" name="rateable_id" value="{{$product->id}}">
<input type="hidden" name="rateable_type" value="{{\App\Models\Product::class}}">
@foreach($product->evaluations() as $e)
<rate-input xtitle="{{$e->title}}" xname="rate[{{ $e->id }}]"></rate-input>
<rate-input xtitle="{{$e->title}}" xname="rate[{{ $e->id }}]" :xvalue="{{detectRateCustomer(\App\Models\Product::class,$product->id,$e->id)}}"></rate-input>
<hr>
@endforeach
<button class="btn btn-primary w-100">
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function () {

Route::post('ckeditor/upload', [\App\Http\Controllers\Admin\CkeditorController::class, 'upload'])->name('ckeditor.upload');
Route::get('adminlogs', [\App\Http\Controllers\Admin\AdminLogController::class, 'index'])->name('adminlog.index');
Route::get('rates', [\App\Http\Controllers\Admin\RateController::class, 'index'])->name('rate.index');
Route::get('adminlogs/{user}', [\App\Http\Controllers\Admin\AdminLogController::class, 'log'])->name('adminlog.show');
Route::post('images/store/{gallery}', [\App\Http\Controllers\Admin\ImageController::class, 'store'])->name('image.store');
Route::get('images/destroy/{image}', [\App\Http\Controllers\Admin\ImageController::class, 'destroy'])->name('image.destroy');
Expand Down

0 comments on commit d518446

Please sign in to comment.