|
@@ -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;
|
|
|
+ }
|
|
|
+}
|