Skip to content

Instantly share code, notes, and snippets.

@arpitr
Created March 21, 2012 15:04
Show Gist options
  • Save arpitr/2148087 to your computer and use it in GitHub Desktop.
Save arpitr/2148087 to your computer and use it in GitHub Desktop.
<?php
include "citygrid-places-api-class.php";
/*
*
*
*/
class ExternalListingService {
private $node;
public function __construct($node) {
$this->node = $node;
}
public function lookupListing();
public function getReviewCount();
public function getListingURL();
public function getAllReviews();
public function getListingData();
public function postListing();
public function postReview();
public function applyListingDataToLocalRecord($search) {
$lang = LANGUAGE_NONE;
if (!$node->field_phone[$lang][0]['value']) {
$node->field_phone[$lang][0]['value'] = $search->location[contact_info][display_phone];
}
if (!$node->field_location[$lang][0]['name']) {
$node->field_location[$lang][0]['name'] = $search->location[name];
}
if (!$node->field_location[$lang][0]['street']) {
$node->field_location[$lang][0]['street'] = $search->location[address][street];
}
if (!$node->field_location[$lang][0]['city']) {
$node->field_location[$lang][0]['city'] = $search->location[address][city];
}
if (!$node->field_location[$lang][0]['province']) {
$node->field_location[$lang][0]['province'] = $search->location[address][state];
}
if (!$node->field_location[$lang][0]['postal_code']) {
$node->field_location[$lang][0]['postal_code'] = $search->location[address][postal_code];
}
if (!$node->field_location[$lang][0]['latitude']) {
$node->field_location[$lang][0]['latitude'] = $search->location[address][latitude];
}
if (!$node->field_location[$lang][0]['longitude']) {
$node->field_location[$lang][0]['longitude'] = $search->location[address][longitude];
}
if (!$node->field_location[$lang][0]['phone']) {
$node->field_location[$lang][0]['phone'] = $search->location[contact_info][display_phone];
}
if (!$node->field_website_url[$lang][0]['url']) {
$node->field_website_url[$lang][0]['url'] = $search->location[contact_info][display_url];
}
if (!$node->field_hours[$lang][0]['value']) {
$node->field_hours[$lang][0]['value'] = $search->location[business_hours];
}
}
}
class CitySearch extends ExternalListingService {
public $search;
public function lookupListing() {
$lang = LANGUAGE_NONE;
$phone = $node->field_phone[$lang][0]['value'];
$publishercode = "test";
$customer_only = null;
$placement = null;
$all_results = null;
$review_count = null;
$i = null;
$format = 'json';
$callback = null;
$id_type = 'cg';
//Get Place Detail
$citygrid = new citygrid($publishercode);
$this->search = $citygrid->places_detail($id, $id_type, $phone, $customer_only, $all_results, $review_count, $placement, $format, $callback, $i);
//var_dump($search);
if ($this->search) {
applyListingDataToLocalRecord($this->search);
}
$what = $node->title;
$type = null;
$where = str_replace('', '+', $node->location['street']) . ',' . $node->location['city'] . ',' . $node->location['state'];
$format = 'json';
$placement = null;
$has_offers = false;
$histograms = false;
$i = null;
$citygrid = new citygrid($publishercode);
$searchWhere = $citygrid->srch_places_where($what, $type, $where, $page, $rpp, $sort, $format, $placement, $has_offers, $i);
//var_dump($search);
if ($searchWhere) {
applyListingDataToLocalRecord($searchWhere);
}
}
public function getAllReviews() {
$review = new Review();
foreach ($this->search->review_info[reviews][review] as reviewSearch) {
$review->reviewerName[] = reviewSearch[review_author];
$review->rating[] = reviewSearch[review_rating];
$review->reviewText[] = reviewSearch[review_text];
$review->subject[] = reviewSearch[review_title];
$review->reviewURL[] = reviewSearch[review_url];
return review;
}
}
}
/*
*
*
*/
class Review {
public $revireviewerName;
public $rating;
public $reviewText;
public $reviewURL;
public $subject;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment