Skip to content

Commit

Permalink
Issue #10 - Implementation of faculty search.
Browse files Browse the repository at this point in the history
  • Loading branch information
nhoobin committed Sep 22, 2016
1 parent 0ea8887 commit d0a3c52
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 11 deletions.
18 changes: 13 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
$stateid = optional_param('state', 0, PARAM_INT);
$contextid = optional_param('contextid', 0, PARAM_INT);
$search = optional_param('search', '', PARAM_RAW); // Make sure it is processed with p() or s() when sending to output!
$faculty = optional_param('faculty', '', PARAM_RAW); // Make sure it is processed with p() or s() when sending to output!

$PAGE->set_url('/local/extension/index.php', array(
'page' => $page,
Expand All @@ -43,7 +44,8 @@
'catid' => $categoryid,
'state' => $stateid,
'id' => $courseid,
'search' => $search,
'search' => s($search),
'faculty' => s($faculty),
));

require_login();
Expand Down Expand Up @@ -93,13 +95,14 @@

// Should use this variable so that we don't break stuff every time a variable is added or changed.
$baseurl = new moodle_url('/local/extension/index.php', array(
'id' => $courseid,
'catid' => $categoryid,
'search' => s($search)
'id' => $courseid,
'catid' => $categoryid,
'search' => s($search),
'faculty' => s($faculty),
));

// New filter functionality, searching and listing of requests.
echo $renderer->render_index_search_controls($context, $categoryid, $courseid, $stateid, $baseurl, $search);
echo $renderer->render_index_search_controls($context, $categoryid, $courseid, $stateid, $baseurl, $search, $faculty);

$table = new \local_extension\local\table\index($baseurl);

Expand Down Expand Up @@ -202,6 +205,11 @@
$params['search3'] = "%$search%";
}

if (!empty($faculty)) {
$wheres[] = $DB->sql_like('c.shortname', ':faculty', false, false);
$params['faculty'] = "%$faculty%";
}

list($twhere, $tparams) = $table->get_sql_where();
if ($twhere) {
$wheres[] = $twhere;
Expand Down
1 change: 1 addition & 0 deletions lang/en/local_extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
$string['page_index_all'] = 'All';
$string['page_index_categories'] = 'Categories';
$string['page_index_courses'] = 'Courses';
$string['page_index_faculties'] = 'Faculty';
$string['page_index_toomanycourses'] = 'Too many courses, please search or filter by category.';
$string['page_request_notriggersdefined'] = 'No extension triggers have been defined.';
$string['page_request_outofrange'] = 'Please reduce the look ahead range.';
Expand Down
64 changes: 58 additions & 6 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,10 @@ public function render_request_search_controls($courseid, $cmid, $searchback, $s
* @param int $stateid
* @param \moodle_url $baseurl
* @param string $search
* @param string $faculty
* @return string
*/
public function render_index_search_controls($context, $categoryid, $courseid, $stateid, $baseurl, $search) {
public function render_index_search_controls($context, $categoryid, $courseid, $stateid, $baseurl, $search, $faculty) {
global $SITE;

$systemcontext = context_system::instance();
Expand Down Expand Up @@ -607,6 +608,45 @@ public function render_index_search_controls($context, $categoryid, $courseid, $
$controlstable->data[0]->cells[] = $categorycell;
}

// Display a list of faculties to filter by
if (!empty($categorylist) || $viewallrequests || $modifyrequeststatus) {
$options = array();
$options['0'] = get_string('page_index_all', 'local_extension');

if (!empty($categoryid)) {
$cat = coursecat::get($categoryid);
$courses = $cat->get_courses(array('recursive' => true));
} else {
$courses = coursecat::get(0)->get_courses(array('recursive' => true));

}

foreach ($courses as $course) {
$re = "/^([A-Z]+)/i";
if (preg_match($re, $course->shortname, $matches)) {
$options[$matches[1]] = $matches[1];
}

}

$popupurl = new moodle_url('/local/extension/index.php', array(
'catid' => $categoryid
));

$select = new single_select($popupurl, 'faculty', $options, $faculty, null, 'requestform');

$strcourses = get_string('page_index_faculties', 'local_extension');
$html = html_writer::span($strcourses, '', array('id' => 'courses'));
$html .= $this->render($select);

$categorycell = new html_table_cell();
$categorycell->attributes['class'] = 'right';
$categorycell->text = $html;

$controlstable->data[0]->cells[] = $categorycell;

}

// Display a list of all courses to filter by
// TODO change this to categories that the user is enroled in. / has the cap to modify
if (!empty($categorylist) || $viewallrequests || $modifyrequeststatus) {
Expand All @@ -629,15 +669,26 @@ public function render_index_search_controls($context, $categoryid, $courseid, $
} else {
}
*/

foreach ($courses as $course) {
$options[$course->id] = $course->fullname;

if (!empty($faculty)) {
$re = "/^$faculty/i";
if (preg_match($re, $course->shortname)) {
$options[$course->id] = $course->fullname;
}

} else {
$options[$course->id] = $course->fullname;

}
}

$popupurl = new moodle_url('/local/extension/index.php', array(
'catid' => $categoryid
'catid' => $categoryid,
'faculty' => $faculty,
));

$select = new single_select($popupurl, 'id', $options, $courseid, null, 'requestform');
Expand Down Expand Up @@ -674,7 +725,7 @@ public function render_index_search_controls($context, $categoryid, $courseid, $
}

$popupurl = new moodle_url('/local/extension/index.php', array(
'catid' => $categoryid
'catid' => $categoryid,
));

$select = new single_select($popupurl, 'id', $courselist, $courseid, null, 'requestform');
Expand All @@ -697,7 +748,8 @@ public function render_index_search_controls($context, $categoryid, $courseid, $

$popupurl = new moodle_url('/local/extension/index.php', array(
'catid' => $categoryid,
'id' => $courseid
'id' => $courseid,
'faculty' => $faculty,
));

$select = new single_select($popupurl, 'state', $statelist, $stateid, null, 'requestform');
Expand Down

0 comments on commit d0a3c52

Please sign in to comment.