16971 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use Laminas\Log\LoggerInterface;
|
|
|
11 |
|
|
|
12 |
use Laminas\View\Model\ViewModel;
|
|
|
13 |
use Laminas\View\Model\JsonModel;
|
|
|
14 |
use LeadersLinked\Library\Functions;
|
|
|
15 |
use Laminas\Mvc\I18n\Translator;
|
|
|
16 |
use LeadersLinked\Mapper\DiscoveryContactBlackListMapper;
|
|
|
17 |
use LeadersLinked\Mapper\DiscoveryContactBlackListReasonMapper;
|
|
|
18 |
use LeadersLinked\Model\DiscoveryContactLog;
|
|
|
19 |
use LeadersLinked\Mapper\DiscoveryContactMapper;
|
|
|
20 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
21 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
22 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
23 |
use Laminas\Paginator\Paginator;
|
|
|
24 |
use LeadersLinked\Form\DiscoveryContact\BlackListAddForm;
|
|
|
25 |
use LeadersLinked\Form\DiscoveryContact\BlackListEditForm;
|
|
|
26 |
use LeadersLinked\Model\DiscoveryContactBlackList;
|
|
|
27 |
use LeadersLinked\Mapper\DiscoveryContactLogMapper;
|
|
|
28 |
use LeadersLinked\Model\DiscoveryContact;
|
|
|
29 |
use LeadersLinked\Form\DiscoveryContact\BlackListUploadForm;
|
|
|
30 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
class DiscoveryContactBlackListController extends AbstractActionController
|
|
|
34 |
{
|
|
|
35 |
/**
|
|
|
36 |
*
|
|
|
37 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
|
|
38 |
*/
|
|
|
39 |
private $adapter;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
*
|
|
|
43 |
* @var \LeadersLinked\Cache\CacheInterface
|
|
|
44 |
*/
|
|
|
45 |
private $cache;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @var \Laminas\Log\LoggerInterface
|
|
|
51 |
*/
|
|
|
52 |
private $logger;
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
*
|
|
|
56 |
* @var array
|
|
|
57 |
*/
|
|
|
58 |
private $config;
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
*
|
|
|
63 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
64 |
*/
|
|
|
65 |
private $translator;
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
*
|
|
|
70 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
71 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
72 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
|
|
73 |
* @param array $config
|
|
|
74 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
|
|
75 |
*/
|
|
|
76 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
|
|
77 |
{
|
|
|
78 |
$this->adapter = $adapter;
|
|
|
79 |
$this->cache = $cache;
|
|
|
80 |
$this->logger = $logger;
|
|
|
81 |
$this->config = $config;
|
|
|
82 |
$this->translator = $translator;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public function indexAction()
|
|
|
86 |
{
|
|
|
87 |
$request = $this->getRequest();
|
|
|
88 |
if($request->isGet()) {
|
|
|
89 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
90 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
91 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
92 |
|
|
|
93 |
$headers = $request->getHeaders();
|
|
|
94 |
|
|
|
95 |
$isJson = false;
|
|
|
96 |
if($headers->has('Accept')) {
|
|
|
97 |
$accept = $headers->get('Accept');
|
|
|
98 |
|
|
|
99 |
$prioritized = $accept->getPrioritized();
|
|
|
100 |
|
|
|
101 |
foreach($prioritized as $key => $value) {
|
|
|
102 |
$raw = trim($value->getRaw());
|
|
|
103 |
|
|
|
104 |
if(!$isJson) {
|
|
|
105 |
$isJson = strpos($raw, 'json');
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
if($isJson) {
|
|
|
112 |
|
|
|
113 |
$request = $this->getRequest();
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
$search = $this->params()->fromQuery('search');
|
|
|
117 |
$search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
|
|
|
118 |
|
|
|
119 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
120 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
121 |
|
|
|
122 |
$order = $this->params()->fromQuery('order', []);
|
|
|
123 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
124 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
|
|
|
125 |
|
|
|
126 |
$fields = ['corporate_email', 'first_name', 'last_name'];
|
|
|
127 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'corporate_email';
|
|
|
128 |
|
|
|
129 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
130 |
$order_direction = 'ASC';
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
136 |
$select = $queryMapper->getSql()->select();
|
|
|
137 |
$select->from([ 'tb1' => DiscoveryContactMapper::_TABLE ]);
|
|
|
138 |
$select->columns(['first_name', 'last_name', 'corporate_email']);
|
|
|
139 |
$select->join(['tb2' => DiscoveryContactBlackListMapper::_TABLE], 'tb1.id = tb2.contact_id', ['uuid', 'notes']);
|
|
|
140 |
$select->join(['tb3' => DiscoveryContactBlackListReasonMapper::_TABLE], 'tb2.blacklist_reason_id = tb3.id' , ['reason' => 'name']);
|
|
|
141 |
$select->where->equalTo('tb1.company_id', $currentCompany->id);
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
if($search) {
|
|
|
147 |
$select->where->nest()
|
|
|
148 |
->like('tb1.first_name', '%' . $search . '%')
|
|
|
149 |
->or->like('tb1.last_name', '%' . $search . '%')
|
|
|
150 |
->or->like('tb1.corporate_email', '%' . $search . '%')
|
|
|
151 |
->or->like('tb3.name', '%' . $search . '%')
|
|
|
152 |
->unnest();
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
156 |
|
|
|
157 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
158 |
|
|
|
159 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
160 |
|
|
|
161 |
$adapter = new DbSelect($select, $queryMapper->getSql());
|
|
|
162 |
$paginator = new Paginator($adapter);
|
|
|
163 |
$paginator->setItemCountPerPage($records_x_page);
|
|
|
164 |
$paginator->setCurrentPageNumber($page);
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
$items = [];
|
|
|
168 |
$records = $paginator->getCurrentItems();
|
|
|
169 |
foreach($records as $record)
|
|
|
170 |
{
|
|
|
171 |
|
|
|
172 |
$item = [
|
|
|
173 |
'corporate_email' => $record['corporate_email'],
|
|
|
174 |
'first_name' => $record['first_name'],
|
|
|
175 |
'last_name' => $record['last_name'],
|
|
|
176 |
'reason' => $record['reason'],
|
|
|
177 |
'notes' => $record['notes'],
|
|
|
178 |
'actions' => [
|
|
|
179 |
'link_edit' => $this->url()->fromRoute('discovery-contacts/blacklist/edit', ['id' => $record['uuid'] ]),
|
|
|
180 |
'link_delete' => $this->url()->fromRoute('discovery-contacts/blacklist/delete', ['id' => $record['uuid'] ]),
|
|
|
181 |
]
|
|
|
182 |
];
|
|
|
183 |
|
|
|
184 |
array_push($items, $item);
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
return new JsonModel([
|
|
|
189 |
'success' => true,
|
|
|
190 |
'data' => [
|
|
|
191 |
'items' => $items,
|
|
|
192 |
'total' => $paginator->getTotalItemCount(),
|
|
|
193 |
]
|
|
|
194 |
]);
|
|
|
195 |
|
|
|
196 |
} else {
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
$formAdd = new BlackListAddForm($this->adapter, $currentCompany->id);
|
|
|
201 |
$formEdit = new BlackListEditForm($this->adapter, $currentCompany->id);
|
|
|
202 |
$formUpload = new BlackListUploadForm($this->adapter, $currentCompany->id);
|
|
|
203 |
|
|
|
204 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
205 |
$viewModel = new ViewModel();
|
|
|
206 |
$viewModel->setTemplate('leaders-linked/discovery-contact-blacklist/index.phtml');
|
|
|
207 |
$viewModel->setVariables([
|
|
|
208 |
'formAdd' => $formAdd,
|
|
|
209 |
'formEdit' => $formEdit,
|
|
|
210 |
'formUpload' => $formUpload,
|
|
|
211 |
]);
|
|
|
212 |
return $viewModel ;
|
|
|
213 |
}
|
|
|
214 |
} else {
|
|
|
215 |
return new JsonModel([
|
|
|
216 |
'success' => false,
|
|
|
217 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
218 |
]);
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
public function addAction()
|
|
|
223 |
{
|
|
|
224 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
225 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
226 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
227 |
|
|
|
228 |
$request = $this->getRequest();
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
$request = $this->getRequest();
|
|
|
232 |
if($request->isPost()) {
|
|
|
233 |
$form = new BlackListAddForm($this->adapter, $currentCompany->id);
|
|
|
234 |
$dataPost = $request->getPost()->toArray();
|
|
|
235 |
|
|
|
236 |
|
|
|
237 |
$form->setData($dataPost);
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
if($form->isValid()) {
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
$dataPost = (array) $form->getData();
|
|
|
244 |
$notes = $dataPost['notes'];
|
|
|
245 |
$blacklist_reason_id = $dataPost['blacklist_reason_id'];
|
|
|
246 |
|
|
|
247 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
248 |
$discoveryContact = $discoveryContactMapper->fetchOneByCorporateEmailAndCompanyId($dataPost['email'], $currentCompany->id);
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
|
|
|
252 |
$discoveryContactBlackListReasonMapper = DiscoveryContactBlackListReasonMapper::getInstance($this->adapter);
|
|
|
253 |
$discoveryContactBlackListReason = $discoveryContactBlackListReasonMapper->fetchOneByUuid($blacklist_reason_id);
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
$discoveryContactBlackList = new DiscoveryContactBlackList();
|
|
|
257 |
$discoveryContactBlackList->user_id = $currentUser->id;
|
|
|
258 |
$discoveryContactBlackList->company_id = $discoveryContact->company_id;
|
|
|
259 |
$discoveryContactBlackList->contact_id = $discoveryContact->id;
|
|
|
260 |
$discoveryContactBlackList->blacklist_reason_id = $discoveryContactBlackListReason->id;
|
|
|
261 |
$discoveryContactBlackList->notes = $notes;
|
|
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
$discoveryContactBlackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
266 |
$result = $discoveryContactBlackListMapper->insert($discoveryContactBlackList);
|
|
|
267 |
|
|
|
268 |
if($result) {
|
|
|
269 |
|
|
|
270 |
$this->logger->info('Se agrego la lista negra del relevamiento de contacto : ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name . '(' . $discoveryContact->corporate_email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
$data = [
|
|
|
274 |
'success' => true,
|
|
|
275 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
276 |
];
|
|
|
277 |
} else {
|
|
|
278 |
$data = [
|
|
|
279 |
'success' => false,
|
|
|
280 |
'data' => $discoveryContactBlackListMapper->getError()
|
|
|
281 |
];
|
|
|
282 |
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
return new JsonModel($data);
|
|
|
286 |
|
|
|
287 |
} else {
|
|
|
288 |
$messages = [];
|
|
|
289 |
$form_messages = (array) $form->getMessages();
|
|
|
290 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
291 |
{
|
|
|
292 |
|
|
|
293 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
return new JsonModel([
|
|
|
297 |
'success' => false,
|
|
|
298 |
'data' => $messages
|
|
|
299 |
]);
|
|
|
300 |
}
|
|
|
301 |
|
|
|
302 |
} else {
|
|
|
303 |
$data = [
|
|
|
304 |
'success' => false,
|
|
|
305 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
306 |
];
|
|
|
307 |
|
|
|
308 |
return new JsonModel($data);
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
return new JsonModel($data);
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
public function editAction()
|
|
|
315 |
{
|
|
|
316 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
317 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
318 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
319 |
|
|
|
320 |
$request = $this->getRequest();
|
|
|
321 |
$uuid = $this->params()->fromRoute('id');
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
if(!$uuid) {
|
|
|
325 |
$data = [
|
|
|
326 |
'success' => false,
|
|
|
327 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
328 |
];
|
|
|
329 |
|
|
|
330 |
return new JsonModel($data);
|
|
|
331 |
}
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
$discoveryContactBlackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
335 |
$discoveryContactBlackList = $discoveryContactBlackListMapper->fetchOneByUuid($uuid);
|
|
|
336 |
if(!$discoveryContactBlackList) {
|
|
|
337 |
$data = [
|
|
|
338 |
'success' => false,
|
|
|
339 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
340 |
];
|
|
|
341 |
|
|
|
342 |
return new JsonModel($data);
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
|
|
|
346 |
if($discoveryContactBlackList->company_id != $currentCompany->id) {
|
|
|
347 |
return new JsonModel([
|
|
|
348 |
'success' => false,
|
|
|
349 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
350 |
]);
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
|
355 |
if($request->isGet()) {
|
|
|
356 |
|
|
|
357 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
358 |
$discoveryContact = $discoveryContactMapper->fetchOne($discoveryContactBlackList->contact_id);
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
$discoveryContactBlackListReasonMapper = DiscoveryContactBlackListReasonMapper::getInstance($this->adapter);
|
|
|
362 |
$discoveryContactBlackListReason = $discoveryContactBlackListReasonMapper->fetchOne($discoveryContactBlackList->blacklist_reason_id);
|
|
|
363 |
|
|
|
364 |
return new JsonModel([
|
|
|
365 |
'success' => true,
|
|
|
366 |
'data' => [
|
|
|
367 |
'first_name' => $discoveryContact->first_name,
|
|
|
368 |
'last_name' => $discoveryContact->last_name,
|
|
|
369 |
'email' => $discoveryContact->corporate_email,
|
|
|
370 |
'blacklist_reason_id' => $discoveryContactBlackListReason->uuid,
|
|
|
371 |
'notes' => $discoveryContactBlackList->notes,
|
|
|
372 |
]
|
|
|
373 |
]);
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
|
379 |
} else if($request->isPost()) {
|
|
|
380 |
$form = new BlackListAddForm($this->adapter, $currentCompany->id);
|
|
|
381 |
$dataPost = $request->getPost()->toArray();
|
|
|
382 |
|
|
|
383 |
$form->setData($dataPost);
|
|
|
384 |
|
|
|
385 |
if($form->isValid()) {
|
|
|
386 |
|
|
|
387 |
$dataPost = (array) $form->getData();
|
|
|
388 |
$notes = $dataPost['notes'];
|
|
|
389 |
$blacklist_reason_id = $dataPost['blacklist_reason_id'];
|
|
|
390 |
|
|
|
391 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
392 |
$discoveryContact = $discoveryContactMapper->fetchOne($discoveryContactBlackList->contact_id);
|
|
|
393 |
|
|
|
394 |
$discoveryContactBlackListReasonMapper = DiscoveryContactBlackListReasonMapper::getInstance($this->adapter);
|
|
|
395 |
$discoveryContactBlackListReason = $discoveryContactBlackListReasonMapper->fetchOneByUuid($blacklist_reason_id);
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
$discoveryContactBlackList->blacklist_reason_id = $discoveryContactBlackListReason->id;
|
|
|
399 |
$discoveryContactBlackList->notes = $notes;
|
|
|
400 |
$discoveryContactBlackList->user_id = $currentUser->id;
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
$discoveryContactBlackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
404 |
$result = $discoveryContactBlackListMapper->update($discoveryContactBlackList);
|
|
|
405 |
|
|
|
406 |
if($result) {
|
|
|
407 |
|
|
|
408 |
$this->logger->info('Se edito la lista negra del relevamiento de contacto : ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name . '(' . $discoveryContact->corporate_email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
409 |
|
|
|
410 |
$data = [
|
|
|
411 |
'success' => true,
|
|
|
412 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
413 |
];
|
|
|
414 |
} else {
|
|
|
415 |
$data = [
|
|
|
416 |
'success' => false,
|
|
|
417 |
'data' => $discoveryContactBlackListMapper->getError()
|
|
|
418 |
];
|
|
|
419 |
|
|
|
420 |
}
|
|
|
421 |
|
|
|
422 |
return new JsonModel($data);
|
|
|
423 |
|
|
|
424 |
} else {
|
|
|
425 |
$messages = [];
|
|
|
426 |
$form_messages = (array) $form->getMessages();
|
|
|
427 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
428 |
{
|
|
|
429 |
|
|
|
430 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
431 |
}
|
|
|
432 |
|
|
|
433 |
return new JsonModel([
|
|
|
434 |
'success' => false,
|
|
|
435 |
'data' => $messages
|
|
|
436 |
]);
|
|
|
437 |
}
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
$data = [
|
|
|
441 |
'success' => false,
|
|
|
442 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
443 |
];
|
|
|
444 |
|
|
|
445 |
return new JsonModel($data);
|
|
|
446 |
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
|
|
|
450 |
public function deleteAction()
|
|
|
451 |
{
|
|
|
452 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
453 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
454 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
455 |
|
|
|
456 |
$request = $this->getRequest();
|
|
|
457 |
$uuid = $this->params()->fromRoute('id');
|
|
|
458 |
|
|
|
459 |
|
|
|
460 |
|
|
|
461 |
if(!$uuid) {
|
|
|
462 |
$data = [
|
|
|
463 |
'success' => false,
|
|
|
464 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
465 |
];
|
|
|
466 |
|
|
|
467 |
return new JsonModel($data);
|
|
|
468 |
}
|
|
|
469 |
|
|
|
470 |
|
|
|
471 |
$discoveryContactBlackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
472 |
$discoveryContactBlackList = $discoveryContactBlackListMapper->fetchOneByUuid($uuid);
|
|
|
473 |
if(!$discoveryContactBlackList) {
|
|
|
474 |
$data = [
|
|
|
475 |
'success' => false,
|
|
|
476 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
477 |
];
|
|
|
478 |
|
|
|
479 |
return new JsonModel($data);
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
|
|
|
483 |
if($discoveryContactBlackList->company_id != $currentCompany->id) {
|
|
|
484 |
return new JsonModel([
|
|
|
485 |
'success' => false,
|
|
|
486 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
487 |
]);
|
|
|
488 |
}
|
|
|
489 |
|
|
|
490 |
|
|
|
491 |
if($request->isPost()) {
|
|
|
492 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
493 |
$discoveryContact = $discoveryContactMapper->fetchOne($discoveryContactBlackList->contact_id);
|
|
|
494 |
|
|
|
495 |
|
|
|
496 |
|
|
|
497 |
$result = $discoveryContactBlackListMapper->delete($discoveryContactBlackList);
|
|
|
498 |
if($result) {
|
|
|
499 |
$this->logger->info('Se borro la lista negra del relevamiento de contacto ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name . '(' . $discoveryContact->corporate_email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
500 |
|
|
|
501 |
|
|
|
502 |
$data = [
|
|
|
503 |
'success' => true,
|
|
|
504 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
505 |
];
|
|
|
506 |
} else {
|
|
|
507 |
|
|
|
508 |
$data = [
|
|
|
509 |
'success' => false,
|
|
|
510 |
'data' => $discoveryContactBlackListMapper->getError()
|
|
|
511 |
];
|
|
|
512 |
|
|
|
513 |
return new JsonModel($data);
|
|
|
514 |
}
|
|
|
515 |
|
|
|
516 |
} else {
|
|
|
517 |
$data = [
|
|
|
518 |
'success' => false,
|
|
|
519 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
520 |
];
|
|
|
521 |
|
|
|
522 |
return new JsonModel($data);
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
return new JsonModel($data);
|
|
|
526 |
}
|
|
|
527 |
|
|
|
528 |
|
|
|
529 |
public function searchEmailAction()
|
|
|
530 |
{
|
|
|
531 |
$request = $this->getRequest();
|
|
|
532 |
if ($request->isGet()) {
|
|
|
533 |
|
|
|
534 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
535 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
536 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
537 |
|
|
|
538 |
$search = Functions::sanitizeFilterString($this->params()->fromQuery('search', ''));
|
|
|
539 |
$page = intval($this->params()->fromQuery('page', '0'));
|
|
|
540 |
|
|
|
541 |
|
|
|
542 |
if (strlen($search) >= 3) {
|
|
|
543 |
|
|
|
544 |
$discoveryContactBlackListaMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
545 |
$contact_ids = $discoveryContactBlackListaMapper->fetchAllContactIdsByCompanyId($currentCompany->id);
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
|
|
|
549 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
550 |
$paginator = $discoveryContactMapper->fetchAllByCompanyIdAndSearchCorporateEmailPaginationSelect2WithOutContactIds($currentCompany->id, $search, $page, $contact_ids);
|
|
|
551 |
|
|
|
552 |
$users = [];
|
|
|
553 |
$records = $paginator->getCurrentItems();
|
|
|
554 |
foreach ($records as $record) {
|
|
|
555 |
|
|
|
556 |
|
|
|
557 |
array_push($users, [
|
|
|
558 |
'id' => $record->corporate_email ,
|
|
|
559 |
'text' => $record->corporate_email . ' (' . trim($record->first_name . ' ' . $record->last_name) . ')'
|
|
|
560 |
|
|
|
561 |
]);
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
$pagination_more = $paginator->getCurrentPageNumber() < $paginator->getPages()->pageCount;
|
|
|
565 |
|
|
|
566 |
|
|
|
567 |
return new JsonModel([
|
|
|
568 |
'success' => true,
|
|
|
569 |
'data' => [
|
|
|
570 |
'results' => $users,
|
|
|
571 |
'pagination' => [
|
|
|
572 |
'more' => $pagination_more,
|
|
|
573 |
],
|
|
|
574 |
]
|
|
|
575 |
|
|
|
576 |
]);
|
|
|
577 |
} else {
|
|
|
578 |
return new JsonModel([
|
|
|
579 |
'success' => true,
|
|
|
580 |
'data' => []
|
|
|
581 |
]);
|
|
|
582 |
}
|
|
|
583 |
} else {
|
|
|
584 |
return new JsonModel([
|
|
|
585 |
'success' => false,
|
|
|
586 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
587 |
]);
|
|
|
588 |
}
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
|
|
|
592 |
public function uploadAction()
|
|
|
593 |
{
|
|
|
594 |
$request = $this->getRequest();
|
|
|
595 |
|
|
|
596 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
597 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
598 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
599 |
|
|
|
600 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
601 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
602 |
|
|
|
603 |
$request = $this->getRequest();
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
|
|
|
607 |
|
|
|
608 |
if ($request->isPost()) {
|
|
|
609 |
|
|
|
610 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
611 |
$form = new BlackListUploadForm($this->adapter, $currentCompany->id);
|
|
|
612 |
$form->setData($dataPost);
|
|
|
613 |
|
|
|
614 |
if ($form->isValid()) {
|
|
|
615 |
$dataPost = (array) $form->getData();
|
|
|
616 |
|
|
|
617 |
$file = $_FILES['file'];
|
|
|
618 |
$tmp_filename = $file['tmp_name'];
|
|
|
619 |
$final_filename = 'data/' . $file['name'];
|
|
|
620 |
|
|
|
621 |
if (!move_uploaded_file($tmp_filename, $final_filename)) {
|
|
|
622 |
return new JsonModel([
|
|
|
623 |
'success' => false,
|
|
|
624 |
'data' => 'ERROR_UPLOAD_FILE'
|
|
|
625 |
]);
|
|
|
626 |
}
|
|
|
627 |
|
|
|
628 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
629 |
$discoveryContactBlackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
630 |
$discoveryContactBlackListReasonMapper = DiscoveryContactBlackListReasonMapper::getInstance($this->adapter);
|
|
|
631 |
$discoveryContactBlackListReason = $discoveryContactBlackListReasonMapper->fetchOneByUuid($dataPost['blacklist_reason_id']);
|
|
|
632 |
|
|
|
633 |
|
|
|
634 |
$spreadsheet = IOFactory::load($final_filename);
|
|
|
635 |
$records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
|
|
636 |
|
|
|
637 |
$csv = "EMAIL|STATUS\r\n";
|
|
|
638 |
|
|
|
639 |
$new_contacts = 0;
|
|
|
640 |
$error_contacts = 0;
|
|
|
641 |
$duplicate_contacts = 0;
|
|
|
642 |
|
|
|
643 |
foreach ($records as $record)
|
|
|
644 |
{
|
|
|
645 |
$email = strtolower(Functions::sanitizeFilterString($record['A']));
|
|
|
646 |
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
|
647 |
|
|
|
648 |
$discoveryContact = $discoveryContactMapper->fetchOneByCorporateEmailAndCompanyId($email, $currentCompany->id);
|
|
|
649 |
if($discoveryContact) {
|
|
|
650 |
$discoveryContactBlackList = $discoveryContactBlackListMapper->fetchOneByContactId($discoveryContact->id);
|
|
|
651 |
if($discoveryContactBlackList) {
|
|
|
652 |
$csv .= "$email|DUPLICATE\r\n";
|
|
|
653 |
$duplicate_contacts += 1;
|
|
|
654 |
} else {
|
|
|
655 |
$discoveryContactBlackList = new DiscoveryContactBlackList();
|
|
|
656 |
$discoveryContactBlackList->user_id = $currentUser->id;
|
|
|
657 |
$discoveryContactBlackList->company_id = $discoveryContact->company_id;
|
|
|
658 |
$discoveryContactBlackList->contact_id = $discoveryContact->id;
|
|
|
659 |
$discoveryContactBlackList->blacklist_reason_id = $discoveryContactBlackListReason->id;
|
|
|
660 |
|
|
|
661 |
|
|
|
662 |
if($discoveryContactBlackListMapper->insert($discoveryContactBlackList)) {
|
|
|
663 |
$csv .= "$email|NEW\r\n";
|
|
|
664 |
$new_contacts += 1;
|
|
|
665 |
} else {
|
16978 |
efrain |
666 |
$csv .= "$email|ERROR-INSERT\r\n";
|
16971 |
efrain |
667 |
$error_contacts += 1;
|
|
|
668 |
}
|
|
|
669 |
}
|
|
|
670 |
} else {
|
16978 |
efrain |
671 |
$csv .= "$email|ERROR-NOT-FOUND\r\n";
|
16971 |
efrain |
672 |
$error_contacts += 1;
|
|
|
673 |
}
|
|
|
674 |
}
|
|
|
675 |
|
|
|
676 |
|
|
|
677 |
|
|
|
678 |
}
|
|
|
679 |
|
|
|
680 |
$csv_filename = 'discovery-contact-blacklist-' . date('Y-m-d H:i') . '.csv';
|
|
|
681 |
$csv_filename = str_replace(' ', '-', $csv_filename);
|
|
|
682 |
|
|
|
683 |
return new JsonModel([
|
|
|
684 |
'success' => true,
|
|
|
685 |
'data' => [
|
|
|
686 |
'new_contacts' => $new_contacts,
|
|
|
687 |
'error_contacts' => $error_contacts,
|
|
|
688 |
'duplicate_contacts' => $duplicate_contacts,
|
|
|
689 |
'csv_filename' => $csv_filename,
|
|
|
690 |
'csv_base64_content' => base64_encode($csv),
|
|
|
691 |
]
|
|
|
692 |
]);
|
|
|
693 |
|
|
|
694 |
} else {
|
|
|
695 |
$messages = [];
|
|
|
696 |
$form_messages = (array) $form->getMessages();
|
|
|
697 |
foreach ($form_messages as $fieldname => $field_messages)
|
|
|
698 |
{
|
|
|
699 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
700 |
}
|
|
|
701 |
|
|
|
702 |
return new JsonModel([
|
|
|
703 |
'success' => false,
|
|
|
704 |
'data' => $messages
|
|
|
705 |
]);
|
|
|
706 |
}
|
|
|
707 |
|
|
|
708 |
|
|
|
709 |
}
|
|
|
710 |
|
|
|
711 |
return new JsonModel([
|
|
|
712 |
'success' => false,
|
|
|
713 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
714 |
]);
|
|
|
715 |
}
|
|
|
716 |
|
|
|
717 |
|
|
|
718 |
}
|