template today now
This commit is contained in:
@@ -260,13 +260,20 @@ class Htmlizer
|
||||
|
||||
$data = $this->getDataFromEntity($entity, $skipLinks);
|
||||
|
||||
if (!array_key_exists('today', $data)) {
|
||||
$data['today'] = $this->dateTime->getTodayString();
|
||||
}
|
||||
|
||||
if (!array_key_exists('now', $data)) {
|
||||
$data['now'] = $this->dateTime->getNowString();
|
||||
}
|
||||
|
||||
foreach ($additionalData as $k => $value) {
|
||||
$data[$k] = $value;
|
||||
}
|
||||
|
||||
$html = $renderer($data);
|
||||
|
||||
|
||||
$html = str_replace('?entryPoint=attachment&', '?entryPoint=attachment&', $html);
|
||||
|
||||
if ($this->getEntityManager()) {
|
||||
|
||||
@@ -189,4 +189,38 @@ class DateTime
|
||||
{
|
||||
return date($this->getInternalDateFormat());
|
||||
}
|
||||
|
||||
public function getTodayString($timezone = null)
|
||||
{
|
||||
if ($timezone) {
|
||||
$timezoneObj = new \DateTimeZone($timezone);
|
||||
} else {
|
||||
$timezoneObj = $this->timezone;
|
||||
}
|
||||
|
||||
$dateTime = new \DateTime();
|
||||
$dateTime->setTimezone($timezoneObj);
|
||||
|
||||
return $dateTime->format($this->getPhpDateFormat());
|
||||
}
|
||||
|
||||
public function getNowString($timezone = null, $format = null)
|
||||
{
|
||||
if ($timezone) {
|
||||
$timezoneObj = new \DateTimeZone($timezone);
|
||||
} else {
|
||||
$timezoneObj = $this->timezone;
|
||||
}
|
||||
|
||||
$dateTime = new \DateTime();
|
||||
$dateTime->setTimezone($timezoneObj);
|
||||
|
||||
if ($format) {
|
||||
$phpFormat = $this->convertFormatToPhp($format);
|
||||
} else {
|
||||
$phpFormat = $this->getPhpDateTimeFormat();
|
||||
}
|
||||
|
||||
return $dateTime->format($phpFormat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
"pageOrientation": {
|
||||
"Portrait": "Portrait",
|
||||
"Landscape": "Landscape"
|
||||
},
|
||||
"placeholders": {
|
||||
"today": "Today (date)",
|
||||
"now": "Now (date-time)"
|
||||
}
|
||||
},
|
||||
"tooltips": {
|
||||
|
||||
@@ -86,12 +86,15 @@ Espo.define('views/template/fields/variables', 'views/fields/base', function (De
|
||||
|
||||
this.attributeList = attributeList;
|
||||
|
||||
attributeList.unshift('');
|
||||
if (!~this.attributeList.indexOf('now')) {
|
||||
this.attributeList.unshift('now');
|
||||
}
|
||||
|
||||
this.translatedOptions = {};
|
||||
attributeList.forEach(function (item) {
|
||||
this.translatedOptions[item] = this.translate(item, 'fields', entityType);
|
||||
}, this);
|
||||
if (!~this.attributeList.indexOf('today')) {
|
||||
this.attributeList.unshift('today');
|
||||
}
|
||||
|
||||
attributeList.unshift('');
|
||||
|
||||
var links = this.getMetadata().get('entityDefs.' + entityType + '.links') || {};
|
||||
|
||||
@@ -135,6 +138,12 @@ Espo.define('views/template/fields/variables', 'views/fields/base', function (De
|
||||
|
||||
var entityType = this.model.get('entityType');
|
||||
this.attributeList.forEach(function (item) {
|
||||
if (~['today', 'now'].indexOf(item)) {
|
||||
if (!this.getMetadata().get(['entityDefs', entityType, 'fields', item])) {
|
||||
this.translatedOptions[item] = this.getLanguage().translateOption(item, 'placeholders', 'Template');
|
||||
return;
|
||||
}
|
||||
}
|
||||
var field = item;
|
||||
var scope = entityType;
|
||||
var isForeign = false;
|
||||
|
||||
Reference in New Issue
Block a user