@ 2014-08-19T11:08:37Z <?php
class ProfileRepository extends EntityRepository{
public function getProfilesExperimental($searchString, $isMapSearch = false){
$searchString = strtolower($searchString);
$em = $this->getEntityManager();
$cit = $em->getRepository('LunnarBundle:City')->findAll();
$cat = $em->getRepository('LunnarBundle:Profilecategory')->findAll();
$bra = $em->getRepository('LunnarBundle:Brand')->findAll();
$cities = array();
$profilecategories = array();
$brands = array();
foreach($cit as $city){
array_push($cities, strtolower($city->getName()));
}
foreach($cat as $category){
array_push($profilecategories, strtolower($category->getName()));
}
foreach($bra as $brand){
array_push($brands, strtolower($brand->getName()));
}
$parameters = array();
//'var' => '%'.$searchString.'%',
$searchQuerySelectJoin = "SELECT p FROM LunnarBundle:Profile p LEFT JOIN p.divisions d ";
$searchQueryWhere = "";
//////////////////////////
$searchStringArray = explode(" ", $searchString);
// Remove í, á and við
$removeWords = array('í','á','við');
//Find city, category, brand and save for later, and remove them from $searchStringArray
$searchStringArray = array_diff($searchStringArray, $removeWords);
$city = array_intersect($searchStringArray, $cities);
$searchStringArray = array_diff($searchStringArray, $city);
$category = array_intersect($searchStringArray, $profilecategories);
$searchStringArray = array_diff($searchStringArray, $category);
$brand = array_intersect($searchStringArray, $brands);
$searchStringArray = array_diff($searchStringArray, $brand);
//// PRINTS
print_r($searchStringArray);
echo '<br/>';
//print_r($city);
//print_r($profilecategory);
//print_r($brand);
$first = true;
$searchTerms = " ";
if (sizeof($searchStringArray)>0){
$searchTerms = current($searchStringArray);
$parameters['var'] = "%".$searchTerms."%";
$searchQueryWhere = "WHERE ( p.name LIKE :var ".$searchQueryWhere;
$first = false;
} elseif (sizeof($searchStringArray)==0){
$searchQueryWhere = " WHERE ( ".$searchQueryWhere;
}
if ($category){
$parameters['category'] = $category;
$searchQuerySelectJoin .= " LEFT JOIN p.profilecategory pc ";
if (!$first){
$searchQueryWhere .= " AND pc.name = :category ";
}else {
$first = false;
$searchQueryWhere .= " pc.name = :category ";
}
}
if ($brand){
$parameters['brand'] = $brand;
$searchQuerySelectJoin .= " LEFT JOIN p.brand b ";
if (!$first){
$searchQueryWhere .= " AND b.name = :brand ";
}else {
$first = false;
$searchQueryWhere .= " b.name = :brand ";
}
}
if ($city){
$parameters['city'] = $city;
$searchQuerySelectJoin .= " LEFT JOIN d.city c ";
if (!$first){
$searchQueryWhere .= " AND c.name = :city ";
}else {
$first = false;
$searchQueryWhere .= " c.name = :city ";
}
}
//////////////////////////
if($isMapSearch == true){
$searchQuery .= "AND d.latitude IS NOT NULL ";
}
$searchQuery = $searchQuerySelectJoin.$searchQueryWhere." ) ORDER BY p.name ASC";
echo $searchQuery;
$query = $this->getEntityManager()
->createQuery(
$searchQuery
)->setParameters($parameters);
return $query->getResult();
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught Error: Class "EntityRepository" not found in /in/IUQt1:3
Stack trace:
#0 {main}
thrown in /in/IUQt1 on line 3
Process exited with code 255 . Output for 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 Fatal error: Uncaught Error: Class 'EntityRepository' not found in /in/IUQt1:3
Stack trace:
#0 {main}
thrown in /in/IUQt1 on line 3
Process exited with code 255 . Output for 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 Fatal error: Class 'EntityRepository' not found in /in/IUQt1 on line 3
Process exited with code 255 . Output for 4.4.2 - 4.4.9 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IUQt1 on line 5
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/IUQt1 on line 5
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/IUQt1 on line 5
Process exited with code 255 . preferences:dark mode live preview
303.07 ms | 401 KiB | 459 Q