From a5bdd50ae2ab8cb32d490bf4c4596979907901ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Mon, 17 Oct 2016 12:19:34 -0200 Subject: [PATCH] =?UTF-8?q?Adiciona=20filtro=20por=20m=C3=A9todo=20de=20in?= =?UTF-8?q?scri=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.php | 12 +++++++++--- report_form.php | 14 +++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 6607f08..f3fa500 100644 --- a/index.php +++ b/index.php @@ -105,7 +105,7 @@ if (!$role_confirmed or !$role_revoked) { } $roles = array($role_confirmed=>$allroles[$role_confirmed], $role_revoked=>$allroles[$role_revoked]); -$mform = new filter_form($course->id, $filterfields, $roles); +$mform = new filter_form($course->id, $filterfields, $roles, $instances); // Generate where clause $where = array(); @@ -141,7 +141,7 @@ if ($formdata = $mform->get_data()) { } // Role filter -if ($formdata and array_key_exists('role', $formdata)) { +if (array_key_exists('role', $formdata)) { list($in_roles, $param_roles) = $DB->get_in_or_equal(array_keys($formdata->role), SQL_PARAMS_NAMED); } else { list($in_roles, $param_roles) = $DB->get_in_or_equal(array_keys($roles), SQL_PARAMS_NAMED); @@ -150,7 +150,13 @@ if ($formdata and array_key_exists('role', $formdata)) { $where[] = "ra.roleid {$in_roles}"; $where_params = $where_params + $param_roles; -list($in_instances, $param_instances) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED); +// Enrol instance filter +if (array_key_exists('instance', $formdata)) { + list($in_instances, $param_instances) = $DB->get_in_or_equal(array_keys($formdata->instance), SQL_PARAMS_NAMED); +} else { + list($in_instances, $param_instances) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED); +} + list($in_contexts, $param_contexts) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED); list($in_fields, $param_fields) = $DB->get_in_or_equal(array_keys($filterfields), SQL_PARAMS_NAMED); $params = $param_instances + $param_contexts + $param_fields; diff --git a/report_form.php b/report_form.php index f2419b7..8393219 100644 --- a/report_form.php +++ b/report_form.php @@ -36,11 +36,13 @@ class filter_form extends moodleform { protected $_courseid; protected $_filterfields; protected $_roles; + protected $_instances; - function filter_form($courseid, $filterfields, $roles, $action=null, $customdata=null, $method='get', $target='', $attributes=null, $editable=true) { + function filter_form($courseid, $filterfields, $roles, $instances, $action=null, $customdata=null, $method='get', $target='', $attributes=null, $editable=true) { $this->_filterfields = $filterfields; $this->_courseid = $courseid; $this->_roles = $roles; + $this->_instances = $instances; parent::moodleform($action, $customdata, $method, $target, $attributes, $editable); } @@ -51,6 +53,8 @@ class filter_form extends moodleform { $courseid = $this->_courseid; $filterfields = $this->_filterfields; $roles = $this->_roles; + $instances = $this->_instances; + $plugins = enrol_get_plugins(false); // User fields filter $mform->addElement('text', 'email', get_string('email')); @@ -61,6 +65,14 @@ class filter_form extends moodleform { $mform->addElement('checkbox', "role[{$role->id}]", $role->localname); } + // Role instance filter + $mform->addElement('header', 'filter', get_string('enrolmentinstances', 'enrol')); + foreach ($instances as $instance) { + $plugin = $plugins[$instance->enrol]; + $mform->addElement('checkbox', "instance[{$instance->id}]", $plugin->get_instance_name($instance)); + } + + // User fields foreach ($filterfields as $field) { $mform->addElement('header', $field->shortname, $field->name); $options = explode("\n", $field->param1);