16758 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
16768 |
efrain |
7 |
|
16758 |
efrain |
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
use Laminas\View\Model\ViewModel;
|
|
|
11 |
use Laminas\View\Model\JsonModel;
|
|
|
12 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
13 |
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
14 |
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
15 |
use LeadersLinked\Form\DiscoveryContact\ContactDownloadForm;
|
|
|
16 |
use LeadersLinked\Mapper\DiscoveryContactMapper;
|
|
|
17 |
use Laminas\Mvc\I18n\Translator;
|
16766 |
efrain |
18 |
use LeadersLinked\Library\Functions;
|
16817 |
efrain |
19 |
use Laminas\Http\Response;
|
16971 |
efrain |
20 |
use LeadersLinked\Mapper\DiscoveryContactBlackListMapper;
|
16758 |
efrain |
21 |
|
|
|
22 |
class DiscoveryContactReportController extends AbstractActionController
|
|
|
23 |
{
|
|
|
24 |
/**
|
|
|
25 |
*
|
16769 |
efrain |
26 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
16758 |
efrain |
27 |
*/
|
|
|
28 |
private $adapter;
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
*
|
16769 |
efrain |
32 |
* @var \LeadersLinked\Cache\CacheInterface
|
16758 |
efrain |
33 |
*/
|
16769 |
efrain |
34 |
private $cache;
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
*
|
|
|
39 |
* @var \Laminas\Log\LoggerInterface
|
|
|
40 |
*/
|
16758 |
efrain |
41 |
private $logger;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
*
|
|
|
45 |
* @var array
|
|
|
46 |
*/
|
|
|
47 |
private $config;
|
|
|
48 |
|
16769 |
efrain |
49 |
|
16758 |
efrain |
50 |
/**
|
|
|
51 |
*
|
16769 |
efrain |
52 |
* @var \Laminas\Mvc\I18n\Translator
|
16758 |
efrain |
53 |
*/
|
|
|
54 |
private $translator;
|
|
|
55 |
|
16769 |
efrain |
56 |
|
16758 |
efrain |
57 |
/**
|
|
|
58 |
*
|
16769 |
efrain |
59 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
60 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
61 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
16758 |
efrain |
62 |
* @param array $config
|
16769 |
efrain |
63 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
16758 |
efrain |
64 |
*/
|
16769 |
efrain |
65 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
16758 |
efrain |
66 |
{
|
|
|
67 |
$this->adapter = $adapter;
|
16769 |
efrain |
68 |
$this->cache = $cache;
|
16758 |
efrain |
69 |
$this->logger = $logger;
|
|
|
70 |
$this->config = $config;
|
|
|
71 |
$this->translator = $translator;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
public function indexAction()
|
|
|
76 |
{
|
|
|
77 |
|
|
|
78 |
$request = $this->getRequest();
|
|
|
79 |
if($request->isGet()) {
|
|
|
80 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
81 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
82 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
83 |
|
|
|
84 |
$headers = $request->getHeaders();
|
|
|
85 |
|
|
|
86 |
$isJson = false;
|
|
|
87 |
if($headers->has('Accept')) {
|
|
|
88 |
$accept = $headers->get('Accept');
|
|
|
89 |
|
|
|
90 |
$prioritized = $accept->getPrioritized();
|
|
|
91 |
|
|
|
92 |
foreach($prioritized as $key => $value) {
|
|
|
93 |
$raw = trim($value->getRaw());
|
|
|
94 |
|
|
|
95 |
if(!$isJson) {
|
|
|
96 |
$isJson = strpos($raw, 'json');
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
if($isJson) {
|
|
|
103 |
|
16971 |
efrain |
104 |
$discoveryContactBlackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
105 |
$contact_ids = $discoveryContactBlackListMapper->fetchAllContactIdsByCompanyId($currentCompany->id);
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
16766 |
efrain |
109 |
$first_name = Functions::sanitizeFilterString($this->params()->fromQuery('first_name', ''));
|
|
|
110 |
$last_name = Functions::sanitizeFilterString($this->params()->fromQuery('last_name', ''));
|
|
|
111 |
$corporate_email = Functions::sanitizeFilterString($this->params()->fromQuery('corporate_email', ''));
|
|
|
112 |
$company = Functions::sanitizeFilterString($this->params()->fromQuery('company', ''));
|
|
|
113 |
$position = Functions::sanitizeFilterString($this->params()->fromQuery('position', ''));
|
|
|
114 |
$country = Functions::sanitizeFilterString($this->params()->fromQuery('country', ''));
|
|
|
115 |
$state = Functions::sanitizeFilterString($this->params()->fromQuery('state', ''));
|
|
|
116 |
$city = Functions::sanitizeFilterString($this->params()->fromQuery('city', ''));
|
|
|
117 |
$personal_email = Functions::sanitizeFilterString($this->params()->fromQuery('personal_email', ''));
|
|
|
118 |
$phone = Functions::sanitizeFilterString($this->params()->fromQuery('phone', ''));
|
|
|
119 |
$phone_extension = Functions::sanitizeFilterString($this->params()->fromQuery('phone_extension', ''));
|
|
|
120 |
$celular = Functions::sanitizeFilterString($this->params()->fromQuery('celular', ''));
|
|
|
121 |
$whatsapp = Functions::sanitizeFilterString($this->params()->fromQuery('whatsapp', ''));
|
|
|
122 |
$linkedin = Functions::sanitizeFilterString($this->params()->fromQuery('linkedin', ''));
|
16758 |
efrain |
123 |
|
|
|
124 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
125 |
$select = $queryMapper->getSql()->select(DiscoveryContactMapper::_TABLE);
|
|
|
126 |
|
16971 |
efrain |
127 |
if($contact_ids ) {
|
|
|
128 |
$select->where->notIn('id', $contact_ids );
|
|
|
129 |
}
|
|
|
130 |
|
16758 |
efrain |
131 |
if($first_name) {
|
|
|
132 |
$select->where->like('first_name', '%'.$first_name.'%');
|
|
|
133 |
}
|
|
|
134 |
if($last_name) {
|
|
|
135 |
$select->where->like('last_name', '%'.$last_name.'%');
|
|
|
136 |
}
|
|
|
137 |
if($corporate_email) {
|
|
|
138 |
$select->where->like('corporate_email', '%'.$corporate_email.'%');
|
|
|
139 |
}
|
|
|
140 |
if($company) {
|
|
|
141 |
$select->where->like('company', '%'.$company.'%');
|
|
|
142 |
}
|
|
|
143 |
if($position) {
|
|
|
144 |
$select->where->like('position', '%'.$position.'%');
|
|
|
145 |
}
|
|
|
146 |
if($country) {
|
|
|
147 |
$select->where->like('country', '%'.$country.'%');
|
|
|
148 |
}
|
|
|
149 |
if($state) {
|
|
|
150 |
$select->where->like('state', '%'.$state.'%');
|
|
|
151 |
}
|
|
|
152 |
if($city) {
|
|
|
153 |
$select->where->like('city', '%'.$city.'%');
|
|
|
154 |
}
|
|
|
155 |
if($personal_email) {
|
|
|
156 |
$select->where->like('personal_email', '%'.$personal_email.'%');
|
|
|
157 |
}
|
|
|
158 |
if($phone) {
|
|
|
159 |
$select->where->like('phone', '%'.$phone.'%');
|
|
|
160 |
}
|
|
|
161 |
if($phone_extension) {
|
|
|
162 |
$select->where->like('phone_extension', '%'.$phone_extension.'%');
|
|
|
163 |
}
|
|
|
164 |
if($celular) {
|
|
|
165 |
$select->where->like('celular', '%'.$celular.'%');
|
|
|
166 |
}
|
|
|
167 |
if($whatsapp) {
|
|
|
168 |
$select->where->like('whatsapp', '%'.$whatsapp.'%');
|
|
|
169 |
}
|
|
|
170 |
if($linkedin) {
|
|
|
171 |
$select->where->like('linkedin', '%'.$linkedin.'%');
|
|
|
172 |
}
|
|
|
173 |
$select->limit(100);
|
|
|
174 |
$select->order('added_on ASC');
|
|
|
175 |
|
|
|
176 |
$items = $queryMapper->fetchAll($select);
|
|
|
177 |
|
|
|
178 |
return new JsonModel([
|
|
|
179 |
'success' => true,
|
|
|
180 |
'data' => [
|
|
|
181 |
'items' => $items,
|
|
|
182 |
]
|
|
|
183 |
]);
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
} else {
|
|
|
187 |
$form = new ContactDownloadForm();
|
|
|
188 |
|
|
|
189 |
$this->layout()->setTemplate('layout/layout-backend.phtml');
|
|
|
190 |
$viewModel = new ViewModel();
|
|
|
191 |
$viewModel->setTemplate('leaders-linked/discovery-contact-report/index');
|
|
|
192 |
$viewModel->setVariables([
|
|
|
193 |
'form' => $form
|
|
|
194 |
]);
|
|
|
195 |
return $viewModel ;
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
return new JsonModel([
|
|
|
200 |
'success' => false,
|
|
|
201 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
202 |
]);;
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
public function downloadAction()
|
|
|
206 |
{
|
|
|
207 |
$request = $this->getRequest();
|
|
|
208 |
if($request->isGet()) {
|
|
|
209 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
210 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
211 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
212 |
|
16766 |
efrain |
213 |
$first_name = Functions::sanitizeFilterString($this->params()->fromQuery('first_name', ''));
|
|
|
214 |
$last_name = Functions::sanitizeFilterString($this->params()->fromQuery('last_name', ''));
|
|
|
215 |
$corporate_email = Functions::sanitizeFilterString($this->params()->fromQuery('corporate_email', ''));
|
|
|
216 |
$company = Functions::sanitizeFilterString($this->params()->fromQuery('company', ''));
|
|
|
217 |
$position = Functions::sanitizeFilterString($this->params()->fromQuery('position', ''));
|
|
|
218 |
$country = Functions::sanitizeFilterString($this->params()->fromQuery('country', ''));
|
|
|
219 |
$state = Functions::sanitizeFilterString($this->params()->fromQuery('state', ''));
|
|
|
220 |
$city = Functions::sanitizeFilterString($this->params()->fromQuery('city', ''));
|
|
|
221 |
$personal_email = Functions::sanitizeFilterString($this->params()->fromQuery('personal_email', ''));
|
|
|
222 |
$phone = Functions::sanitizeFilterString($this->params()->fromQuery('phone', ''));
|
|
|
223 |
$phone_extension = Functions::sanitizeFilterString($this->params()->fromQuery('phone_extension', ''));
|
|
|
224 |
$celular = Functions::sanitizeFilterString($this->params()->fromQuery('celular', ''));
|
|
|
225 |
$whatsapp = Functions::sanitizeFilterString($this->params()->fromQuery('whatsapp', ''));
|
|
|
226 |
$linkedin = Functions::sanitizeFilterString($this->params()->fromQuery('linkedin', ''));
|
|
|
227 |
$scholarship = Functions::sanitizeFilterString($this->params()->fromQuery('scholarship', ''));
|
16758 |
efrain |
228 |
|
16971 |
efrain |
229 |
$discoveryContactBlackListMapper = DiscoveryContactBlackListMapper::getInstance($this->adapter);
|
|
|
230 |
$contact_ids = $discoveryContactBlackListMapper->fetchAllContactIdsByCompanyId($currentCompany->id);
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
16758 |
efrain |
234 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
235 |
$select = $queryMapper->getSql()->select(DiscoveryContactMapper::_TABLE);
|
|
|
236 |
$select->columns([
|
|
|
237 |
'first_name',
|
|
|
238 |
'last_name',
|
|
|
239 |
'personal_email',
|
|
|
240 |
'corporate_email',
|
|
|
241 |
'company',
|
|
|
242 |
'position',
|
|
|
243 |
'country',
|
|
|
244 |
'state',
|
|
|
245 |
'city',
|
|
|
246 |
'phone',
|
|
|
247 |
'phone_extension',
|
|
|
248 |
'celular',
|
|
|
249 |
'whatsapp',
|
|
|
250 |
'linkedin',
|
|
|
251 |
'sector',
|
16766 |
efrain |
252 |
'scholarship',
|
16759 |
efrain |
253 |
'added_on'
|
16758 |
efrain |
254 |
]);
|
16971 |
efrain |
255 |
|
|
|
256 |
if($contact_ids ) {
|
|
|
257 |
$select->where->notIn('id', $contact_ids );
|
|
|
258 |
}
|
16758 |
efrain |
259 |
|
|
|
260 |
if($first_name) {
|
|
|
261 |
$select->where->like('first_name', '%'.$first_name.'%');
|
|
|
262 |
}
|
|
|
263 |
if($last_name) {
|
|
|
264 |
$select->where->like('last_name', '%'.$last_name.'%');
|
|
|
265 |
}
|
|
|
266 |
if($corporate_email) {
|
|
|
267 |
$select->where->like('corporate_email', '%'.$corporate_email.'%');
|
|
|
268 |
}
|
|
|
269 |
if($company) {
|
|
|
270 |
$select->where->like('company', '%'.$company.'%');
|
|
|
271 |
}
|
|
|
272 |
if($position) {
|
|
|
273 |
$select->where->like('position', '%'.$position.'%');
|
|
|
274 |
}
|
|
|
275 |
if($country) {
|
|
|
276 |
$select->where->like('country', '%'.$country.'%');
|
|
|
277 |
}
|
|
|
278 |
if($state) {
|
|
|
279 |
$select->where->like('state', '%'.$state.'%');
|
|
|
280 |
}
|
|
|
281 |
if($city) {
|
|
|
282 |
$select->where->like('city', '%'.$city.'%');
|
|
|
283 |
}
|
|
|
284 |
if($personal_email) {
|
|
|
285 |
$select->where->like('personal_email', '%'.$personal_email.'%');
|
|
|
286 |
}
|
|
|
287 |
if($phone) {
|
|
|
288 |
$select->where->like('phone', '%'.$phone.'%');
|
|
|
289 |
}
|
|
|
290 |
if($phone_extension) {
|
|
|
291 |
$select->where->like('phone_extension', '%'.$phone_extension.'%');
|
|
|
292 |
}
|
|
|
293 |
if($celular) {
|
|
|
294 |
$select->where->like('celular', '%'.$celular.'%');
|
|
|
295 |
}
|
|
|
296 |
if($whatsapp) {
|
|
|
297 |
$select->where->like('whatsapp', '%'.$whatsapp.'%');
|
|
|
298 |
}
|
|
|
299 |
if($linkedin) {
|
|
|
300 |
$select->where->like('linkedin', '%'.$linkedin.'%');
|
|
|
301 |
}
|
16766 |
efrain |
302 |
if($scholarship) {
|
|
|
303 |
// scholarship
|
|
|
304 |
}
|
16758 |
efrain |
305 |
|
16817 |
efrain |
306 |
$fileName = 'reporte_relevamiento_de_contactos.csv';
|
|
|
307 |
$tempFilename = tempnam(sys_get_temp_dir(), 'reporte_relevamiento_de_contactos_' . time(). '.csv');
|
16758 |
efrain |
308 |
|
16802 |
efrain |
309 |
$fp = fopen($tempFilename, 'w');
|
|
|
310 |
fputcsv($fp, [
|
|
|
311 |
$this->translator->translate('LABEL_FIRST_NAME'),
|
|
|
312 |
$this->translator->translate('LABEL_LAST_NAME'),
|
|
|
313 |
$this->translator->translate('LABEL_PERSONAL_EMAIL'),
|
|
|
314 |
$this->translator->translate('LABEL_CORPORATE_EMAIL'),
|
|
|
315 |
$this->translator->translate('LABEL_COMPANY'),
|
|
|
316 |
$this->translator->translate('LABEL_POSITION'),
|
|
|
317 |
$this->translator->translate('LABEL_COUNTRY'),
|
|
|
318 |
$this->translator->translate('LABEL_STATE'),
|
|
|
319 |
$this->translator->translate('LABEL_CITY'),
|
|
|
320 |
$this->translator->translate('LABEL_PHONE'),
|
|
|
321 |
$this->translator->translate('LABEL_PHONE_EXTENSION'),
|
|
|
322 |
$this->translator->translate('LABEL_CELULAR'),
|
|
|
323 |
$this->translator->translate('LABEL_WHATSAPP'),
|
|
|
324 |
$this->translator->translate('LABEL_LINKEDIN'),
|
|
|
325 |
$this->translator->translate('LABEL_SECTOR'),
|
|
|
326 |
$this->translator->translate('LABEL_SCHOLARSHIP'),
|
|
|
327 |
$this->translator->translate('LABEL_ADDED_DATE')
|
|
|
328 |
]);
|
16758 |
efrain |
329 |
|
16802 |
efrain |
330 |
|
16758 |
efrain |
331 |
$items = $queryMapper->fetchAll($select);
|
16760 |
efrain |
332 |
|
16758 |
efrain |
333 |
foreach ( $items as $item )
|
|
|
334 |
{
|
16802 |
efrain |
335 |
fputcsv($fp,$item);
|
16758 |
efrain |
336 |
}
|
16802 |
efrain |
337 |
fclose($fp);
|
16817 |
efrain |
338 |
$items = null;
|
16758 |
efrain |
339 |
|
16817 |
efrain |
340 |
$zipName = 'reporte_relevamiento_de_contactos.zip';
|
|
|
341 |
$zipFilename = tempnam(sys_get_temp_dir(), $zipName);
|
16760 |
efrain |
342 |
|
16758 |
efrain |
343 |
|
|
|
344 |
|
16975 |
efrain |
345 |
$zip = new \ZipArchive;
|
|
|
346 |
if ($zip->open($zipFilename,\ZipArchive::CREATE|\ZipArchive::OVERWRITE) === TRUE) {
|
16817 |
efrain |
347 |
$zip->addFile($tempFilename, $fileName);
|
|
|
348 |
$zip->close();
|
|
|
349 |
|
|
|
350 |
|
|
|
351 |
$content = file_get_contents($zipFilename);
|
|
|
352 |
|
|
|
353 |
@unlink($tempFilename);
|
|
|
354 |
@unlink($zipFilename);
|
|
|
355 |
|
|
|
356 |
|
|
|
357 |
return new JsonModel([
|
|
|
358 |
'success' => true,
|
|
|
359 |
'data' => [
|
|
|
360 |
'content' => base64_encode($content),
|
|
|
361 |
'basename' => $zipName
|
|
|
362 |
|
|
|
363 |
]
|
|
|
364 |
]);
|
|
|
365 |
|
|
|
366 |
|
|
|
367 |
|
|
|
368 |
|
|
|
369 |
} else {
|
|
|
370 |
|
|
|
371 |
@unlink($tempFilename);
|
|
|
372 |
|
|
|
373 |
return new JsonModel([
|
|
|
374 |
'success' => true,
|
|
|
375 |
'data' => 'ERROR_ZIP_CREATE_FILE',
|
|
|
376 |
]);
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
|
|
|
380 |
|
16758 |
efrain |
381 |
}
|
|
|
382 |
|
|
|
383 |
return new JsonModel([
|
|
|
384 |
'success' => false,
|
|
|
385 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
386 |
]);;
|
|
|
387 |
}
|
|
|
388 |
}
|