Skip to content

Commit

Permalink
#40 MINFO works for new model classes
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Apr 14, 2016
1 parent bbb19d7 commit 5ad0953
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
33 changes: 33 additions & 0 deletions Classes/Frontend/Marker/BaseMarker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright notice
*
* (c) 2016 René Nitzsche <[email protected]>
* 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!
*/

/**
*
* @package TYPO3
* @subpackage rn_base
* @author René Nitzsche <[email protected]>
*/
class Tx_Rnbase_Frontend_Marker_BaseMarker {

}
67 changes: 67 additions & 0 deletions Classes/Frontend/Marker/Utility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright notice
*
* (c) 2016 René Nitzsche <[email protected]>
* 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!
*/

/**
*
* @package TYPO3
* @subpackage rn_base
* @author René Nitzsche <[email protected]>
*/
class Tx_Rnbase_Frontend_Marker_Utility {
/**
* Returns an array with all attribute names not used in template
*
* @param Tx_Rnbase_Domain_Model_Data $item
* @param string $template
* @param string $marker
* @return array
*/
public static function findUnusedAttributes(Tx_Rnbase_Domain_Model_Data $item, $template, $marker) {
$ignore = array();
$minfo = self::containsMarker($template, $marker.'___MINFO');
$minfoArr = array();
foreach($item As $key=>$value) {
if($minfo) {
$minfoArr[$key] = $marker.'_'.strtoupper($key);
}
if(!self::containsMarker($template, $marker.'_'.strtoupper($key)))
$ignore[] = $key;
}
if($minfo) {
tx_rnbase::load('tx_rnbase_util_Debug');
$item->setProperty('__MINFO', tx_rnbase_util_Debug::viewArray($minfoArr));
}
return $ignore;

}

/**
* @param string $template
* @param string $markerPrefix a string like MATCH_HOME
* @return boolean
*/
public static function containsMarker($template, $markerPrefix) {
return (strpos($template, '###'.$markerPrefix) !== FALSE);
}
}
6 changes: 4 additions & 2 deletions util/class.tx_rnbase_util_BaseMarker.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

tx_rnbase::load('tx_rnbase_util_Misc');
tx_rnbase::load('tx_rnbase_util_Templates');

tx_rnbase::load('Tx_Rnbase_Frontend_Marker_BaseMarker');


/**
* Base class for Markers.
*/
class tx_rnbase_util_BaseMarker {
class tx_rnbase_util_BaseMarker extends Tx_Rnbase_Frontend_Marker_BaseMarker {
private $defaultMarkerArr = array();
/** Array for dummy objects */
private static $emptyObjects = array();
Expand Down Expand Up @@ -109,6 +109,7 @@ public function initTSLabelMarkers(&$formatter, $confId, $marker, $defaultMarker
* @param string $template
* @param string $marker
* @return array
* @deprecated use Tx_Rnbase_Frontend_Marker_Utility::findUnusedAttributes
*/
public static function findUnusedCols(&$record, $template, $marker) {
$ignore = array();
Expand All @@ -128,6 +129,7 @@ public static function findUnusedCols(&$record, $template, $marker) {
return $ignore;
}


protected static $token = '';
/**
* Returns a token string.
Expand Down
6 changes: 5 additions & 1 deletion util/class.tx_rnbase_util_SimpleMarker.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
***************************************************************/

tx_rnbase::load('tx_rnbase_util_BaseMarker');
tx_rnbase::load('Tx_Rnbase_Frontend_Marker_Utility');

/**
* A generic marker class.
Expand Down Expand Up @@ -57,7 +58,10 @@ public function parseTemplate($template, &$item, &$formatter, $confId, $marker)
$template = $this->prepareTemplate($template, $item, $formatter, $confId, $marker);

// Es wird das MarkerArray mit den Daten des Records gefüllt.
$ignore = self::findUnusedCols($item->getRecord(), $template, $marker);
// TODO: Der instancof-Check ist nicht schon. Der Typ des Models sollte besser konfiguriert werden, oder?
$ignore = $item instanceof Tx_Rnbase_Domain_Model_Data ?
Tx_Rnbase_Frontend_Marker_Utility::findUnusedAttributes($item, $template, $marker) :
self::findUnusedCols($item->getRecord(), $template, $marker);
$markerArray = $formatter->getItemMarkerArrayWrapped($item->getRecord(), $confId , $ignore, $marker.'_', $item->getColumnNames());

// subparts erzeugen
Expand Down

0 comments on commit 5ad0953

Please sign in to comment.