current_course.class.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. use \ChamiloSession as Session;
  3. /**
  4. * Wrapper for the current course. Provide access to its data.
  5. *
  6. * @license see /license.txt
  7. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  8. */
  9. class CurrentCourse
  10. {
  11. /**
  12. *
  13. * @return CurrentCourse
  14. */
  15. public static function instance()
  16. {
  17. static $result = null;
  18. if (empty($result)) {
  19. $result = new self();
  20. }
  21. return $result;
  22. }
  23. protected function __construct()
  24. {
  25. ;
  26. }
  27. public function is_empty()
  28. {
  29. $id = $this->real_id();
  30. return empty($id);
  31. }
  32. public function data()
  33. {
  34. global $_course;
  35. if ($_course == '-1') {
  36. $_course = array();
  37. }
  38. return $_course;
  39. }
  40. public function real_id()
  41. {
  42. return (int)$this->get('real_id');
  43. }
  44. public function code()
  45. {
  46. return $this->get('code');
  47. }
  48. public function name()
  49. {
  50. return $this->get('name');
  51. }
  52. public function title()
  53. {
  54. return $this->get('title');
  55. }
  56. public function official_code()
  57. {
  58. return $this->get('official_code');
  59. }
  60. public function sys_code()
  61. {
  62. return $this->get('sysCode');
  63. }
  64. public function path()
  65. {
  66. return $this->get('path');
  67. }
  68. /**
  69. * not needed in Chamilo 1.9
  70. *
  71. * @return type
  72. */
  73. public function db_name()
  74. {
  75. return $this->get('dbName');
  76. }
  77. public function db_name_glu()
  78. {
  79. return $this->get('dbNameGlu');
  80. }
  81. public function titular()
  82. {
  83. return $this->get('titular');
  84. }
  85. public function language()
  86. {
  87. return $this->get('language');
  88. }
  89. public function category_code()
  90. {
  91. return $this->get('categoryCode');
  92. }
  93. public function category_ame()
  94. {
  95. return $this->get('category_name');
  96. }
  97. public function visibility()
  98. {
  99. return $this->get('visibility');
  100. }
  101. public function subscribe_allowed()
  102. {
  103. return $this->get('subscribe_allowed');
  104. }
  105. public function unsubscribe_allowed()
  106. {
  107. return $this->get('unsubscribe');
  108. }
  109. public function activate_legal()
  110. {
  111. return $this->get('activate_legal');
  112. }
  113. public function show_score()
  114. {
  115. return $this->get('show_score');
  116. }
  117. public function extrnal_link()
  118. {
  119. return $this->get('extLink');
  120. }
  121. /**
  122. * Returns the current user (logged in user) relationship with the course.
  123. * I.e his role
  124. *
  125. * @return array
  126. */
  127. public function user()
  128. {
  129. $result = Session::read('_courseUser');
  130. $result = $result ? $result : array();
  131. return $result;
  132. }
  133. public function get($name, $default = false)
  134. {
  135. $data = $this->data();
  136. return isset($data[$name]) ? $data[$name] : $default;
  137. }
  138. }