Commit 767a67a3 authored by Dirk Wildt's avatar Dirk Wildt

0.0.8

parent b04a5de3
......@@ -7,6 +7,7 @@ namespace Netzmacher\Tile\ViewHelpers\Get;
use Netzmacher\Tile\Domain\Repository\CategoryRepository;
use Netzmacher\Tile\Domain\Repository\CellRepository;
use Netzmacher\Tile\Domain\Repository\CssRepository;
use Netzmacher\Tile\Domain\Repository\GroupRepository;
use Netzmacher\Tile\Domain\Repository\TicketRepository;
use Netzmacher\Tile\Utility\ObjectUtility;
use Netzmacher\Tile\Utility\SessionUtility;
......@@ -29,7 +30,7 @@ class CellClassViewHelper extends AbstractViewHelper
* @var \Netzmacher\Tile\Domain\Model\Cell
*/
private $_cell = null;
/**
* Category Repository
*
......@@ -37,100 +38,205 @@ class CellClassViewHelper extends AbstractViewHelper
*/
private $_categoryRepository = null;
/**
* Prompts in context with static varibales. For development only
*
* @var boolean
*/
private $_promptStatic = true;
/**
* Session class
*
* @var Netzmacher\Tile\Utility\SessionUtility
*/
private static $_sessionUtility = null;
private $_sessionUtility = null;
/**
* @param string $class
* @param string $additionalClass
* @return mixed
*/
private function _getClassCategory()
private function _classConcatenator( $class, $additionalClass )
{
switch( true )
{
case( empty( $additionalClass )):
return $class;
case( empty( $class ) ):
return $additionalClass;
default:
return $class . ' ' . $additionalClass;
}
}
/**
* @return mixed
*/
private function _dontDisplayCategory()
{
static $display = null;
if( $display === false )
if( $display !== null )
{
return;
return $display;
}
$display = $this->_sessionUtility->getSessionElement( 'formCellWiCategories', false );
if( empty( $display ) )
{
$display = false;
$this->_promptStatic( __METHOD__, __LINE__ );
$display = true;
return $display;
}
//var_dump( __METHOD__, __LINE__, $display );
$this->_initCategoryRepository();
$uidCategory = $this->_cell->getTxTileCategory();
if( empty( $uidCategory ) )
$this->_promptStatic( __METHOD__, __LINE__ );
$display = false;
return $display;
}
/**
* @param string $formProperty
* @return mixed
*/
private function _dontDisplay( $formProperty )
{
static $display = null;
if( isset( $display[ $formProperty ] ) )
{
return;
return $display[ $formProperty ];
}
$category = $this->_categoryRepository->findByUid( $uidCategory );
$display[ $formProperty ] = $this->_sessionUtility->getSessionElement( $formProperty, false );
if( empty( $category ) )
$prompt = 'This prompt should display once only for display "' . $formProperty . '"! Check of static variables:';
$this->_promptStatic( __METHOD__, __LINE__, $prompt );
if( empty( $display[ $formProperty ] ) )
{
return;
$display[ $formProperty ] = true;
return $display[ $formProperty ];
}
$categoryCss = $category->getTxTileCss();
$categoryCssUid = $categoryCss->getUid();
$display[ $formProperty ] = false;
return $display[ $formProperty ];
}
$cssRepository = ObjectUtility::getObjectManager()->get( CssRepository::class );
$css = $cssRepository->findByUid( $categoryCssUid );
/**
* @param integer $uid
* @return \Netzmacher\Tile\Domain\Model\Category $category
*/
private function _getCategoryByUid( $uid ): \Netzmacher\Tile\Domain\Model\Category
{
static $categories = null;
var_dump( __METHOD__, __LINE__, $uidCategory );
var_dump( __METHOD__, __LINE__, 'Hier weiterarbeiten' );
die();
// return;
//
return $css->getClass();
if( isset( $categories[ $uid ] ) )
{
return $categories[ $uid ];
}
$categories[ $uid ] = $this->_categoryRepository->findByUid( $uid );
$prompt = 'This prompt should display once only for categorie "' . $categories[ $uid ]->getTitle() . '" (#' . $uid . ')! Check of static variables:';
$this->_promptStatic( __METHOD__, __LINE__, $prompt );
return $categories[ $uid ];
}
/**
* @param string $class
* @return mixed
*/
private function _getGroupCss()
private function _getClassCategory( $class )
{
static $display = null;
if( $this->_dontDisplay( 'formCellWiCategories' ) )
{
return $class;
}
if( $display === false )
$additionalClass = $this->_getClassCategoryOfCurrentCell();
return $this->_classConcatenator( $class, $additionalClass );
}
/**
* @return mixed
*/
private function _getClassCategoryOfCurrentCell()
{
$this->_initCategoryRepository();
$uid = ( int ) $this->_cell->getTxTileCategory();
if( empty( $uid ) )
{
return;
}
$display = $this->_sessionUtility->getSessionElement( 'formCellWiGroups', false );
if( empty( $display ) )
$category = $this->_getCategoryByUid( $uid );
if( empty( $category ) )
{
$display = false;
return;
}
var_dump( __METHOD__, __LINE__, $display );
return;
$default = $this->arguments[ 'default' ];
$class = $this->arguments[ 'class' ];
$uidCell = $this->arguments[ 'uidCell' ];
switch( true )
$strClass = $this->_getCssClassByCategory( $category, $uid );
return $strClass;
}
/**
* @param string $class
* @return mixed
*/
private function _getClassGroup( $class )
{
if( $this->_dontDisplay( 'formCellWiGroups' ) )
{
case( empty( $uidCell ) ):
case( empty( $class ) ):
return $default;
default :
// follow the workflow
break;
return $class;
}
$cssCell = ObjectUtility::getObjectManager()->get( CellRepository::class );
$cell = $cssCell->findByUid( $uidCell );
$additionalClass = $this->_cell->getGroupcss();
return $this->_classConcatenator( $class, $additionalClass );
}
if( empty( $cell ) )
/**
* @param \Netzmacher\Tile\Domain\Model\Category $category
* @param integer $uidCategory
* @return string
*/
private function _getCssClassByCategory( \Netzmacher\Tile\Domain\Model\Category $category, int $uidCategory ): string
{
static $classes = null;
//static $cssRepository = null;
if( isset( $classes[ $uidCategory ] ) )
{
return '';
return $classes[ $uidCategory ];
}
return $cell->getGroupcss();
$css = $category->getTxTileCss();
$classes[ $uidCategory ] = $css->getClass();
$prompt = 'This prompt should display once only for css class "' . $classes[ $uidCategory ] . '" (#' . $css->getUid() . ')! Check of static variables:';
$this->_promptStatic( __METHOD__, __LINE__, $prompt );
return $classes[ $uidCategory ];
}
/**
* @param \Netzmacher\Tile\Domain\Model\Group $group
* @return string
*/
private function _getCssClassByGroup( \Netzmacher\Tile\Domain\Model\Group $group ): string
{
static $classes = null;
$uidGroup = $group->getUid();
if( isset( $classes[ $uidGroup ] ) )
{
return $classes[ $uidGroup ];
}
$css = $group->getTxTileCss();
$classes[ $uidGroup ] = $css->getClass();
$prompt = 'This prompt should display once only for css class "' . $classes[ $uidGroup ] . '" (#' . $css->getUid() . ')! Check of static variables:';
$this->_promptStatic( __METHOD__, __LINE__, $prompt );
return $classes[ $uidGroup ];
}
/**
......@@ -209,7 +315,7 @@ class CellClassViewHelper extends AbstractViewHelper
*
* @return void
*/
private function _initCategoryRepository( )
private function _initCategoryRepository()
{
static $categoryRepository = null;
......@@ -218,11 +324,32 @@ class CellClassViewHelper extends AbstractViewHelper
$this->_categoryRepository = $categoryRepository;
return;
}
var_dump( __METHOD__, __LINE__ );
$categoryRepository = ObjectUtility::getObjectManager()->get( CategoryRepository::class );
// $categoryRepository = GeneralUtility::makeInstance( SessionUtility::class );
$this->_categoryRepository = $categoryRepository;
$this->_promptStatic( __METHOD__, __LINE__ );
}
/**
* Init the Group Repository once
*
* @return void
*/
private function _initGroupRepository()
{
static $groupRepository = null;
if( $groupRepository !== null )
{
$this->_groupRepository = $groupRepository;
return;
}
$groupRepository = ObjectUtility::getObjectManager()->get( GroupRepository::class );
$this->_groupRepository = $groupRepository;
$this->_promptStatic( __METHOD__, __LINE__ );
}
/**
......@@ -246,6 +373,25 @@ class CellClassViewHelper extends AbstractViewHelper
$sessionUtility = GeneralUtility::makeInstance( SessionUtility::class );
$this->_sessionUtility = $sessionUtility;
$this->_sessionUtility->setCData( $cData );
$this->_promptStatic( __METHOD__, __LINE__ );
}
/**
* Prompt in context with static variables
*
* @param string $method
* @param string $line
* @param string $prompt
*
* @return void
*/
private function _promptStatic( $method, $line, $prompt = 'This prompt should display once only! Check of static variables:' )
{
if( !$this->_promptStatic )
{
return;
}
echo '[#' . $line . '] ' . $prompt . ' @ ' . $method . ' (#' . $line . ')<br />' . PHP_EOL;
}
/**
......@@ -311,9 +457,9 @@ class CellClassViewHelper extends AbstractViewHelper
$this->_cell = $cell;
$this->_initSessionObject( $cData );
$class = $class . $this->_getClassCategory();
$class = $class . $this->_getGroupCss();
$class = $class . $this->_getProductCss();
$class = $this->_getClassCategory( $class );
$class = $this->_getClassGroup( $class );
//$class = $this->_getProductCss( $class );
//$class = $class . $this->_getUndefinedTileCss();
return $class;
......@@ -324,7 +470,7 @@ class CellClassViewHelper extends AbstractViewHelper
// case('cssClassForCategory'):
// return $this->_getClassCategory();
// case('cssClassForGroup'):
// return $this->_getGroupCss();
// return $this->_getClassGroup();
// case('cssClassForTicketCaddy'):
// return $this->_getProductCss( 'caddy' );
// case('cssClassForTicket'):
......
<?php
//declare(strict_types=1);
namespace Netzmacher\Tile\ViewHelpers\Get;
use Netzmacher\Tile\Domain\Repository\CategoryRepository;
use Netzmacher\Tile\Domain\Repository\CellRepository;
use Netzmacher\Tile\Domain\Repository\CssRepository;
use Netzmacher\Tile\Domain\Repository\TicketRepository;
use Netzmacher\Tile\Utility\ObjectUtility;
use Netzmacher\Tile\Utility\SessionUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class CellClassViewHelper
*
* @version 0.0.8
* @since 0.0.8
* @internal #t3816
*/
class CellClassViewHelper extends AbstractViewHelper
{
/**
* Current cell
*
* @var \Netzmacher\Tile\Domain\Model\Cell
*/
private $_cell = null;
/**
* Category Repository
*
* @var Netzmacher\Tile\Domain\Repository\CategoryRepository
*/
private $_categoryRepository = null;
/**
* Prompts in context with static varibales. For development only
*
* @var boolean
*/
private $_promptStatic = true;
/**
* Session class
*
* @var Netzmacher\Tile\Utility\SessionUtility
*/
private static $_sessionUtility = null;
/**
* @return mixed
*/
private function _getClassCategory()
{
if( $this->_dontDisplayCategory() )
{
return;
}
$class = $this->_getClassCategoryOfCurrentCell();
return $class;
}
/**
* @return mixed
*/
private function _getClassCategoryOfCurrentCell()
{
$this->_initCategoryRepository();
$uidCategory = $this->_cell->getTxTileCategory();
if( empty( $uidCategory ) )
{
return;
}
$category = $this->_getCategoryByUid( $uidCategory );
if( empty( $category ) )
{
return;
}
$categoryCss = $category->getTxTileCss();
$categoryCssUid = $categoryCss->getUid();
$cssRepository = ObjectUtility::getObjectManager()->get( CssRepository::class );
$css = $cssRepository->findByUid( $categoryCssUid );
var_dump( __METHOD__, __LINE__, $uidCategory );
var_dump( __METHOD__, __LINE__, 'Hier weiterarbeiten' );
die();
// return;
//
return $css->getClass();
}
/**
* @param integer $uid
* @return mixed
*/
private function _getCategoryByUid( $uid )
{
static $categories = null;
if( isset( $categories[ $uid ] ) )
{
return $categories[ $uid ];
}
$categories[ $uid ] = $this->categoryRepository->findByUid( $uid );
$prompt = 'This prompt should display once only for "' . $categories[ $uid ] . '"! Check of static variables:';
$this->_promptStatic( __METHOD__, __LINE__, $prompt );
return $categories[ $uid ];
}
/**
* @return mixed
*/
private function _getGroupCss()
{
static $display = null;
if( $display === false )
{
return;
}
$display = $this->_sessionUtility->getSessionElement( 'formCellWiGroups', false );
if( empty( $display ) )
{
$display = false;
}
var_dump( __METHOD__, __LINE__, $display );
return;
$default = $this->arguments[ 'default' ];
$class = $this->arguments[ 'class' ];
$uidCell = $this->arguments[ 'uidCell' ];
switch( true )
{
case( empty( $uidCell ) ):
case( empty( $class ) ):
return $default;
default :
// follow the workflow
break;
}
$cssCell = ObjectUtility::getObjectManager()->get( CellRepository::class );
$cell = $cssCell->findByUid( $uidCell );
if( empty( $cell ) )
{
return '';
}
return $cell->getGroupcss();
}
/**
* @param string $status: caddy | default | selled
* @return mixed
*/
private function _getProductCss( $status = 'default' )
{
$default = $this->arguments[ 'default' ];
$class = $this->arguments[ 'class' ];
$uid = $this->arguments[ 'uidTicket' ];
switch( true )
{
case( empty( $uid ) ):
case( empty( $class ) ):
return $default;
default :
// follow the workflow
break;
}
$ticketRepository = ObjectUtility::getObjectManager()->get( TicketRepository::class );
$ticket = $ticketRepository->findByUid( $uid );
if( empty( $ticket ) )
{
return null;
}
switch( $status )
{
case('caddy'):
$ticketCss = $ticket->getTxTileCsscaddy();
break;
case('default'):
$ticketCss = $ticket->getTxTileCssdefault();
break;
case('selled'):
$ticketCss = $ticket->getTxTileCssselled();
break;
default:
$prompt = 'Undefined value in switch @ ' . __METHOD__ . ' (#' . __LINE__ . ')';
die( $prompt );
}
if( empty( $ticketCss ) )
{
$this->_getProductCssPromptDie( __METHOD__, __LINE__, $ticket );
}
$ticketCssUid = $ticketCss->getUid();
$cssRepository = ObjectUtility::getObjectManager()->get( CssRepository::class );
$css = $cssRepository->findByUid( $ticketCssUid );
return $css->getClass();
}
/**
* @param string $method
* @param string $line
* @param string $ticket
* @return void
*/
private function _getProductCssPromptDie( $method, $line, $ticket )
{
$prompt = 'ERROR @ ' . $method . ' (#' . $line . ')<br />'
. '<br />'
. 'It seems, that a CSS class of the ticket with the uid #' . $ticket->getUid() . ' is empty.<br />'
. 'Please check the ticket!'
;
die( $prompt );
}
/**
* Init the Category Repository once
*
* @return void
*/
private function _initCategoryRepository()
{
static $categoryRepository = null;
if( $categoryRepository !== null )
{
$this->_categoryRepository = $categoryRepository;
return;
}
$categoryRepository = ObjectUtility::getObjectManager()->get( CategoryRepository::class );
$this->_categoryRepository = $categoryRepository;
$this->_promptStatic( __METHOD__, __LINE__ );
}
/**
* Init the session class once
*
* @param array $cData content data of current object
*
* @return void
*/
private function _initSessionObject( $cData )
{
static $sessionUtility = null;
if( $sessionUtility !== null )
{
$this->_sessionUtility = $sessionUtility;
$this->_sessionUtility->setCData( $cData );
return;
}
$sessionUtility = GeneralUtility::makeInstance( SessionUtility::class );
$this->_sessionUtility = $sessionUtility;
$this->_sessionUtility->setCData( $cData );
$this->_promptStatic( __METHOD__, __LINE__ );
}
/**
* @return mixed
*/
private function _dontDisplayCategory()
{
static $display = null;
if( $display === false )
{
return false;
}
$display = $this->_sessionUtility->getSessionElement( 'formCellWiCategories', false );
if( empty( $display ) )
{
$this->_promptStatic( __METHOD__, __LINE__ );
return false;
}
$this->_promptStatic( __METHOD__, __LINE__ );
return true;
}
/**
* Prompt in context with static variables
*
* @param string $method
* @param string $line
* @param string $prompt
*
* @return void
*/
private function _promptStatic( $method, $line, $prompt = 'This prompt should display once only! Check of static variables:' )
{
if( !$this->_promptStatic )
{
return;
}
echo '[#' . $line . '] ' . $prompt . ' @ ' . $method . ' (#' . $line . ')<br />' . PHP_EOL;
}
/**
* @param int $uid
* @return mixed
*/
private function _getProductCssSelled()
{
$default = $this->arguments[ 'default' ];
$class = $this->arguments[ 'class' ];
$uid = $this->arguments[ 'uidTicket' ];
switch( true )
{
case( empty( $uid ) ):
case( empty( $class ) ):
return $default;
default :
// follow the workflow
break;
}
$ticketRepository = ObjectUtility::getObjectManager()->get( TicketRepository::class );
$ticket = $ticketRepository->findByUid( $uid );
if( empty( $ticket ) )
{
return null;
}
$ticketCss = $ticket->getTxTileCss();
$ticketCssUid = $ticketCss->getUid();
$cssRepository = ObjectUtility::getObjectManager()->get( CssRepository::class );
$css = $cssRepository->findByUid( $ticketCssUid );
return $css->getClass();
}
/**
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument( 'cell', 'Netzmacher\Tile\Domain\Model\Cell', 'cell', false, null );
$this->registerArgument( 'cData', 'array', 'cData', false, null );
}
/**
* @return mixed
*/