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.

70 lines
1.6 KiB

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