Completed
Push — master ( 735cac...641d44 )
by Jean-Christophe
04:20
created

SearchCategory::setId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Ajax\semantic\components\search;
4
5
class SearchCategory implements ISearch {
6
	private $id;
7
	private $name;
8
	private $results;
9
10
	public function __construct($id, $name, $results=NULL) {
11
		$this->results=new SearchResults($results);
12
		$this->id=$id;
13
		$this->name=$name;
14
	}
15
16
	public function addResult($object) {
17
		$this->results->addResult($object);
18
		return $this;
19
	}
20
21
	public function addResults($objects) {
22
		$this->results->addResults($objects);
23
		return $this;
24
	}
25
26
	public function __toString() {
27
		$result="\"" . $this->id . "\": { \"name\": \"" . $this->name . "\"," . $this->results . "}";
28
		return $result;
29
	}
30
31
	public function getId() {
32
		return $this->id;
33
	}
34
35
	public function setId($id) {
36
		$this->id=$id;
37
		return $this;
38
	}
39
40
	public function getName() {
41
		return $this->name;
42
	}
43
44
	public function setName($name) {
45
		$this->name=$name;
46
		return $this;
47
	}
48
49
	public function getResults() {
50
		return $this->results;
51
	}
52
53
	public function setResults($results) {
54
		$this->results=$results;
55
		return $this;
56
	}
57
58
	public function search($query, $field="title") {
59
		$result=$this->results->search($query, $field);
60
		if ($result !== false) {
61
			return new SearchCategory($this->id, $this->name, $result);
62
		}
63
		return false;
64
	}
65
66
	public function getResponse() {
67
		return $this->__toString();
68
	}
69
}