current_user.class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. use \ChamiloSession as Session;
  3. /**
  4. * Wrapper for the current user - i.e. the logged in user. Provide access
  5. * to the current user's data.
  6. *
  7. * @license see /license.txt
  8. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  9. */
  10. class CurrentUser
  11. {
  12. /**
  13. *
  14. * @return CurrentUser
  15. */
  16. public static function instance()
  17. {
  18. static $result = null;
  19. if (empty($result)) {
  20. $result = new self();
  21. }
  22. return $result;
  23. }
  24. protected function __construct()
  25. {
  26. ;
  27. }
  28. public function data()
  29. {
  30. global $_user;
  31. return $_user;
  32. //return Session::read('_user');
  33. }
  34. public function is_anonymous()
  35. {
  36. return api_is_anonymous();
  37. }
  38. public function first_name()
  39. {
  40. return $this->get('firstName');
  41. }
  42. public function last_name()
  43. {
  44. return $this->get('lastName');
  45. }
  46. public function email()
  47. {
  48. return $this->get('mail');
  49. }
  50. public function last_login()
  51. {
  52. return $this->get('lastLogin');
  53. }
  54. public function official_code()
  55. {
  56. return $this->get('official_code');
  57. }
  58. public function picture_uri()
  59. {
  60. return $this->get('picture_uri');
  61. }
  62. public function user_id()
  63. {
  64. return (int) $this->get('user_id');
  65. }
  66. public function language()
  67. {
  68. return $this->get('language');
  69. }
  70. public function auth_source()
  71. {
  72. return $this->get('auth_source');
  73. }
  74. public function theme()
  75. {
  76. return $this->get('theme');
  77. }
  78. /**
  79. * Returns true if user is a platform administrator, false otherwise.
  80. *
  81. * @return boolean
  82. * @see UserManager::is_admin(user_id) for user-id specific function.
  83. */
  84. public function is_platform_admin()
  85. {
  86. return (bool) Session::read('is_platformAdmin', false);
  87. }
  88. /**
  89. * Returns true if user is a session administrator, false otherwise.
  90. *
  91. * @return boolean
  92. */
  93. public function is_session_admin($allow_sessions_admins = false)
  94. {
  95. global $_user;
  96. return (bool) $_user['status'] == SESSIONADMIN;
  97. }
  98. /**
  99. * Returns true if the current user is allowed to create courses, false otherwise.
  100. *
  101. * @return boolean
  102. * false otherwise.
  103. */
  104. public function is_allowed_to_create_course()
  105. {
  106. return (bool) Session::read('is_allowedCreateCourse', false);
  107. }
  108. /**
  109. * Returns true if the current user is a course administrator for the current course, false otherwise.
  110. *
  111. * @return boolean
  112. */
  113. public function is_course_admin()
  114. {
  115. return (bool) Session::read('is_courseAdmin', false);
  116. }
  117. /**
  118. * Returns true if the current user is a course member of the current course, false otherwise.
  119. *
  120. * @return bool
  121. */
  122. public function is_course_member()
  123. {
  124. return (bool) Session::read('is_courseMember', false);
  125. }
  126. /**
  127. * Returns true if the current user is allowed in the current course, false otherwise.
  128. *
  129. * @return bool
  130. */
  131. public function is_allowed_in_course()
  132. {
  133. return (bool) Session::read('is_allowed_in_course', false);
  134. }
  135. /**
  136. * Returns true if the current user is a course coach for the current course, false otherwise.
  137. *
  138. * @return bool
  139. */
  140. public function is_course_coach()
  141. {
  142. return (bool) Session::read('is_courseCoach', false);
  143. }
  144. /**
  145. * Returns true if the current user is a course tutor for the current course, false otherwise.
  146. *
  147. * @return bool
  148. */
  149. public function is_course_tutor()
  150. {
  151. return (bool) Session::read('is_courseTutor', false);
  152. }
  153. public function get($name, $default = false)
  154. {
  155. $data = $this->data();
  156. return isset($data[$name]) ? $data[$name] : $default;
  157. }
  158. }