Continued work on getter/setters: timestamps

This commit is contained in:
Marcin Kurczewski 2014-05-07 20:33:52 +02:00
parent a619662585
commit 16942d9d19
20 changed files with 68 additions and 37 deletions

View file

@ -10,7 +10,7 @@ class AddCommentJob extends AbstractJob
$comment = CommentModel::spawn();
$comment->setCommenter($user);
$comment->setPost($post);
$comment->setDateTime(time());
$comment->setCreationTime(time());
$comment->setText($text);
CommentModel::save($comment);

View file

@ -6,7 +6,7 @@ class AddUserJob extends AbstractJob
$firstUser = UserModel::getCount() == 0;
$user = UserModel::spawn();
$user->joinDate = time();
$user->setJoinTime(time());
$user->staffConfirmed = $firstUser;
UserModel::forgeId($user);

View file

@ -12,7 +12,7 @@ class EditCommentJob extends AbstractJob
{
$comment = $this->comment;
$comment->setDateTime(time());
$comment->setCreationTime(time());
$comment->setText($this->getArgument(self::TEXT));
CommentModel::save($comment);

View file

@ -18,7 +18,7 @@ class PreviewCommentJob extends AbstractJob
}
$comment->setCommenter($user);
$comment->setDateTime(time());
$comment->setCreationTime(time());
$comment->setText($text);
$comment->validate();

View file

@ -90,7 +90,7 @@ class Mailer
$token->setUser($user);
$token->setText(TokenModel::forgeUnusedToken());
$token->setUsed(false);
$token->setExpirationDate(null);
$token->setExpirationTime(null);
TokenModel::save($token);
$tokens['link'] = \Chibi\Router::linkTo($linkDestination, ['tokenText' => $token->getText()]);

View file

@ -12,7 +12,7 @@ final class CommentModel extends AbstractCrudModel
public static function spawn()
{
$comment = new CommentEntity;
$comment->setDateTime(time());
$comment->setCreationTime(time());
return $comment;
}
@ -27,7 +27,7 @@ final class CommentModel extends AbstractCrudModel
$bindings = [
'text' => $comment->getText(),
'post_id' => $comment->getPostId(),
'comment_date' => $comment->getDateTime(),
'comment_date' => $comment->getCreationTime(),
'commenter_id' => $comment->getCommenterId()];
$stmt = new Sql\UpdateStatement();

View file

@ -20,7 +20,7 @@ final class CommentEntity extends AbstractEntity implements IValidatable
if (!$this->getPostId())
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');
$this->setText($text);
@ -61,14 +61,14 @@ final class CommentEntity extends AbstractEntity implements IValidatable
$this->postId = $post->getId();
}
public function getDateTime()
public function getCreationTime()
{
return $this->commentDate;
}
public function setDateTime($dateTime)
public function setCreationTime($unixTime)
{
$this->commentDate = $dateTime;
$this->commentDate = $unixTime;
}
public function getCommenter()

View file

@ -12,11 +12,12 @@ class PostEntity extends AbstractEntity implements IValidatable
protected $mimeType;
protected $safety;
protected $hidden;
public $uploadDate;
protected $uploadDate;
protected $imageWidth;
protected $imageHeight;
protected $uploaderId;
protected $source;
public $commentCount = 0;
public $favCount = 0;
public $score = 0;
@ -199,6 +200,16 @@ class PostEntity extends AbstractEntity implements IValidatable
$this->hidden = boolval($hidden);
}
public function getCreationTime()
{
return $this->uploadDate;
}
public function setCreationTime($unixTime)
{
$this->uploadDate = $unixTime;
}
public function getImageWidth()
{
return $this->imageWidth;

View file

@ -31,14 +31,14 @@ class TokenEntity extends AbstractEntity implements IValidatable
$this->used = $used;
}
public function getExpirationDate()
public function getExpirationTime()
{
return $this->expires;
}
public function setExpirationDate($time)
public function setExpirationTime($unixTime)
{
$this->expires = $time;
$this->expires = $unixTime;
}
public function getUser()

View file

@ -10,8 +10,8 @@ class UserEntity extends AbstractEntity implements IValidatable
public $staffConfirmed;
protected $emailUnconfirmed;
protected $emailConfirmed;
public $joinDate;
public $lastLoginDate;
protected $joinDate;
protected $lastLoginDate;
protected $accessRank;
public $settings;
protected $banned = false;
@ -33,7 +33,6 @@ class UserEntity extends AbstractEntity implements IValidatable
throw new Exception('Trying to save anonymous user into database');
}
protected function validateUserName()
{
$userName = $this->getName();
@ -103,6 +102,7 @@ class UserEntity extends AbstractEntity implements IValidatable
return $accessRank;
}
public function isBanned()
{
return $this->banned;
@ -128,6 +128,26 @@ class UserEntity extends AbstractEntity implements IValidatable
$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()
{
return $this->emailUnconfirmed;

View file

@ -27,7 +27,7 @@ class PostModel extends AbstractCrudModel
$post = new PostEntity;
$post->setSafety(new PostSafety(PostSafety::Safe));
$post->setHidden(false);
$post->uploadDate = time();
$post->setCreationTime(time());
do
{
$post->setName(md5(mt_rand() . uniqid()));
@ -53,7 +53,7 @@ class PostModel extends AbstractCrudModel
'mime_type' => $post->getMimeType(),
'safety' => $post->getSafety()->toInteger(),
'hidden' => $post->isHidden(),
'upload_date' => $post->uploadDate,
'upload_date' => $post->getCreationTime(),
'image_width' => $post->getImageWidth(),
'image_height' => $post->getImageHeight(),
'uploader_id' => $post->getUploaderId(),

View file

@ -21,7 +21,7 @@ class TokenModel extends AbstractCrudModel
'user_id' => $token->getUserId(),
'token' => $token->getText(),
'used' => $token->isUsed(),
'expires' => $token->getExpirationDate(),
'expires' => $token->getExpirationTime(),
];
$stmt = new Sql\UpdateStatement();
@ -64,7 +64,7 @@ class TokenModel extends AbstractCrudModel
if ($token->isUsed())
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');
}

View file

@ -48,8 +48,8 @@ class UserModel extends AbstractCrudModel
'staff_confirmed' => $user->staffConfirmed,
'email_unconfirmed' => $user->getUnconfirmedEmail(),
'email_confirmed' => $user->getConfirmedEmail(),
'join_date' => $user->joinDate,
'last_login_date' => $user->lastLoginDate,
'join_date' => $user->getJoinTime(),
'last_login_date' => $user->getLastLoginTime(),
'access_rank' => $user->getAccessRank()->toInteger(),
'settings' => $user->settings,
'banned' => $user->isBanned(),

View file

@ -32,8 +32,8 @@ Assets::addScript('comment-edit.js');
<?php endif ?>
</span>
<span class="date" title="<?= TextHelper::formatDate($this->context->comment->getDateTime(), true) ?>">
<?= TextHelper::formatDate($this->context->comment->getDateTime(), false) ?>
<span class="date" title="<?= TextHelper::formatDate($this->context->comment->getCreationTime(), true) ?>">
<?= TextHelper::formatDate($this->context->comment->getCreationTime(), false) ?>
</span>
<?php if (Access::check(new Privilege(

View file

@ -109,8 +109,8 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
<?php endif ?>
<br>
<span class="date"
title="<?= TextHelper::formatDate($this->context->transport->post->uploadDate, true) ?>">
<?= TextHelper::formatDate($this->context->transport->post->uploadDate, false) ?>
title="<?= TextHelper::formatDate($this->context->transport->post->getCreationTime(), true) ?>">
<?= TextHelper::formatDate($this->context->transport->post->getCreationTime(), false) ?>
</span>
</div>

View file

@ -56,8 +56,8 @@ if (Auth::getCurrentUser()->hasEnabledEndlessScrolling())
</a>
</h1>
<div class="date-registered" title="<?= TextHelper::formatDate($user->joinDate, true) ?>">
Registered: <?= TextHelper::formatDate($user->joinDate, false) ?>
<div class="date-registered" title="<?= TextHelper::formatDate($user->getJoinTime(), true) ?>">
Registered: <?= TextHelper::formatDate($user->getJoinTime(), false) ?>
</div>
<div class="post-count">

View file

@ -23,9 +23,9 @@ Assets::addStylesheet('user-view.css');
<span class="key">Joined:</span>
<span
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>
</div>
@ -34,9 +34,9 @@ Assets::addStylesheet('user-view.css');
<span class="key">Last login:</span>
<span
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>
</div>

View file

@ -17,7 +17,7 @@ class AddCommentJobTest extends AbstractTest
$this->assert->areEqual($text, $comment->getText());
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
$this->assert->areEqual(1, $comment->getPost()->getId());
$this->assert->isNotNull($comment->getDateTime());
$this->assert->isNotNull($comment->getCreationTime());
$this->assert->doesNotThrow(function() use ($comment)
{
CommentModel::findById($comment->getId());

View file

@ -15,7 +15,7 @@ class EditCommentJobTest extends AbstractTest
$this->assert->areEqual($text, $comment->getText());
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
$this->assert->areEqual(1, $comment->getPost()->getId());
$this->assert->isNotNull($comment->getDateTime());
$this->assert->isNotNull($comment->getCreationTime());
$this->assert->doesNotThrow(function() use ($comment)
{
CommentModel::findById($comment->getId());

View file

@ -14,7 +14,7 @@ class PreviewCommentJobTest extends AbstractTest
$this->assert->areEqual(0, CommentModel::getCount());
$this->assert->areEqual($text, $comment->getText());
$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)
{
CommentModel::findById($comment->getId());