install.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * Script for install all ilm in iassign table.
  4. *
  5. * This file replaces:
  6. * STATEMENTS section in db/install.xml
  7. * lib.php/modulename_install() post installation hook partially defaults.php.
  8. *
  9. * Release Notes:
  10. * - v 1.4 2017/02/16
  11. * + Insert iVProgH5, updated iGeom, iGraf, iComb, iHanoi
  12. * - v 1.3 2013/12/12
  13. * + Language support in iLM
  14. * - v 1.2 2013/09/19
  15. * + Change path file for ilm, consider version in pathname
  16. *
  17. * @author Patricia Alves Rodrigues
  18. * @author Leônidas O. Brandão
  19. * @author Luciano Oliveira Borges
  20. * @version v 1.2 2013/09/19
  21. * @package mod_iassign_db
  22. * @since 2010/09/27
  23. * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - Computer Science Dep. of IME-USP (Brazil)
  24. *
  25. * <b>License</b>
  26. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27. */
  28. require_once ($CFG->dirroot . '/mod/iassign/locallib.php');
  29. function xmldb_iassign_install() {
  30. global $DB, $USER, $CFG;
  31. $records = array(
  32. // iGeom 5.9.21
  33. array_combine(
  34. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'), array('iGeom', 'http://www.matematica.br/igeom', '5.9.21', 'Java', '{"en":"Interactive Geometry on the Internet","pt_br":"Geometria Interativa na Internet"}', 'geo', 'iGeom.jar', 'IGeomApplet.class', 800, 600, 1, time(), $USER->id, time(), 1)),
  35. // iGraf 4.4.0.10
  36. array_combine(
  37. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'), 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', 'iGraf.jar', 'igraf.IGraf.class', 840, 600, 1, time(), $USER->id, time(), 1)),
  38. // iComb 0.9.5
  39. array_combine(
  40. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'), array('iComb', 'http://www.matematica.br/icomb', '0.9.5', 'Java', '{"en":"Combinatorics Interactive on the Internet","pt_br":"Combinatória Interativa na Internet"}', 'icb,cmb', 'iComb.jar', 'icomb.IComb.class', 750, 685, 1, time(), $USER->id, time(), 1)),
  41. // iVProg2 2.1.0
  42. array_combine(
  43. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'), array('iVProg2', 'http://www.matematica.br/ivprog2', '2.1.0', 'Java', '{"en":"Visual Interactive Programming on the Internet","pt_br":"Programação visual interativa na Internet"}', 'ivp2', 'iVProg2.jar', 'usp.ime.line.ivprog.Ilm.class', 800, 700, 1, time(), $USER->id, time(), 1)),
  44. // iTangram2 0.4.6
  45. array_combine(
  46. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  47. array('iTangram2', 'http://www.matematica.br/itangram', '0.4.6', 'Java', '{"en":"The Objective of the game is to reproduce the form of the model using all 7 pieces of iTangram","pt_br":"O Objetivo do jogo é reproduzir a forma do modelo usando todas as 7 peças do iTangram"}', 'itg2', 'iTangram2.jar', 'ilm.line.itangram2.Tangram', 800, 600, 1, time(), $USER->id, time(), 1)),
  48. // iHanoi 3.1.0
  49. array_combine(
  50. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  51. array('iHanoi', 'http://www.matematica.br/ihanoi', '3.1.0', 'Java', '{"en":"The Objective to move N discs from stick A to C, following some rule (from the game Towers of Hanoi)","pt_br":"O objetivo é mover N discos da haste A para C, seguindo algumas regras (implementa o jogo Torres de Hanói)"}', 'ihn', 'iHanoi.jar', 'ihanoi.iHanoi', 730, 450, 1, time(), $USER->id, time(), 1)),
  52. // Risco 2
  53. array_combine(
  54. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  55. array('Risko', 'http://risko.pcc.usp.br/', '2.2.23', 'Java', '{"en":"Interactive computational tool for teaching geometry","pt_br":"Ferramenta computacional interativa para o ensino de geometria"}', 'rsk', 'Risko.jar', 'RiskoApplet.class', 800, 600, 1, time(), $USER->id, time(), 0)),
  56. // iVProgH5 0.1 - HTML5
  57. array_combine(
  58. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  59. array('iVProgH5', 'http://www.matematica.br/ivprogh5', '0.1.0', 'HTML5', '{"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}', 'ivph', 'ilm/ivprog-html/', 'main.html', 800, 600, 1, time(), $USER->id, time(), 1)),
  60. // fractions 0.1 - HTML5
  61. array_combine(
  62. array('name', 'url', 'version', 'type', 'description', 'extension', 'file_jar', 'file_class', 'width', 'height', 'enable', 'timemodified', 'author', 'timecreated', 'evaluate'),
  63. array('iFractions', 'http://www.line.ime.usp.br', '0.1.0', 'HTML5', '{"en":"Visual Interactive Fractions Learning","pt_br":"Aprendizagem visual interativa de frações"}', 'frc', 'ilm/ifractions/', 'index.html', 1000, 600, 1, time(), $USER->id, time(), 1))
  64. );
  65. $fs = get_file_storage();
  66. $is_delete = true;
  67. $context = context_system::instance();
  68. $ilm_path = $CFG->dirroot . "/mod/iassign/ilm/";
  69. foreach ($records as $record) {
  70. // Verify if there is a previous iLM (an old version that must be kept)
  71. $iassign_ilm_parent = $DB->get_record('iassign_ilm', array('name' => $record['name'], 'parent' => 0));
  72. $ilm_exists = false;
  73. if ($iassign_ilm_parent) {
  74. if ($iassign_ilm_parent->version != $record['version'])
  75. $record['parent'] = $iassign_ilm_parent->id;
  76. else
  77. $ilm_exists = true;
  78. }
  79. if (strtolower($record['type']) != 'html5') {
  80. $filenames = explode(",", $record['file_jar']); // get the JAR filename as "*.jar" or just first name if it is HTML5
  81. $file_jar = array(); // If there are several '*.jar' for this iLM
  82. // If the iLM is a set of JAR files (this was the case for iComb 0.9) get all '*.jar' files separated by ','
  83. foreach ($filenames as $filename) {
  84. if (!$ilm_exists) {
  85. $name_ilm = $record['name'];
  86. $version_ilm = $record['version'];
  87. $file_ilm = array(
  88. 'userid' => $USER->id, // ID of context
  89. 'contextid' => $context->id, // ID of context
  90. 'component' => 'mod_iassign', // usually = table name
  91. 'filearea' => 'ilm', // usually = table name (e.g, in table '*_files' all iAssign exercises will have 'filearea="exercise"')
  92. 'itemid' => 0,
  93. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($name_ilm) . '/' . iassign_utils::format_pathname($version_ilm) . '/', // any path beginning and ending in /
  94. 'filename' => $filename); // any filename
  95. //TODO iLM_HTML5 : What model to implement to HTML5?
  96. //TODO 1. The first version of iLM HTML5 in '/var/www/html/moodle/mod/iassign/ilm/ilm-nome' and others in '/var/moodledata/filedir/'?
  97. //TODO 2. Inserting new iLM HTML5 by ZIP file => explode it and register in '/var/moodledata/filedir/'?
  98. // Create file using the content: the file information is inserted in the Moodle table '*_files'
  99. // The real file will be registered in Moodle data (default '/var/moodledata/filedir/xx/yy' - 'xxyy' is the first 4 char in '*_files.contenthash')
  100. //TODO Keep this even change the model to not insert iLM HTML5 (need this object to connect with '*_iassign_ilm' bellow)
  101. $file_ilm = $fs->create_file_from_string($file_ilm, file_get_contents($ilm_path . $filename));
  102. if ($file_ilm)
  103. $is_delete &= @unlink($ilm_path . $filename);
  104. array_push($file_jar, $file_ilm->get_id()); // register the '*_files.id' for all JAR package from this iLM
  105. }
  106. else
  107. $is_delete &= @unlink($ilm_path . $filename);
  108. } // foreach ($filenames as $filename)
  109. $record['file_jar'] = implode(",", $file_jar);
  110. }
  111. if (!empty($file_jar)) {
  112. $DB->insert_record('iassign_ilm', $record, false); // insert new iLM in the table '*_iassign_ilm'
  113. }
  114. } // foreach ($records as $record)
  115. // Add iAssign button to the Atto Editor
  116. $toolbar = get_config('editor_atto', 'toolbar');
  117. if (strpos($toolbar, 'iassign') === false && $toolbar && $toolbar != '') {
  118. $groups = explode("\n", $toolbar);
  119. // Try to put iassign in the html group.
  120. $found = false;
  121. foreach ($groups as $i => $group) {
  122. $parts = explode('=', $group);
  123. if (trim($parts[0]) == 'other') {
  124. $groups[$i] = 'other = ' . trim($parts[1]) . ', iassign';
  125. $found = true;
  126. }
  127. }
  128. // if the group is not found, create the other group and insert it there
  129. // Maybe unecessary as the other group is a standard, but if the user has changed it?
  130. if (!$found) {
  131. do {
  132. $last = array_pop($groups);
  133. } while (empty($last) && !empty($groups));
  134. $groups[] = 'other = iassign';
  135. $groups[] = $last;
  136. }
  137. // Update $toolbar and add to the config
  138. $toolbar = implode("\n", $groups);
  139. set_config('toolbar', $toolbar, 'editor_atto');
  140. } // if (strpos($toolbar, 'iassign') === false && $toolbar && $toolbar != '')
  141. // end Add
  142. $is_delete &= @unlink($ilm_path . "index.*");
  143. if ($is_delete && is_dir($ilm_path))
  144. @rmdir($ilm_path);
  145. // log event -----------------------------------------------------
  146. if (class_exists('plugin_manager'))
  147. $pluginman = plugin_manager::instance();
  148. else
  149. $pluginman = core_plugin_manager::instance();
  150. $plugins = $pluginman->get_plugins();
  151. iassign_log::add_log('install', 'version: ' . $plugins['mod']['iassign']->versiondb);
  152. // log event -----------------------------------------------------
  153. }
  154. // function xmldb_iassign_install()