Hi,

I don't know if this is the good place to post this snippet, but it might be
usefull for new midgard users.

/* put this code into the <[code-init]> page element */

function init_prefs()
{
  if($lp=mgd_list_preferences($midgard-user))
    while($lp->fetch())
    {
      $pref[$lp->domain][$lp->name][id]=$lp->id;
      $pref[$lp->domain][$lp->name][val]=$lp->value;
    }
  return $pref;
}

function set_pref($pref,$domain,$key,$val)
{
  if(isset($pref[$domain][$key][id]))
    mgd_update_preference($pref[$domain][$key][id],$val);
  else

$pref[$domain][key][id]=mgd_create_preference($midgard->user,$domain,$key,$v
al);
  return $pref[$domain][key][id];
}

/* init_prefs() needs only to be called once */
$user_prefs=init_prefs();

/* end of code */

the function init_prefs initialize and return a table which make it easy to
access any preference you want.
example:

to set the user prefs to domain="GUI", key="menu", val="treelike" call the
function
set_pref($user_prefs,"GUI","menu","treelike");

to get the value :
$menustyle=$user_prefs[GUI][menu][val];

to get the pref record id:
$id=$user_prefs[GUI][menu][id];

to delete the pref:
mgd_delete_preference($user_prefs[GUI][menu][id]);

Here it is !
Maybe these functions should be added to the documentation, because there is
absolutely no references to any mgd_xxx_preference() function in it.

Tell me if you want more snippets, I have some other functions to make life
easier...

[EMAIL PROTECTED]


--
This is The Midgard Project's mailing list. For more information,
please visit the project's web site at http://www.midgard-project.org

To unsubscribe the list, send an empty email message to address
[EMAIL PROTECTED]

Reply via email to