No Description

User.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. use Illuminate\Auth\UserTrait;
  3. use Illuminate\Auth\UserInterface;
  4. use Illuminate\Auth\Reminders\RemindableTrait;
  5. use Illuminate\Auth\Reminders\RemindableInterface;
  6. use Zizaco\Entrust\HasRole;
  7. class User extends Eloquent implements UserInterface, RemindableInterface
  8. {
  9. use UserTrait, RemindableTrait, HasRole;
  10. /**
  11. * The database table used by the model.
  12. *
  13. * @var string
  14. */
  15. protected $table = 'users';
  16. /**
  17. * The attributes excluded from the model's JSON form.
  18. *
  19. * @var array
  20. */
  21. protected $hidden = array();
  22. /**
  23. * The attributes that can be massively assigned
  24. */
  25. protected $fillable = array('ssn', 'first_name', 'surnames', 'email', 'role', 'school_id', 'has_access', 'cell_phone', 'office_phone', 'office_extension');
  26. /**
  27. * Searchable rules.
  28. *
  29. * @var array
  30. */
  31. protected $searchable = [
  32. 'columns' => [
  33. 'first_name' => 10,
  34. 'surnames' => 10,
  35. 'email' => 2,
  36. ],
  37. ];
  38. public function scopeFromSchool($query, $school_id)
  39. {
  40. return $query->join('program_user', 'program_user.user_id', '=', 'users.id')
  41. ->join('programs', 'program_user.program_id', '=', 'programs.id')
  42. ->where('programs.school_id', $school_id)
  43. ->select('users.*');
  44. }
  45. public function scoreFromPrograms($query, $program_ids)
  46. {
  47. return $query->join("program_user", 'users.id', '=', 'program_user.user_id')
  48. ->whereIn('program_user.program_id', $program_ids)
  49. ->select('users.*');
  50. }
  51. public function program()
  52. {
  53. return $this->belongsTo('Program');
  54. }
  55. public function school()
  56. {
  57. return $this->belongsTo('School');
  58. }
  59. public function courses()
  60. {
  61. return $this->hasMany('Course')->whereIn('semester_id', Session::get('semesters_ids'))->orderBy('code')->orderBy('number')->orderBy('section')->orderBy('semester_id');
  62. }
  63. public function rubrics()
  64. {
  65. return $this->hasMany('Rubric')->orderBy('name');
  66. }
  67. // return the programs the user is a pcoord of
  68. public function programs()
  69. {
  70. // return $this->hasManyThrough('Program','Program_user')->select('programs.id', 'programs.name', 'programs.school_id', 'programs.is_graduate');
  71. // $sal= $this->belongsToMany('Program')->select('programs.id', 'programs.name', 'programs.school_id', 'programs.is_graduate');
  72. $sal= $this->belongsToMany('Program')->select('programs.id', 'programs.name', 'programs.school_id', 'programs.is_graduate');
  73. Log::info(json_encode($sal));
  74. return $sal;
  75. }
  76. }