profiloo.module 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // $Id: profiloo.module,v 1.1 2008-10-08 09:01:35 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 $arFilter
  21. * @return array
  22. */
  23. static function getFields($arFilter = 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($arFilter))
  29. {
  30. $q = db_query($sq);
  31. }
  32. else
  33. {
  34. $arQuery = array();
  35. $arParams = array();
  36. foreach ($arFilter as $key => $value)
  37. {
  38. if (in_array($key, array('fid', 'weight', 'required', 'register', 'visibility', 'autocomplete')))
  39. {
  40. $arQuery[] = "pf.$key = %d";
  41. $arParams[] = $value;
  42. }
  43. else
  44. {
  45. $arQuery[] = "LOWER(pf.$key) = LOWER('%s')";
  46. $arParams[] = $value;
  47. }
  48. }
  49. $sq .= 'WHERE ' . implode(' AND ', $arQuery);
  50. $q = db_query($sq, $arParams);
  51. }
  52. $arFields = array();
  53. while (is_object($o = db_fetch_object($q)))
  54. {
  55. $arFields[$o->fid] = $o;
  56. }
  57. return $arFields;
  58. }
  59. /**
  60. * Return a list of the currently defined fields as a FormsAPI #select needs them.
  61. *
  62. * This function is not subject to access control.
  63. *
  64. * @param array $arFilter
  65. * @return array
  66. */
  67. static function getFieldsAsOptions($arFilter = array()) {
  68. $arFields = self::getFields($arFilter);
  69. $arRet = array();
  70. foreach($arFields as $fid => $oField)
  71. {
  72. $arRet[$fid] = $oField->title;
  73. }
  74. return $arRet;
  75. }
  76. }