Skip to content

Commit

Permalink
survey filters according to roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Gusain committed Aug 26, 2024
1 parent 22d8c08 commit e7a0032
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
16 changes: 14 additions & 2 deletions classes/model/survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ public static function delete_categories($id) {
}

public static function get_all_survey_categories() {
global $DB;
return $DB->get_records('cc_categories', array('type' => 'survey'));
global $DB, $USER;

if (is_sel_admin()) {
return $DB->get_records('cc_categories', array('type' => 'survey'));
}

$userschool = get_user_school();
$sql = "SELECT categories.* FROM {cc_survey_audience_access} as survey_school
JOIN {cc_surveys} as survey ON survey.id = survey_school.survey_id
JOIN {cc_categories} as categories ON survey.category_id = categories.id
WHERE survey_school.school_id = :schoolid;
";
$params = ['schoolid' => $userschool->companyid];
return $DB->get_records_sql($sql, $params);
}

public static function get_category_by_id($id) {
Expand Down
4 changes: 2 additions & 2 deletions manage_survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// Fetch surveys
$surveys = fetch_surveys($filters);

display_page($surveys);
display_page($surveys, $filters);

/**
* Initializes the page context and resources.
Expand Down Expand Up @@ -67,7 +67,7 @@ function fetch_surveys($filters) {
*
* @param array $surveys
*/
function display_page($surveys) {
function display_page($surveys, $filters) {
global $OUTPUT, $USER;

// Include the HTML for the survey management interface
Expand Down
9 changes: 4 additions & 5 deletions templates/manage_survey_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@
foreach ($categories as $key => $category) {
$categoryoptions[$category->id] = $category->label;
}

echo html_writer::start_tag('form', ['method' => 'get', 'action' => $PAGE->url, 'id' => 'filter-form']);
echo html_writer::start_div('filter-form d-flex justify-content-between');
echo html_writer::select($surveystatusoptions, 'status', $status, null, ['class' => 'status-select', 'id' => 'status-select']);
echo html_writer::empty_tag('input', ['type' => 'date', 'name' => 'createdon', 'placeholder' => get_string('createdat', 'local_moodle_survey'), 'class' => 'date-input']);
echo html_writer::select($categoryoptions, 'category', $surveycategory, null, ['class' => 'status-select', 'id' => 'category-select']);
echo html_writer::select($surveystatusoptions, 'status', $filters['status'], null, ['class' => 'status-select', 'id' => 'status-select']);
echo html_writer::empty_tag('input', ['type' => 'date', 'name' => 'createdon', 'value' => $filters['createdon'], 'placeholder' => get_string('createdat', 'local_moodle_survey'), 'class' => 'date-input']);
echo html_writer::select($categoryoptions, 'category', $filters['surveycategory'], null, ['class' => 'status-select', 'id' => 'category-select']);

echo html_writer::empty_tag('input', ['type' => 'text', 'name' => 'search', 'value' => $search, 'placeholder' => get_string('search', 'local_moodle_survey'), 'class' => 'search-input']);
echo html_writer::empty_tag('input', ['type' => 'text', 'name' => 'search', 'value' => $filters['search'], 'placeholder' => get_string('search', 'local_moodle_survey'), 'class' => 'search-input']);

echo html_writer::end_div();
echo html_writer::end_tag('form');
Expand Down

0 comments on commit e7a0032

Please sign in to comment.