123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- <?php
- require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
- function xmldb_iassign_upgrade ($oldversion) {
- global $CFG, $DB, $USER;
- $dbman = $DB->get_manager();
-
- if ($oldversion < 2020070613) {
- $table = new xmldb_table('iassign_submission');
- $field = new xmldb_field('previous_grade', XMLDB_TYPE_FLOAT, null, null, null, null, null);
- if (!$dbman->field_exists($table, $field)) {
- $dbman->add_field($table, $field);
- }
- $records = array(
- array_combine(
- array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
- array('iGeom', 'http://www.matematica.br/igeom', '5.9.22', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}', 'geo', 'ilm/iGeom/5.9.22/iGeom.jar', 'IGeomApplet.class', 800, 600, 1, time(), $USER->id, time(), 1, 0)),
- array_combine(
- array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
- array('iGraf', 'http://www.matematica.br/igraf', '4.4.0.10', 'Java', '{"en":"Interactive Graphic on the Internet","pt_br":"Gráficos Interativos na Internet"}', 'grf', 'ilm/iGraf/4.4.0.10/iGraf.jar', 'igraf.IGraf.class', 840, 600, 1, time(), $USER->id, time(), 1, 0)),
- array_combine(
- array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
- array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}', 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500, 1, time(), $USER->id, time(), 1, 0)),
- array_combine(
- array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
- array('iVProg', 'http://www.usp.br/line/ivprog/', '1.0.20200221', 'HTML5', '{"en":"Visual Interactive Programming on the Internet (HTML)","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/iVProg/1.0.20200221/ivprog/', 'index.html', 800, 600, 1, time(), $USER->id, time(), 1, 1)),
- array_combine(
- array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate', 'reevaluate'),
- array('iFractions', 'http://www.matematica.br/ifractions', '0.1.20200221', 'HTML5', '{"en":"Interactive Fractions game","pt_br":"Jogo interativa de frações"}', 'frc', 'ilm/iFractions/0.1.20200221/ifractions/', 'index.html', 1000, 600, 1, time(), $USER->id, time(), 1, 0))
- );
- $iassign_ilm = $DB->get_records('iassign_ilm');
- $strNot_installed = '';
- foreach ($records as $record) {
- $newentry = new stdClass();
- $newentry->name = $record['name'];
- $newentry->version = $record['version'];
- $newentry->type = $record['type'];
- $newentry->url = $record['url'];
- $newentry->description = $record['description'];
- $newentry->extension = $record['extension'];
- $newentry->file_jar = $record['file_jar'];
- $newentry->file_class = $record['file_class'];
- $newentry->width = $record['width'];
- $newentry->height = $record['height'];
- $newentry->enable = $record['enable'];
- $newentry->timemodified = time();
- $newentry->author = $USER->id;
- $newentry->timecreated = time();
- $newentry->evaluate = $record['evaluate'];
- $exists = 0;
- if ($iassign_ilm) {
- $record_type = strtolower($record['type']);
- foreach ($iassign_ilm as $iassign) {
- if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
- if ($iassign->version == $record['version']) {
- $exists = 1;
- $strNot_installed += "\n" + ' <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
- break;
- }
- }
- }
- }
- if ($exists == 0) try {
- $DB->insert_record("iassign_ilm", $newentry, false);
- } catch (Exception $e) {
- print 'Caught exception: ' . $e->getMessage() . "<br/>\n";
- }
- }
- if ($strNot_installed != '') {
- print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
- print get_string('upgrade_alert_exists', 'iassign');
- print ' <ul style="margin-top: 1rem;">' + "\n";
- print $strNot_installed;
- print ' </ul>' + "\n";
- print '</div>' + "\n";
- }
-
- $strNot_found = '';
- if ($iassign_ilm) {
- foreach ($iassign_ilm as $iassign) {
- $found = false;
- foreach ($records as $record) {
- if ($iassign->name == $record['name']) {
- $found = true;
- break;
- }
- }
- if (!$found) {
- $strNot_found .= '<li>' . $iassign->name . ' - <a href="' . $iassign->url . '" target="_blank">' . $iassign->url . '</a></li>' . "\n";
- $updateentry = new stdClass();
- $updateentry->id = $iassign->id;
- $updateentry->enable = 0;
- $updateentry->timemodified = time();
- $DB->update_record("iassign_ilm", $updateentry);
- }
- }
- }
- if ($strNot_found != '') {
- print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
- print get_string('upgrade_alert_iMA_msg', 'iassign');
- print '<ul style="margin-top: 1rem;">' + "\n";
- print $strNot_found;
- print '</ul>' + "\n";
- print get_string('upgrade_alert_iMA_solution_pt1', 'iassign');
- print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' . "\n";
- print '</div>' + "\n";
- }
- }
- if ($oldversion < 2020070613) {
- $table = new xmldb_table('iassign_ilm');
- $field = new xmldb_field('reevaluate');
- $field->set_attributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', null, null, null);
- if (!$dbman->field_exists($table, $field)) {
- $dbman->add_field($table, $field);
- }
- $iassign_ilm = $DB->get_records('iassign_ilm');
- foreach ($iassign_ilm as $iassign) {
- if ($iassign->type == 'HTML5' && ($iassign->name == 'iVProg' || $iassign->name == 'iHanoi')) {
- $updateentry = new stdClass();
- $updateentry->id = $iassign->id;
- $updateentry->reevaluate = 1;
- $updateentry->timemodified = time();
- $DB->update_record("iassign_ilm", $updateentry);
- break;
- }
- }
- }
- if ($oldversion < 2020080300) {
-
- if ($dbman->field_exists('iassign', 'grade')) {
- $sql = 'ALTER TABLE {iassign} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
- $DB->execute($sql);
- }
- if ($dbman->field_exists('iassign_statement', 'grade')) {
- $sql = 'ALTER TABLE {iassign_statement} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
- $DB->execute($sql);
- }
- if ($dbman->field_exists('iassign_submission', 'grade')) {
- $sql = 'ALTER TABLE {iassign_submission} CHANGE grade grade FLOAT NOT NULL DEFAULT 0.0';
- $DB->execute($sql);
- }
- if ($dbman->field_exists('iassign_submission', 'previous_grade')) {
-
- $sql = 'ALTER TABLE {iassign_submission} CHANGE previous_grade previous_grade FLOAT DEFAULT 0.0';
- $DB->execute($sql);
- }
-
- $records = array(
- array_combine(
- array('name', 'url', 'version', 'type', 'description',
- 'extension', 'file_jar', 'file_class', 'width', 'height',
- 'enable', 'timemodified', 'evaluate', 'reevaluate', 'author', 'timecreated'),
- array('iHanoi', 'http://www.matematica.br/ihanoi', '1.0.20200803', 'HTML5', '{"en":"interactive Tower os Hanoi (by LInE)", "pt_br":"Torres de Hanói (do LInE)"}',
- 'ihn', 'ilm/iHanoi/1.0.20200803/ihanoi/', 'index.html', 1100, 500,
- 1, time(), 1, 1, $USER->id, time()))
- );
- $iassign_ilm = $DB->get_records('iassign_ilm');
- foreach ($records as $record) {
- $newentry = new stdClass();
- $newentry->name = $record['name'];
- $newentry->version = $record['version'];
- $newentry->type = $record['type'];
- $newentry->url = $record['url'];
- $newentry->description = $record['description'];
- $newentry->extension = $record['extension'];
- $newentry->file_jar = $record['file_jar'];
- $newentry->file_class = $record['file_class'];
- $newentry->width = $record['width'];
- $newentry->height = $record['height'];
- $newentry->enable = $record['enable'];
- $newentry->timemodified = time();
- $newentry->evaluate = $record['evaluate'];
- $newentry->reevaluate = $record['reevaluate'];
- $newentry->author = $USER->id;
- $newentry->timecreated = time();
- $newentry->evaluate = $record['evaluate'];
- $exists = 0;
- $last_id = -1;
- if ($iassign_ilm) {
- $record_type = strtolower($record['type']);
- foreach ($iassign_ilm as $iassign) {
- if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
- if ($iassign->id > $last_id)
- $last_id = $iassign->id;
- if ($iassign->version == $record['version']) {
- $exists = 1;
- $strNot_installed += "\n" + ' <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
- break;
- }
- }
- }
- }
- if ($exists == 0) {
- $newentry->parent = $record['parent'];
- $DB->insert_record("iassign_ilm", $newentry, false);
- }
- }
- if ($strNot_installed != '') {
- print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
- print get_string('upgrade_alert_exists', 'iassign');
- print ' <ul style="margin-top: 1rem;">' + "\n";
- print $strNot_installed;
- print ' </ul>' + "\n";
- print '</div>' + "\n";
- }
-
-
-
- $iassign_ilm = $DB->get_records('iassign_ilm');
- foreach ($iassign_ilm as $iassign) {
- if ($iassign->name == 'iHanoi' && $iassign->type == 'HTML5' && $iassign->reevaluate!=1) {
- $updateentry = new stdClass();
- $updateentry->id = $iassign->id;
- $updateentry->reevaluate = 1;
- $updateentry->timemodified = time();
- $DB->update_record("iassign_ilm", $updateentry);
- break;
- }
- }
-
- upgrade_mod_savepoint(true, 2020080300, 'iassign');
- }
-
- if ($oldversion < 2020120500) {
-
- $table = new xmldb_table('iassign_statement');
- $field_filesid = new xmldb_field('filesid', XMLDB_TYPE_CHAR, '255', null, null, null, null, null);
- if (!$dbman->field_exists($table, $field_filesid))
- $dbman->add_field($table, $field_filesid);
-
-
- $DB->execute("UPDATE {iassign_statement} SET filesid = file");
-
- $iassign_contexts_list = $DB->get_records_sql("SELECT DISTINCT contextid FROM {files} f WHERE component='mod_iassign'");
-
- $contexts = array();
- foreach ($iassign_contexts_list as $iassign_context_item) {
- array_push($contexts, $iassign_context_item->contextid);
- }
-
- $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s WHERE s.id != s.file");
- $fs = get_file_storage();
-
- foreach ($iassign_statement_list as $iassign_statement_activity_item) {
-
-
- $files = array();
- foreach ($contexts as $context) {
- $files = $fs->get_area_files($context, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
-
-
- if ($files) {
- foreach ($files as $value) {
- if ($value != null && $value->get_filename() != ".") {
-
- $newfile = $fs->create_file_from_storedfile(array('contextid' => $context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_statement_activity_item->id), $value);
-
- $update_entry = new stdClass();
- $update_entry->id = $iassign_statement_activity_item->id;
- $update_entry->file = $newfile->get_itemid();
- $update_entry->filesid = $newfile->get_itemid();
- $DB->update_record("iassign_statement", $update_entry);
-
- $value->delete();
- }
- else if ($value != null && $value->get_filename() == ".") {
-
- $value->delete();
- }
- }
- break;
- }
- }
- }
- }
-
- if ($oldversion < 2020122900) {
-
- $table = new xmldb_table('iassign_allsubmissions');
-
- $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
- $table->add_field('iassign_statementid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
- $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
- $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '16', null, XMLDB_NOTNULL, null, null);
- $table->add_field('grade', XMLDB_TYPE_FLOAT, null, null, null, null, null, null);
- $table->add_field('answer', XMLDB_TYPE_TEXT, 'long', null, null, null, null, null);
-
- $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
-
- if (!$dbman->table_exists($table)) {
- $dbman->create_table($table);
- }
-
- $table = new xmldb_table('iassign_ilm');
- $field_editingbehavior = new xmldb_field('editingbehavior', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
- if (!$dbman->field_exists($table, $field_editingbehavior))
- $dbman->add_field($table, $field_editingbehavior);
- $field_submissionbehavior = new xmldb_field('submissionbehavior', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
- if (!$dbman->field_exists($table, $field_submissionbehavior))
- $dbman->add_field($table, $field_submissionbehavior);
- $field_action_buttons = new xmldb_field('action_buttons', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1', null);
-
- if (!$dbman->field_exists($table, $field_action_buttons))
- $dbman->add_field($table, $field_action_buttons);
-
- $table = new xmldb_table('iassign_statement');
- $field_store_all_submissions = new xmldb_field('store_all_submissions', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', null);
- if (!$dbman->field_exists($table, $field_store_all_submissions))
- $dbman->add_field($table, $field_store_all_submissions);
-
- $iassign_ilm = $DB->get_records('iassign_ilm');
- foreach ($iassign_ilm as $iassign) {
- $updateentry = new stdClass();
- $updateentry->id = $iassign->id;
- if (($iassign->name == 'iHanoi' && $iassign->type == 'HTML5')) {
- $updateentry->editingbehavior = 0;
- $updateentry->submissionbehavior = 0;
- }
- if (($iassign->name == 'iGeom' && $iassign->type == 'Java')) {
- $updateentry->editingbehavior = 0;
- $updateentry->submissionbehavior = 0;
- }
- if (($iassign->name == 'iVProg' && $iassign->type == 'HTML5')) {
- $updateentry->editingbehavior = 1;
- $updateentry->submissionbehavior = 0;
- }
- if (($iassign->name == 'iFractions' && $iassign->type == 'HTML5')) {
- $updateentry->editingbehavior = 0;
- $updateentry->submissionbehavior = 1;
- }
- if (($iassign->name == 'Risko' && $iassign->type == 'Java')) {
- $updateentry->editingbehavior = 1;
- $updateentry->submissionbehavior = 0;
- }
- if (isset($updateentry->editingbehavior)) {
- $updateentry->timemodified = time();
- $DB->update_record("iassign_ilm", $updateentry);
- }
- }
-
- $table = new xmldb_table('iassign_allsubmissions');
- if (!$dbman->table_exists($table)) {
- $field1 = new xmldb_field('id');
- $field1->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
- $field2 = new xmldb_field('iassign_statementid');
- $field2->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
- $field3 = new xmldb_field('userid');
- $field3->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
-
- $field4 = new xmldb_field('timecreated');
- $field4->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
- $field5 = new xmldb_field('grade');
- $field5->set_attributes(XMLDB_TYPE_FLOAT, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null);
- $field6 = new xmldb_field('answer');
- $field6->set_attributes(XMLDB_TYPE_TEXT, 'long', null, null, null, null, 'type');
- $table->addIndex($field1);
- $table->addField($field2);
- $table->addField($field3);
- $table->addField($field4);
- $table->addField($field5);
- $table->addField($field6);
- $dbman->create_table($table);
- }
-
- try {
- $DB->execute("ALTER TABLE {iassign_ilm} DROP INDEX {iassilm_fil_uix}");
- } catch (Exception $ex) {}
- }
-
- if (class_exists('plugin_manager'))
- $pluginman = plugin_manager::instance();
- else
- $pluginman = core_plugin_manager::instance();
- $plugins = $pluginman->get_plugins();
- iassign_log::add_log('upgrade', 'version: ' . $plugins['mod']['iassign']->versiondisk);
-
- return true;
- }
|