/** * Get deals based on given client * * @param Model\Contact|null $contact * @param Model\Company $company * @return array<Model\Deal> * @throws ArgumentException */ public function getDealsByContactOrCompany(Model\Contact $contact = null, Model\Company $company) { if ($contact !== null && $company !== null) { throw new ArgumentException('Both contact and company are given, only one is expected.', 1440418090); } $action = 'getDealsByContactOrCompany.php'; $parameters = []; if ($contact !== null) { $parameters['contact_or_company'] = 'contact'; $parameters['contact_or_company_id'] = $contact->getId(); } elseif ($company !== null) { $parameters['contact_or_company'] = 'company'; $parameters['contact_or_company_id'] = $company->getId(); } $response = $this->doRequest($action, $parameters); $deals = []; foreach ((array) $response as $deal) { $deals[] = Model\Deal::_create($deal); } return $deals; }
/** * Retrieve tickets based on given client * * @param string $type Model\Ticket::TYPE_* * @param Model\Contact $contact * @param Model\Company $company * @param boolean $deepSearch * @return array<Model\Ticket> * @throws ArgumentException */ public function getTickets($type, Model\Contact $contact = null, Model\Company $company = null, $deepSearch = null) { $action = 'getTickets.php'; $parameters = ['type' => $type]; if ($contact !== null && $company !== null) { throw new ArgumentException('Both contact and company are given, only one is expected.', 1440420214); } elseif (null !== $contact) { $parameters['contact_or_company'] = 'contact'; $parameters['contact_or_company_id'] = $contact->getId(); } elseif (null !== $company) { $parameters['contact_or_company'] = 'company'; $parameters['contact_or_company_id'] = $company->getId(); } if (null !== $deepSearch) { $parameters['deep_search'] = $deepSearch; } $response = $this->doRequest($action, $parameters); $tickets = []; foreach ((array) $response as $ticket) { $tickets[] = Model\Ticket::_create($ticket); } return $tickets; }
/** * Get all linked clients based on given project * * @return array<Model\LinkedProjectClient> */ public function getRelatedPartiesByProject(Model\Project $project) { $action = 'getRelatedPartiesByProject.php'; $parameters = ['project_id' => $project->getId()]; $response = $this->doRequest($action, $parameters); $parties = []; foreach ($response as $client) { $projectClient = new Model\LinkedProjectClient(); $projectClient->setProject($project); switch ($client['type']) { case 'company': $projectClient->setClient(Model\Company::_create($client)); break; case 'contact': $projectClient->setClient(Model\Contact::_create($client)); break; } $projectClient->setGroup($client['group']); $projectClient->setRole($client['role']); $parties[] = $projectClient; } return $parties; }
/** * Parse data model of Teamleader for add/update * * @param Model\Contact $contact * @param array $parameters * @return array */ protected function parseContactParameters(Model\Contact $contact, $parameters = []) { $fields = ['contact_id' => $contact->getId(), 'forename' => $contact->getForename(), 'surname' => $contact->getSurname(), 'email' => $contact->getEmail(), 'telephone' => $contact->getTelephone(), 'gsm' => $contact->getGsm(), 'website' => $contact->getWebsite(), 'country' => $contact->getCountry(), 'zipcode' => $contact->getZipcode(), 'city' => $contact->getCity(), 'street' => $contact->getStreet(), 'number' => $contact->getNumber(), 'language' => $contact->getLanguage(), 'gender' => $contact->getGender(), 'dob' => $contact->getDob()]; // @todo tags // Include dynamic extra addresses if ($contact->getExtraAddresses()) { foreach ($contact->getExtraAddresses() as $type => $data) { foreach ($data as $key => $value) { $fields[$key . "_" . $type] = $value; } } } // Include the custom fields if ($contact->getCustomFields()) { foreach ($contact->getCustomFields() as $id => $value) { $fields['custom_field_' . $id] = $value; } } return array_merge($parameters, $fields); }