/** * Gets an array of available filters. * @return array An array of deepsight_filter objects that will be available. */ protected function get_filters() { $langautoenrol = get_string('usersetprogram_auto_enrol', 'local_elisprogram'); $filters = parent::get_filters(); $fielddata = array('clstcur.autoenrol' => $langautoenrol); $autoenrol = new deepsight_filter_menuofchoices($this->DB, 'autoenrol', $langautoenrol, $fielddata, $this->endpoint); $autoenrol->set_choices(array(0 => get_string('no', 'moodle'), 1 => get_string('yes', 'moodle'))); $filters[] = $autoenrol; return $filters; }
/** * Gets an array of available filters. * * @return array An array of deepsight_filter objects that will be available. */ protected function get_filters() { $langenrolmenttime = get_string('enrolment_time', 'local_elisprogram'); $langcompletetime = get_string('completion_time', 'local_elisprogram'); $langgrade = get_string('student_grade', 'local_elisprogram'); $langcredits = get_string('student_credits', 'local_elisprogram'); $langcompletestatus = get_string('student_status', 'local_elisprogram'); $completestatus = new deepsight_filter_menuofchoices($this->DB, 'completestatus', $langcompletestatus, array('enrol.completestatusid' => $langcompletestatus), $this->endpoint); $choices = array(STUSTATUS_NOTCOMPLETE => 'Not Complete', STUSTATUS_PASSED => 'Passed', STUSTATUS_FAILED => 'Failed'); $completestatus->set_choices($choices); $filters = array(new deepsight_filter_date($this->DB, 'enrolmenttime', $langenrolmenttime, array('enrol.enrolmenttime' => $langenrolmenttime)), $completestatus, new deepsight_filter_date($this->DB, 'completetime', $langcompletetime, array('enrol.completetime' => $langcompletetime)), new deepsight_filter_textsearch($this->DB, 'grade', $langgrade, array('enrol.grade' => $langgrade)), new deepsight_filter_textsearch($this->DB, 'credits', $langcredits, array('enrol.credits' => $langcredits))); $filters = array_merge(parent::get_filters(), $filters); return $filters; }
/** * Gets an array of available filters. * @return array An array of deepsight_filter objects that will be available. */ protected function get_filters() { $filters = parent::get_filters(); // Required. $langrequired = get_string('curriculumcourseform:required', 'local_elisprogram'); $fielddata = array('curcrs.required' => $langrequired); $required = new deepsight_filter_menuofchoices($this->DB, 'required', $langrequired, $fielddata, $this->endpoint); $required->set_choices(array(0 => get_string('no', 'moodle'), 1 => get_string('yes', 'moodle'))); $filters[] = $required; // Frequency. $langfrequency = get_string('curriculumcourseform:frequency', 'local_elisprogram'); $fielddata = array('curcrs.frequency' => $langfrequency); $filters[] = new deepsight_filter_searchselect($this->DB, 'frequency', $langfrequency, $fielddata, $this->endpoint, curriculumcourse::TABLE, 'frequency'); // Timeperiod. $langtimeperiod = get_string('curriculumcourseform:time_period', 'local_elisprogram'); $fielddata = array('curcrs.timeperiod' => $langtimeperiod); $filters[] = new deepsight_filter_searchselect($this->DB, 'timeperiod', $langtimeperiod, $fielddata, $this->endpoint, curriculumcourse::TABLE, 'timeperiod'); // Position. $langposition = get_string('curriculumcourseform:position', 'local_elisprogram'); $fielddata = array('curcrs.position' => $langposition); $filters[] = new deepsight_filter_searchselect($this->DB, 'position', $langposition, $fielddata, $this->endpoint, curriculumcourse::TABLE, 'position'); return $filters; }
/** * Gets custom field information for a given context level. * * Sets the internal $this->custom_fields array with the returned field information, and returns an array of filters * for each custom field found. * NOTE: This will only look for filterable custom fields, which at the moment are "char" or "text" fields. * * @param int $contextlevel The context level of the fields we want. i.e. CONTEXT_ELIS_USER, CONTEXT_ELIS_CLASS, etc. * @return array An array of deepsight_filter objects for each found filterable field. */ protected function get_custom_field_info($contextlevel) { $fieldfilters = array(); $fielddata = array(); // Add custom fields. $sql = 'SELECT field.id, field.name, field.shortname, field.datatype, owner.params FROM {local_eliscore_field} field JOIN {local_eliscore_field_clevels} ctx ON ctx.fieldid = field.id JOIN {local_eliscore_field_owner} owner ON owner.fieldid = field.id AND plugin = "manual" WHERE (field.datatype="char" OR field.datatype="text") AND ctx.contextlevel=?'; $customfields = $this->DB->get_recordset_sql($sql, array($contextlevel)); foreach ($customfields as $field) { $field->params = @unserialize($field->params); if (!is_array($field->params)) { $field->params = array(); } $filtername = 'cf_' . $field->shortname; $fielddata[$filtername] = $field; $filterfielddata = array($filtername . '.data' => $field->name); if (isset($field->params['control']) && $field->params['control'] === 'menu' && !empty($field->params['options'])) { $filtermenu = new deepsight_filter_menuofchoices($this->DB, $filtername, $field->name, $filterfielddata, $this->endpoint); $choices = explode("\n", $field->params['options']); foreach ($choices as $i => $choice) { $choices[$i] = trim($choice); } $filtermenu->set_choices(array_combine($choices, $choices)); $fieldfilters[] = $filtermenu; } else { $fieldfilters[] = new deepsight_filter_textsearch($this->DB, $filtername, $field->name, $filterfielddata); } } $this->custom_fields = $fielddata; return $fieldfilters; }
/** * Test the get_filter_sql() function of the menuofchoices filter. * * @dataProvider menuofchoicesfilter_get_filter_sql_dataprovider */ public function test_filter_menuofchoices_get_filter_sql($filterdata, $expectedresponse) { global $DB; $name = 'menu'; $label = 'Menu Of Choices'; $dataurl = 'test.php'; $filter = new deepsight_filter_menuofchoices($DB, $name, $label, array('choice' => 'Choice'), $dataurl); $filtersql = $filter->get_filter_sql($filterdata); $this->assertEquals($expectedresponse, $filtersql); }