private function delete_displayed_images() { global $CFG, $DB; /* We only process this information if the course we are backing up is in the 'grid' format (target format can change depending of restore options). Note: This appears to be a bit silly as this code is executed even if the course is not in the 'grid' format. */ $courseid = $this->task->get_courseid(); $format = $DB->get_field('course', 'format', array('id' => $courseid)); if ($format != 'grid') { return; } require_once $CFG->dirroot . '/course/format/lib.php'; // For format_base. require_once $CFG->dirroot . '/course/format/grid/lib.php'; // For format_grid. if (format_grid::is_developer_debug()) { error_log('backup_format_grid_plugin::delete_displayed_images() courseid: ' . $courseid); } $courseformat = course_get_format($courseid); $courseformat->delete_displayed_images(); }
/** * Process the 'plugin_format_grid_section' element within the 'section' element in the 'section.xml' file in the * '/sections/section_sectionid' folder of the zipped backup 'mbz' file. * Discovered that the files are contained in the course repository with the new section number, so we just need to alter to * the new value if any. * This was undertaken by performing a restore and using the url * 'http://localhost/moodle23/pluginfile.php/94/course/section/162/mc_fs.png' where I had an image called 'mc_fs.png' in * section 1 which was id 129 but now 162 as the debug code told me. '94' is just the context id. The url was originally * created in '_make_block_icon_topics' of lib.php of the format. * Still need courseid in the 'format_grid_icon' table as it is used in discovering what records to remove when deleting a * course, see lib.php 'format_grid_delete_course'. */ public function process_gridsection($data) { global $DB; $data = (object) $data; /* We only process this information if the course we are restoring to has 'grid' format (target format can change depending of restore options). */ $format = $DB->get_field('course', 'format', array('id' => $this->task->get_courseid())); if ($format != 'grid') { return; } $data->courseid = $this->task->get_courseid(); $data->sectionid = $this->task->get_sectionid(); if (format_grid::is_developer_debug()) { error_log('restore_format_grid_plugin::process_gridsection() before:' . print_r($data, true)); } if (!empty($data->imagepath)) { $data->image = $data->imagepath; unset($data->imagepath); } else { if (empty($data->image)) { $data->image = null; } } if (format_grid::is_developer_debug()) { error_log('restore_format_grid_plugin::process_gridsection() after:' . print_r($data, true)); } if (!$DB->record_exists('format_grid_icon', array('courseid' => $data->courseid, 'sectionid' => $data->sectionid))) { if (!$DB->insert_record('format_grid_icon', $data, true)) { throw new moodle_exception('invalidrecordid', 'format_grid', '', 'Could not insert icon. Grid format table format_grid_icon is not ready. An administrator must visit the notifications section.'); } } else { $old = $DB->get_record('format_grid_icon', array('courseid' => $data->courseid, 'sectionid' => $data->sectionid)); // Always update missing icons during restore / import, noting merge into existing course currently doesn't restore the grid icons. if (is_null($old->image)) { // Update the record to use this icon as we are restoring or importing and no icon exists already. $data->id = $old->id; if (!$DB->update_record('format_grid_icon', $data)) { throw new moodle_exception('invalidrecordid', 'format_grid', '', 'Could not update icon. Grid format table format_grid_icon is not ready. An administrator must visit the notifications section.'); } } } // No need to annotate anything here. }
/** * Makes the grid image containers. */ private function make_block_icon_topics($contextid, $modinfo, $course, $editing, $hascapvishidsect, $urlpicedit) { global $USER, $CFG; if ($this->settings['newactivity'] == 2) { $currentlanguage = current_language(); if (!file_exists("{$CFG->dirroot}/course/format/grid/pix/new_activity_" . $currentlanguage . ".png")) { $currentlanguage = 'en'; } $url_pic_new_activity = $this->output->pix_url('new_activity_' . $currentlanguage, 'format_grid'); // Get all the section information about which items should be marked with the NEW picture. $sectionupdated = $this->new_activity($course); } if ($editing) { $streditimage = get_string('editimage', 'format_grid'); $streditimagealt = get_string('editimage_alt', 'format_grid'); } // Get the section images for the course. $sectionimages = $this->courseformat->get_images($course->id); // CONTRIB-4099:... $gridimagepath = $this->courseformat->get_image_path(); // Start at 1 to skip the summary block or include the summary block if it's in the grid display. for ($section = $this->topic0_at_top ? 1 : 0; $section <= $course->numsections; $section++) { $thissection = $modinfo->get_section_info($section); // Check if section is visible to user. $showsection = $hascapvishidsect || $thissection->visible && ($thissection->available || $thissection->showavailability || !$course->hiddensections); if ($showsection) { // We now know the value for the grid shade box shown array. $this->shadeboxshownarray[$section] = 2; $sectionname = $this->courseformat->get_section_name($thissection); /* Roles info on based on: http://www.w3.org/TR/wai-aria/roles. Looked into the 'grid' role but that requires 'row' before 'gridcell' and there are none as the grid is responsive, so as the container is a 'navigation' then need to look into converting the containing 'div' to a 'nav' tag (www.w3.org/TR/2010/WD-html5-20100624/sections.html#the-nav-element) when I'm that all browsers support it against the browser requirements of Moodle. */ $liattributes = array('class' => 'span6', 'role' => 'region', 'aria-label' => $sectionname); if ($this->courseformat->is_section_current($section)) { $liattributes['class'] = 'currenticon'; } echo html_writer::start_tag('li', $liattributes); // Ensure the record exists. if ($sectionimages === false || !array_key_exists($thissection->id, $sectionimages)) { // get_image has 'repair' functionality for when there are issues with the data. $sectionimage = $this->courseformat->get_image($course->id, $thissection->id); } else { $sectionimage = $sectionimages[$thissection->id]; } // If the image is set then check that displayedimageindex is greater than 0 otherwise create the displayed image. // This is a catch-all for existing courses. if (isset($sectionimage->image) && $sectionimage->displayedimageindex < 1) { // Set up the displayed image:... $sectionimage->newimage = $sectionimage->image; $sectionimage = $this->courseformat->setup_displayed_image($sectionimage, $contextid, $this->settings); if (format_grid::is_developer_debug()) { error_log('make_block_icon_topics: Updated displayed image for section ' . $thissection->id . ' to ' . $sectionimage->newimage . ' and index ' . $sectionimage->displayedimageindex); } } if ($course->coursedisplay != COURSE_DISPLAY_MULTIPAGE) { //echo html_writer::start_tag('a', array( // 'href' => '#section-' . $thissection->section, // 'id' => 'gridsection-' . $thissection->section, // 'class' => 'gridicon_link', // 'role' => 'link', // 'aria-label' => $sectionname)); echo html_writer::start_tag('div', array('class' => 'sectionbox')); echo html_writer::start_tag('div', array('class' => 'section_title')); echo html_writer::start_tag('h2', array('class' => 'title icon_content')); echo html_writer::tag('a', $sectionname, array('href' => '#section-' . $thissection->section, 'id' => 'gridsection-' . $thissection->section, 'class' => 'gridicon_link', 'role' => 'link', 'aria-label' => $sectionname)); echo html_writer::end_tag('h2'); echo html_writer::end_tag('div'); $thissummary = $this->format_summary_text($thissection); // $thissummary = trim(clean_param($thissummary, PARAM_NOTAGS)); $thissummary = strchr(strchr($thissummary, "<p>"), "</p>", true); $thissummary = $this->text_limit($thissummary, 200); echo html_writer::tag('p', $thissummary, array('class' => 'summary 2')); //echo html_writer::end_tag('div'); if ($this->settings['newactivity'] == 2 && isset($sectionupdated[$thissection->id])) { // The section has been updated since the user last visited this course, add NEW label. echo html_writer::empty_tag('img', array('class' => 'new_activity', 'src' => $url_pic_new_activity, 'alt' => '')); } echo html_writer::start_tag('div', array('class' => 'image_holder')); $showimg = false; if (is_object($sectionimage) && $sectionimage->displayedimageindex > 0) { $imgurl = moodle_url::make_pluginfile_url($contextid, 'course', 'section', $thissection->id, $gridimagepath, $sectionimage->displayedimageindex . '_' . $sectionimage->image); $showimg = true; } else { if ($section == 0) { $imgurl = $this->output->pix_url('info', 'format_grid'); $showimg = true; } } if ($showimg) { echo html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $sectionname, 'role' => 'img', 'aria-label' => $sectionname)); } echo html_writer::end_tag('div'); echo html_writer::end_tag('div'); //echo html_writer::end_tag('a'); if ($editing) { echo html_writer::link($this->courseformat->grid_moodle_url('editimage.php', array('sectionid' => $thissection->id, 'contextid' => $contextid, 'userid' => $USER->id, 'role' => 'link', 'aria-label' => $streditimagealt)), html_writer::empty_tag('img', array('src' => $urlpicedit, 'alt' => $streditimagealt, 'role' => 'img', 'aria-label' => $streditimagealt)) . ' ' . $streditimage, array('title' => $streditimagealt)); if ($section == 0) { $strdisplaysummary = get_string('display_summary', 'format_grid'); $strdisplaysummaryalt = get_string('display_summary_alt', 'format_grid'); echo html_writer::empty_tag('br') . html_writer::link($this->courseformat->grid_moodle_url('mod_summary.php', array('sesskey' => sesskey(), 'course' => $course->id, 'showsummary' => 1, 'role' => 'link', 'aria-label' => $strdisplaysummaryalt)), html_writer::empty_tag('img', array('src' => $this->output->pix_url('out_of_grid', 'format_grid'), 'alt' => $strdisplaysummaryalt, 'role' => 'img', 'aria-label' => $strdisplaysummaryalt)) . ' ' . $strdisplaysummary, array('title' => $strdisplaysummaryalt)); } } echo html_writer::end_tag('li'); } else { //$title = html_writer::start_tag('div', array('class'=>'section_title')); //$title .= html_writer::tag('h2', $sectionname, array('class' => 'title icon_content')); //$title .= html_writer::end_tag('div'); $url = ''; $url = course_get_url($course, $thissection->section); $title = html_writer::start_tag('div', array('class' => 'sectionbox')); $title .= html_writer::start_tag('div', array('class' => 'section_title')); $title .= html_writer::start_tag('h2', array('class' => 'title icon_content')); $title .= html_writer::tag('a', $sectionname, array('href' => $url, 'id' => 'gridsection-' . $thissection->section, 'class' => 'gridicon_link', 'role' => 'link', 'aria-label' => $sectionname)); $title .= html_writer::end_tag('h2'); $title .= html_writer::end_tag('div'); $thissummary = $this->format_summary_text($thissection); // $thissummary = trim(clean_param($thissummary, PARAM_NOTAGS)); $thissummary = strchr(strchr($thissummary, "<p>"), "</p>", true); $thissummary = $this->text_limit($thissummary, 200); $title .= html_writer::tag('p', $thissummary, array('class' => 'summary')); if ($this->settings['newactivity'] == 2 && isset($sectionupdated[$thissection->id])) { $title .= html_writer::empty_tag('img', array('class' => 'new_activity', 'src' => $url_pic_new_activity, 'alt' => '')); } $title .= html_writer::start_tag('div', array('class' => 'image_holder')); $showimg = false; if (is_object($sectionimage) && $sectionimage->displayedimageindex > 0) { $imgurl = moodle_url::make_pluginfile_url($contextid, 'course', 'section', $thissection->id, $gridimagepath, $sectionimage->displayedimageindex . '_' . $sectionimage->image); $showimg = true; } else { if ($section == 0) { $imgurl = $this->output->pix_url('info', 'format_grid'); $showimg = true; } } if ($showimg) { $title .= html_writer::empty_tag('img', array('src' => $imgurl, 'alt' => $sectionname, 'role' => 'img', 'aria-label' => $sectionname)); } $title .= html_writer::end_tag('div'); $title .= html_writer::end_tag('div'); //$url = course_get_url($course, $thissection->section); //if ($url) { // $title = html_writer::link($url, $title, array( // 'id' => 'gridsection-' . $thissection->section, // 'role' => 'link', // 'aria-label' => $sectionname)); //} echo $title; if ($editing) { echo html_writer::link($this->courseformat->grid_moodle_url('editimage.php', array('sectionid' => $thissection->id, 'contextid' => $contextid, 'userid' => $USER->id, 'role' => 'link', 'aria-label' => $streditimagealt)), html_writer::empty_tag('img', array('src' => $urlpicedit, 'alt' => $streditimagealt, 'role' => 'img', 'aria-label' => $streditimagealt)) . ' ' . $streditimage, array('title' => $streditimagealt)); if ($section == 0) { $strdisplaysummary = get_string('display_summary', 'format_grid'); $strdisplaysummaryalt = get_string('display_summary_alt', 'format_grid'); echo html_writer::empty_tag('br') . html_writer::link($this->courseformat->grid_moodle_url('mod_summary.php', array('sesskey' => sesskey(), 'course' => $course->id, 'showsummary' => 1, 'role' => 'link', 'aria-label' => $strdisplaysummaryalt)), html_writer::empty_tag('img', array('src' => $this->output->pix_url('out_of_grid', 'format_grid'), 'alt' => $strdisplaysummaryalt, 'role' => 'img', 'aria-label' => $strdisplaysummaryalt)) . ' ' . $strdisplaysummary, array('title' => $strdisplaysummaryalt)); } } echo html_writer::end_tag('li'); } } else { // We now know the value for the grid shade box shown array. $this->shadeboxshownarray[$section] = 1; } } }