Ei kuvausta

Rubric.php 929B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. class Rubric extends Eloquent
  3. {
  4. /**
  5. * Searchable rules.
  6. *
  7. * @var array
  8. */
  9. protected $searchable = [
  10. 'columns' => [
  11. 'name' => 10,
  12. ],
  13. ];
  14. public function getTitles()
  15. {
  16. $titles = DB::table('titles')
  17. ->join('rubric_title', 'rubric_title.title_id', '=', 'titles.id')
  18. ->where('rubric_id', $this->id)
  19. ->orderBy('position', "ASC")
  20. ->get();
  21. return $titles;
  22. }
  23. public function professor()
  24. {
  25. return $this->belongsTo('User')->orderBy('created_at');
  26. }
  27. public function activities()
  28. {
  29. return $this->belongsToMany('Activity', 'rubric_activity');
  30. }
  31. public function getCriterion($id, $criterion_id)
  32. {
  33. $rubric = Rubric::findOrFail($id);
  34. $rubric_contents = json_decode($rubric->contents);
  35. foreach ($rubric_contents as $key => $criterion) {
  36. if ($criterion->id == $criterion_id) {
  37. return $criterion;
  38. }
  39. }
  40. }
  41. }