Ejemplo n.º 1
0
 public function testSetGetTags()
 {
     $data = array('Id' => 1);
     $tags = array(1, 2);
     $c = new Contact($data);
     $c->setTags($tags);
     $this->assertEquals($tags, $c->getTags());
 }
Ejemplo n.º 2
0
 public function pull()
 {
     $allContacts = new ContactCollection();
     $isdk = $this->getIsdk();
     $fields = $this->getConfigFields();
     if (!in_array('Groups', array_values($fields))) {
         $fields[] = 'Groups';
     }
     if (!in_array('LastUpdated', array_values($fields))) {
         $fields[] = 'LastUpdated';
     }
     if (!in_array('Id', array_values($fields))) {
         $fields[] = 'Id';
     }
     $validTags = $this->getConfigTags();
     $limit = 1000;
     $page = 0;
     while (true) {
         $results = $isdk->dsQuery('Contact', $limit, $page, array('Id' => '%'), $fields);
         if (is_string($results)) {
             throw new SyncException($results);
         } else {
             if (is_array($results)) {
                 foreach ($results as $r) {
                     $tags = array();
                     if (!empty($r['Groups'])) {
                         $tags = array_intersect(explode(',', $r['Groups']), $validTags);
                         unset($r['Groups']);
                     }
                     $c = new Contact($r);
                     $c->setTags($tags);
                     $allContacts->create($c);
                 }
             }
         }
         if (count($results) < $limit) {
             break;
         }
         $page++;
     }
     return $allContacts;
 }
Ejemplo n.º 3
0
 public function testPushUpdateWithTags()
 {
     $unique = md5(microtime());
     $isdk = $this->i->getIsdk();
     $tId1 = $isdk->dsAdd('ContactGroup', array('GroupName' => '1' . $unique));
     $tId2 = $isdk->dsAdd('ContactGroup', array('GroupName' => '2' . $unique));
     $tId3 = $isdk->dsAdd('ContactGroup', array('GroupName' => '3' . $unique));
     $validTags = array($tId1 => '1' . $unique, $tId2 => '2' . $unique, $tId3 => '3' . $unique);
     $config = $this->testConfig;
     $config['tags'] = array_keys($validTags);
     $i = new Sync($config);
     $contact = new Contact(array('Email' => $unique . '@test.com', 'FirstName' => $unique, 'OwnerID' => 0));
     $contact->setTags(array($tId1));
     $collection = new ContactCollection();
     $collection->create($contact);
     $c = $i->push($collection);
     $read = $c['create']->read();
     $data = reset($read);
     $dataUpdate = $data->getData();
     $dataUpdate['Id'] = $data->getId();
     $contactUpdate = new Contact($dataUpdate);
     $contactUpdate->setTags(array($tId2, $tId3));
     $collection = new ContactCollection();
     $collection->create($contactUpdate);
     $c = $i->push($collection);
     $read = $c['update']->read();
     $data = reset($read);
     $expectedTags = $isdk->dsQuery('ContactGroupAssign', 1000, 0, array('ContactId' => $data->getId()), array('GroupId'));
     $this->assertCount(2, $expectedTags);
     $isdk->dsDelete('Contact', $data->getId());
     $isdk->dsDelete('ContactGroup', $tId1);
     $isdk->dsDelete('ContactGroup', $tId2);
     $isdk->dsDelete('ContactGroup', $tId3);
 }