15397 |
efrain |
1 |
<?php
|
15623 |
anderson |
2 |
|
15397 |
efrain |
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
8 |
|
16768 |
efrain |
9 |
|
15397 |
efrain |
10 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
|
|
|
13 |
use Laminas\View\Model\ViewModel;
|
|
|
14 |
use Laminas\View\Model\JsonModel;
|
|
|
15 |
use LeadersLinked\Library\Functions;
|
|
|
16 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
17 |
use LeadersLinked\Model\DiscoveryContact;
|
|
|
18 |
use LeadersLinked\Mapper\DiscoveryContactMapper;
|
|
|
19 |
use LeadersLinked\Form\DiscoveryContact\ContactForm;
|
|
|
20 |
use LeadersLinked\Model\DiscoveryContactLog;
|
|
|
21 |
use LeadersLinked\Mapper\DiscoveryContactLogMapper;
|
|
|
22 |
use LeadersLinked\Form\DiscoveryContact\InteractionForm;
|
15546 |
efrain |
23 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
24 |
use LeadersLinked\Form\DiscoveryContact\ContactUploadForm;
|
|
|
25 |
use LeadersLinked\Mapper\DiscoveryContactInteractionMapper;
|
|
|
26 |
use LeadersLinked\Mapper\DiscoveryContactInteractionTypeMapper;
|
|
|
27 |
use LeadersLinked\Model\DiscoveryContactInteraction;
|
16643 |
efrain |
28 |
use LeadersLinked\Model\DiscoveryContactInteractionType;
|
16768 |
efrain |
29 |
use LeadersLinked\Cache\CacheInterface;
|
|
|
30 |
use LeadersLinked\Cache\CacheImpl;
|
16971 |
efrain |
31 |
use LeadersLinked\Mapper\DiscoveryContactBlackListMapper;
|
15397 |
efrain |
32 |
|
|
|
33 |
|
|
|
34 |
class DiscoveryContactController extends AbstractActionController
|
|
|
35 |
{
|
|
|
36 |
/**
|
|
|
37 |
*
|
16769 |
efrain |
38 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
15397 |
efrain |
39 |
*/
|
|
|
40 |
private $adapter;
|
16768 |
efrain |
41 |
|
15397 |
efrain |
42 |
/**
|
|
|
43 |
*
|
16769 |
efrain |
44 |
* @var \LeadersLinked\Cache\CacheInterface
|
15397 |
efrain |
45 |
*/
|
16769 |
efrain |
46 |
private $cache;
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
*
|
|
|
51 |
* @var \Laminas\Log\LoggerInterface
|
|
|
52 |
*/
|
15397 |
efrain |
53 |
private $logger;
|
16768 |
efrain |
54 |
|
15397 |
efrain |
55 |
/**
|
|
|
56 |
*
|
|
|
57 |
* @var array
|
|
|
58 |
*/
|
|
|
59 |
private $config;
|
16768 |
efrain |
60 |
|
16769 |
efrain |
61 |
|
15397 |
efrain |
62 |
/**
|
16769 |
efrain |
63 |
*
|
|
|
64 |
* @var \Laminas\Mvc\I18n\Translator
|
16768 |
efrain |
65 |
*/
|
16769 |
efrain |
66 |
private $translator;
|
16768 |
efrain |
67 |
|
16769 |
efrain |
68 |
|
16768 |
efrain |
69 |
/**
|
15397 |
efrain |
70 |
*
|
16769 |
efrain |
71 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
72 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
73 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
15397 |
efrain |
74 |
* @param array $config
|
16769 |
efrain |
75 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
15397 |
efrain |
76 |
*/
|
16769 |
efrain |
77 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
15397 |
efrain |
78 |
{
|
16769 |
efrain |
79 |
$this->adapter = $adapter;
|
|
|
80 |
$this->cache = $cache;
|
|
|
81 |
$this->logger = $logger;
|
|
|
82 |
$this->config = $config;
|
|
|
83 |
$this->translator = $translator;
|
15397 |
efrain |
84 |
}
|
15623 |
anderson |
85 |
|
15397 |
efrain |
86 |
public function indexAction()
|
|
|
87 |
{
|
|
|
88 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
89 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
90 |
$currentCompany = $currentUserPlugin->getCompany();
|
15623 |
anderson |
91 |
|
15397 |
efrain |
92 |
$request = $this->getRequest();
|
15623 |
anderson |
93 |
if ($request->isGet()) {
|
|
|
94 |
|
|
|
95 |
|
15397 |
efrain |
96 |
$headers = $request->getHeaders();
|
15623 |
anderson |
97 |
|
15397 |
efrain |
98 |
$isJson = false;
|
15623 |
anderson |
99 |
if ($headers->has('Accept')) {
|
15397 |
efrain |
100 |
$accept = $headers->get('Accept');
|
15623 |
anderson |
101 |
|
15397 |
efrain |
102 |
$prioritized = $accept->getPrioritized();
|
15623 |
anderson |
103 |
|
|
|
104 |
foreach ($prioritized as $key => $value) {
|
15397 |
efrain |
105 |
$raw = trim($value->getRaw());
|
15623 |
anderson |
106 |
|
|
|
107 |
if (!$isJson) {
|
15397 |
efrain |
108 |
$isJson = strpos($raw, 'json');
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
}
|
15623 |
anderson |
112 |
|
|
|
113 |
if ($isJson) {
|
15397 |
efrain |
114 |
$search = $this->params()->fromQuery('search');
|
16766 |
efrain |
115 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
15546 |
efrain |
116 |
|
15623 |
anderson |
117 |
|
16971 |
efrain |
118 |
|
|
|
119 |
|
15623 |
anderson |
120 |
|
15397 |
efrain |
121 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
122 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
123 |
$order = $this->params()->fromQuery('order', []);
|
|
|
124 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
16766 |
efrain |
125 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
|
15623 |
anderson |
126 |
|
16766 |
efrain |
127 |
$fields = ['first_name', 'last_name', 'corporate_email', 'company', 'country', 'sector', 'scholarship'];
|
15397 |
efrain |
128 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
|
15623 |
anderson |
129 |
|
|
|
130 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
15397 |
efrain |
131 |
$order_direction = 'ASC';
|
|
|
132 |
}
|
|
|
133 |
|
16971 |
efrain |
134 |
$discoveryContactBackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
135 |
$contact_ids = $discoveryContactBackListMapper->fetchAllContactIdsByCompanyId($currentCompany->id);
|
15623 |
anderson |
136 |
|
|
|
137 |
|
15397 |
efrain |
138 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
16971 |
efrain |
139 |
$paginator = $discoveryContactMapper->fetchAllDataTableForCompanyIdWithOutContactIds($search, $currentCompany->id, $page, $records_x_page, $order_field, $order_direction, $contact_ids);
|
15623 |
anderson |
140 |
|
15397 |
efrain |
141 |
$items = [];
|
|
|
142 |
$records = $paginator->getCurrentItems();
|
15623 |
anderson |
143 |
foreach ($records as $record) {
|
15397 |
efrain |
144 |
|
16766 |
efrain |
145 |
switch($record->scholarship)
|
|
|
146 |
{
|
|
|
147 |
case DiscoveryContact::SCHOLARSHIP_YES :
|
|
|
148 |
$scholarship = 'LABEL_YES';
|
|
|
149 |
break;
|
|
|
150 |
|
|
|
151 |
case DiscoveryContact::SCHOLARSHIP_NO :
|
|
|
152 |
$scholarship = 'LABEL_NO';
|
|
|
153 |
break;
|
|
|
154 |
|
|
|
155 |
default :
|
|
|
156 |
$scholarship = 'LABEL_UNKNOW';
|
|
|
157 |
break;
|
|
|
158 |
}
|
|
|
159 |
|
15623 |
anderson |
160 |
|
15397 |
efrain |
161 |
$item = [
|
|
|
162 |
'first_name' => $record->first_name,
|
|
|
163 |
'last_name' => $record->last_name,
|
|
|
164 |
'corporate_email' => $record->corporate_email,
|
15623 |
anderson |
165 |
'company' => $record->company,
|
|
|
166 |
'country' => $record->country,
|
15628 |
anderson |
167 |
'sector' => $record->sector,
|
16766 |
efrain |
168 |
'scholarship' => $scholarship,
|
15397 |
efrain |
169 |
'actions' => [
|
15623 |
anderson |
170 |
'link_edit' => $this->url()->fromRoute('discovery-contacts/edit', ['id' => $record->uuid]),
|
|
|
171 |
'link_delete' => $this->url()->fromRoute('discovery-contacts/delete', ['id' => $record->uuid]),
|
|
|
172 |
'link_view' => $this->url()->fromRoute('discovery-contacts/view', ['id' => $record->uuid]),
|
|
|
173 |
],
|
15397 |
efrain |
174 |
];
|
15623 |
anderson |
175 |
|
15397 |
efrain |
176 |
array_push($items, $item);
|
|
|
177 |
}
|
15623 |
anderson |
178 |
|
15397 |
efrain |
179 |
return new JsonModel([
|
|
|
180 |
'success' => true,
|
|
|
181 |
'data' => [
|
|
|
182 |
'items' => $items,
|
|
|
183 |
'total' => $paginator->getTotalItemCount(),
|
|
|
184 |
]
|
|
|
185 |
]);
|
|
|
186 |
} else {
|
15750 |
anderson |
187 |
$exclude_id = 0;
|
|
|
188 |
$form = new ContactForm($this->adapter, $currentCompany->id, $exclude_id);
|
|
|
189 |
$formInteraction = new InteractionForm($this->adapter, $currentCompany->id);
|
|
|
190 |
$contactUploadForm = new ContactUploadForm();
|
15623 |
anderson |
191 |
|
|
|
192 |
|
15750 |
anderson |
193 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
194 |
$viewModel = new ViewModel();
|
|
|
195 |
$viewModel->setTemplate('leaders-linked/discovery-contacts/index.phtml');
|
|
|
196 |
$viewModel->setVariables([
|
|
|
197 |
'form' => $form,
|
|
|
198 |
'formInteraction' => $formInteraction,
|
|
|
199 |
'contactUploadForm' => $contactUploadForm,
|
|
|
200 |
]);
|
|
|
201 |
return $viewModel;
|
15623 |
anderson |
202 |
}
|
15397 |
efrain |
203 |
} else {
|
|
|
204 |
return new JsonModel([
|
|
|
205 |
'success' => false,
|
|
|
206 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
207 |
]);;
|
|
|
208 |
}
|
|
|
209 |
}
|
15623 |
anderson |
210 |
|
15397 |
efrain |
211 |
public function addAction()
|
|
|
212 |
{
|
|
|
213 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
214 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
215 |
$currentCompany = $currentUserPlugin->getCompany();
|
15623 |
anderson |
216 |
|
15397 |
efrain |
217 |
$request = $this->getRequest();
|
15623 |
anderson |
218 |
if ($request->isPost()) {
|
15397 |
efrain |
219 |
$exclude_id = 0;
|
|
|
220 |
$form = new ContactForm($this->adapter, $currentCompany->id, $exclude_id);
|
|
|
221 |
$dataPost = $request->getPost()->toArray();
|
15623 |
anderson |
222 |
|
15397 |
efrain |
223 |
$form->setData($dataPost);
|
15623 |
anderson |
224 |
|
|
|
225 |
if ($form->isValid()) {
|
15397 |
efrain |
226 |
$dataPost = (array) $form->getData();
|
|
|
227 |
|
|
|
228 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
229 |
$discoveryContact = new DiscoveryContact();
|
|
|
230 |
$hydrator->hydrate($dataPost, $discoveryContact);
|
15623 |
anderson |
231 |
|
|
|
232 |
|
15397 |
efrain |
233 |
$discoveryContact->company_id = $currentCompany->id;
|
|
|
234 |
|
|
|
235 |
|
16643 |
efrain |
236 |
$discoveryContactInteractionTypeMapper = DiscoveryContactInteractionTypeMapper::getInstance($this->adapter);
|
|
|
237 |
$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneDefaultByCompanyId($currentCompany->id);
|
|
|
238 |
if(!$discoveryContactInteractionTypeDefault) {
|
|
|
239 |
$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneFirstActiveByCompanyId($currentCompany->id);
|
|
|
240 |
$discoveryContactInteractionTypeDefault->default = DiscoveryContactInteractionType::DEFAULT_YES;
|
|
|
241 |
$discoveryContactInteractionTypeMapper->update($discoveryContactInteractionTypeDefault);
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
|
15397 |
efrain |
245 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
246 |
$result = $discoveryContactMapper->insert($discoveryContact);
|
15623 |
anderson |
247 |
|
|
|
248 |
if ($result) {
|
|
|
249 |
$this->logger->info('Se agrego el Contacto : ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
250 |
|
16643 |
efrain |
251 |
if($discoveryContactInteractionTypeDefault) {
|
|
|
252 |
$discoveryContactInteraction = new DiscoveryContactInteraction();
|
|
|
253 |
$discoveryContactInteraction->company_id = $currentCompany->id;
|
|
|
254 |
$discoveryContactInteraction->user_id = $currentUser->id;
|
|
|
255 |
$discoveryContactInteraction->interaction_type_id = $discoveryContactInteractionTypeDefault->id;
|
|
|
256 |
|
|
|
257 |
$discoveryContactInteractionMapper = DiscoveryContactInteractionMapper::getInstance($this->adapter);
|
|
|
258 |
$discoveryContactInteractionMapper->insert($discoveryContactInteraction);
|
|
|
259 |
}
|
|
|
260 |
|
15397 |
efrain |
261 |
$discoveryContactLog = new DiscoveryContactLog();
|
|
|
262 |
$discoveryContactLog->company_id = $currentCompany->id;
|
|
|
263 |
$discoveryContactLog->contact_id = $discoveryContact->id;
|
|
|
264 |
$discoveryContactLog->user_id = $currentUser->id;
|
|
|
265 |
$discoveryContactLog->activity = 'LABEL_RECORD_CONTACT_ADDED';
|
15623 |
anderson |
266 |
$discoveryContactLog->details = 'LABEL_FIRST_NAME : ' . $discoveryContact->first_name . PHP_EOL .
|
|
|
267 |
'LABEL_LAST_NAME : ' . $discoveryContact->last_name . PHP_EOL .
|
|
|
268 |
'LABEL_CORPORATE_EMAIL : ' . $discoveryContact->corporate_email . PHP_EOL .
|
|
|
269 |
'LABEL_COMPANY : ' . $discoveryContact->company . PHP_EOL .
|
|
|
270 |
'LABEL_POSITION : ' . $discoveryContact->position . PHP_EOL .
|
|
|
271 |
'LABEL_COUNTRY : ' . $discoveryContact->country . PHP_EOL;
|
|
|
272 |
|
|
|
273 |
|
|
|
274 |
if ($discoveryContact->state) {
|
15397 |
efrain |
275 |
$discoveryContactLog->details .= 'LABEL_STATE : ' . $discoveryContact->state . PHP_EOL;
|
|
|
276 |
}
|
15623 |
anderson |
277 |
if ($discoveryContact->city) {
|
15397 |
efrain |
278 |
$discoveryContactLog->details .= 'LABEL_CITY : ' . $discoveryContact->city . PHP_EOL;
|
|
|
279 |
}
|
15623 |
anderson |
280 |
if ($discoveryContact->phone) {
|
15397 |
efrain |
281 |
$discoveryContactLog->details .= 'LABEL_PHONE : ' . $discoveryContact->phone . PHP_EOL;
|
|
|
282 |
}
|
15623 |
anderson |
283 |
if ($discoveryContact->phone_extension) {
|
15397 |
efrain |
284 |
$discoveryContactLog->details .= 'LABEL_PHONE_EXTENSION : ' . $discoveryContact->phone_extension . PHP_EOL;
|
|
|
285 |
}
|
15623 |
anderson |
286 |
if ($discoveryContact->personal_email) {
|
15397 |
efrain |
287 |
$discoveryContactLog->details .= 'LABEL_PERSONAL_EMAIL : ' . $discoveryContact->personal_email . PHP_EOL;
|
|
|
288 |
}
|
15623 |
anderson |
289 |
if ($discoveryContact->celular) {
|
15397 |
efrain |
290 |
$discoveryContactLog->details .= 'LABEL_CELULAR : ' . $discoveryContact->celular . PHP_EOL;
|
|
|
291 |
}
|
15623 |
anderson |
292 |
if ($discoveryContact->whatsapp) {
|
15397 |
efrain |
293 |
$discoveryContactLog->details .= 'LABEL_WHATSAPP : ' . $discoveryContact->whatsapp . PHP_EOL;
|
|
|
294 |
}
|
15623 |
anderson |
295 |
if ($discoveryContact->linkedin) {
|
15397 |
efrain |
296 |
$discoveryContactLog->details .= 'LABEL_LINKEDIN : ' . $discoveryContact->linkedin . PHP_EOL;
|
|
|
297 |
}
|
16766 |
efrain |
298 |
if ($discoveryContact->scholarship) {
|
|
|
299 |
$discoveryContactLog->details .= 'LABEL_SCHOLARSHIP : ' . $discoveryContact->scholarship . PHP_EOL;
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
|
15623 |
anderson |
303 |
|
15397 |
efrain |
304 |
$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
|
|
|
305 |
$discoveryContactLogMapper->insert($discoveryContactLog);
|
15623 |
anderson |
306 |
|
15397 |
efrain |
307 |
$data = [
|
|
|
308 |
'success' => true,
|
|
|
309 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
310 |
];
|
|
|
311 |
} else {
|
|
|
312 |
$data = [
|
|
|
313 |
'success' => false,
|
|
|
314 |
'data' => $discoveryContactMapper->getError()
|
|
|
315 |
];
|
|
|
316 |
}
|
15623 |
anderson |
317 |
|
15397 |
efrain |
318 |
return new JsonModel($data);
|
|
|
319 |
} else {
|
|
|
320 |
$messages = [];
|
|
|
321 |
$form_messages = (array) $form->getMessages();
|
15623 |
anderson |
322 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
323 |
|
15397 |
efrain |
324 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
325 |
}
|
15623 |
anderson |
326 |
|
15397 |
efrain |
327 |
return new JsonModel([
|
|
|
328 |
'success' => false,
|
|
|
329 |
'data' => $messages
|
|
|
330 |
]);
|
|
|
331 |
}
|
|
|
332 |
} else {
|
|
|
333 |
$data = [
|
|
|
334 |
'success' => false,
|
|
|
335 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
336 |
];
|
15623 |
anderson |
337 |
|
15397 |
efrain |
338 |
return new JsonModel($data);
|
|
|
339 |
}
|
15623 |
anderson |
340 |
|
15397 |
efrain |
341 |
return new JsonModel($data);
|
|
|
342 |
}
|
15623 |
anderson |
343 |
|
15397 |
efrain |
344 |
public function editAction()
|
|
|
345 |
{
|
|
|
346 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
347 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
348 |
$currentCompany = $currentUserPlugin->getCompany();
|
15623 |
anderson |
349 |
|
15397 |
efrain |
350 |
$request = $this->getRequest();
|
|
|
351 |
$uuid = $this->params()->fromRoute('id');
|
|
|
352 |
|
15623 |
anderson |
353 |
|
|
|
354 |
if (!$uuid) {
|
15397 |
efrain |
355 |
$data = [
|
|
|
356 |
'success' => false,
|
|
|
357 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
358 |
];
|
15623 |
anderson |
359 |
|
15397 |
efrain |
360 |
return new JsonModel($data);
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
364 |
$discoveryContact = $discoveryContactMapper->fetchOneByUuid($uuid);
|
15623 |
anderson |
365 |
if (!$discoveryContact) {
|
15397 |
efrain |
366 |
$data = [
|
|
|
367 |
'success' => false,
|
|
|
368 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
369 |
];
|
15623 |
anderson |
370 |
|
15397 |
efrain |
371 |
return new JsonModel($data);
|
|
|
372 |
}
|
15623 |
anderson |
373 |
|
15397 |
efrain |
374 |
$discoveryContactOld = clone $discoveryContact;
|
|
|
375 |
|
15623 |
anderson |
376 |
if ($request->isPost()) {
|
|
|
377 |
|
15397 |
efrain |
378 |
$form = new ContactForm($this->adapter, $currentCompany->id, $discoveryContact->id);
|
|
|
379 |
$dataPost = $request->getPost()->toArray();
|
|
|
380 |
|
|
|
381 |
$form->setData($dataPost);
|
15623 |
anderson |
382 |
|
|
|
383 |
if ($form->isValid()) {
|
15397 |
efrain |
384 |
$dataPost = (array) $form->getData();
|
15623 |
anderson |
385 |
|
15397 |
efrain |
386 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
387 |
$hydrator->hydrate($dataPost, $discoveryContact);
|
|
|
388 |
$result = $discoveryContactMapper->update($discoveryContact);
|
15623 |
anderson |
389 |
|
|
|
390 |
if ($result) {
|
15397 |
efrain |
391 |
$this->logger->info('Se actualizo el Contacto ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
15623 |
anderson |
392 |
|
|
|
393 |
|
15397 |
efrain |
394 |
$discoveryContactLog = new DiscoveryContactLog();
|
|
|
395 |
$discoveryContactLog->company_id = $currentCompany->id;
|
|
|
396 |
$discoveryContactLog->contact_id = $discoveryContact->id;
|
|
|
397 |
$discoveryContactLog->user_id = $currentUser->id;
|
|
|
398 |
$discoveryContactLog->activity = 'LABEL_RECORD_CONTACT_UPDATED';
|
|
|
399 |
$discoveryContactLog->details = '';
|
15623 |
anderson |
400 |
|
|
|
401 |
if ($discoveryContactOld->first_name != $discoveryContact->first_name) {
|
15397 |
efrain |
402 |
$discoveryContactLog->details .= 'LABEL_FIRST_NAME : ' . $discoveryContactOld->first_name . ' / ' . $discoveryContact->first_name . PHP_EOL;
|
|
|
403 |
}
|
15623 |
anderson |
404 |
if ($discoveryContactOld->last_name != $discoveryContact->last_name) {
|
|
|
405 |
$discoveryContactLog->details .= 'LABEL_LAST_NAME : ' . $discoveryContactOld->last_name . ' / ' . $discoveryContact->last_name . PHP_EOL;
|
15397 |
efrain |
406 |
}
|
15623 |
anderson |
407 |
if ($discoveryContactOld->corporate_email != $discoveryContact->corporate_email) {
|
|
|
408 |
$discoveryContactLog->details .= 'LABEL_CORPORATE_EMAIL : ' . $discoveryContactOld->corporate_email . ' / ' . $discoveryContact->corporate_email . PHP_EOL;
|
15397 |
efrain |
409 |
}
|
15623 |
anderson |
410 |
if ($discoveryContactOld->company != $discoveryContact->company) {
|
|
|
411 |
$discoveryContactLog->details .= 'LABEL_COMPANY : ' . $discoveryContactOld->company . ' / ' . $discoveryContact->company . PHP_EOL;
|
15397 |
efrain |
412 |
}
|
15623 |
anderson |
413 |
if ($discoveryContactOld->position != $discoveryContact->position) {
|
|
|
414 |
$discoveryContactLog->details .= 'LABEL_POSITION : ' . $discoveryContactOld->position . ' / ' . $discoveryContact->position . PHP_EOL;
|
15397 |
efrain |
415 |
}
|
15623 |
anderson |
416 |
if ($discoveryContactOld->country != $discoveryContact->country) {
|
15397 |
efrain |
417 |
$discoveryContactLog->details .= 'LABEL_COUNTRY : ' . $discoveryContactOld->country . ' / ' . $discoveryContact->country . PHP_EOL;
|
|
|
418 |
}
|
15623 |
anderson |
419 |
if ($discoveryContactOld->state != $discoveryContact->state) {
|
15397 |
efrain |
420 |
$discoveryContactLog->details .= 'LABEL_STATE : ' . $discoveryContactOld->state . ' / ' . $discoveryContact->state . PHP_EOL;
|
|
|
421 |
}
|
15623 |
anderson |
422 |
if ($discoveryContactOld->city != $discoveryContact->city) {
|
15397 |
efrain |
423 |
$discoveryContactLog->details .= 'LABEL_CITY : ' . $discoveryContactOld->city . ' / ' . $discoveryContact->city . PHP_EOL;
|
|
|
424 |
}
|
15623 |
anderson |
425 |
if ($discoveryContactOld->phone != $discoveryContact->phone) {
|
|
|
426 |
$discoveryContactLog->details .= 'LABEL_PHONE : ' . $discoveryContactOld->phone . ' / ' . $discoveryContact->phone . PHP_EOL;
|
15397 |
efrain |
427 |
}
|
15623 |
anderson |
428 |
|
|
|
429 |
if ($discoveryContactOld->phone_extension != $discoveryContact->phone_extension) {
|
15397 |
efrain |
430 |
$discoveryContactLog->details .= 'LABEL_PHONE_EXTENSION : ' . $discoveryContactOld->phone_extension . ' / ' . $discoveryContact->phone_extension . PHP_EOL;
|
|
|
431 |
}
|
15623 |
anderson |
432 |
if ($discoveryContactOld->personal_email != $discoveryContact->personal_email) {
|
15397 |
efrain |
433 |
$discoveryContactLog->details .= 'LABEL_PERSONAL_EMAIL : ' . $discoveryContactOld->personal_email . ' / ' . $discoveryContact->personal_email . PHP_EOL;
|
|
|
434 |
}
|
15623 |
anderson |
435 |
if ($discoveryContactOld->celular != $discoveryContact->celular) {
|
15397 |
efrain |
436 |
$discoveryContactLog->details .= 'LABEL_CELULAR : ' . $discoveryContactOld->celular . ' / ' . $discoveryContact->celular . PHP_EOL;
|
|
|
437 |
}
|
15623 |
anderson |
438 |
if ($discoveryContactOld->whatsapp != $discoveryContact->whatsapp) {
|
|
|
439 |
$discoveryContactLog->details .= 'LABEL_WHATSAPP : ' . $discoveryContactOld->whatsapp . ' / ' . $discoveryContact->whatsapp . PHP_EOL;
|
15397 |
efrain |
440 |
}
|
15623 |
anderson |
441 |
if ($discoveryContactOld->linkedin != $discoveryContact->linkedin) {
|
15397 |
efrain |
442 |
$discoveryContactLog->details .= 'LABEL_LINKEDIN : ' . $discoveryContactOld->linkedin . ' / ' . $discoveryContact->linkedin . PHP_EOL;
|
|
|
443 |
}
|
16766 |
efrain |
444 |
if ($discoveryContactOld->scholarship != $discoveryContact->scholarship) {
|
|
|
445 |
$discoveryContactLog->details .= 'LABEL_SCHOLARSHIP: ' . $discoveryContactOld->scholarship . ' / ' . $discoveryContact->scholarship . PHP_EOL;
|
|
|
446 |
}
|
15397 |
efrain |
447 |
$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
|
|
|
448 |
$discoveryContactLogMapper->insert($discoveryContactLog);
|
15623 |
anderson |
449 |
|
|
|
450 |
|
15397 |
efrain |
451 |
$data = [
|
|
|
452 |
'success' => true,
|
|
|
453 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
454 |
];
|
|
|
455 |
} else {
|
|
|
456 |
$data = [
|
|
|
457 |
'success' => false,
|
|
|
458 |
'data' => $discoveryContactMapper->getError()
|
|
|
459 |
];
|
|
|
460 |
}
|
15623 |
anderson |
461 |
|
15397 |
efrain |
462 |
return new JsonModel($data);
|
|
|
463 |
} else {
|
|
|
464 |
$messages = [];
|
|
|
465 |
$form_messages = (array) $form->getMessages();
|
15623 |
anderson |
466 |
foreach ($form_messages as $fieldname => $field_messages) {
|
15397 |
efrain |
467 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
468 |
}
|
15623 |
anderson |
469 |
|
15397 |
efrain |
470 |
return new JsonModel([
|
|
|
471 |
'success' => false,
|
|
|
472 |
'data' => $messages
|
|
|
473 |
]);
|
|
|
474 |
}
|
|
|
475 |
} else if ($request->isGet()) {
|
|
|
476 |
|
15623 |
anderson |
477 |
|
15397 |
efrain |
478 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
479 |
$data = $hydrator->extract($discoveryContact);
|
15623 |
anderson |
480 |
|
15397 |
efrain |
481 |
$data['first_name'] = $data['first_name'] ? trim($data['first_name']) : '';
|
|
|
482 |
$data['last_name'] = $data['last_name'] ? trim($data['last_name']) : '';
|
|
|
483 |
$data['corporate_email'] = $data['corporate_email'] ? trim($data['corporate_email']) : '';
|
|
|
484 |
$data['company'] = $data['company'] ? trim($data['company']) : '';
|
|
|
485 |
$data['position'] = $data['position'] ? trim($data['position']) : '';
|
|
|
486 |
$data['country'] = $data['country'] ? trim($data['country']) : '';
|
|
|
487 |
$data['state'] = $data['state'] ? trim($data['state']) : '';
|
|
|
488 |
$data['city'] = $data['city'] ? trim($data['city']) : '';
|
|
|
489 |
$data['phone'] = $data['phone'] ? trim($data['phone']) : '';
|
|
|
490 |
$data['phone_extension'] = $data['phone_extension'] ? trim($data['phone_extension']) : '';
|
|
|
491 |
$data['personal_email'] = $data['personal_email'] ? trim($data['personal_email']) : '';
|
|
|
492 |
$data['celular'] = $data['celular'] ? trim($data['celular']) : '';
|
|
|
493 |
$data['whatsapp'] = $data['whatsapp'] ? trim($data['whatsapp']) : '';
|
|
|
494 |
$data['linkedin'] = $data['linkedin'] ? trim($data['linkedin']) : '';
|
16766 |
efrain |
495 |
$data['scholarship'] = $data['scholarship'] ? trim($data['scholarship']) : '';
|
15623 |
anderson |
496 |
|
|
|
497 |
|
|
|
498 |
|
|
|
499 |
|
15397 |
efrain |
500 |
$result = [
|
|
|
501 |
'success' => true,
|
|
|
502 |
'data' => $data
|
|
|
503 |
];
|
15623 |
anderson |
504 |
|
15397 |
efrain |
505 |
return new JsonModel($result);
|
|
|
506 |
} else {
|
|
|
507 |
$data = [
|
|
|
508 |
'success' => false,
|
|
|
509 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
510 |
];
|
15623 |
anderson |
511 |
|
15397 |
efrain |
512 |
return new JsonModel($data);
|
|
|
513 |
}
|
15623 |
anderson |
514 |
|
15397 |
efrain |
515 |
return new JsonModel($data);
|
|
|
516 |
}
|
15623 |
anderson |
517 |
|
15397 |
efrain |
518 |
public function deleteAction()
|
|
|
519 |
{
|
|
|
520 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
521 |
$currentUser = $currentUserPlugin->getUser();
|
15623 |
anderson |
522 |
|
15397 |
efrain |
523 |
$request = $this->getRequest();
|
|
|
524 |
$uuid = $this->params()->fromRoute('id');
|
15623 |
anderson |
525 |
|
|
|
526 |
if (!$uuid) {
|
15397 |
efrain |
527 |
$data = [
|
|
|
528 |
'success' => false,
|
|
|
529 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
530 |
];
|
15623 |
anderson |
531 |
|
15397 |
efrain |
532 |
return new JsonModel($data);
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
536 |
$discoveryContact = $discoveryContactMapper->fetchOneByUuid($uuid);
|
15623 |
anderson |
537 |
if (!$discoveryContact) {
|
15397 |
efrain |
538 |
$data = [
|
|
|
539 |
'success' => false,
|
|
|
540 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
541 |
];
|
15623 |
anderson |
542 |
|
15397 |
efrain |
543 |
return new JsonModel($data);
|
|
|
544 |
}
|
15623 |
anderson |
545 |
|
|
|
546 |
if ($request->isPost()) {
|
15397 |
efrain |
547 |
$result = $discoveryContactMapper->delete($discoveryContact);
|
15623 |
anderson |
548 |
if ($result) {
|
15397 |
efrain |
549 |
$this->logger->info('Se borro el Contacto : ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
15623 |
anderson |
550 |
|
15397 |
efrain |
551 |
$data = [
|
|
|
552 |
'success' => true,
|
|
|
553 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
554 |
];
|
|
|
555 |
} else {
|
|
|
556 |
|
|
|
557 |
$data = [
|
|
|
558 |
'success' => false,
|
|
|
559 |
'data' => $discoveryContactMapper->getError()
|
|
|
560 |
];
|
|
|
561 |
|
|
|
562 |
return new JsonModel($data);
|
|
|
563 |
}
|
|
|
564 |
} else {
|
|
|
565 |
$data = [
|
|
|
566 |
'success' => false,
|
|
|
567 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
568 |
];
|
15623 |
anderson |
569 |
|
15397 |
efrain |
570 |
return new JsonModel($data);
|
|
|
571 |
}
|
15623 |
anderson |
572 |
|
15397 |
efrain |
573 |
return new JsonModel($data);
|
|
|
574 |
}
|
15623 |
anderson |
575 |
|
15397 |
efrain |
576 |
public function viewAction()
|
|
|
577 |
{
|
|
|
578 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
579 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
580 |
$currentCompany = $currentUserPlugin->getCompany();
|
15623 |
anderson |
581 |
|
15397 |
efrain |
582 |
$request = $this->getRequest();
|
|
|
583 |
$uuid = $this->params()->fromRoute('id');
|
15623 |
anderson |
584 |
|
|
|
585 |
|
|
|
586 |
if (!$uuid) {
|
15397 |
efrain |
587 |
$data = [
|
|
|
588 |
'success' => false,
|
|
|
589 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
590 |
];
|
15623 |
anderson |
591 |
|
15397 |
efrain |
592 |
return new JsonModel($data);
|
|
|
593 |
}
|
15623 |
anderson |
594 |
|
15397 |
efrain |
595 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
596 |
$discoveryContact = $discoveryContactMapper->fetchOneByUuid($uuid);
|
15623 |
anderson |
597 |
if (!$discoveryContact) {
|
15397 |
efrain |
598 |
$data = [
|
|
|
599 |
'success' => false,
|
|
|
600 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
601 |
];
|
15623 |
anderson |
602 |
|
15397 |
efrain |
603 |
return new JsonModel($data);
|
|
|
604 |
}
|
|
|
605 |
|
15623 |
anderson |
606 |
|
|
|
607 |
|
15397 |
efrain |
608 |
if ($request->isGet()) {
|
15623 |
anderson |
609 |
|
|
|
610 |
|
15397 |
efrain |
611 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
612 |
$data = $hydrator->extract($discoveryContact);
|
15623 |
anderson |
613 |
|
15397 |
efrain |
614 |
$data['first_name'] = $data['first_name'] ? trim($data['first_name']) : '';
|
|
|
615 |
$data['last_name'] = $data['last_name'] ? trim($data['last_name']) : '';
|
|
|
616 |
$data['corporate_email'] = $data['corporate_email'] ? trim($data['corporate_email']) : '';
|
|
|
617 |
$data['company'] = $data['company'] ? trim($data['company']) : '';
|
|
|
618 |
$data['position'] = $data['position'] ? trim($data['position']) : '';
|
|
|
619 |
$data['country'] = $data['country'] ? trim($data['country']) : '';
|
|
|
620 |
$data['state'] = $data['state'] ? trim($data['state']) : '';
|
|
|
621 |
$data['city'] = $data['city'] ? trim($data['city']) : '';
|
|
|
622 |
$data['phone'] = $data['phone'] ? trim($data['phone']) : '';
|
|
|
623 |
$data['phone_extension'] = $data['phone_extension'] ? trim($data['phone_extension']) : '';
|
|
|
624 |
$data['personal_email'] = $data['personal_email'] ? trim($data['personal_email']) : '';
|
|
|
625 |
$data['celular'] = $data['celular'] ? trim($data['celular']) : '';
|
|
|
626 |
$data['whatsapp'] = $data['whatsapp'] ? trim($data['whatsapp']) : '';
|
|
|
627 |
$data['linkedin'] = $data['linkedin'] ? trim($data['linkedin']) : '';
|
16766 |
efrain |
628 |
$data['scholarship'] = $data['scholarship'] ? trim($data['scholarship']) : '';
|
15623 |
anderson |
629 |
|
|
|
630 |
|
15397 |
efrain |
631 |
$data['link_interactions'] = $this->url()->fromRoute('discovery-contacts/interactions', ['id' => $discoveryContact->uuid]);
|
|
|
632 |
$data['link_interactions_add'] = $this->url()->fromRoute('discovery-contacts/interactions/add', ['id' => $discoveryContact->uuid]);
|
|
|
633 |
$data['link_logs'] = $this->url()->fromRoute('discovery-contacts/logs', ['id' => $discoveryContact->uuid]);
|
|
|
634 |
|
15623 |
anderson |
635 |
|
|
|
636 |
|
15397 |
efrain |
637 |
$result = [
|
|
|
638 |
'success' => true,
|
|
|
639 |
'data' => $data
|
|
|
640 |
];
|
15623 |
anderson |
641 |
|
15397 |
efrain |
642 |
return new JsonModel($result);
|
|
|
643 |
} else {
|
|
|
644 |
$data = [
|
|
|
645 |
'success' => false,
|
|
|
646 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
647 |
];
|
15623 |
anderson |
648 |
|
15397 |
efrain |
649 |
return new JsonModel($data);
|
|
|
650 |
}
|
15623 |
anderson |
651 |
|
15397 |
efrain |
652 |
return new JsonModel($data);
|
|
|
653 |
}
|
15623 |
anderson |
654 |
|
|
|
655 |
|
15546 |
efrain |
656 |
public function uploadAction()
|
|
|
657 |
{
|
|
|
658 |
$request = $this->getRequest();
|
15623 |
anderson |
659 |
|
15546 |
efrain |
660 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
661 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
662 |
$currentCompany = $currentUserPlugin->getCompany();
|
15623 |
anderson |
663 |
|
15546 |
efrain |
664 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
665 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
15623 |
anderson |
666 |
|
15546 |
efrain |
667 |
$request = $this->getRequest();
|
|
|
668 |
|
15623 |
anderson |
669 |
|
|
|
670 |
|
|
|
671 |
if ($request->isPost()) {
|
16972 |
efrain |
672 |
|
|
|
673 |
$step = Functions::sanitizeFilterString($this->params()->fromPost('step'));
|
15623 |
anderson |
674 |
if ($step == 'validation') {
|
16972 |
efrain |
675 |
|
|
|
676 |
|
|
|
677 |
|
15623 |
anderson |
678 |
|
|
|
679 |
|
15546 |
efrain |
680 |
$form = new ContactUploadForm();
|
|
|
681 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
15623 |
anderson |
682 |
|
15546 |
efrain |
683 |
$form->setData($dataPost);
|
15623 |
anderson |
684 |
|
|
|
685 |
if ($form->isValid()) {
|
|
|
686 |
|
15546 |
efrain |
687 |
$file = $_FILES['file'];
|
|
|
688 |
$tmp_filename = $file['tmp_name'];
|
|
|
689 |
$final_filename = 'data/' . $file['name'];
|
15623 |
anderson |
690 |
|
|
|
691 |
if (!move_uploaded_file($tmp_filename, $final_filename)) {
|
15546 |
efrain |
692 |
return new JsonModel([
|
|
|
693 |
'success' => false,
|
|
|
694 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
695 |
]);
|
|
|
696 |
}
|
15623 |
anderson |
697 |
|
|
|
698 |
|
15546 |
efrain |
699 |
$emails = [];
|
|
|
700 |
$contacts = [];
|
|
|
701 |
$spreadsheet = IOFactory::load($final_filename);
|
|
|
702 |
$records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
15623 |
anderson |
703 |
|
|
|
704 |
foreach ($records as $record) {
|
15546 |
efrain |
705 |
/*
|
|
|
706 |
A = Nombre
|
|
|
707 |
B = Apellido
|
|
|
708 |
C = Correo Personal
|
|
|
709 |
D = Correo Trabajo
|
|
|
710 |
E = Empresa
|
|
|
711 |
F = Puesto
|
|
|
712 |
G = Pais
|
|
|
713 |
H = Estado
|
|
|
714 |
I = Ciudad
|
|
|
715 |
J = Telefono
|
|
|
716 |
K = Extensión
|
|
|
717 |
L = Celular
|
|
|
718 |
M = Whatsapp
|
|
|
719 |
N = Linkedin
|
15831 |
efrain |
720 |
O = Sector
|
15546 |
efrain |
721 |
|
|
|
722 |
*/
|
15623 |
anderson |
723 |
|
|
|
724 |
|
16766 |
efrain |
725 |
$first_name = Functions::sanitizeFilterString($record['A']);
|
|
|
726 |
$last_name = Functions::sanitizeFilterString($record['B']);
|
|
|
727 |
$email_personal = strtolower(Functions::sanitizeFilterString($record['C']));
|
|
|
728 |
$email_company = strtolower(Functions::sanitizeFilterString($record['D']));
|
15623 |
anderson |
729 |
|
16766 |
efrain |
730 |
$company = isset($record['E']) ? Functions::sanitizeFilterString($record['E']) : '';
|
|
|
731 |
$position = isset($record['F']) ? Functions::sanitizeFilterString($record['F']) : '';
|
|
|
732 |
$country = isset($record['G']) ? Functions::sanitizeFilterString($record['G']) : '';
|
|
|
733 |
$state = isset($record['H']) ? Functions::sanitizeFilterString($record['H']) : '';
|
|
|
734 |
$city = isset($record['I']) ? Functions::sanitizeFilterString($record['I']) : '';
|
15623 |
anderson |
735 |
|
|
|
736 |
|
16766 |
efrain |
737 |
$phone = isset($record['J']) ? Functions::sanitizeFilterString(filter_var($record['J'])) : '';
|
15623 |
anderson |
738 |
$phone = preg_replace('/[^0-9]/', '', $phone);
|
|
|
739 |
|
16766 |
efrain |
740 |
$extension = isset($record['K']) ? Functions::sanitizeFilterString($record['K']) : '';
|
15623 |
anderson |
741 |
$extension = preg_replace('/[^0-9]/', '', $extension);
|
|
|
742 |
|
16766 |
efrain |
743 |
$movil = isset($record['L']) ? Functions::sanitizeFilterString($record['L']) : '';
|
15623 |
anderson |
744 |
$movil = preg_replace('/[^0-9]/', '', $movil);
|
|
|
745 |
|
16766 |
efrain |
746 |
$whatsapp = isset($record['M']) ? Functions::sanitizeFilterString($record['M']) : '';
|
15623 |
anderson |
747 |
$whatsapp = preg_replace('/[^0-9]/', '', $whatsapp);
|
|
|
748 |
|
|
|
749 |
|
15546 |
efrain |
750 |
$linkedin = isset($record['N']) ? trim(filter_var($record['N'], FILTER_SANITIZE_URL)) : '';
|
16766 |
efrain |
751 |
$sector = isset($record['O']) ? Functions::sanitizeFilterString($record['O']) : '';
|
|
|
752 |
$scholarship = isset($record['P']) ? strtolower(Functions::sanitizeFilterString($record['P'])) : '';
|
|
|
753 |
|
|
|
754 |
if($scholarship == 'yes' || $scholarship == 'si') {
|
|
|
755 |
$scholarship = DiscoveryContact::SCHOLARSHIP_YES;
|
|
|
756 |
} else {
|
|
|
757 |
$scholarship = DiscoveryContact::SCHOLARSHIP_NO;
|
|
|
758 |
}
|
|
|
759 |
|
|
|
760 |
|
|
|
761 |
|
|
|
762 |
|
15546 |
efrain |
763 |
//|| empty($password)
|
15623 |
anderson |
764 |
if (empty($first_name) || empty($last_name) || !filter_var($email_company, FILTER_VALIDATE_EMAIL)) {
|
15546 |
efrain |
765 |
continue;
|
|
|
766 |
}
|
15623 |
anderson |
767 |
|
|
|
768 |
if (!in_array($email_company, $emails)) {
|
|
|
769 |
|
15546 |
efrain |
770 |
array_push($emails, $email_company);
|
15623 |
anderson |
771 |
|
15546 |
efrain |
772 |
array_push($contacts, [
|
15623 |
anderson |
773 |
'first_name' => $first_name,
|
15546 |
efrain |
774 |
'last_name' => $last_name,
|
|
|
775 |
'email_personal' => $email_personal,
|
|
|
776 |
'email_company' => $email_company,
|
15623 |
anderson |
777 |
'company' => $company,
|
15546 |
efrain |
778 |
'position' => $position,
|
|
|
779 |
'country' => $country,
|
|
|
780 |
'state' => $state,
|
|
|
781 |
'city' => $city,
|
|
|
782 |
'phone' => $phone,
|
|
|
783 |
'extension' => $extension,
|
|
|
784 |
'movil' => $movil,
|
|
|
785 |
'whatsapp' => $whatsapp,
|
|
|
786 |
'linkedin' => $linkedin,
|
15831 |
efrain |
787 |
'sector' => $sector,
|
16766 |
efrain |
788 |
'scholarship' => $scholarship,
|
15546 |
efrain |
789 |
]);
|
|
|
790 |
}
|
|
|
791 |
}
|
15623 |
anderson |
792 |
|
|
|
793 |
|
|
|
794 |
$key = md5($currentUser->id . '-discovery-contacts-' . uniqid());
|
15546 |
efrain |
795 |
$this->cache->setItem($key, serialize($contacts));
|
15623 |
anderson |
796 |
|
15546 |
efrain |
797 |
return new JsonModel([
|
|
|
798 |
'success' => true,
|
|
|
799 |
'data' => [
|
|
|
800 |
'key' => $key,
|
|
|
801 |
'items' => $contacts,
|
|
|
802 |
]
|
|
|
803 |
]);
|
|
|
804 |
} else {
|
|
|
805 |
$messages = [];
|
|
|
806 |
$form_messages = (array) $form->getMessages();
|
15623 |
anderson |
807 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
808 |
|
15546 |
efrain |
809 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
810 |
}
|
15623 |
anderson |
811 |
|
15546 |
efrain |
812 |
return new JsonModel([
|
|
|
813 |
'success' => false,
|
|
|
814 |
'data' => $messages
|
|
|
815 |
]);
|
|
|
816 |
}
|
15623 |
anderson |
817 |
} else if ($step == 'process') {
|
|
|
818 |
|
16972 |
efrain |
819 |
|
|
|
820 |
|
16766 |
efrain |
821 |
$key = Functions::sanitizeFilterString($this->params()->fromPost('key'));
|
15623 |
anderson |
822 |
if (!$key) {
|
15546 |
efrain |
823 |
return new JsonModel([
|
|
|
824 |
'success' => false,
|
|
|
825 |
'data' => 'ERROR_CACHE_KEY_EMPTY'
|
|
|
826 |
]);
|
|
|
827 |
}
|
15623 |
anderson |
828 |
|
15546 |
efrain |
829 |
$value = $this->cache->getItem($key);
|
15623 |
anderson |
830 |
if (!$value) {
|
|
|
831 |
|
15546 |
efrain |
832 |
return new JsonModel([
|
|
|
833 |
'success' => false,
|
|
|
834 |
'data' => 'ERROR_CACHE_NOT_FOUND'
|
|
|
835 |
]);
|
|
|
836 |
}
|
15623 |
anderson |
837 |
|
15546 |
efrain |
838 |
$records = unserialize($value);
|
15623 |
anderson |
839 |
if (!$records) {
|
15546 |
efrain |
840 |
return new JsonModel([
|
|
|
841 |
'success' => false,
|
|
|
842 |
'data' => 'ERROR_CACHE_INVALID'
|
|
|
843 |
]);
|
|
|
844 |
}
|
16971 |
efrain |
845 |
|
|
|
846 |
|
|
|
847 |
$csv = "EMAIL|STATUS\r\n";
|
15623 |
anderson |
848 |
|
|
|
849 |
|
|
|
850 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
851 |
$discoveryContactInteractionTypeMapper = DiscoveryContactInteractionTypeMapper::getInstance($this->adapter);
|
|
|
852 |
|
16643 |
efrain |
853 |
$discoveryContactInteractionTypeMapper = DiscoveryContactInteractionTypeMapper::getInstance($this->adapter);
|
|
|
854 |
$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneDefaultByCompanyId($currentCompany->id);
|
|
|
855 |
if(!$discoveryContactInteractionTypeDefault) {
|
|
|
856 |
$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneFirstActiveByCompanyId($currentCompany->id);
|
|
|
857 |
$discoveryContactInteractionTypeDefault->default = DiscoveryContactInteractionType::DEFAULT_YES;
|
|
|
858 |
$discoveryContactInteractionTypeMapper->update($discoveryContactInteractionTypeDefault);
|
|
|
859 |
}
|
|
|
860 |
|
|
|
861 |
|
|
|
862 |
|
15623 |
anderson |
863 |
$discoveryContactInteractionMapper = DiscoveryContactInteractionMapper::getInstance($this->adapter);
|
16643 |
efrain |
864 |
$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
|
15623 |
anderson |
865 |
|
|
|
866 |
|
15546 |
efrain |
867 |
$new_contacts = 0;
|
|
|
868 |
$duplicate_contacts = 0;
|
|
|
869 |
$error_contacts = 0;
|
16971 |
efrain |
870 |
foreach ($records as $record)
|
|
|
871 |
{
|
15546 |
efrain |
872 |
$first_name = $record['first_name'];
|
|
|
873 |
$last_name = $record['last_name'];
|
|
|
874 |
$email_personal = $record['email_personal'];
|
|
|
875 |
$email_company = $record['email_company'];
|
|
|
876 |
$company = $record['company'];
|
|
|
877 |
$position = $record['position'];
|
|
|
878 |
$country = $record['country'];
|
|
|
879 |
$state = $record['state'];
|
|
|
880 |
$city = $record['city'];
|
|
|
881 |
$phone = $record['phone'];
|
|
|
882 |
$extension = $record['extension'];
|
|
|
883 |
$movil = $record['movil'];
|
|
|
884 |
$whatsapp = $record['whatsapp'];
|
|
|
885 |
$linkedin = $record['linkedin'];
|
15831 |
efrain |
886 |
$sector = $record['sector'];
|
16766 |
efrain |
887 |
$scholarship = $record['scholarship'];
|
15831 |
efrain |
888 |
|
16972 |
efrain |
889 |
|
|
|
890 |
$discoveryContact = $discoveryContactMapper->fetchOneByCorporateEmailAndCompanyId($email_company, $currentCompany->id);
|
15623 |
anderson |
891 |
if ($discoveryContact) {
|
16971 |
efrain |
892 |
|
|
|
893 |
$csv .= "$email_company|DUPLICATE\r\n";
|
15546 |
efrain |
894 |
$duplicate_contacts++;
|
|
|
895 |
} else {
|
15623 |
anderson |
896 |
|
15546 |
efrain |
897 |
$discoveryContact = new DiscoveryContact();
|
|
|
898 |
$discoveryContact->company_id = $currentCompany->id;
|
|
|
899 |
$discoveryContact->first_name = $first_name;
|
|
|
900 |
$discoveryContact->last_name = $last_name;
|
|
|
901 |
$discoveryContact->corporate_email = $email_company;
|
|
|
902 |
$discoveryContact->personal_email = $email_personal;
|
|
|
903 |
$discoveryContact->company = $company;
|
|
|
904 |
$discoveryContact->position = $position;
|
15831 |
efrain |
905 |
$discoveryContact->sector = $sector;
|
15546 |
efrain |
906 |
$discoveryContact->country = $country;
|
|
|
907 |
$discoveryContact->state = $state;
|
|
|
908 |
$discoveryContact->city = $city;
|
|
|
909 |
$discoveryContact->phone = empty($phone) ? '' : '+' . $phone;
|
|
|
910 |
$discoveryContact->phone_extension = $extension;
|
|
|
911 |
$discoveryContact->celular = empty($movil) ? '' : '+' . $movil;
|
|
|
912 |
$discoveryContact->whatsapp = empty($whatsapp) ? '' : '+' . $whatsapp;
|
|
|
913 |
$discoveryContact->linkedin = $linkedin;
|
16766 |
efrain |
914 |
$discoveryContact->scholarship = $scholarship;
|
15831 |
efrain |
915 |
|
16972 |
efrain |
916 |
|
15831 |
efrain |
917 |
if($discoveryContactMapper->insert($discoveryContact)) {
|
|
|
918 |
$new_contacts++;
|
|
|
919 |
|
16971 |
efrain |
920 |
|
16643 |
efrain |
921 |
if($discoveryContactInteractionTypeDefault) {
|
15831 |
efrain |
922 |
|
15546 |
efrain |
923 |
$discoveryContactInteraction = new DiscoveryContactInteraction();
|
|
|
924 |
$discoveryContactInteraction->company_id = $currentCompany->id;
|
|
|
925 |
$discoveryContactInteraction->contact_id = $discoveryContact->id;
|
16643 |
efrain |
926 |
$discoveryContactInteraction->interaction_type_id = $discoveryContactInteractionTypeDefault->id;
|
15546 |
efrain |
927 |
$discoveryContactInteraction->user_id = $currentUser->id;
|
15623 |
anderson |
928 |
|
15546 |
efrain |
929 |
$discoveryContactInteractionMapper->insert($discoveryContactInteraction);
|
|
|
930 |
}
|
16643 |
efrain |
931 |
|
|
|
932 |
$discoveryContactLog = new DiscoveryContactLog();
|
|
|
933 |
$discoveryContactLog->company_id = $currentCompany->id;
|
|
|
934 |
$discoveryContactLog->contact_id = $discoveryContact->id;
|
|
|
935 |
$discoveryContactLog->user_id = $currentUser->id;
|
|
|
936 |
$discoveryContactLog->activity = 'LABEL_RECORD_CONTACT_ADDED';
|
|
|
937 |
$discoveryContactLog->details = 'LABEL_FIRST_NAME : ' . $discoveryContact->first_name . PHP_EOL .
|
|
|
938 |
'LABEL_LAST_NAME : ' . $discoveryContact->last_name . PHP_EOL .
|
|
|
939 |
'LABEL_CORPORATE_EMAIL : ' . $discoveryContact->corporate_email . PHP_EOL .
|
|
|
940 |
'LABEL_COMPANY : ' . $discoveryContact->company . PHP_EOL .
|
|
|
941 |
'LABEL_POSITION : ' . $discoveryContact->position . PHP_EOL .
|
|
|
942 |
'LABEL_COUNTRY : ' . $discoveryContact->country . PHP_EOL;
|
|
|
943 |
|
|
|
944 |
|
|
|
945 |
if ($discoveryContact->state) {
|
|
|
946 |
$discoveryContactLog->details .= 'LABEL_STATE : ' . $discoveryContact->state . PHP_EOL;
|
|
|
947 |
}
|
|
|
948 |
if ($discoveryContact->city) {
|
|
|
949 |
$discoveryContactLog->details .= 'LABEL_CITY : ' . $discoveryContact->city . PHP_EOL;
|
|
|
950 |
}
|
|
|
951 |
if ($discoveryContact->phone) {
|
|
|
952 |
$discoveryContactLog->details .= 'LABEL_PHONE : ' . $discoveryContact->phone . PHP_EOL;
|
|
|
953 |
}
|
|
|
954 |
if ($discoveryContact->phone_extension) {
|
|
|
955 |
$discoveryContactLog->details .= 'LABEL_PHONE_EXTENSION : ' . $discoveryContact->phone_extension . PHP_EOL;
|
|
|
956 |
}
|
|
|
957 |
if ($discoveryContact->personal_email) {
|
|
|
958 |
$discoveryContactLog->details .= 'LABEL_PERSONAL_EMAIL : ' . $discoveryContact->personal_email . PHP_EOL;
|
|
|
959 |
}
|
|
|
960 |
if ($discoveryContact->celular) {
|
|
|
961 |
$discoveryContactLog->details .= 'LABEL_CELULAR : ' . $discoveryContact->celular . PHP_EOL;
|
|
|
962 |
}
|
|
|
963 |
if ($discoveryContact->whatsapp) {
|
|
|
964 |
$discoveryContactLog->details .= 'LABEL_WHATSAPP : ' . $discoveryContact->whatsapp . PHP_EOL;
|
|
|
965 |
}
|
|
|
966 |
if ($discoveryContact->linkedin) {
|
|
|
967 |
$discoveryContactLog->details .= 'LABEL_LINKEDIN : ' . $discoveryContact->linkedin . PHP_EOL;
|
|
|
968 |
}
|
16766 |
efrain |
969 |
if ($discoveryContact->scholarship) {
|
|
|
970 |
$discoveryContactLog->details .= 'LABEL_SCHOLARSHIP : ' . $discoveryContact->scholarship . PHP_EOL;
|
|
|
971 |
}
|
16643 |
efrain |
972 |
|
|
|
973 |
|
16971 |
efrain |
974 |
if($discoveryContactLogMapper->insert($discoveryContactLog)) {
|
|
|
975 |
$csv .= "$email_company|NEW\r\n";
|
|
|
976 |
} else {
|
|
|
977 |
$csv .= "$email_company|ERROR\r\n";
|
|
|
978 |
}
|
16643 |
efrain |
979 |
|
|
|
980 |
|
|
|
981 |
|
15546 |
efrain |
982 |
} else {
|
16971 |
efrain |
983 |
$csv .= "$email_company|ERROR\r\n";
|
15546 |
efrain |
984 |
$error_contacts++;
|
|
|
985 |
}
|
|
|
986 |
}
|
16972 |
efrain |
987 |
}
|
16971 |
efrain |
988 |
|
|
|
989 |
$csv_filename = 'discovery-contact-' . date('Y-m-d H:i') . '.csv';
|
|
|
990 |
$csv_filename = str_replace(' ', '-', $csv_filename);
|
15546 |
efrain |
991 |
|
15623 |
anderson |
992 |
|
15546 |
efrain |
993 |
return new JsonModel([
|
|
|
994 |
'success' => true,
|
|
|
995 |
'data' => [
|
|
|
996 |
'new_contacts' => $new_contacts,
|
|
|
997 |
'error_contacts' => $error_contacts,
|
|
|
998 |
'duplicate_contacts' => $duplicate_contacts,
|
16971 |
efrain |
999 |
'csv_filename' => $csv_filename,
|
|
|
1000 |
'csv_base64_content' => base64_encode($csv),
|
15546 |
efrain |
1001 |
]
|
|
|
1002 |
]);
|
|
|
1003 |
} else {
|
|
|
1004 |
return new JsonModel([
|
|
|
1005 |
'success' => false,
|
|
|
1006 |
'data' => 'ERROR_PARAMETERS_ARE_INVALID'
|
|
|
1007 |
]);
|
|
|
1008 |
}
|
|
|
1009 |
}
|
15623 |
anderson |
1010 |
|
15546 |
efrain |
1011 |
return new JsonModel([
|
|
|
1012 |
'success' => false,
|
|
|
1013 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1014 |
]);
|
|
|
1015 |
}
|
15397 |
efrain |
1016 |
}
|