Browse Source

Add job model method docblocks

pull/12/head
Nafies Luthfi 8 years ago
parent
commit
d24a164d22
  1. 50
      app/Entities/Projects/Job.php
  2. 2
      resources/views/jobs/partials/job-show.blade.php

50
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);

2
resources/views/jobs/partials/job-show.blade.php

@ -7,7 +7,7 @@
@can('see-pricings', $job)
<tr><th>{{ __('job.price') }}</th><td>{{ formatRp($job->price) }}</td></tr>
@endcan
<tr><th>{{ __('job.progress') }}</th><td>{{ formatDecimal($job->tasks->avg('progress')) }}%</td></tr>
<tr><th>{{ __('job.progress') }}</th><td>{{ formatDecimal($job->progress) }}%</td></tr>
<tr><th>{{ __('job.worker') }}</th><td>{{ $job->worker->name }}</td></tr>
<tr><th>{{ __('job.description') }}</th><td>{!! nl2br($job->description) !!}</td></tr>
</tbody>

Loading…
Cancel
Save