|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\semantic\components\search; |
|
4
|
|
|
|
|
5
|
|
|
class SearchResult implements \JsonSerializable { |
|
6
|
|
|
private $id; |
|
7
|
|
|
private $title; |
|
8
|
|
|
private $description; |
|
9
|
|
|
private $image; |
|
10
|
|
|
private $price; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct($id=NULL, $title=NULL, $description=NULL, $image=NULL, $price=NULL) { |
|
13
|
|
|
if (\is_array($id)) { |
|
14
|
|
|
$this->fromArray($id); |
|
15
|
|
|
} else { |
|
16
|
|
|
$this->id=$id; |
|
17
|
|
|
$this->title=$title; |
|
18
|
|
|
$this->description=$description; |
|
19
|
|
|
$this->image=$image; |
|
20
|
|
|
$this->price=$price; |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getId() { |
|
25
|
|
|
return $this->id; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function setId($id) { |
|
29
|
|
|
$this->id=$id; |
|
30
|
|
|
return $this; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getTitle() { |
|
34
|
|
|
return $this->title; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function setTitle($title) { |
|
38
|
|
|
$this->title=$title; |
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getDescription() { |
|
43
|
|
|
return $this->description; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function setDescription($description) { |
|
47
|
|
|
$this->description=$description; |
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getImage() { |
|
52
|
|
|
return $this->image; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function setImage($image) { |
|
56
|
|
|
$this->image=$image; |
|
57
|
|
|
return $this; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getPrice() { |
|
61
|
|
|
return $this->price; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function setPrice($price) { |
|
65
|
|
|
$this->price=$price; |
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function fromArray($array) { |
|
70
|
|
|
foreach ( $array as $key => $value ) { |
|
71
|
|
|
$this->{$key}=$value; |
|
72
|
|
|
} |
|
73
|
|
|
return $this; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function asArray() { |
|
77
|
|
|
return $this->JsonSerialize(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function JsonSerialize() { |
|
81
|
|
|
$vars=get_object_vars($this); |
|
82
|
|
|
$result=array (); |
|
83
|
|
|
foreach ( $vars as $k => $v ) { |
|
84
|
|
|
if (isset($v)) |
|
85
|
|
|
$result[$k]=$v; |
|
86
|
|
|
} |
|
87
|
|
|
return $result; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function search($query, $field="title") { |
|
91
|
|
|
$value=$this->$field; |
|
92
|
|
|
return \stripos($value, $query) !== false; |
|
93
|
|
|
} |
|
94
|
|
|
} |