Skip to content

Commit

Permalink
Implement issue #4 - support translated and custom date formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
discordier committed Jul 3, 2013
1 parent c3058db commit 457fb54
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 18 deletions.
Expand Up @@ -11,6 +11,7 @@
* @subpackage AttributeTimestamp
* @author Stefan Heimes <stefan_heimes@hotmail.com>
* @author Andreas Isaak <info@andreas-isaak.de>
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
* @copyright The MetaModels team.
* @license LGPL.
* @filesource
Expand All @@ -23,6 +24,7 @@
* @subpackage AttributeTimestamp
* @author Stefan Heimes <stefan_heimes@hotmail.com>
* @author Andreas Isaak <info@andreas-isaak.de>
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
*/
class MetaModelAttributeTimestamp extends MetaModelAttributeNumeric
{
Expand All @@ -43,6 +45,44 @@ public function getAttributeSettingNames()
));
}

/**
* Prepare a template.
*
* @param MetaModelTemplate $objTemplate The template being prepared.
*
* @param array $arrRowData The row date of the item.
*
* @param IMetaModelRenderSettingAttribute $objSettings The render settings to use.
*
* @return void
*/
protected function prepareTemplate(MetaModelTemplate $objTemplate, $arrRowData, $objSettings = null)
{
parent::prepareTemplate($objTemplate, $arrRowData, $objSettings);

if ($objSettings->get('timeformat'))
{
$objTemplate->format = $objSettings->get('timeformat');
}
else
{
$strDateType = $this->get('timetype');
$strFormatName = (empty($strDateType) ? 'date' : $strDateType) . 'Format';
if ($GLOBALS['objPage'] && $GLOBALS['objPage']->$strFormatName)
{
$objTemplate->format = $GLOBALS['objPage']->$strFormatName;
}
else
{
$objTemplate->format = $GLOBALS['TL_CONFIG'][$strFormatName];
}
}
if ($objTemplate->raw !== null)
{
$objTemplate->parsedDate = MetaModelController::getInstance()->parseDate($objTemplate->format, $objTemplate->raw);
}
}

/**
* {@inheritdoc}
*/
Expand All @@ -66,4 +106,4 @@ public function widgetToValue($varValue, $intId)
return ($varValue === '')? null : $varValue;
}

}
}
Expand Up @@ -14,3 +14,11 @@
CREATE TABLE `tl_metamodel_attribute` (
`timetype` varchar(64) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Table `tl_metamodel_rendersetting`
--

CREATE TABLE `tl_metamodel_rendersetting` (
`timeformat` varchar(64) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -0,0 +1,35 @@
<?php

/**
* The MetaModels extension allows the creation of multiple collections of custom items,
* each with its own unique set of selectable attributes, with attribute extendability.
* The Front-End modules allow you to build powerful listing and filtering of the
* data in each collection.
*
* PHP version 5
* @package MetaModels
* @subpackage AttributeTimestamp
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
* @copyright The MetaModels team.
* @license LGPL.
* @filesource
*/

/**
* Table tl_metamodel_attribute
*/
$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['metapalettes']['timestamp extends default'] = array
(
'timesettings' => array('timeformat')
);

$GLOBALS['TL_DCA']['tl_metamodel_rendersetting']['fields']['timeformat'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['timeformat'],
'exclude' => true,
'inputType' => 'text',
'eval' => array
(
'tl_class' => 'w50'
)
);
@@ -0,0 +1,26 @@
<?php

/**
* The MetaModels extension allows the creation of multiple collections of custom items,
* each with its own unique set of selectable attributes, with attribute extendability.
* The Front-End modules allow you to build powerful listing and filtering of the
* data in each collection.
*
* PHP version 5
* @package MetaModels
* @subpackage AttributeTimestamp
* @author Christian Schiffler <c.schiffler@cyberspectrum.de>
* @copyright The MetaModels team.
* @license LGPL.
* @filesource
*/

/**
* Fields
*/
$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['timeformat'] = array('Format', 'Here you can define a custom date format. If empty, the default will be used. The format string will be parsed with the PHP date() function.');

/**
* Legends
*/
$GLOBALS['TL_LANG']['tl_metamodel_rendersetting']['timesettings_legend'] = 'Date and time settings';
@@ -1,5 +1 @@
<?php if($this->attribute->get('timetype') == 'date'):?>
<span class="text"><?php if ($this->raw !== null): ?><?php echo date($GLOBALS['TL_CONFIG']['dateFormat'], $this->raw); ?><?php endif; ?></span>
<?php elseif($this->attribute->get('timetype') == 'datim'): ?>
<span class="text"><?php if ($this->raw !== null): ?><?php echo date($GLOBALS['TL_CONFIG']['datimFormat'], $this->raw); ?><?php endif; ?></span>
<?php endif; ?>
<span class="text"><?php echo $this->parsedDate; ?></span>
@@ -1,7 +1 @@
<?php if ($this->raw !== null): ?>
<?php if($this->attribute->get('timetype') == 'date'):?>
<?php echo date($GLOBALS['TL_CONFIG']['dateFormat'], $this->raw); ?>
<?php elseif($this->attribute->get('timetype') == 'datim'): ?>
<?php echo date($GLOBALS['TL_CONFIG']['datimFormat'], $this->raw); ?>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->parsedDate; ?>
@@ -1,5 +1 @@
<?php if($this->attribute->get('timetype') == 'date'):?>
<span class="text"><?php if ($this->raw !== null): ?><?php echo date($GLOBALS['TL_CONFIG']['dateFormat'], $this->raw); ?><?php endif; ?></span>
<?php elseif($this->attribute->get('timetype') == 'datim'): ?>
<span class="text"><?php if ($this->raw !== null): ?><?php echo date($GLOBALS['TL_CONFIG']['datimFormat'], $this->raw); ?><?php endif; ?></span>
<?php endif; ?>
<span class="text"><?php echo $this->parsedDate; ?></span>

0 comments on commit 457fb54

Please sign in to comment.