public function searchBands($searchParameters, $dbConnection = null) { $bandList = null; $preparedStatement = null; try { $bandSearchQuery = null; $bandIDQuery = null; if ($dbConnection == null) { $dbConnection = DatabaseUtilities::getDatabaseConnection(); } $bandIDQuery = "SELECT DISTINCT B.BAND_ID FROM band B WHERE 1 = 1"; $bandIDQuery .= BandSearchDao::getBandSearchWhereClause($searchParameters); $bandSearchQuery = BandSearchDao::BAND_SEARCH_SELECT; $bandSearchQuery .= " AND B.BAND_ID IN (" . $bandIDQuery . ")\n\t\t\t\t\t\t\t\t\t\t\t\tORDER BY B.NAME ASC\n\t\t\t\t\t\t\t\t\t\t\t\tLIMIT :pagingAmount OFFSET :startingPoint"; $preparedStatement = BandSearchDao::getBandSearchPreparedStatement($bandSearchQuery, $searchParameters, $dbConnection); //Add paging parameters. $startingPoint = 0; $currentPage = $searchParameters->getVariable(SearchConstants::CURRENT_PAGE_ID); $pagingAmount = $searchParameters->getVariable(SearchConstants::PAGING_AMOUNT_ID); if ($currentPage > 1) { $startingPoint = ($currentPage - 1) * $pagingAmount; } $pagingAmount = (int) $pagingAmount; $startingPoint = (int) $startingPoint; $preparedStatement->bindParam(":pagingAmount", $pagingAmount, PDO::PARAM_INT); $preparedStatement->bindParam(":startingPoint", $startingPoint, PDO::PARAM_INT); $preparedStatement->execute(); while ($result = $preparedStatement->fetch()) { $band = BandSearchDao::extractBandSearchObject($result); if ($band !== null) { $band->setVariable(Band::GENRES, BandGenreDao::selectBandGenres($band->getVariable(Band::BAND_ID), $dbConnection)); $bandList[] = $band; } } $preparedStatement = null; } catch (Exception $ex) { echo "searchBands error: " . $ex->getMessage(); $bandList = null; } $preparedStatement = null; return $bandList; }
public function browseBandsByLocation($country, $state, $city, $region, $searchType, $currentPage, $pagingAmount, $dbConnection = null) { $bandSearchResults = null; $bandSkeletons = null; $countryID = null; $stateID = null; $cityID = null; $regionID = null; try { $bandParameters = new SearchParameters(); $bandParameters->setVariable(SearchConstants::CURRENT_PAGE_ID, $currentPage); $bandParameters->setVariable(SearchConstants::PAGING_AMOUNT_ID, $pagingAmount); //These elements are common to both search types $countryID = SearchUtilities::processSelectValues($country, 'defaultValue', '0'); if ($countryID != null) { $stateID = SearchUtilities::processSelectValues($state, 'defaultValue', '0'); } if ($stateID != null) { $cityID = SearchUtilities::processSelectValues($city, 'defaultValue', '0'); } if ($cityID != null) { $regionID = SearchUtilities::processSelectValues($region, 'defaultValue', '0'); } $bandParameters->setVariable(LocationConstants::LOCATION_COUNTRY_INPUT_ID, $countryID); $bandParameters->setVariable(LocationConstants::LOCATION_STATE_INPUT_ID, $stateID); $bandParameters->setVariable(LocationConstants::LOCATION_CITY_INPUT_ID, $cityID); $bandParameters->setVariable(LocationConstants::LOCATION_REGION_INPUT_ID, $regionID); $bandCount = BandSearchDao::getBandSearchCount($bandParameters, $dbConnection); $bandSkeletons = BandSearchDao::searchBands($bandParameters, $dbConnection); $bandSearchResults = new SearchResults(); $bandSearchResults->setVariable(SearchResults::SEARCH_PARAMETERS, $bandParameters); $bandSearchResults->setVariable(SearchResults::SKELETONS, $bandSkeletons); $bandSearchResults->setVariable(SearchResults::COUNT, $bandCount); $bandSearchResults->setVariable(SearchResults::PAGE_COUNT, ceil($bandCount / $pagingAmount)); } catch (Exception $ex) { $bandSearchResults = null; echo 'Caught exception: ', $ex->getMessage(), "\n"; } return $bandSearchResults; }