Exemple #1
0
 /**
  * parent converts Tinebase_Record_RecordSet to external format
  * this resolves Image Paths
  * @TODO: Can be removed when "0000284: modlog of contact images / move images to vfs" is resolved.
  * @param  Tinebase_Record_RecordSet  $_records
  * @param  array $_resolveUserFields
  * @return mixed
  */
 public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records, $_resolveUserFields = array())
 {
     if (count($_records) == 0) {
         return array();
     }
     Addressbook_Frontend_Json::resolveImages($_records);
     return parent::fromTine20RecordSet($_records, $_resolveUserFields);
 }
 /**
  * parent converts Tinebase_Record_RecordSet to external format
  * this resolves Image Paths
  * @TODO: Can be removed when "0000284: modlog of contact images / move images to vfs" is resolved.
  * 
  * @param Tinebase_Record_RecordSet  $_records
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param Tinebase_Model_Pagination $_pagination
  * @return mixed
  */
 public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records = NULL, $_filter = NULL, $_pagination = NULL)
 {
     if (count($_records) == 0) {
         return array();
     }
     Addressbook_Frontend_Json::resolveImages($_records);
     return parent::fromTine20RecordSet($_records, $_filter, $_pagination);
 }
 /**
  * parent converts Tinebase_Record_RecordSet to external format
  * this resolves Image Paths
  *
  * @param Tinebase_Record_RecordSet  $_records
  * @param Tinebase_Model_Filter_FilterGroup $_filter
  * @param Tinebase_Model_Pagination $_pagination
  * @return mixed
  */
 public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records = NULL, $_filter = NULL, $_pagination = NULL)
 {
     if (count($_records) == 0) {
         return array();
     }
     // TODO: Can be removed when "0000284: modlog of contact images / move images to vfs" is resolved.
     Addressbook_Frontend_Json::resolveImages($_records);
     $this->_appendRecordPaths($_records, $_filter);
     $result = parent::fromTine20RecordSet($_records, $_filter, $_pagination);
     return $result;
 }
 /**
  * @see 0011584: allow to set group member roles
  */
 public function testListMemberRoles()
 {
     $contact = $this->_addContact();
     $listRole = $this->_uit->saveListRole(array('name' => 'my test role', 'description' => 'my test description'));
     $memberroles = array(array('contact_id' => $contact['id'], 'list_role_id' => $listRole['id']));
     $list = $this->_uit->saveList(array('name' => 'my test list', 'description' => '', 'members' => array($contact['id']), 'memberroles' => $memberroles, 'type' => Addressbook_Model_List::LISTTYPE_LIST));
     $this->assertEquals(array($contact['id']), $list['members'], 'members are not saved/returned in list: ' . print_r($list, true));
     $this->assertTrue(isset($list['memberroles']), 'memberroles missing from list');
     $this->assertEquals(1, count($list['memberroles']), 'member roles are not saved/returned in list: ' . print_r($list, true));
     $this->assertTrue(isset($list['memberroles'][0]['list_role_id']['id']), 'list roles should be resolved');
     $this->assertEquals($listRole['id'], $list['memberroles'][0]['list_role_id']['id'], 'member roles are not saved/returned in list: ' . print_r($list, true));
     $list['memberroles'] = array();
     $updatedList = $this->_uit->saveList($list);
     $this->assertTrue(empty($updatedList['memberroles']), 'memberroles should be removed: ' . print_r($updatedList, true));
 }
 /**
  * testContactDisabledFilter
  */
 public function testContactDisabledFilter()
 {
     $this->_makeSCleverVisibleAgain = TRUE;
     // hide sclever from adb
     $sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever');
     $sclever->visibility = Tinebase_Model_User::VISIBILITY_HIDDEN;
     Tinebase_User::getInstance()->updateUser($sclever);
     // search for her with ContactDisabledFilter
     $filter = array(array('field' => 'n_given', 'operator' => 'equals', 'value' => 'Susan'));
     $result = $this->_instance->searchContacts($filter, array());
     $this->assertEquals(0, $result['totalcount']);
     $filter[] = array('field' => 'showDisabled', 'operator' => 'equals', 'value' => TRUE);
     $result = $this->_instance->searchContacts($filter, array());
     $this->assertEquals(1, $result['totalcount']);
 }
 public function testAttachMultipleTagsToMultipleRecords()
 {
     $contact1 = $this->_addContact('contact1');
     $contact2 = $this->_addContact('contact2');
     $tag1 = Tinebase_Tags::getInstance()->create($this->_getTag(Tinebase_Model_Tag::TYPE_PERSONAL, 'tag1'));
     $tag2 = Tinebase_Tags::getInstance()->create($this->_getTag(Tinebase_Model_Tag::TYPE_PERSONAL, 'tag2'));
     $filter = array(array('field' => 'id', 'operator' => 'in', 'value' => array($contact1['id'], $contact2['id'])));
     $json = new Tinebase_Frontend_Json();
     $json->attachMultipleTagsToMultipleRecords($filter, 'Addressbook_Model_ContactFilter', array($tag1->toArray(), $tag2->toArray()));
     $result = $this->_instance->searchContacts($filter, array());
     $this->assertCount(2, $result['results'], 'search count failed');
     foreach ($result['results'] as $contactData) {
         $this->assertCount(2, $contactData['tags'], $contactData['n_fn'] . ' tags failed');
     }
 }
 /**
  * test searching records by bool as a customfield type
  * https://forge.tine20.org/mantisbt/view.php?id=6730
  */
 public function testSearchByBool()
 {
     $cf = self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact', 'definition' => array('type' => 'bool')));
     $this->_instance->addCustomField($cf);
     // contact1 with customfield bool = true
     $contact1 = new Addressbook_Model_Contact(array('n_given' => 'Rita', 'n_family' => 'Blütenrein'));
     $contact1->customfields = array($cf->name => true);
     $contact1 = Addressbook_Controller_Contact::getInstance()->create($contact1, false);
     // contact2 with customfield bool is not set -> should act like set to false
     $contact2 = new Addressbook_Model_Contact(array('n_given' => 'Rainer', 'n_family' => 'Blütenrein'));
     $contact2 = Addressbook_Controller_Contact::getInstance()->create($contact2, false);
     // test bool = true
     $json = new Addressbook_Frontend_Json();
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => true)), array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')))))), array());
     // test bool = false
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-bool = true (Rita Blütenrein)');
     $this->assertEquals('Rita', $result['results'][0]['n_given'], 'The Record should be Rita Blütenrein');
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => false)), array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')))))), array());
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-bool is not set (Rainer Blütenrein)');
     $this->assertEquals('Rainer', $result['results'][0]['n_given'], 'The Record should be Rainer Blütenrein');
 }
 /**
  * @see 0011704: PHP 7 can't decode empty JSON-strings
  */
 public function testEmptyPagingParamJsonDecode()
 {
     $filter = array(array('field' => 'n_family', 'operator' => 'equals', 'value' => 'somename'));
     $result = $this->_uit->searchContacts($filter, '');
     $this->assertEquals(0, $result['totalcount']);
 }
 /**
  * testSetRelationToFileInPersonalFolder
  * 
  * @see 0006736: Create File (Edit)InfoDialog
  */
 public function testSetRelationToFileInPersonalFolder()
 {
     $node = $this->testCreateFileNodeWithUTF8Filenames();
     $node['relations'] = array($this->_getRelationData($node));
     $node = $this->_json->saveNode($node);
     $adbJson = new Addressbook_Frontend_Json();
     $contact = $adbJson->getContact($node['relations'][0]['related_id']);
     $this->assertEquals(1, count($contact['relations']));
     $relatedNode = $contact['relations'][0]['related_record'];
     $this->assertEquals($node['name'], $relatedNode['name']);
     $pathRegEx = '@^/personal/[a-f0-9-]+/[0-9]+/' . preg_quote($relatedNode['name']) . '$@';
     $this->assertTrue(preg_match($pathRegEx, $relatedNode['path']) === 1, 'path mismatch: ' . print_r($relatedNode, TRUE) . ' regex: ' . $pathRegEx);
 }
 /**
  * on saving 
  */
 public function testUpdateTimeaccountWithRelatedContact()
 {
     $this->_getTimeaccount(array(), TRUE);
     $ta = $this->_lastCreatedRecord;
     $contactController = Addressbook_Controller_Contact::getInstance();
     $taController = Timetracker_Controller_Timeaccount::getInstance();
     $bday = new Tinebase_DateTime();
     $bday->setDate(2013, 12, 24);
     $bday->setTime(0, 0, 0);
     $contact = $contactController->create(new Addressbook_Model_Contact(array('n_given' => 'Test', 'n_family' => 'Unit', 'bday' => $bday)));
     $bday = $contact['bday'];
     Tinebase_Relations::getInstance()->setRelations('Timetracker_Model_Timeaccount', 'Sql', $ta['id'], array(array('related_backend' => 'Sql', 'type' => 'RESPONSIBLE', 'related_model' => 'Addressbook_Model_Contact', 'related_id' => $contact->getId(), 'own_degree' => 'sibling')));
     // update a few times, bday of contract should not change
     $tajson = $this->_json->getTimeaccount($ta['id']);
     $this->_json->saveTimeaccount($tajson);
     $tajson = $this->_json->getTimeaccount($ta['id']);
     $this->_json->saveTimeaccount($tajson);
     $tajson = $this->_json->getTimeaccount($ta['id']);
     $ajson = new Addressbook_Frontend_Json();
     $contactJson = $ajson->getContact($contact->getId());
     $this->assertEquals($bday->setTimezone(Tinebase_Core::getUserTimezone())->toString(), $contactJson['bday']);
 }
 /**
  * test searching records by record as a customfield type
  * https://forge.tine20.org/mantisbt/view.php?id=6730
  */
 public function testSearchByRecord()
 {
     $cf = self::getCustomField(array('application_id' => Tinebase_Application::getInstance()->getApplicationByName('Addressbook')->getId(), 'model' => 'Addressbook_Model_Contact', 'definition' => array('type' => 'record', "recordConfig" => array("value" => array("records" => "Tine.Sales.Model.Contract")))));
     $this->_instance->addCustomField($cf);
     $contract = Sales_Controller_Contract::getInstance()->create(new Sales_Model_Contract(array('number' => Tinebase_Record_Abstract::generateUID(10), 'title' => Tinebase_Record_Abstract::generateUID(10), 'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId())));
     // contact1 with customfield record = contract
     $contact1 = new Addressbook_Model_Contact(array('n_given' => 'Rita', 'n_family' => 'Blütenrein'));
     $contact1->customfields = array($cf->name => $contract->getId());
     $contact1 = Addressbook_Controller_Contact::getInstance()->create($contact1, false);
     // contact2 with customfield record is not set -> should act like without this record
     $contact2 = new Addressbook_Model_Contact(array('n_given' => 'Rainer', 'n_family' => 'Blütenrein'));
     $contact2 = Addressbook_Controller_Contact::getInstance()->create($contact2, false);
     $json = new Addressbook_Frontend_Json();
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId()))))))), array());
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record = contract (Rita Blütenrein)');
     $this->assertEquals('Rita', $result['results'][0]['n_given'], 'The Record should be Rita Blütenrein');
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "not", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())), array('field' => 'n_family', 'operator' => 'equals', 'value' => 'Blütenrein')))))), array());
     $this->assertEquals(1, $result['totalcount'], 'One Record should have been found where cf-record is not set (Rainer Blütenrein)');
     $this->assertEquals('Rainer', $result['results'][0]['n_given'], 'The Record should be Rainer Blütenrein');
     // search using the same cf filter in an or - filter
     $contract2 = Sales_Controller_Contract::getInstance()->create(new Sales_Model_Contract(array('number' => Tinebase_Record_Abstract::generateUID(10), 'title' => Tinebase_Record_Abstract::generateUID(10), 'container_id' => Tinebase_Container::getInstance()->getDefaultContainer('Sales_Model_Contract')->getId())));
     $contact2->customfields = array($cf->name => $contract2->getId());
     $contact2 = Addressbook_Controller_Contact::getInstance()->update($contact2, false);
     $result = $json->searchContacts(array(array("condition" => "OR", "filters" => array(array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract->getId())))), array("condition" => "AND", "filters" => array(array("field" => "customfield", "operator" => "equals", "value" => array("cfId" => $cf->getId(), "value" => $contract2->getId()))))))), array());
     $this->assertEquals(2, $result['totalcount'], 'Rainer and Rita should have been found.');
     $this->assertEquals('Blütenrein', $result['results'][0]['n_family'], 'Rainer and Rita should have been found.');
     $this->assertEquals('Blütenrein', $result['results'][1]['n_family'], 'Rainer and Rita should have been found.');
 }
 public function testPathResolvingForContacts()
 {
     $this->testBuildGroupMemberPathForContact();
     $adbJson = new Addressbook_Frontend_Json();
     $filter = $this->_getPathFilterArray('father');
     $result = $adbJson->searchContacts($filter, array());
     $this->assertEquals(2, $result['totalcount'], print_r($result['results'], true));
     $firstRecord = $result['results'][0];
     $this->assertTrue(isset($firstRecord['paths']), 'paths should be set in record' . print_r($firstRecord, true));
     // sometimes only 1 path is resolved. this is a little bit strange ...
     $this->assertGreaterThan(0, count($firstRecord['paths']), print_r($firstRecord['paths'], true));
     $this->assertContains('/grandparent', $firstRecord['paths'][0]['path'], 'could not find grandparent in paths of record' . print_r($firstRecord, true));
 }