backup_iassign_stepslib.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Define all the backup steps that will be used by the backup_iassign_activity_task
  4. *
  5. * @author Patricia Alves Rodrigues
  6. * @author Leônidas O. Brandão
  7. * @version v 1.0 2012
  8. * @package mod_iassign_backup
  9. * @since 2012
  10. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  11. *
  12. * <b>License</b>
  13. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  14. *
  15. * @see backup_activity_structure_step
  16. */
  17. /**
  18. * Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
  19. */
  20. defined('MOODLE_INTERNAL') || die();
  21. /**
  22. * Define the complete choice structure for backup, with file and id annotations
  23. * @see backup_activity_structure_step
  24. */
  25. class backup_iassign_activity_structure_step extends backup_activity_structure_step {
  26. /**
  27. * Define the structure for the iassign activity
  28. * @return void Return the root element (choice), wrapped into standard activity structure
  29. */
  30. protected function define_structure () {
  31. // To know if we are including userinfo
  32. $userinfo = $this->get_setting_value('userinfo');
  33. $iassign = new backup_nested_element('iassign', array('id'), array('name',
  34. 'course',
  35. 'intro',
  36. 'introformat',
  37. 'activity_group',
  38. 'grade',
  39. 'timeavailable',
  40. 'timedue',
  41. 'preventlate',
  42. 'test',
  43. 'max_experiment'));
  44. $statements = new backup_nested_element('statements');
  45. $statement = new backup_nested_element('statement', array('id'), array('name',
  46. 'iassignid',
  47. 'type_iassign',
  48. 'proposition',
  49. 'author_name',
  50. 'author_modified_name',
  51. 'iassign_ilmid',
  52. 'file',
  53. 'grade',
  54. 'timecreated',
  55. 'timemodified',
  56. 'timeavailable',
  57. 'timedue',
  58. 'preventlate',
  59. 'test',
  60. 'special_param1',
  61. 'position',
  62. 'visible',
  63. 'max_experiment',
  64. 'dependency',
  65. 'automatic_evaluate',
  66. 'show_answer'));
  67. $iassign_submissions = new backup_nested_element('iassign_submissions');
  68. $iassign_submission = new backup_nested_element('iassign_submission', array('id'), array('iassign_statementid',
  69. 'userid',
  70. 'timecreated',
  71. 'timemodified',
  72. 'grade',
  73. 'teacher',
  74. 'answer',
  75. 'experiment',
  76. 'status'));
  77. $iassign_submission_comments = new backup_nested_element('iassign_submission_comments');
  78. $iassign_submission_comment = new backup_nested_element('iassign_submission_comment', array('id'), array('iassign_submissionid',
  79. 'comment_authorid',
  80. 'timecreated',
  81. 'comment',
  82. 'return_status',
  83. 'receiver'));
  84. // Build the tree
  85. $iassign->add_child($statements);
  86. $statements->add_child($statement);
  87. $statement->add_child($iassign_submissions);
  88. $iassign_submissions->add_child($iassign_submission);
  89. $iassign_submission->add_child($iassign_submission_comments);
  90. $iassign_submission_comments->add_child($iassign_submission_comment);
  91. // Define sources
  92. $iassign->set_source_table('iassign', array('id' => backup::VAR_ACTIVITYID));
  93. $statement->set_source_sql('
  94. SELECT *
  95. FROM {iassign_statement}
  96. WHERE iassignid = ?', array(backup::VAR_PARENTID));
  97. if($userinfo) {
  98. $iassign_submission->set_source_table('iassign_submission', array('iassign_statementid' => backup::VAR_PARENTID));
  99. $iassign_submission_comment->set_source_table('iassign_submission_comment', array('iassign_submissionid' => backup::VAR_PARENTID));
  100. }
  101. // Define id annotations
  102. $iassign_submission->annotate_ids('user', 'userid');
  103. $iassign_submission->annotate_ids('user', 'teacher');
  104. $iassign_submission_comment->annotate_ids('user', 'comment_authorid');
  105. // Define file annotations
  106. $iassign->annotate_files('mod_iassign', 'exercise', null); // This file area hasn't itemid
  107. return $this->prepare_activity_structure($iassign);
  108. }
  109. }