From d154543c3443b686ecb4f2615348cf19b34a7ab0 Mon Sep 17 00:00:00 2001 From: Yuko Kajihara Date: Mon, 15 Feb 2021 18:41:25 +0900 Subject: [PATCH 01/36] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=86=E3=83=B3=E3=83=84=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E9=96=8B=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config/eccube/packages/eccube_nav.yaml | 3 + .../Admin/Setting/Shop/CalendarController.php | 64 +++++ src/Eccube/Entity/Calendar.php | 164 +++++++++++++ src/Eccube/Form/Type/Admin/CalendarType.php | 60 +++++ src/Eccube/Repository/CalendarRepository.php | 52 +++++ .../admin/Setting/Shop/calendar_rule.twig | 218 ++++++++++++++++++ 6 files changed, 561 insertions(+) create mode 100644 src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php create mode 100644 src/Eccube/Entity/Calendar.php create mode 100644 src/Eccube/Form/Type/Admin/CalendarType.php create mode 100644 src/Eccube/Repository/CalendarRepository.php create mode 100644 src/Eccube/Resource/template/admin/Setting/Shop/calendar_rule.twig diff --git a/app/config/eccube/packages/eccube_nav.yaml b/app/config/eccube/packages/eccube_nav.yaml index ebd6a83a66f..d91ef5f7dbf 100644 --- a/app/config/eccube/packages/eccube_nav.yaml +++ b/app/config/eccube/packages/eccube_nav.yaml @@ -115,6 +115,9 @@ parameters: shop_order_status: name: admin.setting.shop.order_status_setting url: admin_setting_shop_order_status + shop_calendar: + name: admin.setting.shop.calendar_setting + url: admin_setting_shop_calendar system: name: admin.setting.system children: diff --git a/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php b/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php new file mode 100644 index 00000000000..30209802280 --- /dev/null +++ b/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php @@ -0,0 +1,64 @@ +calendarRepository = $calendarRepository; + } + + /** + * カレンダー設定の初期表示・登録 + * + * @Route("/%eccube_admin_route%/setting/shop/calendar", name="admin_setting_shop_calendar") + //* @Route("/%eccube_admin_route%/setting/shop/calendar/new", name="admin_setting_shop_calendar_new") + * @Template("@admin/Setting/Shop/calendar_rule.twig") + */ + public function index(Request $request) + { + + $Calendar = new \Eccube\Entity\Calendar(); + $builder = $this->formFactory + ->createBuilder(CalendarType::class, $Calendar); + + $form = $builder->getForm(); + $form->handleRequest($request); + + return [ + 'form' => $form->createView(), + ]; + } +} diff --git a/src/Eccube/Entity/Calendar.php b/src/Eccube/Entity/Calendar.php new file mode 100644 index 00000000000..7b9230d0301 --- /dev/null +++ b/src/Eccube/Entity/Calendar.php @@ -0,0 +1,164 @@ +getId(); + } + + /** + * @var int + * + * @ORM\Column(name="id", type="integer", options={"unsigned":true}) + * @ORM\Id + * @ORM\GeneratedValue(strategy="IDENTITY") + */ + private $id; + + /** + * @var string + * + * @ORM\Column(name="name", type="string", length=255, nullable=true) + */ + private $title; + + /** + * @var \DateTime + * + * @ORM\Column(name="holiday", type="datetimetz") + */ + private $holiday; + + /** + * @var \DateTime + * + * @ORM\Column(name="create_date", type="datetimetz") + */ + private $create_date; + + /** + * @var \DateTime + * + * @ORM\Column(name="update_date", type="datetimetz") + */ + private $update_date; + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set title. + * + * @param string $title + * + * @return Calendar + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get title. + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Set createDate. + * + * @param \DateTime $createDate + * + * @return Calendar + */ + public function setCreateDate($createDate) + { + $this->create_date = $createDate; + + return $this; + } + + /** + * Get createDate. + * + * @return \DateTime + */ + public function getCreateDate() + { + return $this->create_date; + } + + /** + * Set updateDate. + * + * @param \DateTime $updateDate + * + * @return Calendar + */ + public function setUpdateDate($updateDate) + { + $this->update_date = $updateDate; + + return $this; + } + + /** + * Get updateDate. + * + * @return \DateTime + */ + public function getUpdateDate() + { + return $this->update_date; + } + } +} diff --git a/src/Eccube/Form/Type/Admin/CalendarType.php b/src/Eccube/Form/Type/Admin/CalendarType.php new file mode 100644 index 00000000000..479621df78d --- /dev/null +++ b/src/Eccube/Form/Type/Admin/CalendarType.php @@ -0,0 +1,60 @@ +eccubeConfig = $eccubeConfig; + } + + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('title', TextType::class, [ + 'required' => true, + 'constraints' => [ + new Assert\Length([ + 'max' => $this->eccubeConfig['eccube_stext_len'], + ]), + ], + ]) + ; + + } +} diff --git a/src/Eccube/Repository/CalendarRepository.php b/src/Eccube/Repository/CalendarRepository.php new file mode 100644 index 00000000000..55df5dc080c --- /dev/null +++ b/src/Eccube/Repository/CalendarRepository.php @@ -0,0 +1,52 @@ +find($id); + + if (null === $calendar) { + throw new \Exception('Calendar not found. id = '.$id); + } + + return $this->find($id); + } +} diff --git a/src/Eccube/Resource/template/admin/Setting/Shop/calendar_rule.twig b/src/Eccube/Resource/template/admin/Setting/Shop/calendar_rule.twig new file mode 100644 index 00000000000..d8b915931df --- /dev/null +++ b/src/Eccube/Resource/template/admin/Setting/Shop/calendar_rule.twig @@ -0,0 +1,218 @@ +{# +This file is part of EC-CUBE + +Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. + +http://www.ec-cube.co.jp/ + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +#} +{% extends '@admin/default_frame.twig' %} + +{% set menus = ['setting', 'shop', 'shop_calendar'] %} + +{% block title %}{{ 'admin.setting.shop.calendar_setting'|trans }}{% endblock %} +{% block sub_title %}{{ 'admin.setting.shop'|trans }}{% endblock %} + +{#{% form_theme form '@admin/Form/bootstrap_4_horizontal_layout.html.twig' %}#} + +{% block stylesheet %} + +{% endblock stylesheet %} + +{% block javascript %} + +{% endblock javascript %} + +{% block main %} +
+
+
+
+
+
+ {{ 'admin.setting.shop.calendar_setting'|trans }} + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + {#{{ form_widget(form._token) }}#} + + + + + + + + + + {#{% for TaxRule in TaxRules %} + + + {{ form_widget(forms[TaxRule.id]._token) }} + + + + + + + + + + + {% endfor %}#} + +
{{ 'admin.common.id'|trans }}{{ 'admin.setting.shop.calendar.title'|trans }}{{ 'admin.setting.shop.calendar.holiday'|trans }}
+
+ {{ form_widget(form.title) }} + {{ form_errors(form.title) }} +
+
+ bbb{#{{ form_widget(form.rounding_type) }}#} + {#{{ form_errors(form.rounding_type) }}#} + + ccc{#{{ form_widget(form.apply_date) }}#} + {#{{ form_errors(form.apply_date) }}#} + +
+ +
+
{{ TaxRule.id }} +
+
+ {{ form_widget(forms[TaxRule.id].tax_rate, {attr: {class: 'col-auto text-right'}}) }} +
+ % +
+ {{ form_errors(forms[TaxRule.id].tax_rate) }} +
+
+
+ {{ TaxRule.tax_rate }}% +
+
+
+ {{ form_widget(forms[TaxRule.id].rounding_type) }} +
+
+ {{ TaxRule.rounding_type }} +
+
+
+ {% if TaxRule.default_tax_rule %} + {{ 'admin.setting.shop.tax.base_rate_setting'|trans }} + {% else %} + {{ form_widget(forms[TaxRule.id].apply_date) }} + {{ form_errors(forms[TaxRule.id].apply_date) }} + {% endif %} +
+
+ {{ TaxRule.default_tax_rule ? 'admin.setting.shop.tax.base_rate_setting'|trans : TaxRule.apply_date|date_min }} +
+
+
+ + +
+
+
+
+
+ +
+ {% if not TaxRule.default_tax_rule %} +
+ + + +
+ + + {% endif %} +
+
+
+
+
+
+
+
+
+{% endblock %} From d90544ce940a82aa877ba1857c2249ead8c48476 Mon Sep 17 00:00:00 2001 From: Yuko Kajihara Date: Wed, 17 Feb 2021 15:30:40 +0900 Subject: [PATCH 02/36] =?UTF-8?q?=E5=AE=9A=E4=BC=91=E6=97=A5=E6=96=B0?= =?UTF-8?q?=E8=A6=8F=E7=99=BB=E9=8C=B2=E5=87=A6=E7=90=86=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Setting/Shop/CalendarController.php | 43 ++++++++++++++++--- src/Eccube/Entity/Calendar.php | 24 +++++++++++ src/Eccube/Event/EccubeEvents.php | 9 ++++ src/Eccube/Form/Type/Admin/CalendarType.php | 16 ++++++- src/Eccube/Resource/locale/messages.ja.yaml | 9 ++++ .../{calendar_rule.twig => calendar.twig} | 12 ++---- 6 files changed, 98 insertions(+), 15 deletions(-) rename src/Eccube/Resource/template/admin/Setting/Shop/{calendar_rule.twig => calendar.twig} (95%) diff --git a/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php b/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php index 30209802280..4fff0bf21c8 100644 --- a/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php +++ b/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php @@ -14,11 +14,14 @@ namespace Eccube\Controller\Admin\Setting\Shop; use Eccube\Controller\AbstractController; +use Eccube\Event\EccubeEvents; +use Eccube\Event\EventArgs; use Eccube\Form\Type\Admin\CalendarType; use Eccube\Repository\CalendarRepository; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Eccube\Entity\Calendar; /** * Class CalendarController @@ -44,20 +47,50 @@ public function __construct(CalendarRepository $calendarRepository) * カレンダー設定の初期表示・登録 * * @Route("/%eccube_admin_route%/setting/shop/calendar", name="admin_setting_shop_calendar") - //* @Route("/%eccube_admin_route%/setting/shop/calendar/new", name="admin_setting_shop_calendar_new") - * @Template("@admin/Setting/Shop/calendar_rule.twig") + * @Route("/%eccube_admin_route%/setting/shop/calendar/new", name="admin_setting_shop_calendar_new") + * @Template("@admin/Setting/Shop/calendar.twig") */ public function index(Request $request) { - - $Calendar = new \Eccube\Entity\Calendar(); + $Calendar = new Calendar(); $builder = $this->formFactory ->createBuilder(CalendarType::class, $Calendar); + $event = new EventArgs( + [ + 'builder' => $builder, + 'Calendar' => $Calendar, + ], + $request + ); + $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_CALENDAR_INDEX_INITIALIZE, $event); + $form = $builder->getForm(); - $form->handleRequest($request); + + $mode = $request->get('mode'); + if ($mode != 'edit_inline') { + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->persist($Calendar); + $this->entityManager->flush(); + + $event = new EventArgs( + [ + 'form' => $form, + 'Calendar' => $Calendar, + ], + $request + ); + $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_CALENDAR_INDEX_COMPLETE, $event); + + $this->addSuccess('admin.common.save_complete', 'admin'); + + return $this->redirectToRoute('admin_setting_shop_calendar'); + } + } return [ + 'Calendar' => $Calendar, 'form' => $form->createView(), ]; } diff --git a/src/Eccube/Entity/Calendar.php b/src/Eccube/Entity/Calendar.php index 7b9230d0301..38139dbfac7 100644 --- a/src/Eccube/Entity/Calendar.php +++ b/src/Eccube/Entity/Calendar.php @@ -113,6 +113,30 @@ public function getTitle() return $this->title; } + /** + * Set holiday. + * + * @param \DateTime $holiday + * + * @return Calendar + */ + public function setHoliday($holiday) + { + $this->holiday = $holiday; + + return $this; + } + + /** + * Get holiday. + * + * @return \DateTime + */ + public function getHoliday() + { + return $this->holiday; + } + /** * Set createDate. * diff --git a/src/Eccube/Event/EccubeEvents.php b/src/Eccube/Event/EccubeEvents.php index c3eb8cdf5e9..1fbc0ff8d80 100644 --- a/src/Eccube/Event/EccubeEvents.php +++ b/src/Eccube/Event/EccubeEvents.php @@ -337,6 +337,15 @@ final class EccubeEvents const ADMIN_SETTING_SHOP_TAX_RULE_EDIT_PARAMETER_INITIALIZE = 'admin.setting.shop.tax.rule.edit.parameter.initialize'; const ADMIN_SETTING_SHOP_TAX_RULE_EDIT_PARAMETER_COMPLETE = 'admin.setting.shop.tax.rule.edit.parameter.complete'; + /** + * Admin/Setting/Shop/CalendarController + */ + // index + const ADMIN_SETTING_SHOP_CALENDAR_INDEX_INITIALIZE = 'admin.setting.shop.calendar.index.initialize'; + const ADMIN_SETTING_SHOP_CALENDAR_INDEX_COMPLETE = 'admin.setting.shop.calendar.index.complete'; + // delete + const ADMIN_SETTING_SHOP_CALENDAR_DELETE_COMPLETE = 'admin.setting.shop.calendar.delete.complete'; + /** * Admin/Setting/System/AuthorityController */ diff --git a/src/Eccube/Form/Type/Admin/CalendarType.php b/src/Eccube/Form/Type/Admin/CalendarType.php index 479621df78d..665942e147c 100644 --- a/src/Eccube/Form/Type/Admin/CalendarType.php +++ b/src/Eccube/Form/Type/Admin/CalendarType.php @@ -16,6 +16,8 @@ use Eccube\Common\EccubeConfig; use Eccube\Repository\CalendarRepository; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints as Assert; @@ -54,7 +56,19 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]), ], ]) + ->add('holiday', DateType::class, [ + 'label' => 'admin.common.create_date__start', + 'required' => true, + 'input' => 'datetime', + 'widget' => 'single_text', + 'format' => 'yyyy-MM-dd', + 'placeholder' => ['year' => '----', 'month' => '--', 'day' => '--'], + 'attr' => [ + 'class' => 'datetimepicker-input', + 'data-target' => '#'.$this->getBlockPrefix().'_create_date_start', + 'data-toggle' => 'datetimepicker', + ], + ]) ; - } } diff --git a/src/Eccube/Resource/locale/messages.ja.yaml b/src/Eccube/Resource/locale/messages.ja.yaml index 2d6d3b38261..0070d35ebe3 100644 --- a/src/Eccube/Resource/locale/messages.ja.yaml +++ b/src/Eccube/Resource/locale/messages.ja.yaml @@ -1073,6 +1073,7 @@ admin.setting.shop.tax_setting: 税率設定 admin.setting.shop.mail_setting: メール設定 admin.setting.shop.csv_setting: CSV出力項目設定 admin.setting.shop.order_status_setting: 受注対応状況設定 +admin.setting.shop.calendar_setting: '定休日カレンダー設定' admin.setting.system: システム設定 admin.setting.system.member_management: メンバー管理 admin.setting.system.member_password_change: パスワード変更 @@ -1201,6 +1202,13 @@ admin.setting.shop.order_status.customer_order_status_name: 名称(マイペー admin.setting.shop.order_status.color: 色 admin.setting.shop.order_status.display_order_count: 件数表示 +#------------------------------------------------------------------------------------ +# 設定:店舗設定:受注対応状況設定 +#------------------------------------------------------------------------------------ + +admin.setting.shop.calendar.title: 'タイトル' +admin.setting.shop.calendar.holiday: '日付' + #------------------------------------------------------------------------------------ # 設定:システム設定:メンバー管理 / パスワード変更 #------------------------------------------------------------------------------------ @@ -1610,6 +1618,7 @@ tooltip.setting.shop.order_status.order_status: 受注管理およびマイペ tooltip.setting.shop.order_status.customer_order_status_name: 対応状況の名称を設定できます。ここで設定した名称は会員ログイン後のマイページで表示されます。 tooltip.setting.shop.order_status.color: 受注管理の対応状況の色を設定できます。 tooltip.setting.shop.order_status.display_order_count: 受注管理の対応状況ごとの受注件数の表示・非表示を設定できます。 +tooltip.setting.shop.calendar_setting: 定休日カレンダーに表示する定休日を設定できます。 tooltip.setting.system.member.authority: 権限管理で設定した権限を選択できます。 tooltip.setting.system.member.work: 一時的に非稼働にすることが可能です。必要ない場合はメンバー一覧より削除してください。 tooltip.setting.system.security.admin_url: 管理画面にログインするためのURLを指定します。推測されにくいURLを指定して下さい。 diff --git a/src/Eccube/Resource/template/admin/Setting/Shop/calendar_rule.twig b/src/Eccube/Resource/template/admin/Setting/Shop/calendar.twig similarity index 95% rename from src/Eccube/Resource/template/admin/Setting/Shop/calendar_rule.twig rename to src/Eccube/Resource/template/admin/Setting/Shop/calendar.twig index d8b915931df..a361acfb304 100644 --- a/src/Eccube/Resource/template/admin/Setting/Shop/calendar_rule.twig +++ b/src/Eccube/Resource/template/admin/Setting/Shop/calendar.twig @@ -71,14 +71,12 @@ file that was distributed with this source code. - {{ 'admin.common.id'|trans }} {{ 'admin.setting.shop.calendar.title'|trans }} {{ 'admin.setting.shop.calendar.holiday'|trans }} - @@ -86,7 +84,7 @@ file that was distributed with this source code.
- {#{{ form_widget(form._token) }}#} + {{ form_widget(form._token) }}
@@ -95,12 +93,8 @@ file that was distributed with this source code.
- bbb{#{{ form_widget(form.rounding_type) }}#} - {#{{ form_errors(form.rounding_type) }}#} - - - ccc{#{{ form_widget(form.apply_date) }}#} - {#{{ form_errors(form.apply_date) }}#} + {{ form_widget(form.holiday) }} + {{ form_errors(form.holiday) }} From 9688c917134519c03e1a9d1efef288819fc8c769 Mon Sep 17 00:00:00 2001 From: Yuko Kajihara Date: Wed, 17 Feb 2021 18:28:07 +0900 Subject: [PATCH 03/36] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=83=BB=E5=89=8A?= =?UTF-8?q?=E9=99=A4=E5=87=A6=E7=90=86=E3=81=BE=E3=81=A7=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Setting/Shop/CalendarController.php | 79 +++++--- src/Eccube/Event/EccubeEvents.php | 9 - src/Eccube/Repository/CalendarRepository.php | 50 +++++ .../template/admin/Setting/Shop/calendar.twig | 171 ++++++++---------- 4 files changed, 183 insertions(+), 126 deletions(-) diff --git a/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php b/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php index 4fff0bf21c8..1af81a12198 100644 --- a/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php +++ b/src/Eccube/Controller/Admin/Setting/Shop/CalendarController.php @@ -14,14 +14,12 @@ namespace Eccube\Controller\Admin\Setting\Shop; use Eccube\Controller\AbstractController; -use Eccube\Event\EccubeEvents; -use Eccube\Event\EventArgs; +use Eccube\Entity\Calendar; use Eccube\Form\Type\Admin\CalendarType; use Eccube\Repository\CalendarRepository; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; -use Eccube\Entity\Calendar; /** * Class CalendarController @@ -34,9 +32,9 @@ class CalendarController extends AbstractController protected $calendarRepository; /** - * TaxRuleController constructor. + * CalendarRepository constructor. * - * @param CalendarRepository $calendarRepository + * @param CalendarRepository $calendarRepository */ public function __construct(CalendarRepository $calendarRepository) { @@ -56,15 +54,6 @@ public function index(Request $request) $builder = $this->formFactory ->createBuilder(CalendarType::class, $Calendar); - $event = new EventArgs( - [ - 'builder' => $builder, - 'Calendar' => $Calendar, - ], - $request - ); - $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_CALENDAR_INDEX_INITIALIZE, $event); - $form = $builder->getForm(); $mode = $request->get('mode'); @@ -74,24 +63,68 @@ public function index(Request $request) $this->entityManager->persist($Calendar); $this->entityManager->flush(); - $event = new EventArgs( - [ - 'form' => $form, - 'Calendar' => $Calendar, - ], - $request - ); - $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_CALENDAR_INDEX_COMPLETE, $event); - $this->addSuccess('admin.common.save_complete', 'admin'); return $this->redirectToRoute('admin_setting_shop_calendar'); } } + // カレンダーリスト取得 + $Calendars = $this->calendarRepository->getList(); + + $forms = []; + $errors = []; + /** @var Calendar $Calendar */ + foreach ($Calendars as $Calendar) { + /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ + $builder = $this->formFactory->createBuilder(CalendarType::class, $Calendar); + + $editCalendarForm = $builder->getForm(); + + // error number + $error = 0; + if ($mode == 'edit_inline' + && $request->getMethod() === 'POST' + && (string) $Calendar->getId() === $request->get('calendar_id') + ) { + $editCalendarForm->handleRequest($request); + if ($editCalendarForm->isValid()) { + $calendarData = $editCalendarForm->getData(); + + $this->entityManager->persist($calendarData); + $this->entityManager->flush(); + + $this->addSuccess('admin.common.save_complete', 'admin'); + + return $this->redirectToRoute('admin_setting_shop_calendar'); + } + $error = count($editCalendarForm->getErrors(true)); + } + + $forms[$Calendar->getId()] = $editCalendarForm->createView(); + $errors[$Calendar->getId()] = $error; + } + return [ 'Calendar' => $Calendar, + 'Calendars' => $Calendars, 'form' => $form->createView(), + 'forms' => $forms, + 'errors' => $errors, ]; } + + /** + * カレンダー設定の削除 + * + * @Route("/%eccube_admin_route%/setting/shop/calendar/{id}/delete", requirements={"id" = "\d+"}, name="admin_setting_shop_calendar_delete", methods={"DELETE"}) + */ + public function delete(Request $request, Calendar $Calendar) + { + $this->isTokenValid(); + $this->calendarRepository->delete($Calendar); + $this->addSuccess('admin.common.delete_complete', 'admin'); + + return $this->redirectToRoute('admin_setting_shop_calendar'); + } } diff --git a/src/Eccube/Event/EccubeEvents.php b/src/Eccube/Event/EccubeEvents.php index 1fbc0ff8d80..c3eb8cdf5e9 100644 --- a/src/Eccube/Event/EccubeEvents.php +++ b/src/Eccube/Event/EccubeEvents.php @@ -337,15 +337,6 @@ final class EccubeEvents const ADMIN_SETTING_SHOP_TAX_RULE_EDIT_PARAMETER_INITIALIZE = 'admin.setting.shop.tax.rule.edit.parameter.initialize'; const ADMIN_SETTING_SHOP_TAX_RULE_EDIT_PARAMETER_COMPLETE = 'admin.setting.shop.tax.rule.edit.parameter.complete'; - /** - * Admin/Setting/Shop/CalendarController - */ - // index - const ADMIN_SETTING_SHOP_CALENDAR_INDEX_INITIALIZE = 'admin.setting.shop.calendar.index.initialize'; - const ADMIN_SETTING_SHOP_CALENDAR_INDEX_COMPLETE = 'admin.setting.shop.calendar.index.complete'; - // delete - const ADMIN_SETTING_SHOP_CALENDAR_DELETE_COMPLETE = 'admin.setting.shop.calendar.delete.complete'; - /** * Admin/Setting/System/AuthorityController */ diff --git a/src/Eccube/Repository/CalendarRepository.php b/src/Eccube/Repository/CalendarRepository.php index 55df5dc080c..24339ab50ec 100644 --- a/src/Eccube/Repository/CalendarRepository.php +++ b/src/Eccube/Repository/CalendarRepository.php @@ -13,6 +13,7 @@ namespace Eccube\Repository; +use Doctrine\ORM\NoResultException; use Eccube\Entity\Calendar; use Symfony\Bridge\Doctrine\RegistryInterface; @@ -49,4 +50,53 @@ public function get($id = 1) return $this->find($id); } + + /** + * getList + * + * @return array|null + */ + public function getList() + { + $qb = $this->createQueryBuilder('c') + ->orderBy('c.id', 'DESC') + //->where('t.Product IS NULL AND t.ProductClass IS NULL') + ; + $Calendars = $qb + ->getQuery() + ->getResult(); + + return $Calendars; + } + + /** + * delete. + * + * @param int|\Eccube\Entity\Calend $Calendar + * + * @throws NoResultException + */ + public function delete($Calendar) + { + if (!$Calendar instanceof Calendar) { + $Calendar = $this->find($Calendar); + } + if (!$Calendar) { + throw new NoResultException(); + } + $em = $this->getEntityManager(); + $em->remove($Calendar); + $em->flush(); + } + + /** + * Calendar のキャッシュをクリアする. + * + * getByRule() をコールすると、結果をキャッシュし、2回目以降はデータベースへアクセスしない. + * このメソッドをコールすると、キャッシュをクリアし、再度データベースを参照して結果を取得する. + */ + public function clearCache() + { + $this->rules = []; + } } diff --git a/src/Eccube/Resource/template/admin/Setting/Shop/calendar.twig b/src/Eccube/Resource/template/admin/Setting/Shop/calendar.twig index a361acfb304..1298416d208 100644 --- a/src/Eccube/Resource/template/admin/Setting/Shop/calendar.twig +++ b/src/Eccube/Resource/template/admin/Setting/Shop/calendar.twig @@ -36,16 +36,16 @@ file that was distributed with this source code. {% block javascript %}