diff --git a/CHANGELOG.md b/CHANGELOG.md index c9fccf4..09a2d8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,14 +8,15 @@ - **gitignore:** Add ignore of `/backup` folder ### Feat +- **Category:** Add Image and class_name support - **Category:** Add Categories Manage Pane - **Category:** Add Default sprite image of category -- **Category:** Add Image and class_name support - **Category:** Add Categories Support when upload torrent - **Crontab:** Move From Timer to Process - **Editor:** Support wysibb editor - **Gravatar:** Add support of gravatar - **Pager:** Add Pager Support +- **Pager:** Torrents/{SearchForm,TagsForm} - **Process:** Clean Components before sleep - **Process:** Add custom Process Support - **Redis:** Add mutiDelete() function for Redis diff --git a/apps/controllers/TorrentController.php b/apps/controllers/TorrentController.php index 7017808..f4184dc 100644 --- a/apps/controllers/TorrentController.php +++ b/apps/controllers/TorrentController.php @@ -9,6 +9,7 @@ namespace apps\controllers; use apps\models\Torrent; +use apps\models\form\Torrent as TorrentForm; use Rid\Http\Controller; @@ -29,10 +30,14 @@ public function actionEdit() // TODO public function actionSnatch() // TODO { - $tid = app()->request->get('id'); - $torrent = new Torrent($tid); + $pager = new TorrentForm\SnatchForm(); + $pager->setData(app()->request->get()); + $success = $pager->validate(); + if (!$success) { + return $this->render('action/action_fail'); + } - return $this->render('torrent/snatch', ['torrent' => $torrent]); + return $this->render('torrent/snatch', ['pager' => $pager]); } public function actionDownload() diff --git a/apps/messages/.gitkeep b/apps/messages/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/apps/models/Torrent.php b/apps/models/Torrent.php index 21b2c16..183c912 100644 --- a/apps/models/Torrent.php +++ b/apps/models/Torrent.php @@ -318,8 +318,9 @@ public function getPinnedTags(): array }); } - public function hasNfo() { - return (boolean) $this->nfo; + public function hasNfo() + { + return (boolean)$this->nfo; } /** @@ -368,7 +369,8 @@ protected static function nfoConvert($ibm_437, $swedishmagic = false) return $s; } - public function getComments() { + public function getComments() + { return $this->comments; } @@ -382,11 +384,4 @@ public function getLastCommentsDetails() }); } - public function getSnatchDetails() { - return $this->getCacheValue('snatched_details', function () { - return app()->pdo->createCommand('SELECT * FROM `snatched` WHERE `torrent_id` = :tid ORDER BY finish_at,create_at DESC;')->bindParams([ - 'tid' => $this->id - ])->queryAll(); - }); - } } diff --git a/apps/models/api/v1/form/TorrentsForm.php b/apps/models/api/v1/form/TorrentsForm.php index 4f25cd8..8877fe6 100644 --- a/apps/models/api/v1/form/TorrentsForm.php +++ b/apps/models/api/v1/form/TorrentsForm.php @@ -8,10 +8,13 @@ namespace apps\models\api\v1\form; -use apps\models\form\Base\TorrentForm; +use apps\models\form\Traits\isValidTorrentTrait; -class TorrentsForm extends TorrentForm +use Rid\Validators\Validator; + +class TorrentsForm extends Validator { + use isValidTorrentTrait; public static function inputRules() { diff --git a/apps/models/form/Torrent/SnatchForm.php b/apps/models/form/Torrent/SnatchForm.php new file mode 100644 index 0000000..9b4923b --- /dev/null +++ b/apps/models/form/Torrent/SnatchForm.php @@ -0,0 +1,45 @@ + 'required | Integer' + ]); + } + + public static function callbackRules() + { + return ['checkPager', 'isExistTorrent']; + } + + protected function getRemoteTotal() + { + $tid = $this->getData('id'); + return app()->pdo->createCommand('SELECT COUNT(`id`) FROM `snatched` WHERE `torrent_id` = :tid')->bindParams([ + 'tid' => $tid + ])->queryScalar(); + } + + protected function getRemoteData() + { + return app()->pdo->createCommand([ + ['SELECT * FROM `snatched` WHERE `torrent_id` = :tid ORDER BY finish_at,create_at DESC ', 'params' => ['tid' => $this->id]], + ['LIMIT :offset, :limit', 'params' => ['offset' => $this->offset, 'limit' => $this->limit]] + ])->queryAll(); + } +} diff --git a/apps/models/form/Torrents/UploadForm.php b/apps/models/form/Torrents/UploadForm.php index 498666e..72699bd 100644 --- a/apps/models/form/Torrents/UploadForm.php +++ b/apps/models/form/Torrents/UploadForm.php @@ -376,7 +376,7 @@ private function insertTags() } } - // TODO sep to Trait + // TODO sep to Traits private function setTorrentBuff($operator_id = 0, $beneficiary_id = 0, $buff_type = 'mod', $ratio_type = 'Normal', $upload_ratio = 1, $download_ratio = 1) { diff --git a/apps/models/form/Base/TorrentForm.php b/apps/models/form/Traits/isValidTorrentTrait.php similarity index 77% rename from apps/models/form/Base/TorrentForm.php rename to apps/models/form/Traits/isValidTorrentTrait.php index db33a56..1d0eb8c 100644 --- a/apps/models/form/Base/TorrentForm.php +++ b/apps/models/form/Traits/isValidTorrentTrait.php @@ -3,24 +3,30 @@ * Created by PhpStorm. * User: Rhilip * Date: 8/6/2019 - * Time: 5:20 PM + * Time: 11:06 PM */ -namespace apps\models\form\Base; +namespace apps\models\form\Traits; use apps\models\Torrent; -use Rid\Validators\Validator; -class TorrentForm extends Validator +trait isValidTorrentTrait { - public $id; public $tid; /** @var Torrent */ protected $torrent; + /** + * @return Torrent + */ + public function getTorrent(): Torrent + { + return $this->torrent; + } + protected function isExistTorrent() { $tid = $this->getData('tid') ?? $this->getData('id'); $torrent_exist = app()->pdo->createCommand('SELECT COUNT(`id`) FROM `torrents` WHERE `id` = :tid')->bindParams([ diff --git a/apps/views/torrent/snatch.php b/apps/views/torrent/snatch.php index cbae056..61eeca2 100644 --- a/apps/views/torrent/snatch.php +++ b/apps/views/torrent/snatch.php @@ -6,10 +6,11 @@ * Time: 17:10 * * @var League\Plates\Template\Template $this - * @var \apps\models\Torrent $torrent + * @var \apps\models\form\Torrent\SnatchForm $pager */ $timenow = time(); +$torrent = $pager->getTorrent(); ?> layout('layout/base') ?> @@ -28,16 +29,7 @@
Torrent Snatched Details
- getSnatchDetails()): ?> - getSnatchDetails(); - $count = count($torrent->getSnatchDetails()); - $limit = app()->request->get('limit',50); - if ($limit > 50) $limit = 50; - $page = app()->request->get('page',1); - $offset = ($page - 1) * $limit; - if ($offset > $count / $limit) $offset = intval($count/$limit); - ?> + getDataTotal()): ?> @@ -54,7 +46,7 @@ - getSnatchDetails(), $offset, $limit) as $snatchDetail): ?> + getPagerData() as $snatchDetail): ?> @@ -84,7 +76,7 @@
insert('helper/username',['user'=>app()->site->getUser($snatchDetail['user_id'])]) ?>
-
    +
      No Snatched Records exist. diff --git a/apps/views/torrents/list.php b/apps/views/torrents/list.php index e70753f..7404495 100644 --- a/apps/views/torrents/list.php +++ b/apps/views/torrents/list.php @@ -93,7 +93,7 @@
      -
        +