Implement format wrapper for distribution-list; add more utility functions

This commit is contained in:
Thomas B 2012-03-08 21:22:09 +01:00
parent 80fa73b895
commit c8696e278c
3 changed files with 48 additions and 34 deletions

View file

@ -45,11 +45,11 @@ abstract class kolab_format
/** /**
* Generate random UID for Kolab objects * Generate random UID for Kolab objects
* *
* @return string MD5 hash with a unique value * @return string UUID with a unique MD5 value
*/ */
public static function generate_uid() public static function generate_uid()
{ {
return md5(uniqid(mt_rand(), true)); return 'urn:uuid:' . md5(uniqid(mt_rand(), true));
} }
/** /**

View file

@ -10,7 +10,7 @@ class kolab_format_distributionlist extends kolab_format
function __construct() function __construct()
{ {
$obj = new DistList; $this->obj = new DistList;
} }
/** /**
@ -35,12 +35,28 @@ class kolab_format_distributionlist extends kolab_format
public function set(&$object) public function set(&$object)
{ {
// TODO: do the hard work of setting object values // set some automatic values if missing
if (empty($object['uid']))
$object['uid'] = self::generate_uid();
// do the hard work of setting object values
$this->obj->setUid($object['uid']);
$this->obj->setName($object['name']);
$members = new vectormember;
foreach ($object['member'] as $member) {
$m = new Member;
$m->setName($member['name']);
$m->setEmail($member['mailto']);
$m->setUid($member['uid']);
$members->push($m);
}
$this->obj->setMembers($members);
} }
public function is_valid() public function is_valid()
{ {
return $this->data || (is_object($this->obj) && true /*$this->obj->isValid()*/); return $this->data || (is_object($this->obj) && $this->obj->isValid());
} }
/** /**
@ -87,40 +103,17 @@ class kolab_format_distributionlist extends kolab_format
$members = $this->obj->members(); $members = $this->obj->members();
for ($i=0; $i < $members->size(); $i++) { for ($i=0; $i < $members->size(); $i++) {
$adr = self::decode_member($members->get($i)); $member = $members->get($i);
if ($adr[0]['mailto']) if ($mailto = $member->email())
$object['member'][] = array( $object['member'][] = array(
'mailto' => $adr[0]['mailto'], 'mailto' => $mailto,
'name' => $adr[0]['name'], 'name' => $member->name(),
'uid' => '????', 'uid' => $member->uid(),
); );
} }
$this->data = $object;
return $this->data; return $this->data;
} }
/**
* Compose a valid Mailto URL according to RFC 822
*
* @param string E-mail address
* @param string Person name
* @return string Formatted string
*/
public static function format_member($email, $name = '')
{
// let Roundcube internals do the job
return 'mailto:' . format_email_recipient($email, $name);
}
/**
* Split a mailto: url into a structured member component
*
* @param string RFC 822 mailto: string
* @return array Hash array with member properties
*/
public static function decode_member($str)
{
$adr = rcube_mime::decode_address_list(preg_replace('/^mailto:/', '', $str));
return $adr[0];
}
} }

View file

@ -203,4 +203,25 @@ class kolab_storage
return $folder; return $folder;
} }
/**
* Creates a SELECT field with folders list
*
* @param string $type Folder type
* @param array $attrs SELECT field attributes (e.g. name)
* @param string $current The name of current folder (to skip it)
*
* @return html_select SELECT object
*/
public static function folder_selector($type, $attrs, $current = '')
{
// TODO: implement this
// Build SELECT field of parent folder
$select = new html_select($attrs);
$select->add('---', '');
return $select;
}
} }