Skip to content

Commit dd0f7c7

Browse files
authored
Merge pull request #49 from bdecentgmbh/MOODLE_4X_DEV
Merge to main for release
2 parents 653eab4 + 35222e2 commit dd0f7c7

19 files changed

+160
-85
lines changed

.github/workflows/moodle-ci.yml

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ on: [push, pull_request]
44

55
jobs:
66
test:
7-
runs-on: ubuntu-18.04
7+
runs-on: ubuntu-20.04
88

99
services:
1010
postgres:
11-
image: postgres:13
11+
image: postgres:13.0
1212
env:
1313
POSTGRES_USER: 'postgres'
1414
POSTGRES_HOST_AUTH_METHOD: 'trust'
@@ -29,35 +29,11 @@ jobs:
2929
matrix:
3030
include:
3131
- php: '8.0'
32-
moodle-branch: 'MOODLE_400_STABLE'
32+
moodle-branch: 'MOODLE_402_STABLE'
3333
database: 'mariadb'
3434
- php: '8.0'
35-
moodle-branch: 'MOODLE_401_STABLE'
36-
database: 'mariadb'
37-
- php: '8.0'
38-
moodle-branch: 'master'
39-
database: 'mariadb'
40-
- php: '8.0'
41-
moodle-branch: 'MOODLE_400_STABLE'
35+
moodle-branch: 'MOODLE_402_STABLE'
4236
database: 'pgsql'
43-
- php: '8.0'
44-
moodle-branch: 'MOODLE_401_STABLE'
45-
database: 'pgsql'
46-
- php: '8.0'
47-
moodle-branch: 'master'
48-
database: 'pgsql'
49-
- php: '7.4'
50-
moodle-branch: 'MOODLE_401_STABLE'
51-
database: 'pgsql'
52-
- php: '7.4'
53-
moodle-branch: 'MOODLE_401_STABLE'
54-
database: 'mariadb'
55-
- php: '7.4'
56-
moodle-branch: 'MOODLE_400_STABLE'
57-
database: 'pgsql'
58-
- php: '7.4'
59-
moodle-branch: 'MOODLE_400_STABLE'
60-
database: 'mariadb'
6137

6238
steps:
6339
- name: Check out repository code
@@ -118,9 +94,9 @@ jobs:
11894
if: ${{ always() }}
11995
run: moodle-plugin-ci mustache
12096

121-
# - name: Grunt
122-
# if: ${{ always() }}
123-
# run: moodle-plugin-ci grunt
97+
- name: Grunt
98+
if: ${{ always() }}
99+
run: moodle-plugin-ci grunt
124100

125101
- name: PHPUnit tests
126102
if: ${{ always() }}

classes/course_importer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function import_from_template($templateid, $courseid) {
7272
$backuptempdir = make_backup_temp_directory('template' . $templateid);
7373
$files[0]->extract_to_pathname($fp, $backuptempdir);
7474

75-
self::import('template' . $templateid, $courseid, $templateid);
75+
self::import('template' . $templateid, $courseid);
7676
} else {
7777
$course = (array) $DB->get_record('course', array('id' => $courseid));
7878
$course['format'] = $template->format;
@@ -106,13 +106,12 @@ public static function import_from_template($templateid, $courseid) {
106106
*
107107
* @param string $backuptempdir
108108
* @param int $courseid
109-
* @param int $templateid
110109
* @throws \base_plan_exception
111110
* @throws \base_setting_exception
112111
* @throws \dml_exception
113112
* @throws \restore_controller_exception
114113
*/
115-
public static function import($backuptempdir, $courseid, $templateid) {
114+
public static function import($backuptempdir, $courseid) {
116115
global $USER, $DB;
117116

118117
$course = $DB->get_record('course', ['id' => $courseid]);

classes/form/template_form.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function definition() {
5050
$mform = $this->_form;
5151
$templatebgoptions = $this->_customdata['templatebgoptions'];
5252
$template = isset($this->_customdata['template']) ? $this->_customdata['template'] : [];
53+
$editoroptions = $this->_customdata['editoroptions'];
5354

5455
$mform->addElement('hidden', 'id');
5556
$mform->setType('id', PARAM_INT);
@@ -63,8 +64,8 @@ public function definition() {
6364
if (!$checkformat) {
6465
$mform->addRule('title', get_string('required'), 'required');
6566
}
66-
$mform->addElement('editor', 'description', get_string('description', 'format_kickstart'));
67-
$mform->setType('description', PARAM_RAW);
67+
$mform->addElement('editor', 'description_editor', get_string('description', 'format_kickstart'), null, $editoroptions);
68+
$mform->setType('description_editor', PARAM_RAW);
6869

6970
$mform->addElement('tags', 'tags', get_string('tags'),
7071
['itemtype' => 'format_kickstart_template', 'component' => 'format_kickstart']);
@@ -79,6 +80,7 @@ public function definition() {
7980
'return_types' => FILE_INTERNAL | FILE_EXTERNAL
8081
]);
8182
$mform->addHelpButton('course_backup', 'course_backup', 'format_kickstart');
83+
$mform->addRule('course_backup', get_string('required'), 'required');
8284
}
8385

8486
$mform->addElement('text', 'preview_url', get_string('previewurl', 'format_kickstart'));

classes/output/course_template_list.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,16 @@ public function get_templates() {
110110
// Apply template access if pro is installed.
111111
if (format_kickstart_has_pro()) {
112112
$categoryids = [];
113-
$rootcategoryids = json_decode($template->categoryids, true);
114-
if (is_array($rootcategoryids)) {
115-
foreach ($rootcategoryids as $categoryid) {
116-
$coursecat = \core_course_category::get($categoryid, IGNORE_MISSING);
117-
if ($coursecat) {
118-
$categoryids[] = $categoryid;
119-
if ($template->includesubcategories) {
120-
$categoryids = array_merge($categoryids, $coursecat->get_all_children_ids());
113+
if ($template->categoryids) {
114+
$rootcategoryids = json_decode($template->categoryids, true);
115+
if (is_array($rootcategoryids)) {
116+
foreach ($rootcategoryids as $categoryid) {
117+
$coursecat = \core_course_category::get($categoryid, IGNORE_MISSING);
118+
if ($coursecat) {
119+
$categoryids[] = $categoryid;
120+
if ($template->includesubcategories) {
121+
$categoryids = array_merge($categoryids, $coursecat->get_all_children_ids());
122+
}
121123
}
122124
}
123125
}
@@ -132,7 +134,12 @@ public function get_templates() {
132134
}
133135
}
134136

135-
$template->description_formatted = format_text($template->description, $template->description_format);
137+
$template->description_formatted = format_text(file_rewrite_pluginfile_urls($template->description,
138+
'pluginfile.php',
139+
\context_system::instance()->id,
140+
'format_kickstart',
141+
'description',
142+
$template->id), $template->descriptionformat);
136143
$tags = [];
137144
foreach (\core_tag_tag::get_item_tags('format_kickstart', 'format_kickstart_template', $template->id) as $tag) {
138145
$tags[] = '#' . $tag->get_display_name(false);

classes/output/renderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace format_kickstart\output;
2626

27-
use plugin_renderer_base;
27+
use core_courseformat\output\section_renderer;
2828
use renderable;
2929

3030
/**
@@ -33,7 +33,7 @@
3333
* @copyright 2021 bdecent gmbh <https://bdecent.de>
3434
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3535
*/
36-
class renderer extends plugin_renderer_base {
36+
class renderer extends section_renderer {
3737

3838
/**
3939
* Overrides the parent so that templatable widgets are handled even without their explicit render method.

classes/template_table.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,21 @@ public function col_tags($data) {
8989
null, 'template-tags');
9090
}
9191

92+
/**
93+
* Generate description.
94+
* @param \stdClass $data
95+
* @return mixed
96+
*/
97+
public function col_description($data) {
98+
$context = \context_system::instance();
99+
return format_text(file_rewrite_pluginfile_urls($data->description,
100+
'pluginfile.php',
101+
$context->id,
102+
'format_kickstart',
103+
'description',
104+
$data->id), $data->descriptionformat);
105+
}
106+
92107
/**
93108
* Get any extra classes names to add to this row in the HTML.
94109
*
@@ -191,7 +206,6 @@ public function col_actions($data) {
191206
*/
192207
public function query_db($pagesize, $useinitialsbar = true) {
193208
global $DB, $CFG;
194-
195209
list($wsql, $params) = $this->get_sql_where();
196210
if ($wsql) {
197211
$wsql = 'AND ' . $wsql;

db/install.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
1010
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
1111
<FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
12-
<FIELD NAME="description_format" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
12+
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
1313
<FIELD NAME="preview_url" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Link to preview template"/>
1414
<FIELD NAME="restrictcohort" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
1515
<FIELD NAME="restrictcategory" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>

db/upgrade.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ function xmldb_format_kickstart_upgrade($oldversion) {
6060

6161
// Define field description_format to be added to format_kickstart_template.
6262
$table = new xmldb_table('kickstart_template');
63-
$field = new xmldb_field('description_format', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'description');
63+
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'description');
6464

65-
// Conditionally launch add field description_format.
65+
// Conditionally launch add field descriptionformat.
6666
if (!$dbman->field_exists($table, $field)) {
6767
$dbman->add_field($table, $field);
6868
}
@@ -75,7 +75,7 @@ function xmldb_format_kickstart_upgrade($oldversion) {
7575

7676
// Define field preview_url to be added to format_kickstart_template.
7777
$table = new xmldb_table('kickstart_template');
78-
$field = new xmldb_field('preview_url', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'description_format');
78+
$field = new xmldb_field('preview_url', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'descriptionformat');
7979

8080
// Conditionally launch add field preview_url.
8181
if (!$dbman->field_exists($table, $field)) {
@@ -238,6 +238,16 @@ function xmldb_format_kickstart_upgrade($oldversion) {
238238
upgrade_plugin_savepoint(true, 2023040300, 'format', 'kickstart');
239239
}
240240

241+
if ($oldversion < 2023071101) {
242+
$table = new xmldb_table('format_kickstart_template');
243+
$field = new xmldb_field('description_format', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'description');
244+
if ($dbman->field_exists($table, $field)) {
245+
$dbman->rename_field($table, $field, 'descriptionformat');
246+
}
247+
// Kickstart savepoint reached.
248+
upgrade_plugin_savepoint(true, 2023071101, 'format', 'kickstart');
249+
}
250+
241251
format_kickstart_import_courseformat_template();
242252

243253
return true;

freetemplates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
'includesubcategories' => 0,
4242
'restrictrole' => 0,
4343
'roleids' => [],
44-
'description_format' => 1,
44+
'descriptionformat' => 1,
4545
),
4646
];
4747

lang/en/format_kickstart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
$string['description'] = 'Description';
5050
$string['edit'] = 'Edit';
5151
$string['edit_template'] = 'Edit template';
52-
$string['enrollmenthelp'] = 'Before continuing you may enroll teachers (or any users). Click <b>Course</b> in the secondary navigation to choose a template to import.';
52+
$string['enrollmenthelp'] = 'Before continuing you may enroll teachers (or any users). Click <b>Proceed to course content</b> to choose a template to import.';
5353
$string['general_settings'] = 'General settings';
5454
$string['getpro'] = 'Get more templates with Kickstart Pro';
5555
$string['goprotoenable'] = 'Go Pro to enable';

lib.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,30 @@ function format_kickstart_get_designer_coursetypes() {
575575
return $coursetypes;
576576
}
577577
}
578+
579+
580+
/**
581+
* Serves file from.
582+
*
583+
* @param mixed $course course or id of the course
584+
* @param mixed $cm course module or id of the course module
585+
* @param context $context Context used in the file.
586+
* @param string $filearea Filearea the file stored
587+
* @param array $args Arguments
588+
* @param bool $forcedownload Force download the file instead of display.
589+
* @param array $options additional options affecting the file serving
590+
* @return bool false if file not found, does not return if found - just send the file
591+
*/
592+
function format_kickstart_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
593+
require_login();
594+
if ($context->contextlevel != CONTEXT_SYSTEM && $filearea != 'description') {
595+
return false;
596+
}
597+
598+
$fs = get_file_storage();
599+
$file = $fs->get_file($context->id, 'format_kickstart', $filearea, $args[0], '/', $args[1]);
600+
if (!$file) {
601+
return false;
602+
}
603+
send_stored_file($file, 0, 0, 0, $options);
604+
}

styles.css

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ body.format-kickstart .form-control .fa-search {
5757
border: 1px solid rgba(0, 0, 0, .125);
5858
margin-bottom: .5rem;
5959
}
60-
60+
.format-kickstart .course-content > a {
61+
float: right;
62+
}
6163
.format-kickstart .card-deck .carousel-inner {
6264
display: flex;
6365
margin-bottom: .5rem;
@@ -121,7 +123,19 @@ body.format-kickstart .form-control .fa-search {
121123
flex: 1 1 auto;
122124
padding: 1.25rem;
123125
}
124-
126+
.format-kickstart .card-body .card-title {
127+
margin-top: 10px;
128+
margin-bottom: 0;
129+
}
130+
.format-kickstart .course-content > .card .card-body {
131+
text-align: right;
132+
}
133+
.format-kickstart .course-content > .card .card-body .card-title {
134+
text-align: left;
135+
margin-top: 5px;
136+
margin-bottom: 9px;
137+
margin-right: 5px;
138+
}
125139
.format-kickstart .card-footer {
126140
padding: .75rem 1.25rem;
127141
background-color: rgba(0, 0, 0, .03);
@@ -136,8 +150,10 @@ body.format-kickstart .form-control .fa-search {
136150
.mform > .form-group {
137151
margin-left: 1.5rem;
138152
}
153+
.format-kickstart .course-content > .card .card-body .card-title {
154+
float: left;
155+
}
139156
}
140-
141157
body#page-course-format-kickstart-template.template-designer-format #fitem_id_coursetype {
142158
display: none;
143159
}
@@ -200,4 +216,10 @@ body#page-course-format-kickstart-template.template-designer-format #fitem_id_co
200216
}
201217
.format-kickstart .course-content .kickstart-list-view .templates-block .card .card-footer a.btn-outline-primary {
202218
margin-left: 10px;
219+
}
220+
#page-admin-course-format-kickstart-templates .generaltable tbody tr td .singlebutton {
221+
margin-right: 10px;
222+
}
223+
#page-admin-course-format-kickstart-templates .generaltable tbody tr td .singlebutton + .singlebutton {
224+
margin: 10px 0;
203225
}

0 commit comments

Comments
 (0)