Skip to content

Commit

Permalink
SImplify formatting of DateTime for display.
Browse files Browse the repository at this point in the history
  • Loading branch information
EreMaijala committed Sep 4, 2024
1 parent f29a508 commit 59a5442
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
54 changes: 54 additions & 0 deletions module/VuFind/src/VuFind/View/Helper/Root/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ class Config extends \Laminas\View\Helper\AbstractHelper
*/
protected $configLoader;

/**
* Display date format
*
* @var ?string
*/
protected $displayDateFormat = null;

/**
* Display time format
*
* @var ?string
*/
protected $displayTimeFormat = null;

/**
* Config constructor.
*
Expand Down Expand Up @@ -140,4 +154,44 @@ public function offcanvasSide(): ?string
? 'left'
: 'right';
}

/**
* Get date display format
*
* @return string
*/
public function dateFormat(): string
{
if (null === $this->displayDateFormat) {
$config = $this->get('config');
$this->displayDateFormat = $config->Site->displayDateFormat ?? 'm-d-Y';
}
return $this->displayDateFormat;
}

/**
* Get time display format
*
* @return string
*/
public function timeFormat(): string
{
if (null === $this->displayTimeFormat) {
$config = $this->get('config');
$this->displayTimeFormat = $config->Site->displayTimeFormat ?? 'H:i';
}
return $this->displayTimeFormat;
}

/**
* Get date+time display format
*
* @param string $separator String between date and time
*
* @return string
*/
public function dateTimeFormat($separator = ' '): string
{
return $this->dateFormat() . $separator . $this->timeFormat();
}
}
4 changes: 2 additions & 2 deletions themes/bootstrap3/templates/admin/feedback/home.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ $this->headTitle($this->translate('VuFind Administration - Feedback Management')
<strong><?=$this->escapeHtml($key)?></strong>: <?=$this->escapeHtml($value)?><br>
<?php endforeach; ?>
<strong><?=$this->transEsc('Created')?></strong>:
<?=$this->escapeHtml($this->dateTime()->convertToDisplayDateAndTime('Y-m-d H:i:s', $feedbackEntity->getCreated()->format('Y-m-d H:i:s')))?>
<?=$this->escapeHtml($feedbackEntity->getCreated()->format($this->config()->dateTimeFormat()))?>
<?=$feedbackItem['user_name'] ? (' ' . $this->transEsc('by') . ' ' . $this->escapeHtml($feedbackItem['user_name']) . ' (' . $feedbackEntity->getUser()->getId() . ')') : ''?>
<br>
<strong><?=$this->transEsc('Updated')?></strong>:
<?=$this->escapeHtml($this->dateTime()->convertToDisplayDateAndTime('Y-m-d H:i:s', $feedbackEntity->getUpdated()->format('Y-m-d H:i:s')))?>
<?=$this->escapeHtml($feedbackEntity->getUpdated()->format($this->config()->dateTimeFormat()))?>
<?=$feedbackItem['manager_name'] ? (' ' . $this->transEsc('by') . ' ' . $this->escapeHtml($feedbackItem['manager_name']) . ' (' . $feedbackEntity->getUpdatedBy() . ')') : ''?>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/bootstrap3/templates/record/comments-list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="comment-name">
<strong><?=null === $comment->getUser()->getId() ? $this->transEsc('comment_anonymous_user') : $this->escapeHtml(trim($comment->getUser()->getFirstName() . ' ' . $comment->getUser()->getLastName()))?></strong><br>
<small>
<?=$this->escapeHtml($comment->getCreated()->format('Y-m-d H:i:s'))?>
<?=$this->escapeHtml($comment->getCreated()->format($this->config()->dateTimeFormat()))?>
<?php if (($user = $this->auth()->getUserObject()) && $comment->getUser()->getId() == $user->id): ?>
<a href="<?=$this->escapeHtmlAttr($this->recordLinker()->getActionUrl($this->driver, 'DeleteComment', ['delete' => $comment->getId()]))?>" id="recordComment<?=$this->escapeHtml($comment->getId())?>" class="delete"><?=$this->transEsc('Delete')?></a>
<?php endif; ?>
Expand Down
4 changes: 2 additions & 2 deletions themes/bootstrap5/templates/admin/feedback/home.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ $this->headTitle($this->translate('VuFind Administration - Feedback Management')
<strong><?=$this->escapeHtml($key)?></strong>: <?=$this->escapeHtml($value)?><br>
<?php endforeach; ?>
<strong><?=$this->transEsc('Created')?></strong>:
<?=$this->escapeHtml($this->dateTime()->convertToDisplayDateAndTime('Y-m-d H:i:s', $feedbackEntity->getCreated()->format('Y-m-d H:i:s')))?>
<?=$this->escapeHtml($feedbackEntity->getCreated()->format($this->config()->dateTimeFormat()))?>
<?=$feedbackItem['user_name'] ? (' ' . $this->transEsc('by') . ' ' . $this->escapeHtml($feedbackItem['user_name']) . ' (' . $feedbackEntity->getUser()->getId() . ')') : ''?>
<br>
<strong><?=$this->transEsc('Updated')?></strong>:
<?=$this->escapeHtml($this->dateTime()->convertToDisplayDateAndTime('Y-m-d H:i:s', $feedbackEntity->getUpdated()->format('Y-m-d H:i:s')))?>
<?=$this->escapeHtml($feedbackEntity->getUpdated()->format($this->config()->dateTimeFormat()))?>
<?=$feedbackItem['manager_name'] ? (' ' . $this->transEsc('by') . ' ' . $this->escapeHtml($feedbackItem['manager_name']) . ' (' . $feedbackEntity->getUpdatedBy() . ')') : ''?>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion themes/bootstrap5/templates/record/comments-list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="comment-name">
<strong><?=null === $comment->getUser()->getId() ? $this->transEsc('comment_anonymous_user') : $this->escapeHtml(trim($comment->getUser()->getFirstName() . ' ' . $comment->getUser()->getLastName()))?></strong><br>
<small>
<?=$this->escapeHtml($comment->getCreated()->format('Y-m-d H:i:s'))?>
<?=$this->escapeHtml($comment->getCreated()->format($this->config()->dateTimeFormat()))?>
<?php if (($user = $this->auth()->getUserObject()) && $comment->getUser()->getId() == $user->id): ?>
<a href="<?=$this->escapeHtmlAttr($this->recordLinker()->getActionUrl($this->driver, 'DeleteComment', ['delete' => $comment->getId()]))?>" id="recordComment<?=$this->escapeHtml($comment->getId())?>" class="delete"><?=$this->transEsc('Delete')?></a>
<?php endif; ?>
Expand Down

0 comments on commit 59a5442

Please sign in to comment.