view.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * This php script contains all the stuff to present iAssign activity.
  4. *
  5. * @author Patricia Alves Rodrigues
  6. * @author Leo^nidas O. Branda~o
  7. * @version v 1.0 2012/10/16
  8. * @package mod_iassign
  9. * @since 2010/09/27
  10. * @copyeleft LInE (<a href="http://www.matematica.br">iMath</a>)
  11. * iMatica (<a href="http://www.usp.br/line">LInE</a>)
  12. * Computer Science Dep. of IME-USP (Brazil)
  13. *
  14. * <b>License</b>
  15. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  16. */
  17. /// About the relation Moodle/iAssign through "view.php"
  18. /// @calledby locallib.php!view_iassign_current(): onclick="submit_comment('http://.../mod/iassign/view.php?id=...')"
  19. /// @calledby locallib.php!write_comment_submission(): $return = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id="...
  20. // 1776/9739 : function add_comment () : com codigo teste invocando "generateCallTrace(.)"
  21. // 1795/9739 : $contexto = $this->generateCallTrace(); // debug_backtrace()
  22. // 3084/9739 : function view_iassign_current () : tem o codigo JS com a funcao JS "function view_iassign_current()"
  23. // onclick="submit_comment('http://localhost/saw/mod/iassign/view.php?id=26981&action=newcomment&iassign_current=6848&iassign_submission_current=35665&userid_iassign=10823&row=6&column=2')
  24. // resultado: submit_comment(url): url=http://localhost/saw/mod/iassign/view.php?id=26981&action=newcomment&iassign_current=6848&iassign_submission_current=35665&userid_iassign=10823&row=6&column=2
  25. // 3790/9739 : [JS] function submit_comment(url) :
  26. // 5610/9739 : function write_comment_submission ()
  27. require_once("../../config.php");
  28. require_once("lib.php");
  29. require_once($CFG->libdir . '/completionlib.php'); // $completion = new completion_info($course); $completion->set_module_viewed($cm);
  30. require_once($CFG->libdir . '/plagiarismlib.php');
  31. //DEBUG To be used in debug process, mainlly when 'view.php' is called by JavaScript (e.g. during send comment, call evaluation)
  32. function generateCallTrace () { //DEBUG @sse locallib.php!generateCallTrace()
  33. // $e = new Exception(); $trace = explode("\n", $e->getTraceAsString());
  34. $trace = debug_print_backtrace();
  35. // reverse array to make steps line up chronologically
  36. if (is_null($trace)) return "";
  37. $trace = array_reverse($trace);
  38. array_shift($trace); // remove {main}
  39. array_pop($trace); // remove call to this method
  40. $length = count($trace);
  41. $result = array();
  42. for ($i = 0; $i < $length; $i++) {
  43. $result[] = ($i + 1) . ')' . substr($trace[$i], strpos($trace[$i], ' ')); // replace '#someNum' with '$i)', set the right ordering
  44. }
  45. return "\t" . implode("\n\t", $result);
  46. }
  47. //DEBUG To trace "view.php" called by JavaScript (e.g. when teacher/nonediting teacher send comment, student calls evaluation)
  48. //DEBUG can use generateCallTrace() to write into "ilm_debug/" throught "ilm_debug/escreva.php".
  49. //DEBUG echo "<pre>generateCallTrace(): " . generateCallTrace() . "</pre><br/>\n"; exit;
  50. //D require_once("ilm_debug/escreva.php");
  51. //D $resp = writeContent("", "", "todos_files_iassign.txt", "Teste"); // ($filetype1, $pathbase, $outputFile, $msgToRegister) //leo REMOVER!
  52. //DEBUG To debug problems with Moodle FileSystem
  53. function get_all_iassign_files () {
  54. // Get all iAssign files on table 'files':
  55. // files = id; contenthash; pathnamehash; contextid; component; filearea; itemid; filepath; filename; userid; filesize; mimetype; status; source; author;
  56. // license; timecreated; timemodified; sortorder; referencefileid
  57. global $DB;
  58. // $all_files = $DB->get_records('files', array('component' => 'mod_iassign')); // pegar os do iAssign
  59. $indices = "id=257279 OR id=257791 OR id=258303 OR id=258559 OR id=127743 OR id=64767 OR id=65023 OR id= 65535 OR id= 87394 OR " .
  60. "id=138498 OR id=138506 OR id=138514 OR id=138522 OR id=50463 OR id=50464 OR id= 50465 OR id=138530 OR id= 50466 OR " .
  61. "id= 50467 OR id= 50468 OR id= 50469 OR id=50470 OR id=50471 OR id=104744 OR id=50472";
  62. $str_query = "SELECT id,contextid,filearea,itemid,filepath,filename,userid,author,timecreated FROM {files}\n" .
  63. "WHERE " . $indices . " ORDER BY timecreated DESC";
  64. $all_files = $DB->get_records_sql($str_query);
  65. $total = count($all_files);
  66. $msg = $str_query . "\n#linhas = " . $total . "\n";
  67. foreach ($all_files as $linha) {
  68. foreach ($linha as $key => $value) {
  69. if ($key == "timecreated") {
  70. $time1 = date('Y-m-d H:i:s', $value - date('Z')); // 12:50:29
  71. $msg .= $time1 . ";" . $value . ";";
  72. }
  73. else
  74. if ($key == "source") {
  75. // $item = str_replace(";", "\;", $value);
  76. $item = addslashes($value);
  77. $msg .= "'" . addslashes($value) . "';";
  78. }
  79. else $msg .= $value . ";";
  80. }
  81. $msg .= "\n";
  82. }
  83. require_once("ilm_debug/escreva.php"); //leo REMOVER! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  84. $resp = writeContent("", "", "todos_files_iassign.csv", $msg); // ($filetype1, $pathbase, $outputFile, $msgToRegister) //leo REMOVER!
  85. }
  86. //D get_all_iassign_files(); //REMOVER
  87. //D get_all_iassign_files(); //leo REMOVER! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  88. //D Remover todos itens de 'files' tal que: filesize = 0
  89. // Parameters GET and POST
  90. $id = optional_param('id', 0, PARAM_INT); // Course Module ID
  91. $a = optional_param('a', 0, PARAM_INT); // iAssign instance id (from table 'iassign')
  92. $mood_url = new moodle_url('/mod/iassign/view.php');
  93. if ($id) {
  94. // ./lib/datalib.php : function get_coursemodule_from_id($modulename, $cmid, $courseid=0, $sectionnum=false, $strictness=IGNORE_MISSING): returns 'course_modules.*' and 'modules.name'
  95. $cm = get_coursemodule_from_id('iassign', $id);
  96. if (!$cm) { // Moodle function 'get_coursemodule_from_id(...)' returns the object from table '*_iassign_statement'
  97. print_error('invalidcoursemodule');
  98. }
  99. $iassign = $DB->get_record("iassign", array("id" => $cm->instance));
  100. if (!$iassign) { // 'course_modules.instance = iassign.id'
  101. print_error('invalidid', 'iassign');
  102. }
  103. $course = $DB->get_record("course", array("id" => $iassign->course));
  104. if (!$course) {
  105. print_error('coursemisconf', 'iassign');
  106. }
  107. $mood_url->param('id', $id);
  108. }
  109. else {
  110. if (!$a) { // try with 'iassign_current'
  111. $iassign_current = optional_param('iassign_current', 0, PARAM_INT);
  112. if ($iassign_current) { // use {iassign_statement}.id to get {iassign}.id
  113. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_current));
  114. $a = $iassign_statement->iassignid;
  115. }
  116. }
  117. $iassign = $DB->get_record("iassign", array("id" => $a));
  118. if (!$iassign) {
  119. print_error('invalidid', 'iassign');
  120. }
  121. $course = $DB->get_record("course", array("id" => $iassign->course));
  122. if (!$course) {
  123. print_error('coursemisconf', 'iassign');
  124. }
  125. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $course->id);
  126. if (!$cm) {
  127. print_error('invalidcoursemodule');
  128. }
  129. $mood_url->param('a', $a);
  130. }
  131. $PAGE->set_url($mood_url);
  132. require_login($course, true, $cm);
  133. $PAGE->set_title(format_string($iassign->name));
  134. $PAGE->set_heading($course->fullname);
  135. // About each object/table
  136. // - $iassing :: object from table '*_iassign_statement'
  137. // - $cm :: object from table '*_course_modules'
  138. // - $course :: object from table '*_course_modules_completion'
  139. // Marks a module as viewed, i.e., register in {course_modules_completion} the current {course_modules}.id and {user}.id
  140. // It is necessary: "$CFG->enablecompletion = 1" in "./config.php"
  141. // With "$CFG->enablecompletion = 1" in "config.php" it is possible to set item "Completion tracking" in ./course/edit.php?id=X
  142. // {course} must have 'enablecompletion = 1'
  143. $completion = new completion_info($course);
  144. $completion->set_module_viewed($cm, $USER->id); // ./lib/completionlib.php : set_module_viewed($cm, $userid=0)
  145. // ./lib/completionlib.php : see this
  146. // - public function set_module_viewed($cm, $userid=0): 715/1372 - need {course_modules}.completionview == 1
  147. // cm->completionview=1, COMPLETION_VIEW_NOT_REQUIRED=0, this->is_enabled(cm)=0
  148. // if ($cm->completionview == COMPLETION_VIEW_NOT_REQUIRED || !$this->is_enabled($cm)) return;
  149. // $this->update_state($cm, COMPLETION_COMPLETE, $userid);
  150. // - public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0, $override = false) : 565/1374
  151. // $this->internal_set_data($cm, $current);
  152. // - public function internal_set_data($cm, $data) : 1039/1372
  153. // $event->add_record_snapshot('course_modules_completion', $data);
  154. // - public function is_enabled($cm = null): 279/1374 -- Checks whether completion is enabled in a particular course and possibly activity
  155. // $CFG->enablecompletion, $CFG->enablecompletion != COMPLETION_DISABLED
  156. // $this->course->enablecompletion != COMPLETION_DISABLED == 0 ; COMPLETION_ENABLED == 1
  157. $write_solution = 1;
  158. // ./mod/iassign/locallib.php : class iassign : function __construct ($iassign, $cm, $course)
  159. //$iassigninstance = new iassign($iassign, $cm, $course, array('write_solution' => 1));
  160. $iassigninstance = new iassign($iassign, $cm, $course); // this will provide read iLM content
  161. // ./mod/iassign/locallib.php : in class iassign, actually who display the iAssign whose id is '$id'! (this function ignores parameters)
  162. $iassigninstance->view(); // will call $this->action(), that calls view_iassign_current()