Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17008 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17008 Rev 17019
Línea 18... Línea 18...
18
use LeadersLinked\Mapper\QueryMapper;
18
use LeadersLinked\Mapper\QueryMapper;
19
use Laminas\Paginator\Adapter\DbSelect;
19
use Laminas\Paginator\Adapter\DbSelect;
20
use Laminas\Paginator\Paginator;
20
use Laminas\Paginator\Paginator;
21
use LeadersLinked\Form\Habit\HabitUserForm;
21
use LeadersLinked\Form\Habit\HabitUserForm;
22
use LeadersLinked\Form\Habit\HabitUserUploadForm;
22
use LeadersLinked\Form\Habit\HabitUserUploadForm;
-
 
23
use PhpOffice\PhpSpreadsheet\IOFactory;
-
 
24
use LeadersLinked\Mapper\LocationMapper;
-
 
25
use LeadersLinked\Mapper\CountryMapper;
-
 
26
use LeadersLinked\Mapper\NetworkMapper;
-
 
27
use LeadersLinked\Mapper\UserPasswordMapper;
-
 
28
use LeadersLinked\Model\User;
-
 
29
use LeadersLinked\Model\UserType;
-
 
30
use LeadersLinked\Model\Location;
-
 
31
use LeadersLinked\Model\UserPassword;
-
 
32
use LeadersLinked\Model\Network;
-
 
33
use LeadersLinked\Mapper\CompanyMapper;
-
 
34
use LeadersLinked\Mapper\CompanyFollowerMapper;
-
 
35
use LeadersLinked\Mapper\ConnectionMapper;
-
 
36
use LeadersLinked\Model\Connection;
-
 
37
use LeadersLinked\Model\CompanyFollower;
Línea 23... Línea 38...
23
 
38
 
Línea 24... Línea 39...
24
class HabitUserController extends AbstractActionController {
39
class HabitUserController extends AbstractActionController {
25
 
40
 
Línea 98... Línea 113...
98
                        $isJson = strpos($raw, 'json');
113
                        $isJson = strpos($raw, 'json');
99
                    }
114
                    }
100
                }
115
                }
101
            }
116
            }
Línea 102... Línea 117...
102
 
117
 
103
            //$isJson = true;
118
           // $isJson = true;
Línea 104... Línea 119...
104
            if ($isJson) {
119
            if ($isJson) {
105
    
120
    
Línea 134... Línea 149...
134
              
149
              
Línea 135... Línea 150...
135
                $items = [];
150
                $items = [];
136
                
151
                
137
                $queryMapper = QueryMapper::getInstance($this->adapter);
152
                $queryMapper = QueryMapper::getInstance($this->adapter);
138
                $select = $queryMapper->getSql()->select();
153
                $select = $queryMapper->getSql()->select();
139
                $select->columns(['role']);
154
                $select->columns([]);
Línea -... Línea 155...
-
 
155
                $select->from(['cu' => HabitUserMapper::_TABLE]);
-
 
156
                $select->join(['u' => UserMapper::_TABLE], 'cu.user_id = u.id',  ['uuid', 'first_name', 'last_name', 'email']);
140
                $select->from(['cu' => HabitUserMapper::_TABLE]);
157
            
141
                $select->join(['u' => UserMapper::_TABLE], 'cu.user_id = u.id',  ['uuid', 'first_name', 'last_name', 'email']);
158
                
142
            
159
                $select->where->equalTo('cu.company_id', $currentCompany->id);
143
                
160
                
144
                if($search) {
161
                if($search) {
Línea 185... Línea 202...
185
                    ]
202
                    ]
186
                ]);
203
                ]);
187
            } else {
204
            } else {
Línea 188... Línea 205...
188
                
205
                
189
                
-
 
-
 
206
                
Línea 190... Línea 207...
190
                $form       = new HabitUserForm($this->adapter, $currentCompany->id);
207
                $form = new HabitUserForm($this->adapter, $currentCompany->id);
191
 
208
                $formUploadUsers = new HabitUserUploadForm();
192
 
209
 
193
                $this->layout()->setTemplate('layout/layout-backend');
210
                $this->layout()->setTemplate('layout/layout-backend');
194
                $viewModel = new ViewModel();
211
                $viewModel = new ViewModel();
-
 
212
                $viewModel->setTemplate('leaders-linked/habits/users.phtml');
Línea 195... Línea 213...
195
                $viewModel->setTemplate('leaders-linked/habits/users.phtml');
213
                $viewModel->setVariables([
196
                $viewModel->setVariables([
214
                    'form' =>  $form,
197
                    'form'          =>  $form,
215
                    'formUploadUsers' => $formUploadUsers,
198
 
216
 
Línea 300... Línea 318...
300
        return new JsonModel($data);
318
        return new JsonModel($data);
Línea 301... Línea 319...
301
 
319
 
Línea 302... Línea -...
302
 
-
 
303
    }
-
 
304
 
-
 
305
    public function editAction() 
-
 
306
    {
-
 
307
        $request = $this->getRequest();
-
 
308
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
309
        $currentCompany = $currentUserPlugin->getCompany();
-
 
310
        $currentUser = $currentUserPlugin->getUser();
-
 
311
 
-
 
312
        $request = $this->getRequest();
-
 
313
        $uuid = $this->params()->fromRoute('id');
-
 
314
      
-
 
315
        
-
 
316
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
317
        $user = $userMapper->fetchOneByUuid($uuid);
-
 
318
        
-
 
319
        if(!$user) {
-
 
320
            return new JsonModel([
-
 
321
                'success' => false,
-
 
322
                'data' => 'ERROR_USER_NOT_FOUND'
-
 
323
            ]);
-
 
324
            
-
 
325
        }
-
 
326
        
-
 
327
        $habitUserMapper = HabitUserMapper::getInstance($this->adapter);
-
 
328
        $habitUser = $habitUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user->id);
-
 
329
        
-
 
330
        if(!$habitUser) {
-
 
331
            return new JsonModel([
-
 
332
                'success' => false,
-
 
333
                'data' => 'ERROR_HABITS_USER_NOT_FOUND'
-
 
334
            ]);
-
 
335
        }
-
 
336
 
-
 
337
 
-
 
338
 
-
 
339
        if ($request->isPost()) {
-
 
340
            $dataPost = $request->getPost()->toArray();
-
 
341
            
-
 
342
            $form = new  HabitUserForm($this->adapter, $currentCompany->id);
-
 
343
            $form->setData($dataPost);
-
 
344
            
-
 
345
 
-
 
346
 
-
 
347
            if ($form->isValid()) {
-
 
348
                $dataPost = (array) $form->getData();
-
 
349
                
-
 
350
         
-
 
351
 
-
 
352
                if($habitUserMapper->update($habitUser)) {
-
 
353
                    
-
 
354
                  $this->logger->info('Se actualizo el usuario ' . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ')  ', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
355
                    
-
 
356
                   $data = [
-
 
357
                       'success'   => true,
-
 
358
                       'data'   => 'LABEL_RECORD_UPDATED'
-
 
359
                   ];
-
 
360
               } else {
-
 
361
                   $data = [
-
 
362
                       'success'   => false,
-
 
363
                       'data'      => $habitUserMapper->getError()
-
 
364
                   ];
-
 
365
                   
-
 
366
               }
-
 
367
 
-
 
368
                return new JsonModel($data);
-
 
369
            } else {
-
 
370
                $messages = [];
-
 
371
                $form_messages = (array) $form->getMessages();
-
 
372
                foreach ($form_messages as $fieldname => $field_messages) {
-
 
373
                    $messages[$fieldname] = array_values($field_messages);
-
 
374
                }
-
 
375
 
-
 
376
                return new JsonModel([
-
 
377
                    'success' => false,
-
 
378
                    'data' => $messages
-
 
379
                ]);
-
 
380
            }
-
 
381
        } else if ($request->isGet()) {
-
 
382
            
-
 
383
 
-
 
384
            $data = [
-
 
385
                'success' => true,
-
 
386
                'data' => [
-
 
387
                    'user_id' => $user->uuid,
-
 
388
                    'role' => $habitUser->role,
-
 
389
                ]
-
 
390
            ];
-
 
391
 
-
 
392
            return new JsonModel($data);
-
 
393
        } 
-
 
394
           
-
 
395
           
-
 
396
        $data = [
-
 
397
            'success' => false,
-
 
398
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
Línea 399... Línea -...
399
        ];
-
 
Línea 400... Línea 320...
400
 
320
 
401
        return new JsonModel($data);
321
    }
402
    
322
 
403
    }
323
    
Línea 469... Línea 389...
469
        
389
        
Línea 470... Línea 390...
470
        return new JsonModel($data);
390
        return new JsonModel($data);
Línea -... Línea 391...
-
 
391
 
-
 
392
    }
-
 
393
    
-
 
394
    
-
 
395
    public function uploadAction()
-
 
396
    {
-
 
397
        $request = $this->getRequest();
-
 
398
        
-
 
399
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
-
 
400
        $currentNetwork    = $currentNetworkPlugin->getNetwork();
-
 
401
        
-
 
402
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
403
        $currentUser    = $currentUserPlugin->getUser();
-
 
404
        $currentCompany = $currentUserPlugin->getCompany();
-
 
405
        
-
 
406
        $request    = $this->getRequest();
-
 
407
        
-
 
408
        if($request->isPost()) {
-
 
409
            
-
 
410
            $step = Functions::sanitizeFilterString($this->params()->fromPost('step'));
-
 
411
            if($step == 'validation') {
-
 
412
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
413
                $habitUserMapper = HabitUserMapper::getInstance($this->adapter);
-
 
414
                
-
 
415
                $form = new  HabitUserUploadForm();
-
 
416
                $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
-
 
417
                
-
 
418
                $form->setData($dataPost);
-
 
419
                
-
 
420
                if($form->isValid()) {
-
 
421
                    
-
 
422
                    $file = $_FILES['file'];
-
 
423
                    $tmp_filename = $file['tmp_name'];
-
 
424
                    $final_filename =  'data/' . $file['name'];
-
 
425
                    
-
 
426
                    if(!move_uploaded_file($tmp_filename, $final_filename)) {
-
 
427
                        return new JsonModel([
-
 
428
                            'success' => false,
-
 
429
                            'data' => 'ERROR_UPLOAD_FILE'
-
 
430
                        ]);
-
 
431
                    }
-
 
432
                    
-
 
433
                    
-
 
434
                    $users = [];
-
 
435
                    
-
 
436
                    
-
 
437
                    $spreadsheet = IOFactory::load($final_filename);
-
 
438
                    $records = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
-
 
439
                    
-
 
440
                    $emails = [];
-
 
441
                    
-
 
442
                    foreach($records as $record)
-
 
443
                    {
-
 
444
                        //A = Nombre 	B = Apellidos	C = Email 	D = contraseña
-
 
445
                        
-
 
446
                        
-
 
447
                        $first_name = Functions::sanitizeFilterString($record['A']);
-
 
448
                        $last_name = Functions::sanitizeFilterString($record['B']);
-
 
449
                        $email = trim(filter_var($record['C'], FILTER_SANITIZE_EMAIL));
-
 
450
                        $password = Functions::sanitizeFilterString($record['D']);
-
 
451
                        $isAdult = strtolower(Functions::sanitizeFilterString($record['E']));
-
 
452
                        $country = strtolower(Functions::sanitizeFilterString($record['F']));
-
 
453
                        
-
 
454
                        
-
 
455
                        if(empty($first_name) || empty($last_name) || !filter_var($email, FILTER_VALIDATE_EMAIL) ||  empty($password)) {
-
 
456
                            continue;
-
 
457
                        }
-
 
458
                        
-
 
459
                        if(!in_array($email, $emails)) {
-
 
460
                            
-
 
461
                            $user = $userMapper->fetchOneByEmail($email);
-
 
462
                            
-
 
463
                            array_push($emails, $email);
-
 
464
                            array_push($users, [
-
 
465
                                'first_name' => $first_name,
-
 
466
                                'last_name' => $last_name,
-
 
467
                                'password'  => $password,
-
 
468
                                'email' => $email,
-
 
469
                                'is_adult' => $isAdult,
-
 
470
                                'country' => $country,
-
 
471
                                
-
 
472
                            ]);
-
 
473
                        }
-
 
474
                        
-
 
475
                        
-
 
476
                        
-
 
477
                        
-
 
478
                        
-
 
479
                    }
-
 
480
                    
-
 
481
                    $key = md5($currentUser->id . '-' . microtime(true));
-
 
482
                    $this->cache->setItem($key, serialize($users));
-
 
483
                    
-
 
484
                    return new JsonModel([
-
 
485
                        'success' => true,
-
 
486
                        'data' => [
-
 
487
                            'key' => $key,
-
 
488
                            'items' => $users,
-
 
489
                        ]
-
 
490
                    ]);
-
 
491
                    
-
 
492
                    @unlink($final_filename);
-
 
493
                    
-
 
494
                    
-
 
495
                } else {
-
 
496
                    $messages = [];
-
 
497
                    $form_messages = (array) $form->getMessages();
-
 
498
                    foreach($form_messages  as $fieldname => $field_messages)
-
 
499
                    {
-
 
500
                        
-
 
501
                        $messages[$fieldname] = array_values($field_messages);
-
 
502
                    }
-
 
503
                    
-
 
504
                    return new JsonModel([
-
 
505
                        'success'   => false,
-
 
506
                        'data'   => $messages
-
 
507
                    ]);
-
 
508
                }
-
 
509
            } else if($step == 'process') {
-
 
510
                
-
 
511
                $key = Functions::sanitizeFilterString($this->params()->fromPost('key'));
-
 
512
                if(!$key) {
-
 
513
                    return new JsonModel([
-
 
514
                        'success' => false,
-
 
515
                        'data' => 'ERROR_CACHE_KEY_EMPTY'
-
 
516
                    ]);
-
 
517
                }
-
 
518
                
-
 
519
                $value = $this->cache->getItem($key);
-
 
520
                if(!$value) {
-
 
521
                    
-
 
522
                    return new JsonModel([
-
 
523
                        'success' => false,
-
 
524
                        'data' => 'ERROR_CACHE_NOT_FOUND'
-
 
525
                    ]);
-
 
526
                }
-
 
527
                
-
 
528
                $records = unserialize($value);
-
 
529
                if(!$records) {
-
 
530
                    return new JsonModel([
-
 
531
                        'success' => false,
-
 
532
                        'data' => 'ERROR_CACHE_INVALID'
-
 
533
                    ]);
-
 
534
                }
-
 
535
                
-
 
536
                $locationMapper = LocationMapper::getInstance($this->adapter);
-
 
537
                $countryMapper = CountryMapper::getInstance($this->adapter);
-
 
538
                
-
 
539
                
-
 
540
                $networkMapper = NetworkMapper::getInstance($this->adapter);
-
 
541
                $networkDefault = $networkMapper->fetchOneByDefault();
-
 
542
                
-
 
543
                $userMapper = UserMapper::getInstance($this->adapter);
-
 
544
                $userPasswordMapper = UserPasswordMapper::getInstance($this->adapter);
-
 
545
                
-
 
546
                
-
 
547
                $user_ids_in_default_network = [];
-
 
548
                
-
 
549
                
-
 
550
                $users_created = 0;
-
 
551
                $user_ids = [];
-
 
552
                foreach($records as $record)
-
 
553
                {
-
 
554
                    $first_name = $record['first_name'];
-
 
555
                    $last_name = $record['last_name'];
-
 
556
                    $password = $record['password'];
-
 
557
                    $email = $record['email'];
-
 
558
                    
-
 
559
                    
-
 
560
                    $user = $userMapper->fetchOneByEmailAndNetworkId($email, $currentNetwork->id);
-
 
561
                    if(!$user) {
-
 
562
                        $password_hash = password_hash($password, PASSWORD_DEFAULT);
-
 
563
                        
-
 
564
                        $user = new User();
-
 
565
                        $user->network_id = $currentNetwork->id;
-
 
566
                        $user->blocked = User::BLOCKED_NO;
-
 
567
                        $user->email_verified = User::EMAIL_VERIFIED_YES;
-
 
568
                        $user->email = $email;
-
 
569
                        $user->first_name = $first_name;
-
 
570
                        $user->last_name = $last_name;
-
 
571
                        $user->password = $password_hash;
-
 
572
                        $user->login_attempt = 0;
-
 
573
                        $user->usertype_id = UserType::USER;
-
 
574
                        $user->status = User::STATUS_ACTIVE;
-
 
575
                        $user->is_adult = $record['is_adult'] == 'y' ? User::IS_ADULT_YES : User::IS_ADULT_NO;
-
 
576
                        
-
 
577
                        $result = $userMapper->insert($user);
-
 
578
                        if($result) {
-
 
579
                            $users_created++;
-
 
580
                            
-
 
581
                            $country_code = trim($record['country']);
-
 
582
                            
-
 
583
                            if($country_code) {
-
 
584
                                $country = $countryMapper->fetchOneByCodeOrCountry($record['country']);
-
 
585
                                if($country) {
-
 
586
                                    
-
 
587
                                    $location = new Location();
-
 
588
                                    $location->formatted_address = $country->country;
-
 
589
                                    $location->country = $country->country;
-
 
590
                                    if($locationMapper->insert($location)) {
-
 
591
                                        
-
 
592
                                        $user->location_id = $location->id;
-
 
593
                                        $userMapper->updateLocation($user);
-
 
594
                                    }
-
 
595
                                    
-
 
596
                                }
-
 
597
                            } else {
-
 
598
                                $country_code = '';
-
 
599
                            }
-
 
600
                            
-
 
601
                            $userPassword = new UserPassword();
-
 
602
                            $userPassword->user_id = $user->id;
-
 
603
                            $userPassword->password = $password_hash;
-
 
604
                            $userPasswordMapper->insert($userPassword);
-
 
605
                            
-
 
606
                            
-
 
607
                            if($currentNetwork->default == Network::DEFAULT_YES) {
-
 
608
                                array_push($user_ids_in_default_network, $user->id);
-
 
609
                            } else {
-
 
610
                                
-
 
611
                                
-
 
612
                                
-
 
613
                                if($user->is_adult == User::IS_ADULT_YES) {
-
 
614
                                    
-
 
615
                                    $userInDefaultNetwork = $userMapper->fetchOneByEmailAndNetworkId($user->email, $networkDefault->id);
-
 
616
                                    if($userInDefaultNetwork) {
-
 
617
                                        
-
 
618
                                        array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
-
 
619
                                        
-
 
620
                                        if($userInDefaultNetwork->email_verified == User::EMAIL_VERIFIED_NO || $userInDefaultNetwork->status != User::STATUS_ACTIVE) {
-
 
621
                                            $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
-
 
622
                                            $userInDefaultNetwork->status != User::STATUS_ACTIVE;
-
 
623
                                            
-
 
624
                                            if(!$userMapper->update($userInDefaultNetwork)) {
-
 
625
                                                continue;
-
 
626
                                            }
-
 
627
                                        }
-
 
628
                                        
-
 
629
                                        
-
 
630
                                    } else {
-
 
631
                                        $userInDefaultNetwork = new User();
-
 
632
                                        $userInDefaultNetwork->network_id = $networkDefault->id;
-
 
633
                                        $userInDefaultNetwork->blocked = User::BLOCKED_NO;
-
 
634
                                        $userInDefaultNetwork->email_verified = User::EMAIL_VERIFIED_YES;
-
 
635
                                        $userInDefaultNetwork->email = $email;
-
 
636
                                        $userInDefaultNetwork->first_name = $first_name;
-
 
637
                                        $userInDefaultNetwork->last_name = $last_name;
-
 
638
                                        $userInDefaultNetwork->password = $password_hash;
-
 
639
                                        $userInDefaultNetwork->login_attempt = 0;
-
 
640
                                        $userInDefaultNetwork->usertype_id = UserType::USER;
-
 
641
                                        $userInDefaultNetwork->status = User::STATUS_ACTIVE;
-
 
642
                                        $userInDefaultNetwork->is_adult = User::IS_ADULT_YES;
-
 
643
                                        $result = $userMapper->insert($userInDefaultNetwork);
-
 
644
                                        if($result) {
-
 
645
                                            array_push($user_ids_in_default_network, $userInDefaultNetwork->id);
-
 
646
                                            
-
 
647
                                            if($country) {
-
 
648
                                                
-
 
649
                                                $location = new Location();
-
 
650
                                                $location->formatted_address = $country->country;
-
 
651
                                                $location->country = $country->country;
-
 
652
                                                if($locationMapper->insert($location)) {
-
 
653
                                                    
-
 
654
                                                    $userInDefaultNetwork->location_id = $location->id;
-
 
655
                                                    $userMapper->updateLocation($userInDefaultNetwork);
-
 
656
                                                }
-
 
657
                                                
-
 
658
                                            }
-
 
659
                                            
-
 
660
                                            
-
 
661
                                            $userPassword = new UserPassword();
-
 
662
                                            $userPassword->user_id = $userInDefaultNetwork->id;
-
 
663
                                            $userPassword->password = $password_hash;
-
 
664
                                            $userPasswordMapper->insert($userPassword);
-
 
665
                                        }
-
 
666
                                        
-
 
667
                                    }
-
 
668
                                    
-
 
669
                                    
-
 
670
                                }
-
 
671
                                
-
 
672
                                
-
 
673
                            }
-
 
674
                            
-
 
675
                            
-
 
676
                            
-
 
677
                            
-
 
678
                            
-
 
679
                            
-
 
680
                        } else {
-
 
681
                            continue;
-
 
682
                        }
-
 
683
                    } else {
-
 
684
                        if($user->email_verified == User::EMAIL_VERIFIED_NO || $user->status != User::STATUS_ACTIVE) {
-
 
685
                            $user->email_verified = User::EMAIL_VERIFIED_YES;
-
 
686
                            $user->status != User::STATUS_ACTIVE;
-
 
687
                            
-
 
688
                            if(!$userMapper->update($user)) {
-
 
689
                                continue;
-
 
690
                            }
-
 
691
                        }
-
 
692
                    }
-
 
693
                    
-
 
694
                    array_push($user_ids, $user->id);
-
 
695
                    
-
 
696
                }
-
 
697
                
-
 
698
                if($currentCompany) {
-
 
699
                    
-
 
700
                    $habitUserMapper = HabitUserMapper::getInstance($this->adapter);
-
 
701
                    
-
 
702
                    $company_users_created = 0;
-
 
703
                    
-
 
704
                    foreach($user_ids as $user_id)
-
 
705
                    {
-
 
706
                        $habitUser = $habitUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id, $user_id);
-
 
707
                        if(!$habitUser) {
-
 
708
                            
-
 
709
                            $habitUser = new HabitUser();
-
 
710
                            $habitUser->network_id  = $currentCompany->network_id;
-
 
711
                            $habitUser->company_id  = $currentCompany->id;
-
 
712
                            $habitUser->user_id     = $user_id;
-
 
713
                            $habitUser->access      = HabitUser::ACCESS_UNLIMITED;
-
 
714
    
-
 
715
                            
-
 
716
                            if($habitUserMapper->insert($habitUser)) {
-
 
717
                                $company_users_created++;
-
 
718
                            }
-
 
719
                            
-
 
720
                        }
-
 
721
                        
-
 
722
                    }
-
 
723
                    
-
 
724
                    $this->logger->info('Se agregaron ' . $users_created . '  usuarios  la empresa ' . $currentCompany->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
725
                    
-
 
726
                    
-
 
727
                    
-
 
728
                } else {
-
 
729
                    
-
 
730
                    $this->logger->info('Se agregaron ' . $users_created . ' usuarios a la red', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
731
                    
-
 
732
                }
-
 
733
                
-
 
734
                if($user_ids_in_default_network) {
-
 
735
                    $companyMapper = CompanyMapper::getInstance($this->adapter);
-
 
736
                    $companyToFollower = $companyMapper->fetchOneDefaultForFollowers();
-
 
737
                    
-
 
738
                    $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
-
 
739
                    
-
 
740
                    $userToConnection = $userMapper->fetchOneDefaultForConnection();
-
 
741
                    
-
 
742
                    
-
 
743
                    $connectionMapper = ConnectionMapper::getInstance($this->adapter);
-
 
744
                    
-
 
745
                    foreach($user_ids_in_default_network as $user_id)
-
 
746
                    {
-
 
747
                        if($userToConnection) {
-
 
748
                            $connection = $connectionMapper->fetchOneByUserId1AndUserId2($user_id, $userToConnection->id);
-
 
749
                            if(!$connection) {
-
 
750
                                $connection = new Connection();
-
 
751
                                $connection->request_from = $user_id;
-
 
752
                                $connection->request_to = $userToConnection->id;
-
 
753
                                $connection->status = Connection::STATUS_ACCEPTED;
-
 
754
                                
-
 
755
                                $connectionMapper->insert($connection);
-
 
756
                            } else {
-
 
757
                                if($connection->status == Connection::STATUS_SENT) {
-
 
758
                                    $connectionMapper->approve($connection);
-
 
759
                                }
-
 
760
                            }
-
 
761
                        }
-
 
762
                        
-
 
763
                        if($companyToFollower) {
-
 
764
                            $companyFollower = $companyFollowerMapper->fetchOneByCompanyIdAndUserId($companyToFollower->id, $user_id);
-
 
765
                            if(!$companyFollower) {
-
 
766
                                $companyFollower = new CompanyFollower();
-
 
767
                                $companyFollower->company_id = $companyToFollower->id;
-
 
768
                                $companyFollower->follower_id = $user_id;
-
 
769
                                
-
 
770
                                $companyFollowerMapper->insert($companyFollower);
-
 
771
                                
-
 
772
                            }
-
 
773
                        }
-
 
774
                        
-
 
775
                    }
-
 
776
                    
-
 
777
                    
-
 
778
                    
-
 
779
                    
-
 
780
                }
-
 
781
                
-
 
782
                
-
 
783
                
-
 
784
                return new JsonModel([
-
 
785
                    'success' => true,
-
 
786
                    'data' => [
-
 
787
                        'users_created' => $users_created
-
 
788
                    ]
-
 
789
                ]);
-
 
790
                
-
 
791
                
-
 
792
                
-
 
793
                
-
 
794
            } else {
-
 
795
                return new JsonModel([
-
 
796
                    'success' => false,
-
 
797
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
-
 
798
                ]);
-
 
799
            }
-
 
800
            
-
 
801
            
-
 
802
            
-
 
803
            
-
 
804
        }
-
 
805
        
-
 
806
        return new JsonModel([
-
 
807
            'success' => false,
-
 
808
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
Línea 471... Línea 809...
471
 
809
        ]);
472
    }
810
    }