profiloo.module 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // $Id: profiloo.module,v 1.2 2008-10-13 13:43:08 marand Exp $
  3. /**
  4. * @file
  5. * An OO wrapper around the profile module
  6. *
  7. * Copyright 2008 Ouest Systemes Informatiques (OSI) http://www.osinet.eu/
  8. * License: GPL2 or later
  9. * Author: Frederic G. MARAND
  10. */
  11. /**
  12. * The wrapper class
  13. */
  14. class Profiloo {
  15. /**
  16. * Return a list of the currently defined profile fields.
  17. *
  18. * This function is not subject to access control.
  19. *
  20. * @param array $ar_filter
  21. * @return array
  22. */
  23. static function get_fields($ar_filter = array()) {
  24. $sq = 'SELECT pf.fid, pf.title, pf.name, pf.explanation, pf.category, '
  25. .' pf.page, pf.type, pf.weight, pf.required, pf.register, '
  26. .' pf.visibility, pf.autocomplete, pf.options '
  27. .'FROM {profile_fields} pf ';
  28. if (empty($ar_filter)) {
  29. $q = db_query($sq);
  30. }
  31. else {
  32. $ar_query = array();
  33. $ar_params = array();
  34. foreach ($ar_filter as $key => $value) {
  35. if (in_array($key, array('fid', 'weight', 'required', 'register', 'visibility', 'autocomplete'))) {
  36. $ar_query[] = "pf.$key = %d";
  37. $ar_params[] = $value;
  38. }
  39. else {
  40. $ar_query[] = "LOWER(pf.$key) = LOWER('%s')";
  41. $ar_params[] = $value;
  42. }
  43. }
  44. $sq .= 'WHERE '. implode(' AND ', $ar_query);
  45. $q = db_query($sq, $ar_params);
  46. }
  47. $ar_fields = array();
  48. while (is_object($o = db_fetch_object($q))) {
  49. $ar_fields[$o->fid] = $o;
  50. }
  51. return $ar_fields;
  52. }
  53. /**
  54. * Return a list of the currently defined fields as a FormsAPI #select needs them.
  55. *
  56. * This function is not subject to access control.
  57. *
  58. * @param array $ar_filter
  59. * @return array
  60. */
  61. static function get_fields_as_options($ar_filter = array()) {
  62. $ar_fields = self::get_fields($ar_filter);
  63. $ar_ret = array();
  64. foreach ($ar_fields as $fid => $o_field) {
  65. $ar_ret[$fid] = $o_field->title;
  66. }
  67. return $ar_ret;
  68. }
  69. }