/** * Open Job Search * * @param string $catId */ public function anySearch($catId = null) { $categories = array(); if (Input::has("q") && trim(Input::get("q")) != "") { $q = strtolower(Input::get("q")); $foundCategories = JobCategory::whereRaw("LOWER(keywords) LIKE '%{$q}%' OR Lower(name) LIKE '%{$q}%'")->lists("id"); $categories = array_merge($categories, $foundCategories); } else { if (Input::has("catId") && intval(Input::get("catId")) > 0) { $catId = intval(Input::get("catId")); $categories[] = $catId; } } $user = Sentry::getUser(); $student = StudentInfo::findOrFail($user->id); $studentAddress = $student->primaryAddress; if ($studentAddress == null) { $studentAddress = $student->primaryAddress; } // $categories=$student->studentJobPreferences->lists("id"); $orWhereQ = array(); if (count($categories) > 0) { $orWhereQ[] = '`jobs`.`job_category_id` IN (' . implode(",", $categories) . ')'; } if (isset($q)) { $subWhereTitle = array(); $subWhereDescript = array(); if (strpos($q, ' ') > 0) { foreach (explode(' ', $q) as $r) { $subWhereTitle[] = "LOWER(`jobs`.`job_title`) LIKE '%" . $r . "%'"; $subWhereDescript[] = "LOWER(`jobs`.`job_description`) LIKE '%" . $r . "%'"; } $orWhereQ[] = "(" . implode(" AND ", $subWhereTitle) . ")"; $orWhereQ[] = "(" . implode(" AND ", $subWhereDescript) . ")"; } else { $orWhereQ[] = "LOWER(`jobs`.`job_title`) LIKE '%" . $q . "%'"; $orWhereQ[] = "LOWER(`jobs`.`job_description`) LIKE '%" . $q . "%'"; } } if (count($orWhereQ) > 0) { $jobs = Job::whereJobStatusId(JobStatus::$OPEN)->where("jobs.start_date", ">=", date("Y-m-d"))->whereRaw('(' . implode(" OR ", $orWhereQ) . ")")->select("jobs.*", Address::distanceSelectStatement($studentAddress->latitude, $studentAddress->longitude, 'distance', 'jobs'))->orderBy('jobs.start_date', 'asc')->having("distance", "<=", $student->studentProfile->preferred_job_radius)->get(); } else { $jobs = Job::whereJobStatusId(JobStatus::$OPEN)->where("jobs.start_date", ">=", date("Y-m-d"))->select("jobs.*", Address::distanceSelectStatement($studentAddress->latitude, $studentAddress->longitude, 'distance', 'jobs'))->orderBy('jobs.start_date', 'asc')->having("distance", "<=", $student->studentProfile->preferred_job_radius)->get(); } $student->load('userCertifications'); return View::make("jobs.search", compact("jobs", "student")); }