Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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