1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* YAWIK |
4
|
|
|
* |
5
|
|
|
* @filesource |
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
7
|
|
|
* @license MIT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Solr\Filter; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Jobs\Entity\Location; |
14
|
|
|
use Jobs\Entity\Job; |
15
|
|
|
use Organizations\Entity\Organization; |
16
|
|
|
use Organizations\Entity\OrganizationImage; |
17
|
|
|
use Organizations\Entity\OrganizationName; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class JobBoardPaginationQuery |
21
|
|
|
* |
22
|
|
|
* @author Anthonius Munthi <[email protected]> |
23
|
|
|
* @since 0.27 |
24
|
|
|
* @package Solr\Filter |
25
|
|
|
*/ |
26
|
|
|
class JobBoardPaginationQuery extends AbstractPaginationQuery |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $sortPropertiesMap = [ |
32
|
|
|
'company' => 'companyName', |
33
|
|
|
'date' => 'dateCreated', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
protected $propertiesMap = [ |
37
|
|
|
'organizationName' => 'convertOrganizationName', |
38
|
|
|
'companyLogo' => 'convertCompanyLogo', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
public function createQuery(array $params, $query) |
45
|
|
|
{ |
46
|
|
|
$search = isset($params['search']) ? $params['search']:''; |
47
|
|
|
|
48
|
|
|
if(!empty($search)){ |
49
|
|
|
$q = 'title:'.$search.' OR organizationName:'.$search; |
50
|
|
|
}else{ |
51
|
|
|
$q = '*:*'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$query->setQuery($q); |
55
|
|
|
|
56
|
|
|
if(isset($params['sort'])){ |
57
|
|
|
$sorts = $this->filterSort($params['sort']); |
58
|
|
|
foreach($sorts as $field=>$order){ |
59
|
|
|
$query->addSortField($field,$order); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if(isset($params['location'])){ |
64
|
|
|
/* @var Location $location */ |
65
|
|
|
$location = $params['location']; |
66
|
|
|
if(!is_null($location->getCoordinates())){ |
67
|
|
|
$coordinates = $location->getCoordinates()->getCoordinates(); |
|
|
|
|
68
|
|
|
$query->addFilterQuery(sprintf( |
69
|
|
|
"{!geofilt pt=%s sfield=latLon d=%s}", |
70
|
|
|
doubleval($coordinates[0]).','.doubleval($coordinates[1]), |
71
|
|
|
$params['d'] |
72
|
|
|
)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $query; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritdoc |
81
|
|
|
*/ |
82
|
|
|
public function getEntityClass() |
83
|
|
|
{ |
84
|
|
|
return Job::class; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Convert organizationName result |
89
|
|
|
* @param Job $ob |
90
|
|
|
* @param string $value |
91
|
|
|
*/ |
92
|
|
|
public function convertOrganizationName($ob,$value) |
93
|
|
|
{ |
94
|
|
|
if(!is_object($ob->getOrganization())){ |
95
|
|
|
$ob->setOrganization(new Organization()); |
96
|
|
|
} |
97
|
|
|
$orgName = new OrganizationName($value); |
98
|
|
|
$ob->getOrganization()->setOrganizationName($orgName); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Convert companyLogo result |
103
|
|
|
* @param Job $ob |
104
|
|
|
* @param mixed $value |
105
|
|
|
*/ |
106
|
|
|
public function convertCompanyLogo($ob,$value) |
107
|
|
|
{ |
108
|
|
|
if(!is_object($ob->getOrganization())){ |
109
|
|
|
$ob->setOrganization(new Organization()); |
110
|
|
|
} |
111
|
|
|
$exp = explode('/',$value); |
112
|
|
|
$id = $exp[3]; |
113
|
|
|
$name = $exp[4]; |
114
|
|
|
$image = new OrganizationImage(); |
115
|
|
|
$image->setId($id); |
116
|
|
|
$image->setName($name); |
117
|
|
|
$ob->getOrganization()->setImage($image); |
118
|
|
|
} |
119
|
|
|
} |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: