Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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