1 |
www |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Helper;
|
|
|
6 |
|
|
|
7 |
use Laminas\View\Helper\AbstractHelper;
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
9 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
10 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
11 |
use LeadersLinked\Mapper\CompanyLocationMapper;
|
|
|
12 |
use LeadersLinked\Mapper\LocationMapper;
|
|
|
13 |
use LeadersLinked\Model\Company;
|
|
|
14 |
|
|
|
15 |
class CompanySuggestionHelper extends AbstractHelper
|
|
|
16 |
{
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
*
|
|
|
20 |
* @var AdapterInterface
|
|
|
21 |
*/
|
|
|
22 |
private $adapter;
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
*
|
|
|
27 |
* @param AdapterInterface $adapter
|
|
|
28 |
*/
|
|
|
29 |
public function __construct($adapter)
|
|
|
30 |
{
|
|
|
31 |
$this->adapter = $adapter;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function __invoke($company_id)
|
|
|
35 |
{
|
|
|
36 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
37 |
$company = $companyMapper->fetchOne($company_id);
|
|
|
38 |
|
|
|
39 |
$items = [];
|
|
|
40 |
if($company) {
|
|
|
41 |
$location = null;
|
|
|
42 |
|
|
|
43 |
$companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
|
|
|
44 |
$companyLocation = $companyLocationMapper->fetchOneMainLocationByCompanyId($company->id);
|
|
|
45 |
|
|
|
46 |
if($companyLocation) {
|
|
|
47 |
$locationMapper = LocationMapper::getInstance($this->adapter);
|
|
|
48 |
$location = $locationMapper->fetchOne($companyLocation->location_id);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
$mapper = QueryMapper::getInstance($this->adapter);
|
|
|
52 |
$select = $mapper->getSql()->select();
|
|
|
53 |
$select->columns(['id', 'name', 'image']);
|
|
|
54 |
$select->from(['c' => CompanyMapper::_TABLE]);
|
|
|
55 |
$select->join(['cl' => CompanyLocationMapper::_TABLE], 'cl.company_id = c.id', []);
|
|
|
56 |
$select->join(['l' => LocationMapper::_TABLE], 'l.id = cl.location_id', ['state','country']);
|
|
|
57 |
$select->where->equalTo('company_size_id', $company->company_size_id);
|
|
|
58 |
$select->where->equalTo('industry_id', $company->industry_id);
|
|
|
59 |
$select->where->equalTo('state', $location ? $location->state : '');
|
|
|
60 |
$select->where->equalTo('country', $location ? $location->country : '');
|
|
|
61 |
$select->where->equalTo('c.status', Company::STATUS_ACTIVE);
|
|
|
62 |
$select->where->notEqualTo('c.id', $company->id);
|
|
|
63 |
$select->limit(20);
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
$items = $mapper->fetchAll($select);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
$items = $mapper->fetchAll($select);
|
|
|
71 |
return $this->getView()->render('helpers/company-suggestions.phtml', ['items' => $items]);
|
|
|
72 |
}
|
|
|
73 |
}
|