You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7 KiB

  1. <?php
  2. namespace App;
  3. use App\HiLib\Models\Model;
  4. use Illuminate\Validation\Rule;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. class Sprint extends Model
  7. {
  8. protected $table = 'sprints';
  9. protected $fillable = ['business_id', 'project_id', 'name', 'description', 'started_at', 'ended_at', 'active'];
  10. protected $reportable = [
  11. 'name', 'started_at', 'ended_at', // fields
  12. ];
  13. public function rules()
  14. {
  15. return [
  16. 'name' => 'bail|required|string|min:2|max:225',
  17. 'started_at' => 'bail|required|date|date_format:Y-m-d',
  18. 'ended_at' => 'bail|required|date|date_format:Y-m-d|after:started_at',
  19. 'active' => 'nullable|boolean',
  20. 'description' => 'nullable|string|min:2|max:1000',
  21. ];
  22. }
  23. protected $casts = [
  24. 'active' => 'boolean'
  25. ];
  26. public function getValueOf(?string $key)
  27. {
  28. $values = [
  29. 'business_id' => $this->business_id,
  30. 'project_id' => $this->project_id,
  31. 'sprint_id' => $this->id,
  32. 'workflow_id' => null,
  33. 'status_id' => null,
  34. 'system_id' => null,
  35. 'user_id' => null,
  36. 'task_id' => null,
  37. 'subject_id' => $this->id,
  38. ];
  39. if ($key && isset($values, $key)) {
  40. return $values[$key];
  41. }
  42. return $values;
  43. }
  44. public function business()
  45. {
  46. return $this->belongsTo(Business::class, 'business_id', 'id');
  47. }
  48. public function projects()
  49. {
  50. return $this->belongsTo(Project::class, 'project_id', 'id');
  51. }
  52. public function tasks()
  53. {
  54. return $this->hasMany(Task::class, 'sprint_id', 'id');
  55. }
  56. }