mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Adding some comments
This commit is contained in:
parent
8c96e8fd4b
commit
62195a805a
|
@ -18,12 +18,24 @@ use Illuminate\Support\Str;
|
||||||
|
|
||||||
class AcceptanceController extends Controller {
|
class AcceptanceController extends Controller {
|
||||||
|
|
||||||
public function index(Request $request) {
|
/**
|
||||||
|
* Show a listing of pending checkout acceptances for the current user
|
||||||
|
*
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
|
public function index() {
|
||||||
$acceptances = CheckoutAcceptance::forUser(Auth::user())->pending()->get();
|
$acceptances = CheckoutAcceptance::forUser(Auth::user())->pending()->get();
|
||||||
|
|
||||||
return view('account/accept.index', compact('acceptances'));
|
return view('account/accept.index', compact('acceptances'));
|
||||||
}
|
}
|
||||||
public function create(Request $request, $id) {
|
|
||||||
|
/**
|
||||||
|
* Shows a form to either accept or decline the checkout acceptance
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function create($id) {
|
||||||
|
|
||||||
$acceptance = CheckoutAcceptance::find($id);
|
$acceptance = CheckoutAcceptance::find($id);
|
||||||
|
|
||||||
|
@ -46,6 +58,13 @@ class AcceptanceController extends Controller {
|
||||||
return view('account/accept.create', compact('acceptance'));
|
return view('account/accept.create', compact('acceptance'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the accept/decline of the checkout acceptance
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @param int $id
|
||||||
|
* @return Redirect
|
||||||
|
*/
|
||||||
public function store(Request $request, $id) {
|
public function store(Request $request, $id) {
|
||||||
|
|
||||||
$acceptance = CheckoutAcceptance::find($id);
|
$acceptance = CheckoutAcceptance::find($id);
|
||||||
|
|
|
@ -24,22 +24,48 @@ class CheckoutAcceptance extends Model
|
||||||
'deleted_at'
|
'deleted_at'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resource that was is out
|
||||||
|
*
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\MorphTo
|
||||||
|
*/
|
||||||
public function checkoutable() {
|
public function checkoutable() {
|
||||||
return $this->morphTo();
|
return $this->morphTo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user that the checkoutable was checked out to
|
||||||
|
*
|
||||||
|
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
*/
|
||||||
public function assignedTo() {
|
public function assignedTo() {
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this checkout acceptance pending?
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function isPending() {
|
public function isPending() {
|
||||||
return $this->accepted_at == null && $this->declined_at == null;
|
return $this->accepted_at == null && $this->declined_at == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Was the checkoutable checked out to this user?
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
public function isCheckedOutTo(User $user) {
|
public function isCheckedOutTo(User $user) {
|
||||||
return $this->assignedTo->is($user);
|
return $this->assignedTo->is($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept the checkout acceptance
|
||||||
|
*
|
||||||
|
* @param string $signature_filename
|
||||||
|
*/
|
||||||
public function accept($signature_filename) {
|
public function accept($signature_filename) {
|
||||||
$this->accepted_at = now();
|
$this->accepted_at = now();
|
||||||
$this->signature_filename = $signature_filename;
|
$this->signature_filename = $signature_filename;
|
||||||
|
@ -51,6 +77,11 @@ class CheckoutAcceptance extends Model
|
||||||
$this->checkoutable->acceptedCheckout($this->assignedTo, $signature_filename);
|
$this->checkoutable->acceptedCheckout($this->assignedTo, $signature_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decline the checkout acceptance
|
||||||
|
*
|
||||||
|
* @param string $signature_filename
|
||||||
|
*/
|
||||||
public function decline($signature_filename) {
|
public function decline($signature_filename) {
|
||||||
$this->declined_at = now();
|
$this->declined_at = now();
|
||||||
$this->signature_filename = $signature_filename;
|
$this->signature_filename = $signature_filename;
|
||||||
|
@ -62,10 +93,21 @@ class CheckoutAcceptance extends Model
|
||||||
$this->checkoutable->declinedCheckout($this->assignedTo, $signature_filename);
|
$this->checkoutable->declinedCheckout($this->assignedTo, $signature_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter checkout acceptences by the user
|
||||||
|
* @param Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @param User $user
|
||||||
|
* @return Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
public function scopeForUser(Builder $query, User $user) {
|
public function scopeForUser(Builder $query, User $user) {
|
||||||
return $query->where('assigned_to_id', $user->id);
|
return $query->where('assigned_to_id', $user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter to only get pending acceptances
|
||||||
|
* @param Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
public function scopePending(Builder $query) {
|
public function scopePending(Builder $query) {
|
||||||
return $query->whereNull('accepted_at')->whereNull('declined_at');
|
return $query->whereNull('accepted_at')->whereNull('declined_at');
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,11 @@ use App\Models\CustomField;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This trait allows models to have a callback after their checkout gets accepted or declined.
|
||||||
|
*
|
||||||
|
* @author Till Deeke <kontakt@tilldeeke.de>
|
||||||
|
*/
|
||||||
trait Acceptable {
|
trait Acceptable {
|
||||||
/**
|
/**
|
||||||
* Run after the checkout acceptance was accepted by the user
|
* Run after the checkout acceptance was accepted by the user
|
||||||
|
|
Loading…
Reference in a new issue