phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
SearchCategories.php
Go to the documentation of this file.
1 <?php
2 
4 
6  private $categories;
7 
8  public function __construct() {
9  $this->categories=array ();
10  }
11 
12  public function add($results, $category) {
13  $count=\sizeof($this->categories);
14  if (\array_key_exists($category, $this->categories)) {
15  $this->categories[$category]->addResults($results);
16  } else {
17  $categoryO=new SearchCategory("category" . $count, $category, $results);
18  $this->categories[$category]=$categoryO;
19  }
20  return $this;
21  }
22 
23  public function search($query, $field="title") {
24  $result=array ();
25  foreach ( $this->categories as $category ) {
26  $r=$category->search($query, $field);
27  if ($r !== false)
28  $result[]=$r;
29  }
30  $this->categories=$result;
31  return $this;
32  }
33 
34  public function __toString() {
35  return "{\"results\":{" . \implode(",", \array_values($this->categories)) . "}}";
36  }
37 
38  public function getResponse() {
39  return $this->__toString();
40  }
41 
47  public function fromDatabaseObjects($objects, $function) {
48  parent::fromDatabaseObjects($objects, $function);
49  }
50 
51  protected function fromDatabaseObject($object, $function) {
52  $result=$function($object);
53  if ($result instanceof SearchCategory) {
54  $this->categories[]=$result;
55  }
56  }
57 }
fromDatabaseObjects($objects, $function)
Loads results and categories from a collection of DB objects.