Skip to content

Commit

Permalink
Update codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
luukverhoeven committed Nov 16, 2023
1 parent 3e2a083 commit 808de01
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 72 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ Types of changes
* **Fixed** for any bug fixes.
* **Security** in case of vulnerabilities.

## Version (4.1.2) - 2023-03-19

##### Updated

- Refactor to block_quickcourselist
- Fix behat
- Fix code guidelines
- Fix issues with query `splitterms` setting


## Version (4.1.1) - 2023-03-19

- 4.1 / PHP 80 check - no issues found
Expand Down
121 changes: 66 additions & 55 deletions block_quickcourselist.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later till v2.1, for other versions Freeware
* https://ltnc.nl/ltc-plugin-freeware-licentie
*/
defined('MOODLE_INTERNAL') || die;

/**
* Class definition for the Quick Course List Block
Expand All @@ -40,6 +39,21 @@ class block_quickcourselist extends block_base {
*/
private $globalconf;

/**
* get_sql_like_fields
*
* @return string
*/
private static function get_sql_like_fields(): string {
global $DB;

return ' AND ' .
'(' . $DB->sql_like('shortname', '?', false) .
' OR ' . $DB->sql_like('fullname', '?', false) .
' OR ' . $DB->sql_like('idnumber', '?', false) .
')';
}

/**
* @return void
*/
Expand Down Expand Up @@ -90,17 +104,19 @@ public function get_content() {
}

$this->content = new stdClass();
$context_block = context_block::instance($this->instance->id);
$contextblock = context_block::instance($this->instance->id);
$search = optional_param('efquicklistsearch', '', PARAM_TEXT);
$quickcoursesubmit = optional_param('quickcoursesubmit', false, PARAM_TEXT);
if (has_capability('block/quickcourselist:use', $context_block)) {
if (has_capability('block/quickcourselist:use', $contextblock)) {

$list_contents = '';
// TODO mustache template.
$listcontents = '';
$anchor = html_writer::tag('a', '', ['name' => 'efquicklistanchor']);
$inputattrs = [
'autocomplete' => 'off',
'name' => 'efquicklistsearch',
'id' => 'efquicklistsearch',
'class' => 'form-control',
'value' => $search,
];
$input = html_writer::empty_tag('input', $inputattrs);
Expand Down Expand Up @@ -130,52 +146,51 @@ public function get_content() {

$courses = self::get_courses(
$search,
$context_block,
$contextblock,
$this->globalconf->splitterms,
$this->globalconf->restrictcontext,
$this->page->context
);
if (!empty($courses)) {
foreach ($courses as $course) {
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
$resultstr = null;
if (isset($this->globalconf->displaymode)) {
$displaymode = $this->globalconf->displaymode;
} else {
$displaymode = 3;
}
switch ($displaymode):
case 1:
$resultstr = $course->shortname;
break;
case 2:
$resultstr = $course->fullname;
break;
case 5:
$resultstr = $course->fullname . ' - ' . $course->category;
break;
case 6:
$resultstr = $course->shortname . ' - ' . $course->fullname . ' - ' . $course->category;
break;
default:
$resultstr = $course->shortname . ': ' . $course->fullname;
break;
endswitch;

$link = html_writer::tag(
'a',
$resultstr,
['href' => $url->out()]
);
$li = html_writer::tag('li', $link);
$list_contents .= $li;

foreach ($courses as $course) {
$url = new moodle_url('/course/view.php', ['id' => $course->id]);
$resultstr = null;
if (isset($this->globalconf->displaymode)) {
$displaymode = $this->globalconf->displaymode;
} else {
$displaymode = 3;
}
switch ($displaymode):
case 1:
$resultstr = $course->shortname;
break;
case 2:
$resultstr = $course->fullname;
break;
case 5:
$resultstr = $course->fullname . ' - ' . $course->category;
break;
case 6:
$resultstr = $course->shortname . ' - ' . $course->fullname . ' - ' . $course->category;
break;
default:
$resultstr = $course->shortname . ': ' . $course->fullname;
break;
endswitch;

$link = html_writer::tag(
'a',
$resultstr,
['href' => $url->out()]
);
$li = html_writer::tag('li', $link);
$listcontents .= $li;
}
}
if (!isset($this->globalconf->displaymode)) {
$this->globalconf->displaymode = '3';
}
$list = html_writer::tag('ul', $list_contents, ['id' => 'quickcourselist']);
$list = html_writer::tag('ul', $listcontents, ['id' => 'quickcourselist']);

$this->content->text = $anchor . $form . $list;

Expand Down Expand Up @@ -222,27 +237,23 @@ public static function get_courses(
): moodle_recordset {
global $DB;
$params = [SITEID];
$where = 'id != ? AND (';
$where = 'id != ? ';
if ($splitterms) {
$terms = explode(' ', $search);
$like = '%1$s LIKE';
foreach ($terms as $key => $term) {
$like .= ' ?';
if ($key < count($terms) - 1) {
$like .= ' AND %1$s LIKE';
}
$terms[$key] = '%' . $term . '%';
foreach ($terms as $term) {
$where .= self::get_sql_like_fields();
$params[] = '%' . $term . '%';
$params[] = '%' . $term . '%';
$params[] = '%' . $term . '%';
}
$params = array_merge($params, $terms);
$where .= sprintf($like, 'shortname')
. ' OR ' . sprintf($like, 'fullname')
. ' OR ' . sprintf($like, 'idnumber');

} else {
$params = array_merge($params, ["%$search%", "%$search%", "%$search%"]);
$where .= 'shortname LIKE ? OR fullname LIKE ? OR idnumber like ? ';
$where .= self::get_sql_like_fields();
$params[] = '%' . $search . '%';
$params[] = '%' . $search . '%';
$params[] = '%' . $search . '%';
}
$where .= ')';

if (!has_capability('moodle/course:viewhiddencourses', $blockcontext)) {
$where .= ' AND visible=1';
}
Expand Down
8 changes: 3 additions & 5 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@
*
* @license https://ltnc.nl/ltc-plugin-freeware-licentie
*
* @package moodle-block_quickcourselist
* @package block_quickcourselist
* @copyright 2018-11-20 MFreak.nl
* @author Luuk Verhoeven
**/

namespace block_quickcourselist\privacy;

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

/**
* Privacy Subsystem for block_quickcourselist implementing null_provider.
*
* @package moodle-block_quickcourselist
* @package block_quickcourselist
* @copyright 2018-11-20 MFreak.nl
* @author Luuk Verhoeven
*/
Expand All @@ -47,4 +45,4 @@ public static function get_reason(): string {
return 'privacy:metadata';
}

}
}
3 changes: 1 addition & 2 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
],
'block/quickcourselist:addinstance' => [
'riskbitmask' => RISK_SPAM | RISK_XSS,

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => [
Expand All @@ -59,4 +58,4 @@
],
'clonepermissionsfrom' => 'moodle/site:manageblocks',
],
];
];
7 changes: 6 additions & 1 deletion module.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/**
* TODO should be converted to AMD module
* @type {{init: M.block_quickcourselist.init, search: M.block_quickcourselist.search, sesskey: null}}
*/
M.block_quickcourselist = {

sesskey: null,

/**
* Init
* TODO should be converted to web service in the future
*
* @param Y
* @param instanceid
Expand Down Expand Up @@ -39,7 +44,7 @@ M.block_quickcourselist = {
search: function(string) {

var Y = this.Y;
uri = M.cfg.wwwroot + '/blocks/quickcourselist/quickcourse.php';
uri = M.cfg.wwwroot + '/blocks/quickcourselist/quickcourselist.php';
if (this.xhr != null) {
this.xhr.abort();
}
Expand Down
3 changes: 2 additions & 1 deletion quickcourselist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* Server-side script for generating response to AJAX search request
* TODO should be rewritten to use Moodle's external API
*
* @package block_quickcourselist
* @author Mark Johnson <[email protected]> v2.0
Expand All @@ -27,10 +28,10 @@
* https://ltnc.nl/ltc-plugin-freeware-licentie
*/

//define('AJAX_SCRIPT', true);
require_once('../../config.php');
defined('MOODLE_INTERNAL') || die;

require_login();
require_once($CFG->dirroot . '/blocks/moodleblock.class.php');
require_once($CFG->dirroot . '/blocks/quickcourselist/block_quickcourselist.php');

Expand Down
16 changes: 14 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand All @@ -9,12 +8,25 @@
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Setting page for the Quick Course List block
*
* @package block_quickcourselist
* @author Mark Johnson <[email protected]> v2.0
* @author Onno Schuit v2.1 commissioned by Lesterhuis Training en Consultancy
* @author Luuk Verhoeven v3.8 to 3.10.1 commissioned by Lesterhuis Training en Consultancy
* @author Gemma Lesterhuis v3.10.2 commissioned by Lesterhuis Training en Consultancy
* @copyright 2010 Tauntons College, UK v2.0 and Lesterhuis Training en Consultancy v2.1 and further
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later till v2.1, for other versions Freeware
* https://ltnc.nl/ltc-plugin-freeware-licentie
*/

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

if ($ADMIN->fulltree) {
Expand Down
6 changes: 1 addition & 5 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ body.jsenabled .block_quickcourselist .submitbutton {
border-bottom-style: solid;
border-bottom-width: 1px;
border-bottom-color: #d3d3d3;
}

#efquicklistsearch {
width: 120px;
}
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
$plugin->component = 'block_quickcourselist';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '4.1.2';
$plugin->supported = [39, 402];
$plugin->supported = [39, 402];

0 comments on commit 808de01

Please sign in to comment.