Beispiel #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;
 }