aboutsummaryrefslogtreecommitdiff
path: root/app/class/user.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2019-08-09 02:56:29 +0200
committervincent-peugnet <v.peugnet@free.fr>2019-08-09 02:56:29 +0200
commit49f827b172dd3c07e3c4562a261557feb1ef03f6 (patch)
treec24e1ff26ccfcd4451de660e5307353b5d787b02 /app/class/user.php
parent87ca0b50e624feacd2caff2057c5ebfb62a7977f (diff)
downloadwcms-49f827b172dd3c07e3c4562a261557feb1ef03f6.tar.gz
wcms-49f827b172dd3c07e3c4562a261557feb1ef03f6.zip
Feature : Users may expire
- user have expiredate - admins can set up this date
Diffstat (limited to 'app/class/user.php')
-rw-r--r--app/class/user.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/class/user.php b/app/class/user.php
index 7a05f7b..ba3dfea 100644
--- a/app/class/user.php
+++ b/app/class/user.php
@@ -10,6 +10,7 @@ class User
protected $cookie = 0;
protected $columns = ['title', 'datemodif', 'datecreation', 'secure', 'visitcount'];
protected $connectcount = 0;
+ protected $expiredate = false;
public function __construct($datas = [])
{
@@ -85,6 +86,33 @@ class User
return $this->connectcount;
}
+ public function expiredate(string $type = 'string')
+ {
+ if ($type == 'string') {
+ if(!empty($this->expiredate)) {
+ return $this->expiredate->format('Y-m-d');
+ } else {
+ return false;
+ }
+ } elseif ($type == 'date') {
+ if(!empty($this->expiredate)) {
+ return $this->expiredate;
+ } else {
+ return false;
+ }
+ } elseif ($type == 'hrdi') {
+ if(empty($this->expiredate)) {
+ return 'never';
+ } else {
+ $now = new DateTimeImmutable(null, timezone_open("Europe/Paris"));
+ if($this->expiredate < $now) {
+ return 'expired';
+ } else {
+ return hrdi($this->expiredate->diff($now));
+ }
+ }
+ }
+ }
// _______________________ S E T _______________________
@@ -148,6 +176,15 @@ class User
}
}
+ public function setexpiredate($expiredate)
+ {
+ if ($expiredate instanceof DateTimeImmutable) {
+ $this->expiredate = $expiredate;
+ } else {
+ $this->expiredate = DateTimeImmutable::createFromFormat('Y-m-d', $expiredate, new DateTimeZone('Europe/Paris'));
+ }
+ }
+