Is it possible to add multiple user filters?

Re: Is it possible to add multiple user filters?

Peter Bowen - ން
Number of replies: 0

Hmm - must have missed this post...

This is about using filters to reduce the number of results in your query, not restricting who can see the query.

The lines you need to modify are:

class plugin_filtername extends plugin_base{

You need to replace filtername with the name of your new filter

The within the private function execute_sql, in all places, replace the filter_filtername with the name of your new filter.


For example, I have one that searches for department, so I have....

require_once($CFG->dirroot.'/blocks/configurable_reports/plugin.class.php');

class plugin_department extends plugin_base{
   
    function init(){
        $this->form = true;
        $this->unique = true;
        $this->fullname = get_string('department','block_configurable_reports');
        $this->reporttypes = array('users', 'sql');
    }
   
    function summary($data){
        return $data->field;
    }
   
    function execute($finalelements,$data){
        if($this->report->type == 'sql') {
            return $this->execute_sql($finalelements, $data);
        }

        return $this->execute_users($finalelements, $data);


    }
   
    private function execute_sql($finalelements, $data) {
        $filter_department = optional_param('filter_department_'.$data->field,0,PARAM_RAW);
        $filter = clean_param(base64_decode($filter_department),PARAM_CLEAN);

        if($filter_department &&
           preg_match("/%%FILTER_DEPARTMENTމޮޅިވެރި[^%]+)%%/i",$finalelements, $output)){
            $replace = ' AND '.$output[1].' = '. "'$filter'";
            return str_replace('%%FILTER_DEPARTMENT:'.$output[1].'%%',$replace,$finalelements);
        }

        return $finalelements;
    }

    private function execute_users($finalelements, $data) {
        global $DB, $CFG;
       
        $filter_department = optional_param('filter_department_'.$data->field,0,PARAM_RAW);       
        if($filter_department){
            // addslashes is done in clean param
            $filter = clean_param(base64_decode($filter_department),PARAM_CLEAN);