Skip to content

Commit

Permalink
Merge pull request #37 from NetCommons3/fix/1358_noLocationsAreAvailable
Browse files Browse the repository at this point in the history
change: 施設がひとつも登録されていなければ「予約可能な施設がありません。」と表示するようにした。
  • Loading branch information
RyujiAMANO committed Jul 8, 2020
2 parents 48ff702 + 58aea10 commit 9bc62cf
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
70 changes: 51 additions & 19 deletions Controller/ReservationsController.php
Expand Up @@ -105,37 +105,28 @@ class ReservationsController extends ReservationsAppController {
public function index() {
$vars = array();
$this->setReservationCommonCurrent($vars);

$this->ReservationEvent->initSetting($this->Workflow);

$style = $this->getQueryParam('style');
if (! $style) {
//style未指定の場合、ReservationFrameSettingモデルのdisplay_type情報から表示するctpを決める。

$displayType = (int)Current::read('ReservationFrameSetting.display_type');
switch($displayType) {
case ReservationsComponent::RESERVATION_DISP_TYPE_CATEGORY_WEEKLY:
$style = ReservationsComponent::RESERVATION_STYLE_CATEGORY_WEEKLY;
$this->_setDefaultCategory();
break;
case ReservationsComponent::RESERVATION_DISP_TYPE_CATEGORY_DAILY:
$style = ReservationsComponent::RESERVATION_STYLE_CATEGORY_DAILY;
$this->_setDefaultCategory();
break;
case ReservationsComponent::RESERVATION_DISP_TYPE_LACATION_MONTHLY:
$style = ReservationsComponent::RESERVATION_STYLE_LACATION_MONTHLY;
break;
case ReservationsComponent::RESERVATION_DISP_TYPE_LACATION_WEEKLY:
$style = ReservationsComponent::RESERVATION_STYLE_LACATION_WEEKLY;
break;
default:
$style = ReservationsComponent::RESERVATION_STYLE_DEFAULT;
}
$style = $this->__getStyleByDisplayType($displayType);

$this->__setDefaultCategoryWhenDispTypeIsCategory($displayType);
}

$categoryId = Hash::get($this->request->params['named'], 'category_id');

$locations = $this->ReservationLocation->getLocations($categoryId);

if (empty($locations) && $categoryId === null) {
//施設が1つも登録されてない
$this->view = 'location_not_found';
return;
}

if (empty($locations) && in_array($style,
[ReservationsComponent::RESERVATION_STYLE_LACATION_WEEKLY,
ReservationsComponent::RESERVATION_STYLE_LACATION_MONTHLY
Expand Down Expand Up @@ -431,4 +422,45 @@ protected function _setupCurrentValues4ByCategory() {
}
Current::write('ReservationReservable', $reservable);
}

/**
* __setDefaultCategoryWhenDispTypeIsCategory
*
* @param int|string $displayType display type
* @return void
*/
private function __setDefaultCategoryWhenDispTypeIsCategory($displayType) {
if (in_array($displayType, [
ReservationsComponent::RESERVATION_DISP_TYPE_CATEGORY_WEEKLY,
ReservationsComponent::RESERVATION_DISP_TYPE_CATEGORY_DAILY
])) {
$this->_setDefaultCategory();
}
}

/**
* __getStyleByDisplayType
*
* @param int|string $displayType display type
* @return string
*/
private function __getStyleByDisplayType($displayType) {
switch ($displayType) {
case ReservationsComponent::RESERVATION_DISP_TYPE_CATEGORY_WEEKLY:
$style = ReservationsComponent::RESERVATION_STYLE_CATEGORY_WEEKLY;
break;
case ReservationsComponent::RESERVATION_DISP_TYPE_CATEGORY_DAILY:
$style = ReservationsComponent::RESERVATION_STYLE_CATEGORY_DAILY;
break;
case ReservationsComponent::RESERVATION_DISP_TYPE_LACATION_MONTHLY:
$style = ReservationsComponent::RESERVATION_STYLE_LACATION_MONTHLY;
break;
case ReservationsComponent::RESERVATION_DISP_TYPE_LACATION_WEEKLY:
$style = ReservationsComponent::RESERVATION_STYLE_LACATION_WEEKLY;
break;
default:
$style = ReservationsComponent::RESERVATION_STYLE_DEFAULT;
}
return $style;
}
}
5 changes: 4 additions & 1 deletion Locale/jpn/LC_MESSAGES/reservations.po
Expand Up @@ -1418,4 +1418,7 @@ msgid "-- not specified --"
msgstr "-- 指定しない --"

msgid "Location not found in select category."
msgstr "選択したカテゴリに登録されている施設はありません。"
msgstr "選択したカテゴリに登録されている施設はありません。"

msgid "No locations are available."
msgstr "予約可能な施設がありません。"
3 changes: 3 additions & 0 deletions View/Reservations/location_not_found.ctp
@@ -0,0 +1,3 @@
<div class="alert alert-warning">
<?php echo __d('reservations', 'No locations are available.');?>
</div>

0 comments on commit 9bc62cf

Please sign in to comment.