request.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Glossay request class definition
  5. * @package chamilo.glossary
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace Glossary;
  11. use \ChamiloSession as Session;
  12. /**
  13. * Html request for course description.
  14. *
  15. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  16. * @license /license.txt
  17. */
  18. class Request extends \Request
  19. {
  20. const PARAM_ID = 'id';
  21. const PARAM_IDS = 'ids';
  22. const PARAM_C_ID = 'c_id';
  23. const PARAM_SESSION_ID = 'id_session';
  24. const PARAM_ACTION = 'action';
  25. const PARAM_SEC_TOKEN = 'sec_token';
  26. const PARAM_IS_STUDENT_VIEW = 'isStudentView';
  27. const PARAM_SORT_COLUMN = 'sort_column';
  28. const PARAM_SORT_DIRECTION = 'sort_direction';
  29. const PARAM_PAGE = 'page';
  30. const PARAM_VIEW = 'view';
  31. /**
  32. * Action to perform. *
  33. * @return string
  34. */
  35. public static function get_action()
  36. {
  37. $result = Request::get(self::PARAM_ACTION, '');
  38. return $result;
  39. }
  40. /**
  41. * Returns the object id.
  42. *
  43. * @return int
  44. */
  45. public static function get_id()
  46. {
  47. $result = \Request::get(self::PARAM_ID, 0);
  48. $result = intval($result);
  49. return $result;
  50. }
  51. /**
  52. * List of objet ids
  53. *
  54. * @return array
  55. */
  56. public static function get_ids()
  57. {
  58. $result = Request::get(self::PARAM_IDS, array());
  59. if (is_array($result)) {
  60. return $result;
  61. }
  62. $result = trim($result);
  63. if (empty($result)) {
  64. return array();
  65. }
  66. $result = explode(',', $result);
  67. return $result;
  68. }
  69. /**
  70. * Returns the course id.
  71. *
  72. * @return int
  73. */
  74. public static function get_c_id()
  75. {
  76. $result = Request::get(self::PARAM_C_ID, 0);
  77. $result = intval($result);
  78. $result = $result ? $result : api_get_real_course_id();
  79. $result = $result ? $result : 0;
  80. return $result;
  81. }
  82. /**
  83. * Returns the session id.
  84. *
  85. * @return int
  86. */
  87. public static function get_session_id()
  88. {
  89. $result = Request::get(self::PARAM_SESSION_ID, 0);
  90. $result = intval($result);
  91. return $result;
  92. }
  93. /**
  94. * Returns the security token.
  95. *
  96. * @return string
  97. */
  98. public static function get_security_token()
  99. {
  100. $result = Request::get(self::PARAM_SEC_TOKEN, 0);
  101. return $result;
  102. }
  103. /**
  104. * Returns true if the user is in "student view". False otherwise.
  105. *
  106. * @return bool
  107. */
  108. public static function is_student_view()
  109. {
  110. return Request::get(self::PARAM_IS_STUDENT_VIEW, false) == 'true';
  111. }
  112. /**
  113. * Returns a course key parameters. I.e. not a real course but an
  114. * object with the course c_id and session set up.
  115. *
  116. * @return object
  117. */
  118. public static function get_course_key()
  119. {
  120. $result = (object) array();
  121. $result->c_id = Request::get_c_id();
  122. $result->session_id = Request::get_session_id();
  123. return $result;
  124. }
  125. /**
  126. * Returns an item key. I.e. not a real entity object but an
  127. * object with the object keys set up.
  128. *
  129. * @return object
  130. */
  131. public static function get_item_key()
  132. {
  133. $result = (object) array();
  134. $result->c_id = Request::get_c_id();
  135. $result->id = Request::get_id();
  136. return $result;
  137. }
  138. public static function get_sort_column()
  139. {
  140. $result = Request::get(self::PARAM_SORT_COLUMN, 'name');
  141. $result = ($result == 'description') ? 'description' : 'name';
  142. return $result;
  143. }
  144. public static function get_sort_direction(){
  145. $result = Request::get(self::PARAM_SORT_DIRECTION, 'name');
  146. $result = strtoupper($result);
  147. $result = ($result == 'DESC') ? 'DESC' : 'ASC';
  148. return $result;
  149. }
  150. public static function get_page(){
  151. $result = Request::get(self::PARAM_PAGE, 0);
  152. return (int)$result;
  153. }
  154. public static function get_view(){
  155. $result = Request::get(self::PARAM_VIEW);
  156. $result = $result ? $result : Session::read(self::PARAM_VIEW, 'list');
  157. $result = ($result == 'table') ? 'table' : 'list';
  158. return $result;
  159. }
  160. }