Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6849 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\AuthenticationService;
7
use Laminas\Db\Adapter\AdapterInterface;
6849 efrain 8
 
1 www 9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
13
use LeadersLinked\Mapper\QueryMapper;
14
use LeadersLinked\Mapper\UserMapper;
15
use LeadersLinked\Model\UserExperience;
16
use LeadersLinked\Mapper\UserExperienceMapper;
17
use Laminas\Db\Sql\Select;
18
use LeadersLinked\Mapper\CompanyMapper;
19
use LeadersLinked\Model\User;
20
use LeadersLinked\Mapper\LocationMapper;
21
use LeadersLinked\Mapper\CompanySizeMapper;
22
use LeadersLinked\Mapper\GroupMapper;
23
use LeadersLinked\Mapper\GroupMemberMapper;
24
use LeadersLinked\Mapper\IndustryMapper;
25
use Laminas\Paginator\Adapter\DbSelect;
26
use Laminas\Paginator\Paginator;
27
use LeadersLinked\Mapper\UserSkillMapper;
28
use LeadersLinked\Mapper\SkillMapper;
29
use LeadersLinked\Model\Job;
30
use LeadersLinked\Mapper\ConnectionMapper;
31
use LeadersLinked\Mapper\UserProfileMapper;
32
use LeadersLinked\Model\UserProfile;
33
use Laminas\Db\Sql\Expression;
34
use LeadersLinked\Mapper\GroupTypeMapper;
35
use LeadersLinked\Mapper\JobMapper;
36
use LeadersLinked\Mapper\ProfileVisitMapper;
37
use LeadersLinked\Mapper\CompanyLocationMapper;
38
use LeadersLinked\Mapper\CompanyFollowerMapper;
39
use LeadersLinked\Mapper\JobApplicationMapper;
40
use LeadersLinked\Model\UserType;
41
use LeadersLinked\Mapper\UserBlockedMapper;
42
use LeadersLinked\Mapper\CompanyUserMapper;
43
use LeadersLinked\Model\CompanyUser;
44
use LeadersLinked\Model\Company;
45
use LeadersLinked\Model\Group;
4842 efrain 46
use LeadersLinked\Model\Network;
6749 efrain 47
use LeadersLinked\Library\Functions;
1 www 48
 
49
class SearchController extends AbstractActionController
50
{
51
    /**
52
     *
6866 efrain 53
     * @var \Laminas\Db\Adapter\AdapterInterface
1 www 54
     */
55
    private $adapter;
56
 
57
    /**
58
     *
6866 efrain 59
     * @var \LeadersLinked\Cache\CacheInterface
1 www 60
     */
6866 efrain 61
    private $cache;
62
 
63
 
64
    /**
65
     *
66
     * @var \Laminas\Log\LoggerInterface
67
     */
1 www 68
    private $logger;
69
 
70
    /**
71
     *
72
     * @var array
73
     */
74
    private $config;
75
 
6866 efrain 76
 
1 www 77
    /**
78
     *
6866 efrain 79
     * @var \Laminas\Mvc\I18n\Translator
80
     */
81
    private $translator;
82
 
83
 
84
    /**
85
     *
86
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
87
     * @param \LeadersLinked\Cache\CacheInterface $cache
88
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
1 www 89
     * @param array $config
6866 efrain 90
     * @param \Laminas\Mvc\I18n\Translator $translator
1 www 91
     */
6866 efrain 92
    public function __construct($adapter, $cache, $logger, $config, $translator)
1 www 93
    {
94
        $this->adapter      = $adapter;
6866 efrain 95
        $this->cache        = $cache;
1 www 96
        $this->logger       = $logger;
97
        $this->config       = $config;
6866 efrain 98
        $this->translator   = $translator;
1 www 99
    }
100
 
101
    public function indexAction()
102
    {
4842 efrain 103
        $currentUserPlugin = $this->plugin('currentUserPlugin');
104
        $currentUser = $currentUserPlugin->getUser();
105
 
106
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
107
        $currentNetwork= $currentNetworkPlugin->getNetwork();
108
 
109
 
1 www 110
        $page       = (int) filter_var($this->params()->fromQuery('page'), FILTER_SANITIZE_NUMBER_INT);
6749 efrain 111
        $keyword    = Functions::sanitizeFilterString($this->params()->fromQuery('keyword'));
1 www 112
        $entity     = $this->params()->fromRoute('entity');
6749 efrain 113
        $country    = Functions::sanitizeFilterString($this->params()->fromQuery('country'));
114
        $state      = Functions::sanitizeFilterString($this->params()->fromQuery('state'));
115
        $city1      = Functions::sanitizeFilterString($this->params()->fromQuery('city1'));
116
        $city2      = Functions::sanitizeFilterString($this->params()->fromQuery('city2'));
1 www 117
 
118
 
119
       // echo 'keyword = ' . $keyword .PHP_EOL;
120
        //echo 'entity = ' . $entity . PHP_EOL;
121
 
122
        $request = $this->getRequest();
123
        if($request->isGet()) {
124
 
125
 
126
            $headers  = $request->getHeaders();
127
 
128
            $isJson = false;
129
            if($headers->has('Accept')) {
130
                $accept = $headers->get('Accept');
131
 
132
                $prioritized = $accept->getPrioritized();
133
 
134
                foreach($prioritized as $key => $value) {
135
                    $raw = trim($value->getRaw());
136
 
137
                    if(!$isJson) {
138
                        $isJson = strpos($raw, 'json');
139
                    }
140
 
141
                }
142
            }
143
 
144
 
145
            if($isJson) {
4842 efrain 146
 
1 www 147
 
148
                $userBlockedMapper = UserBlockedMapper::getInstance($this->adapter);
149
                $user_blocked_ids = $userBlockedMapper->fetchAllBlockedReturnIds($currentUser->id);
150
 
151
                switch($entity)
152
                {
153
                    case 'user' :
154
                        $grade1     = intval($this->params()->fromQuery('connection_level_1'), 10);
155
                        $grade2     = intval($this->params()->fromQuery('connection_level_2'), 10);
156
 
157
 
158
 
159
                        $queryMapper = QueryMapper::getInstance($this->adapter);
160
 
161
                        $select = $queryMapper->getSql()->select();
162
                        $select->columns(['id', 'user_uuid' => 'uuid', 'first_name','last_name','image']);
163
                        $select->from(['u' => UserMapper::_TABLE]);
164
                        $select->join(['ue' => UserExperienceMapper::_TABLE], 'u.id = ue.user_id',[ 'industry_id'] , Select::JOIN_LEFT);
165
                        $select->join(['up' => UserProfileMapper::_TABLE], "u.id = up.user_id ", ['user_profile_uuid' => 'uuid', 'user_profile_id' => 'id', 'description'] );
166
                        $select->join(['l' => LocationMapper::_TABLE], "u.location_id = l.id" ,['country', 'state', 'city1', 'city2'], Select::JOIN_LEFT);
3639 efrain 167
                        $select->where->equalTo('u.network_id', $currentUser->network_id);
1 www 168
                        $select->where->equalTo('up.public', UserProfile::PUBLIC_YES);
3639 efrain 169
 
1 www 170
 
171
                        if($country) {
172
                            $select->where->equalTo('country', $country);
173
                        }
174
                        if($state) {
175
                            $select->where->equalTo('state', $state);
176
                        }
177
                        if($city1) {
178
                            $select->where->equalTo('city1', $city1);
179
                        }
180
                        if($city2) {
181
                            $select->where->equalTo('city2', $city2);
182
                        }
183
 
184
                        if($grade1 && $grade2) {
185
                            $connectionMapper = ConnectionMapper::getInstance($this->adapter);
186
                            $first_grade    = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
187
                            if(!$first_grade) {
188
                                array_push($first_grade, 0);
189
                            }
190
 
191
                            $second_grade   = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
192
                            if(!$second_grade) {
193
                                array_push($second_grade, 0);
194
                            }
195
 
196
                            $select->where->nest->in('u.id', $first_grade)->or->in('u.id',$second_grade)->unnest();
197
                        } else {
198
                            if($grade1) {
199
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
200
                                $first_grade    = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
201
                                if(!$first_grade) {
202
                                    array_push($first_grade, 0);
203
                                }
204
 
205
                                $select->where->in('u.id', $first_grade);
206
 
207
                            } else if($grade2) {
208
                                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
209
                                $second_grade   = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
210
                                if(!$second_grade) {
211
                                    array_push($second_grade, 0);
212
                                }
213
 
214
                                $select->where->in('u.id',$second_grade);
215
 
216
                            }
217
                        }
218
                        if($user_blocked_ids) {
219
                            $select->where->notIn('u.id', $user_blocked_ids);
220
                        }
221
 
222
                        $select->where->notEqualTo('u.id', $currentUser->id);
223
                        /*
224
                        $industry_ids = [];
225
 
226
                        $userExperienceMapper = UserExperienceMapper::getInstance($this->adapter);
227
                        $experiences = $userExperienceMapper->fetchAllByUserId($currentUser->id);
228
                        foreach($experiences as $experience)
229
                        {
230
                            if($experience->is_current == UserExperience::IS_CURRENT_YES) {
231
                                if(!in_array($experience->industry_id, $industry_ids)) {
232
                                    array_push($industry_ids, $experience->industry_id);
233
                                }
234
                            }
235
                        }
236
 
237
                        if($industry_ids) {
238
                            $select->where->in('industry_id', $industry_ids);
239
                        }
240
                        */
241
                        $select->where->in('u.usertype_id', [UserType::USER, UserType::ADMIN]);
242
                        $select->where->equalTo('u.status', User::STATUS_ACTIVE);
243
                        $select->where->equalTo('u.show_in_search', User::SHOW_IN_SEARCH_YES);
244
 
245
                        if($keyword) {
246
                            $select->where->NEST->like('u.first_name', '%' . $keyword . '%')->or->like('u.last_name', '%' . $keyword . '%')->UNNEST;
247
                        }
248
                        $select->group('u.id');
249
 
250
                        $select->order(new Expression('rand()'));
251
 
252
                        //echo $select->getSqlString($this->adapter->platform); exit;
253
                        break;
254
 
255
                    case 'company' :
256
 
257
                        $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
258
                        $companySizes = $companySizeMapper->fetchAll();
259
 
260
                        $company_sizes = [];
261
 
262
                        foreach($companySizes as $companySize)
263
                        {
264
 
265
                            $company_size_id = intval($this->params()->fromQuery('company_size_id'. $companySize->uuid), 10);
266
                            if($company_size_id) {
267
                                array_push($company_sizes, $companySize->id);
268
                            }
269
                        }
270
 
271
                        $industryMapper = IndustryMapper::getInstance($this->adapter);
3454 efrain 272
                        $industries = $industryMapper->fetchAllActive();
1 www 273
 
274
                        $industry_ids = [];
275
                        foreach($industries as $industry)
276
                        {
277
                            $industry_id = intval($this->params()->fromQuery('industry_id'. $industry->uuid), 10);
278
                            if($industry_id) {
279
                                if(!in_array($industry_id, $industry_ids)) {
280
                                    array_push($industry_ids, $industry->id);
281
                                }
282
                            }
283
                        }
284
 
285
 
286
                        $queryMapper = QueryMapper::getInstance($this->adapter);
287
                        $select = $queryMapper->getSql()->select();
288
                        $select->columns(['id','company_uuid' => 'uuid', 'name','image', 'description', 'industry_id', 'company_size_id']);
289
                        $select->from(['c' => CompanyMapper::_TABLE]);
290
                        $select->join(['cl' => CompanyLocationMapper::_TABLE], 'c.id = cl.company_id', ['location_id', 'is_main'], Select::JOIN_LEFT);
291
                        $select->join(['l' => LocationMapper::_TABLE], 'cl.location_id = l.id' ,['formatted_address', 'country', 'state', 'city1', 'city2'], Select::JOIN_LEFT);
292
                        $select->join(['cu' => CompanyUserMapper::_TABLE], 'c.id = cu.company_id', ['user_id', 'owner']);
293
                        //$select->where->equalTo('cl.is_main', CompanyLocation::IS_MAIN_YES);
3639 efrain 294
                        $select->where->equalTo('c.network_id', $currentUser->network_id);
1 www 295
                        $select->where->equalTo('cu.owner', CompanyUser::OWNER_YES);
296
                        $select->where->equalTo('c.status', Company::STATUS_ACTIVE);
297
 
298
 
299
 
300
                        if($user_blocked_ids) {
301
                            $select->where->notIn('cu.user_id', $user_blocked_ids);
302
                        }
303
 
304
                        if($industry_ids) {
305
                            $select->where->in('c.industry_id', $industry_ids);
306
                        }
307
 
308
 
309
                        if($company_sizes) {
310
                            $select->where->in('c.company_size_id',$company_sizes);
311
                        }
312
 
313
 
314
                        if($country) {
315
                            $select->where->equalTo('l.country', $country);
316
                        }
317
                        if($state) {
318
                            $select->where->equalTo('l.state', $state);
319
                        }
320
                        if($city1) {
321
                            $select->where->equalTo('l.city1', $city1);
322
                        }
323
                        if($city2) {
324
                            $select->where->equalTo('l.city2', $city2);
325
                        }
326
 
327
                        if($keyword) {
328
                            $select->where->like('c.name', '%' . $keyword . '%');
329
                        }
330
 
331
                        $select->group('c.id');
332
 
333
 
334
                        $select->order(new Expression('rand()'));
335
 
336
                        //echo $select->getSqlString($this->adapter->platform); exit;
337
                        break;
338
 
339
                    case 'group' :
340
 
341
                        $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
3454 efrain 342
                        $groupTypes = $groupTypeMapper->fetchAllActive();
1 www 343
 
344
 
345
                        $group_type_ids = [];
346
                        foreach($groupTypes as $groupType)
347
                        {
348
 
349
                            $group_type_id = intval($this->params()->fromQuery('group_type_id'. $groupType->uuid), 10);
350
                            if($group_type_id) {
351
                                if(!in_array($group_type_id, $group_type_ids)) {
352
                                    array_push($group_type_ids, $groupType->id);
353
                                }
354
                            }
355
                        }
356
 
357
                        $industryMapper = IndustryMapper::getInstance($this->adapter);
3454 efrain 358
                        $industries = $industryMapper->fetchAllActive();
1 www 359
 
360
                        $industry_ids = [];
361
                        foreach($industries as $industry)
362
                        {
363
                            $industry_id = intval($this->params()->fromQuery('industry_id'. $industry->uuid), 10);
364
                            if($industry_id) {
365
                                if(!in_array($industry_id, $industry_ids)) {
366
                                    array_push($industry_ids, $industry->id);
367
                                }
368
                            }
369
                        }
370
 
371
 
372
 
373
 
374
                        $queryMapper = QueryMapper::getInstance($this->adapter);
375
                        $select = $queryMapper->getSql()->select();
376
                        $select->columns(['id', 'group_uuid' => 'uuid',  'name', 'description','image','type_id', 'industry_id', 'user_id' ]);
377
                        $select->from(['g' => GroupMapper::_TABLE]);
3639 efrain 378
                        $select->where->equalTo('g.network_id', $currentUser->network_id);
1 www 379
 
380
                        if($group_type_ids) {
381
                            $select->where->in('type_id', $group_type_ids);
382
                        }
383
 
384
                        if($industry_ids) {
385
                            $select->where->in('industry_id', $industry_ids);
386
                        }
387
 
388
                        if($keyword) {
389
                            $select->where->like('name', '%' . $keyword . '%');
390
                        }
391
 
392
                        if($user_blocked_ids) {
393
                            $select->where->notIn('user_id', $user_blocked_ids);
394
                        }
395
                        $select->where->equalTo('status', Group::STATUS_ACTIVE);
396
                        $select->where->equalTo('privacy', Group::PRIVACY_IS_PUBLIC);
397
 
398
                        $select->group('g.id');
399
                        $select->order(new Expression('rand()'));
400
 
401
                        //echo $select->getSqlString($this->adapter->platform); exit;
402
 
403
                        break;
404
 
405
                    case 'job' :
406
                        $jobFullTime    = intval($this->params()->fromQuery('employment_type_id' . Job::EMPLOYMENT_TYPE_FULL_TIME), 10);
407
                        $jobPartTime    = intval($this->params()->fromQuery('employment_type_id' . Job::EMPLOYMENT_TYPE_PART_TIME), 10);
408
                        $jobContract    = intval($this->params()->fromQuery('employment_type_id' . Job::EMPLOYMENT_TYPE_CONTRACT), 10);
409
                        $jobTemporary   = intval($this->params()->fromQuery('employment_type_id' . Job::EMPLOYMENT_TYPE_TEMPORARY ), 10);
410
 
411
                        $employment_types = [];
412
                        if($jobFullTime) {
413
                            array_push($employment_types, Job::EMPLOYMENT_TYPE_FULL_TIME);
414
                        }
415
                        if($jobPartTime) {
416
                            array_push($employment_types, Job::EMPLOYMENT_TYPE_PART_TIME);
417
                        }
418
                        if($jobContract) {
419
                            array_push($employment_types, Job::EMPLOYMENT_TYPE_CONTRACT);
420
                        }
421
                        if($jobTemporary) {
422
                            array_push($employment_types, Job::EMPLOYMENT_TYPE_TEMPORARY);
423
                        }
424
 
425
                        $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
426
                        $companySizes = $companySizeMapper->fetchAll();
427
 
428
                        $company_sizes = [];
429
 
430
                        foreach($companySizes as $companySize)
431
                        {
432
 
433
                            $company_size_id = intval($this->params()->fromQuery('company_size_id'. $companySize->uuid), 10);
434
                            if($company_size_id) {
435
                                array_push($company_sizes, $companySize->id);
436
                            }
437
                        }
438
 
439
                        $industryMapper = IndustryMapper::getInstance($this->adapter);
3454 efrain 440
                        $industries = $industryMapper->fetchAllActive();
1 www 441
 
442
                        $industry_ids = [];
443
                        foreach($industries as $industry)
444
                        {
445
                            $industry_id = intval($this->params()->fromQuery('industry_id'. $industry->uuid), 10);
446
                            if($industry_id) {
447
                                if(!in_array($industry_id, $industry_ids)) {
448
                                    array_push($industry_ids, $industry->id);
449
                                }
450
                            }
451
                        }
452
 
453
                        $queryMapper = QueryMapper::getInstance($this->adapter);
454
                        $select = $queryMapper->getSql()->select();
455
                        $select->columns(['id', 'job_uuid' => 'uuid', 'company_id','title','description','employment_type','location_id','last_date_of_application','experience_visible','experience_min','experience_max']);
456
                        $select->from(['j' => JobMapper::_TABLE]);
457
                        $select->join(['c' => CompanyMapper::_TABLE] , 'c.id = j.company_id', ['company_uuid' => 'uuid', 'company_name' => 'name', 'image', 'industry_id', 'company_size_id']);
458
                        $select->join(['l' => LocationMapper::_TABLE], 'j.location_id = l.id' ,['formatted_address', 'country', 'state', 'city1', 'city2'] );
459
                        $select->join(['cu' => CompanyUserMapper::_TABLE], 'c.id = cu.company_id', ['user_id', 'owner']);
3639 efrain 460
                        $select->where->equalTo('j.network_id', $currentUser->network_id);
1 www 461
                        $select->where->equalTo('cu.owner', CompanyUser::OWNER_YES);
462
                        $select->where->equalTo('c.status', Company::STATUS_ACTIVE);
463
 
464
                        if($user_blocked_ids) {
465
                            $select->where->notIn('cu.user_id', $user_blocked_ids);
466
                        }
467
 
468
                        if($employment_types) {
469
                            $select->where->in('employment_type', $employment_types);
470
                        }
471
 
472
                        if($industry_ids) {
473
                            $select->where->in('industry_id', $industry_ids);
474
                        }
475
 
476
                        if($company_sizes) {
477
                            $select->where->in('c.company_size_id',$company_sizes);
478
                        }
479
 
480
                        if($country) {
481
                            $select->where->equalTo('country', $country);
482
                        }
483
                        if($state) {
484
                            $select->where->equalTo('state', $state);
485
                        }
486
                        if($city1) {
487
                            $select->where->equalTo('city1', $city1);
488
                        }
489
                        if($city2) {
490
                            $select->where->equalTo('city2', $city2);
491
                        }
492
 
493
                        if($keyword) {
494
                            $select->where->like('title', '%' . $keyword . '%');
495
                        }
496
 
497
                        $select->where->equalTo('c.status', Company::STATUS_ACTIVE);
498
                        $select->where->equalTo('j.status', Job::STATUS_ACTIVE);
499
                        $select->where->greaterThanOrEqualTo('last_date_of_application', new Expression('DATE(NOW())'));
500
 
501
                        $select->group('j.id');
502
                        $select->order(new Expression('rand()'));
503
 
504
                        break;
505
                }
506
 
507
                //echo $select->getSqlString($this->adapter->platform); exit;
508
 
509
                $dbSelect = new DbSelect($select, $this->adapter);
510
                $paginator = new Paginator($dbSelect);
511
                $paginator->setCurrentPageNumber($page ? $page : 1);
512
                $paginator->setItemCountPerPage(10);
513
 
514
                $companyFollowerMapper = CompanyFollowerMapper::getInstance($this->adapter);
515
                $connectionMapper = ConnectionMapper::getInstance($this->adapter);
516
                $industryMapper = IndustryMapper::getInstance($this->adapter);
517
                $jobApplicationMapper = JobApplicationMapper::getInstance($this->adapter);
518
                $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
519
                $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
520
                $profileVisitMapper = ProfileVisitMapper::getInstance($this->adapter);
521
                $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
522
 
523
                $months = [
524
                    1 => 'LABEL_MONTH_JANUARY',
525
                    2 => 'LABEL_MONTH_FEBRUARY',
526
                    3 => 'LABEL_MONTH_MARCH',
527
                    4 => 'LABEL_MONTH_APRIL',
528
                    5 => 'LABEL_MONTH_MAY',
529
                    6 => 'LABEL_MONTH_JUNE',
530
                    7 => 'LABEL_MONTH_JULY',
531
                    8 => 'LABEL_MONTH_AUGUST',
532
                    9 => 'LABEL_MONTH_SEPTEMBER',
533
                    10 => 'LABEL_MONTH_OCTOBER',
534
                    11 => 'LABEL_MONTH_NOVEMBER',
535
                    12 => 'LABEL_MONTH_DECEMBER',
536
                ];
537
 
538
                $employmentTypes = [
539
                    Job::EMPLOYMENT_TYPE_FULL_TIME => 'LABEL_EMPLOYMENT_TYPE_FULL_TIME',
540
                    Job::EMPLOYMENT_TYPE_PART_TIME => 'LABEL_EMPLOYMENT_TYPE_PART_TIME',
541
                    Job::EMPLOYMENT_TYPE_CONTRACT => 'LABEL_EMPLOYMENT_TYPE_CONTRACT',
542
                    Job::EMPLOYMENT_TYPE_TEMPORARY => 'LABEL_EMPLOYMENT_TYPE_TEMPORARY'
543
                ];
544
 
545
 
546
 
547
 
548
                $items = [];
549
                $records = $paginator->getCurrentItems();
550
                foreach($records as $record)
551
                {
552
                    switch($entity)
553
                    {
554
                        case 'user' :
555
 
556
                            $skills = [];
557
                            if($record['user_profile_id']) {
558
                                $skillMapper = SkillMapper::getInstance($this->adapter);
559
 
560
                                $userSkillMapper = UserSkillMapper::getInstance($this->adapter);
561
                                $userSkillRecords = $userSkillMapper->fetchAllByUserProfileId($record['user_profile_id']);
562
 
563
 
564
                                foreach($userSkillRecords as $userSkillRecord)
565
                                {
566
                                    $skill = $skillMapper->fetchOne($userSkillRecord->skill_id);
567
                                    $skills[$skill->uuid] = $skill->name;
568
                                }
569
 
570
                            }
571
 
572
                            $industry       = $record['industry_id'] ? $industryMapper->fetchOne($record['industry_id']) : '';
573
                            $views          = $profileVisitMapper->getTotalByVisitedId($record['id']);
574
 
4842 efrain 575
 
1 www 576
                            $item = [
577
                                'id' => $record['user_uuid'],
578
                                'id_encripted' => $record['user_uuid'],
579
                                'name' => $record['first_name'] . ' ' . $record['last_name'],
580
                                'description' => $record['description'],
581
                                'image' => $this->url()->fromRoute('storage',['type' => 'user', 'code' =>  $record['user_uuid'], 'filename' => $record['image']]),
582
                                'url' => $this->url()->fromRoute('profile/view',['id' => $record['user_uuid'] ]),
583
                                'industry' => $industry? $industry->name : '',
584
                                'skills' => $skills ? $skills : [],
4842 efrain 585
 
1 www 586
                                'views' => $views
587
                            ];
4842 efrain 588
 
589
                            if($currentNetwork->relationship_user_mode == Network::RELATIONSHIP_USER_MODE_USER_2_USER)  {
590
                                $common_connection = count($connectionMapper->fetchAllCommonConnectionsUserIdByUser1ReturnIds($currentUser->id, $record['id']));
591
 
592
                                $item['common_connection'] = $common_connection;
593
                                $item['view_common_connection'] = 1;
594
                            } else {
595
                                $item['common_connection'] = 0;
596
                                $item['view_common_connection'] = 0;
597
                            }
598
 
599
 
1 www 600
                            array_push($items, $item);
601
 
602
                            break;
603
 
604
                        case 'company' :
605
                            $industry       = $industryMapper->fetchOne($record['industry_id']);
606
                            $companySize    = $companySizeMapper->fetchOne($record['company_size_id']);
607
                            $followers      = $companyFollowerMapper->getCountFollowers($record['id']);
608
 
609
                            $item = [
610
                                'id' => $record['id'],
611
                                'id_encripted' => $record['company_uuid'],
612
                                'name' => $record['name'],
613
                                'description' => $record['description'],
614
                                'image' => $this->url()->fromRoute('storage',['type' => 'company', 'code' => $record['company_uuid'] , 'filename' => $record['image']]),
615
                                'url' => $this->url()->fromRoute('company/view',['id' => $record['company_uuid'] ]),
616
                                'industry' => $industry->name,
617
                                'company_size' => $companySize->name,
618
                                'location' => $record['formatted_address'],
619
                                'followers' => $followers,
620
                            ];
621
                            array_push($items, $item);
622
 
623
                            break;
624
 
625
                        case 'job' :
626
 
627
 
628
                            $employment_type = $employmentTypes[ $record['employment_type'] ];
629
 
630
 
631
                            $industry           = $industryMapper->fetchOne($record['industry_id']);
632
                            $companySize        = $companySizeMapper->fetchOne($record['company_size_id']);
633
                            $total_applications = $jobApplicationMapper->fetchTotalApplicationsByJobId($record['id']);
634
 
635
 
636
 
637
                            $followers      = $companyFollowerMapper->getCountFollowers($record['id']);
638
 
639
                            if($record['experience_visible'] == Job::EXPERIENCE_VISIBLE_YES) {
640
                                $experience = $record['experience_min'].'-'.$record['experience_max'] . ' LABEL_YEARS';
641
                            } else {
642
                                $experience = '';
643
                            }
644
 
645
                            $dt = \DateTime::createFromFormat('Y-m-d', $record['last_date_of_application']);
646
 
647
 
648
                            $dt = \DateTime::createFromFormat('Y-m-d', $record['last_date_of_application']);
649
                            $last_date_of_application = $dt->format('d') . ' de ' . $months[$dt->format('n')] . ' de ' . $dt->format('Y');
650
 
651
                            $item = [
652
                                'id' => $record['id'],
653
                                'id_encripted' => $record['job_uuid'],
654
                                'title' => $record['title'],
655
                                'description' => $record['description'],
656
                                'image' => $this->url()->fromRoute('storage',['type' => 'company', 'code' => $record['company_uuid'], 'filename' => $record['image']]),
657
                                'url' => $this->url()->fromRoute('job/view',['id' => $record['job_uuid']]),
658
                                'company_name' => $record['company_name'],
659
                                'company_url' => $this->url()->fromRoute('company/view',['id' => $record['company_uuid'] ]),
660
                                'industry' => $industry->name,
661
                                'company_size' => $companySize->name,
662
                                'employment_type' => $employment_type,
663
                                'location' => $record['formatted_address'],
664
                                'total_applications' => $total_applications,
665
                                'experience' => $experience,
666
                                'last_date' => $last_date_of_application
667
                            ];
668
                            array_push($items, $item);
669
 
670
                            break;
671
 
672
                        case 'group' :
673
 
674
 
675
                            $groupType      = $groupTypeMapper->fetchOne($record['type_id']);
676
                            $industry       = $industryMapper->fetchOne($record['industry_id']);
677
 
678
                            $total_members  = $groupMemberMapper->fetchTotalAcceptedByGroupId($record['id']);
679
 
680
                            $members      = $groupMemberMapper->fetchAllAcceptedUserIdsByGroupId($record['id']);
681
                            $connections  = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
682
                            $common_connection = count(array_intersect($members, $connections));
683
 
684
                            $item = [
685
                                'id' => $record['id'],
686
                                'id_encripted' => $record['group_uuid'],
687
                                'name' => $record['name'],
688
                                'description' => $record['description'],
689
                                'image' => $this->url()->fromRoute('storage',['type' => 'group', 'code' => $record['group_uuid'], 'filename' => $record['image']]),
690
                                'url' => $this->url()->fromRoute('group/view',['id' => $record['group_uuid']]),
691
                                'industry' => $industry->name,
692
                                'group_type' => $groupType->name,
693
                                'total_members' => $total_members,
694
                                'common_connection' => $common_connection,
695
 
696
                            ];
697
                            array_push($items, $item);
698
 
699
                            break;
700
                    }
701
                }
702
 
703
                $response = [
704
                    'success' => true,
705
 
706
                    'data' => [
707
                        'entity' => $entity,
708
                        'total' => [
709
                            'count' => $paginator->getTotalItemCount(),
710
                            'pages' => $paginator->getPages()->pageCount,
711
                        ],
712
                        'current' => [
713
                            'items'    => $items,
714
                            'page'     => $paginator->getCurrentPageNumber(),
715
                            'count'    => $paginator->getCurrentItemCount(),
716
                        ]
717
                    ]
718
                ];
719
 
720
 
721
 
722
                return new JsonModel($response);
723
            } else {
724
 
725
                $sandbox = $this->config['leaderslinked.runmode.sandbox'];
726
                if($sandbox) {
727
                    $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
728
                } else {
729
                    $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
730
                }
731
 
732
                $groupTypes = [];
733
                $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
3454 efrain 734
                $records = $groupTypeMapper->fetchAllActive();
1 www 735
                foreach($records as $record)
736
                {
737
                    $groupTypes[$record->uuid] = $record->name;
738
                }
739
 
740
 
741
                $industries = [];
742
                $industryMapper = IndustryMapper::getInstance($this->adapter);
3454 efrain 743
                $records = $industryMapper->fetchAllActive();
1 www 744
                foreach($records as $record)
745
                {
746
                    $industries[$record->uuid] = $record->name;
747
                }
748
 
749
                $companySizes = [];
750
                $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
3454 efrain 751
                $records = $companySizeMapper->fetchAllActive();
1 www 752
                foreach($records as $record)
753
                {
754
                    $companySizes[$record->uuid] = $record->name . ' ('.$record->minimum_no_of_employee . '-' . $record->maximum_no_of_employee .')';
755
                }
756
 
757
 
758
                $employmentTypes = [
759
                    Job::EMPLOYMENT_TYPE_FULL_TIME => 'LABEL_EMPLOYMENT_TYPE_FULL_TIME',
760
                    Job::EMPLOYMENT_TYPE_PART_TIME => 'LABEL_EMPLOYMENT_TYPE_PART_TIME',
761
                    Job::EMPLOYMENT_TYPE_CONTRACT => 'LABEL_EMPLOYMENT_TYPE_CONTRACT',
762
                    Job::EMPLOYMENT_TYPE_TEMPORARY => 'LABEL_EMPLOYMENT_TYPE_TEMPORARY'
763
                ];
764
 
765
                $connectionLeves = [
766
                    1 => 'LABEL_FIRST_GRADE',
767
                    2 => 'LABEL_SECOND_GRADE'
768
                ];
769
 
770
                $viewModel = new ViewModel();
771
                $this->layout()->setTemplate('layout/layout.phtml');
772
                $viewModel->setTemplate('leaders-linked/search/index.phtml');
773
                $viewModel->setVariables([
774
                    'groupTypes' => $groupTypes,
775
                    'industries' => $industries,
776
                    'companySizes' => $companySizes,
777
                    'employeeTypes' => $employmentTypes,
778
                    'connectionLeves' =>  $connectionLeves,
779
                    'keyword' => $keyword,
780
                    'google_map_key' => $google_map_key,
781
 
782
                ]);
783
 
784
                return $viewModel;
785
            }
786
        }
787
 
788
        return new JsonModel([
789
            'success' => false,
790
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
791
        ]);
792
 
793
 
794
 
795
 
796
    }
797
 
798
 
799
}