This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:heimrichhannot/contao-isotope-bundle
- Loading branch information
Showing
20 changed files
with
565 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) 2018 Heimrich & Hannot GmbH | ||
* | ||
* @license LGPL-3.0-or-later | ||
*/ | ||
|
||
namespace HeimrichHannot\IsotopeBundle\Controller; | ||
|
||
use Contao\CoreBundle\Framework\ContaoFrameworkInterface; | ||
use HeimrichHannot\IsotopeBundle\Attribute\BookingAttributes; | ||
use HeimrichHannot\IsotopeBundle\Model\ProductModel; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
/** | ||
* @Route("/contao/isotope_bundle", defaults={ | ||
* "_scope" = "backend", | ||
* "_token_check" = true | ||
* }) | ||
*/ | ||
class BackendController extends AbstractController | ||
{ | ||
const ROUTE = '/contao/isotope_bundle'; | ||
|
||
/** | ||
* @Route("/bookinglist", name="huh.isotope.backend.bookinglist") | ||
* @Template("@HeimrichHannotContaoIsotope/backend/bookinglist.html.twig") | ||
* | ||
* @param Request $request | ||
* @param ContaoFrameworkInterface $contaoFramework | ||
* @param BookingAttributes $bookingAttributes | ||
* @param TranslatorInterface $translator | ||
* | ||
* @return array | ||
*/ | ||
public function bookingListAction(Request $request, ContaoFrameworkInterface $contaoFramework, BookingAttributes $bookingAttributes, TranslatorInterface $translator) | ||
{ | ||
if (!$contaoFramework->isInitialized()) { | ||
$contaoFramework->initialize(); | ||
} | ||
$id = $request->get('id'); | ||
if (!is_numeric($id) | !$product = ProductModel::findById($id)) { | ||
return ['error' => $translator->trans('Invalid id')]; | ||
} | ||
$day = is_numeric($request->get('day')) ? (int) $request->get('day') : date('d'); | ||
$month = is_numeric($request->get('month')) ? (int) $request->get('month') : date('n'); | ||
$year = is_numeric($request->get('year')) ? (int) $request->get('year') : date('Y'); | ||
$orders = $bookingAttributes->getOrdersWithBookingsByDay($product, $day, $month, $year); | ||
$date = mktime(0, 0, 0, $month, $day, $year); | ||
|
||
return [ | ||
'product' => $product, | ||
'orders' => $orders, | ||
'tstamp' => $date, | ||
]; | ||
} | ||
|
||
/** | ||
* @Route("/bookingoverview", name="huh.isotope.backend.bookingoverview") | ||
* @Template("@HeimrichHannotContaoIsotope/attribute/bookingoverview.html.twig") | ||
* | ||
* @param Request $request | ||
* @param ContaoFrameworkInterface $contaoFramework | ||
* @param BookingAttributes $bookingAttributes | ||
* @param TranslatorInterface $translator | ||
* | ||
* @return array | ||
*/ | ||
public function bookingOverviewAction(Request $request, ContaoFrameworkInterface $contaoFramework, BookingAttributes $bookingAttributes, TranslatorInterface $translator) | ||
{ | ||
$id = $request->get('id'); | ||
if (!is_numeric($id) | !$product = ProductModel::findById($id)) { | ||
return ['error' => $translator->trans('Invalid id')]; | ||
} | ||
$bookings = $bookingAttributes->getBookingCountsByMonth($product, date('n'), date('Y')); | ||
$year = is_numeric($request->get('year')) ? (int) $request->get('year') : date('Y'); | ||
$month = is_numeric($request->get('month')) ? (int) $request->get('month') : date('n'); | ||
$date = mktime(0, 0, 0, $month, 1, $year); | ||
|
||
return [ | ||
'bookings' => $bookings, | ||
'product' => $product, | ||
'time' => $date, | ||
]; | ||
} | ||
} |
Oops, something went wrong.