derez_object.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // Simulates an ajax object-rezzing request
  3. require_once '../../../lib/json/json_encoding.inc.php';
  4. /** Grab the Sloodle/Moodle configuration. */
  5. require_once('../../../init.php');
  6. /** Include the Sloodle PHP API. */
  7. /** Sloodle core library functionality */
  8. require_once(SLOODLE_DIRROOT.'/lib.php');
  9. /** General Sloodle functions. */
  10. require_once(SLOODLE_LIBROOT.'/io.php');
  11. /** Sloodle course data. */
  12. require_once(SLOODLE_LIBROOT.'/course.php');
  13. require_once(SLOODLE_LIBROOT.'/layout_profile.php');
  14. require_once(SLOODLE_LIBROOT.'/active_object.php');
  15. require_once(SLOODLE_LIBROOT.'/user.php');
  16. require_once(SLOODLE_LIBROOT.'/object_configs.php');
  17. $error = '';
  18. if (!$USER->id) {
  19. output( 'User not logged in' );
  20. exit;
  21. }
  22. $rezzer = new SloodleActiveObject();
  23. $sloodleuser = new SloodleUser();
  24. $sloodleuser->user_data = $USER;
  25. // Set this if we really need an answer now.
  26. // This is used when removing from a layout, because we want to derez the objects first
  27. // ...and we won't want to go ahead with the rest of the operation unless the object is gone.
  28. $forcesynchronous = optional_param('synchronous', 0, PARAM_INT);
  29. $async = ( $forcesynchronous || ( defined('SLOODLE_ASYNC_DEREZZING') && SLOODLE_ASYNC_DEREZZING ) );
  30. if (!$layoutentryid = optional_param( 'layoutentryid', 0, PARAM_INT) ) {
  31. error_output( 'Layout ID missing' );
  32. }
  33. if (!$controllerid = optional_param( 'controllerid', 0, PARAM_INT) ) {
  34. error_output( 'Controller ID missing' );
  35. }
  36. $controller_context = get_context_instance( CONTEXT_MODULE, $controllerid);
  37. if (!has_capability('mod/sloodle:uselayouts', $controller_context)) {
  38. error_output( 'Access denied');
  39. }
  40. if ( !$rezzeruuid = optional_param( 'rezzeruuid', null, PARAM_SAFEDIR ) ) {
  41. error_output('Could not load rezzer');
  42. }
  43. $primpassword = sloodle_random_prim_password();
  44. $controller = new SloodleController();
  45. if (!$controller->load( $controllerid )) {
  46. error_output('Could not load controller');
  47. }
  48. $failures = array();
  49. //$active_objects = $controller->get_active_objects( $rezzeruuid, $layoutentryid );
  50. //$active_objects = $controller->get_active_objects( null, $layoutentryid);
  51. $active_objects = $controller->get_active_objects( $rezzeruuid, $layoutentryid );
  52. $result = '';
  53. foreach($active_objects as $ao) {
  54. if ($ao->isQueueActive() && $async) {
  55. if ($ao->queueDeRez()) {
  56. $result = 'queued';
  57. } else {
  58. $failures[] = $ao;
  59. }
  60. } else {
  61. if (!$ao->deRez()) {
  62. $result = 'derezzed';
  63. } else {
  64. $failures[] = $ao;
  65. }
  66. }
  67. //$rezzed_object_uuid = $reply['result'];
  68. }
  69. // TODO: Handle failures properly...
  70. if (count($failures) > 0) {
  71. $result = 'failed';
  72. $error = 'derez_failed';
  73. }
  74. $content = array(
  75. 'result' => $result,
  76. 'error' => $error,
  77. );
  78. print json_encode($content);
  79. function error_output($error) {
  80. $content = array(
  81. 'result' => 'failed',
  82. 'error' => $error,
  83. );
  84. print json_encode($content);
  85. exit;
  86. }
  87. ?>