diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 3e37871aa4..198e11e998 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -18,12 +18,24 @@ use Illuminate\Support\Str; 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(); 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); @@ -46,6 +58,13 @@ class AcceptanceController extends Controller { 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) { $acceptance = CheckoutAcceptance::find($id); diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php index 28442a0aeb..6ff850f41f 100644 --- a/app/Models/CheckoutAcceptance.php +++ b/app/Models/CheckoutAcceptance.php @@ -24,22 +24,48 @@ class CheckoutAcceptance extends Model 'deleted_at' ]; + /** + * The resource that was is out + * + * @return Illuminate\Database\Eloquent\Relations\MorphTo + */ public function checkoutable() { return $this->morphTo(); } + /** + * The user that the checkoutable was checked out to + * + * @return Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function assignedTo() { return $this->belongsTo(User::class); } + /** + * Is this checkout acceptance pending? + * + * @return boolean + */ public function isPending() { 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) { return $this->assignedTo->is($user); } + /** + * Accept the checkout acceptance + * + * @param string $signature_filename + */ public function accept($signature_filename) { $this->accepted_at = now(); $this->signature_filename = $signature_filename; @@ -51,6 +77,11 @@ class CheckoutAcceptance extends Model $this->checkoutable->acceptedCheckout($this->assignedTo, $signature_filename); } + /** + * Decline the checkout acceptance + * + * @param string $signature_filename + */ public function decline($signature_filename) { $this->declined_at = now(); $this->signature_filename = $signature_filename; @@ -62,10 +93,21 @@ class CheckoutAcceptance extends Model $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) { 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) { return $query->whereNull('accepted_at')->whereNull('declined_at'); } diff --git a/app/Models/Traits/Acceptable.php b/app/Models/Traits/Acceptable.php index 0837b9a9ae..a0c93a861b 100644 --- a/app/Models/Traits/Acceptable.php +++ b/app/Models/Traits/Acceptable.php @@ -7,7 +7,11 @@ use App\Models\CustomField; use App\Models\User; use Illuminate\Database\Eloquent\Builder; - +/** + * This trait allows models to have a callback after their checkout gets accepted or declined. + * + * @author Till Deeke + */ trait Acceptable { /** * Run after the checkout acceptance was accepted by the user