public function diff(ContactCollection $collection) { $array = $collection->read(); $data = $this->read(); $result = array_diff_key($data, $array); return new ContactCollection($result); }
/** * `read()` function should return array of all contacts from stack. Keys are * hashes. For more info see `ContactTest.php` file comments */ public function testRead() { $contact1 = array('FirstName' => 'FirstName1', 'Email' => '*****@*****.**'); $contact2 = array('FirstName' => 'FirstName2', 'Email' => '*****@*****.**'); $c = new ContactCollection(array($contact1, $contact2)); $expected = $c->read(); foreach ($expected as $k => $e) { // Key should be a string $this->assertInternalType('string', $k); // Value should be instance of `Contact` class $this->assertInstanceOf('Wildsurfer\\Infusionsoft\\Contact', $e); } }
public function push(ContactCollection $collection) { $isdk = $this->getIsdk(); $count = $collection->count(); $result = array('skip' => new ContactCollection(), 'create' => new ContactCollection(), 'update' => new ContactCollection(), 'fail' => new ContactCollection()); $contacts = $collection->read(); switch ($count) { case 0: return $result; break; /** * If Collection has 1 contact we don't want to pull all contacts from * remote API. */ /** * If Collection has 1 contact we don't want to pull all contacts from * remote API. */ case 1: $contact = reset($contacts); $id = $contact->getId(); if ($id) { // Contact Id is set. Most likely this is update $c = $this->updateContact($contact); } else { // Contact ID not set. Most likely this is new contact $c = $this->createContact($contact); } if ($c->isCreated()) { $result['create']->create($c); } elseif ($c->isUpdated()) { $result['update']->create($c); } elseif ($c->isSkipped()) { $result['skip']->create($c); } elseif ($c->isFailed()) { $result['fail']->create($c); } break; default: foreach ($contacts as $contact) { $id = $contact->getId(); if ($id) { // Contact Id is set. Most likely this is update $c = $this->updateContact($contact); } else { // Contact ID not set. Most likely this is new contact $c = $this->createContact($contact); } if ($c->isCreated()) { $result['create']->create($c); } elseif ($c->isUpdated()) { $result['update']->create($c); } elseif ($c->isSkipped()) { $result['skip']->create($c); } elseif ($c->isFailed()) { $result['fail']->create($c); } } } return $result; }