public function create($contact = array())
 {
     if (is_array($contact)) {
         $contact = new Contact($contact);
     } elseif (!$contact instanceof Contact) {
         throw new Exception('Not instance of `Contact` class');
     }
     $this->stack[$contact->uniqueHash()] = $contact;
     return $this;
 }
예제 #2
0
 /**
  * 'uniqueHash()' should serialize all data and return unique hash. It will
  * be used to verify if data changed or not
  */
 public function testUniqueHash()
 {
     $tags = array(1, 2, 3);
     $c = new Contact(array('Id' => 1, 'FirstName' => 'FirstName', 'Email' => '*****@*****.**'));
     $c1 = new Contact(array('Id' => 1, 'FirstName' => 'FirstName', 'Email' => '*****@*****.**'), $tags);
     $h = $c->uniqueHash();
     $h1 = $c1->uniqueHash();
     $this->assertInternalType('string', $h);
     $this->assertEquals(32, strlen($h));
     $this->assertNotEquals($h1, $h);
 }
예제 #3
0
 public function updateContact(Contact $contact)
 {
     $isdk = $this->getIsdk();
     try {
         $remote = $this->loadContact($contact->getId());
         if (is_string($remote)) {
             $contact->setErrorMessage($remote);
             $contact->setIsFailed();
         } else {
             if ($remote->uniqueHash() == $contact->uniqueHash()) {
                 $contact->setIsSkipped();
             } else {
                 $response = $isdk->updateCon($contact->getId(), $contact->getData());
                 if (is_string($response)) {
                     $messsage = 'Add failed. Error:' . $response;
                     $contact->setErrorMessage($messsage);
                     $contact->setIsFailed();
                 } else {
                     $contact->setId($response);
                     $contact->setIsUpdated();
                     $remoteTags = $remote->getTags();
                     $tags = $contact->getTags();
                     $diff = array_diff($tags, $remoteTags);
                     foreach ($diff as $d) {
                         $response1 = $isdk->grpAssign($contact->getId(), $d);
                         if (is_string($response1)) {
                             $messsage1 = 'Add Tag failed. Error:' . $response1;
                             $isdk->updateCon($contact->getId(), $remote->getData());
                             $contact->setErrorMessage($messsage1);
                             $contact->setIsFailed();
                             break;
                         }
                     }
                     $diffRemote = array_diff($remoteTags, $tags);
                     foreach ($diffRemote as $dr) {
                         $response2 = $isdk->grpRemove($contact->getId(), $dr);
                         if (is_string($response2)) {
                             $messsage1 = 'Delete Tag failed. Error:' . $response2;
                             $isdk->updateCon($contact->getId(), $remote->getData());
                             $contact->setErrorMessage($messsage2);
                             $contact->setIsFailed();
                             break;
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $contact->setErrorMessage($e->getMessage());
         $contact->setIsFailed();
     }
     return $contact;
 }