request.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace Link;
  3. /**
  4. * Html request for Link.
  5. *
  6. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  7. * @license /license.txt
  8. */
  9. class Request extends \Request
  10. {
  11. const PARAM_ID = 'id';
  12. const PARAM_IDS = 'ids';
  13. const PARAM_C_ID = 'c_id';
  14. const PARAM_SESSION_ID = 'id_session';
  15. const PARAM_ACTION = 'action';
  16. const PARAM_SECURITY_TOKEN = 'sec_token';
  17. const PARAM_IS_STUDENT_VIEW = 'isStudentView';
  18. const PARAM_GROUP_ID = 'toolgroup';
  19. /**
  20. * Action to perform. *
  21. * @return string
  22. */
  23. public static function get_action()
  24. {
  25. $result = Request::get(self::PARAM_ACTION, '');
  26. return $result;
  27. }
  28. /**
  29. * Returns the object id.
  30. *
  31. * @return int
  32. */
  33. public static function get_id()
  34. {
  35. $result = \Request::get(self::PARAM_ID, 0);
  36. $result = intval($result);
  37. return $result;
  38. }
  39. /**
  40. * List of objet ids
  41. *
  42. * @return array
  43. */
  44. public static function get_ids()
  45. {
  46. $result = Request::get(self::PARAM_IDS, array());
  47. if (is_array($result)) {
  48. return $result;
  49. }
  50. $result = trim($result);
  51. if (empty($result)) {
  52. return array();
  53. }
  54. $result = explode(',', $result);
  55. return $result;
  56. }
  57. /**
  58. * Returns the course id.
  59. *
  60. * @return int
  61. */
  62. public static function get_c_id()
  63. {
  64. $result = Request::get(self::PARAM_C_ID, 0);
  65. $result = intval($result);
  66. $result = $result ? $result : api_get_real_course_id();
  67. $result = $result ? $result : 0;
  68. return $result;
  69. }
  70. /**
  71. * Returns the session id.
  72. *
  73. * @return int
  74. */
  75. public static function get_session_id()
  76. {
  77. $result = Request::get(self::PARAM_SESSION_ID, 0);
  78. $result = intval($result);
  79. return $result;
  80. }
  81. /**
  82. * Returns the session id.
  83. *
  84. * @return int
  85. */
  86. public static function get_group_id()
  87. {
  88. $result = Request::get(self::PARAM_GROUP_ID, 0);
  89. $result = intval($result);
  90. return $result;
  91. }
  92. /**
  93. * Returns the security token.
  94. *
  95. * @return string
  96. */
  97. public static function get_security_token()
  98. {
  99. $result = Request::get(self::PARAM_SEC_TOKEN, 0);
  100. return $result;
  101. }
  102. /**
  103. * Returns true if the user is in "student view". False otherwise.
  104. *
  105. * @return bool
  106. */
  107. public static function is_student_view()
  108. {
  109. return Request::get(self::PARAM_IS_STUDENT_VIEW, false) == 'true';
  110. }
  111. }