Пример #1
0
 /**
  * Initialize a deal with raw data we got from the API
  *
  * @param  array   $data
  * @return deal
  */
 public static function initializeWithRawData($data)
 {
     $item = new Deal();
     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 'for_id':
             case 'language_name':
                 break;
             case 'deleted':
                 $item->setDeleted($value == 1);
                 break;
             case 'for':
                 if ($value === 'company') {
                     $item->setCompanyId($data['for_id']);
                 } else {
                     $item->setContactId($data['for_id']);
                 }
                 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;
 }
Пример #2
0
 /**
  * Updates a deal
  *
  * @param Deal $deal
  * @return void
  */
 public function dealsUpdateDeal(Deal $deal)
 {
     $fields = $deal->toArrayForApi(false);
     $fields['deal_id'] = (int) $deal->getId();
     $this->doCall('updateDeal.php', $fields);
     return;
 }
Пример #3
0
 /**
  * Tests teamleader->dealsAddDeal)
  */
 public function testOpportunitiesAddDeal()
 {
     $time = time();
     $contact = new Contact();
     $contact->setForename($time);
     $contact->setSurname($time);
     $contact->setEmail($time . '@example.com');
     $id = $this->teamleader->crmAddContact($contact);
     $contact->setId($id);
     $deal = new Deal();
     $deal->setTitle('title_' . $time);
     $deal->setSource('source_' . $time);
     $deal->setContactId($id);
     $deal->setResponsibleUserId(3187);
     $deal->setSysDepartmentId(2131);
     $response = $this->teamleader->dealsAddDeal($deal);
     $this->assertInternalType('integer', $response);
 }