diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2020-01-30 16:38:00 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2020-01-30 16:38:00 +0100 |
commit | de939de88e1ed166d827616e3d17a22fe549202a (patch) | |
tree | 5d11f11f5a337d37dff3f305ab35b7e0b3599c2d /app | |
parent | 0259be325a83e200913b3c9acd6700057f2035d9 (diff) | |
download | wcms-de939de88e1ed166d827616e3d17a22fe549202a.tar.gz wcms-de939de88e1ed166d827616e3d17a22fe549202a.zip |
home date title and manual update
Diffstat (limited to 'app')
-rw-r--r-- | app/class/Page.php | 74 | ||||
-rw-r--r-- | app/view/templates/home.php | 6 |
2 files changed, 37 insertions, 43 deletions
diff --git a/app/class/Page.php b/app/class/Page.php index 7475b6b..4d1a789 100644 --- a/app/class/Page.php +++ b/app/class/Page.php @@ -168,59 +168,23 @@ class Page extends Dbitem public function date($option = 'date') { - if ($option == 'string') { - return $this->date->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->date; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->date->diff($now)); - } elseif ($option == 'pdate') { - return $this->date->format('Y-m-d'); - } elseif ($option == 'ptime') { - return $this->date->format('H:i'); - } elseif ($option = 'dmy') { - return $this->date->format('d/m/Y'); - } - - + return $this->datetransform('date', $option); } public function datecreation($option = 'date') { - if ($option == 'string') { - return $this->datecreation->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->datecreation; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datecreation->diff($now)); - } + return $this->datetransform('datecreation', $option); } public function datemodif($option = 'date') { - if ($option == 'string') { - return $this->datemodif->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->datemodif; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->datemodif->diff($now)); - } + return $this->datetransform('datemodif', $option); } public function daterender($option = 'date') { - if ($option == 'string') { - return $this->daterender->format(DateTime::ISO8601); - } elseif ($option == 'date' || $option == 'sort') { - return $this->daterender; - } elseif ($option == 'hrdi') { - $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); - return hrdi($this->daterender->diff($now)); - } + return $this->datetransform('daterender', $option); } public function css($type = 'string') @@ -849,6 +813,36 @@ class Page extends Dbitem return $taglist; } + /** + * Tool for accessing different view of the same DateTimeImmutable var + * + * @param string $property DateTimeImmutable var to access + * @param string $option + * + * @return mixed string or false if propriety does not exist + */ + private function datetransform(string $property, string $option = 'date') + { + if(property_exists($this, $property)) { + if ($option == 'string') { + return $this->$property->format(DateTime::ISO8601); + } elseif ($option == 'date' || $option == 'sort') { + return $this->$property; + } elseif ($option == 'hrdi') { + $now = new DateTimeImmutable(null, timezone_open("Europe/Paris")); + return hrdi($this->$property->diff($now)); + } elseif ($option == 'pdate') { + return $this->$property->format('Y-m-d'); + } elseif ($option == 'ptime') { + return $this->$property->format('H:i'); + } elseif ($option = 'dmy') { + return $this->$property->format('d/m/Y'); + } + } else { + return false; + } + } + } diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 3ca4556..831282f 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -118,13 +118,13 @@ <td class="linkfrom"><a title="<?= $item->linkfrom('string') ?>"><?= $item->linkfrom('sort') ?></a></td> <?php } if ($columns['datemodif']) { ?> - <td class="datemodif"><?= $item->datemodif('hrdi') ?></td> + <td class="datemodif"><time datetime="<?= $item->datemodif('string') ?>" title="<?= $item->datemodif('dmy') . ' ' . $item->datemodif('ptime') ?>"><?= $item->datemodif('hrdi') ?></time></td> <?php } if ($columns['datecreation']) { ?> - <td class="datecreation"><?= $item->datecreation('hrdi') ?></td> + <td class="datecreation"><time datetime="<?= $item->datecreation('string') ?>" title="<?= $item->datecreation('dmy') . ' ' . $item->datecreation('ptime') ?>"><?= $item->datecreation('hrdi') ?></time></td> <?php } if ($columns['date']) { ?> - <td class="date"><?= $item->date('dmy') ?></td> + <td class="date"><time datetime="<?= $item->date('string') ?>" title="<?= $item->date('dmy') . ' ' . $item->date('ptime') ?>"><?= $item->date('dmy') ?></time></td> <?php } if ($columns['secure']) { ?> <td class="secure"><?= $opt->securelink($item->secure('int') , $item->secure('string')) ?></td> |