Skip to content

Instantly share code, notes, and snippets.

@jleyva
Last active December 19, 2015 01:28
Show Gist options
  • Save jleyva/5875590 to your computer and use it in GitHub Desktop.
Save jleyva/5875590 to your computer and use it in GitHub Desktop.
Assinglib para funcionar con uploadgroup mod/assign/submission/file/locallib.php
/**
* Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type
* and version.
*
* @param string $type
* @param int $version
* @return bool True if upgrade is possible
*/
public function can_upgrade($type, $version) {
$uploadsingletype ='uploadsingle';
$uploadtype ='upload';
$uploadgroup ='uploadsinglegroup';
if (($type == $uploadsingletype || $type == $uploadtype || $type == $uploadgroup) && $version >= 2011112900) {
return true;
}
return false;
}
/**
* Upgrade the settings from the old assignment
* to the new plugin based one
*
* @param context $oldcontext - the old assignment context
* @param stdClass $oldassignment - the old assignment data record
* @param string $log record log events here
* @return bool Was it a success? (false will trigger rollback)
*/
public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) {
global $DB;
if ($oldassignment->assignmenttype == 'uploadsingle') {
$this->set_config('maxfilesubmissions', 1);
$this->set_config('maxsubmissionsizebytes', $oldassignment->maxbytes);
return true;
} else if ($oldassignment->assignmenttype == 'upload') {
$this->set_config('maxfilesubmissions', $oldassignment->var1);
$this->set_config('maxsubmissionsizebytes', $oldassignment->maxbytes);
// Advanced file upload uses a different setting to do the same thing.
$DB->set_field('assign',
'submissiondrafts',
$oldassignment->var4,
array('id'=>$this->assignment->get_instance()->id));
// Convert advanced file upload "hide description before due date" setting.
$alwaysshow = 0;
if (!$oldassignment->var3) {
$alwaysshow = 1;
}
$DB->set_field('assign',
'alwaysshowdescription',
$alwaysshow,
array('id'=>$this->assignment->get_instance()->id));
return true;
} else if ($oldassignment->assignmenttype == 'uploadsinglegroup') {
$this->set_config('maxfilesubmissions', 1);
$this->set_config('maxsubmissionsizebytes', $oldassignment->maxbytes);
$DB->set_field('assign',
'teamsubmission',
1,
array('id'=>$this->assignment->get_instance()->id));
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment