checkParams($params, array( // 'tags' => "Muzich\CoreBundle\Searcher\ElementSearch::init(): \$params: Au moins un tag est nécéssaire" // )); // Mise a jour des attributs $this->setAttributes($params); } /** * @see SearcherInterface * @param array $params */ public function update($params) { // Mise a jour des attributs $this->setAttributes($params); } /** * @see SearcherInterface * * @return array */ public function getParams($tags_string = false) { return array( 'network' => $this->getNetwork(), 'tags' => $this->getTags($tags_string), 'count' => $this->getCount(), 'user_id' => $this->getUserId(), 'group_id' => $this->getGroupId(), 'favorite' => $this->isFavorite(), 'ids' => $this->getIds(), 'ids_display' => $this->getIdsDisplay(), 'tag_strict' => $this->getTagStrict(), 'need_tags' => $this->getNeedTags(), 'string' => $this->getString() ); } public function getNetwork() { return $this->network; } public function isNetworkPublic() { if ($this->network == self::NETWORK_PUBLIC) { return true; } return false; } public function isNetworkPersonal() { if ($this->network == self::NETWORK_PERSONAL) { return true; } return false; } public function setNoTags() { $this->tags = array(); } public function getTags($tags_string = false) { if (!$tags_string) { return $this->tags; } $ids = array(); foreach ($this->tags as $id => $name) { $ids[] = $id; } return json_encode($ids); } public function getCount() { return $this->count; } public function getUserId() { return $this->user_id; } public function getIdLimit() { return $this->id_limit; } public function getGroupId() { return $this->group_id; } public function isFavorite() { return $this->favorite; } public function setIds($ids) { $this->ids = $ids; } public function getIds() { return $this->ids; } public function hasIds() { if (count($this->ids)) { return true; } return false; } public function setIdsDisplay($display) { $this->ids_display = $display; } public function getIdsDisplay() { return $this->ids_display; } public function setTagStrict($strict) { $this->tag_strict = $strict; } public function getTagStrict() { return $this->tag_strict; } public function getNeedTags() { return ($this->need_tags); } public function setString($string) { $this->string = $string; } public function getString() { return $this->string; } /** * Construction de l'objet Query * * @param Registry $doctrine * @param int $user_id * @param string $exec_type * * @return collection */ protected function constructQueryObject(Registry $doctrine, $user_id, $exec_type = 'execute', $params = array()) { $this->setQuery($doctrine ->getRepository('MuzichCoreBundle:Element') ->findBySearch($this, $user_id, $exec_type, $params)) ; } /** * Retourne l'objet Query * * @param Registry $doctrine * @param int $user_id * @param string $exec_type * * @return collection */ public function getQuery(Registry $doctrine, $user_id, $exec_type = 'execute', $params = array()) { $this->constructQueryObject($doctrine, $user_id, $exec_type, $params); return $this->query; } /** * Retourne les elements correspondant a la recherche * user_id: Identifiant de celui qui navigue * * @param Registry $doctrine * @param int $user_id * @param string $exec_type Type d'execution * * @return collection */ public function getElements(Registry $doctrine, $user_id, $exec_type = 'execute', $params = array()) { $query = $this->getQuery($doctrine, $user_id, $exec_type, $params); switch ($exec_type) { case 'execute': return $query->execute(); break; case 'count': return count($query->getArrayResult()); break; case 'single': return $query->getSingleResult(); break; default : throw new \Exception('Mode de récupération des Elements non supporté.'); break; } } public function isSearchingNew() { return $this->searchnew; } public function isNeedTags() { if ($this->need_tags) { return true; } return false; } public function setNetwork($network) { if (!in_array($network, array(self::NETWORK_PERSONAL, self::NETWORK_PUBLIC))) { throw new \Exception("Wrong network set"); } $this->network = $network; } }