request.class.php 3.8 KB

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