Continued work on getter/setters: timestamps
This commit is contained in:
parent
a619662585
commit
16942d9d19
20 changed files with 68 additions and 37 deletions
|
@ -10,7 +10,7 @@ class AddCommentJob extends AbstractJob
|
||||||
$comment = CommentModel::spawn();
|
$comment = CommentModel::spawn();
|
||||||
$comment->setCommenter($user);
|
$comment->setCommenter($user);
|
||||||
$comment->setPost($post);
|
$comment->setPost($post);
|
||||||
$comment->setDateTime(time());
|
$comment->setCreationTime(time());
|
||||||
$comment->setText($text);
|
$comment->setText($text);
|
||||||
|
|
||||||
CommentModel::save($comment);
|
CommentModel::save($comment);
|
||||||
|
|
|
@ -6,7 +6,7 @@ class AddUserJob extends AbstractJob
|
||||||
$firstUser = UserModel::getCount() == 0;
|
$firstUser = UserModel::getCount() == 0;
|
||||||
|
|
||||||
$user = UserModel::spawn();
|
$user = UserModel::spawn();
|
||||||
$user->joinDate = time();
|
$user->setJoinTime(time());
|
||||||
$user->staffConfirmed = $firstUser;
|
$user->staffConfirmed = $firstUser;
|
||||||
UserModel::forgeId($user);
|
UserModel::forgeId($user);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class EditCommentJob extends AbstractJob
|
||||||
{
|
{
|
||||||
$comment = $this->comment;
|
$comment = $this->comment;
|
||||||
|
|
||||||
$comment->setDateTime(time());
|
$comment->setCreationTime(time());
|
||||||
$comment->setText($this->getArgument(self::TEXT));
|
$comment->setText($this->getArgument(self::TEXT));
|
||||||
|
|
||||||
CommentModel::save($comment);
|
CommentModel::save($comment);
|
||||||
|
|
|
@ -18,7 +18,7 @@ class PreviewCommentJob extends AbstractJob
|
||||||
}
|
}
|
||||||
|
|
||||||
$comment->setCommenter($user);
|
$comment->setCommenter($user);
|
||||||
$comment->setDateTime(time());
|
$comment->setCreationTime(time());
|
||||||
$comment->setText($text);
|
$comment->setText($text);
|
||||||
|
|
||||||
$comment->validate();
|
$comment->validate();
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Mailer
|
||||||
$token->setUser($user);
|
$token->setUser($user);
|
||||||
$token->setText(TokenModel::forgeUnusedToken());
|
$token->setText(TokenModel::forgeUnusedToken());
|
||||||
$token->setUsed(false);
|
$token->setUsed(false);
|
||||||
$token->setExpirationDate(null);
|
$token->setExpirationTime(null);
|
||||||
TokenModel::save($token);
|
TokenModel::save($token);
|
||||||
|
|
||||||
$tokens['link'] = \Chibi\Router::linkTo($linkDestination, ['tokenText' => $token->getText()]);
|
$tokens['link'] = \Chibi\Router::linkTo($linkDestination, ['tokenText' => $token->getText()]);
|
||||||
|
|
|
@ -12,7 +12,7 @@ final class CommentModel extends AbstractCrudModel
|
||||||
public static function spawn()
|
public static function spawn()
|
||||||
{
|
{
|
||||||
$comment = new CommentEntity;
|
$comment = new CommentEntity;
|
||||||
$comment->setDateTime(time());
|
$comment->setCreationTime(time());
|
||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ final class CommentModel extends AbstractCrudModel
|
||||||
$bindings = [
|
$bindings = [
|
||||||
'text' => $comment->getText(),
|
'text' => $comment->getText(),
|
||||||
'post_id' => $comment->getPostId(),
|
'post_id' => $comment->getPostId(),
|
||||||
'comment_date' => $comment->getDateTime(),
|
'comment_date' => $comment->getCreationTime(),
|
||||||
'commenter_id' => $comment->getCommenterId()];
|
'commenter_id' => $comment->getCommenterId()];
|
||||||
|
|
||||||
$stmt = new Sql\UpdateStatement();
|
$stmt = new Sql\UpdateStatement();
|
||||||
|
|
|
@ -20,7 +20,7 @@ final class CommentEntity extends AbstractEntity implements IValidatable
|
||||||
if (!$this->getPostId())
|
if (!$this->getPostId())
|
||||||
throw new SimpleException('Trying to save comment that doesn\'t refer to any post');
|
throw new SimpleException('Trying to save comment that doesn\'t refer to any post');
|
||||||
|
|
||||||
if (!$this->getDateTime())
|
if (!$this->getCreationTime())
|
||||||
throw new SimpleException('Trying to save comment that has no creation date specified');
|
throw new SimpleException('Trying to save comment that has no creation date specified');
|
||||||
|
|
||||||
$this->setText($text);
|
$this->setText($text);
|
||||||
|
@ -61,14 +61,14 @@ final class CommentEntity extends AbstractEntity implements IValidatable
|
||||||
$this->postId = $post->getId();
|
$this->postId = $post->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDateTime()
|
public function getCreationTime()
|
||||||
{
|
{
|
||||||
return $this->commentDate;
|
return $this->commentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDateTime($dateTime)
|
public function setCreationTime($unixTime)
|
||||||
{
|
{
|
||||||
$this->commentDate = $dateTime;
|
$this->commentDate = $unixTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCommenter()
|
public function getCommenter()
|
||||||
|
|
|
@ -12,11 +12,12 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
protected $mimeType;
|
protected $mimeType;
|
||||||
protected $safety;
|
protected $safety;
|
||||||
protected $hidden;
|
protected $hidden;
|
||||||
public $uploadDate;
|
protected $uploadDate;
|
||||||
protected $imageWidth;
|
protected $imageWidth;
|
||||||
protected $imageHeight;
|
protected $imageHeight;
|
||||||
protected $uploaderId;
|
protected $uploaderId;
|
||||||
protected $source;
|
protected $source;
|
||||||
|
|
||||||
public $commentCount = 0;
|
public $commentCount = 0;
|
||||||
public $favCount = 0;
|
public $favCount = 0;
|
||||||
public $score = 0;
|
public $score = 0;
|
||||||
|
@ -199,6 +200,16 @@ class PostEntity extends AbstractEntity implements IValidatable
|
||||||
$this->hidden = boolval($hidden);
|
$this->hidden = boolval($hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCreationTime()
|
||||||
|
{
|
||||||
|
return $this->uploadDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreationTime($unixTime)
|
||||||
|
{
|
||||||
|
$this->uploadDate = $unixTime;
|
||||||
|
}
|
||||||
|
|
||||||
public function getImageWidth()
|
public function getImageWidth()
|
||||||
{
|
{
|
||||||
return $this->imageWidth;
|
return $this->imageWidth;
|
||||||
|
|
|
@ -31,14 +31,14 @@ class TokenEntity extends AbstractEntity implements IValidatable
|
||||||
$this->used = $used;
|
$this->used = $used;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getExpirationDate()
|
public function getExpirationTime()
|
||||||
{
|
{
|
||||||
return $this->expires;
|
return $this->expires;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setExpirationDate($time)
|
public function setExpirationTime($unixTime)
|
||||||
{
|
{
|
||||||
$this->expires = $time;
|
$this->expires = $unixTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUser()
|
public function getUser()
|
||||||
|
|
|
@ -10,8 +10,8 @@ class UserEntity extends AbstractEntity implements IValidatable
|
||||||
public $staffConfirmed;
|
public $staffConfirmed;
|
||||||
protected $emailUnconfirmed;
|
protected $emailUnconfirmed;
|
||||||
protected $emailConfirmed;
|
protected $emailConfirmed;
|
||||||
public $joinDate;
|
protected $joinDate;
|
||||||
public $lastLoginDate;
|
protected $lastLoginDate;
|
||||||
protected $accessRank;
|
protected $accessRank;
|
||||||
public $settings;
|
public $settings;
|
||||||
protected $banned = false;
|
protected $banned = false;
|
||||||
|
@ -33,7 +33,6 @@ class UserEntity extends AbstractEntity implements IValidatable
|
||||||
throw new Exception('Trying to save anonymous user into database');
|
throw new Exception('Trying to save anonymous user into database');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function validateUserName()
|
protected function validateUserName()
|
||||||
{
|
{
|
||||||
$userName = $this->getName();
|
$userName = $this->getName();
|
||||||
|
@ -103,6 +102,7 @@ class UserEntity extends AbstractEntity implements IValidatable
|
||||||
return $accessRank;
|
return $accessRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isBanned()
|
public function isBanned()
|
||||||
{
|
{
|
||||||
return $this->banned;
|
return $this->banned;
|
||||||
|
@ -128,6 +128,26 @@ class UserEntity extends AbstractEntity implements IValidatable
|
||||||
$this->name = trim($name);
|
$this->name = trim($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getJoinTime()
|
||||||
|
{
|
||||||
|
return $this->joinDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJoinTime($unixTime)
|
||||||
|
{
|
||||||
|
$this->joinDate = $unixTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLastLoginTime()
|
||||||
|
{
|
||||||
|
return $this->lastLoginDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLastLoginTime($unixTime)
|
||||||
|
{
|
||||||
|
$this->lastLoginDate = $unixTime;
|
||||||
|
}
|
||||||
|
|
||||||
public function getUnconfirmedEmail()
|
public function getUnconfirmedEmail()
|
||||||
{
|
{
|
||||||
return $this->emailUnconfirmed;
|
return $this->emailUnconfirmed;
|
||||||
|
|
|
@ -27,7 +27,7 @@ class PostModel extends AbstractCrudModel
|
||||||
$post = new PostEntity;
|
$post = new PostEntity;
|
||||||
$post->setSafety(new PostSafety(PostSafety::Safe));
|
$post->setSafety(new PostSafety(PostSafety::Safe));
|
||||||
$post->setHidden(false);
|
$post->setHidden(false);
|
||||||
$post->uploadDate = time();
|
$post->setCreationTime(time());
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
$post->setName(md5(mt_rand() . uniqid()));
|
$post->setName(md5(mt_rand() . uniqid()));
|
||||||
|
@ -53,7 +53,7 @@ class PostModel extends AbstractCrudModel
|
||||||
'mime_type' => $post->getMimeType(),
|
'mime_type' => $post->getMimeType(),
|
||||||
'safety' => $post->getSafety()->toInteger(),
|
'safety' => $post->getSafety()->toInteger(),
|
||||||
'hidden' => $post->isHidden(),
|
'hidden' => $post->isHidden(),
|
||||||
'upload_date' => $post->uploadDate,
|
'upload_date' => $post->getCreationTime(),
|
||||||
'image_width' => $post->getImageWidth(),
|
'image_width' => $post->getImageWidth(),
|
||||||
'image_height' => $post->getImageHeight(),
|
'image_height' => $post->getImageHeight(),
|
||||||
'uploader_id' => $post->getUploaderId(),
|
'uploader_id' => $post->getUploaderId(),
|
||||||
|
|
|
@ -21,7 +21,7 @@ class TokenModel extends AbstractCrudModel
|
||||||
'user_id' => $token->getUserId(),
|
'user_id' => $token->getUserId(),
|
||||||
'token' => $token->getText(),
|
'token' => $token->getText(),
|
||||||
'used' => $token->isUsed(),
|
'used' => $token->isUsed(),
|
||||||
'expires' => $token->getExpirationDate(),
|
'expires' => $token->getExpirationTime(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$stmt = new Sql\UpdateStatement();
|
$stmt = new Sql\UpdateStatement();
|
||||||
|
@ -64,7 +64,7 @@ class TokenModel extends AbstractCrudModel
|
||||||
if ($token->isUsed())
|
if ($token->isUsed())
|
||||||
throw new SimpleException('This token was already used');
|
throw new SimpleException('This token was already used');
|
||||||
|
|
||||||
if ($token->getExpirationDate() !== null and time() > $token->getExpirationDate())
|
if ($token->getExpirationTime() !== null and time() > $token->getExpirationTime())
|
||||||
throw new SimpleException('This token has expired');
|
throw new SimpleException('This token has expired');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ class UserModel extends AbstractCrudModel
|
||||||
'staff_confirmed' => $user->staffConfirmed,
|
'staff_confirmed' => $user->staffConfirmed,
|
||||||
'email_unconfirmed' => $user->getUnconfirmedEmail(),
|
'email_unconfirmed' => $user->getUnconfirmedEmail(),
|
||||||
'email_confirmed' => $user->getConfirmedEmail(),
|
'email_confirmed' => $user->getConfirmedEmail(),
|
||||||
'join_date' => $user->joinDate,
|
'join_date' => $user->getJoinTime(),
|
||||||
'last_login_date' => $user->lastLoginDate,
|
'last_login_date' => $user->getLastLoginTime(),
|
||||||
'access_rank' => $user->getAccessRank()->toInteger(),
|
'access_rank' => $user->getAccessRank()->toInteger(),
|
||||||
'settings' => $user->settings,
|
'settings' => $user->settings,
|
||||||
'banned' => $user->isBanned(),
|
'banned' => $user->isBanned(),
|
||||||
|
|
|
@ -32,8 +32,8 @@ Assets::addScript('comment-edit.js');
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="date" title="<?= TextHelper::formatDate($this->context->comment->getDateTime(), true) ?>">
|
<span class="date" title="<?= TextHelper::formatDate($this->context->comment->getCreationTime(), true) ?>">
|
||||||
<?= TextHelper::formatDate($this->context->comment->getDateTime(), false) ?>
|
<?= TextHelper::formatDate($this->context->comment->getCreationTime(), false) ?>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<?php if (Access::check(new Privilege(
|
<?php if (Access::check(new Privilege(
|
||||||
|
|
|
@ -109,8 +109,8 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<br>
|
<br>
|
||||||
<span class="date"
|
<span class="date"
|
||||||
title="<?= TextHelper::formatDate($this->context->transport->post->uploadDate, true) ?>">
|
title="<?= TextHelper::formatDate($this->context->transport->post->getCreationTime(), true) ?>">
|
||||||
<?= TextHelper::formatDate($this->context->transport->post->uploadDate, false) ?>
|
<?= TextHelper::formatDate($this->context->transport->post->getCreationTime(), false) ?>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,8 @@ if (Auth::getCurrentUser()->hasEnabledEndlessScrolling())
|
||||||
</a>
|
</a>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div class="date-registered" title="<?= TextHelper::formatDate($user->joinDate, true) ?>">
|
<div class="date-registered" title="<?= TextHelper::formatDate($user->getJoinTime(), true) ?>">
|
||||||
Registered: <?= TextHelper::formatDate($user->joinDate, false) ?>
|
Registered: <?= TextHelper::formatDate($user->getJoinTime(), false) ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="post-count">
|
<div class="post-count">
|
||||||
|
|
|
@ -23,9 +23,9 @@ Assets::addStylesheet('user-view.css');
|
||||||
<span class="key">Joined:</span>
|
<span class="key">Joined:</span>
|
||||||
<span
|
<span
|
||||||
class="value"
|
class="value"
|
||||||
title="<?= TextHelper::formatDate($this->context->transport->user->joinDate, true) ?>">
|
title="<?= TextHelper::formatDate($this->context->transport->user->getJoinTime(), true) ?>">
|
||||||
|
|
||||||
<?= TextHelper::formatDate($this->context->transport->user->joinDate, false) ?>
|
<?= TextHelper::formatDate($this->context->transport->user->getJoinTime(), false) ?>
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,9 +34,9 @@ Assets::addStylesheet('user-view.css');
|
||||||
<span class="key">Last login:</span>
|
<span class="key">Last login:</span>
|
||||||
<span
|
<span
|
||||||
class="value"
|
class="value"
|
||||||
title="<?= TextHelper::formatDate($this->context->transport->user->lastLoginDate, true) ?>">
|
title="<?= TextHelper::formatDate($this->context->transport->user->getLastLoginTime(), true) ?>">
|
||||||
|
|
||||||
<?= TextHelper::formatDate($this->context->transport->user->lastLoginDate, false) ?>
|
<?= TextHelper::formatDate($this->context->transport->user->getLastLoginTime(), false) ?>
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,7 +17,7 @@ class AddCommentJobTest extends AbstractTest
|
||||||
$this->assert->areEqual($text, $comment->getText());
|
$this->assert->areEqual($text, $comment->getText());
|
||||||
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
||||||
$this->assert->areEqual(1, $comment->getPost()->getId());
|
$this->assert->areEqual(1, $comment->getPost()->getId());
|
||||||
$this->assert->isNotNull($comment->getDateTime());
|
$this->assert->isNotNull($comment->getCreationTime());
|
||||||
$this->assert->doesNotThrow(function() use ($comment)
|
$this->assert->doesNotThrow(function() use ($comment)
|
||||||
{
|
{
|
||||||
CommentModel::findById($comment->getId());
|
CommentModel::findById($comment->getId());
|
||||||
|
|
|
@ -15,7 +15,7 @@ class EditCommentJobTest extends AbstractTest
|
||||||
$this->assert->areEqual($text, $comment->getText());
|
$this->assert->areEqual($text, $comment->getText());
|
||||||
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
||||||
$this->assert->areEqual(1, $comment->getPost()->getId());
|
$this->assert->areEqual(1, $comment->getPost()->getId());
|
||||||
$this->assert->isNotNull($comment->getDateTime());
|
$this->assert->isNotNull($comment->getCreationTime());
|
||||||
$this->assert->doesNotThrow(function() use ($comment)
|
$this->assert->doesNotThrow(function() use ($comment)
|
||||||
{
|
{
|
||||||
CommentModel::findById($comment->getId());
|
CommentModel::findById($comment->getId());
|
||||||
|
|
|
@ -14,7 +14,7 @@ class PreviewCommentJobTest extends AbstractTest
|
||||||
$this->assert->areEqual(0, CommentModel::getCount());
|
$this->assert->areEqual(0, CommentModel::getCount());
|
||||||
$this->assert->areEqual($text, $comment->getText());
|
$this->assert->areEqual($text, $comment->getText());
|
||||||
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
||||||
$this->assert->isNotNull($comment->getDateTime());
|
$this->assert->isNotNull($comment->getCreationTime());
|
||||||
$this->assert->throws(function() use ($comment)
|
$this->assert->throws(function() use ($comment)
|
||||||
{
|
{
|
||||||
CommentModel::findById($comment->getId());
|
CommentModel::findById($comment->getId());
|
||||||
|
|
Loading…
Reference in a new issue