. /** * Submission form definition * * @package mod_vpl * @copyright 2012 Juan Carlos Rodríguez-del-Pino * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @author Juan Carlos Rodríguez-del-Pino */ defined( 'MOODLE_INTERNAL' ) || die(); global $CFG; require_once($CFG->libdir.'/formslib.php'); require_once(dirname(__FILE__).'/../locallib.php'); require_once(dirname(__FILE__).'/edit.class.php'); class mod_vpl_submission_form extends moodleform { protected $vpl; protected $userid; protected function getinternalform() { return $this->_form; } public function __construct($page, $vpl, $userid) { $this->vpl = $vpl; $this->userid = $userid; parent::__construct( $page ); } protected function definition() { global $CFG; $mform = & $this->_form; // Identification info. $mform->addElement( 'hidden', 'id' ); $mform->setType( 'id', PARAM_INT ); $mform->addElement( 'hidden', 'userid', 0 ); $mform->setType( 'userid', PARAM_INT ); // Comments. $mform->addElement( 'textarea', 'comments', get_string( 'comments', VPL ), array ( 'cols' => '40', 'rows' => 2 ) ); $mform->setType( 'comments', PARAM_TEXT ); $firstsub = ($this->vpl->last_user_submission( $this->userid ) === false); $mform->addElement( 'select', 'submitmethod', get_string( 'submitmethod', VPL ), array('archive' => get_string( 'archive', VPL ), 'files' => get_string( 'files' )) ); $mform->addElement( 'header', 'headersubmitarchive', get_string( 'submitarchive', VPL ) ); if (!$firstsub) { $mform->addElement( 'radio', 'archiveaction', get_string( 'submitarchive', VPL ), get_string( 'archivereplacedelete', VPL ), 'replacedelete'); $mform->addElement( 'radio', 'archiveaction', '', get_string( 'archivereplace', VPL ), 'replace' ); $mform->disabledIf( 'archiveaction', 'submitmethod', 'neq', 'archive' ); } $mform->addElement( 'filepicker', 'archive', null, null, array('accepted_types' => '.zip') ); $mform->disabledIf( 'archive', 'submitmethod', 'neq', 'archive' ); $mform->addElement( 'header', 'headersubmitfiles', get_string( 'submitfiles', VPL ) ); // Files upload. $instance = $this->vpl->get_instance(); $reqfiles = $this->vpl->get_files('required'); $i = 0; foreach ($reqfiles as $reqfile) { $field = 'file' . $i; if (!$firstsub) { $mform->addElement( 'radio', $field . 'action', $reqfile, get_string( 'keepcurrentfile', VPL ), 'keep'); $mform->addElement( 'radio', $field . 'action', '', get_string( 'replacefile', VPL ), 'replace' ); $mform->disabledIf( $field . 'action', 'submitmethod', 'neq', 'files' ); $mform->addElement( 'hidden', $field . 'name', $reqfile ); $mform->setType( $field . 'name', PARAM_RAW ); } $mform->addElement( 'filepicker', $field ); $mform->disabledIf( $field, 'submitmethod', 'neq', 'files' ); if (!$firstsub) { $mform->disabledIf( $field, $field . 'action', 'neq', 'replace' ); } $i++; } $submission = $this->vpl->last_user_submission( $this->userid ); if ($submission !== false) { $subfiles = (new mod_vpl_submission( $this->vpl, $submission ))->get_submitted_fgm()->getFileList(); foreach ($subfiles as $subfile) { if (!in_array($subfile, $reqfiles)) { $field = 'file' . $i; if (!$firstsub) { $mform->addElement( 'radio', $field . 'action', $subfile, get_string( 'keepcurrentfile', VPL ), 'keep'); $mform->addElement( 'radio', $field . 'action', '', get_string( 'deletefile', VPL ), 'delete' ); $mform->addElement( 'radio', $field . 'action', '', get_string( 'replacefile', VPL ), 'replace' ); $mform->disabledIf( $field . 'action', 'submitmethod', 'neq', 'files' ); $mform->addElement( 'hidden', $field . 'name', $subfile ); $mform->setType( $field . 'name', PARAM_RAW ); } $mform->addElement( 'filepicker', $field ); $mform->disabledIf( $field, 'submitmethod', 'neq', 'files' ); if (!$firstsub) { $mform->disabledIf( $field, $field . 'action', 'neq', 'replace' ); } $i++; } } } while ($i < $instance->maxfiles) { $field = 'file' . $i; $mform->addElement( 'filepicker', $field, get_string( 'anyfile', VPL ) ); $mform->disabledIf( $field, 'submitmethod', 'neq', 'files' ); $i++; } $this->add_action_buttons( true, get_string( 'submit' ) ); global $PAGE; $PAGE->requires->js_call_amd('mod_vpl/submissionform', 'setup'); } public function set_data($data) { for($i=0; $i < $this->vpl->get_instance()->maxfiles; $i++) { $data->{'file'.$i.'action'} = 'keep'; $data->{'archiveaction'} = 'replacedelete'; } parent::set_data($data); } }