access.class.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Notebook;
  3. /**
  4. * Authorize current users to perform various actions.
  5. *
  6. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  7. * @license /license.txt
  8. */
  9. class Access extends \Access
  10. {
  11. /**
  12. * Return the instance .
  13. *
  14. * @return \Access
  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. /**
  25. * Returns true if the user has the right to edit.
  26. *
  27. * @return boolean
  28. */
  29. public function can_edit()
  30. {
  31. if (Request::is_student_view()) {
  32. return false;
  33. }
  34. $session_id = Request::get_session_id();
  35. if ($session_id != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  36. return false;
  37. }
  38. if (!api_is_allowed_to_edit()) {
  39. return false;
  40. }
  41. return true;
  42. }
  43. /**
  44. * Returns true if the current user has the right to view
  45. *
  46. * @return boolean
  47. */
  48. public function can_view()
  49. {
  50. $authorize = api_protect_course_script(true);
  51. if (!$authorize) {
  52. return false;
  53. }
  54. $c_id = Request::get_c_id();
  55. if (empty($c_id)) {
  56. return false;
  57. }
  58. return true;
  59. }
  60. public function authorize()
  61. {
  62. if (!$this->can_view()) {
  63. return false;
  64. }
  65. $c_id = Request::get_c_id();
  66. if (empty($c_id)) {
  67. return false;
  68. }
  69. return true;
  70. }
  71. }