PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/assign/feedback/file/importzipform.php

http://github.com/moodle/moodle
PHP | 138 lines | 85 code | 20 blank | 33 comment | 13 complexity | e1d3c53af41f7f0a4942717f05429208 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This file contains the forms to create and edit an instance of this module
  18. *
  19. * @package assignfeedback_file
  20. * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
  24. require_once($CFG->libdir.'/formslib.php');
  25. require_once($CFG->dirroot.'/mod/assign/feedback/file/importziplib.php');
  26. /**
  27. * Import zip form
  28. *
  29. * @package assignfeedback_file
  30. * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
  31. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32. */
  33. class assignfeedback_file_import_zip_form extends moodleform implements renderable {
  34. /**
  35. * Create this grade import form
  36. */
  37. public function definition() {
  38. global $CFG, $PAGE;
  39. $mform = $this->_form;
  40. $params = $this->_customdata;
  41. $renderer = $PAGE->get_renderer('assign');
  42. // Visible elements.
  43. $assignment = $params['assignment'];
  44. $contextid = $assignment->get_context()->id;
  45. $importer = $params['importer'];
  46. $update = false;
  47. if (!$importer) {
  48. print_error('invalidarguments');
  49. return;
  50. }
  51. $files = $importer->get_import_files($contextid);
  52. $mform->addElement('header', 'uploadzip', get_string('confirmuploadzip', 'assignfeedback_file'));
  53. $currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
  54. $allusers = $assignment->list_participants($currentgroup, false);
  55. $participants = array();
  56. foreach ($allusers as $user) {
  57. $participants[$assignment->get_uniqueid_for_user($user->id)] = $user;
  58. }
  59. $fs = get_file_storage();
  60. $updates = array();
  61. foreach ($files as $unzippedfile) {
  62. $user = null;
  63. $plugin = null;
  64. $filename = '';
  65. if ($importer->is_valid_filename_for_import($assignment, $unzippedfile, $participants, $user, $plugin, $filename)) {
  66. if ($importer->is_file_modified($assignment, $user, $plugin, $filename, $unzippedfile)) {
  67. // Get a string we can show to identify this user.
  68. $userdesc = fullname($user, has_capability('moodle/site:viewfullnames', $assignment->get_context()));
  69. $path = pathinfo($filename);
  70. if ($assignment->is_blind_marking()) {
  71. $userdesc = get_string('hiddenuser', 'assign') .
  72. $assignment->get_uniqueid_for_user($user->id);
  73. }
  74. $grade = $assignment->get_user_grade($user->id, false);
  75. $exists = false;
  76. if ($grade) {
  77. $exists = $fs->file_exists($contextid,
  78. 'assignfeedback_file',
  79. ASSIGNFEEDBACK_FILE_FILEAREA,
  80. $grade->id,
  81. $path['dirname'],
  82. $path['basename']);
  83. }
  84. if (!$grade || !$exists) {
  85. $updates[] = get_string('feedbackfileadded', 'assignfeedback_file',
  86. array('filename'=>$filename, 'student'=>$userdesc));
  87. } else {
  88. $updates[] = get_string('feedbackfileupdated', 'assignfeedback_file',
  89. array('filename'=>$filename, 'student'=>$userdesc));
  90. }
  91. }
  92. }
  93. }
  94. if (count($updates)) {
  95. $mform->addElement('html', $renderer->list_block_contents(array(), $updates));
  96. } else {
  97. $mform->addElement('html', get_string('nochanges', 'assignfeedback_file'));
  98. }
  99. $mform->addElement('hidden', 'id', $assignment->get_course_module()->id);
  100. $mform->setType('id', PARAM_INT);
  101. $mform->addElement('hidden', 'action', 'viewpluginpage');
  102. $mform->setType('action', PARAM_ALPHA);
  103. $mform->addElement('hidden', 'confirm', 'true');
  104. $mform->setType('confirm', PARAM_BOOL);
  105. $mform->addElement('hidden', 'plugin', 'file');
  106. $mform->setTYpe('plugin', PARAM_PLUGIN);
  107. $mform->addElement('hidden', 'pluginsubtype', 'assignfeedback');
  108. $mform->setTYpe('pluginsubtype', PARAM_PLUGIN);
  109. $mform->addElement('hidden', 'pluginaction', 'uploadzip');
  110. $mform->setType('pluginaction', PARAM_ALPHA);
  111. if (count($updates)) {
  112. $this->add_action_buttons(true, get_string('confirm'));
  113. } else {
  114. $mform->addElement('cancel');
  115. $mform->closeHeaderBefore('cancel');
  116. }
  117. }
  118. }