Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
SACC.
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Apr 27, 2018
1 parent fd30bc0 commit 0be3ff3
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 46 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ New in 3.2.1.5
- FIX: Issue #862: Missing folder icon in courses list since commit 77abc460.
- FIX: Improved course content search so that will work with $CFG->themedir.
- FIX: Alert close icon in alternative colour schemes.
- NEW: Added 'Search all course content' checkbox user preference to search all course content or only the course
title when performing a 'Course search' on the dashboard. Thanks to "Linnaeus University" for funding this
enhancement.

New in 3.2.1.4
==============
Expand Down
1 change: 1 addition & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Daniel Méthot - e-learning-facile.com/formations/
Floyd Saner, Learning Contexts, LLC
Gemma Lesterhuis
Mihai Bojonca, TCM International Institute
Amigos Library Services

If you are a valued sponsor and have not already told me, please could you state if you would like a credit here and if so what
would you like. Please contact via my 'Moodle profile' above.
Expand Down
2 changes: 1 addition & 1 deletion amd/build/inspector_scourer.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
*/
/* jshint ignore:start */
define(["jquery","jqueryui","core/log"],function(a,b,c){"use strict";// jshint ;_;
return c.debug("Essential Inspector Scourer AMD initialised"),{init:function(b){a(document).ready(function(a){c.debug("Essential Inspector Scourer AMD init"),c.debug("Essential Inspector Scourer AJAX File: "+b.theme),a("#courseitemsearch").autocomplete({source:b.theme,appendTo:"#courseitemsearchresults",minLength:2,select:function(a,b){var c=b.item.id;"#"!=c&&(location.href=c)}}).prop("disabled",!1)})}}});
return c.debug("Essential Inspector Scourer AMD initialised"),{init:function(b){a(document).ready(function(a){c.debug("Essential Inspector Scourer AMD init"),c.debug("Essential Inspector Scourer AJAX URL: "+b.theme),a("#courseitemsearch").autocomplete({source:b.theme,appendTo:"#courseitemsearchresults",minLength:2,select:function(a,b){var c=b.item.id;"#"!=c&&(location.href=c)}}).prop("disabled",!1),a("#courseitemsearchtype").click(function(){var d=0|a(this).prop("checked");c.debug("Essential Inspector Scourer AJAX SACC: "+d),a.ajax({url:b.theme+"&pref=courseitemsearchtype&value="+d,statusCode:{404:function(){c.debug("Essential Inspector Scourer AJAX SACC - url not found")},406:function(){c.debug("Essential Inspector Scourer AJAX SACC - value not acceptable")}}})}),a("#courseitemsearchtype").prop("disabled",!1)})}}});
19 changes: 18 additions & 1 deletion amd/src/inspector_scourer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define(['jquery', 'jqueryui', 'core/log'], function($, jqui, log) {
$(document).ready(function($) {

log.debug('Essential Inspector Scourer AMD init');
log.debug('Essential Inspector Scourer AJAX File: ' + data.theme);
log.debug('Essential Inspector Scourer AJAX URL: ' + data.theme);

$("#courseitemsearch").autocomplete({
source: data.theme,
Expand All @@ -32,6 +32,23 @@ define(['jquery', 'jqueryui', 'core/log'], function($, jqui, log) {
}
}
}).prop("disabled", false);
$("#courseitemsearchtype").click(function(){
var $checked = $(this).prop("checked") | 0; // Convert to integer from true or false.
log.debug('Essential Inspector Scourer AJAX SACC: ' + $checked);

$.ajax({
url: data.theme + '&pref=courseitemsearchtype&value=' + $checked,
statusCode: {
404: function() {
log.debug("Essential Inspector Scourer AJAX SACC - url not found");
},
406: function() {
log.debug("Essential Inspector Scourer AJAX SACC - value not acceptable");
}
}
});
});
$("#courseitemsearchtype").prop("disabled", false);
});
}
};
Expand Down
97 changes: 55 additions & 42 deletions classes/core_course_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,53 +310,66 @@ public function inspector_ajax($term) {
$courses[$remoteid] = $val;
}

if (empty($courses)) {
return $data;
}

$courseitemsearchtype = \get_user_preferences('theme_essential_courseitemsearchtype');
$sesskey = sesskey();
foreach ($courses as $course) {
$modinfo = get_fast_modinfo($course);
$courseformat = course_get_format($course->id);
$course = $courseformat->get_course();
$courseformatsettings = $courseformat->get_format_options();
$sesskey = sesskey();

foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if (!$thissection->uservisible) {
continue;
}
if (is_object($thissection)) {
$thissection = $modinfo->get_section_info($thissection->section);
} else {
$thissection = $modinfo->get_section_info($thissection);
if (!$courseitemsearchtype) {
$label = $course->fullname;
if (stristr($label, $term)) {
$courseurl = new moodle_url('/course/view.php', array('id' => $course->id, 'sesskey' => $sesskey));
$data[] = array('id' => $courseurl->out(false), 'label' => $label, 'value' => $label);
}
if ((string) $thissection->name !== '') {
$sectionname = format_string($thissection->name, true,
array('context' => context_course::instance($course->id)));
} else {
$sectionname = $courseformat->get_section_name($thissection->section);
}
if ($thissection->section <= $course->numsections) {
// Do not link 'orphaned' sections.
$courseurl = new moodle_url('/course/view.php');
$courseurl->param('id', $course->id);
$courseurl->param('sesskey', $sesskey);
if ((!empty($courseformatsettings['coursedisplay'])) &&
($courseformatsettings['coursedisplay'] == COURSE_DISPLAY_MULTIPAGE)) {
$courseurl->param('section', $thissection->section);
$coursehref = $courseurl->out(false);
} else {
$modinfo = get_fast_modinfo($course);
$courseformat = course_get_format($course->id);
$course = $courseformat->get_course();
$courseformatsettings = $courseformat->get_format_options();

foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if (!$thissection->uservisible) {
continue;
}
if (is_object($thissection)) {
$thissection = $modinfo->get_section_info($thissection->section);
} else {
$coursehref = $courseurl->out(false).'#section-'.$thissection->section;
$thissection = $modinfo->get_section_info($thissection);
}
$label = $course->fullname.' - '.$sectionname;
if (stristr($label, $term)) {
$data[] = array('id' => $coursehref, 'label' => $label, 'value' => $label);
if ((string) $thissection->name !== '') {
$sectionname = format_string($thissection->name, true,
array('context' => context_course::instance($course->id)));
} else {
$sectionname = $courseformat->get_section_name($thissection->section);
}
}
if (!empty($modinfo->sections[$thissection->section])) {
foreach ($modinfo->sections[$thissection->section] as $modnumber) {
$mod = $modinfo->cms[$modnumber];
if (!empty($mod->url)) {
$instancename = $mod->get_formatted_name();
$label = $course->fullname.' - '.$sectionname.' - '.$instancename;
if (stristr($label, $term)) {
$data[] = array('id' => $mod->url->out(false), 'label' => $label, 'value' => $label);
if ($thissection->section <= $course->numsections) {
// Do not link 'orphaned' sections.
$courseurl = new moodle_url('/course/view.php');
$courseurl->param('id', $course->id);
$courseurl->param('sesskey', $sesskey);
if ((!empty($courseformatsettings['coursedisplay'])) &&
($courseformatsettings['coursedisplay'] == COURSE_DISPLAY_MULTIPAGE)) {
$courseurl->param('section', $thissection->section);
$coursehref = $courseurl->out(false);
} else {
$coursehref = $courseurl->out(false).'#section-'.$thissection->section;
}
$label = $course->fullname.' - '.$sectionname;
if (stristr($label, $term)) {
$data[] = array('id' => $coursehref, 'label' => $label, 'value' => $label);
}
}
if (!empty($modinfo->sections[$thissection->section])) {
foreach ($modinfo->sections[$thissection->section] as $modnumber) {
$mod = $modinfo->cms[$modnumber];
if (!empty($mod->url)) {
$instancename = $mod->get_formatted_name();
$label = $course->fullname.' - '.$sectionname.' - '.$instancename;
if (stristr($label, $term)) {
$data[] = array('id' => $mod->url->out(false), 'label' => $label, 'value' => $label);
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ public function course_content_header($onlyifnotcalledbefore = false) {
$content .= '<div><p>'.get_string('findcoursecontent', 'theme_essential').'</p></div>';
$content .= '<div id="courseitemsearchresults">';
$content .= '<input type="text" name="courseitemsearch" id="courseitemsearch" disabled="disabled">';
$content .= '<input type="checkbox" name="courseitemsearchtype" id="courseitemsearchtype" disabled="disabled"';
$searchallcoursecontentdefault = 0;
if ($this->get_setting('searchallcoursecontentdefault')) {
$searchallcoursecontentdefault = 1;
}
$courseitemsearchtype = get_user_preferences('theme_essential_courseitemsearchtype', $searchallcoursecontentdefault);
if ($courseitemsearchtype) {
$content .= ' checked';
}
$content .= '><label for="courseitemsearchtype">'.get_string('searchallcoursecontent', 'theme_essential').'</label>';
$content .= '</div></div>';
}
}
Expand Down
30 changes: 30 additions & 0 deletions classes/toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ static public function course_content_search() {
$inspectorscourerdata = array('data' => array('theme' => $essentialsearch->out(false)));
$PAGE->requires->js_call_amd('theme_essential/inspector_scourer', 'init', $inspectorscourerdata);

\user_preference_allow_ajax_update('theme_essential_courseitemsearchtype', PARAM_INT);

$canwe = true;
}
return $canwe;
Expand All @@ -137,6 +139,34 @@ static public function process_content_search() {

die();
}

$pref = \optional_param('pref', '', PARAM_TEXT);
if (($pref) && ($pref == 'courseitemsearchtype')) {
// Autocomplete AJAX user preference call.
global $CFG;

// Might be overkill but would probably stop DOS attack from lots of DB reads.
\require_sesskey();

if ($CFG->forcelogin) {
\require_login();
}

$value = \optional_param('value', '', PARAM_INT);

// Update.
if (($value == 0) || ($value == 1)) {
if (!\set_user_preference('theme_essential_courseitemsearchtype', $value)) {
print_error('errorsettinguserpref');
}
echo 'OK';
} else {
header('HTTP/1.1 406 Not Acceptable');
echo 'Not Acceptable';
}

die();
}
}

static private function check_corerenderer() {
Expand Down
7 changes: 5 additions & 2 deletions lang/en/theme_essential.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,11 @@
// Incourse.
$string['returntosection'] = 'Return to: {$a->section}';

// Course content search.
$string['findcoursecontent'] = 'Course content: ';
// Course fullname and course content search.
$string['findcoursecontent'] = 'Course search: ';
$string['searchallcoursecontent'] = 'Search all course content';
$string['searchallcoursecontentdefault'] = 'Default search all course content';
$string['searchallcoursecontentdefaultdesc'] = 'Sets the value of the \'Search all course content\' checkbox on the course content search. If \'Search all course content\' is unticked, then only the course fullname is searched for a match.';

// essential_admin_setting_configinteger.
$string['asconfigintlower'] = '{$a->value} is less than the lower range limit of {$a->lower}';
Expand Down
4 changes: 4 additions & 0 deletions less/essential/autocomplete.less
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
top: 0;
left: 0;
}
#courseitemsearchtype {
margin-bottom: 0;
margin-left: 4px;
}
}

/* @end */
8 changes: 8 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@
$setting->set_updatedcallback('theme_reset_all_caches');
$essentialsettingsfeature->add($setting);

// Course content search type default.
$name = 'theme_essential/searchallcoursecontentdefault';
$title = get_string('searchallcoursecontentdefault', 'theme_essential');
$description = get_string('searchallcoursecontentdefaultdesc', 'theme_essential');
$default = true;
$setting = new admin_setting_configcheckbox($name, $title, $description, $default, true, false);
$essentialsettingsfeature->add($setting);

// Custom scrollbars.
$name = 'theme_essential/customscrollbars';
$title = get_string('customscrollbars', 'theme_essential');
Expand Down
4 changes: 4 additions & 0 deletions style/essential.css
Original file line number Diff line number Diff line change
Expand Up @@ -19617,6 +19617,10 @@ table.ygtvtable td a {
top: 0;
left: 0;
}
.courseitemsearch #courseitemsearchtype {
margin-bottom: 0;
margin-left: 4px;
}
/* @end */
/* @group Blocks */
.block {
Expand Down

0 comments on commit 0be3ff3

Please sign in to comment.