-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdepartments.php
77 lines (60 loc) · 2.4 KB
/
departments.php
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
<?php
require_once('../../config.php');
include_once('classes/tables/department_table.php');
include_once('classes/forms/department_filter_form.php');
use local_organization\base;
use local_organization\department_table;
use local_organization\department_filter_form;
global $CFG, $OUTPUT, $PAGE, $DB, $USER;
require_login(1, false);
$context = context_system::instance();
if (!has_capability('local/organization:unit_view', $PAGE->context, $USER->id)) {
redirect($CFG->wwwroot . '/my');
}
// Load AMD module
$PAGE->requires->js_call_amd('local_organization/departments', 'init');
// Load CSS file
$PAGE->requires->css('/local/organization/css/general.css');
const USER_CONTEXT = 'DEPARTMENT';
$term = optional_param('q', '', PARAM_TEXT);
$campus_id = required_param('campus_id', PARAM_INT);
$unit_id = required_param('unit_id', PARAM_INT);
$formdata = new stdClass();
$formdata->name = $term;
$formdata->user_context = USER_CONTEXT;
$formdata->campus_id = $campus_id;
$formdata->unit_id = $unit_id;
$mform = new department_filter_form(null, array('formdata' => $formdata));
if ($mform->is_cancelled()) {
// Handle form cancel operation, if cancel button is present
redirect($CFG->wwwroot . '/local/organization/departments.php?unit_id= '.$unit_id. '&campus_id='.$campus_id);
} else if ($data = $mform->get_data()) { // on submit and reset/refresh of the button group form
// Process validated data
$term_filter = $data->q;
$campus_id = $data->campus_id;
$unit_id = $data->unit_id;
} else {
// Display the form
// $mform->display();
}
$params = array();
$table = new department_table('local_organization_departments_table', $formdata);
// Define the SQL query to fetch data
$sql = "unit_id = $unit_id";
if (!empty($term_filter)) {
$sql .= " AND (LOWER(name) LIKE '%$term_filter%') OR (LOWER(shortname) LIKE '%$term_filter%') AND (unit_id = $unit_id)";
}
// Define the SQL query to fetch data
$table->set_sql('*', '{local_organization_dept}', $sql);
// Define the base URL for the table
$table->define_baseurl(new moodle_url('/local/organization/departments.php', ['unit_id' => $unit_id, 'campus_id' => $campus_id]));
base::page(
new moodle_url('/local/organization/departments.php'),
get_string('departments', 'local_organization'),
get_string('departments', 'local_organization')
);
echo $OUTPUT->header();
// Set up the table
$mform->display();
$table->out(20, true);
echo $OUTPUT->footer();