From 7df8a6fa3b6a0624cc6a7d92c26af09764dc828e Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 5 May 2014 21:20:40 +0200 Subject: [PATCH] Continued work on getter/setters: entity IDs --- src/Access.php | 2 +- src/Api/Jobs/AddCommentJob.php | 2 +- src/Api/Jobs/EditPostRelationsJob.php | 4 ++-- src/Api/Jobs/EditUserEmailJob.php | 2 +- src/Api/Jobs/FeaturePostJob.php | 2 +- src/Api/Jobs/GetPostContentJob.php | 2 +- src/Auth.php | 2 +- src/Controllers/UserController.php | 8 +++---- src/Helpers/TextHelper.php | 2 +- src/Models/AbstractCrudModel.php | 4 ++-- src/Models/CommentModel.php | 8 +++---- src/Models/Entities/AbstractEntity.php | 12 +++++++++- src/Models/Entities/PostEntity.php | 24 +++++++++---------- src/Models/Entities/TagEntity.php | 2 +- src/Models/Entities/TokenEntity.php | 2 +- src/Models/Entities/UserEntity.php | 14 +++++------ src/Models/PostModel.php | 20 ++++++++-------- src/Models/SearchParsers/PostSearchParser.php | 12 +++++----- .../SearchServices/TagSearchService.php | 2 +- src/Models/TagModel.php | 14 +++++------ src/Models/TokenModel.php | 2 +- src/Models/UserModel.php | 22 ++++++++--------- src/Views/comment-add.phtml | 2 +- src/Views/comment-edit.phtml | 2 +- src/Views/comment-list.phtml | 2 +- src/Views/comment-small.phtml | 4 ++-- src/Views/post-edit.phtml | 4 ++-- src/Views/post-small.phtml | 6 ++--- src/Views/post-view.phtml | 22 +++++++++-------- src/Views/static-main.phtml | 2 +- src/Views/user-delete.phtml | 2 +- src/Views/user-edit.phtml | 2 +- tests/CommentAddTest.php | 10 ++++---- tests/CommentDeleteTest.php | 4 ++-- tests/CommentEditTest.php | 10 ++++---- tests/CommentListTest.php | 2 +- 36 files changed, 125 insertions(+), 113 deletions(-) diff --git a/src/Access.php b/src/Access.php index 544bba7a..29f9d6fb 100644 --- a/src/Access.php +++ b/src/Access.php @@ -105,7 +105,7 @@ class Access { if (!$user) return 'all'; - return $user->id == Auth::getCurrentUser()->id ? 'own' : 'all'; + return $user->getId() == Auth::getCurrentUser()->getId() ? 'own' : 'all'; } public static function getAllowedSafety() diff --git a/src/Api/Jobs/AddCommentJob.php b/src/Api/Jobs/AddCommentJob.php index 4d995804..1475bc33 100644 --- a/src/Api/Jobs/AddCommentJob.php +++ b/src/Api/Jobs/AddCommentJob.php @@ -16,7 +16,7 @@ class AddCommentJob extends AbstractJob CommentModel::save($comment); Logger::log('{user} commented on {post}', [ 'user' => TextHelper::reprUser($user), - 'post' => TextHelper::reprPost($comment->getPost()->id)]); + 'post' => TextHelper::reprPost($comment->getPost())]); return $comment; } diff --git a/src/Api/Jobs/EditPostRelationsJob.php b/src/Api/Jobs/EditPostRelationsJob.php index 76b261b7..7a1c3a5e 100644 --- a/src/Api/Jobs/EditPostRelationsJob.php +++ b/src/Api/Jobs/EditPostRelationsJob.php @@ -8,9 +8,9 @@ class EditPostRelationsJob extends AbstractPostEditJob $post = $this->post; $relations = $this->getArgument(self::RELATED_POST_IDS); - $oldRelatedIds = array_map(function($post) { return $post->id; }, $post->getRelations()); + $oldRelatedIds = array_map(function($post) { return $post->getId(); }, $post->getRelations()); $post->setRelationsFromText($relations); - $newRelatedIds = array_map(function($post) { return $post->id; }, $post->getRelations()); + $newRelatedIds = array_map(function($post) { return $post->getId(); }, $post->getRelations()); if (!$this->skipSaving) PostModel::save($post); diff --git a/src/Api/Jobs/EditUserEmailJob.php b/src/Api/Jobs/EditUserEmailJob.php index 875644be..c9a69dea 100644 --- a/src/Api/Jobs/EditUserEmailJob.php +++ b/src/Api/Jobs/EditUserEmailJob.php @@ -19,7 +19,7 @@ class EditUserEmailJob extends AbstractUserEditJob $user->emailUnconfirmed = $newEmail; $user->emailConfirmed = null; - if (Auth::getCurrentUser()->id == $user->id) + if (Auth::getCurrentUser()->getId() == $user->getId()) { if (!empty($newEmail)) ActivateUserEmailJob::sendEmail($user); diff --git a/src/Api/Jobs/FeaturePostJob.php b/src/Api/Jobs/FeaturePostJob.php index f18297d7..e52855d8 100644 --- a/src/Api/Jobs/FeaturePostJob.php +++ b/src/Api/Jobs/FeaturePostJob.php @@ -5,7 +5,7 @@ class FeaturePostJob extends AbstractPostJob { $post = $this->post; - PropertyModel::set(PropertyModel::FeaturedPostId, $post->id); + PropertyModel::set(PropertyModel::FeaturedPostId, $post->getId()); PropertyModel::set(PropertyModel::FeaturedPostDate, time()); PropertyModel::set(PropertyModel::FeaturedPostUserName, Auth::getCurrentUser()->getName()); diff --git a/src/Api/Jobs/GetPostContentJob.php b/src/Api/Jobs/GetPostContentJob.php index 823e65a0..2a83d9d3 100644 --- a/src/Api/Jobs/GetPostContentJob.php +++ b/src/Api/Jobs/GetPostContentJob.php @@ -22,7 +22,7 @@ class GetPostContentJob extends AbstractJob $fileName = sprintf('%s_%s_%s.%s', $config->main->title, - $post->id, + $post->getId(), join(',', array_map(function($tag) { return $tag->getName(); }, $post->getTags())), TextHelper::resolveMimeType($post->mimeType) ?: 'dat'); $fileName = preg_replace('/[[:^print:]]/', '', $fileName); diff --git a/src/Auth.php b/src/Auth.php index c91f33be..6f4e16ce 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -85,7 +85,7 @@ class Auth private static function getAnonymousUser() { $dummy = UserModel::spawn(); - $dummy->id = null; + $dummy->setId(null); $dummy->setName(UserModel::getAnonymousName()); $dummy->setAccessRank(new AccessRank(AccessRank::Anonymous)); return $dummy; diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index b2a1f483..5a345c6f 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -83,7 +83,7 @@ class UserController if ($user->getAccessRank()->toInteger() != AccessRank::Anonymous) UserModel::save($user); - if ($user->id == Auth::getCurrentUser()->id) + if ($user->getId() == Auth::getCurrentUser()->getId()) Auth::setCurrentUser($user); Messenger::message('Browsing settings updated!'); @@ -109,7 +109,7 @@ class UserController $args = array_filter($args); $user = Api::run(new EditUserJob(), $args); - if (Auth::getCurrentUser()->id == $user->id) + if (Auth::getCurrentUser()->getId() == $user->getId()) Auth::setCurrentUser($user); $message = 'Account settings updated!'; @@ -127,7 +127,7 @@ class UserController Api::run(new DeleteUserJob(), [ DeleteUserJob::USER_NAME => $name]); - $user = UserModel::findById(Auth::getCurrentUser()->id, false); + $user = UserModel::findById(Auth::getCurrentUser()->getId(), false); if (!$user) Auth::logOut(); @@ -292,7 +292,7 @@ class UserController private function requirePasswordConfirmation() { $user = getContext()->transport->user; - if (Auth::getCurrentUser()->id == $user->id) + if (Auth::getCurrentUser()->getId() == $user->getId()) { $suppliedPassword = InputHelper::get('current-password'); $suppliedPasswordHash = UserModel::hashPassword($suppliedPassword, $user->passSalt); diff --git a/src/Helpers/TextHelper.php b/src/Helpers/TextHelper.php index 7e9ec8a1..d8a1066b 100644 --- a/src/Helpers/TextHelper.php +++ b/src/Helpers/TextHelper.php @@ -150,7 +150,7 @@ class TextHelper { if (!is_object($post)) return '@' . $post; - return '@' . $post->id; + return '@' . $post->getId(); } public static function reprUser($user) diff --git a/src/Models/AbstractCrudModel.php b/src/Models/AbstractCrudModel.php index 9a176e27..c7173a26 100644 --- a/src/Models/AbstractCrudModel.php +++ b/src/Models/AbstractCrudModel.php @@ -126,7 +126,7 @@ abstract class AbstractCrudModel implements IModel $table = static::getTableName(); if (!Database::inTransaction()) throw new Exception('Can be run only within transaction'); - if (!$entity->id) + if (!$entity->getId()) { $stmt = new Sql\InsertStatement(); $stmt->setTable($table); @@ -139,7 +139,7 @@ abstract class AbstractCrudModel implements IModel $stmt->setColumn($key, new Sql\Binding($val)); } Database::exec($stmt); - $entity->id = (int) Database::lastInsertId(); + $entity->setId((int) Database::lastInsertId()); } } diff --git a/src/Models/CommentModel.php b/src/Models/CommentModel.php index 6325f78e..37053956 100644 --- a/src/Models/CommentModel.php +++ b/src/Models/CommentModel.php @@ -32,7 +32,7 @@ class CommentModel extends AbstractCrudModel $stmt = new Sql\UpdateStatement(); $stmt->setTable('comment'); - $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($comment->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($comment->getId()))); foreach ($bindings as $key => $val) $stmt->setColumn($key, new Sql\Binding($val)); @@ -49,7 +49,7 @@ class CommentModel extends AbstractCrudModel { $stmt = new Sql\DeleteStatement(); $stmt->setTable('comment'); - $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($comment->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($comment->getId()))); Database::exec($stmt); }); } @@ -75,7 +75,7 @@ class CommentModel extends AbstractCrudModel { self::preloadOneToMany($comments, function($comment) { return $comment->commenterId; }, - function($user) { return $user->id; }, + function($user) { return $user->getId(); }, function($userIds) { return UserModel::findByIds($userIds); }, function($comment, $user) { return $comment->setCache('commenter', $user); }); } @@ -84,7 +84,7 @@ class CommentModel extends AbstractCrudModel { self::preloadOneToMany($comments, function($comment) { return $comment->postId; }, - function($post) { return $post->id; }, + function($post) { return $post->getId(); }, function($postIds) { return PostModel::findByIds($postIds); }, function($comment, $post) { $comment->setCache('post', $post); }); } diff --git a/src/Models/Entities/AbstractEntity.php b/src/Models/Entities/AbstractEntity.php index c4cc469b..61b41d09 100644 --- a/src/Models/Entities/AbstractEntity.php +++ b/src/Models/Entities/AbstractEntity.php @@ -1,9 +1,19 @@ id; + } + + public function setId($id) + { + $this->id = $id; + } + public function resetCache() { $this->__cache = []; diff --git a/src/Models/Entities/PostEntity.php b/src/Models/Entities/PostEntity.php index 70a137f0..67bd70bb 100644 --- a/src/Models/Entities/PostEntity.php +++ b/src/Models/Entities/PostEntity.php @@ -39,7 +39,7 @@ class PostEntity extends AbstractEntity implements IValidatable public function setUploader($user) { - $this->uploaderId = $user->id; + $this->uploaderId = $user->getId(); $this->setCache('uploader', $user); } @@ -47,7 +47,7 @@ class PostEntity extends AbstractEntity implements IValidatable { if ($this->hasCache('comments')) return $this->getCache('comments'); - $comments = CommentModel::findAllByPostId($this->id); + $comments = CommentModel::findAllByPostId($this->getId()); $this->setCache('comments', $comments); return $comments; } @@ -60,7 +60,7 @@ class PostEntity extends AbstractEntity implements IValidatable $stmt->setColumn('user.*'); $stmt->setTable('user'); $stmt->addInnerJoin('favoritee', new Sql\EqualsFunctor('favoritee.user_id', 'user.id')); - $stmt->setCriterion(new Sql\EqualsFunctor('favoritee.post_id', new Sql\Binding($this->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('favoritee.post_id', new Sql\Binding($this->getId()))); $rows = Database::fetchAll($stmt); $favorites = UserModel::convertRows($rows); $this->setCache('favoritee', $favorites); @@ -75,7 +75,7 @@ class PostEntity extends AbstractEntity implements IValidatable $stmt = new Sql\SelectStatement(); $stmt->setColumn('post.*'); $stmt->setTable('post'); - $binding = new Sql\Binding($this->id); + $binding = new Sql\Binding($this->getId()); $stmt->addInnerJoin('crossref', (new Sql\DisjunctionFunctor) ->add( (new Sql\ConjunctionFunctor) @@ -94,11 +94,11 @@ class PostEntity extends AbstractEntity implements IValidatable public function setRelations(array $relations) { foreach ($relations as $relatedPost) - if (!$relatedPost->id) + if (!$relatedPost->getId()) throw new Exception('All related posts must be saved'); $uniqueRelations = []; foreach ($relations as $relatedPost) - $uniqueRelations[$relatedPost->id] = $relatedPost; + $uniqueRelations[$relatedPost->getId()] = $relatedPost; $relations = array_values($uniqueRelations); $this->setCache('relations', $relations); } @@ -111,7 +111,7 @@ class PostEntity extends AbstractEntity implements IValidatable $relatedPosts = []; foreach ($relatedIds as $relatedId) { - if ($relatedId == $this->id) + if ($relatedId == $this->getId()) continue; if (count($relatedPosts) > $config->browsing->maxRelatedPosts) @@ -131,7 +131,7 @@ class PostEntity extends AbstractEntity implements IValidatable { if ($this->hasCache('tags')) return $this->getCache('tags'); - $tags = TagModel::findAllByPostId($this->id); + $tags = TagModel::findAllByPostId($this->getId()); $this->setCache('tags', $tags); return $tags; } @@ -139,11 +139,11 @@ class PostEntity extends AbstractEntity implements IValidatable public function setTags(array $tags) { foreach ($tags as $tag) - if (!$tag->id) + if (!$tag->getId()) throw new Exception('All tags must be saved'); $uniqueTags = []; foreach ($tags as $tag) - $uniqueTags[$tag->id] = $tag; + $uniqueTags[$tag->getId()] = $tag; $tags = array_values($uniqueTags); $this->setCache('tags', $tags); } @@ -323,7 +323,7 @@ class PostEntity extends AbstractEntity implements IValidatable } $duplicatedPost = PostModel::findByHash($this->fileHash, false); - if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id)) + if ($duplicatedPost !== null and (!$this->getId() or $this->getId() != $duplicatedPost->getId())) { throw new SimpleException( 'Duplicate upload: %s', @@ -361,7 +361,7 @@ class PostEntity extends AbstractEntity implements IValidatable unlink($thumbPath); $duplicatedPost = PostModel::findByHash($youtubeId, false); - if ($duplicatedPost !== null and (!$this->id or $this->id != $duplicatedPost->id)) + if ($duplicatedPost !== null and (!$this->getId() or $this->getId() != $duplicatedPost->getId())) { throw new SimpleException( 'Duplicate upload: %s', diff --git a/src/Models/Entities/TagEntity.php b/src/Models/Entities/TagEntity.php index a8ba5452..faea5265 100644 --- a/src/Models/Entities/TagEntity.php +++ b/src/Models/Entities/TagEntity.php @@ -29,7 +29,7 @@ class TagEntity extends AbstractEntity implements IValidatable $stmt = new Sql\SelectStatement(); $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('post_tag'); - $stmt->setCriterion(new Sql\EqualsFunctor('tag_id', new Sql\Binding($this->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('tag_id', new Sql\Binding($this->getId()))); return Database::fetchOne($stmt)['count']; } } diff --git a/src/Models/Entities/TokenEntity.php b/src/Models/Entities/TokenEntity.php index fc22f5f7..01dac09c 100644 --- a/src/Models/Entities/TokenEntity.php +++ b/src/Models/Entities/TokenEntity.php @@ -18,6 +18,6 @@ class TokenEntity extends AbstractEntity implements IValidatable public function setUser($user) { - $this->userId = $user ? $user->id : null; + $this->userId = $user ? $user->getId() : null; } } diff --git a/src/Models/Entities/UserEntity.php b/src/Models/Entities/UserEntity.php index 89221c2c..678f5add 100644 --- a/src/Models/Entities/UserEntity.php +++ b/src/Models/Entities/UserEntity.php @@ -172,8 +172,8 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('favoritee'); $stmt->setCriterion((new Sql\ConjunctionFunctor) - ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($this->id))) - ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->id)))); + ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($this->getId()))) + ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->getId())))); return Database::fetchOne($stmt)['count'] == 1; } @@ -183,8 +183,8 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt->setColumn('score'); $stmt->setTable('post_score'); $stmt->setCriterion((new Sql\ConjunctionFunctor) - ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($this->id))) - ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->id)))); + ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($this->getId()))) + ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->getId())))); $row = Database::fetchOne($stmt); if ($row) return intval($row['score']); @@ -196,7 +196,7 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt = new Sql\SelectStatement(); $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('favoritee'); - $stmt->setCriterion(new Sql\EqualsFunctor('user_id', new Sql\Binding($this->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('user_id', new Sql\Binding($this->getId()))); return Database::fetchOne($stmt)['count']; } @@ -205,7 +205,7 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt = new Sql\SelectStatement(); $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('comment'); - $stmt->setCriterion(new Sql\EqualsFunctor('commenter_id', new Sql\Binding($this->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('commenter_id', new Sql\Binding($this->getId()))); return Database::fetchOne($stmt)['count']; } @@ -214,7 +214,7 @@ class UserEntity extends AbstractEntity implements IValidatable $stmt = new Sql\SelectStatement(); $stmt->setColumn(new Sql\AliasFunctor(new Sql\CountFunctor('1'), 'count')); $stmt->setTable('post'); - $stmt->setCriterion(new Sql\EqualsFunctor('uploader_id', new Sql\Binding($this->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('uploader_id', new Sql\Binding($this->getId()))); return Database::fetchOne($stmt)['count']; } } diff --git a/src/Models/PostModel.php b/src/Models/PostModel.php index 48e1b997..9ed0701a 100644 --- a/src/Models/PostModel.php +++ b/src/Models/PostModel.php @@ -73,7 +73,7 @@ class PostModel extends AbstractCrudModel foreach ($bindings as $key => $value) $stmt->setColumn($key, new Sql\Binding($value)); - $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($post->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($post->getId()))); Database::exec($stmt); //tags @@ -81,15 +81,15 @@ class PostModel extends AbstractCrudModel $stmt = new Sql\DeleteStatement(); $stmt->setTable('post_tag'); - $stmt->setCriterion(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->getId()))); Database::exec($stmt); foreach ($tags as $postTag) { $stmt = new Sql\InsertStatement(); $stmt->setTable('post_tag'); - $stmt->setColumn('post_id', new Sql\Binding($post->id)); - $stmt->setColumn('tag_id', new Sql\Binding($postTag->id)); + $stmt->setColumn('post_id', new Sql\Binding($post->getId())); + $stmt->setColumn('tag_id', new Sql\Binding($postTag->getId())); Database::exec($stmt); } @@ -98,7 +98,7 @@ class PostModel extends AbstractCrudModel $stmt = new Sql\DeleteStatement(); $stmt->setTable('crossref'); - $binding = new Sql\Binding($post->id); + $binding = new Sql\Binding($post->getId()); $stmt->setCriterion((new Sql\DisjunctionFunctor) ->add(new Sql\EqualsFunctor('post_id', $binding)) ->add(new Sql\EqualsFunctor('post2_id', $binding))); @@ -108,8 +108,8 @@ class PostModel extends AbstractCrudModel { $stmt = new Sql\InsertStatement(); $stmt->setTable('crossref'); - $stmt->setColumn('post_id', new Sql\Binding($post->id)); - $stmt->setColumn('post2_id', new Sql\Binding($relatedPost->id)); + $stmt->setColumn('post_id', new Sql\Binding($post->getId())); + $stmt->setColumn('post2_id', new Sql\Binding($relatedPost->getId())); Database::exec($stmt); } }); @@ -121,7 +121,7 @@ class PostModel extends AbstractCrudModel { Database::transaction(function() use ($post) { - $binding = new Sql\Binding($post->id); + $binding = new Sql\Binding($post->getId()); $stmt = new Sql\DeleteStatement(); $stmt->setTable('post_score'); @@ -204,7 +204,7 @@ class PostModel extends AbstractCrudModel $tagsMap = []; foreach ($posts as $post) { - $postId = $post->id; + $postId = $post->getId(); $postMap[$postId] = $post; $commentMap[$postId] = []; } @@ -245,7 +245,7 @@ class PostModel extends AbstractCrudModel $tagsMap = []; foreach ($posts as $post) { - $postId = $post->id; + $postId = $post->getId(); $postMap[$postId] = $post; $tagsMap[$postId] = []; } diff --git a/src/Models/SearchParsers/PostSearchParser.php b/src/Models/SearchParsers/PostSearchParser.php index adbfb54f..e4e018ad 100644 --- a/src/Models/SearchParsers/PostSearchParser.php +++ b/src/Models/SearchParsers/PostSearchParser.php @@ -43,7 +43,7 @@ class PostSearchParser extends AbstractSearchParser $innerStmt->setTable('post_tag'); $innerStmt->setCriterion((new Sql\ConjunctionFunctor) ->add(new Sql\EqualsFunctor('post_tag.post_id', 'post.id')) - ->add(new Sql\EqualsFunctor('post_tag.tag_id', new Sql\Binding($tag->id)))); + ->add(new Sql\EqualsFunctor('post_tag.tag_id', new Sql\Binding($tag->getId())))); $operator = new Sql\ExistsFunctor($innerStmt); if ($neg) $operator = new Sql\NegationFunctor($operator); @@ -78,7 +78,7 @@ class PostSearchParser extends AbstractSearchParser ->setTable('favoritee') ->setCriterion((new Sql\ConjunctionFunctor) ->add(new Sql\EqualsFunctor('favoritee.post_id', 'post.id')) - ->add(new Sql\EqualsFunctor('favoritee.user_id', new Sql\Binding($user->id)))); + ->add(new Sql\EqualsFunctor('favoritee.user_id', new Sql\Binding($user->getId())))); return new Sql\ExistsFunctor($innerStmt); } @@ -89,14 +89,14 @@ class PostSearchParser extends AbstractSearchParser ->setTable('comment') ->setCriterion((new Sql\ConjunctionFunctor) ->add(new Sql\EqualsFunctor('comment.post_id', 'post.id')) - ->add(new Sql\EqualsFunctor('comment.commenter_id', new Sql\Binding($user->id)))); + ->add(new Sql\EqualsFunctor('comment.commenter_id', new Sql\Binding($user->getId())))); return new Sql\ExistsFunctor($innerStmt); } elseif (in_array($key, ['submit', 'upload', 'uploads', 'uploader', 'uploaded'])) { $user = UserModel::findByNameOrEmail($value); - return new Sql\EqualsFunctor('post.uploader_id', new Sql\Binding($user->id)); + return new Sql\EqualsFunctor('post.uploader_id', new Sql\Binding($user->getId())); } elseif (in_array($key, ['idmin', 'id_min'])) @@ -165,7 +165,7 @@ class PostSearchParser extends AbstractSearchParser { $this->statement->addLeftOuterJoin('post_score', (new Sql\ConjunctionFunctor) ->add(new Sql\EqualsFunctor('post_score.post_id', 'post.id')) - ->add(new Sql\EqualsFunctor('post_score.user_id', new Sql\Binding($activeUser->id)))); + ->add(new Sql\EqualsFunctor('post_score.user_id', new Sql\Binding($activeUser->getId())))); } return new Sql\EqualsFunctor(new Sql\IfNullFunctor('post_score.score', '0'), '1'); } @@ -177,7 +177,7 @@ class PostSearchParser extends AbstractSearchParser { $this->statement->addLeftOuterJoin('post_score', (new Sql\ConjunctionFunctor) ->add(new Sql\EqualsFunctor('post_score.post_id', 'post.id')) - ->add(new Sql\EqualsFunctor('post_score.user_id', new Sql\Binding($activeUser->id)))); + ->add(new Sql\EqualsFunctor('post_score.user_id', new Sql\Binding($activeUser->getId())))); } return new Sql\EqualsFunctor(new Sql\IfNullFunctor('post_score.score', '0'), '-1'); } diff --git a/src/Models/SearchServices/TagSearchService.php b/src/Models/SearchServices/TagSearchService.php index 28052847..04c1a059 100644 --- a/src/Models/SearchServices/TagSearchService.php +++ b/src/Models/SearchServices/TagSearchService.php @@ -14,7 +14,7 @@ class TagSearchService extends AbstractSearchService $parentTagEntity = TagModel::findByName($parentTagName, false); if (empty($parentTagEntity)) return []; - $parentTagId = $parentTagEntity->id; + $parentTagId = $parentTagEntity->getId(); //get tags that appear with selected tag along with their occurence frequency $stmt = (new Sql\SelectStatement) diff --git a/src/Models/TagModel.php b/src/Models/TagModel.php index f27253e3..cfce366c 100644 --- a/src/Models/TagModel.php +++ b/src/Models/TagModel.php @@ -28,7 +28,7 @@ class TagModel extends AbstractCrudModel $stmt = new Sql\UpdateStatement(); $stmt->setTable('tag'); $stmt->setColumn('name', new Sql\Binding($tag->getName())); - $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($tag->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($tag->getId()))); Database::exec($stmt); }); @@ -38,7 +38,7 @@ class TagModel extends AbstractCrudModel public static function remove($tag) { - $binding = new Sql\Binding($tag->id); + $binding = new Sql\Binding($tag->getId()); $stmt = new Sql\DeleteStatement(); $stmt->setTable('post_tag'); @@ -58,7 +58,7 @@ class TagModel extends AbstractCrudModel $sourceTag = TagModel::findByName($sourceName); $targetTag = TagModel::findByName($targetName, false); - if ($targetTag and $targetTag->id != $sourceTag->id) + if ($targetTag and $targetTag->getId() != $sourceTag->getId()) throw new SimpleException('Target tag already exists'); $sourceTag->setName($targetName); @@ -74,7 +74,7 @@ class TagModel extends AbstractCrudModel $sourceTag = TagModel::findByName($sourceName); $targetTag = TagModel::findByName($targetName); - if ($sourceTag->id == $targetTag->id) + if ($sourceTag->getId() == $targetTag->getId()) throw new SimpleException('Source and target tag are the same'); $stmt = new Sql\SelectStatement(); @@ -89,7 +89,7 @@ class TagModel extends AbstractCrudModel ->setCriterion( (new Sql\ConjunctionFunctor) ->add(new Sql\EqualsFunctor('post_tag.post_id', 'post.id')) - ->add(new Sql\EqualsFunctor('post_tag.tag_id', new Sql\Binding($sourceTag->id)))))) + ->add(new Sql\EqualsFunctor('post_tag.tag_id', new Sql\Binding($sourceTag->getId())))))) ->add( new Sql\NegationFunctor( new Sql\ExistsFunctor( @@ -98,7 +98,7 @@ class TagModel extends AbstractCrudModel ->setCriterion( (new Sql\ConjunctionFunctor) ->add(new Sql\EqualsFunctor('post_tag.post_id', 'post.id')) - ->add(new Sql\EqualsFunctor('post_tag.tag_id', new Sql\Binding($targetTag->id)))))))); + ->add(new Sql\EqualsFunctor('post_tag.tag_id', new Sql\Binding($targetTag->getId())))))))); $rows = Database::fetchAll($stmt); $postIds = array_map(function($row) { return $row['id']; }, $rows); @@ -109,7 +109,7 @@ class TagModel extends AbstractCrudModel $stmt = new Sql\InsertStatement(); $stmt->setTable('post_tag'); $stmt->setColumn('post_id', new Sql\Binding($postId)); - $stmt->setColumn('tag_id', new Sql\Binding($targetTag->id)); + $stmt->setColumn('tag_id', new Sql\Binding($targetTag->getId())); Database::exec($stmt); } }); diff --git a/src/Models/TokenModel.php b/src/Models/TokenModel.php index 01857301..faafcc42 100644 --- a/src/Models/TokenModel.php +++ b/src/Models/TokenModel.php @@ -26,7 +26,7 @@ class TokenModel extends AbstractCrudModel $stmt = new Sql\UpdateStatement(); $stmt->setTable('user_token'); - $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($token->id))); + $stmt->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($token->getId()))); foreach ($bindings as $key => $val) $stmt->setColumn($key, new Sql\Binding($val)); diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php index 80c98ffc..9822b30b 100644 --- a/src/Models/UserModel.php +++ b/src/Models/UserModel.php @@ -56,7 +56,7 @@ class UserModel extends AbstractCrudModel $stmt = (new Sql\UpdateStatement) ->setTable('user') - ->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($user->id))); + ->setCriterion(new Sql\EqualsFunctor('id', new Sql\Binding($user->getId()))); foreach ($bindings as $key => $val) $stmt->setColumn($key, new Sql\Binding($val)); @@ -71,7 +71,7 @@ class UserModel extends AbstractCrudModel { Database::transaction(function() use ($user) { - $binding = new Sql\Binding($user->id); + $binding = new Sql\Binding($user->getId()); $stmt = new Sql\DeleteStatement(); $stmt->setTable('post_score'); @@ -144,16 +144,16 @@ class UserModel extends AbstractCrudModel $stmt = new Sql\DeleteStatement(); $stmt->setTable('post_score'); $stmt->setCriterion((new Sql\ConjunctionFunctor) - ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->id))) - ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($user->id)))); + ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->getId()))) + ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($user->getId())))); Database::exec($stmt); $score = intval($score); if ($score != 0) { $stmt = new Sql\InsertStatement(); $stmt->setTable('post_score'); - $stmt->setColumn('post_id', new Sql\Binding($post->id)); - $stmt->setColumn('user_id', new Sql\Binding($user->id)); + $stmt->setColumn('post_id', new Sql\Binding($post->getId())); + $stmt->setColumn('user_id', new Sql\Binding($user->getId())); $stmt->setColumn('score', new Sql\Binding($score)); Database::exec($stmt); } @@ -167,8 +167,8 @@ class UserModel extends AbstractCrudModel self::removeFromUserFavorites($user, $post); $stmt = new Sql\InsertStatement(); $stmt->setTable('favoritee'); - $stmt->setColumn('post_id', new Sql\Binding($post->id)); - $stmt->setColumn('user_id', new Sql\Binding($user->id)); + $stmt->setColumn('post_id', new Sql\Binding($post->getId())); + $stmt->setColumn('user_id', new Sql\Binding($user->getId())); $stmt->setColumn('fav_date', time()); Database::exec($stmt); }); @@ -181,8 +181,8 @@ class UserModel extends AbstractCrudModel $stmt = new Sql\DeleteStatement(); $stmt->setTable('favoritee'); $stmt->setCriterion((new Sql\ConjunctionFunctor) - ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->id))) - ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($user->id)))); + ->add(new Sql\EqualsFunctor('post_id', new Sql\Binding($post->getId()))) + ->add(new Sql\EqualsFunctor('user_id', new Sql\Binding($user->getId())))); Database::exec($stmt); }); } @@ -195,7 +195,7 @@ class UserModel extends AbstractCrudModel $config = getConfig(); $otherUser = self::findByName($userName, false); - if ($otherUser !== null and $otherUser->id != $user->id) + if ($otherUser !== null and $otherUser->getId() != $user->getId()) { if (!$otherUser->emailConfirmed and $config->registration->needEmailForRegistering) throw new SimpleException('User with this name is already registered and awaits e-mail confirmation'); diff --git a/src/Views/comment-add.phtml b/src/Views/comment-add.phtml index cdae4709..719c0089 100644 --- a/src/Views/comment-add.phtml +++ b/src/Views/comment-add.phtml @@ -16,7 +16,7 @@ Assets::addScript('comment-edit.js');
- +
  diff --git a/src/Views/comment-edit.phtml b/src/Views/comment-edit.phtml index 92a46ce1..ced63b85 100644 --- a/src/Views/comment-edit.phtml +++ b/src/Views/comment-edit.phtml @@ -7,7 +7,7 @@ Assets::addScript('comment-edit.js'); method="post" action=" $this->context->transport->comment->id]) ?>" + ['id' => $this->context->transport->comment->getId()]) ?>" class="edit-comment">

edit comment

diff --git a/src/Views/comment-list.phtml b/src/Views/comment-list.phtml index 5c8ce22e..ac29ca1b 100644 --- a/src/Views/comment-list.phtml +++ b/src/Views/comment-list.phtml @@ -33,7 +33,7 @@ Assets::setSubTitle('comments'); count($commentsToDisplay)): ?> + ['id' => $this->context->post->getId()]) ?>"> (more…) diff --git a/src/Views/comment-small.phtml b/src/Views/comment-small.phtml index f664bd39..d1b1d463 100644 --- a/src/Views/comment-small.phtml +++ b/src/Views/comment-small.phtml @@ -42,7 +42,7 @@ Assets::addScript('comment-edit.js'); + ['id' => $this->context->comment->getId()]) ?>"> edit @@ -56,7 +56,7 @@ Assets::addScript('comment-edit.js'); data-confirm-text="Are you sure you want to delete this comment?" href=" $this->context->comment->id]) ?>"> + ['id' => $this->context->comment->getId()]) ?>"> delete diff --git a/src/Views/post-edit.phtml b/src/Views/post-edit.phtml index aaf2a844..b5a0ebe8 100644 --- a/src/Views/post-edit.phtml +++ b/src/Views/post-edit.phtml @@ -1,7 +1,7 @@
$this->context->transport->post->getId()]) ?>" enctype="multipart/form-data" class="edit-post"> @@ -79,7 +79,7 @@ id="relations" placeholder="id1,id2,…" value="id; + return $post->getId(); }, $this->context->transport->post->getRelations())) ?>"/>
diff --git a/src/Views/post-small.phtml b/src/Views/post-small.phtml index 5a2f4e82..512133b1 100644 --- a/src/Views/post-small.phtml +++ b/src/Views/post-small.phtml @@ -29,7 +29,7 @@ if ($masstag) hasEnabledPostTagTitles()): ?> title="context->post->getTags()) ?>" - href=" $this->context->post->id]) ?>"> + href=" $this->context->post->getId()]) ?>"> @<?= $this->context->post->id ?> + alt="@context->post->getId() ?>"/> 0; { return \Chibi\Router::linkTo( ['PostController', 'scoreAction'], - ['id' => $this->context->transport->post->id, 'score' => $score]); + ['id' => $this->context->transport->post->getId(), 'score' => $score]); } ?> 0; + ['id' => $this->context->transport->post->getId()]) ?>"> Add to favorites @@ -218,7 +218,7 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0; + ['id' => $this->context->transport->post->getId()]) ?>"> Remove from favorites @@ -259,8 +259,10 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;