Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to main for release #52

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
- php: '8.2'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'mariadb'
- php: '8.1'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
Expand Down
6 changes: 5 additions & 1 deletion classes/course_importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function import_from_template($templateid, $courseid) {

self::import('template' . $templateid, $courseid);
} else {
$course = (array) $DB->get_record('course', array('id' => $courseid));
$course = (array) $DB->get_record('course', ['id' => $courseid]);
$course['format'] = $template->format;
// Get format opitions.
$params['format'] = $template->format;
Expand Down Expand Up @@ -166,12 +166,16 @@ public static function import($backuptempdir, $courseid) {
throw $e;
} finally {
// Reset some settings.
$fullname = $course->fullname;
$shortname = $course->shortname;
$summary = $course->summary;
$summaryformat = $course->summaryformat;
$enddate = $course->enddate;
$timecreated = $course->timecreated;
// Reload course.
$course = $DB->get_record('course', ['id' => $courseid]);
$course->fullname = $fullname;
$course->shortname = $shortname;
$course->summary = $summary;
$course->summaryformat = $summaryformat;
$course->enddate = $enddate;
Expand Down
10 changes: 5 additions & 5 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

defined('MOODLE_INTERNAL') || die();

use \format_kickstart\course_importer;
use format_kickstart\course_importer;

require_once($CFG->libdir.'/externallib.php');

Expand All @@ -42,10 +42,10 @@ class external extends \external_api {
public static function import_template_parameters() {

return new \external_function_parameters(
array(
[
'templateid' => new \external_value(PARAM_INT, 'Kickstart Template id'),
'courseid' => new \external_value(PARAM_INT, 'Course id')
)
'courseid' => new \external_value(PARAM_INT, 'Course id'),
],
);
}

Expand All @@ -62,7 +62,7 @@ public static function import_template($templateid, $courseid) {
$context = \context_course::instance($courseid);
require_capability('format/kickstart:import_from_template', $context);
$params = self::validate_parameters(self::import_template_parameters(),
array('templateid' => $templateid, 'courseid' => $courseid));
['templateid' => $templateid, 'courseid' => $courseid]);
course_importer::import_from_template($templateid, $courseid);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions classes/form/template_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function definition() {
$attributes = [];
$checkformat = !empty($template) && isset($template['courseformat']) && $template['courseformat'];
if ($checkformat) {
$attributes = array('disabled' => true);
$attributes = ['disabled' => true];
}
$mform->addElement('text', 'title', get_string('title', 'format_kickstart'), $attributes);
$mform->setType('title', PARAM_TEXT);
Expand All @@ -77,7 +77,7 @@ public function definition() {
'subdirs' => 0,
'maxfiles' => 1,
'accepted_types' => ['.mbz'],
'return_types' => FILE_INTERNAL | FILE_EXTERNAL
'return_types' => FILE_INTERNAL | FILE_EXTERNAL,
]);
$mform->addHelpButton('course_backup', 'course_backup', 'format_kickstart');
$mform->addRule('course_backup', get_string('required'), 'required');
Expand Down Expand Up @@ -108,7 +108,7 @@ public function definition() {
}

$mform->addElement('autocomplete', 'cohortids', get_string('cohorts', 'cohort'), $options, [
'multiple' => true
'multiple' => true,
]);
$mform->hideIf('cohortids', 'restrictcohort');

Expand Down
2 changes: 1 addition & 1 deletion classes/form/template_table_settings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function definition() {
-1 => get_string('all'),
25 => '25',
50 => '50',
100 => '100'
100 => '100',
]);
$mform->setType('pagesize', PARAM_INT);
$mform->setDefault('pagesize', 25);
Expand Down
10 changes: 5 additions & 5 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@ public static function format_kickstart_changeconfig($event) {
$data = $event->get_data();
$plugin = $data['other']['plugin'];
$name = isset($data['other']['name']) ? $data['other']['name'] : '';
if (preg_match("/^format_/", $plugin) && $name == 'disabled') {
if (preg_match("/^format_/", $plugin ?? '') && $name == 'disabled') {
$templates = isset($CFG->kickstart_templates) ? explode(",", $CFG->kickstart_templates) : [];
$disable = ($data['other']['value'] == 1) ? true : false;
$format = substr($plugin, 7);
if ($disable) {
$removetemplates = $DB->get_records_menu('format_kickstart_template',
array('format' => $format, 'courseformat' => 1), '', 'id,id');
['format' => $format, 'courseformat' => 1], '', 'id,id');
if ($removetemplates) {
$removetemplates = array_keys($removetemplates);
$templates = array_diff($templates, $removetemplates);
}
$DB->set_field('format_kickstart_template', 'visible', 0, array('format' => $format, 'courseformat' => 1));
$DB->set_field('format_kickstart_template', 'visible', 0, ['format' => $format, 'courseformat' => 1]);
} else {
$addtemplates = $DB->get_records_menu('format_kickstart_template',
array('format' => $format, 'courseformat' => 1), '', 'id,id');
['format' => $format, 'courseformat' => 1], '', 'id,id');
if ($addtemplates) {
$addtemplates = array_keys($addtemplates);
$templates = array_merge($templates, $addtemplates);
}
$DB->set_field('format_kickstart_template', 'visible', 1, array('format' => $format, 'courseformat' => 1));
$DB->set_field('format_kickstart_template', 'visible', 1, ['format' => $format, 'courseformat' => 1]);
}
set_config('kickstart_templates', implode(',', $templates));
}
Expand Down
7 changes: 4 additions & 3 deletions classes/output/course_template_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,20 @@ public function get_templates() {
'format_kickstart',
'description',
$template->id), $template->descriptionformat);
$template->title = format_string($template->title);
$tags = [];
foreach (\core_tag_tag::get_item_tags('format_kickstart', 'format_kickstart_template', $template->id) as $tag) {
$tags[] = '#' . $tag->get_display_name(false);
}
$template->hashtags = implode(' ', $tags);
$template->link = new \moodle_url('/course/format/kickstart/confirm.php', [
'template_id' => $template->id,
'course_id' => $COURSE->id
'course_id' => $COURSE->id,
]);
if (!$template->courseformat) {
$templatecount++;
}
if ($limit > 0 && $templatecount >= $limit) {
if ($limit > 0 && $templatecount > $limit) {
break;
}
if (format_kickstart_has_pro()) {
Expand Down Expand Up @@ -197,7 +198,7 @@ public function export_for_template(renderer_base $output) {
'notemplates' => empty($templates),
'canmanage' => has_capability('format/kickstart:manage_templates', \context_system::instance()),
'createtemplateurl' => new \moodle_url('/course/format/kickstart/template.php', ['action' => 'create']),
'managetemplateurl' => new \moodle_url('/course/format/kickstart/templates.php')
'managetemplateurl' => new \moodle_url('/course/format/kickstart/templates.php'),
];
}

Expand Down
6 changes: 3 additions & 3 deletions classes/output/import_course_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public function export_for_template(renderer_base $output) {
}
$course->url = new \moodle_url('/course/view.php', ['id' => $course->id]);
$course->fullname = format_string($course->fullname, true, [
'context' => \context_course::instance($course->id)
'context' => \context_course::instance($course->id),
]);
$course->importurl = new \moodle_url('/local/kickstart_pro/import.php', [
'id' => $COURSE->id,
'importid' => $course->id,
'target' => $target
'target' => $target,
]);
$courses[] = $course;
}
Expand All @@ -90,7 +90,7 @@ public function export_for_template(renderer_base $output) {
'searchlabel' => get_string('showing', 'format_kickstart', ['count' => $component->get_count()]),
'moreresults' => $component->has_more_results(),
'prourl' => 'https://bdecent.de/products/moodle-plugins/kickstart-course-wizard-pro/',
'courseurl' => new \moodle_url('/course/view.php', ['id' => $COURSE->id])
'courseurl' => new \moodle_url('/course/view.php', ['id' => $COURSE->id]),
];
}
}
44 changes: 32 additions & 12 deletions classes/template_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
*/
class template_table extends \table_sql {

/**
* @var int
*/
public $totaltemplates;

/**
* @var int
*/
public $cnt;

/**
* Setup table.
*
Expand Down Expand Up @@ -77,6 +87,16 @@ public function __construct() {
$this->define_headers($headers);
}

/**
* Generate title.
*
* @param \stdClass $data
* @return mixed
*/
public function col_title($data) {
return format_string($data->title);
}

/**
* Generate tag list.
*
Expand Down Expand Up @@ -128,14 +148,14 @@ public function col_status($data) {
$status = '';
if ($data->status) {
$status .= \html_writer::link($templateurl->out(false,
array('action' => 'disable', 'template' => $data->id)),
$OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', array('class' => 'iconsmall')),
array('id' => "sort-template-up-action")). '';
['action' => 'disable', 'template' => $data->id]),
$OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', ['class' => 'iconsmall']),
['id' => "sort-template-up-action"]). '';
} else {
$status .= \html_writer::link($templateurl->out(false,
array('action' => 'enable', 'template' => $data->id)),
$OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', array('class' => 'iconsmall')),
array('id' => "sort-template-up-action")). '';
['action' => 'enable', 'template' => $data->id]),
$OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', ['class' => 'iconsmall']),
['id' => "sort-template-up-action"]). '';
}
return $status;
}
Expand All @@ -153,21 +173,21 @@ public function col_updown($data) {
$updown = '';
$strup = get_string('up');
$strdown = get_string('down');
$spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'iconsmall'));
$spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', ['class' => 'iconsmall']);
if ($this->cnt) {
$updown .= \html_writer::link($templateurl->out(false,
array('action' => 'up', 'template' => $data->id)),
$OUTPUT->pix_icon('t/up', $strup, 'moodle', array('class' => 'iconsmall')),
array('id' => "sort-template-up-action")). '';
['action' => 'up', 'template' => $data->id]),
$OUTPUT->pix_icon('t/up', $strup, 'moodle', ['class' => 'iconsmall']),
['id' => "sort-template-up-action"]). '';
} else {
$updown .= $spacer;
}

if ($this->cnt < ($this->totaltemplates - 1)) {
$updown .= '&nbsp;'. \html_writer::link($templateurl->out(false,
array('action' => 'down', 'template' => $data->id)),
['action' => 'down', 'template' => $data->id]),
$OUTPUT->pix_icon('t/down', $strdown, 'moodle',
array('class' => 'iconsmall')), array('id' => "sort-template-down-action"));
['class' => 'iconsmall']), ['id' => "sort-template-down-action"]);
} else {
$updown .= $spacer;
}
Expand Down
8 changes: 4 additions & 4 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => [
'manager' => CAP_ALLOW,
]
],
],
'format/kickstart:import_from_template' => [
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'manager' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW
]
]
'editingteacher' => CAP_ALLOW,
],
],
];

8 changes: 4 additions & 4 deletions db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

defined('MOODLE_INTERNAL') || die();

$definitions = array(
'templates' => array(
$definitions = [
'templates' => [
'mode' => cache_store::MODE_APPLICATION,
),
);
],
];
8 changes: 4 additions & 4 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
*/
defined('MOODLE_INTERNAL') || die();

$observers = array(
array(
$observers = [
[
'eventname' => 'core\event\config_log_created',
'callback' => '\format_kickstart\observer::format_kickstart_changeconfig',
),
);
],
];
8 changes: 4 additions & 4 deletions db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@

defined('MOODLE_INTERNAL') || die();

$functions = array(
'format_kickstart_import_template' => array(
$functions = [
'format_kickstart_import_template' => [
'classname' => 'format_kickstart\external',
'methodname' => 'import_template',
'description' => 'Import the template',
'type' => 'write',
'capabilities' => 'format/kickstart:import_from_template',
'ajax' => true,
'loginrequired' => true,
),
);
],
];
2 changes: 1 addition & 1 deletion db/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function xmldb_format_kickstart_uninstall() {
$DB->delete_records_select(
'course_format_options',
"courseid = :siteid AND format != :site",
array("siteid" => $SITE->id, 'site' => 'site')
["siteid" => $SITE->id, 'site' => 'site'],
);
unset_config('kickstart_templates');
return true;
Expand Down
2 changes: 1 addition & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function xmldb_format_kickstart_upgrade($oldversion) {

if ($oldversion < 2023040300) {
$DB->set_field('tag_instance', 'itemtype', 'format_kickstart_template',
array('itemtype' => 'kickstart_template', 'component' => 'format_kickstart'));
['itemtype' => 'kickstart_template', 'component' => 'format_kickstart']);
// Kickstart savepoint reached.
upgrade_plugin_savepoint(true, 2023040300, 'format', 'kickstart');
}
Expand Down
2 changes: 1 addition & 1 deletion format.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
$output = $PAGE->get_renderer('format_kickstart');

$PAGE->requires->js_call_amd('format_kickstart/formatkickstart', 'init',
array('contextid' => $context->id, 'courseid' => $course->id));
['contextid' => $context->id, 'courseid' => $course->id]);

if (has_capability('format/kickstart:import_from_template', $context)) {
// Check the template add or remove.
Expand Down
4 changes: 2 additions & 2 deletions freetemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
global $freetemplates;
$freetemplates = [

'0' => array(
'0' => [
'id' => 0,
'title' => 'demo test 1',
'description' => '<p dir="ltr" style="text-align: left;">test content of the block content</p>',
Expand All @@ -42,6 +42,6 @@
'restrictrole' => 0,
'roleids' => [],
'descriptionformat' => 1,
),
],
];

Loading
Loading