Example #1
0
 /**
  * Добавляет связь контакт-сделка
  * @param Lead $lead
  * @throws Exception
  */
 public function addLead(Lead $lead)
 {
     if ($lead->isNew()) {
         throw new Exception('Сделка должна быть сохранённой');
     }
     $this->linked_leads_id[] = $lead->id;
 }
Example #2
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;
 }
Example #3
0
 public function getLeadsContacts(array $leads)
 {
     Lead::fixArray($leads);
     $links = $this->getApi()->getContacts()->byLeads(array_map(function ($l) {
         return $l->id;
     }, $leads));
     $contacts = $this->getApi()->getContacts()->get(['id' => array_map(function ($link) {
         return $link->contact_id;
     }, $links)]);
     return $contacts;
 }