require_js($CFG->wwwroot . '/blocks/student_gradeviewer/functions.js'); // Start of the form output print_header_simple($heading_main, '', build_navigation($navigation)); // An empty prequery and no admin means that they have no association list($table, $prequery) = get_pre_query($USER->id); if (empty($prequery) && !has_capability('block/student_gradeviewer:academicadmin', $context) && !has_capability('block/student_gradeviewer:sportsadmin', $context)) { echo '<div class="results">' . get_string('no_mentees', 'block_student_gradeviewer') . '<div>'; print_footer(); die; } // Used for paging the results $per_page = optional_param('per_page', 10, PARAM_INT); $page = optional_param('page', 0, PARAM_INT); $components = cps_user_component::build_components(); if ($viewsports) { $components->components[] = new sports_drop_down(cps_transform_filter('sports')); } // Per page selector $components->components[] = new results_drop_down($per_page); $components->display_as_table($heading_main); $where = $components->where_clause(); // Do a prequery to figure out if the table doesn't just print out $threshold = get_config('', 'block_student_gradeviewer_threshold'); //Running a count on the pre query info if (!empty($prequery) && empty($where)) { $sql = "SELECT COUNT(u.id) FROM {$CFG->prefix}block_courseprefs_users u {$table} WHERE " . $prequery; $count = count_records_sql($sql); } else { $count = $threshold; } // Print table if they submitted data
public static function build_filters($script, $params = null, $filter_data = null, $filter = null, $filters = null) { $filters = !is_null($filters) ? $filters : cps_user_component::filters(); $filters = $filter ? array_filter($filters, $filter) : $filters; $param_dict = $filters ? array_combine($filters, array_map('cps_transform_filter', $filters)) : array(); $param_dict = ($param_dict ? $param_dict : array()) + ($params && is_array($params) ? $params : array()); $components = array(); foreach ($param_dict as $key => $value) { if (!in_array($key, $filters)) { continue; } if (isset($filter_data[$key])) { $extra = $filter_data[$key]; } else { $extra = null; } $rest = $param_dict; unset($rest[$key]); $class = $key . "_filter"; $components[] = new $class($script, cps_transform_filter($key), $rest, $extra); } return new cps_user_component_collection($components, $param_dict); }