access.class.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Glossary access class
  5. * @package chamilo.glossary
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace Glossary;
  11. /**
  12. * Authorize current users to perform various actions.
  13. *
  14. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Genevas
  15. * @license /license.txt
  16. */
  17. class Access extends \Access
  18. {
  19. /**
  20. * Return the instance .
  21. *
  22. * @return \Access
  23. */
  24. public static function instance()
  25. {
  26. static $result = null;
  27. if (empty($result)) {
  28. $result = new self();
  29. }
  30. return $result;
  31. }
  32. /**
  33. * Returns true if the user has the right to edit.
  34. *
  35. * @return boolean
  36. */
  37. public function can_edit()
  38. {
  39. if (Request::is_student_view()) {
  40. return false;
  41. }
  42. $session_id = Request::get_session_id();
  43. if ($session_id != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  44. return false;
  45. }
  46. if (!api_is_allowed_to_edit(false, true, true)) {
  47. return false;
  48. }
  49. return true;
  50. }
  51. /**
  52. * Returns true if the current user has the right to view
  53. *
  54. * @return boolean
  55. */
  56. public function can_view()
  57. {
  58. $authorize = api_protect_course_script(true);
  59. if (!$authorize) {
  60. return false;
  61. }
  62. $c_id = Request::get_c_id();
  63. if (empty($c_id)) {
  64. return false;
  65. }
  66. return true;
  67. }
  68. public function authorize()
  69. {
  70. if (!$this->can_view()) {
  71. return false;
  72. }
  73. $c_id = Request::get_c_id();
  74. if (empty($c_id)) {
  75. return false;
  76. }
  77. return true;
  78. }
  79. }