/** * Return an LDAP changeset from the difference between the current object * data and the new dataset. * * @return array The LDAP changeset. */ public function getChangeset() { $cs = array(); $old = $this->_object->readInternal(); $new = $this->_data; $attributes = array_merge(array_keys($old), array_keys($new)); foreach ($attributes as $attribute) { if (!isset($old[$attribute])) { $cs['add'][$attribute] = $new[$attribute]; continue; } if (!isset($new[$attribute])) { $cs['delete'][] = $attribute; continue; } if ((!is_array($new[$attribute]) || count($new[$attribute]) == 1) && (!is_array($old[$attribute]) || count($old[$attribute]) == 1)) { if ($new[$attribute][0] == $old[$attribute][0]) { continue; } else { $cs['replace'][$attribute] = $new[$attribute][0]; continue; } } $adds = array_diff($new[$attribute], $old[$attribute]); if (!empty($adds)) { $cs['add'][$attribute] = array_values($adds); } $deletes = array_diff($old[$attribute], $new[$attribute]); if (!empty($deletes)) { $cs['delete'][$attribute] = array_values($deletes); } } return $cs; }
/** * Returns the set of actions supported by this object type. * * @return array An array of supported actions. */ public function getActions() { if (!isset($this->_actions)) { $this->_actions = $this->_object->getActions(); } return $this->_actions; }
/** * Check the generating of the "First Name" attribute. * * @param string $data Object data. * @param string $expect Expect this full name. * * @dataProvider provideGetArrayChanges * * @return NULL */ public function testGetArrayChanges($data, $expect) { $ko =& Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolab_User', null, $this->_dummydb, array('dn' => 'test', 'cn' => 'Frank Mustermann', 'sn' => 'Mustermann')); $this->assertNoError($ko); $c = $ko->getArrayChanges($data[0], $data[1]); $this->assertEquals($expect, empty($c)); }
/** * List all objects of a specific type. * * @param string $type The type of the objects to be listed * @param array $params Additional parameters. * * @return array An array of Kolab objects. * * @throws Horde_Kolab_Server_Exception * * @todo Sorting */ public function listObjects($type, $params = null) { $result = Horde_Kolab_Server_Object::loadClass($type); $vars = get_class_vars($type); $criteria = call_user_func(array($type, 'getFilter')); $filter = $this->searchQuery($criteria); $sort = $vars['sort_by']; if (isset($params['sort'])) { $sort = $params['sort']; } $options = array('scope' => 'sub'); if (isset($params['attributes'])) { $options['attributes'] = $params['attributes']; } else { $options['attributes'] = $this->getAttributes($type); } $data = $this->search($filter, $options, $base); if (empty($data)) { return array(); } if ($sort) { /* @todo: sorting */ /* $data = $result->as_sorted_struct(); */ /*$this->sort($result, $sort); */ } if (isset($params['from'])) { $from = $params['from']; } else { $from = -1; } if (isset($params['to'])) { $sort = $params['to']; } else { $to = -1; } if (!empty($vars['required_group'])) { $required_group = new Horde_Kolab_Server_Object_Kolabgroupofnames($this, null, $vars['required_group']); } $objects = array(); foreach ($data as $uid => $entry) { if (!empty($vars['required_group'])) { if (!$required_group->exists() || !$required_group->isMember($uid)) { continue; } } $objects[$uid] =& Horde_Kolab_Server_Object::factory($type, $uid, $this, $entry); } return $objects; }
/** * The generating a uid for an object. * * @return NULL */ public function testGenerateUid() { $ks = $this->getMockServer(); $user = new Horde_Kolab_Server_Object($ks, null, null); $this->assertEquals(preg_replace('/[0-9a-f]*/', '', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)), ''); }
/** * Delete an external account. * * @param string $mail The mail address of the pop3 account. * * @return NULL */ public function deleteExternalAccount($mail) { $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_OWNERUID] = $this->getUid(); $account[Horde_Kolab_Server_Object_Kolabpop3account::ATTRIBUTE_MAIL] = $mail; $object =& Horde_Kolab_Server_Object::factory('Horde_Kolab_Server_Object_Kolabpop3account', null, $this->server, $account); $object->delete(); }
/** * Returns the set of actions supported by this object type. * * @return array An array of supported actions. */ public function getActions() { $this->_object->getActions(); }
/** * Assert that a save() operation yields some predictable attribute results. * * @param Horde_Kolab_Server_Object $object The object to work on. * @param Horde_Kolab_Server $server The server the object resides on. * @param array $store The information to save. * @param array $fetch The expected results. * * @return NULL. */ protected function assertStoreFetch(Horde_Kolab_Server_Object $object, Horde_Kolab_Server $server, array $store, array $fetch, $pop_arrays = false) { $result = $object->save($store); $this->assertNoError($result); $object = $server->fetch($object->getUid()); foreach ($fetch as $attribute => $expect) { $actual = $object->get($attribute, false); if ($pop_arrays && is_array($actual) && count($actual) == 1) { $actual = array_pop($actual); } $this->assertEquals($expect, $actual); } }