Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
defined('MOODLE_INTERNAL') || die();
class block_hshcourselist extends block_base {
private $globalconf;
public function init() {
$this->globalconf = get_config('block_hshcourselist');
$this->title = get_string('default_blocktitle', 'block_hshcourselist');
}
//stop it showing up on any add block lists
public function applicable_formats() {
return (array(
'all' => false,
'site' => true,
'my' => true,
'course-index' => true
));
}
public function has_config() {
return true;
}
public function get_content() {
global $CFG, $DB;
$this->page->requires->js('/blocks/hshcourselist/javascript/jquery-3.2.0.min.js');
$this->page->requires->js('/blocks/hshcourselist/javascript/listselect.js');
$this->page->requires->css('/blocks/hshcourselist/style.css');
if ($this->content !== null) {
return $this->content;
}
$this->content = new stdClass();
$context_block = context_block::instance($this->instance->id);
$search = optional_param('hshcoursesearch', '', PARAM_TEXT);
$hshcoursesubmit = optional_param('hshcoursesubmit', false, PARAM_TEXT);
$list_contents = '';
$anchor = html_writer::tag('a', '', array('name' => 'hshcourselistanchor'));
$ordercheckbox = html_writer::empty_tag('input', array('type' => 'checkbox', 'name' => 'orderbysemestercheckbox', 'id' => 'orderbysemestercheckbox_id'));
$ordercheckbox .= html_writer::start_tag('label', array('for' => 'orderbysemestercheckbox_id'));
$ordercheckbox .= get_string('orderbysemester', 'block_hshcourselist');
$ordercheckbox .= html_writer::end_tag('label');
$idSearchinglabel = html_writer::empty_tag('p', array('class' => 'idSarchingLabel'));
$idSearchinglabel .= get_string('idSearchingLabel', 'block_hshcourselist');
$idSearchinglabel .= html_writer::end_tag('p');
$inputattrs = array(
'autocomplete' => 'off',
'name' => 'hshcourselistsearch',
'id' => 'hshcourselistsearch',
'class' => 'form-control',
'value' => $search
);
$input = html_writer::empty_tag('input', $inputattrs);
$progressattrs = array(
'src' => $this->page->theme->pix_url('i/loading_small', 'moodle'),
'class' => 'hshcourseprogress',
'id' => 'hshcourseprogress',
'alt' => get_string('loading', 'block_hshcourselist')
);
$progress = html_writer::empty_tag('img', $progressattrs);
$formattrs = array(
'id' => 'hshcourseform',
'method' => 'post',
'name' => 'hshcourselistform',
//'action' => $this->page->url->out().'#hshcourselistanchor'
'action' => new moodle_url('/')
);
$form = html_writer::tag('form', $idSearchinglabel.$ordercheckbox.$input.$progress, $formattrs);
if (!empty($hshcoursesubmit)) {
$courses = self::get_courses($search, $context_block, $this->globalconf->splitterms,
$this->globalconf->restrictcontext, $this->page->context,
$this->globalconf->idSearching, $this->config->orderbysemester);
if (!empty($courses)) {
foreach ($courses as $course) {
$url = new moodle_url('/course/view.php', array('id' => $course->id));
$resultstr = null;
if (!empty($this->config->displaymode)) {
$displaymode = $this->config->displaymode;
} else {
$displaymode = 2;
}
switch ($displaymode):
case 1: $resultstr = $course->shortname; break;
case 2: $resultstr = $course->fullname; break;
default: $resultstr = $course->shortname.': '.$course->fullname; break;
endswitch;
$link = html_writer::tag('a', $resultstr, array('href' => $url->out()));
$li = html_writer::tag('li', $link);
$list_contents .= $li;
}
}
}
$list = html_writer::tag('ul', $list_contents, array('id' => 'hshcourselistul'));
$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(
'instanceid' => $this->instance->id,
'sesskey' => sesskey(),

Tobias Baden
committed
/*
Notice: Trying to get property of non-object in C:\Dev\xampp\htdocs\moodle\blocks\hshcourselist\block_hshcourselist.php on line 117 (122)
Notice: Trying to get property of non-object in C:\Dev\xampp\htdocs\moodle\blocks\hshcourselist\block_hshcourselist.php on line 118 (123)
*/
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'displaymode' => $this->config->displaymode,
'orderbysemester' => $this->config->orderbysemester,
'contextid' => $this->page->context->id
);
$this->page->requires->js_call_amd('block_hshcourselist/jmodule', 'init', array($jsdata));
//Einstellungen für den Custom-Footer
if (!empty($this->config->footer) && $this->config->enablefooter) {
$this->content->footer = $this->config->footer;
}
//Einstellungen für den Custom-Header
if (!empty($this->config->title) && $this->config->enablecustomheader) {
$this->title = $this->config->title;
}
return $this->content;
}
public static function get_courses($search, $blockcontext, $splitterms = false, $restrictcontext = false, $pagecontext = null, $idSearch, $orderbysemester) {
global $DB;
$params = array(SITEID);
$where = 'id != ? AND (';
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.'%';
}
$params = array_merge($params, $terms, $terms);
$where .= sprintf($like, 'shortname').' OR '.sprintf($like, 'fullname');
} else {
if($idSearch) {
$params = array_merge($params, array($search));
$where .= 'id = ?';
// $where .= 'idnumber LIKE ?'; --- Bei Postgres nur "id"
} else {
$params = array_merge($params, array("%$search%", "%$search%"));

Tobias Baden
committed
$where .= 'shortname ILIKE ? OR fullname ILIKE ?';
}
}
$where .= ')';
if (!has_capability('moodle/course:viewhiddencourses', $blockcontext)) {
$where .= ' AND visible=1';
}
if ($restrictcontext) {
if ($pagecontext && $pagecontext->get_level_name() == get_string('category')) {
$where .= ' AND category = ?';
$params[] = $pagecontext->instanceid;
}
}
if($orderbysemester) {
$order = 'startdate DESC';
} else if($idSearch) {
$order = 'idnumber';
} else {
$order = 'shortname';
}
$fields = 'id, idnumber, shortname, fullname';
$courses = $DB->get_recordset_select('course', $where, $params, $order, $fields);
return $courses;
}
}