Skip to content

Commit

Permalink
Change the date format of the Last Access and Last Edit fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ericras authored Oct 7, 2024
1 parent f3ac576 commit 66f50e0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Form/UnlMultisiteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'site_id' => array('#plain_text' => (isset($site->site_id) ? $site->site_id : null)),
'primary_base_url' => array('#plain_text' => (!empty($site->primary_base_url) ? $site->primary_base_url : 'Not set')),
'd7_site_id' => array('#plain_text' => (isset($site->d7_site_id) ? $site->d7_site_id : 'Not set')),
'access' => array('#plain_text' => (isset($site->access) ? $site->access : 0)),
'access' => array('#plain_text' => (isset($site->access) ? $site->access : '')),
'last_edit' => array('#plain_text' => (isset($site->last_edit) ? $site->last_edit : '')),
'site_admin' => array('#markup' => (isset($site->site_admin) ? $site->site_admin : 'No Site admin')),
'installed' => array('#plain_text' => $this->_unl_get_install_status_text($site->installed)),
Expand Down Expand Up @@ -177,13 +177,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$sort = TableSort::getsort($header, $this->request);
$rows = $this->unl_sites_sort($rows, $order, $sort);
// Now that the access timestamp has been used to sort, convert it to something readable
foreach ($rows as $key=>$row) {
$rows[$key]['access'] = array('#plain_text' =>
isset($row['access']) && $row['access']['#plain_text'] > 0
? t('@time ago', array('@time' => \Drupal::service("date.formatter")->formatInterval(REQUEST_TIME - $row['access']['#plain_text'])))
: t('never')
);
}
// foreach ($rows as $key=>$row) {
// $rows[$key]['access'] = array('#plain_text' =>
// isset($row['access']) && $row['access']['#plain_text'] > 0
// ? t('@time ago', array('@time' => \Drupal::service("date.formatter")->formatInterval(REQUEST_TIME - $row['access']['#plain_text'])))
// : t('never')
// );
// }

foreach ($rows as $key => $row) {
$form['unl_sites'][$key] = $row;
Expand Down Expand Up @@ -265,11 +265,11 @@ function unl_add_extra_site_info(&$sites) {
$primary_base_url = 'Not set';
}
// Retrieve the last accessed date by a Site Admin.
$access = $database_connection->query("SELECT u.access FROM {users_field_data} u, {user__roles} r WHERE u.uid = r.entity_id AND u.access > 0 AND r.roles_target_id = 'site_admin' ORDER BY u.access DESC");
$access = $database_connection->query("SELECT FROM_UNIXTIME(MAX(u.access), '%Y-%m-%d') FROM {users_field_data} u, {user__roles} r WHERE u.uid = r.entity_id AND u.access > 0 AND r.roles_target_id = 'site_admin' ORDER BY u.access DESC");
$access = $access->fetchField();

//Retrieve the last edited node date.
$site_last_edit = $database_connection->query("SELECT FROM_UNIXTIME(MAX(changed)) AS most_recent_node_update FROM node_field_data");
$site_last_edit = $database_connection->query("SELECT FROM_UNIXTIME(MAX(changed), '%Y-%m-%d') AS most_recent_node_update FROM node_field_data");
$site_last_edit = $site_last_edit->fetchField();

// Retrieve the site's users with the site_admin role.
Expand All @@ -282,7 +282,7 @@ function unl_add_extra_site_info(&$sites) {

$row->primary_base_url = $primary_base_url;
$row->name = $name;
$row->access = (int) $access;
$row->access = $access;
$row->last_edit = $site_last_edit;
$row->site_admin = $site_admin_list;
}
Expand Down

0 comments on commit 66f50e0

Please sign in to comment.