Skip to content

Commit

Permalink
Merge pull request #49 from bdecentgmbh/MOODLE_4X_DEV
Browse files Browse the repository at this point in the history
Merge to main for release
  • Loading branch information
stefanscholz committed Aug 4, 2023
2 parents 653eab4 + 35222e2 commit dd0f7c7
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 85 deletions.
38 changes: 7 additions & 31 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

services:
postgres:
image: postgres:13
image: postgres:13.0
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -29,35 +29,11 @@ jobs:
matrix:
include:
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
moodle-branch: 'MOODLE_402_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'master'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
moodle-branch: 'MOODLE_402_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'master'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'

steps:
- name: Check out repository code
Expand Down Expand Up @@ -118,9 +94,9 @@ jobs:
if: ${{ always() }}
run: moodle-plugin-ci mustache

# - name: Grunt
# if: ${{ always() }}
# run: moodle-plugin-ci grunt
- name: Grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt

- name: PHPUnit tests
if: ${{ always() }}
Expand Down
5 changes: 2 additions & 3 deletions classes/course_importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function import_from_template($templateid, $courseid) {
$backuptempdir = make_backup_temp_directory('template' . $templateid);
$files[0]->extract_to_pathname($fp, $backuptempdir);

self::import('template' . $templateid, $courseid, $templateid);
self::import('template' . $templateid, $courseid);
} else {
$course = (array) $DB->get_record('course', array('id' => $courseid));
$course['format'] = $template->format;
Expand Down Expand Up @@ -106,13 +106,12 @@ public static function import_from_template($templateid, $courseid) {
*
* @param string $backuptempdir
* @param int $courseid
* @param int $templateid
* @throws \base_plan_exception
* @throws \base_setting_exception
* @throws \dml_exception
* @throws \restore_controller_exception
*/
public static function import($backuptempdir, $courseid, $templateid) {
public static function import($backuptempdir, $courseid) {
global $USER, $DB;

$course = $DB->get_record('course', ['id' => $courseid]);
Expand Down
6 changes: 4 additions & 2 deletions classes/form/template_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function definition() {
$mform = $this->_form;
$templatebgoptions = $this->_customdata['templatebgoptions'];
$template = isset($this->_customdata['template']) ? $this->_customdata['template'] : [];
$editoroptions = $this->_customdata['editoroptions'];

$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
Expand All @@ -63,8 +64,8 @@ public function definition() {
if (!$checkformat) {
$mform->addRule('title', get_string('required'), 'required');
}
$mform->addElement('editor', 'description', get_string('description', 'format_kickstart'));
$mform->setType('description', PARAM_RAW);
$mform->addElement('editor', 'description_editor', get_string('description', 'format_kickstart'), null, $editoroptions);
$mform->setType('description_editor', PARAM_RAW);

$mform->addElement('tags', 'tags', get_string('tags'),
['itemtype' => 'format_kickstart_template', 'component' => 'format_kickstart']);
Expand All @@ -79,6 +80,7 @@ public function definition() {
'return_types' => FILE_INTERNAL | FILE_EXTERNAL
]);
$mform->addHelpButton('course_backup', 'course_backup', 'format_kickstart');
$mform->addRule('course_backup', get_string('required'), 'required');
}

$mform->addElement('text', 'preview_url', get_string('previewurl', 'format_kickstart'));
Expand Down
25 changes: 16 additions & 9 deletions classes/output/course_template_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ public function get_templates() {
// Apply template access if pro is installed.
if (format_kickstart_has_pro()) {
$categoryids = [];
$rootcategoryids = json_decode($template->categoryids, true);
if (is_array($rootcategoryids)) {
foreach ($rootcategoryids as $categoryid) {
$coursecat = \core_course_category::get($categoryid, IGNORE_MISSING);
if ($coursecat) {
$categoryids[] = $categoryid;
if ($template->includesubcategories) {
$categoryids = array_merge($categoryids, $coursecat->get_all_children_ids());
if ($template->categoryids) {
$rootcategoryids = json_decode($template->categoryids, true);
if (is_array($rootcategoryids)) {
foreach ($rootcategoryids as $categoryid) {
$coursecat = \core_course_category::get($categoryid, IGNORE_MISSING);
if ($coursecat) {
$categoryids[] = $categoryid;
if ($template->includesubcategories) {
$categoryids = array_merge($categoryids, $coursecat->get_all_children_ids());
}
}
}
}
Expand All @@ -132,7 +134,12 @@ public function get_templates() {
}
}

$template->description_formatted = format_text($template->description, $template->description_format);
$template->description_formatted = format_text(file_rewrite_pluginfile_urls($template->description,
'pluginfile.php',
\context_system::instance()->id,
'format_kickstart',
'description',
$template->id), $template->descriptionformat);
$tags = [];
foreach (\core_tag_tag::get_item_tags('format_kickstart', 'format_kickstart_template', $template->id) as $tag) {
$tags[] = '#' . $tag->get_display_name(false);
Expand Down
4 changes: 2 additions & 2 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace format_kickstart\output;

use plugin_renderer_base;
use core_courseformat\output\section_renderer;
use renderable;

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

/**
* Overrides the parent so that templatable widgets are handled even without their explicit render method.
Expand Down
16 changes: 15 additions & 1 deletion classes/template_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ public function col_tags($data) {
null, 'template-tags');
}

/**
* Generate description.
* @param \stdClass $data
* @return mixed
*/
public function col_description($data) {
$context = \context_system::instance();
return format_text(file_rewrite_pluginfile_urls($data->description,
'pluginfile.php',
$context->id,
'format_kickstart',
'description',
$data->id), $data->descriptionformat);
}

/**
* Get any extra classes names to add to this row in the HTML.
*
Expand Down Expand Up @@ -191,7 +206,6 @@ public function col_actions($data) {
*/
public function query_db($pagesize, $useinitialsbar = true) {
global $DB, $CFG;

list($wsql, $params) = $this->get_sql_where();
if ($wsql) {
$wsql = 'AND ' . $wsql;
Expand Down
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="description" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="description_format" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="preview_url" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Link to preview template"/>
<FIELD NAME="restrictcohort" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="restrictcategory" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false"/>
Expand Down
16 changes: 13 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ function xmldb_format_kickstart_upgrade($oldversion) {

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

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

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

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

if ($oldversion < 2023071101) {
$table = new xmldb_table('format_kickstart_template');
$field = new xmldb_field('description_format', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'description');
if ($dbman->field_exists($table, $field)) {
$dbman->rename_field($table, $field, 'descriptionformat');
}
// Kickstart savepoint reached.
upgrade_plugin_savepoint(true, 2023071101, 'format', 'kickstart');
}

format_kickstart_import_courseformat_template();

return true;
Expand Down
2 changes: 1 addition & 1 deletion freetemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'includesubcategories' => 0,
'restrictrole' => 0,
'roleids' => [],
'description_format' => 1,
'descriptionformat' => 1,
),
];

2 changes: 1 addition & 1 deletion lang/en/format_kickstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
$string['description'] = 'Description';
$string['edit'] = 'Edit';
$string['edit_template'] = 'Edit template';
$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.';
$string['enrollmenthelp'] = 'Before continuing you may enroll teachers (or any users). Click <b>Proceed to course content</b> to choose a template to import.';
$string['general_settings'] = 'General settings';
$string['getpro'] = 'Get more templates with Kickstart Pro';
$string['goprotoenable'] = 'Go Pro to enable';
Expand Down
27 changes: 27 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,30 @@ function format_kickstart_get_designer_coursetypes() {
return $coursetypes;
}
}


/**
* Serves file from.
*
* @param mixed $course course or id of the course
* @param mixed $cm course module or id of the course module
* @param context $context Context used in the file.
* @param string $filearea Filearea the file stored
* @param array $args Arguments
* @param bool $forcedownload Force download the file instead of display.
* @param array $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - just send the file
*/
function format_kickstart_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
require_login();
if ($context->contextlevel != CONTEXT_SYSTEM && $filearea != 'description') {
return false;
}

$fs = get_file_storage();
$file = $fs->get_file($context->id, 'format_kickstart', $filearea, $args[0], '/', $args[1]);
if (!$file) {
return false;
}
send_stored_file($file, 0, 0, 0, $options);
}
28 changes: 25 additions & 3 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ body.format-kickstart .form-control .fa-search {
border: 1px solid rgba(0, 0, 0, .125);
margin-bottom: .5rem;
}

.format-kickstart .course-content > a {
float: right;
}
.format-kickstart .card-deck .carousel-inner {
display: flex;
margin-bottom: .5rem;
Expand Down Expand Up @@ -121,7 +123,19 @@ body.format-kickstart .form-control .fa-search {
flex: 1 1 auto;
padding: 1.25rem;
}

.format-kickstart .card-body .card-title {
margin-top: 10px;
margin-bottom: 0;
}
.format-kickstart .course-content > .card .card-body {
text-align: right;
}
.format-kickstart .course-content > .card .card-body .card-title {
text-align: left;
margin-top: 5px;
margin-bottom: 9px;
margin-right: 5px;
}
.format-kickstart .card-footer {
padding: .75rem 1.25rem;
background-color: rgba(0, 0, 0, .03);
Expand All @@ -136,8 +150,10 @@ body.format-kickstart .form-control .fa-search {
.mform > .form-group {
margin-left: 1.5rem;
}
.format-kickstart .course-content > .card .card-body .card-title {
float: left;
}
}

body#page-course-format-kickstart-template.template-designer-format #fitem_id_coursetype {
display: none;
}
Expand Down Expand Up @@ -200,4 +216,10 @@ body#page-course-format-kickstart-template.template-designer-format #fitem_id_co
}
.format-kickstart .course-content .kickstart-list-view .templates-block .card .card-footer a.btn-outline-primary {
margin-left: 10px;
}
#page-admin-course-format-kickstart-templates .generaltable tbody tr td .singlebutton {
margin-right: 10px;
}
#page-admin-course-format-kickstart-templates .generaltable tbody tr td .singlebutton + .singlebutton {
margin: 10px 0;
}
Loading

0 comments on commit dd0f7c7

Please sign in to comment.