Ejemplo n.º 1
0
 /**
  * @param Task[] $tasks
  * @return array
  */
 public function getTasksElement(array $tasks)
 {
     Task::fixArray($tasks);
     $leadsId = [];
     $contactsId = [];
     foreach ($tasks as $task) {
         if ($task->isContact()) {
             $contactsId[] = $task->element_id;
         } else {
             $leadsId[] = $task->element_id;
         }
     }
     $contacts = $this->getApi()->getContacts()->get(['id' => $contactsId]);
     $leads = $this->getApi()->getLeads()->get(['id' => $leadsId]);
     foreach ($tasks as $task) {
         if ($task->isContact()) {
             $task->placeElement($contacts[$task->element_id]);
         } else {
             $task->placeElement($leads[$task->element_id]);
         }
     }
     Contact::fixArray($contacts);
     Lead::fixArray($leads);
     foreach ($contacts as $key => $contact) {
         $leads[$key] = $contact;
     }
     return $leads;
 }
Ejemplo n.º 2
0
 public function getContactLeads(array $contacts)
 {
     Contact::fixArray($contacts);
     $links = $this->getApi()->getContacts()->byContacts(array_map(function ($l) {
         return $l->id;
     }, $contacts));
     $leads = $this->getApi()->getLeads()->get(['id' => array_map(function ($link) {
         return $link->lead_id;
     }, $links)]);
     /*
     foreach($contacts as $contact){
         foreach($contact->linked_leads_id as $leadId){
             $contact->pushLead($leads[$leadId]);
             $leads[$leadId]->pushContact($contact);
         }
     }
     */
     return $leads;
 }