Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * 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;
 }
Esempio n. 4
0
 /**
  * Parse data model of Teamleader for add/update
  *
  * @param Model\Company $company
  * @param array $parameters
  * @return array
  */
 protected function parseCompanyParameters(Model\Company $company, $parameters = [])
 {
     $fields = ['company_id' => $company->getId(), 'name' => $company->getName(), 'vat_code' => $company->getTaxCode(), 'city' => $company->getCity(), 'zipcode' => $company->getZipCode(), 'street' => $company->getStreet(), 'number' => $company->getNumber(), 'country' => $company->getCountry(), 'telephone' => $company->getTelephone(), 'website' => $company->getWebsite(), 'fax' => $company->getFax(), 'email' => $company->getEmail(), 'business_type' => $company->getBusinessType()];
     // @todo tags
     // Include dynamic extra addresses
     if ($company->getExtraAddresses()) {
         foreach ($company->getExtraAddresses() as $type => $data) {
             foreach ($data as $key => $value) {
                 $fields[$key . "_" . $type] = $value;
             }
         }
     }
     // Include the custom fields
     if ($company->getCustomFields()) {
         foreach ($company->getCustomFields() as $id => $value) {
             $fields['custom_field_' . $id] = $value;
         }
     }
     return array_merge($parameters, $fields);
 }