15397 |
efrain |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
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 LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
16 |
use LeadersLinked\Model\DiscoveryContact;
|
|
|
17 |
use LeadersLinked\Mapper\DiscoveryContactMapper;
|
|
|
18 |
use LeadersLinked\Form\DiscoveryContact\ContactForm;
|
|
|
19 |
use LeadersLinked\Model\DiscoveryContactLog;
|
|
|
20 |
use LeadersLinked\Mapper\DiscoveryContactLogMapper;
|
|
|
21 |
use LeadersLinked\Form\DiscoveryContact\InteractionForm;
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
class DiscoveryContactController extends AbstractActionController
|
|
|
25 |
{
|
|
|
26 |
/**
|
|
|
27 |
*
|
|
|
28 |
* @var AdapterInterface
|
|
|
29 |
*/
|
|
|
30 |
private $adapter;
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
* @var AbstractAdapter
|
|
|
36 |
*/
|
|
|
37 |
private $cache;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
*
|
|
|
41 |
* @var LoggerInterface
|
|
|
42 |
*/
|
|
|
43 |
private $logger;
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
*
|
|
|
47 |
* @var array
|
|
|
48 |
*/
|
|
|
49 |
private $config;
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
*
|
|
|
53 |
* @param AdapterInterface $adapter
|
|
|
54 |
* @param AbstractAdapter $cache
|
|
|
55 |
* @param LoggerInterface $logger
|
|
|
56 |
* @param array $config
|
|
|
57 |
*/
|
|
|
58 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
59 |
{
|
|
|
60 |
$this->adapter = $adapter;
|
|
|
61 |
$this->cache = $cache;
|
|
|
62 |
$this->logger = $logger;
|
|
|
63 |
$this->config = $config;
|
|
|
64 |
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public function indexAction()
|
|
|
68 |
{
|
|
|
69 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
70 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
71 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
72 |
|
|
|
73 |
$request = $this->getRequest();
|
|
|
74 |
if($request->isGet()) {
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
$headers = $request->getHeaders();
|
|
|
78 |
|
|
|
79 |
$isJson = false;
|
|
|
80 |
if($headers->has('Accept')) {
|
|
|
81 |
$accept = $headers->get('Accept');
|
|
|
82 |
|
|
|
83 |
$prioritized = $accept->getPrioritized();
|
|
|
84 |
|
|
|
85 |
foreach($prioritized as $key => $value) {
|
|
|
86 |
$raw = trim($value->getRaw());
|
|
|
87 |
|
|
|
88 |
if(!$isJson) {
|
|
|
89 |
$isJson = strpos($raw, 'json');
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
if($isJson) {
|
|
|
96 |
$search = $this->params()->fromQuery('search');
|
|
|
97 |
$search = empty($search) ? '' : filter_var($search, FILTER_SANITIZE_STRING);
|
|
|
98 |
|
|
|
99 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
100 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
101 |
$order = $this->params()->fromQuery('order', []);
|
|
|
102 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
103 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
104 |
|
|
|
105 |
$fields = ['first_name', 'last_name', 'corporate_email'];
|
|
|
106 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
|
|
|
107 |
|
|
|
108 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
109 |
$order_direction = 'ASC';
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
115 |
$paginator = $discoveryContactMapper->fetchAllDataTableForCompanyId($search, $currentCompany->id, $page, $records_x_page, $order_field, $order_direction);
|
|
|
116 |
|
|
|
117 |
$items = [];
|
|
|
118 |
$records = $paginator->getCurrentItems();
|
|
|
119 |
foreach($records as $record)
|
|
|
120 |
{
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
$item = [
|
|
|
124 |
'first_name' => $record->first_name,
|
|
|
125 |
'last_name' => $record->last_name,
|
|
|
126 |
'corporate_email' => $record->corporate_email,
|
|
|
127 |
'actions' => [
|
|
|
128 |
'link_edit' => $this->url()->fromRoute('discovery-contacts/edit', ['id' => $record->uuid ]),
|
|
|
129 |
'link_delete' => $this->url()->fromRoute('discovery-contacts/delete', ['id' => $record->uuid ]),
|
|
|
130 |
'link_view' => $this->url()->fromRoute('discovery-contacts/view', ['id' => $record->uuid ]),
|
|
|
131 |
],
|
|
|
132 |
];
|
|
|
133 |
|
|
|
134 |
array_push($items, $item);
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
return new JsonModel([
|
|
|
138 |
'success' => true,
|
|
|
139 |
'data' => [
|
|
|
140 |
'items' => $items,
|
|
|
141 |
'total' => $paginator->getTotalItemCount(),
|
|
|
142 |
]
|
|
|
143 |
]);
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
} else {
|
|
|
147 |
$exclude_id = 0;
|
|
|
148 |
$form = new ContactForm($this->adapter, $currentCompany->id, $exclude_id);
|
|
|
149 |
$formInteraction = new InteractionForm($this->adapter, $currentCompany->id);
|
|
|
150 |
|
|
|
151 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
152 |
$viewModel = new ViewModel();
|
|
|
153 |
$viewModel->setTemplate('leaders-linked/discovery-contacts/index.phtml');
|
|
|
154 |
$viewModel->setVariables([
|
|
|
155 |
'form' => $form,
|
|
|
156 |
'formInteraction' => $formInteraction
|
|
|
157 |
]);
|
|
|
158 |
return $viewModel ;
|
|
|
159 |
}
|
|
|
160 |
} else {
|
|
|
161 |
return new JsonModel([
|
|
|
162 |
'success' => false,
|
|
|
163 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
164 |
]);;
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
public function addAction()
|
|
|
169 |
{
|
|
|
170 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
171 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
172 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
173 |
|
|
|
174 |
$request = $this->getRequest();
|
|
|
175 |
if($request->isPost()) {
|
|
|
176 |
$exclude_id = 0;
|
|
|
177 |
$form = new ContactForm($this->adapter, $currentCompany->id, $exclude_id);
|
|
|
178 |
$dataPost = $request->getPost()->toArray();
|
|
|
179 |
|
|
|
180 |
$form->setData($dataPost);
|
|
|
181 |
|
|
|
182 |
if($form->isValid()) {
|
|
|
183 |
$dataPost = (array) $form->getData();
|
|
|
184 |
|
|
|
185 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
186 |
$discoveryContact = new DiscoveryContact();
|
|
|
187 |
$hydrator->hydrate($dataPost, $discoveryContact);
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
$discoveryContact->company_id = $currentCompany->id;
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
195 |
$result = $discoveryContactMapper->insert($discoveryContact);
|
|
|
196 |
|
|
|
197 |
if($result) {
|
|
|
198 |
$this->logger->info('Se agrego el Contacto : ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name , ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
199 |
|
|
|
200 |
$discoveryContactLog = new DiscoveryContactLog();
|
|
|
201 |
$discoveryContactLog->company_id = $currentCompany->id;
|
|
|
202 |
$discoveryContactLog->contact_id = $discoveryContact->id;
|
|
|
203 |
$discoveryContactLog->user_id = $currentUser->id;
|
|
|
204 |
$discoveryContactLog->activity = 'LABEL_RECORD_CONTACT_ADDED';
|
|
|
205 |
$discoveryContactLog->details = 'LABEL_FIRST_NAME : ' . $discoveryContact->first_name . PHP_EOL.
|
|
|
206 |
'LABEL_LAST_NAME : ' . $discoveryContact->last_name . PHP_EOL.
|
|
|
207 |
'LABEL_CORPORATE_EMAIL : ' . $discoveryContact->corporate_email . PHP_EOL.
|
|
|
208 |
'LABEL_COMPANY : ' . $discoveryContact->company . PHP_EOL.
|
|
|
209 |
'LABEL_POSITION : ' . $discoveryContact->position . PHP_EOL.
|
|
|
210 |
'LABEL_COUNTRY : ' . $discoveryContact->country . PHP_EOL;
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
if($discoveryContact->state) {
|
|
|
214 |
$discoveryContactLog->details .= 'LABEL_STATE : ' . $discoveryContact->state . PHP_EOL;
|
|
|
215 |
}
|
|
|
216 |
if($discoveryContact->city) {
|
|
|
217 |
$discoveryContactLog->details .= 'LABEL_CITY : ' . $discoveryContact->city . PHP_EOL;
|
|
|
218 |
}
|
|
|
219 |
if($discoveryContact->phone) {
|
|
|
220 |
$discoveryContactLog->details .= 'LABEL_PHONE : ' . $discoveryContact->phone . PHP_EOL;
|
|
|
221 |
}
|
|
|
222 |
if($discoveryContact->phone_extension) {
|
|
|
223 |
$discoveryContactLog->details .= 'LABEL_PHONE_EXTENSION : ' . $discoveryContact->phone_extension . PHP_EOL;
|
|
|
224 |
}
|
|
|
225 |
if($discoveryContact->personal_email) {
|
|
|
226 |
$discoveryContactLog->details .= 'LABEL_PERSONAL_EMAIL : ' . $discoveryContact->personal_email . PHP_EOL;
|
|
|
227 |
}
|
|
|
228 |
if($discoveryContact->celular) {
|
|
|
229 |
$discoveryContactLog->details .= 'LABEL_CELULAR : ' . $discoveryContact->celular . PHP_EOL;
|
|
|
230 |
}
|
|
|
231 |
if($discoveryContact->whatsapp) {
|
|
|
232 |
$discoveryContactLog->details .= 'LABEL_WHATSAPP : ' . $discoveryContact->whatsapp . PHP_EOL;
|
|
|
233 |
}
|
|
|
234 |
if($discoveryContact->linkedin) {
|
|
|
235 |
$discoveryContactLog->details .= 'LABEL_LINKEDIN : ' . $discoveryContact->linkedin . PHP_EOL;
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
|
|
|
239 |
$discoveryContactLogMapper->insert($discoveryContactLog);
|
|
|
240 |
|
|
|
241 |
$data = [
|
|
|
242 |
'success' => true,
|
|
|
243 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
244 |
];
|
|
|
245 |
} else {
|
|
|
246 |
$data = [
|
|
|
247 |
'success' => false,
|
|
|
248 |
'data' => $discoveryContactMapper->getError()
|
|
|
249 |
];
|
|
|
250 |
|
|
|
251 |
}
|
|
|
252 |
|
|
|
253 |
return new JsonModel($data);
|
|
|
254 |
|
|
|
255 |
} else {
|
|
|
256 |
$messages = [];
|
|
|
257 |
$form_messages = (array) $form->getMessages();
|
|
|
258 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
259 |
{
|
|
|
260 |
|
|
|
261 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
return new JsonModel([
|
|
|
265 |
'success' => false,
|
|
|
266 |
'data' => $messages
|
|
|
267 |
]);
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
} else {
|
|
|
271 |
$data = [
|
|
|
272 |
'success' => false,
|
|
|
273 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
274 |
];
|
|
|
275 |
|
|
|
276 |
return new JsonModel($data);
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
return new JsonModel($data);
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
public function editAction()
|
|
|
283 |
{
|
|
|
284 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
285 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
286 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
287 |
|
|
|
288 |
$request = $this->getRequest();
|
|
|
289 |
$uuid = $this->params()->fromRoute('id');
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
if(!$uuid) {
|
|
|
293 |
$data = [
|
|
|
294 |
'success' => false,
|
|
|
295 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
296 |
];
|
|
|
297 |
|
|
|
298 |
return new JsonModel($data);
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
302 |
$discoveryContact = $discoveryContactMapper->fetchOneByUuid($uuid);
|
|
|
303 |
if(!$discoveryContact) {
|
|
|
304 |
$data = [
|
|
|
305 |
'success' => false,
|
|
|
306 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
307 |
];
|
|
|
308 |
|
|
|
309 |
return new JsonModel($data);
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
$discoveryContactOld = clone $discoveryContact;
|
|
|
313 |
|
|
|
314 |
if($request->isPost()) {
|
|
|
315 |
|
|
|
316 |
$form = new ContactForm($this->adapter, $currentCompany->id, $discoveryContact->id);
|
|
|
317 |
$dataPost = $request->getPost()->toArray();
|
|
|
318 |
|
|
|
319 |
$form->setData($dataPost);
|
|
|
320 |
|
|
|
321 |
if($form->isValid()) {
|
|
|
322 |
$dataPost = (array) $form->getData();
|
|
|
323 |
|
|
|
324 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
325 |
$hydrator->hydrate($dataPost, $discoveryContact);
|
|
|
326 |
$result = $discoveryContactMapper->update($discoveryContact);
|
|
|
327 |
|
|
|
328 |
if($result) {
|
|
|
329 |
$this->logger->info('Se actualizo el Contacto ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
$discoveryContactLog = new DiscoveryContactLog();
|
|
|
333 |
$discoveryContactLog->company_id = $currentCompany->id;
|
|
|
334 |
$discoveryContactLog->contact_id = $discoveryContact->id;
|
|
|
335 |
$discoveryContactLog->user_id = $currentUser->id;
|
|
|
336 |
$discoveryContactLog->activity = 'LABEL_RECORD_CONTACT_UPDATED';
|
|
|
337 |
$discoveryContactLog->details = '';
|
|
|
338 |
|
|
|
339 |
if($discoveryContactOld->first_name != $discoveryContact->first_name) {
|
|
|
340 |
$discoveryContactLog->details .= 'LABEL_FIRST_NAME : ' . $discoveryContactOld->first_name . ' / ' . $discoveryContact->first_name . PHP_EOL;
|
|
|
341 |
}
|
|
|
342 |
if($discoveryContactOld->last_name != $discoveryContact->last_name ) {
|
|
|
343 |
$discoveryContactLog->details .= 'LABEL_LAST_NAME : ' . $discoveryContactOld->last_name . ' / ' . $discoveryContact->last_name . PHP_EOL;
|
|
|
344 |
}
|
|
|
345 |
if($discoveryContactOld->corporate_email != $discoveryContact->corporate_email) {
|
|
|
346 |
$discoveryContactLog->details .= 'LABEL_CORPORATE_EMAIL : ' . $discoveryContactOld->corporate_email . ' / ' . $discoveryContact->corporate_email . PHP_EOL ;
|
|
|
347 |
}
|
|
|
348 |
if($discoveryContactOld->company != $discoveryContact->company) {
|
|
|
349 |
$discoveryContactLog->details .= 'LABEL_COMPANY : ' . $discoveryContactOld->company . ' / ' . $discoveryContact->company . PHP_EOL ;
|
|
|
350 |
}
|
|
|
351 |
if($discoveryContactOld->position != $discoveryContact->position) {
|
|
|
352 |
$discoveryContactLog->details .= 'LABEL_POSITION : ' . $discoveryContactOld->position . ' / ' . $discoveryContact->position . PHP_EOL;
|
|
|
353 |
}
|
|
|
354 |
if($discoveryContactOld->country != $discoveryContact->country) {
|
|
|
355 |
$discoveryContactLog->details .= 'LABEL_COUNTRY : ' . $discoveryContactOld->country . ' / ' . $discoveryContact->country . PHP_EOL;
|
|
|
356 |
}
|
|
|
357 |
if($discoveryContactOld->state != $discoveryContact->state) {
|
|
|
358 |
$discoveryContactLog->details .= 'LABEL_STATE : ' . $discoveryContactOld->state . ' / ' . $discoveryContact->state . PHP_EOL;
|
|
|
359 |
}
|
|
|
360 |
if($discoveryContactOld->city != $discoveryContact->city) {
|
|
|
361 |
$discoveryContactLog->details .= 'LABEL_CITY : ' . $discoveryContactOld->city . ' / ' . $discoveryContact->city . PHP_EOL;
|
|
|
362 |
}
|
|
|
363 |
if($discoveryContactOld->phone != $discoveryContact->phone) {
|
|
|
364 |
$discoveryContactLog->details .= 'LABEL_PHONE : ' . $discoveryContactOld->phone . ' / ' . $discoveryContact->phone . PHP_EOL;
|
|
|
365 |
}
|
|
|
366 |
|
|
|
367 |
if($discoveryContactOld->phone_extension != $discoveryContact->phone_extension ) {
|
|
|
368 |
$discoveryContactLog->details .= 'LABEL_PHONE_EXTENSION : ' . $discoveryContactOld->phone_extension . ' / ' . $discoveryContact->phone_extension . PHP_EOL;
|
|
|
369 |
}
|
|
|
370 |
if($discoveryContactOld->personal_email != $discoveryContact->personal_email ) {
|
|
|
371 |
$discoveryContactLog->details .= 'LABEL_PERSONAL_EMAIL : ' . $discoveryContactOld->personal_email . ' / ' . $discoveryContact->personal_email . PHP_EOL;
|
|
|
372 |
}
|
|
|
373 |
if($discoveryContactOld->celular != $discoveryContact->celular) {
|
|
|
374 |
$discoveryContactLog->details .= 'LABEL_CELULAR : ' . $discoveryContactOld->celular . ' / ' . $discoveryContact->celular . PHP_EOL;
|
|
|
375 |
}
|
|
|
376 |
if($discoveryContactOld->whatsapp != $discoveryContact->whatsapp ) {
|
|
|
377 |
$discoveryContactLog->details .= 'LABEL_WHATSAPP : ' . $discoveryContactOld->whatsapp . ' / ' . $discoveryContact->whatsapp . PHP_EOL;
|
|
|
378 |
}
|
|
|
379 |
if($discoveryContactOld->linkedin != $discoveryContact->linkedin) {
|
|
|
380 |
$discoveryContactLog->details .= 'LABEL_LINKEDIN : ' . $discoveryContactOld->linkedin . ' / ' . $discoveryContact->linkedin . PHP_EOL;
|
|
|
381 |
}
|
|
|
382 |
$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);
|
|
|
383 |
$discoveryContactLogMapper->insert($discoveryContactLog);
|
|
|
384 |
|
|
|
385 |
|
|
|
386 |
$data = [
|
|
|
387 |
'success' => true,
|
|
|
388 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
389 |
];
|
|
|
390 |
} else {
|
|
|
391 |
$data = [
|
|
|
392 |
'success' => false,
|
|
|
393 |
'data' => $discoveryContactMapper->getError()
|
|
|
394 |
];
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
return new JsonModel($data);
|
|
|
398 |
|
|
|
399 |
} else {
|
|
|
400 |
$messages = [];
|
|
|
401 |
$form_messages = (array) $form->getMessages();
|
|
|
402 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
403 |
{
|
|
|
404 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
return new JsonModel([
|
|
|
408 |
'success' => false,
|
|
|
409 |
'data' => $messages
|
|
|
410 |
]);
|
|
|
411 |
}
|
|
|
412 |
} else if ($request->isGet()) {
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
416 |
$data = $hydrator->extract($discoveryContact);
|
|
|
417 |
|
|
|
418 |
$data['first_name'] = $data['first_name'] ? trim($data['first_name']) : '';
|
|
|
419 |
$data['last_name'] = $data['last_name'] ? trim($data['last_name']) : '';
|
|
|
420 |
$data['corporate_email'] = $data['corporate_email'] ? trim($data['corporate_email']) : '';
|
|
|
421 |
$data['company'] = $data['company'] ? trim($data['company']) : '';
|
|
|
422 |
$data['position'] = $data['position'] ? trim($data['position']) : '';
|
|
|
423 |
$data['country'] = $data['country'] ? trim($data['country']) : '';
|
|
|
424 |
$data['state'] = $data['state'] ? trim($data['state']) : '';
|
|
|
425 |
$data['city'] = $data['city'] ? trim($data['city']) : '';
|
|
|
426 |
$data['phone'] = $data['phone'] ? trim($data['phone']) : '';
|
|
|
427 |
$data['phone_extension'] = $data['phone_extension'] ? trim($data['phone_extension']) : '';
|
|
|
428 |
$data['personal_email'] = $data['personal_email'] ? trim($data['personal_email']) : '';
|
|
|
429 |
$data['celular'] = $data['celular'] ? trim($data['celular']) : '';
|
|
|
430 |
$data['whatsapp'] = $data['whatsapp'] ? trim($data['whatsapp']) : '';
|
|
|
431 |
$data['linkedin'] = $data['linkedin'] ? trim($data['linkedin']) : '';
|
|
|
432 |
|
|
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
|
436 |
$result = [
|
|
|
437 |
'success' => true,
|
|
|
438 |
'data' => $data
|
|
|
439 |
];
|
|
|
440 |
|
|
|
441 |
return new JsonModel($result);
|
|
|
442 |
} else {
|
|
|
443 |
$data = [
|
|
|
444 |
'success' => false,
|
|
|
445 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
446 |
];
|
|
|
447 |
|
|
|
448 |
return new JsonModel($data);
|
|
|
449 |
}
|
|
|
450 |
|
|
|
451 |
return new JsonModel($data);
|
|
|
452 |
}
|
|
|
453 |
|
|
|
454 |
public function deleteAction()
|
|
|
455 |
{
|
|
|
456 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
457 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
458 |
|
|
|
459 |
$request = $this->getRequest();
|
|
|
460 |
$uuid = $this->params()->fromRoute('id');
|
|
|
461 |
|
|
|
462 |
if(!$uuid) {
|
|
|
463 |
$data = [
|
|
|
464 |
'success' => false,
|
|
|
465 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
466 |
];
|
|
|
467 |
|
|
|
468 |
return new JsonModel($data);
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
472 |
$discoveryContact = $discoveryContactMapper->fetchOneByUuid($uuid);
|
|
|
473 |
if(!$discoveryContact) {
|
|
|
474 |
$data = [
|
|
|
475 |
'success' => false,
|
|
|
476 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
477 |
];
|
|
|
478 |
|
|
|
479 |
return new JsonModel($data);
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
if($request->isPost()) {
|
|
|
483 |
$result = $discoveryContactMapper->delete($discoveryContact);
|
|
|
484 |
if($result) {
|
|
|
485 |
$this->logger->info('Se borro el Contacto : ' . $discoveryContact->first_name . ' ' . $discoveryContact->last_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
486 |
|
|
|
487 |
$data = [
|
|
|
488 |
'success' => true,
|
|
|
489 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
490 |
];
|
|
|
491 |
} else {
|
|
|
492 |
|
|
|
493 |
$data = [
|
|
|
494 |
'success' => false,
|
|
|
495 |
'data' => $discoveryContactMapper->getError()
|
|
|
496 |
];
|
|
|
497 |
|
|
|
498 |
return new JsonModel($data);
|
|
|
499 |
}
|
|
|
500 |
|
|
|
501 |
} else {
|
|
|
502 |
$data = [
|
|
|
503 |
'success' => false,
|
|
|
504 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
505 |
];
|
|
|
506 |
|
|
|
507 |
return new JsonModel($data);
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
return new JsonModel($data);
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
public function viewAction()
|
|
|
514 |
{
|
|
|
515 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
516 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
517 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
518 |
|
|
|
519 |
$request = $this->getRequest();
|
|
|
520 |
$uuid = $this->params()->fromRoute('id');
|
|
|
521 |
|
|
|
522 |
|
|
|
523 |
if(!$uuid) {
|
|
|
524 |
$data = [
|
|
|
525 |
'success' => false,
|
|
|
526 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
527 |
];
|
|
|
528 |
|
|
|
529 |
return new JsonModel($data);
|
|
|
530 |
}
|
|
|
531 |
|
|
|
532 |
$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);
|
|
|
533 |
$discoveryContact = $discoveryContactMapper->fetchOneByUuid($uuid);
|
|
|
534 |
if(!$discoveryContact) {
|
|
|
535 |
$data = [
|
|
|
536 |
'success' => false,
|
|
|
537 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
538 |
];
|
|
|
539 |
|
|
|
540 |
return new JsonModel($data);
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
|
545 |
if ($request->isGet()) {
|
|
|
546 |
|
|
|
547 |
|
|
|
548 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
549 |
$data = $hydrator->extract($discoveryContact);
|
|
|
550 |
|
|
|
551 |
$data['first_name'] = $data['first_name'] ? trim($data['first_name']) : '';
|
|
|
552 |
$data['last_name'] = $data['last_name'] ? trim($data['last_name']) : '';
|
|
|
553 |
$data['corporate_email'] = $data['corporate_email'] ? trim($data['corporate_email']) : '';
|
|
|
554 |
$data['company'] = $data['company'] ? trim($data['company']) : '';
|
|
|
555 |
$data['position'] = $data['position'] ? trim($data['position']) : '';
|
|
|
556 |
$data['country'] = $data['country'] ? trim($data['country']) : '';
|
|
|
557 |
$data['state'] = $data['state'] ? trim($data['state']) : '';
|
|
|
558 |
$data['city'] = $data['city'] ? trim($data['city']) : '';
|
|
|
559 |
$data['phone'] = $data['phone'] ? trim($data['phone']) : '';
|
|
|
560 |
$data['phone_extension'] = $data['phone_extension'] ? trim($data['phone_extension']) : '';
|
|
|
561 |
$data['personal_email'] = $data['personal_email'] ? trim($data['personal_email']) : '';
|
|
|
562 |
$data['celular'] = $data['celular'] ? trim($data['celular']) : '';
|
|
|
563 |
$data['whatsapp'] = $data['whatsapp'] ? trim($data['whatsapp']) : '';
|
|
|
564 |
$data['linkedin'] = $data['linkedin'] ? trim($data['linkedin']) : '';
|
|
|
565 |
|
|
|
566 |
|
|
|
567 |
$data['link_interactions'] = $this->url()->fromRoute('discovery-contacts/interactions', ['id' => $discoveryContact->uuid]);
|
|
|
568 |
$data['link_interactions_add'] = $this->url()->fromRoute('discovery-contacts/interactions/add', ['id' => $discoveryContact->uuid]);
|
|
|
569 |
$data['link_logs'] = $this->url()->fromRoute('discovery-contacts/logs', ['id' => $discoveryContact->uuid]);
|
|
|
570 |
|
|
|
571 |
|
|
|
572 |
|
|
|
573 |
$result = [
|
|
|
574 |
'success' => true,
|
|
|
575 |
'data' => $data
|
|
|
576 |
];
|
|
|
577 |
|
|
|
578 |
return new JsonModel($result);
|
|
|
579 |
} else {
|
|
|
580 |
$data = [
|
|
|
581 |
'success' => false,
|
|
|
582 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
583 |
];
|
|
|
584 |
|
|
|
585 |
return new JsonModel($data);
|
|
|
586 |
}
|
|
|
587 |
|
|
|
588 |
return new JsonModel($data);
|
|
|
589 |
}
|
|
|
590 |
}
|