Browse Source

- Initial commit for Drupal 5.x

Frederic G. Marand 15 years ago
commit
8919cff78d
2 changed files with 88 additions and 0 deletions
  1. 6 0
      profiloo.info
  2. 82 0
      profiloo.module

+ 6 - 0
profiloo.info

@@ -0,0 +1,6 @@
+; $Id: profiloo.info,v 1.1 2008-10-08 09:01:35 marand Exp $
+name = "Profiloo"
+description = "Profile Object Oriented extensions"
+package = "Development"
+version = "5.x-1.0"
+dependencies = profile

+ 82 - 0
profiloo.module

@@ -0,0 +1,82 @@
+<?php
+// $Id: profiloo.module,v 1.1 2008-10-08 09:01:35 marand Exp $
+/**
+ * @file
+ *   An OO wrapper around the profile module
+ *
+ * Copyright 2008 Ouest Systemes Informatiques (OSI) http://www.osinet.eu/
+ * License: GPL2 or later
+ * Author: Frederic G. MARAND
+ */
+
+/**
+ * The wrapper class
+ */
+class Profiloo {
+
+  /**
+   * Return a list of the currently defined profile fields.
+   *
+   * This function is not subject to access control.
+   *
+   * @param array $arFilter
+   * @return array
+   */
+  static function getFields($arFilter = array()) {
+
+    $sq = 'SELECT pf.fid, pf.title, pf.name, pf.explanation, pf.category, '
+        . '  pf.page, pf.type, pf.weight, pf.required, pf.register, '
+        . '  pf.visibility, pf.autocomplete, pf.options '
+        . 'FROM {profile_fields} pf ';
+
+    if (empty($arFilter))
+      {
+      $q = db_query($sq);
+      }
+    else
+      {
+      $arQuery  = array();
+      $arParams = array();
+      foreach ($arFilter as $key => $value)
+        {
+        if (in_array($key, array('fid', 'weight', 'required', 'register', 'visibility', 'autocomplete')))
+          {
+          $arQuery[] = "pf.$key = %d";
+          $arParams[] = $value;
+          }
+        else
+          {
+          $arQuery[] = "LOWER(pf.$key) = LOWER('%s')";
+          $arParams[] = $value;
+          }
+        }
+      $sq .= 'WHERE ' . implode(' AND ', $arQuery);
+      $q = db_query($sq, $arParams);
+      }
+
+    $arFields = array();
+    while (is_object($o = db_fetch_object($q)))
+      {
+      $arFields[$o->fid] = $o;
+      }
+    return $arFields;
+  }
+
+  /**
+   * Return a list of the currently defined fields as a FormsAPI #select needs them.
+   *
+   * This function is not subject to access control.
+   *
+   * @param array $arFilter
+   * @return array
+   */
+  static function getFieldsAsOptions($arFilter = array()) {
+    $arFields = self::getFields($arFilter);
+    $arRet = array();
+    foreach($arFields as $fid => $oField)
+      {
+      $arRet[$fid] = $oField->title;
+      }
+    return $arRet;
+  }
+}