PageRenderTime 27ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/quiz/restorelib.php

https://github.com/manoj240375/moodle_edify
PHP | 212 lines | 178 code | 4 blank | 30 comment | 36 complexity | b3b94bb58549175fced978902cf6aef7 MD5 | raw file
  1. <?php
  2. //This function returns a log record with all the necessary transformations
  3. //done. It's used by restore_log_module() to restore modules log.
  4. function quiz_restore_logs($restore,$log) {
  5. $status = false;
  6. //Depending of the action, we recode different things
  7. switch ($log->action) {
  8. case "add":
  9. if ($log->cmid) {
  10. //Get the new_id of the module (to recode the info field)
  11. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  12. if ($mod) {
  13. $log->url = "view.php?id=".$log->cmid;
  14. $log->info = $mod->new_id;
  15. $status = true;
  16. }
  17. }
  18. break;
  19. case "update":
  20. if ($log->cmid) {
  21. //Get the new_id of the module (to recode the info field)
  22. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  23. if ($mod) {
  24. $log->url = "view.php?id=".$log->cmid;
  25. $log->info = $mod->new_id;
  26. $status = true;
  27. }
  28. }
  29. break;
  30. case "view":
  31. if ($log->cmid) {
  32. //Get the new_id of the module (to recode the info field)
  33. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  34. if ($mod) {
  35. $log->url = "view.php?id=".$log->cmid;
  36. $log->info = $mod->new_id;
  37. $status = true;
  38. }
  39. }
  40. break;
  41. case "view all":
  42. $log->url = "index.php?id=".$log->course;
  43. $status = true;
  44. break;
  45. case "report":
  46. if ($log->cmid) {
  47. //Get the new_id of the module (to recode the info field)
  48. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  49. if ($mod) {
  50. $log->url = "report.php?id=".$log->cmid;
  51. $log->info = $mod->new_id;
  52. $status = true;
  53. }
  54. }
  55. break;
  56. case "attempt":
  57. if ($log->cmid) {
  58. //Get the new_id of the module (to recode the info field)
  59. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  60. if ($mod) {
  61. //Extract the attempt id from the url field
  62. $attid = substr(strrchr($log->url,"="),1);
  63. //Get the new_id of the attempt (to recode the url field)
  64. $att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
  65. if ($att) {
  66. $log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
  67. $log->info = $mod->new_id;
  68. $status = true;
  69. }
  70. }
  71. }
  72. break;
  73. case "submit":
  74. if ($log->cmid) {
  75. //Get the new_id of the module (to recode the info field)
  76. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  77. if ($mod) {
  78. //Extract the attempt id from the url field
  79. $attid = substr(strrchr($log->url,"="),1);
  80. //Get the new_id of the attempt (to recode the url field)
  81. $att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
  82. if ($att) {
  83. $log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
  84. $log->info = $mod->new_id;
  85. $status = true;
  86. }
  87. }
  88. }
  89. break;
  90. case "review":
  91. if ($log->cmid) {
  92. //Get the new_id of the module (to recode the info field)
  93. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  94. if ($mod) {
  95. //Extract the attempt id from the url field
  96. $attid = substr(strrchr($log->url,"="),1);
  97. //Get the new_id of the attempt (to recode the url field)
  98. $att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
  99. if ($att) {
  100. $log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
  101. $log->info = $mod->new_id;
  102. $status = true;
  103. }
  104. }
  105. }
  106. break;
  107. case "editquestions":
  108. if ($log->cmid) {
  109. //Get the new_id of the module (to recode the url field)
  110. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  111. if ($mod) {
  112. $log->url = "view.php?id=".$log->cmid;
  113. $log->info = $mod->new_id;
  114. $status = true;
  115. }
  116. }
  117. break;
  118. case "preview":
  119. if ($log->cmid) {
  120. //Get the new_id of the module (to recode the url field)
  121. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  122. if ($mod) {
  123. $log->url = "attempt.php?id=".$log->cmid;
  124. $log->info = $mod->new_id;
  125. $status = true;
  126. }
  127. }
  128. break;
  129. case "start attempt":
  130. if ($log->cmid) {
  131. //Get the new_id of the module (to recode the info field)
  132. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  133. if ($mod) {
  134. //Extract the attempt id from the url field
  135. $attid = substr(strrchr($log->url,"="),1);
  136. //Get the new_id of the attempt (to recode the url field)
  137. $att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
  138. if ($att) {
  139. $log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
  140. $log->info = $mod->new_id;
  141. $status = true;
  142. }
  143. }
  144. }
  145. break;
  146. case "close attempt":
  147. if ($log->cmid) {
  148. //Get the new_id of the module (to recode the info field)
  149. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  150. if ($mod) {
  151. //Extract the attempt id from the url field
  152. $attid = substr(strrchr($log->url,"="),1);
  153. //Get the new_id of the attempt (to recode the url field)
  154. $att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
  155. if ($att) {
  156. $log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
  157. $log->info = $mod->new_id;
  158. $status = true;
  159. }
  160. }
  161. }
  162. break;
  163. case "continue attempt":
  164. if ($log->cmid) {
  165. //Get the new_id of the module (to recode the info field)
  166. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  167. if ($mod) {
  168. //Extract the attempt id from the url field
  169. $attid = substr(strrchr($log->url,"="),1);
  170. //Get the new_id of the attempt (to recode the url field)
  171. $att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
  172. if ($att) {
  173. $log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
  174. $log->info = $mod->new_id;
  175. $status = true;
  176. }
  177. }
  178. }
  179. break;
  180. case "continue attemp":
  181. if ($log->cmid) {
  182. //Get the new_id of the module (to recode the info field)
  183. $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
  184. if ($mod) {
  185. //Extract the attempt id from the url field
  186. $attid = substr(strrchr($log->url,"="),1);
  187. //Get the new_id of the attempt (to recode the url field)
  188. $att = backup_getid($restore->backup_unique_code,"quiz_attempts",$attid);
  189. if ($att) {
  190. $log->url = "review.php?id=".$log->cmid."&attempt=".$att->new_id;
  191. $log->info = $mod->new_id;
  192. $log->action = "continue attempt"; //To recover some bad actions
  193. $status = true;
  194. }
  195. }
  196. }
  197. break;
  198. default:
  199. if (!defined('RESTORE_SILENTLY')) {
  200. echo "action (".$log->module."-".$log->action.") unknown. Not restored<br />"; //Debug
  201. }
  202. break;
  203. }
  204. if ($status) {
  205. $status = $log;
  206. }
  207. return $status;
  208. }