16643 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Command;
|
|
|
6 |
|
|
|
7 |
use Symfony\Component\Console\Command\Command;
|
|
|
8 |
use Symfony\Component\Console\Input\InputInterface;
|
|
|
9 |
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
10 |
use Laminas\Db\Adapter\AdapterInterface;
|
16768 |
efrain |
11 |
|
16643 |
efrain |
12 |
use Laminas\Log\LoggerInterface;
|
|
|
13 |
use GeoIp2\Database\Reader As GeoIp2Reader;
|
|
|
14 |
use LeadersLinked\Library\Functions;
|
|
|
15 |
use LeadersLinked\Mapper\CompanyServiceMapper;
|
|
|
16 |
use LeadersLinked\Mapper\DiscoveryContactInteractionTypeMapper;
|
|
|
17 |
use LeadersLinked\Model\Service;
|
|
|
18 |
use LeadersLinked\Model\DiscoveryContactInteractionType;
|
|
|
19 |
use LeadersLinked\Mapper\DiscoveryContactLogMapper;
|
|
|
20 |
use LeadersLinked\Mapper\DiscoveryContactMapper;
|
|
|
21 |
use LeadersLinked\Mapper\DiscoveryContactInteractionMapper;
|
|
|
22 |
use LeadersLinked\Model\DiscoveryContactLog;
|
|
|
23 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
24 |
|
|
|
25 |
class CheckDiscoveryContactCommand extends Command
|
|
|
26 |
{
|
|
|
27 |
/**
|
|
|
28 |
*
|
16769 |
efrain |
29 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
16643 |
efrain |
30 |
*/
|
|
|
31 |
private $adapter;
|
|
|
32 |
|
16769 |
efrain |
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @var \LeadersLinked\Cache\CacheInterface
|
|
|
36 |
*/
|
|
|
37 |
private $cache;
|
16643 |
efrain |
38 |
|
16769 |
efrain |
39 |
|
16643 |
efrain |
40 |
/**
|
|
|
41 |
*
|
16769 |
efrain |
42 |
* @var \Laminas\Log\LoggerInterface
|
16643 |
efrain |
43 |
*/
|
|
|
44 |
private $logger;
|
16769 |
efrain |
45 |
|
16643 |
efrain |
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @var array
|
|
|
49 |
*/
|
|
|
50 |
private $config;
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
*
|
16769 |
efrain |
55 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
56 |
*/
|
|
|
57 |
private $translator;
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
*
|
|
|
62 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
63 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
64 |
* @param \Laminas\Log\LoggerInterface
|
16643 |
efrain |
65 |
* @param array $config
|
16769 |
efrain |
66 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
16643 |
efrain |
67 |
*/
|
16769 |
efrain |
68 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
16643 |
efrain |
69 |
{
|
|
|
70 |
$this->adapter = $adapter;
|
16769 |
efrain |
71 |
$this->cache = $cache;
|
16643 |
efrain |
72 |
$this->logger = $logger;
|
|
|
73 |
$this->config = $config;
|
16769 |
efrain |
74 |
$this->translator = $translator;
|
16643 |
efrain |
75 |
|
|
|
76 |
parent::__construct();
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
protected function execute(InputInterface $input, OutputInterface $output) : int
|
|
|
81 |
{
|
|
|
82 |
$output->writeln('Inicio del proceso');
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
86 |
|
|
|
87 |
$companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);
|
|
|
88 |
$companiesService = $companyServiceMapper->fetchAllActiveByServiceId(Service::DISCOVERY_CONTACTS);
|
|
|
89 |
|
|
|
90 |
$discoveryContactInteractionTypeMapper = DiscoveryContactInteractionTypeMapper::getInstance($this->adapter);
|
|
|
91 |
|
|
|
92 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
93 |
$discoveryContactInteractionMapper = DiscoveryContactInteractionMapper::getInstance($this->adapter);
|
|
|
94 |
$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
|
|
|
95 |
|
|
|
96 |
foreach($companiesService as $companyService)
|
|
|
97 |
{
|
|
|
98 |
$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneDefaultByCompanyId($companyService->company_id);
|
|
|
99 |
if(!$discoveryContactInteractionTypeDefault) {
|
|
|
100 |
$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneFirstActiveByCompanyId($companyService->company_id);
|
|
|
101 |
$discoveryContactInteractionTypeDefault->default = DiscoveryContactInteractionType::DEFAULT_YES;
|
|
|
102 |
$discoveryContactInteractionTypeMapper->update($discoveryContactInteractionTypeDefault);
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
$discoveryContacts = $discoveryContactMapper ->fetchAllByCompanyId($companyService->company_id);
|
|
|
111 |
foreach($discoveryContacts as $discoveryContact)
|
|
|
112 |
{
|
|
|
113 |
$discoveryContactInteraction = $discoveryContactInteractionMapper->fetchByContactIdAndInteractionTypeId($discoveryContact->id, $discoveryContactInteractionTypeDefault->id);
|
|
|
114 |
if($discoveryContactInteraction) {
|
|
|
115 |
$discoveryContactLog = $discoveryContactLogMapper->fetchOneFirstByContactId($discoveryContact->id);
|
|
|
116 |
if(!$discoveryContactLog) {
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
$discoveryContactLog = new DiscoveryContactLog();
|
|
|
121 |
$discoveryContactLog->company_id = $discoveryContactInteraction->company_id;
|
|
|
122 |
$discoveryContactLog->contact_id = $discoveryContact->id;
|
|
|
123 |
$discoveryContactLog->user_id = $discoveryContactInteraction->user_id;
|
|
|
124 |
$discoveryContactLog->activity = 'LABEL_RECORD_CONTACT_ADDED';
|
|
|
125 |
$discoveryContactLog->details = 'LABEL_FIRST_NAME : ' . $discoveryContact->first_name . PHP_EOL .
|
|
|
126 |
'LABEL_LAST_NAME : ' . $discoveryContact->last_name . PHP_EOL .
|
|
|
127 |
'LABEL_CORPORATE_EMAIL : ' . $discoveryContact->corporate_email . PHP_EOL .
|
|
|
128 |
'LABEL_COMPANY : ' . $discoveryContact->company . PHP_EOL .
|
|
|
129 |
'LABEL_POSITION : ' . $discoveryContact->position . PHP_EOL .
|
|
|
130 |
'LABEL_COUNTRY : ' . $discoveryContact->country . PHP_EOL;
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
if ($discoveryContact->state) {
|
|
|
134 |
$discoveryContactLog->details .= 'LABEL_STATE : ' . $discoveryContact->state . PHP_EOL;
|
|
|
135 |
}
|
|
|
136 |
if ($discoveryContact->city) {
|
|
|
137 |
$discoveryContactLog->details .= 'LABEL_CITY : ' . $discoveryContact->city . PHP_EOL;
|
|
|
138 |
}
|
|
|
139 |
if ($discoveryContact->phone) {
|
|
|
140 |
$discoveryContactLog->details .= 'LABEL_PHONE : ' . $discoveryContact->phone . PHP_EOL;
|
|
|
141 |
}
|
|
|
142 |
if ($discoveryContact->phone_extension) {
|
|
|
143 |
$discoveryContactLog->details .= 'LABEL_PHONE_EXTENSION : ' . $discoveryContact->phone_extension . PHP_EOL;
|
|
|
144 |
}
|
|
|
145 |
if ($discoveryContact->personal_email) {
|
|
|
146 |
$discoveryContactLog->details .= 'LABEL_PERSONAL_EMAIL : ' . $discoveryContact->personal_email . PHP_EOL;
|
|
|
147 |
}
|
|
|
148 |
if ($discoveryContact->celular) {
|
|
|
149 |
$discoveryContactLog->details .= 'LABEL_CELULAR : ' . $discoveryContact->celular . PHP_EOL;
|
|
|
150 |
}
|
|
|
151 |
if ($discoveryContact->whatsapp) {
|
|
|
152 |
$discoveryContactLog->details .= 'LABEL_WHATSAPP : ' . $discoveryContact->whatsapp . PHP_EOL;
|
|
|
153 |
}
|
|
|
154 |
if ($discoveryContact->linkedin) {
|
|
|
155 |
$discoveryContactLog->details .= 'LABEL_LINKEDIN : ' . $discoveryContact->linkedin . PHP_EOL;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
$values = $hydrator->extract($discoveryContactLog);
|
|
|
159 |
$values['added_on'] = $discoveryContactInteraction->added_on;
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
$discoveryContactLogMapper->insertRaw($values);
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
} else {
|
|
|
167 |
$discoveryContactLog = $discoveryContactLogMapper->fetchOneFirstByContactId($discoveryContact->id);
|
|
|
168 |
if($discoveryContactLog) {
|
|
|
169 |
$values = [
|
|
|
170 |
'company_id' => $discoveryContact->company_id,
|
|
|
171 |
'contact_id' => $discoveryContact->id,
|
|
|
172 |
'user_id' => $discoveryContactLog->user_id,
|
|
|
173 |
'interaction_type_id' => $discoveryContactInteractionTypeDefault->id,
|
|
|
174 |
'notes' => '',
|
|
|
175 |
'added_on' => $discoveryContactLog->added_on
|
|
|
176 |
] ;
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
$discoveryContactInteractionMapper->insertRaw($values);
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
$output->writeln('Fin del proceso');
|
|
|
199 |
|
|
|
200 |
return 0;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
}
|