From d24a164d2249a23844cd32a1e9412bcd7d8aac9e Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Tue, 12 Jun 2018 21:57:16 +0800 Subject: [PATCH] Add job model method docblocks --- app/Entities/Projects/Job.php | 50 ++++++++++++++++++++++-- resources/views/jobs/partials/job-show.blade.php | 2 +- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/Entities/Projects/Job.php b/app/Entities/Projects/Job.php index 51941df..9630f4f 100755 --- a/app/Entities/Projects/Job.php +++ b/app/Entities/Projects/Job.php @@ -15,44 +15,86 @@ class Job extends Model { use PresentableTrait; + /** + * @var \App\Entities\Projects\JobPresenter + */ protected $presenter = JobPresenter::class; + + /** + * @var array + */ protected $guarded = ['id', 'created_at', 'updated_at']; + /** + * Show job name with link to job detail. + * + * @return Illuminate\Support\HtmlString + */ public function nameLink() { return link_to_route('jobs.show', $this->name, [$this->id], [ - 'title' => trans( + 'title' => __( 'app.show_detail_title', - ['name' => $this->name, 'type' => trans('job.job')] + ['name' => $this->name, 'type' => __('job.job')] ), ]); } + /** + * Job belongs to a Project relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function project() { return $this->belongsTo(Project::class, 'project_id'); } + /** + * Job belongs to a Worker relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ public function worker() { return $this->belongsTo(User::class, 'worker_id'); } + /** + * Job has many Tasks relation ordered by position. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function tasks() { - return $this->hasMany(Task::class)->orderBy('progress')->orderBy('position'); + return $this->hasMany(Task::class)->orderBy('position'); } + /** + * Get the job type. + * + * @return string + */ public function type() { - return $this->type_id == 1 ? trans('job.main') : trans('job.additional'); + return $this->type_id == 1 ? __('job.main') : __('job.additional'); } + /** + * Add progress attribute on Job model. + * + * @return int + */ public function getProgressAttribute() { return $this->tasks->isEmpty() ? 0 : $this->tasks->avg('progress'); } + /** + * Add receiveable_earning attribute on Job model. + * + * @return float + */ public function getReceiveableEarningAttribute() { return $this->price * ($this->progress / 100); diff --git a/resources/views/jobs/partials/job-show.blade.php b/resources/views/jobs/partials/job-show.blade.php index cd52b6b..857b1ab 100644 --- a/resources/views/jobs/partials/job-show.blade.php +++ b/resources/views/jobs/partials/job-show.blade.php @@ -7,7 +7,7 @@ @can('see-pricings', $job) {{ __('job.price') }}{{ formatRp($job->price) }} @endcan - {{ __('job.progress') }}{{ formatDecimal($job->tasks->avg('progress')) }}% + {{ __('job.progress') }}{{ formatDecimal($job->progress) }}% {{ __('job.worker') }}{{ $job->worker->name }} {{ __('job.description') }}{!! nl2br($job->description) !!}