00001 <?php
00002
00003
00004
00005
00006
00007
00008 require_once('VCSDBDriver/VCSDBDriverBase.php');
00009
00010 define('KODAWARI_ONLINE_BOOK', '24時間オンライン予約/空席照会ができる');
00011 define('KODAWARI_MILAGE', '指定した航空会社でマイル加算');
00012 define('KODAWARI_TRANSP_SERV', '送迎つき');
00013 define('KODAWARI_CHILD_DISC','子供・幼児割引');
00014 define('KODAWARI_DIRECT_FLIGHT', '直行便で行く');
00015 define('KODAWARI_OPEN_TICKET', 'オープンジョー可');
00016
00017 define('SERVICE_TYPE_HOTEL', 'hotel');
00018 define('SERVICE_TYPE_TOUR', 'tour');
00019 define('SERVICE_TYPE_AIR_TICKET', 'airticket');
00020
00027 class FormattedItem {
00028
00030 private $formattedHtml = null;
00031
00033 private $serviceRoot = null;
00034
00044 private function __construct(&$view,&$item) {
00045 $itemHtml = $view;
00046
00047 $serviceRoot = '';
00048 $serviceType = $item->xpath('vc_servType');
00049
00050 if (count($serviceType)>0) {
00051 $serviceType = $serviceType[0];
00052
00053 if ($serviceType == SERVICE_TYPE_HOTEL) {
00054 $serviceRoot = 'vc_hotel';
00055 } else if ($serviceType == SERVICE_TYPE_TOUR) {
00056 $serviceRoot = 'vc_tour';
00057 } else if ($serviceType == SERVICE_TYPE_AIR_TICKET) {
00058 $serviceRoot = 'vc_ticket';
00059 }
00060 }
00061
00062 $this->serviceRoot = $serviceRoot;
00063
00064 $itemHtml = $this->renderTitle($item, $itemHtml);
00065 $itemHtml = $this->renderLink($item, $itemHtml);
00066 $itemHtml = $this->renderImage($item, $itemHtml);
00067 $itemHtml = $this->renderDestination($item, $itemHtml);
00068 $itemHtml = $this->renderDescription($item, $itemHtml);
00069 $itemHtml = $this->renderPrice($item, $itemHtml);
00070 $itemHtml = $this->renderGrade($item, $itemHtml);
00071 $itemHtml = $this->renderDetailLink($item, $itemHtml);
00072
00073 $itemHtml = $this->renderPvImage($item, $itemHtml);
00074 $itemHtml = $this->renderAccessInfo($item, $itemHtml);
00075 $itemHtml = $this->renderGoogleMapLink($item, $itemHtml);
00076 $itemHtml = $this->renderHotel($item, $itemHtml);
00077 $itemHtml = $this->renderServiceId($item, $itemHtml);
00078 $itemHtml = $this->renderLatLng($item, $itemHtml);
00079
00080 $_SESSION['LAT_DETAIL'] = $this->getLat($item);
00081 $_SESSION['LNG_DETAIL'] = $this->getLNG($item);
00082
00083 if ($serviceType == SERVICE_TYPE_TOUR) {
00084 $itemHtml = $this->renderTerm($item, $itemHtml);
00085 }
00086
00087 if ($serviceType == SERVICE_TYPE_TOUR || $serviceType == SERVICE_TYPE_AIR_TICKET) {
00088 $itemHtml = $this->renderKodawari($item, $itemHtml);
00089 $itemHtml = $this->renderAirline($item, $itemHtml);
00090 $itemHtml = $this->renderMerchant($item, $itemHtml);
00091 }
00092
00093 $this->formattedHtml = $itemHtml;
00094 }
00095
00101 public function toString() {
00102 return $this->formattedHtml;
00103 }
00104
00112 public static function getItems(&$template,$response) {
00113 $items = array();
00114
00115 if (get_class($response) != 'SimpleXMLElement') {
00116 return $items;
00117 }
00118
00119 $itemElements = $response->xpath('/rss/channel/item');
00120 foreach($itemElements as $item) {
00121 array_push($items, new FormattedItem($template,$item));
00122 }
00123
00124 return $items;
00125 }
00126
00130 private function toGradeStar($grade){
00131
00132 $staron = '<img src="images/star.gif" />';
00133 $staroff = '<img src="images/star_no.gif" />';
00134
00135 $gradestar = null;
00136
00137 if($grade == 5.0)
00138 {
00139 $gradestar = $staron . $staron . $staron . $staron . $staron;
00140 }
00141 elseif(4 <= $grade && $grade < 5)
00142 {
00143 $gradestar = $staron . $staron . $staron . $staron . $staroff;
00144 }
00145 elseif(3 <= $grade && $grade < 4)
00146 {
00147 $gradestar = $staron . $staron . $staron . $staroff . $staroff;
00148 }
00149 elseif(2 <= $grade && $grade < 3)
00150 {
00151 $gradestar = $staron . $staron . $staroff . $staroff . $staroff;
00152 }
00153 elseif(1 <= $grade && $grade < 2)
00154 {
00155 $gradestar = $staron . $staroff . $staroff . $staroff . $staroff;
00156 }
00157 elseif($grade < 1){
00158 $gradestar = $staroff . $staroff . $staroff . $staroff . $staroff;
00159 }
00160 else{
00161 $gradestar = $staroff . $staroff . $staroff . $staroff . $staroff;
00162 }
00163
00164 return $gradestar;
00165
00166
00167
00168 }
00169
00177 private function renderTitle($item, $itemHtml) {
00178 $titleStr = '';
00179 $title = $item->xpath('title');
00180 if (count($title)>0) {
00181 $titleStr = $title[0];
00182 $itemHtml = str_replace(
00183 '${TITLE}',
00184 strip_tags(VCSDBDriverBase::toInternalCharset($titleStr)),
00185 $itemHtml
00186 );
00187 $itemHtml = str_replace(
00188 '${VC_PAGEHOTELNAME}',
00189 strip_tags(VCSDBDriverBase::toInternalCharset($titleStr)),
00190 $itemHtml
00191 );
00192 $itemHtml = str_replace(
00193 '${TITLE_URLENCODE}',
00194 urlencode( VCSDBDriverBase::toInternalCharset($titleStr)),
00195 $itemHtml
00196 );
00197 }
00198
00199 return $itemHtml;
00200 }
00201
00209 private function renderImage($item, $itemHtml) {
00210 $found = false;
00211 $images = $item->xpath($this->serviceRoot.'/vc_images/vc_imageSet/vc_image');
00212 foreach($images as $image) {
00213 foreach ($image->attributes() as $a => $b) {
00214 if ((string)$a == "class" && (string)$b == "free") {
00215 $itemHtml = str_replace('${IMAGE}',(string)$image,$itemHtml);
00216 $found = true;
00217 }
00218 if ($found)
00219 break;
00220 }
00221
00222 if ($found) {
00223 break;
00224 }
00225 }
00226
00227 return $itemHtml;
00228 }
00229
00237 private function renderPvImage($item, $itemHtml) {
00238 $pvImg = $item->xpath($this->serviceRoot.'/vc_pvImg');
00239 if (count($pvImg)>0) {
00240 $itemHtml = str_replace('${PVIMG}',(string)$pvImg[0],$itemHtml);
00241 }
00242
00243 return $itemHtml;
00244 }
00245
00253 private function renderAccessInfo($item, $itemHtml) {
00254 $accessInfo = $item->xpath($this->serviceRoot.'/vc_access');
00255 if (count($accessInfo)>0) {
00256 $itemHtml = str_replace(
00257 '${ACCESS_INFO}',
00258 VCSDBDriverBase::toInternalCharset((string)$accessInfo[0]),
00259 $itemHtml
00260 );
00261 }
00262
00263 return $itemHtml;
00264 }
00265
00273 private function renderLink($item, $itemHtml) {
00274 $link = $item->xpath('link');
00275 if (count($link)>0) {
00276 $itemHtml = str_replace('${LINK}',(string)$link[0],$itemHtml);
00277 }
00278
00279 return $itemHtml;
00280 }
00281
00282
00290 private function renderGoogleMapLink($item, $itemHtml) {
00291 $latitude = $item->xpath($this->serviceRoot.'/vc_lat');
00292 $longitude = $item->xpath($this->serviceRoot.'/vc_lng');
00293
00294 if (count($latitude)>0 && count($longitude)>0) {
00295 $url = VCSDBDRIVER_GOOGLEMAP . '&ll=' . (string)$latitude[0]
00296 . ',' . (string)$longitude[0] . '&q=' . (string)$latitude[0]. ',' . (string)$longitude[0];
00297
00298 $itemHtml = str_replace('${GOOGLE_MAP_LINK}',$url,$itemHtml);
00299 }
00300
00301 return $itemHtml;
00302 }
00303
00311 private function renderDestination($item, $itemHtml) {
00312 $dest = $item->xpath($this->serviceRoot.'/vc_dests/vc_summ');
00313 if (count($dest) > 0) {
00314 $itemHtml = str_replace('${DEST}',(string)$dest[0],$itemHtml);
00315 }
00316
00317 return $itemHtml;
00318 }
00319
00327 private function renderDescription($item, $itemHtml) {
00328 $description = $item->xpath('description');
00329 if (count($description)>0) {
00330 $itemHtml = str_replace(
00331 '${DESCRIPTION}',
00332 strip_tags(VCSDBDriverBase::toInternalCharset($description[0])),
00333 $itemHtml
00334 );
00335 }
00336
00337 return $itemHtml;
00338 }
00339
00347 private function renderPrice($item, $itemHtml) {
00348 $priceMin = $item->xpath($this->serviceRoot.'/vc_priceMin');
00349 if (count($priceMin)>0) {
00350 $itemHtml = str_replace(
00351 '${PRICE_MIN}',
00352 (string)number_format($priceMin[0]),
00353 $itemHtml
00354 );
00355 }
00356
00357 $priceMax = $item->xpath($this->serviceRoot.'/vc_priceMax');
00358 if (count($priceMax)>0) {
00359 $itemHtml = str_replace(
00360 '${PRICE_MAX}',
00361 (string)number_format($priceMax[0]),
00362 $itemHtml
00363 );
00364 }
00365
00366 return $itemHtml;
00367 }
00368
00376 private function renderGrade($item, $itemHtml) {
00377 $grade = $item->xpath($this->serviceRoot.'/vc_grade');
00378 if (count($grade)>0) {
00379 $itemHtml = str_replace(
00380 '${GRADE}',
00381 $this->toGradeStar((string)$grade[0]),
00382 $itemHtml
00383 );
00384 }
00385
00386 return $itemHtml;
00387 }
00388
00396 private function renderTerm($item, $itemHtml) {
00397 $termMin = $item->xpath($this->serviceRoot.'/vc_termMin');
00398 if (count($termMin)>0) {
00399 $itemHtml = str_replace(
00400 '${TERM_MIN}',
00401 (string)$termMin[0],
00402 $itemHtml
00403 );
00404 }
00405
00406 $termMax = $item->xpath($this->serviceRoot.'/vc_termMax');
00407 if (count($termMax)>0) {
00408 $itemHtml = str_replace(
00409 '${TERM_MAX}',
00410 (string)$termMax[0],
00411 $itemHtml
00412 );
00413 }
00414
00415 return $itemHtml;
00416 }
00417
00425 private function renderKodawari($item, $itemHtml) {
00426 $kodawari = $item->xpath($this->serviceRoot.'/vc_kodawari');
00427 if (count($kodawari) >0) {
00428 $values = explode(',', VCSDBDriverBase::toInternalCharset((string)$kodawari[0]));
00429
00430 $online_book_on = false;
00431 $transp_serv_on = false;
00432 $child_disc_on = false;
00433 $milage_on = false;
00434 $direct_flight_on = false;
00435 $open_ticket_on = false;
00436
00437 foreach ($values as $value) {
00438 $value = VCSDBDriverBase::toInternalCharset((string)$value);
00439
00440 if ($value == KODAWARI_TRANSP_SERV) {
00441 $transp_serv_on = true;
00442 } else if($value == KODAWARI_CHILD_DISC) {
00443 $child_disc_on = true;
00444 } else if($value == KODAWARI_ONLINE_BOOK) {
00445 $online_book_on = true;
00446 } else if($value == KODAWARI_MILAGE) {
00447 $milage_on = true;
00448 } else if($value == KODAWARI_DIRECT_FLIGHT) {
00449 $direct_flight_on = true;
00450 } else if($value == KODAWARI_OPEN_TICKET) {
00451 $open_ticket_on = true;
00452 }
00453 }
00454
00455 $itemHtml = str_replace('${TRANSP_SERV_STATUS}', $transp_serv_on ? '' : 'off', $itemHtml);
00456 $itemHtml = str_replace('${CHILD_DISC_STATUS}', $child_disc_on ? '' : 'off', $itemHtml);
00457 $itemHtml = str_replace('${ONLINE_BOOK_STATUS}', $online_book_on ? '' : 'off', $itemHtml);
00458 $itemHtml = str_replace('${MILAGE_STATUS}', $milage_on ? '' : 'off', $itemHtml);
00459 $itemHtml = str_replace('${DIRECT_FLIGHT_STATUS}', $direct_flight_on ? '' : 'off', $itemHtml);
00460 $itemHtml = str_replace('${OPEN_TICKET_STATUS}',$open_ticket_on ? '' : 'off', $itemHtml);
00461 }
00462
00463 return $itemHtml;
00464 }
00465
00473 private function renderMerchant($item, $itemHtml) {
00474 $merchant = $item->xpath('vc_merchName');
00475 if (count($merchant) > 0) {
00476 $itemHtml = str_replace('${MERCHANT}',
00477 VCSDBDriverBase::toInternalCharset((string)$merchant[0]),
00478 $itemHtml
00479 );
00480 }
00481
00482 return $itemHtml;
00483 }
00484
00492 private function renderHotel($item, $itemHtml) {
00493 $hotel = $item->xpath($this->serviceRoot."/vc_hotels/vc_hotel[1]/vc_name[@lang='JP']");
00494 if (count($hotel) > 0) {
00495 $itemHtml = str_replace('${HOTEL}',
00496 VCSDBDriverBase::toInternalCharset((string)$hotel[0]),
00497 $itemHtml
00498 );
00499 }
00500
00501 return $itemHtml;
00502 }
00503
00511 private function renderServiceId($item, $itemHtml) {
00512 $hotel = $item->xpath($this->serviceRoot."/vc_id");
00513 if (count($hotel) > 0) {
00514 $itemHtml = str_replace('${SERV_ID}',
00515 VCSDBDriverBase::toInternalCharset((string)$hotel[0]),
00516 $itemHtml
00517 );
00518 }
00519
00520 return $itemHtml;
00521 }
00522
00530 private function renderLatLng($item, $itemHtml) {
00531 $lat = $item->xpath($this->serviceRoot."/vc_lat");
00532 if (count($lat) > 0) {
00533 $itemHtml = str_replace('${LAT}',
00534 VCSDBDriverBase::toInternalCharset((string)$lat[0]),
00535 $itemHtml
00536 );
00537 }
00538 $lng = $item->xpath($this->serviceRoot."/vc_lng");
00539 if (count($lng) > 0) {
00540 $itemHtml = str_replace('${LNG}',
00541 VCSDBDriverBase::toInternalCharset((string)$lng[0]),
00542 $itemHtml
00543 );
00544 }
00545 return $itemHtml;
00546 }
00547
00555 private function renderDetailLink($item, $itemHtml) {
00556 global $_GET;
00557
00558 $link = '';
00559
00561 foreach($_GET as $name => $value) {
00562 if ($name == 'page' || $name == 'submit' || $name == 'x' || $name == 'y' || $name == 'error_flg') {
00563 continue;
00564 }
00565 $link .= '&' . $name . '=' . $value;
00566 }
00567
00568 $title = $item->xpath('title');
00569 if (count($title)>0) {
00570 $itemHtml = str_replace('${SEARCH_PARAM}',$link, $itemHtml);
00571 }
00572
00573 return $itemHtml;
00574 }
00575
00583 private function renderAirline($item, $itemHtml) {
00584 $airline = $item->xpath($this->serviceRoot."/vc_airlines/vc_airline[1]/vc_name[@lang='JP']");
00585 if (count($airline) > 0) {
00586 $itemHtml = str_replace('${AIRLINE}',
00587 VCSDBDriverBase::toInternalCharset((string)$airline[0]),
00588 $itemHtml
00589 );
00590 }
00591
00592 return $itemHtml;
00593 }
00594
00601 private function getLat($item) {
00602 $lat = $item->xpath($this->serviceRoot."/vc_lat");
00603 if (count($lat) > 0) {
00604 return VCSDBDriverBase::toInternalCharset((string)$lat[0]);
00605 }
00606 else
00607 {
00608 return false;
00609 }
00610 }
00611
00618 private function getLng($item) {
00619 $lng = $item->xpath($this->serviceRoot."/vc_lng");
00620 if (count($lng) > 0) {
00621 return VCSDBDriverBase::toInternalCharset((string)$lng[0]);
00622 }
00623 else
00624 {
00625 return false;
00626 }
00627 }
00628
00629
00630 }
00631
00632 ?>