Commit 978e3065 authored by Dirk Wildt's avatar Dirk Wildt

0.0.7

parent 68e64735
<?php
namespace Netzmacher\Tile\Controller;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/* * *************************************************************
* Copyright notice
*
* (c) 2019 - Dirk Wildt <http://wildt.at.die-netzmacher.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */
/**
* AbstractFrontendController for the tile extension
*
* @package TYPO3
* @subpackage tile
* @author Dirk Wildt <http://wildt.at.die-netzmacher.de>
* @version 0.0.7
* @since 0.0.7
* @internal #t3866
*/
class AbstractFrontendController extends AbstractController
{
/**
* @var Netzmacher\Tile\Utility\SessionUtility
*/
protected $_oSessionUtility;
/**
* _initObjectSession( ) :
*
* @return void
* @access private
* @version 0.0.7
* @since 0.0.7
*/
private function _initObjectSession()
{
$this->_oSessionUtility = GeneralUtility::makeInstance( 'Netzmacher\\Tile\\Utility\\SessionUtility' );
}
/**
* _getSessionSpace( ): Get the name of the session data space.
* The name is user, if a frontend user is logged in.
* The name is ses, if any frontend user isn't logged in.
*
* @return string user || ses
* @version 0.0.7
* @since 0.0.7
*/
protected function _getSessionSpace()
{
switch( $GLOBALS[ 'TSFE' ]->loginUser )
{
case( true ):
return 'user';
default:
return 'ses';
}
}
/**
* initObjects( ) :
*
* @return void
* @access private
* @version 0.0.7
* @since 0.0.7
*/
protected function _initObjects()
{
$this->_initObjectContent();
$this->_initObjectSession();
}
}
......@@ -4,7 +4,7 @@ namespace Netzmacher\Tile\Controller;
use Netzmacher\Tile\Utility\Module\AreaModuleUtility;
use Netzmacher\Tile\Utility\Module\CellModuleUtility;
use Netzmacher\Tile\Utility\Module\SessionModuleUtility;
use Netzmacher\Tile\Utility\SessionUtility;
/* * *
*
......@@ -21,118 +21,77 @@ use Netzmacher\Tile\Utility\Module\SessionModuleUtility;
* BookingController: frontend plugin for booking tiles
*
* @version 0.0.7
* @since 0.0.7
* @since 0.0.6
*/
class BookingController extends AbstractController
class BookingController extends AbstractFrontendController
{
/**
* _cellIsEmpty
* _cellIsSelled
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @return void
* @version 0.0.6
* @since 0.0.6
* @return boolean
* @version 0.0.7
* @since 0.0.7
*/
private function _cellIsEmpty( \Netzmacher\Tile\Domain\Model\Cell $cell )
private function _cellIsSelled( \Netzmacher\Tile\Domain\Model\Cell $cell ): bool
{
switch( true )
$product = $cell->getTxTileProduct();
if( $product->getStockquantity() > 0 )
{
case($cell->getTxTileGroup());
case($cell->getTxTileTicket());
return false;
default:
return true;
return false;
}
$this->addFlashMessage( 'Ticket ist bereits verkauft.', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR );
return true;
}
/**
* _cellModeIsGroup()
* _cellIsWoTicket
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @return boolean
* @version 0.0.6
* @since 0.0.6
* @internal #t3816
* @version 0.0.7
* @since 0.0.7
*/
private function _cellModeIsGroup()
private function _cellIsWoTicket( \Netzmacher\Tile\Domain\Model\Cell $cell ): bool
{
$mode = SessionModuleUtility::getFormCellMode();
switch( $mode )
if( $cell->getTxTileProduct() > 0 )
{
case('cell'):
return false;
case('group'):
return true;
default:
$prompt = 'Warning @ ' . __METHOD__ . ' (#' . __LINE__ . ')! Undefined value in switch: "' . $mode . '"';
$this->addFlashMessage( $prompt, '', \TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING );
return false;
return false;
}
$this->addFlashMessage( 'Objekt kann nicht gebucht werden: kein Ticket.', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::WARNING );
return true;
}
/**
* _cellRangeIsEditable
* _cellToggleCaddy
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @return void
* @version 0.0.6
* @since 0.0.6
* @return boolean
* @version 0.0.7
* @since 0.0.7
*/
private function _cellRangeIsEditable( \Netzmacher\Tile\Domain\Model\Cell $cell )
private function _cellToggleCaddy( \Netzmacher\Tile\Domain\Model\Cell $cell ): bool
{
switch( true )
{
case($this->_ticketIsNull()):
return true;
case($this->_cellRangeIsEmpty( $cell )):
return true;
default:
return false;
}
$this->addFlashMessage( 'Ticket in Warenkorb legen oder aus dem Warenkorb entfernen.', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::OK );
return true;
}
/**
* _cellRangeIsEmpty
* _getArea
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @return void
* @version 0.0.6
* @since 0.0.6
* @version 0.0.7
* @since 0.0.7
*/
private function _cellRangeIsEmpty( \Netzmacher\Tile\Domain\Model\Cell $cell )
private function _getArea()
{
// Mode: single cell
if( !$this->_cellModeIsGroup() )
{
if( $this->_cellIsEmpty( $cell ) )
{
return true;
}
return false;
}
// Mode: cell group
$formerCellUid = SessionModuleUtility::getValue( 'formerCellUid' );
// return, there is no former cell
if( empty( $formerCellUid ) )
{
return true;
}
$formerCell = $this->cellRepository->findByUid( $formerCellUid );
$xyRange = CellModuleUtility::getXsYsOrdered( $formerCell, $cell );
$cellUids = $this->cellRepository->getCellsByXyRange( $cell, $xyRange );
foreach( $cellUids as $cellUid )
{
$cell = $this->cellRepository->findByUid( $cellUid );
if( !$this->_cellIsEmpty( $cell ) )
{
return false;
}
}
return true;
$xmlFlexform = $this->contentObject->data[ 'pi_flexform' ];
$sheet = 'area';
$field = 'settings.flexform.pi1.area.uid';
$areaUid = $this->_getFlexformValue( __METHOD__, __LINE__, $xmlFlexform, $sheet, $field );
$area = $this->areaRepository->findByUid( $areaUid );
return $area;
}
/**
......@@ -150,280 +109,18 @@ class BookingController extends AbstractController
}
/**
* _getTicketTitle()
*
* @param integer $uid
*
* @return \Netzmacher\Tile\Domain\Model\Ticket
* @version 0.0.6
* @since 0.0.6
* @internal #t3812
*/
private function _getTicketTitle( $uid )
{
$ticket = $this->ticketRepository->findByUid( $uid );
if( !is_object( $ticket ) )
{
return;
}
return $ticket->getTitle();
}
/**
* _getTickets()
*
* @return \Netzmacher\Tile\Domain\Model\Category
* @version 0.0.6
* @since 0.0.6
* @internal #t3812
*/
private function _getTickets()
{
$returnArray = [];
$defaultOrderings = [
'title' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
];
$this->ticketRepository->setDefaultOrderings( $defaultOrderings );
$tickets = $this->ticketRepository->findAll();
foreach( $tickets as $ticket )
{
$returnArray[ $ticket->getUid() ] = $ticket->getTitle();
}
return $returnArray;
}
/**
* _promptCellRangeIsNotEmpty
*
* @return void
* @version 0.0.6
* @since 0.0.6
*/
private function _promptCellRangeIsNotEmpty()
{
$header = '';
$prompt = 'Tickets können nicht überschrieben werden.';
$this->addFlashMessage( $prompt, $header, \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR );
$header = '';
$prompt = 'Bitte leere den Bereich, bevor Du diesem ein neues Ticket zuweist.';
$this->addFlashMessage( $prompt, $header, \TYPO3\CMS\Core\Messaging\AbstractMessage::INFO );
}
/**
* _resetCellsByDeprecatedGroups()
*
* @param array $groups
* @return void
* @version 0.0.6
* @since 0.0.6
* @internal #t3816
*/
private function _resetCellsByDeprecatedGroups( array $groups )
{
switch( true )
{
case(empty( $groups ) ):
$prompt = 'Warning @ ' . __METHOD__ . ' (#' . __LINE__ . ')! Groups are empty.';
$this->addFlashMessage( $prompt, 'ERROR', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR );
return;
case(!$this->_ticketIsNull() ):
// Do nothing
return;
case( $this->_ticketIsNull() ):
$groups = array_unique( $groups );
foreach( $groups as $group )
{
if( empty( $group ) )
{
continue;
}
$cellUids = $this->cellRepository->getCellsByGroup( $group );
foreach( $cellUids as $cellUid )
{
$cell = $this->cellRepository->findByUid( $cellUid );
$this->_setTicketForCell( $cell );
$this->_setGroupForCell( $cell, $group );
$this->cellRepository->update( $cell );
}
}
return;
}
}
/**
* _removeDeprecatedGroups()
*
* @param array $groups
* @return void
* @version 0.0.6
* @since 0.0.6
* @internal #t3816
*/
private function _removeDeprecatedGroups( array $groups )
{
switch( true )
{
case(empty( $groups ) ):
$prompt = 'Warning @ ' . __METHOD__ . ' (#' . __LINE__ . ')! Groups are empty.';
$this->addFlashMessage( $prompt, 'ERROR', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR );
return;
case(!$this->_ticketIsNull() ):
// Do nothing
return;
case( $this->_ticketIsNull() ):
$this->groupRepository->removeGroups( $groups );
return;
}
}
/**
* _setGroupForCell()
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @param \Netzmacher\Tile\Domain\Model\Group $group
* @return mixed
* @version 0.0.6
* @since 0.0.6
* @internal #t3816
*/
private function _setGroupForCell( \Netzmacher\Tile\Domain\Model\Cell $cell, \Netzmacher\Tile\Domain\Model\Group $group = null )
{
switch( true )
{
case(!$this->_ticketIsNull() ):
if( empty( $group ) )
{
// Create a new group and set it
$group = new \Netzmacher\Tile\Domain\Model\Group();
$title = $cell->getTitle();
$group->setTitle( $title );
}
$group->setTxTileCell( ( int ) $group->getTxTileCell() + 1 );
$cell->setTxTileGroup( $group );
break;
case( $this->_ticketIsNull() ):
// Remove the group of the current cell from the current cell
$group = $cell->getTxTileGroup();
$cell->removeTxTileGroup( $group );
break;
}
return $group;
}
/**
* _setGroupTitle()
*
* @param \Netzmacher\Tile\Domain\Model\Group $group
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @param array $xyRange
* @return mixed
* @version 0.0.6
* @since 0.0.6
* @internal #t3816
*/
private function _setGroupTitle( $cell, $xyRange, $group = null )
{
if( empty( $group ) )
{
return;
}
$range = 'x' . $xyRange[ 'minX' ] . 'y' . $xyRange[ 'minY' ] . '-x' . $xyRange[ 'maxX' ] . 'y' . $xyRange[ 'maxY' ];
$title = $cell->getTxTileArea()->getTitle() . ' ' . $range;
$group->setTitle( $title );
}
/**
* _setTicketForCell()
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
*
* @return void
* @version 0.0.6
* @since 0.0.6
* @internal #t3816
*/
private function _setTicketForCell( \Netzmacher\Tile\Domain\Model\Cell $cell )
{
$cell->setTxTileTicket( SessionModuleUtility::getFormCellTicket() );
$cell->setGroupcss( SessionModuleUtility::getFormCellMode() );
$this->cellRepository->update( $cell );
return;
}
/**
* _setTicketForCells()
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* initializeAction: is executed before any Action in the Controller.
*
* @return void
* @version 0.0.6
* @since 0.0.6
* @internal #t3816
*/
private function _setTicketForCells( \Netzmacher\Tile\Domain\Model\Cell $cell )
{
$group = $this->_setGroupForCell( $cell );
$groups[] = $group;
if( !$this->_cellModeIsGroup() )
{
$this->_setTicketForCell( $cell );
$this->_resetCellsByDeprecatedGroups( $groups );
$this->_removeDeprecatedGroups( $groups );
return;
}
$formerCellUid = SessionModuleUtility::getValue( 'formerCellUid' );
// return: there is no former cell, any range isn't possible
if( empty( $formerCellUid ) )
{
SessionModuleUtility::setValue( 'formerCellUid', $cell->getUid() );
return;
}
$formerCell = $this->cellRepository->findByUid( $formerCellUid );
SessionModuleUtility::removeValue( 'formerCellUid' );
$xyRange = CellModuleUtility::getXsYsOrdered( $formerCell, $cell );
$cellUids = $this->cellRepository->getCellsByXyRange( $cell, $xyRange );
foreach( $cellUids as $cellUid )
{
$cell = $this->cellRepository->findByUid( $cellUid );
$cell->setTxTileTicket( SessionModuleUtility::getFormCellTicket() );
$cell->setGroupcss( SessionModuleUtility::getFormCellMode(), $xyRange, $cell );
$groups[] = $this->_setGroupForCell( $cell, $group );
$this->cellRepository->update( $cell );
}
$this->_setGroupTitle( $cell, $xyRange, $group );
if( !empty( $group ) )
{
$group->setTxTileCell( ( int ) $group->getTxTileCell() - 1 );
}
$this->_resetCellsByDeprecatedGroups( $groups );
$this->_removeDeprecatedGroups( $groups );
}
/**
* _ticketIsNull
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @return void
* @version 0.0.6
* @since 0.0.6
* @version 0.0.3
* @since 0.0.3
* @internal #t3728
*/
private function _ticketIsNull()
public function initializeAction()
{
if( SessionModuleUtility::getFormCellTicket() == 0 )
{
return true;
}
return false;
$this->_initObjects();
$this->_oSessionUtility->setCData( $this->contentObject->data );
$this->_oSessionUtility->setSession();
}
/**
......@@ -436,139 +133,51 @@ class BookingController extends AbstractController
*/
public function listAction()
{
//\Netzmacher\Tile\Domain\Model\Area $area
// $this->initObjects();
$xmlFlexform = $this->contentObject->data['pi_flexform'];
$sheet = 'area';
$field = 'settings.flexform.pi1.area.uid';
$areaUid = $this->_getFlexformValue( __METHOD__, __LINE__, $xmlFlexform, $sheet, $field );
$area = $this->areaRepository->findByUid($areaUid);
// var_dump( __METHOD__, __LINE__, $this->contentObject->data, $areaUid );
// die();
$ticketTitle = $this->_getTicketTitle( SessionModuleUtility::getFormCellTicket() );
if( empty( $ticketTitle ) )
{
$ticketTitle = 'Zurücksetzen';
}
$formCellModeSelected = SessionModuleUtility::getFormCellMode();
if( empty( $formCellModeSelected ) )
{
$formCellModeSelected = 'cell';
}
$formCellModeOptions = [
'cell' => 'Kachel',
'group' => 'Gruppe'
];
$currentModeLabel = $formCellModeOptions[ SessionModuleUtility::getFormCellMode() ];
if( empty( $currentModeLabel ) )
{
$currentModeLabel = 'Kachel';
}
$formCellTicketOptions = [ 0 => 'Zurücksetzen' ] + ( array ) $this->_getTickets();
$formCellTicketSelected = SessionModuleUtility::getFormCellTicket();
$formCellWiBgimageChecked = SessionModuleUtility::getFormCellWiBgimage( true );
$formCellWiCategoriesChecked = SessionModuleUtility::getFormCellWiCategories( true );
$formCellWiGroupsChecked = SessionModuleUtility::getFormCellWiGroups( true );
$formCellWiTicketsChecked = SessionModuleUtility::getFormCellWiTickets( true );
$formCellWiUndefinedCellsChecked = SessionModuleUtility::getFormCellWiUndefinedCells( true );
$area = $this->_getArea();
$this->view->assign( 'area', $area );
$this->view->assign( 'ticketTitle', $ticketTitle );
$this->view->assign( 'cells', $this->_getAreaCells( $area ) );
$this->view->assign( 'currentModeLabel', $currentModeLabel );
$this->view->assign( 'formCellModeOptions', $formCellModeOptions );
$this->view->assign( 'formCellModeSelected', $formCellModeSelected );
$this->view->assign( 'formCellTicketOptions', $formCellTicketOptions );
$this->view->assign( 'formCellTicketSelected', $formCellTicketSelected );
$this->view->assign( 'formCellWiBgimageChecked', $formCellWiBgimageChecked );
$this->view->assign( 'formCellWiCategoriesChecked', $formCellWiCategoriesChecked );
$this->view->assign( 'formCellWiGroupsChecked', $formCellWiGroupsChecked );
$this->view->assign( 'formCellWiTicketsChecked', $formCellWiTicketsChecked );
$this->view->assign( 'formCellWiUndefinedCellsChecked', $formCellWiUndefinedCellsChecked );
$this->view->assign( 'grid-template-columns', AreaModuleUtility::getAutoElementsForGridCSS( $area ) );
$this->view->assign( 'size', '15' );
}
/**
* initializeAction: is executed before any Action in the Controller.
*
* @return void
* @version 0.0.3
* @since 0.0.3
* @internal #t3728
*/
public function initializeAction()
{
$this->_initObjectContent();
SessionModuleUtility::setSession();
$this->view->assignMultiple(
array(
'area' => $area
, 'cells' => $this->_getAreaCells( $area )
, 'formCellWiBgimageChecked' => $this->_oSessionUtility->getSessionElement( 'formCellWiBgimage', false )
, 'formCellWiCategoriesChecked' => $this->_oSessionUtility->getSessionElement( 'formCellWiCategories', false )
, 'formCellWiGroupsChecked' => $this->_oSessionUtility->getSessionElement( 'formCellWiGroups', true )
, 'formCellWiTicketsChecked' => $this->_oSessionUtility->getSessionElement( 'formCellWiTickets', true )
, 'formCellWiUndefinedCellsChecked' => $this->_oSessionUtility->getSessionElement( 'formCellWiUndefinedCells', true )
, 'grid-template-columns' => AreaModuleUtility::getAutoElementsForGridCSS( $area )
, 'size' => '15'
)
);
}
/**
* updatecell
* caddy
*
* @param \Netzmacher\Tile\Domain\Model\Cell $cell
* @param \Netzmacher\Tile\Domain\Model\Area $area
* @return void
* @version 0.0.6
* @since 0.0.1
* @version 0.0.7
* @since 0.0.7
*/
public function updatecellAction( \Netzmacher\Tile\Domain\Model\Cell $cell )
public function caddyAction( \Netzmacher\Tile\Domain\Model\Cell $cell, \Netzmacher\Tile\Domain\Model\Area $area )
{
switch( $this->_cellRangeIsEditable( $cell ) )
switch( true )
{
case(true):
$this->_setTicketForCells( $cell );
case($this->_cellIsWoTicket( $cell )):
break;
case($this->_cellIsSelled( $cell )):
break;
case($this->_cellToggleCaddy( $cell )):
break;
case(false):
default:
$this->_promptCellRangeIsNotEmpty();
SessionModuleUtility::removeValue( 'formerCellUid' );
$this->addFlashMessage( 'Undefinierter Fehler @ ' . __METHOD__ . ' (#' . __LINE__ . ')', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR );
break;
}
$area = $this->request->getArgument( 'area' );
$arguments = [
'area' => $area
];
$this->redirect( 'list', NULL, NULL, $arguments );
}
/**
* flexformAreaRecord
*
* @return array item array for a flexform
* @return array
* @version 0.0.6
* @since 0.0.1
*/
public function flexformAreaRecord( &$params )
{
$params[ 'items' ][] = [ '', '', '' ];
$rows = $this->areaRepository->getAreasCloned();
foreach( ( array ) $rows as $row )
{
// if not clone
// continue;
if( $row[ 'type' ] != 1 )
{
continue;
}
$params[ 'items' ][] = [
$row[ 'title' ]
, $row[ 'uid' ]
, 'typo3/sysext/core/Resources/Public/Icons/T3Icons/mimetypes/mimetypes-x-content-plugin.svg'
];
}
// var_dump( __METHOD__, __LINE__, $rows );
// die();
array_multisort( array_column( $params[ 'items' ], 0 ), SORT_ASC, $params[ 'items' ] );
return $params;
}
}
......@@ -37,11 +37,25 @@ class Ticket extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
protected $title = '';