--- /dev/null
+<?php
+
+/**
+ * SearchDisplay.php
+ *
+ * PHP version 5.3
+ *
+ * @category Toolkit
+ * @package Members
+ * @author Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: (0.1)
+ * @link <>
+ */
+
+/**
+ * Toolkit_Package_SearchDisplay
+ *
+ * Description of SearchDisplay
+ *
+ * @category Toolkit
+ * @package Members
+ * @author Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license Gaslight Media
+ * @release Release: (0.1)
+ * @link <>
+ */
+class Toolkit_Members_SearchDisplay
+{
+ private $_searchTerms;
+
+ public function __construct(PDO $dbh)
+ {
+ $this->_searchTerms = new ArrayObject();
+ $posted = filter_var_array(
+ $_REQUEST,
+ array(
+ 'member_name' => FILTER_SANITIZE_STRING,
+ 'activityId' => FILTER_VALIDATE_INT,
+ 'parkId' => FILTER_VALIDATE_INT,
+ 'regionId' => FILTER_VALIDATE_INT,
+ 'countyId' => FILTER_VALIDATE_INT,
+ 'amenity' => array(
+ 'filter' => FILTER_VALIDATE_INT,
+ 'flags' => FILTER_FORCE_ARRAY
+ )
+ )
+ );
+ extract($posted);
+ if ($member_name) {
+ $this->_searchTerms->offsetSet('member_name', $member_name);
+ }
+ if ($activityId) {
+ $activityName = $this->getCategoryName($dbh, $activityId);
+ $this->_searchTerms->offsetSet('activity', $activityName);
+ }
+ if ($parkId) {
+ $parkName = $this->getCategoryName($dbh, $parkId);
+ $this->_searchTerms->offsetSet('park', $parkName);
+ }
+ if ($regionId) {
+ $regionName = $this->getRegionName($dbh, $regionId);
+ $this->_searchTerms->offsetSet('region', $regionName);
+ }
+ if ($countyId) {
+ $countyName = $this->getCountyName($dbh, $countyId);
+ $this->_searchTerms->offsetSet('county', $countyName);
+ }
+ if (!empty($amenity) && $amenity[0]) {
+ $amenities = array();
+ foreach ($amenity as $amm) {
+ $amenities[] = $this->getAmenityName($dbh, $amm);
+ }
+ $this->_searchTerms->offsetSet('amenity', $amenities);
+ }
+ }
+
+ public function toHtml()
+ {
+ $html = '';
+ if (count($this->_searchTerms) > 0) {
+ $html .= 'Searching for ';
+ if ($this->_searchTerms->offsetExists('activity')) {
+ $activity = $this->_searchTerms->offsetGet('activity');
+ $html .= $activity . ' ';
+ if (!preg_match('%trails%i', $activity)) {
+ $html .= 'Trials ';
+ }
+ } else {
+ $html .= 'Trials ';
+ }
+ if ($this->_searchTerms->offsetExists('amenity')) {
+ $amenities = $this->_searchTerms->offsetGet('amenity');
+ $html .= 'that are ' . implode(' or ', $amenities) . ' ';
+ }
+ if ($this->_searchTerms->offsetExists('park')) {
+ $park = $this->_searchTerms->offsetGet('park');
+ $html .= 'in ' . $park . ' ';
+ if (!preg_match('%parks%i', $park)) {
+ $html .= 'Parks ';
+ }
+ }
+ if ($this->_searchTerms->offsetExists('region')) {
+ $html .= 'in ' . $this->_searchTerms->offsetGet('region')
+ . ' Region ';
+ }
+ if ($this->_searchTerms->offsetExists('county')) {
+ $html .= 'in ' . $this->_searchTerms->offsetGet('county')
+ . ' County ';
+ }
+
+ }
+ return $html;
+ }
+
+ protected function getCategoryName(PDO $dbh, $id)
+ {
+ try {
+ $sql = "
+ SELECT name
+ FROM members.category
+ WHERE category_id = :id";
+ $stmt = $dbh->prepare($sql);
+ $stmt->bindParam(':id', $id, PDO::PARAM_INT);
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+
+ }
+
+ protected function getRegionName(PDO $dbh, $id)
+ {
+ try {
+ $sql = "
+ SELECT region_name
+ FROM members.region
+ WHERE region_id = :id";
+ $stmt = $dbh->prepare($sql);
+ $stmt->bindParam(':id', $id, PDO::PARAM_INT);
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ protected function getCountyName(PDO $dbh, $id)
+ {
+ try {
+ $sql = "
+ SELECT county_name
+ FROM members.county
+ WHERE county_id = :id";
+ $stmt = $dbh->prepare($sql);
+ $stmt->bindParam(':id', $id, PDO::PARAM_INT);
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ protected function getAmenityName(PDO $dbh, $id)
+ {
+ try {
+ $sql = "
+ SELECT amenity_name
+ FROM members.amenity
+ WHERE amenity_id = :id";
+ $stmt = $dbh->prepare($sql);
+ $stmt->bindParam(':id', $id, PDO::PARAM_INT);
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+}
+
// }}}
+ public function getSearchTerms(PDO $dbh)
+ {
+ $terms = new Toolkit_Members_SearchDisplay($dbh);
+
+ return $terms->toHtml();
+ }
+
// {{{ getQuery()
/**
WHERE amenity_id IN ("
.implode(',', $amenity)."))";
}
- if (!empty($activity) && $activity[0]) {
- $params[] = "m.member_id IN (
- SELECT member_id
- FROM member_category
- WHERE category_id IN ("
- .implode(',', $activity)."))";
- }
+// if (!empty($activity) && $activity[0]) {
+// $params[] = "m.member_id IN (
+// SELECT member_id
+// FROM member_category
+// WHERE category_id IN ("
+// .implode(',', $activity)."))";
+// }
if ($activityId) {
$params[] = "m.member_id IN (
SELECT member_id
FROM member_category
WHERE category_id = {$parkId})";
}
- if ($regionId) {
- $params[] = "m.region = {$regionId}";
- }
+// if ($regionId) {
+// $params[] = "m.region = {$regionId}";
+// }
if ($countyId) {
$params[] = "m.county = {$countyId}";
}
- if (!empty($park) && $park[0]) {
- $params[] = "m.member_id IN (
- SELECT member_id
- FROM member_category
- WHERE category_id IN ("
- .implode(',', $park)."))";
- }
+// if (!empty($park) && $park[0]) {
+// $params[] = "m.member_id IN (
+// SELECT member_id
+// FROM member_category
+// WHERE category_id IN ("
+// .implode(',', $park)."))";
+// }
// Limit to members who have the category assigned to them
// that a user selected from the member type box.