PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/user/filters/user_filter_forms.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 68 lines | 51 code | 14 blank | 3 comment | 4 complexity | 85566ef0d1b0799734fa5547aeb28bfb MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. require_once($CFG->libdir.'/formslib.php');
  3. class user_add_filter_form extends moodleform {
  4. function definition() {
  5. $mform =& $this->_form;
  6. $fields = $this->_customdata['fields'];
  7. $extraparams = $this->_customdata['extraparams'];
  8. $mform->addElement('header', 'newfilter', get_string('newfilter','filters'));
  9. foreach($fields as $ft) {
  10. $ft->setupForm($mform);
  11. }
  12. // in case we wasnt to track some page params
  13. if ($extraparams) {
  14. foreach ($extraparams as $key=>$value) {
  15. $mform->addElement('hidden', $key, $value);
  16. $mform->setType($key, PARAM_RAW);
  17. }
  18. }
  19. // Add button
  20. $mform->addElement('submit', 'addfilter', get_string('addfilter','filters'));
  21. }
  22. }
  23. class user_active_filter_form extends moodleform {
  24. function definition() {
  25. global $SESSION; // this is very hacky :-(
  26. $mform =& $this->_form;
  27. $fields = $this->_customdata['fields'];
  28. $extraparams = $this->_customdata['extraparams'];
  29. if (!empty($SESSION->user_filtering)) {
  30. // add controls for each active filter in the active filters group
  31. $mform->addElement('header', 'actfilterhdr', get_string('actfilterhdr','filters'));
  32. foreach ($SESSION->user_filtering as $fname=>$datas) {
  33. if (!array_key_exists($fname, $fields)) {
  34. continue; // filter not used
  35. }
  36. $field = $fields[$fname];
  37. foreach($datas as $i=>$data) {
  38. $description = $field->get_label($data);
  39. $mform->addElement('checkbox', 'filter['.$fname.']['.$i.']', null, $description);
  40. }
  41. }
  42. if ($extraparams) {
  43. foreach ($extraparams as $key=>$value) {
  44. $mform->addElement('hidden', $key, $value);
  45. $mform->setType($key, PARAM_RAW);
  46. }
  47. }
  48. $objs = array();
  49. $objs[] = &$mform->createElement('submit', 'removeselected', get_string('removeselected','filters'));
  50. $objs[] = &$mform->createElement('submit', 'removeall', get_string('removeall','filters'));
  51. $mform->addElement('group', 'actfiltergrp', '', $objs, ' ', false);
  52. }
  53. }
  54. }