diff options
Diffstat (limited to 'core/namespace/Post')
-rw-r--r-- | core/namespace/Post/Attribute.php | 22 | ||||
-rw-r--r-- | core/namespace/Post/Entity.php | 13 | ||||
-rw-r--r-- | core/namespace/Post/Exception.php | 4 | ||||
-rw-r--r-- | core/namespace/Post/Factory.php | 4 | ||||
-rw-r--r-- | core/namespace/Post/Item.php | 27 | ||||
-rw-r--r-- | core/namespace/Post/Repository.php | 17 |
6 files changed, 30 insertions, 57 deletions
diff --git a/core/namespace/Post/Attribute.php b/core/namespace/Post/Attribute.php deleted file mode 100644 index 20aafae..0000000 --- a/core/namespace/Post/Attribute.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php -namespace Post; - -class Attribute extends \Attribute { - - #=============================================================================== - # Pre-Define database table columns - #=============================================================================== - protected $id = FALSE; - protected $user = FALSE; - protected $slug = FALSE; - protected $name = FALSE; - protected $body = FALSE; - protected $argv = FALSE; - protected $time_insert = FALSE; - protected $time_update = FALSE; - - #=============================================================================== - # Define database table name - #=============================================================================== - const TABLE = 'post'; -} diff --git a/core/namespace/Post/Entity.php b/core/namespace/Post/Entity.php new file mode 100644 index 0000000..399f5bb --- /dev/null +++ b/core/namespace/Post/Entity.php @@ -0,0 +1,13 @@ +<?php +namespace Post; + +class Entity extends \Entity { + protected $id = FALSE; + protected $user = FALSE; + protected $slug = FALSE; + protected $name = FALSE; + protected $body = FALSE; + protected $argv = FALSE; + protected $time_insert = FALSE; + protected $time_update = FALSE; +} diff --git a/core/namespace/Post/Exception.php b/core/namespace/Post/Exception.php deleted file mode 100644 index 29b9345..0000000 --- a/core/namespace/Post/Exception.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php -namespace Post; - -class Exception extends \Exception {} diff --git a/core/namespace/Post/Factory.php b/core/namespace/Post/Factory.php deleted file mode 100644 index 20b29cc..0000000 --- a/core/namespace/Post/Factory.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php -namespace Post; - -class Factory extends \ItemFactory {} diff --git a/core/namespace/Post/Item.php b/core/namespace/Post/Item.php deleted file mode 100644 index e8b4615..0000000 --- a/core/namespace/Post/Item.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -namespace Post; - -class Item extends \Item { - const CONFIGURATION = 'POST'; - - #=============================================================================== - # Return unique post IDs for search results - #=============================================================================== - public static function getSearchResultIDs($search, array $date, \Database $Database): array { - $D = ($D = intval($date[0])) !== 0 ? $D : 'NULL'; - $M = ($M = intval($date[1])) !== 0 ? $M : 'NULL'; - $Y = ($Y = intval($date[2])) !== 0 ? $Y : 'NULL'; - - $Statement = $Database->prepare(sprintf("SELECT id FROM %s WHERE - ({$Y} IS NULL OR YEAR(time_insert) = {$Y}) AND - ({$M} IS NULL OR MONTH(time_insert) = {$M}) AND - ({$D} IS NULL OR DAY(time_insert) = {$D}) AND - MATCH(name, body) AGAINST(? IN BOOLEAN MODE) LIMIT 20", Attribute::TABLE)); - - if($Statement->execute([$search])) { - return $Statement->fetchAll($Database::FETCH_COLUMN); - } - - return []; - } -} diff --git a/core/namespace/Post/Repository.php b/core/namespace/Post/Repository.php new file mode 100644 index 0000000..5a3d834 --- /dev/null +++ b/core/namespace/Post/Repository.php @@ -0,0 +1,17 @@ +<?php +namespace Post; + +class Repository extends \Repository { + public static function getTableName(): string { return 'post'; } + public static function getClassName(): string { return 'Post\Entity'; } + + public function getCountByUser(\User\Entity $User): int { + $query = 'SELECT COUNT(id) FROM %s WHERE user = ?'; + $query = sprintf($query, static::getTableName()); + + $Statement = $this->Database->prepare($query); + $Statement->execute([$User->getID()]); + + return $Statement->fetchColumn(); + } +} |