-
<?php
-
require_once 'Services/Hotpepper.php';
-
require_once 'Pager.php';
-
-
class HotPepperApp
-
{
-
private $hotpepper;
-
private $searchResult;
-
private $parameters;
-
-
const DEFAULT_ADDRESS = '東京';
-
-
public
function __construct
($parameters =
array())
-
{
-
$this->hotpepper = new Services_Hotpepper();
-
$this->hotpepper->setResponseFormat('array');
-
$this->hotpepper->setUseCache(true);
-
$this->parameters = $parameters;
-
if (isset($this->
parameters['Start'])) {
-
if (!
isset($this->
parameters['Count'])) {
-
$this->parameters['Count'] = 10;
-
}
-
$this->parameters['Start'] *= (int)$this->parameters['Count'];
-
}
-
// 2006-12-25T16:03:16 修正 parametersに使えない値があるとInvalidParamerExceptionを吐くので、とりあえずそれ以外は削る。
-
-
'ShopIdFront', 'ShopNameKana', 'ShopName', 'ShopTel', 'ShopAddress',
-
'KtaiCoupon', 'LargeServiceAreaCD', 'ServiceAreaCD', 'LargeAreaCD',
-
'MiddleAreaCD', 'SmallAreaCD', 'Keyword', 'GenreCD', 'Order',
-
'Start', 'Count');
-
foreach ($this->parameters as $key => $value) {
-
if (!
in_array($key,
$availables) or
$value ==
'') {
-
unset($this->
parameters[$key]);
-
}
-
}
-
}
-
-
public function getOptions($master)
-
{
-
$method = 'get' . $master;
-
$result = $this->hotpepper->$method();
-
-
$output = '<select name="' .$master. 'CD">';
-
$output .= '<option value=""> - </option>';
-
foreach ($result[$master] as $item) {
-
$output .= '<option value="' . $item[$master.'CD'] . '"';
-
if (isset($_REQUEST[$master.
'CD']) and
$_REQUEST[$master.
'CD'] ==
$item[$master.
'CD']) {
-
$output .= ' selected="selected"';
-
}
-
$output .= '>' . $item[$master .'Name'] . '</option>';
-
}
-
$output .= '</select>';
-
return $output;
-
}
-
-
public function getResult()
-
{
-
if (!
isset($_REQUEST['search'])) { return array();
}
-
$output = '';
-
if (empty($this->
searchResult)) {
-
$this->searchResult = $this->hotpepper->getGourmetSearch($this->parameters);
-
}
-
if (is_null($this->
searchResult['NumberOfResults'])) { return array();
}
-
return $this->searchResult['Shop'];
-
}
-
-
public function getPager()
-
{
-
if (!
isset($this->
parameters)) { return '';
}
-
if (empty($this->
searchResult)) {
-
$this->searchResult = $this->hotpepper->getGourmetSearch($this->parameters);
-
}
-
-
'mode' => 'Sliding',
-
'urlVar' => 'Start',
-
'totalItems' => (int)$this->searchResult['NumberOfResults'] - (int)$this->searchResult['DisplayPerPage'],
-
'perPage' => (int)$this->searchResult['DisplayPerPage'],
-
'currentPage' => (int)$this->searchResult['DisplayFrom'] / (int)$this->searchResult['DisplayPerPage'],
-
);
-
-
$pager = Pager::factory($options);
-
return $pager->links;
-
}
-
-
public function getShopAddress()
-
{
-
return isset($_REQUEST['ShopAddress']) ?
htmlspecialchars($_REQUEST['ShopAddress']) : self::
DEFAULT_ADDRESS;
-
}
-
-
// Helper Method
-
public
static function getTabHtml
($result)
-
{
-
-
-
-
$noKtaiCoupon = (boolean)$result['KtaiCoupon'];
-
-
-
-
-
-
-
-
-
$ktaiText = $isKtaiCoupon ? '携帯NG!' : '携帯OK!';
-
-
$base =<<<eof
-
<a href='$url'>$name($ktaiText)<br />$catch<br /><hr />$address<br />
-
<!-- HotPepperのページからメールを送ればいいんじゃない?
-
<form>
-
<lable>携帯にアクセス先アドレスを:<input type='text' name='email'/>
-
<input type='hidden' name='url' value='$ktaiShopUrl'/>
-
<input type='submit' value='送信!'/>
-
-
-->
-
EOF;
-
$detail =<<<eof
-
<div style='float:left;width=200;text-align:center;'>
-
<img src='$image' alt='$name' /><br />写真提供:ホットペッパー.jp<br />
-
-
<div>
-
ジャンル($genre)<br />予算($budget)<br />総席数($capacity)
-
<hr />
-
$access
-
</div>
-
EOF;
-
-
-
-
);
-
return $tab;
-
}
-
}
-
-
if (isset($_REQUEST['search'])) {
-
$app = new HotPepperApp($_REQUEST);
-
} else {
-
$app = new HotPepperApp;
-
}
-
-
?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
-
<title>Google Maps JavaScript API Example</title>
-
<!-- http://localhost/ -->
-
-
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAvkm9X7SZvAyCad0c7GjwBhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRo7UhGG5tiSNLbTXH8AFUQzXffZg"
-
type="text/javascript"></script>
-
-
<!-- http://www.ganchiku.com/ -->
-
<!--
-
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAvkm9X7SZvAyCad0c7GjwBhR3SquV7UZw5piZBM9SKA5Ap0BlHxRIXFNr6SBh14IfS1Z5EVaMbEE3jw"
-
type="text/javascript">
-
-->
-
<script type="text/javascript">
-
-
//<![CDATA[
-
-
function load() {
-
if (GBrowserIsCompatible()) {
-
var map = new GMap2(document.getElementById("map"));
-
var geocoder = new GClientGeocoder();
-
var address = '<?php echo $app->getShopAddress(); ?>';
-
map.addControl(new GLargeMapControl());
-
map.addControl(new GMapTypeControl());
-
map.addControl(new GOverviewMapControl());
-
geocoder.getLatLng(address, function(point) {
-
if (!point) {
-
alert("存在する住所(一部可)を入力してください。");
-
} else {
-
map.setCenter(point, 13);}
-
});
-
}
-
var shopAddress = '';
-
<?php foreach ($app->getResult() as $result) : ?>
-
shopAddress = '<?php echo array_shift(explode(" ", $result['ShopAddress'])); ?>';
-
geocoder.getLatLng(shopAddress, function(point) {
-
if (point) {
-
var marker = new GMarker(point);
-
var windowTabs = [
-
<?php foreach (HotPepperApp::getTabHtml($result) as $tab => $content) : ?>
-
new GInfoWindowTab("<?php echo $tab; ?>", "<?php echo $content; ?>"),
-
<?php endforeach; ?>
-
];
-
map.addOverlay(marker);
-
GEvent.addListener(marker, "click", function() {
-
marker.openInfoWindowTabsHtml(windowTabs);
-
});
-
}
-
});
-
<?php endforeach; ?>
-
}
-
-
//]]>
-
</script>
-
</head>
-
<body onload="load()" onunload="GUnload()">
-
<div id="form">
-
<form method="get" action="hotpepper.php">
-
<input type="text" name="ShopAddress" value="<?php echo $app-/>getShopAddress(); ?>" size="64" maxlength="128">
-
<?php echo $app->
getOptions('Genre');
?>
-
<select name="Count">
-
<?php
-
for($i = 0; $i <10; $i++) {
-
$value = ($i+1) * 10;
-
echo '<option value="'.
$value.
'"';
-
if (isset($_REQUEST['Count']) and
$_REQUEST['Count'] ==
$value) {
-
echo ' selected="selected"';
-
}
-
$output .= '>' . $item[$master .'Name'] . '';
-
-
}
-
?>
-
</select>
-
<input name="search" type="submit" value="検索"/>
-
</form>
-