Example #1
0
 public function crmLinkContactToCompany(Contact $contact, Company $company, $mode = 'link', $function = null)
 {
     $fields = array();
     $fields['contact_id'] = $contact->getId();
     $fields['company_id'] = $company->getId();
     $fields['mode'] = $mode;
     if ($function) {
         $fields['function'] = $function;
     }
     return $this->doCall('linkContactToCompany.php', $fields);
 }
Example #2
0
 /**
  * Initialize a Contact with raw data we got from the API
  *
  * @param  array   $data
  * @return Contact
  */
 public static function initializeWithRawData($data)
 {
     $item = new Contact();
     foreach ($data as $key => $value) {
         switch ($key) {
             case substr($key, 0, 3) == 'cf_':
                 $chunks = explode('_', $key);
                 $id = end($chunks);
                 $item->setCustomField($id, $value);
                 break;
             case 'language_name':
                 break;
             case 'deleted':
                 $item->setDeleted($value == 1);
                 break;
             default:
                 // ignore empty values
                 if ($value == '') {
                     continue;
                 }
                 $methodName = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
                 if (!method_exists(__CLASS__, $methodName)) {
                     if (Teamleader::DEBUG) {
                         var_dump($key, $value);
                         throw new Exception('Unknown method (' . $methodName . ')');
                     }
                 } else {
                     call_user_func(array($item, $methodName), $value);
                 }
         }
     }
     return $item;
 }
Example #3
0
 /**
  * Tests teamleader->invoicesGetCreditnotes()
  */
 public function testSubscriptionsAddSubscription()
 {
     $time = time();
     $contact = new Contact();
     $contact->setForename($time);
     $contact->setSurname($time);
     $contact->setEmail($time . '@example.com');
     $id = $this->teamleader->crmAddContact($contact);
     $contact->setId($id);
     $subscription = new Subscription();
     $subscription->setContact($contact);
     $subscription->setSysDepartmentId(2131);
     $subscription->setTitle($time);
     $subscription->setDateStart($time);
     $subscription->setRepeatAfter('monthly');
     $line1 = new SubscriptionLine();
     $line1->setAmount(1);
     $line1->setDescription('Description ' . $time);
     $line1->setPrice(30);
     $line1->setVat('06');
     $subscription->addLine($line1);
     $id = $this->teamleader->subscriptionsAddSubscription($subscription);
     $this->assertEquals($subscription->getId(), $id);
 }