PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/backup/util/ui/renderer.php

https://bitbucket.org/kudutest1/moodlegit
PHP | 726 lines | 480 code | 63 blank | 183 comment | 54 complexity | cec9af509f616efdf4c0d04efffa0ec6 MD5 | raw file
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * This file contains backup and restore output renderers
  18. *
  19. * @package moodlecore
  20. * @copyright 2010 Sam Hemelryk
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. /**
  24. * The primary renderer for the backup.
  25. *
  26. * Can be retrieved with the following code:
  27. * <?php
  28. * $renderer = $PAGE->get_renderer('core','backup');
  29. * ?>
  30. *
  31. * @copyright 2010 Sam Hemelryk
  32. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33. */
  34. class core_backup_renderer extends plugin_renderer_base {
  35. /**
  36. * Renderers a progress bar for the backup or restore given the items that
  37. * make it up.
  38. * @param array $items An array of items
  39. * @return string
  40. */
  41. public function progress_bar(array $items) {
  42. foreach ($items as &$item) {
  43. $text = $item['text'];
  44. unset($item['text']);
  45. if (array_key_exists('link', $item)) {
  46. $link = $item['link'];
  47. unset($item['link']);
  48. $item = html_writer::link($link, $text, $item);
  49. } else {
  50. $item = html_writer::tag('span', $text, $item);
  51. }
  52. }
  53. return html_writer::tag('div', join(get_separator(), $items), array('class'=>'backup_progress clearfix'));
  54. }
  55. /**
  56. * Prints a dependency notification
  57. * @param string $message
  58. * @return string
  59. */
  60. public function dependency_notification($message) {
  61. return html_writer::tag('div', $message, array('class'=>'notification dependencies_enforced'));
  62. }
  63. /**
  64. * Displays the details of a backup file
  65. *
  66. * @param stdClass $details
  67. * @param moodle_url $nextstageurl
  68. * @return string
  69. */
  70. public function backup_details($details, $nextstageurl) {
  71. $yestick = $this->output->pix_icon('i/valid', get_string('yes'));
  72. $notick = $this->output->pix_icon('i/valid', get_string('no'));
  73. $html = html_writer::start_tag('div', array('class'=>'backup-restore'));
  74. $html .= html_writer::start_tag('div', array('class'=>'backup-section'));
  75. $html .= $this->output->heading(get_string('backupdetails', 'backup'), 2, array('class'=>'header'));
  76. $html .= $this->backup_detail_pair(get_string('backuptype', 'backup'), get_string('backuptype'.$details->type, 'backup'));
  77. $html .= $this->backup_detail_pair(get_string('backupformat', 'backup'), get_string('backupformat'.$details->format, 'backup'));
  78. $html .= $this->backup_detail_pair(get_string('backupmode', 'backup'), get_string('backupmode'.$details->mode, 'backup'));
  79. $html .= $this->backup_detail_pair(get_string('backupdate', 'backup'), userdate($details->backup_date));
  80. $html .= $this->backup_detail_pair(get_string('moodleversion', 'backup'),
  81. html_writer::tag('span', $details->moodle_release, array('class'=>'moodle_release')).
  82. html_writer::tag('span', '['.$details->moodle_version.']', array('class'=>'moodle_version sub-detail')));
  83. $html .= $this->backup_detail_pair(get_string('backupversion', 'backup'),
  84. html_writer::tag('span', $details->backup_release, array('class'=>'moodle_release')).
  85. html_writer::tag('span', '['.$details->backup_version.']', array('class'=>'moodle_version sub-detail')));
  86. $html .= $this->backup_detail_pair(get_string('originalwwwroot', 'backup'),
  87. html_writer::tag('span', $details->original_wwwroot, array('class'=>'originalwwwroot')).
  88. html_writer::tag('span', '['.$details->original_site_identifier_hash.']', array('class'=>'sitehash sub-detail')));
  89. if (!empty($details->include_file_references_to_external_content)) {
  90. $message = '';
  91. if (backup_general_helper::backup_is_samesite($details)) {
  92. $message = $yestick . ' ' . get_string('filereferencessamesite', 'backup');
  93. } else {
  94. $message = $notick . ' ' . get_string('filereferencesnotsamesite', 'backup');
  95. }
  96. $html .= $this->backup_detail_pair(get_string('includefilereferences', 'backup'), $message);
  97. }
  98. $html .= html_writer::end_tag('div');
  99. $html .= html_writer::start_tag('div', array('class'=>'backup-section settings-section'));
  100. $html .= $this->output->heading(get_string('backupsettings', 'backup'), 2, array('class'=>'header'));
  101. foreach ($details->root_settings as $label=>$value) {
  102. if ($label == 'filename' or $label == 'user_files') {
  103. continue;
  104. }
  105. $html .= $this->backup_detail_pair(get_string('rootsetting'.str_replace('_','',$label), 'backup'), $value?$yestick:$notick);
  106. }
  107. $html .= html_writer::end_tag('div');
  108. if ($details->type === 'course') {
  109. $html .= html_writer::start_tag('div', array('class'=>'backup-section'));
  110. $html .= $this->output->heading(get_string('backupcoursedetails', 'backup'), 2, array('class'=>'header'));
  111. $html .= $this->backup_detail_pair(get_string('coursetitle', 'backup'), $details->course->title);
  112. $html .= $this->backup_detail_pair(get_string('courseid', 'backup'), $details->course->courseid);
  113. $html .= html_writer::start_tag('div', array('class'=>'backup-sub-section'));
  114. $html .= $this->output->heading(get_string('backupcoursesections', 'backup'), 3, array('class'=>'subheader'));
  115. foreach ($details->sections as $key=>$section) {
  116. $included = $key.'_included';
  117. $userinfo = $key.'_userinfo';
  118. if ($section->settings[$included] && $section->settings[$userinfo]) {
  119. $value = get_string('sectionincanduser','backup');
  120. } else if ($section->settings[$included]) {
  121. $value = get_string('sectioninc','backup');
  122. } else {
  123. continue;
  124. }
  125. $html .= $this->backup_detail_pair(get_string('backupcoursesection', 'backup', $section->title), $value);
  126. $table = null;
  127. foreach ($details->activities as $activitykey=>$activity) {
  128. if ($activity->sectionid != $section->sectionid) {
  129. continue;
  130. }
  131. if (empty($table)) {
  132. $table = new html_table();
  133. $table->head = array('Module', 'Title', 'Userinfo');
  134. $table->colclasses = array('modulename', 'moduletitle', 'userinfoincluded');
  135. $table->align = array('left','left', 'center');
  136. $table->attributes = array('class'=>'activitytable generaltable');
  137. $table->data = array();
  138. }
  139. $name = get_string('pluginname', $activity->modulename);
  140. $icon = new pix_icon('icon', $name, $activity->modulename, array('class' => 'iconlarge icon-pre'));
  141. $table->data[] = array(
  142. $this->output->render($icon).$name,
  143. $activity->title,
  144. ($activity->settings[$activitykey.'_userinfo'])?$yestick:$notick,
  145. );
  146. }
  147. if (!empty($table)) {
  148. $html .= $this->backup_detail_pair(get_string('sectionactivities','backup'), html_writer::table($table));
  149. }
  150. }
  151. $html .= html_writer::end_tag('div');
  152. $html .= html_writer::end_tag('div');
  153. }
  154. $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
  155. $html .= html_writer::end_tag('div');
  156. return $html;
  157. }
  158. /**
  159. * Displays the general information about a backup file with non-standard format
  160. *
  161. * @param moodle_url $nextstageurl URL to send user to
  162. * @param array $details basic info about the file (format, type)
  163. * @return string HTML code to display
  164. */
  165. public function backup_details_nonstandard($nextstageurl, array $details) {
  166. $html = html_writer::start_tag('div', array('class' => 'backup-restore nonstandardformat'));
  167. $html .= html_writer::start_tag('div', array('class' => 'backup-section'));
  168. $html .= $this->output->heading(get_string('backupdetails', 'backup'), 2, 'header');
  169. $html .= $this->output->box(get_string('backupdetailsnonstandardinfo', 'backup'), 'noticebox');
  170. $html .= $this->backup_detail_pair(
  171. get_string('backupformat', 'backup'),
  172. get_string('backupformat'.$details['format'], 'backup'));
  173. $html .= $this->backup_detail_pair(
  174. get_string('backuptype', 'backup'),
  175. get_string('backuptype'.$details['type'], 'backup'));
  176. $html .= html_writer::end_tag('div');
  177. $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
  178. $html .= html_writer::end_tag('div');
  179. return $html;
  180. }
  181. /**
  182. * Displays the general information about a backup file with unknown format
  183. *
  184. * @param moodle_url $nextstageurl URL to send user to
  185. * @return string HTML code to display
  186. */
  187. public function backup_details_unknown(moodle_url $nextstageurl) {
  188. $html = html_writer::start_tag('div', array('class' => 'unknownformat'));
  189. $html .= $this->output->heading(get_string('errorinvalidformat', 'backup'), 2, 'notifyproblem');
  190. $html .= html_writer::tag('div', get_string('errorinvalidformatinfo', 'backup'), array('class' => 'notifyproblem'));
  191. $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
  192. $html .= html_writer::end_tag('div');
  193. return $html;
  194. }
  195. /**
  196. * Displays a course selector for restore
  197. *
  198. * @param moodle_url $nextstageurl
  199. * @param bool $wholecourse true if we are restoring whole course (as with backup::TYPE_1COURSE), false otherwise
  200. * @param restore_category_search $categories
  201. * @param restore_course_search $courses
  202. * @param int $currentcourse
  203. * @return string
  204. */
  205. public function course_selector(moodle_url $nextstageurl, $wholecourse = true, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) {
  206. global $CFG, $PAGE;
  207. require_once($CFG->dirroot.'/course/lib.php');
  208. $nextstageurl->param('sesskey', sesskey());
  209. $form = html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring()));
  210. foreach ($nextstageurl->params() as $key=>$value) {
  211. $form .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
  212. }
  213. $hasrestoreoption = false;
  214. $html = html_writer::start_tag('div', array('class'=>'backup-course-selector backup-restore'));
  215. if ($wholecourse && !empty($categories) && ($categories->get_count() > 0 || $categories->get_search())) {
  216. // New course
  217. $hasrestoreoption = true;
  218. $html .= $form;
  219. $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section'));
  220. $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
  221. $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
  222. $html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories));
  223. $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
  224. $html .= html_writer::end_tag('div');
  225. $html .= html_writer::end_tag('form');
  226. }
  227. if ($wholecourse && !empty($currentcourse)) {
  228. // Current course
  229. $hasrestoreoption = true;
  230. $html .= $form;
  231. $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'targetid', 'value'=>$currentcourse));
  232. $html .= html_writer::start_tag('div', array('class'=>'bcs-current-course backup-section'));
  233. $html .= $this->output->heading(get_string('restoretocurrentcourse', 'backup'), 2, array('class'=>'header'));
  234. $html .= $this->backup_detail_input(get_string('restoretocurrentcourseadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked'));
  235. $html .= $this->backup_detail_input(get_string('restoretocurrentcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING);
  236. $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
  237. $html .= html_writer::end_tag('div');
  238. $html .= html_writer::end_tag('form');
  239. }
  240. if (!empty($courses) && ($courses->get_count() > 0 || $courses->get_search())) {
  241. // Existing course
  242. $hasrestoreoption = true;
  243. $html .= $form;
  244. $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section'));
  245. $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header'));
  246. if ($wholecourse) {
  247. $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked'));
  248. $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
  249. $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
  250. } else {
  251. // We only allow restore adding to existing for now. Enforce it here.
  252. $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'target', 'value'=>backup::TARGET_EXISTING_ADDING));
  253. $courses->invalidate_results(); // Clean list of courses
  254. $courses->set_include_currentcourse(); // Show current course in the list
  255. $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
  256. }
  257. $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
  258. $html .= html_writer::end_tag('div');
  259. $html .= html_writer::end_tag('form');
  260. }
  261. if (!$hasrestoreoption) {
  262. echo $this->output->notification(get_string('norestoreoptions','backup'));
  263. }
  264. $html .= html_writer::end_tag('div');
  265. return $html;
  266. }
  267. /**
  268. * Displays the import course selector
  269. *
  270. * @param moodle_url $nextstageurl
  271. * @param import_course_search $courses
  272. * @return string
  273. */
  274. public function import_course_selector(moodle_url $nextstageurl, import_course_search $courses=null) {
  275. $html = html_writer::start_tag('div', array('class'=>'import-course-selector backup-restore'));
  276. $html .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring()));
  277. foreach ($nextstageurl->params() as $key=>$value) {
  278. $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
  279. }
  280. // We only allow import adding for now. Enforce it here.
  281. $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'target', 'value'=>backup::TARGET_CURRENT_ADDING));
  282. $html .= html_writer::start_tag('div', array('class'=>'ics-existing-course backup-section'));
  283. $html .= $this->output->heading(get_string('importdatafrom'), 2, array('class'=>'header'));
  284. $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
  285. $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
  286. $html .= html_writer::end_tag('div');
  287. $html .= html_writer::end_tag('form');
  288. $html .= html_writer::end_tag('div');
  289. return $html;
  290. }
  291. /**
  292. * Creates a detailed pairing (key + value)
  293. *
  294. * @staticvar int $count
  295. * @param string $label
  296. * @param string $value
  297. * @return string
  298. */
  299. protected function backup_detail_pair($label, $value) {
  300. static $count= 0;
  301. $count++;
  302. $html = html_writer::start_tag('div', array('class'=>'detail-pair'));
  303. $html .= html_writer::tag('label', $label, array('class'=>'detail-pair-label', 'for'=>'detail-pair-value-'.$count));
  304. $html .= html_writer::tag('div', $value, array('class'=>'detail-pair-value', 'name'=>'detail-pair-value-'.$count));
  305. $html .= html_writer::end_tag('div');
  306. return $html;
  307. }
  308. /**
  309. * Created a detailed pairing with an input
  310. *
  311. * @param string $label
  312. * @param string $type
  313. * @param string $name
  314. * @param string $value
  315. * @param array $attributes
  316. * @param string|null $description
  317. * @return string
  318. */
  319. protected function backup_detail_input($label, $type, $name, $value, array $attributes=array(), $description=null) {
  320. if (!empty ($description)) {
  321. $description = html_writer::tag('span', $description, array('class'=>'description'));
  322. } else {
  323. $description = '';
  324. }
  325. return $this->backup_detail_pair($label, html_writer::empty_tag('input', $attributes+array('name'=>$name, 'type'=>$type, 'value'=>$value)).$description);
  326. }
  327. /**
  328. * Creates a detailed pairing with a select
  329. *
  330. * @param string $label
  331. * @param string $name
  332. * @param array $options
  333. * @param string $selected
  334. * @param bool $nothing
  335. * @param array $attributes
  336. * @param string|null $description
  337. * @return string
  338. */
  339. protected function backup_detail_select($label, $name, $options, $selected='', $nothing=false, array $attributes=array(), $description=null) {
  340. if (!empty ($description)) {
  341. $description = html_writer::tag('span', $description, array('class'=>'description'));
  342. } else {
  343. $description = '';
  344. }
  345. return $this->backup_detail_pair($label, html_writer::select($options, $name, $selected, false, $attributes).$description);
  346. }
  347. /**
  348. * Displays precheck notices
  349. *
  350. * @param array $results
  351. * @return string
  352. */
  353. public function precheck_notices($results) {
  354. $output = html_writer::start_tag('div', array('class'=>'restore-precheck-notices'));
  355. if (array_key_exists('errors', $results)) {
  356. foreach ($results['errors'] as $error) {
  357. $output .= $this->output->notification($error);
  358. }
  359. }
  360. if (array_key_exists('warnings', $results)) {
  361. foreach ($results['warnings'] as $warning) {
  362. $output .= $this->output->notification($warning, 'notifywarning notifyproblem');
  363. }
  364. }
  365. return $output.html_writer::end_tag('div');
  366. }
  367. /**
  368. * Displays substage buttons
  369. *
  370. * @param bool $haserrors
  371. * @return string
  372. */
  373. public function substage_buttons($haserrors) {
  374. $output = html_writer::start_tag('div', array('continuebutton'));
  375. if (!$haserrors) {
  376. $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')));
  377. }
  378. $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel')));
  379. $output .= html_writer::end_tag('div');
  380. return $output;
  381. }
  382. /**
  383. * Displays a role mapping interface
  384. *
  385. * @param array $rolemappings
  386. * @param array $roles
  387. * @return string
  388. */
  389. public function role_mappings($rolemappings, $roles) {
  390. $roles[0] = get_string('none');
  391. $output = html_writer::start_tag('div', array('class'=>'restore-rolemappings'));
  392. $output .= $this->output->heading(get_string('restorerolemappings', 'backup'), 2);
  393. foreach ($rolemappings as $id=>$mapping) {
  394. $label = $mapping->name;
  395. $name = 'mapping'.$id;
  396. $selected = $mapping->targetroleid;
  397. $output .= $this->backup_detail_select($label, $name, $roles, $mapping->targetroleid, false, array(), $mapping->description);
  398. }
  399. $output .= html_writer::end_tag('div');
  400. return $output;
  401. }
  402. /**
  403. * Displays a continue button
  404. *
  405. * @param string|moodle_url $url
  406. * @param string $method
  407. * @return string
  408. */
  409. public function continue_button($url, $method='post') {
  410. if (!($url instanceof moodle_url)) {
  411. $url = new moodle_url($url);
  412. }
  413. if ($method != 'post') {
  414. $method = 'get';
  415. }
  416. $url->param('sesskey', sesskey());
  417. $button = new single_button($url, get_string('continue'), $method);
  418. $button->class = 'continuebutton';
  419. return $this->render($button);
  420. }
  421. /**
  422. * Print a backup files tree
  423. * @param array $options
  424. * @return string
  425. */
  426. public function backup_files_viewer(array $options = null) {
  427. $files = new backup_files_viewer($options);
  428. return $this->render($files);
  429. }
  430. /**
  431. * Displays a backup files viewer
  432. *
  433. * @global stdClass $USER
  434. * @param backup_files_viewer $tree
  435. * @return string
  436. */
  437. public function render_backup_files_viewer(backup_files_viewer $viewer) {
  438. global $CFG;
  439. $files = $viewer->files;
  440. $table = new html_table();
  441. $table->attributes['class'] = 'backup-files-table generaltable';
  442. $table->head = array(get_string('filename', 'backup'), get_string('time'), get_string('size'), get_string('download'), get_string('restore'));
  443. $table->width = '100%';
  444. $table->data = array();
  445. foreach ($files as $file) {
  446. if ($file->is_directory()) {
  447. continue;
  448. }
  449. $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename(), true);
  450. $params = array();
  451. $params['action'] = 'choosebackupfile';
  452. $params['filename'] = $file->get_filename();
  453. $params['filepath'] = $file->get_filepath();
  454. $params['component'] = $file->get_component();
  455. $params['filearea'] = $file->get_filearea();
  456. $params['filecontextid'] = $file->get_contextid();
  457. $params['contextid'] = $viewer->currentcontext->id;
  458. $params['itemid'] = $file->get_itemid();
  459. $restoreurl = new moodle_url('/backup/restorefile.php', $params);
  460. $table->data[] = array(
  461. $file->get_filename(),
  462. userdate($file->get_timemodified()),
  463. display_size($file->get_filesize()),
  464. html_writer::link($fileurl, get_string('download')),
  465. html_writer::link($restoreurl, get_string('restore')),
  466. );
  467. }
  468. $html = html_writer::table($table);
  469. $html .= $this->output->single_button(new moodle_url('/backup/backupfilesedit.php', array('currentcontext'=>$viewer->currentcontext->id, 'contextid'=>$viewer->filecontext->id, 'filearea'=>$viewer->filearea, 'component'=>$viewer->component, 'returnurl'=>$this->page->url->out())), get_string('managefiles', 'backup'), 'post');
  470. return $html;
  471. }
  472. /**
  473. * Renders a restore course search object
  474. *
  475. * @param restore_course_search $component
  476. * @return string
  477. */
  478. public function render_restore_course_search(restore_course_search $component) {
  479. $url = $component->get_url();
  480. $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
  481. $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
  482. $table = new html_table();
  483. $table->head = array('', get_string('shortnamecourse'), get_string('fullnamecourse'));
  484. $table->data = array();
  485. if ($component->get_count() !== 0) {
  486. foreach ($component->get_results() as $course) {
  487. $row = new html_table_row();
  488. $row->attributes['class'] = 'rcs-course';
  489. if (!$course->visible) {
  490. $row->attributes['class'] .= ' dimmed';
  491. }
  492. $row->cells = array(
  493. html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$course->id)),
  494. format_string($course->shortname, true, array('context' => context_course::instance($course->id))),
  495. format_string($course->fullname, true, array('context' => context_course::instance($course->id)))
  496. );
  497. $table->data[] = $row;
  498. }
  499. if ($component->has_more_results()) {
  500. $cell = new html_table_cell(get_string('moreresults', 'backup'));
  501. $cell->colspan = 3;
  502. $cell->attributes['class'] = 'notifyproblem';
  503. $row = new html_table_row(array($cell));
  504. $row->attributes['class'] = 'rcs-course';
  505. $table->data[] = $row;
  506. }
  507. } else {
  508. $cell = new html_table_cell(get_string('nomatchingcourses', 'backup'));
  509. $cell->colspan = 3;
  510. $cell->attributes['class'] = 'notifyproblem';
  511. $row = new html_table_row(array($cell));
  512. $row->attributes['class'] = 'rcs-course';
  513. $table->data[] = $row;
  514. }
  515. $output .= html_writer::table($table);
  516. $output .= html_writer::end_tag('div');
  517. $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
  518. $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
  519. $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
  520. $output .= html_writer::end_tag('div');
  521. $output .= html_writer::end_tag('div');
  522. return $output;
  523. }
  524. /**
  525. * Renders an import course search object
  526. *
  527. * @param import_course_search $component
  528. * @return string
  529. */
  530. public function render_import_course_search(import_course_search $component) {
  531. $url = $component->get_url();
  532. $output = html_writer::start_tag('div', array('class' => 'import-course-search'));
  533. if ($component->get_count() === 0) {
  534. $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
  535. $output .= html_writer::start_tag('div', array('class'=>'ics-search'));
  536. $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
  537. $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
  538. $output .= html_writer::end_tag('div');
  539. $output .= html_writer::end_tag('div');
  540. return $output;
  541. }
  542. $countstr = '';
  543. if ($component->has_more_results()) {
  544. $countstr = get_string('morecoursesearchresults', 'backup', $component->get_count());
  545. } else {
  546. $countstr = get_string('totalcoursesearchresults', 'backup', $component->get_count());
  547. }
  548. $output .= html_writer::tag('div', $countstr, array('class'=>'ics-totalresults'));
  549. $output .= html_writer::start_tag('div', array('class' => 'ics-results'));
  550. $table = new html_table();
  551. $table->head = array('', get_string('shortnamecourse'), get_string('fullnamecourse'));
  552. $table->data = array();
  553. foreach ($component->get_results() as $course) {
  554. $row = new html_table_row();
  555. $row->attributes['class'] = 'ics-course';
  556. if (!$course->visible) {
  557. $row->attributes['class'] .= ' dimmed';
  558. }
  559. $row->cells = array(
  560. html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'importid', 'value'=>$course->id)),
  561. format_string($course->shortname, true, array('context' => context_course::instance($course->id))),
  562. format_string($course->fullname, true, array('context' => context_course::instance($course->id)))
  563. );
  564. $table->data[] = $row;
  565. }
  566. if ($component->has_more_results()) {
  567. $cell = new html_table_cell(get_string('moreresults', 'backup'));
  568. $cell->colspan = 3;
  569. $cell->attributes['class'] = 'notifyproblem';
  570. $row = new html_table_row(array($cell));
  571. $row->attributes['class'] = 'rcs-course';
  572. $table->data[] = $row;
  573. }
  574. $output .= html_writer::table($table);
  575. $output .= html_writer::end_tag('div');
  576. $output .= html_writer::start_tag('div', array('class'=>'ics-search'));
  577. $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
  578. $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
  579. $output .= html_writer::end_tag('div');
  580. $output .= html_writer::end_tag('div');
  581. return $output;
  582. }
  583. /**
  584. * Renders a restore category search object
  585. *
  586. * @param restore_category_search $component
  587. * @return string
  588. */
  589. public function render_restore_category_search(restore_category_search $component) {
  590. $url = $component->get_url();
  591. $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
  592. $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
  593. $table = new html_table();
  594. $table->head = array('', get_string('name'), get_string('description'));
  595. $table->data = array();
  596. if ($component->get_count() !== 0) {
  597. foreach ($component->get_results() as $category) {
  598. $row = new html_table_row();
  599. $row->attributes['class'] = 'rcs-course';
  600. if (!$category->visible) {
  601. $row->attributes['class'] .= ' dimmed';
  602. }
  603. $row->cells = array(
  604. html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$category->id)),
  605. format_string($category->name, true, array('context' => context_coursecat::instance($category->id))),
  606. format_text($category->description, $category->descriptionformat, array('overflowdiv'=>true))
  607. );
  608. $table->data[] = $row;
  609. }
  610. if ($component->has_more_results()) {
  611. $cell = new html_table_cell(get_string('moreresults', 'backup'));
  612. $cell->attributes['class'] = 'notifyproblem';
  613. $cell->colspan = 3;
  614. $row = new html_table_row(array($cell));
  615. $row->attributes['class'] = 'rcs-course';
  616. $table->data[] = $row;
  617. }
  618. } else {
  619. $cell = new html_table_cell(get_string('nomatchingcourses', 'backup'));
  620. $cell->colspan = 3;
  621. $cell->attributes['class'] = 'notifyproblem';
  622. $row = new html_table_row(array($cell));
  623. $row->attributes['class'] = 'rcs-course';
  624. $table->data[] = $row;
  625. }
  626. $output .= html_writer::table($table);
  627. $output .= html_writer::end_tag('div');
  628. $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
  629. $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_category_search::$VAR_SEARCH, 'value'=>$component->get_search()));
  630. $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
  631. $output .= html_writer::end_tag('div');
  632. $output .= html_writer::end_tag('div');
  633. return $output;
  634. }
  635. }
  636. /**
  637. * Data structure representing backup files viewer
  638. *
  639. * @copyright 2010 Dongsheng Cai
  640. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  641. * @since Moodle 2.0
  642. */
  643. class backup_files_viewer implements renderable {
  644. public $files;
  645. public $filecontext;
  646. public $component;
  647. public $filearea;
  648. public $currentcontext;
  649. /**
  650. * Constructor of backup_files_viewer class
  651. * @param array $options
  652. */
  653. public function __construct(array $options = null) {
  654. global $CFG, $USER;
  655. $fs = get_file_storage();
  656. $this->currentcontext = $options['currentcontext'];
  657. $this->filecontext = $options['filecontext'];
  658. $this->component = $options['component'];
  659. $this->filearea = $options['filearea'];
  660. $files = $fs->get_area_files($this->filecontext->id, $this->component, $this->filearea, false, 'timecreated');
  661. $this->files = array_reverse($files);
  662. }
  663. }