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.
 }
Exemplo n.º 3
0
 /**
  * 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)) . '&nbsp;' . $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)) . '&nbsp;' . $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)) . '&nbsp;' . $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)) . '&nbsp;' . $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;
         }
     }
 }
// Clean up from previous test....
$courseformat->delete_image($sectionid, $contextid);
// This test....
$storedfilerecord = $courseformat->create_original_image_record($contextid, $sectionid, $imagefilename);
$sectionimage = $courseformat->get_image($courseid, $sectionid);
$courseformat->create_section_image($original, $storedfilerecord, $sectionimage);
$o .= html_writer::start_tag('div');
$o .= html_writer::tag('p', 'Original image resized to maximum width:');
$src = moodle_url::make_pluginfile_url($contextid, 'course', 'section', $sectionid, '/', $imagefilename);
$o .= html_writer::empty_tag('img', array('src' => $src, 'alt' => 'Grid Format Image Test Original Resized'));
$o .= html_writer::end_tag('div');
$o .= html_writer::start_tag('div');
$o .= html_writer::tag('p', 'Converted image to current course settings:');
$sectionimage = $courseformat->get_image($courseid, $sectionid);
$src = moodle_url::make_pluginfile_url($contextid, 'course', 'section', $sectionid, $courseformat->get_image_path(), $sectionimage->displayedimageindex . '_' . $sectionimage->image);
$o .= html_writer::empty_tag('img', array('src' => $src, 'alt' => 'Grid Format Image Test Converted to current course settings'));
$o .= html_writer::end_tag('div');
$currentsettings = $courseformat->get_settings();
$o .= html_writer::start_tag('div');
$o .= html_writer::tag('p', 'Current settings: ' . print_r($currentsettings, true));
$ratios = format_grid::get_image_container_ratios();
$resizemethods = array(1 => new lang_string('scale', 'format_grid'), 2 => new lang_string('crop', 'format_grid'));
$o .= html_writer::tag('p', 'Width: ' . $currentsettings['imagecontainerwidth']);
$o .= html_writer::tag('p', 'Ratio: ' . $ratios[$currentsettings['imagecontainerratio']]);
$o .= html_writer::tag('p', 'Resize method: ' . $resizemethods[$currentsettings['imageresizemethod']]);
$o .= html_writer::end_tag('div');
echo $o;
require_once 'test_footer.php';
// Remove original...
$original->delete();
unset($original);
Exemplo n.º 5
0
 /**
  * Calculates the image container properties so that it can be rendered correctly.
  * @param int $imagecontainerwidth The width of the container.
  * @param int $imagecontainerratio The ratio array index of the container, see: $imagecontainerratios.
  * @param int $borderwidth The width of the border.
  * @return array with the key => value of 'height' for the container and 'margin-top' and 'margin-left' for the new activity
  *               image.
  */
 public function calculate_image_container_properties($imagecontainerwidth, $imagecontainerratio, $borderwidth)
 {
     if ($imagecontainerwidth !== self::$currentwidth || $imagecontainerratio !== self::$currentratio || $borderwidth !== self::$currentborderwidth) {
         $height = $this->calculate_height($imagecontainerwidth, $imagecontainerratio);
         // margin-top = image holder height - ( image height - border width)).
         // margin-left = (image holder width - image width) + border width.
         $result = array('height' => $height, 'margin-top' => $height - (42 - $borderwidth), 'margin-left' => $imagecontainerwidth - 95 + $borderwidth);
         // Store:...
         self::$currentwidth = $imagecontainerwidth;
         self::$currentratio = $imagecontainerratio;
         self::$currentborderwidth = $borderwidth;
         self::$currentheight = $result['height'];
         self::$activitymargintop = $result['margin-top'];
         self::$activitymarginleft = $result['margin-left'];
     } else {
         $result = array('height' => self::$currentheight, 'margin-top' => self::$activitymargintop, 'margin-left' => self::$activitymarginleft);
     }
     return $result;
 }
Exemplo n.º 6
0
 $description = get_string('defaultimagecontainerbackgroundcolour', 'format_grid');
 $default = format_grid::get_default_image_container_background_colour();
 $setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
 $settings->add($setting);
 // Default current selected section colour in hexadecimal RGB with preceding '#'.
 $name = 'format_grid/defaultcurrentselectedsectioncolour';
 $title = get_string('defaultcurrentselectedsectioncolour', 'format_grid');
 $description = get_string('defaultcurrentselectedsectioncolour', 'format_grid');
 $default = format_grid::get_default_current_selected_section_colour();
 $setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
 $settings->add($setting);
 // Default current selected imagecontainer colour in hexadecimal RGB with preceding '#'.
 $name = 'format_grid/defaultcurrentselectedimagecontainercolour';
 $title = get_string('defaultcurrentselectedimagecontainercolour', 'format_grid');
 $description = get_string('defaultcurrentselectedimagecontainercolour', 'format_grid');
 $default = format_grid::get_default_current_selected_image_container_colour();
 $setting = new admin_setting_configcolourpicker($name, $title, $description, $default);
 $settings->add($setting);
 /* Show new activity notification image - 1 = no, 2 = yes. */
 $name = 'format_grid/defaultnewactivity';
 $title = get_string('defaultnewactivity', 'format_grid');
 $description = get_string('defaultnewactivity_desc', 'format_grid');
 $default = 2;
 $choices = array(1 => new lang_string('no'), 2 => new lang_string('yes'));
 $settings->add(new admin_setting_configselect($name, $title, $description, $default, $choices));
 /* Fix the section container popup to the screen. 1 = no, 2 = yes */
 $name = 'format_grid/defaultfitsectioncontainertowindow';
 $title = get_string('defaultfitsectioncontainertowindow', 'format_grid');
 $description = get_string('defaultfitsectioncontainertowindow_desc', 'format_grid');
 $default = 1;
 $choices = array(1 => new lang_string('no'), 2 => new lang_string('yes'));