diff --git a/admin/posts.php b/admin/posts.php
new file mode 100644
index 0000000..7d8041c
--- /dev/null
+++ b/admin/posts.php
@@ -0,0 +1,96 @@
+
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ use Core\Helpers\Pagination;
+ use Core\Models\File;
+ use Core\Models\Posts;
+ use Core\Models\User;
+
+ require_once __DIR__ . '/inc/header.php';
+?>
+
+
+
+
+
+
+
+
+
+
+ | ID |
+ Заголовок |
+ Текст |
+ Автор |
+ Картинка |
+ Создан |
+ Обновлен |
+
+
+
+ getAllCount(), PAGINATION_LIMIT);
+ $limit = Pagination::getLimit();
+
+ $arPosts = $objectPosts->getPosts($limit);
+ foreach ($arPosts as $elPost) {
+ ?>
+
+ | = $elPost['id'] ?> |
+ = $elPost['title'] ?> |
+ = htmlspecialchars($elPost['text']) ?> |
+ = User::getInfoById($elPost['user_id']) ?> |
+ getAllProps();
+ if(!empty($image)) {
+ echo ' ';
+ }
+ ?> |
+
+ = $elPost['date_created'] ? date('d.m.Y H:i:s', strtotime($elPost['date_created'])) : '-'; ?> |
+ = $elPost['date_updated'] ? date('d.m.Y H:i:s', strtotime($elPost['date_updated'])) : '-'; ?> |
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core/lib/Core/Models/File.class.php b/core/lib/Core/Models/File.class.php
index fb099d0..e9f32a4 100644
--- a/core/lib/Core/Models/File.class.php
+++ b/core/lib/Core/Models/File.class.php
@@ -155,6 +155,7 @@
* Получение файла по идентификатору
*
* @return array|null
+ * @throws CoreException
*/
public function getAllProps(): ?array
{
diff --git a/core/lib/Core/Models/Posts.class.php b/core/lib/Core/Models/Posts.class.php
new file mode 100644
index 0000000..2362a29
--- /dev/null
+++ b/core/lib/Core/Models/Posts.class.php
@@ -0,0 +1,127 @@
+
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ /**
+ * Класс для работы с пользователями
+ */
+
+ namespace Core\Models;
+
+ use Core\CoreException;
+ use Core\Helpers\Sanitize;
+ use Core\Models\DB;
+
+ class Posts
+ {
+ private const TABLE = 'posts';
+
+ private const TABLE_SECTIONS = 'sections';
+
+ private $id = null;
+ private $sectionId = null;
+
+ public function __construct(?int $id = null)
+ {
+ if (!empty($id)) {
+ $this->id = $id;
+ }
+ }
+
+ public function setSection(int $sectionId): self
+ {
+ $this->sectionId = Sanitize::sanitizeNumber($sectionId);
+ return $this;
+ }
+
+ public function getSection(): ?int
+ {
+ return $this->sectionId;
+ }
+
+ public function update(array $fields): bool
+ {
+ if(empty($this->id)){
+ throw new CoreException('ID записи не задан');
+ }
+ foreach($fields as $key => $value) {
+ $fields[$key] = Sanitize::sanitizeString($value);
+ }
+ /** @var $DB DB */
+ $DB = DB::getInstance();
+
+ return $DB->update(self::TABLE, ['id' => $this->id], $fields);
+ }
+
+ public function getPosts(string $limit = '10', string $sort = 'DESC'): array
+ {
+ /** @var $DB DB */
+ $DB = DB::getInstance();
+
+ $sql = 'SELECT * FROM ' . self::TABLE;
+ if (!empty($this->sectionId)) {
+ $sql .= ' WHERE section_id="' . $this->sectionId . '"';
+ }
+
+ $sql .= ' ORDER BY id ' . $sort . ' LIMIT ' . $limit;
+ return $DB->query($sql) ?: [];
+ }
+
+ public function getAllPostData(): ?array
+ {
+ $result = (DB::getInstance())->getItem(self::TABLE, ['id' => $this->id]);
+
+ if (!empty($result)) {
+ return $result;
+ }
+
+ return null;
+ }
+
+ public function getImage(): ?array
+ {
+ $result = null;
+ $imageId = $this->getAllPostData()['image_id'];
+
+ if (!empty($imageId)) {
+ try {
+ $result = (new File($imageId))->getAllProps();
+ } catch (CoreException $e) {
+ }
+ }
+
+ return $result;
+ }
+
+ public function getAllCount(): int
+ {
+ /** @var $DB DB */
+ $DB = DB::getInstance();
+
+ $sql = 'SELECT count(*) as count FROM ' . self::TABLE;
+ if (!empty($this->sectionId)) {
+ $sql .= ' WHERE section_id="' . $this->sectionId . '"';
+ }
+ $res = $DB->query($sql);
+ return $res ? (int)$res[0]['count'] : 0;
+ }
+
+
+ }
\ No newline at end of file
diff --git a/core/lib/Core/Models/User.class.php b/core/lib/Core/Models/User.class.php
index a4d5249..055913f 100644
--- a/core/lib/Core/Models/User.class.php
+++ b/core/lib/Core/Models/User.class.php
@@ -63,7 +63,7 @@
/**
* Таблица с пользователями
*/
- const TABLE = 'users';
+ private const TABLE = 'users';
/**
* @var string $cryptoSalt Соль для шифрования
@@ -312,6 +312,34 @@
}
}
+ /**
+ * Получить объект пользователя по ID при его существовании
+ *
+ * @throws CoreException
+ */
+ public static function getById(int $id): ?self
+ {
+ if(self::isUserExistsByParams(['id' => $id])) {
+ return new self($id);
+ }
+ return null;
+ }
+
+ /**
+ * Получение строки с данными о пользователе по ID
+ *
+ * @return string [123] (admin) Роман
+ * @throws CoreException
+ */
+ public static function getInfoById(int $id): string
+ {
+ if (self::isUserExistsByParams(['id' => $id])) {
+ $objectUser = new self($id);
+ return '[' . $id . '] (' . $objectUser->getLogin() . ') ' . $objectUser->getName();
+ }
+ return 'Неизвестно';
+ }
+
/**
* Проверка пользователя на онлайн
*