Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15546 | Rev 15628 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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