chg: [UI] Use date helper

pull/8281/head
Jakub Onderka 2022-04-16 22:55:24 +02:00
parent dbc244f860
commit 559e51e8e0
4 changed files with 16 additions and 4 deletions

View File

@ -1974,8 +1974,6 @@ class AttributesController extends AppController
$result = $this->Attribute->shortDist[$result];
} elseif ($field === 'to_ids') {
$result = ($result == 0 ? 'No' : 'Yes');
} elseif ($field === 'timestamp') {
$result = date('Y-m-d', $result);
} elseif ($field === 'value') {
$this->loadModel('Warninglist');
$attribute['Attribute'] = $this->Warninglist->checkForWarning($attribute['Attribute']);

View File

@ -1,6 +1,8 @@
<?php
if ($field === 'value') {
echo $this->element('Events/View/value_field', ['object' => $object['Attribute']]);
} elseif ($field === 'timestamp') {
echo $this->Time->date($value);
} else {
if ($value === 'No') {
echo '<input type="checkbox" disabled>';

View File

@ -73,7 +73,7 @@ $quickEdit = function($fieldName) use ($editScope, $object, $event) {
</td>
<td class="short">
<div id="Attribute_<?= $objectId ?>_timestamp_solid">
<?= date('Y-m-d', $object['timestamp']) ?>
<?= $this->Time->date($object['timestamp']) ?>
</div>
</td>
<?php
@ -102,7 +102,6 @@ $quickEdit = function($fieldName) use ($editScope, $object, $event) {
endif;
endif;
?>
&nbsp;
</td>
<td class="short"<?= $quickEdit('category') ?>>
<div id="Attribute_<?= $objectId ?>_category_solid" class="inline-field-solid">

View File

@ -26,4 +26,17 @@ class TimeHelper extends AppHelper
return '<time>' . h($time) . '</time>';
}
/**
* @param int $date
* @return string
*/
public function date($date)
{
if (empty($date)) {
return '';
}
$date = date('Y-m-d', $date);
return '<time>' . h($date) . '</time>';
}
}