Skip to content
Snippets Groups Projects
Commit 457139e2 authored by Tobias Baden's avatar Tobias Baden
Browse files

Fixed and implemented the AND-Search

- Added AND to the search
- Searching only fullname
- Edited the help-desciption
- Removed unused statements
- Renamed some variables
- Updated Version
parent d36b39f0
Branches
Tags
No related merge requests found
/*! hshcourselist 2018-08-29 */ /*! hshcourselist 2018-08-30 */
define(["jquery"],function(a){function b(b,c,d,e,f,g,h,i,j){if(c){var k=b.split(/[ ,]+/),l=["-1"],m=a("<ul class='list-group' id='hshcourselistul'></ul>");a("#hshcourseprogress").show(),k.forEach(function(b){a.ajax({type:"GET",url:j+"/blocks/hshcourselist/hshcourselist.php",data:"course="+b+"&instanceid="+e+"&sesskey="+f+"&contextid="+g+"&idSearching="+h+"&orderbysemester="+i,dataType:"json",success:function(b){var c=JSON.stringify(b),e=JSON.parse(c);e.length>0&&a.each(e,function(b,c){switch(d){case"0":displaystr=c.shortname;break;case"1":displaystr=c.fullname;break;case"2":displaystr=c.shortname+": "+c.fullname;break;default:displaystr=c.fullname}l.includes(c.id)||(l.push(c.id),a('<li class="list-group-item hshcoursesearchlistitem " value="'+c.id+'"><a href="'+j+"/course/view.php?id="+c.id+'">'+displaystr+"</a> </li>").appendTo(m))})},error:function(a){console.error("error - courselist")}})}),void 0!==m&&(a("#hshcourselistul").replaceWith(m),a("#hshcourseprogress").hide())}}return{init:function(c,d){var e,c=c,f=c.instanceid,g=c.sesskey,h=c.displaymode,i=c.contextid,j=!1,k=!1,l=!1,m=c.orderbysemester;a("#hshcourseprogress").hide(),a(".idSarchingLabel").hide(),a("#orderbysemestercheckbox_id").on("change",function(){m=document.getElementById("orderbysemestercheckbox_id").checked,j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)}),a("#hshcourselistsearch").on("keyup",function(c){var n=c.keyCode;m=document.getElementById("orderbysemestercheckbox_id").checked,40!==n&&38!==n&&13!==n&&(j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d))}),a("#hshcourseform").on("submit",function(a){a.preventDefault,j=!0,k=!1,l=!1,m=document.getElementById("orderbysemestercheckbox_id").checked,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:k=!1,(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)})}}}); define(["jquery"],function(a){function b(b,c,d,e,f,g,h,i,j){c&&(a("#hshcourseprogress").show(),a.ajax({type:"GET",url:j+"/blocks/hshcourselist/hshcourselist.php",data:"course="+b+"&instanceid="+e+"&sesskey="+f+"&contextid="+g+"&idSearching="+h+"&orderbysemester="+i,dataType:"json",success:function(b){var c=JSON.stringify(b),e=JSON.parse(c),f=a("<ul class='list-group' id='hshcourselistul'></ul>");e.length>0&&a.each(e,function(b,c){switch(d){case"0":displaystr=c.shortname;break;case"1":displaystr=c.fullname;break;case"2":displaystr=c.shortname+": "+c.fullname;break;default:displaystr=c.fullname}a('<li class="list-group-item hshcoursesearchlistitem " value="'+c.id+'"><a href="'+j+"/course/view.php?id="+c.id+'">'+displaystr+"</a> </li>").appendTo(f)}),a("#hshcourselistul").replaceWith(f),a("#hshcourseprogress").hide()},error:function(a){console.error("error "+JSON.stringify(a))}}))}return{init:function(c,d){var e,c=c,f=c.instanceid,g=c.sesskey,h=c.displaymode,i=c.contextid,j=!1,k=!1,l=!1,m=c.orderbysemester;a("#hshcourseprogress").hide(),a(".idSarchingLabel").hide(),a("#orderbysemestercheckbox_id").on("change",function(){m=document.getElementById("orderbysemestercheckbox_id").checked,j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)}),a("#hshcourselistsearch").on("keyup",function(c){var n=c.keyCode;m=document.getElementById("orderbysemestercheckbox_id").checked,40!==n&&38!==n&&13!==n&&(j=!0,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(a(".idSarchingLabel").show(),k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:(a(".idSarchingLabel").hide(),k=!1),(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d))}),a("#hshcourseform").on("submit",function(a){a.preventDefault,j=!0,k=!1,l=!1,m=document.getElementById("orderbysemestercheckbox_id").checked,e=document.getElementById("hshcourselistsearch").value,"#"===e.slice(0,1)?(k=!0,e=e.slice(1)):"%"===e.slice(0,1)?l=!0:k=!1,(1==l||1==k||e.length>=3)&&b(e,j,h,f,g,i,k,m,d)})}}});
\ No newline at end of file \ No newline at end of file
/*! hshcourselist 2018-08-29 */ /*! hshcourselist 2018-08-30 */
define(["jquery"],function(a){function b(b,c){var d=c+"/course/view.php?id="+b.val();a("#hshcourseform").attr("action",d)}function c(a){a.removeClass("active"),a.removeClass("activeCourseSearch")}function d(a){a.addClass("active"),a.addClass("activeCourseSearch")}function e(a){var b=window.innerHeight,c=a.getBoundingClientRect(),d=c.bottom,e=c.top;d>b&&a.scrollIntoView({block:"end",behavior:"smooth"}),e<0&&a.scrollIntoView({block:"start",behavior:"smooth"})}return{init:function(f){a("input").keydown(function(g){var h,i=a(".hshcoursesearchlistitem"),j=g.keyCode,k=i.filter(".activeCourseSearch");40!==j&&38!==j&&13!==j||(c(i),38===j?(h=!k.length||k.is(":first-child")?i.last():k.prev(),b(h,f)):40===j?(h=!k.length||k.is(":last-child")?i.eq(0):k.next(),b(h,f)):13===j&&(h=k,isNaN(h.val())&&(h=i.eq(0)),b(h,f)),d(h),e(h[0]))})}}}); define(["jquery"],function(a){function b(b,c){var d=c+"/course/view.php?id="+b.val();a("#hshcourseform").attr("action",d)}function c(a){a.removeClass("active"),a.removeClass("activeCourseSearch")}function d(a){a.addClass("active"),a.addClass("activeCourseSearch")}function e(a){var b=window.innerHeight,c=a.getBoundingClientRect(),d=c.bottom,e=c.top;d>b&&a.scrollIntoView({block:"end",behavior:"smooth"}),e<0&&a.scrollIntoView({block:"start",behavior:"smooth"})}return{init:function(f){a("input").keydown(function(g){var h,i=a(".hshcoursesearchlistitem"),j=g.keyCode,k=i.filter(".activeCourseSearch");40!==j&&38!==j&&13!==j||(c(i),38===j?(h=!k.length||k.is(":first-child")?i.last():k.prev(),b(h,f)):40===j?(h=!k.length||k.is(":last-child")?i.eq(0):k.next(),b(h,f)):13===j&&(h=k,isNaN(h.val())&&(h=i.eq(0)),b(h,f)),d(h),e(h.eq(0)))})}}});
\ No newline at end of file \ No newline at end of file
define(['jquery'], function ($) { define(['jquery'], function ($) {
function search(searchstring, reloadBool, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester, wwwroot) { function search(searchstring, reloadBool, displaymode, instanceid, sesskey, contextid, idSearching, orderbysemester, wwwroot) {
if (reloadBool) { if (reloadBool) {
var splittedSearchstring = searchstring.split(/[ ,]+/);
var courseInList = ["-1"];
var list = $("<ul class='list-group' id='hshcourselistul'></ul>");;
$("#hshcourseprogress").show(); $("#hshcourseprogress").show();
splittedSearchstring.forEach(function (searchquery) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: wwwroot + '/blocks/hshcourselist/hshcourselist.php', url: wwwroot + '/blocks/hshcourselist/hshcourselist.php',
data: 'course=' + searchquery + '&instanceid=' + instanceid data: 'course=' + searchstring + '&instanceid=' + instanceid
+ '&sesskey=' + sesskey + '&contextid=' + contextid + '&sesskey=' + sesskey + '&contextid=' + contextid
+ '&idSearching=' + idSearching + '&orderbysemester=' + orderbysemester, + '&idSearching=' + idSearching + '&orderbysemester=' + orderbysemester,
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
var plainJSON = JSON.stringify(response); var plainJSON = JSON.stringify(response);
var courses = JSON.parse(plainJSON); var courses = JSON.parse(plainJSON);
var list = $("<ul class='list-group' id='hshcourselistul'></ul>");
if (courses.length > 0) { if (courses.length > 0) {
$.each(courses, function (index, course) { $.each(courses, function (index, course) {
switch (displaymode) { switch (displaymode) {
case '0': case '0':
displaystr = course.shortname; displaystr = course.shortname;
break; break;
case '1': case '1':
displaystr = course.fullname; displaystr = course.fullname;
break; break;
case '2': case '2':
displaystr = course.shortname + ': ' + course.fullname; displaystr = course.shortname + ': ' + course.fullname;
break; break;
default: default:
displaystr = course.fullname; displaystr = course.fullname;
break; break;
} }
if (!courseInList.includes(course.id)) {
courseInList.push(course.id);
$('<li class="list-group-item hshcoursesearchlistitem " value="' + course.id + '">' $('<li class="list-group-item hshcoursesearchlistitem " value="' + course.id + '">'
+ '<a href="' + wwwroot + '/course/view.php?id=' + course.id + '">' + displaystr + '</a> </li>') + '<a href="' + wwwroot + '/course/view.php?id=' + course.id + '">' + displaystr + '</a> </li>')
.appendTo(list); .appendTo(list);
} else {
// Kurs schon in der Liste
}
}); });
} }
},
error: function (o) {
console.error("error - courselist");
}
});
});
if (list !== undefined) {
$("#hshcourselistul").replaceWith(list); $("#hshcourselistul").replaceWith(list);
$("#hshcourseprogress").hide(); $("#hshcourseprogress").hide();
} else { },
error: function (a) {
console.error("error " + JSON.stringify(a));
} }
});
} else { } else {
} }
} }
......
...@@ -33,41 +33,41 @@ define(['jquery'], function ($) { ...@@ -33,41 +33,41 @@ define(['jquery'], function ($) {
return { return {
init: function (wwwroot) { init: function (wwwroot) {
$('input').keydown(function (e) { $('input').keydown(function (e) {
var $listItems = $('.hshcoursesearchlistitem'); var listItems = $('.hshcoursesearchlistitem');
var selected = listItems.filter('.activeCourseSearch');
var current;
var key = e.keyCode; var key = e.keyCode;
var $selected = $listItems.filter('.activeCourseSearch');
var $current;
if (key !== 40 && key !== 38 && key !== 13) { if (key !== 40 && key !== 38 && key !== 13) {
return; return;
} }
setInactive($listItems); setInactive(listItems);
if (key === 38) { // KEY UP if (key === 38) { // KEY UP
if (!$selected.length || $selected.is(':first-child')) { if (!selected.length || selected.is(':first-child')) {
$current = $listItems.last(); current = listItems.last();
} else { } else {
$current = $selected.prev(); current = selected.prev();
} }
changeActionString($current, wwwroot); changeActionString(current, wwwroot);
} else if (key === 40) { // KEY DOWN } else if (key === 40) { // KEY DOWN
if (!$selected.length || $selected.is(':last-child')) { if (!selected.length || selected.is(':last-child')) {
$current = $listItems.eq(0); current = listItems.eq(0);
} else { } else {
$current = $selected.next(); current = selected.next();
} }
changeActionString($current, wwwroot); changeActionString(current, wwwroot);
} else if (key === 13) { // KEY ENTER } else if (key === 13) { // KEY ENTER
$current = $selected; current = selected;
if (isNaN($current.val())) { if (isNaN(current.val())) {
$current = $listItems.eq(0); current = listItems.eq(0);
} }
changeActionString($current, wwwroot); changeActionString(current, wwwroot);
} }
setActive($current); setActive(current);
scrollIntoViewIfNeeded($current[0]); scrollIntoViewIfNeeded(current.eq(0));
}); });
}, },
} }
......
...@@ -80,7 +80,7 @@ class block_hshcourselist extends block_base { ...@@ -80,7 +80,7 @@ class block_hshcourselist extends block_base {
'data-placement'=>'right', 'data-placement'=>'right',
'data-content'=>"<div class='no-overflow'><p>Die Kurssuche ist eine Volltextsuche in der Sie auch mehrere Suchbegriffe (mit Leerzeichen getrennt) eingeben können.<br/> 'data-content'=>"<div class='no-overflow'><p>Die Kurssuche ist eine Volltextsuche in der Sie auch mehrere Suchbegriffe (mit Leerzeichen getrennt) eingeben können.<br/>
Verschiedene Suchbegriffe werden einzeln in den Kursnamen gesucht und dann eine vollständige Liste angezeigt.<br/> Verschiedene Suchbegriffe werden einzeln in den Kursnamen gesucht und dann eine vollständige Liste angezeigt.<br/>
Bsp: WiSe Programmieren => zeigt Ihnen alle Kurse, dessen Kursname oder Kurskurzname 'WiSe' <i>ODER</i> 'Programmieren' enthalten.</p> Bsp: WiSe Programmieren => zeigt Ihnen alle Kurse, dessen Kursname oder Kurskurzname 'WiSe' <i>UND</i> 'Programmieren' enthalten.</p>
<p>Kurzsuche: Möchten Sie einen Kurs schnell über die <i>'id'</i> finden, so können Sie dies durch das Voranstellen einer Raute <i>'#'</i> erreichen.<br/> <p>Kurzsuche: Möchten Sie einen Kurs schnell über die <i>'id'</i> finden, so können Sie dies durch das Voranstellen einer Raute <i>'#'</i> erreichen.<br/>
Bsp: <i>#3303</i> zeigt Ihnen den Kurs <i>'Moodle Demo-Kurs, ELC'</i></p>", Bsp: <i>#3303</i> zeigt Ihnen den Kurs <i>'Moodle Demo-Kurs, ELC'</i></p>",
'data-html'=>'true', 'data-html'=>'true',
...@@ -109,7 +109,6 @@ class block_hshcourselist extends block_base { ...@@ -109,7 +109,6 @@ class block_hshcourselist extends block_base {
'id' => 'hshcourseform', 'id' => 'hshcourseform',
'method' => 'post', 'method' => 'post',
'name' => 'hshcourselistform', 'name' => 'hshcourselistform',
//'action' => $this->page->url->out().'#hshcourselistanchor'
'action' => new moodle_url('/') 'action' => new moodle_url('/')
); );
...@@ -154,11 +153,6 @@ class block_hshcourselist extends block_base { ...@@ -154,11 +153,6 @@ class block_hshcourselist extends block_base {
$list = html_writer::tag('ul', $list_contents, array('id' => 'hshcourselistul')); $list = html_writer::tag('ul', $list_contents, array('id' => 'hshcourselistul'));
$this->content->text = $anchor.$form.$list; $this->content->text = $anchor.$form.$list;
$jsmodule = array(
'name' => 'block_hshcourselist',
'fullpath' => '/blocks/hshcourselist/javascript/jmodule.js',
'requires' => array('base', 'node', 'json', 'io')
);
$jsdata = array( $jsdata = array(
'instanceid' => $this->instance->id, 'instanceid' => $this->instance->id,
'sesskey' => sesskey(), 'sesskey' => sesskey(),
...@@ -184,6 +178,10 @@ class block_hshcourselist extends block_base { ...@@ -184,6 +178,10 @@ class block_hshcourselist extends block_base {
public static function get_courses($search, $blockcontext, $splitterms = false, $restrictcontext = false, $pagecontext = null, $idSearch, $orderbysemester) { public static function get_courses($search, $blockcontext, $splitterms = false, $restrictcontext = false, $pagecontext = null, $idSearch, $orderbysemester) {
global $DB; global $DB;
$params = array(SITEID); $params = array(SITEID);
$keywordArray = explode(" ", $search);
foreach($keywordArray as $key => $value) {
$keywordArray[$key] = "%".$keywordArray[$key]."%";
}
$where = 'id != ? AND ('; $where = 'id != ? AND (';
if ($splitterms) { if ($splitterms) {
$terms = explode(' ', $search); $terms = explode(' ', $search);
...@@ -201,10 +199,12 @@ class block_hshcourselist extends block_base { ...@@ -201,10 +199,12 @@ class block_hshcourselist extends block_base {
if($idSearch) { if($idSearch) {
$params = array_merge($params, array($search)); $params = array_merge($params, array($search));
$where .= 'id = ?'; $where .= 'id = ?';
// $where .= 'idnumber LIKE ?'; --- Bei Postgres nur "id"
} else { } else {
$params = array_merge($params, array("%$search%", "%$search%")); $params = array_merge($params, $keywordArray);
$where .= 'shortname ILIKE ? OR fullname ILIKE ?'; $where .= 'fullname ILIKE ?';
for ($i = 0; $i <= count($keywordArray)-2; $i++) {
$where .= ' AND fullname ILIKE ?';
}
} }
} }
$where .= ')'; $where .= ')';
......
<?php <?php
$plugin->component = 'block_hshcourselist'; $plugin->component = 'block_hshcourselist';
$plugin->version = 2018083000; // YYYYMMDDHH $plugin->version = 2018082902; // YYYYMMDDHH
$plugin->requires = 2016112900; // YYYYMMDDHH $plugin->requires = 2016112900; // YYYYMMDDHH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment