Skip to content

Commit

Permalink
CC
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Oct 14, 2023
1 parent 575babf commit 8511e51
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 160 deletions.
1 change: 0 additions & 1 deletion backup/moodle2/backup_format_grid_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* Provides the information to backup grid course format
*/
class backup_format_grid_plugin extends backup_format_plugin {

/**
* Returns the format information to attach to course element
*/
Expand Down
45 changes: 30 additions & 15 deletions backup/moodle2/restore_format_grid_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* needed to restore one grid format course.
*/
class restore_format_grid_plugin extends restore_format_plugin {

/** @var int */
protected $originalnumsections = 0;

Expand All @@ -50,7 +49,8 @@ protected function define_course_plugin_structure() {
global $DB;
$maxsection = $DB->get_field_sql(
'SELECT max(section) FROM {course_sections} WHERE course = ?',
[$task->get_courseid()]);
[$task->get_courseid()]
);
$this->originalnumsections = (int)$maxsection;
}

Expand Down Expand Up @@ -88,8 +88,12 @@ public function process_grid($data) {
$data->courseid = $courseid;

if (!($course = $DB->get_record('course', ['id' => $data->courseid]))) {
throw new \moodle_exception('invalidcourseid', 'format_grid', '',
get_string('invalidcourseid', 'error'));
throw new \moodle_exception(
'invalidcourseid',
'format_grid',
'',
get_string('invalidcourseid', 'error')
);
} // From /course/view.php.
// No need to annotate anything here.
}
Expand Down Expand Up @@ -133,8 +137,12 @@ public function after_restore_course() {
$filerecord->filename = $filename;
$newfile = $fs->create_file_from_storedfile($filerecord, $file);
if ($newfile) {
$DB->set_field('format_grid_image', 'contenthash', $newfile->get_contenthash(),
['sectionid' => $filesectionid]);
$DB->set_field(
'format_grid_image',
'contenthash',
$newfile->get_contenthash(),
['sectionid' => $filesectionid]
);
}
}
}
Expand Down Expand Up @@ -167,8 +175,10 @@ public function after_restore_course() {
if ($this->step->get_task()->get_setting_value($key . '_included')) {
$sectionnum = (int)$section->title;
if ($sectionnum > $settings['numsections'] && $sectionnum > $this->originalnumsections) {
$DB->execute("UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?",
[$this->step->get_task()->get_courseid(), $sectionnum]);
$DB->execute(
"UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?",
[$this->step->get_task()->get_courseid(), $sectionnum]
);
}
}
}
Expand Down Expand Up @@ -198,10 +208,12 @@ public function process_gridsection($data) {
$data = (object) $data;

$target = $this->step->get_task()->get_target();
if (($target == backup::TARGET_NEW_COURSE) ||
if (
($target == backup::TARGET_NEW_COURSE) ||
($target == backup::TARGET_CURRENT_ADDING) ||
($target == backup::TARGET_CURRENT_DELETING) ||
($target == backup::TARGET_EXISTING_DELETING)) {
($target == backup::TARGET_EXISTING_DELETING)
) {
/* This ensures that when a course is created from an uploaded CSV file that the number of sections is correct.
Thus when an existing course or course file is used but the course restore code is not called.
Because the backup file / course being restored from has the correct 'sections', i.e. that will be in the
Expand All @@ -216,11 +228,13 @@ public function process_gridsection($data) {
/* Allow this to process even if not in the grid format so that our event observer on 'course_restored'
can perform a clean up of restored grid image files after all the data is in place in the database
for this to happen properly. */
if (($target == backup::TARGET_NEW_COURSE) ||
if (
($target == backup::TARGET_NEW_COURSE) ||
($target == backup::TARGET_CURRENT_DELETING) ||
($target == backup::TARGET_EXISTING_DELETING) ||
($target == backup::TARGET_CURRENT_ADDING) ||
($target == backup::TARGET_EXISTING_ADDING)) { // All of them, but just in case a new one is added!
($target == backup::TARGET_EXISTING_ADDING)
) { // All of them, but just in case a new one is added!
if (empty($data->contenthash)) {
// Less than M4.0 backup file.
if (!empty($data->imagepath)) {
Expand All @@ -233,8 +247,10 @@ public function process_gridsection($data) {
if (!empty($data->image)) {
$newsectionid = $this->task->get_sectionid();
$existinggridimage = false;
if (($target == backup::TARGET_CURRENT_ADDING) ||
($target == backup::TARGET_EXISTING_ADDING)) {
if (
($target == backup::TARGET_CURRENT_ADDING) ||
($target == backup::TARGET_EXISTING_ADDING)
) {
$existinggridimage = $DB->get_record('format_grid_image', ['sectionid' => $newsectionid], 'image');
}
if (!$existinggridimage) {
Expand All @@ -256,6 +272,5 @@ public function process_gridsection($data) {
}
}
}

}
}
19 changes: 10 additions & 9 deletions classes/admin_setting_information.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class admin_setting_information extends \admin_setting {

/** @var int The branch this is for. */
protected $mbranch;

Expand Down Expand Up @@ -88,7 +87,7 @@ public function write_setting($data) {
* @param string $query
* @return string Returns an HTML string
*/
public function output_html($data, $query='') {
public function output_html($data, $query = '') {
global $CFG, $OUTPUT;

$formats = \core_plugin_manager::instance()->get_present_plugins('format');
Expand All @@ -106,7 +105,9 @@ public function output_html($data, $query='') {
$attributes['title'] = get_string('love', 'format_grid');
$content = \html_writer::tag('span', $attributes['title'], ['class' => 'sr-only']);
$content = \html_writer::tag('span', $content, $attributes);
$context['versioninfo'] = get_string('versioninfo', 'format_grid',
$context['versioninfo'] = get_string(
'versioninfo',
'format_grid',
[
'moodle' => $CFG->release,
'release' => $plugininfo->release,
Expand All @@ -120,25 +121,25 @@ public function output_html($data, $query='') {
case MATURITY_ALPHA:
$context['maturity'] = get_string('versionalpha', 'format_grid');
$context['maturityalert'] = 'danger';
break;
break;
case MATURITY_BETA:
$context['maturity'] = get_string('versionbeta', 'format_grid');
$context['maturityalert'] = 'danger';
break;
break;
case MATURITY_RC:
$context['maturity'] = get_string('versionrc', 'format_grid');
$context['maturityalert'] = 'warning';
break;
break;
case MATURITY_STABLE:
$context['maturity'] = get_string('versionstable', 'format_grid');
$context['maturityalert'] = 'info';
break;
break;
}
}

if ($CFG->branch != $this->mbranch) {
$context['versioncheck'] = 'Release '.$plugininfo->release.', version '.$plugininfo->version;
$context['versioncheck'] .= ' is incompatible with Moodle '.$CFG->release;
$context['versioncheck'] = 'Release ' . $plugininfo->release . ', version ' . $plugininfo->version;
$context['versioncheck'] .= ' is incompatible with Moodle ' . $CFG->release;
$context['versioncheck'] .= ', please get the correct version from ';
$context['versioncheck'] .= '<a href="https://moodle.org/plugins/format_grid" target="_blank">Moodle.org</a>. ';
$context['versioncheck'] .= 'If none is available, then please consider supporting the format by funding it. ';
Expand Down
7 changes: 3 additions & 4 deletions classes/admin_setting_markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class admin_setting_markdown extends \admin_setting {

/** @var string Filename */
private $filename;

Expand Down Expand Up @@ -88,17 +87,17 @@ public function write_setting($data) {
* @param string $query
* @return string Returns an HTML string
*/
public function output_html($data, $query='') {
public function output_html($data, $query = '') {
global $CFG, $OUTPUT;

$context = new \stdClass();
$context->title = $this->visiblename;
$context->description = $this->description;

if (file_exists("{$CFG->dirroot}/course/format/grid/{$this->filename}")) {
$filecontents = file_get_contents($CFG->dirroot.'/course/format/grid/'.$this->filename);
$filecontents = file_get_contents($CFG->dirroot . '/course/format/grid/' . $this->filename);
} else {
$filecontents = 'Grid format admin_setting_markdown -> file not found: '.$this->filename;
$filecontents = 'Grid format admin_setting_markdown -> file not found: ' . $this->filename;
}
$context->markdown = format_text($filecontents, FORMAT_MARKDOWN);

Expand Down
1 change: 0 additions & 1 deletion classes/courseformat/stateactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class stateactions extends stateactions_base {

/**
* Create a course section.
*
Expand Down
1 change: 0 additions & 1 deletion classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Event observers supported by this format.
*/
class format_grid_observer {

/**
* Observer for the event course_content_deleted.
*
Expand Down
46 changes: 32 additions & 14 deletions classes/output/courseformat/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class content extends content_base {

private $sectioncompletionpercentage = [];
private $sectioncompletionmarkup = [];
private $sectioncompletioncalculated = [];
Expand Down Expand Up @@ -115,8 +114,14 @@ public function export_for_template(\renderer_base $output) {
$fs = get_file_storage();
$coursecontext = \context_course::instance($course->id);
foreach ($coursesectionimages as $coursesectionimage) {
$replacement = $toolbox->check_displayed_image($coursesectionimage, $course->id, $coursecontext->id,
$coursesectionimage->sectionid, $format, $fs);
$replacement = $toolbox->check_displayed_image(
$coursesectionimage,
$course->id,
$coursecontext->id,
$coursesectionimage->sectionid,
$format,
$fs
);
if (!empty($replacement)) {
$coursesectionimages[$coursesectionimage->id] = $replacement;
}
Expand Down Expand Up @@ -162,10 +167,14 @@ public function export_for_template(\renderer_base $output) {
// Do we have an image?
if ((array_key_exists($section->id, $sectionimages)) && ($sectionimages[$section->id]->displayedimagestate >= 1)) {
$sectionimages[$section->id]->imageuri = $toolbox->get_displayed_image_uri(
$sectionimages[$section->id], $coursecontext->id, $section->id, $displayediswebp);
$sectionimages[$section->id],
$coursecontext->id,
$section->id,
$displayediswebp
);
} else {
// No.
$sectionimages[$section->id] = new stdClass;
$sectionimages[$section->id] = new stdClass();
$sectionimages[$section->id]->generatedimageuri = $output->get_generated_image_for_id($section->id);
}
// Number.
Expand Down Expand Up @@ -206,7 +215,7 @@ public function export_for_template(\renderer_base $output) {
// Section break.
if ($sectionformatoptions['sectionbreak'] == 2) { // Yes.
$sectionimages[$section->id]->sectionbreak = true;
if (!empty ($sectionformatoptions['sectionbreakheading'])) {
if (!empty($sectionformatoptions['sectionbreakheading'])) {
// Note: As a PARAM_TEXT, then does need to be passed through 'format_string' for multi-lang or not?
$sectionimages[$section->id]->sectionbreakheading = format_text(
$sectionformatoptions['sectionbreakheading'],
Expand Down Expand Up @@ -287,10 +296,16 @@ protected function get_grid_sections(\renderer_base $output, $settings): array {
foreach ($sectioninfos as $thissection) {
// The course/view.php check the section existence but the output can be called from other parts so we need to check it.
if (!$thissection) {
throw new \moodle_exception('unknowncoursesection', 'error', '',
get_string('unknowncoursesection', 'error',
course_get_url($course).' - '.format_string($course->fullname))
);
throw new \moodle_exception(
'unknowncoursesection',
'error',
'',
get_string(
'unknowncoursesection',
'error',
course_get_url($course) . ' - ' . format_string($course->fullname)
)
);
}

if ($thissection->section > $numsections) {
Expand All @@ -301,7 +316,7 @@ protected function get_grid_sections(\renderer_base $output, $settings): array {
continue;
}

$section = new stdClass;
$section = new stdClass();
$section->id = $thissection->id;
$section->num = $thissection->section;
$section->name = $output->section_title_without_link($thissection, $course);
Expand Down Expand Up @@ -349,8 +364,10 @@ protected function calculate_section_activity_completion($section, $course, $mod
if ($completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
$total++;
$completiondata = $completioninfo->get_data($thismod, true);
if ($completiondata->completionstate == COMPLETION_COMPLETE ||
$completiondata->completionstate == COMPLETION_COMPLETE_PASS) {
if (
$completiondata->completionstate == COMPLETION_COMPLETE ||
$completiondata->completionstate == COMPLETION_COMPLETE_PASS
) {
$complete++;
}
}
Expand Down Expand Up @@ -389,7 +406,8 @@ protected function calculate_section_activity_completion($section, $course, $mod
} else {
$data->percentagequarter = 4;
}
$this->sectioncompletionmarkup[$section->section] = $output->render_from_template('format_grid/grid_completion', $data);
$this->sectioncompletionmarkup[$section->section] =
$output->render_from_template('format_grid/grid_completion', $data);
}

$this->sectioncompletioncalculated[$section->section] = true;
Expand Down
1 change: 0 additions & 1 deletion classes/output/courseformat/content/section.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class section extends section_base {

/** @var course_format the course format */
protected $format;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class controlmenu extends controlmenu_base {

/** @var course_format the course format class */
protected $format;

Expand Down
21 changes: 15 additions & 6 deletions classes/output/courseformat/content/section/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class summary extends summary_base {

/** @var section_info the course section class - core is 'private' */
private $thesection;

Expand Down Expand Up @@ -92,8 +91,8 @@ protected function singlepagesummaryimage($summary, $output): string {
$o = $summary;
$coursesettings = $this->format->get_settings();
if ($coursesettings['singlepagesummaryimage'] > 1) { // I.e. not 'off'.
$data = new stdClass;
switch($coursesettings['singlepagesummaryimage']) {
$data = new stdClass();
switch ($coursesettings['singlepagesummaryimage']) {
case 2:
$data->left = true;
break;
Expand All @@ -117,8 +116,14 @@ protected function singlepagesummaryimage($summary, $output): string {
$fs = get_file_storage();
$coursecontext = \context_course::instance($courseid);
$toolbox = \format_grid\toolbox::get_instance();
$replacement = $toolbox->check_displayed_image($coursesectionimage, $courseid, $coursecontext->id, $sectionid,
$this->format, $fs);
$replacement = $toolbox->check_displayed_image(
$coursesectionimage,
$courseid,
$coursecontext->id,
$sectionid,
$this->format,
$fs
);
if (!empty($replacement)) {
$coursesectionimage = $replacement;
}
Expand All @@ -127,7 +132,11 @@ protected function singlepagesummaryimage($summary, $output): string {
// Yes.
$displayediswebp = (get_config('format_grid', 'defaultdisplayedimagefiletype') == 2);
$data->imageuri = $toolbox->get_displayed_image_uri(
$coursesectionimage, $coursecontext->id, $sectionid, $displayediswebp);
$coursesectionimage,
$coursecontext->id,
$sectionid,
$displayediswebp
);
$sectionformatoptions = $this->format->get_format_options($this->thesection);
$data->alttext = $sectionformatoptions['sectionimagealttext'];

Expand Down
Loading

0 comments on commit 8511e51

Please sign in to comment.