This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Pager): Torrents/{SearchForm,TagsForm}
- Loading branch information
Showing
8 changed files
with
138 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 8/6/2019 | ||
* Time: 9:10 PM | ||
*/ | ||
|
||
namespace apps\models\form\Torrents; | ||
|
||
|
||
use apps\models\Torrent; | ||
use Rid\Validators\Pager; | ||
|
||
class SearchForm extends Pager | ||
{ | ||
public $tags; | ||
|
||
static $max_limit = 100; | ||
|
||
private $_tags; | ||
|
||
private function getTagsArray() | ||
{ | ||
if (is_null($this->_tags)) { | ||
$tags = $this->getData('tags'); | ||
$this->_tags = $tags ? array_map('trim', explode(',', $tags)) : []; | ||
} | ||
|
||
return $this->_tags; | ||
} | ||
|
||
protected function getRemoteTotal() | ||
{ | ||
$tags = $this->getTagsArray(); | ||
|
||
return app()->pdo->createCommand([ | ||
['SELECT COUNT(t.`id`) FROM `torrents` t '], | ||
['INNER JOIN map_torrents_tags mtt on t.id = mtt.torrent_id INNER JOIN tags t2 on mtt.tag_id = t2.id ', 'if' => count($tags)], | ||
['WHERE 1=1 '], | ||
['AND t2.tag IN(:tags) ', 'if' => count($tags), 'params' => ['tags' => $tags]], | ||
])->queryScalar(); | ||
} | ||
|
||
protected function getRemoteData() | ||
{ | ||
$tags = $this->getTagsArray(); | ||
|
||
$fetch = app()->pdo->createCommand([ | ||
['SELECT DISTINCT t.`id`, t.`added_at` FROM `torrents` t '], | ||
['INNER JOIN map_torrents_tags mtt on t.id = mtt.torrent_id INNER JOIN tags t2 on mtt.tag_id = t2.id ', 'if' => count($tags)], | ||
['WHERE 1=1 '], | ||
['AND t2.tag IN(:tags) ', 'if' => count($tags), 'params' => ['tags' => $tags]], | ||
['ORDER BY `t`.`added_at` DESC '], | ||
['LIMIT :offset, :rows', 'params' => ['offset' => $this->offset, 'rows' => $this->limit]], | ||
])->queryColumn(); | ||
|
||
return array_map(function ($id) { | ||
return new Torrent($id); | ||
}, $fetch); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 8/6/2019 | ||
* Time: 8:52 PM | ||
*/ | ||
|
||
namespace apps\models\form\Torrents; | ||
|
||
|
||
use Rid\Validators\Pager; | ||
|
||
class TagsForm extends Pager | ||
{ | ||
public $search; | ||
|
||
static $max_limit = 100; | ||
|
||
public function getRemoteTotal() | ||
{ | ||
return app()->pdo->createCommand([ | ||
['SELECT COUNT(tags.id) as `count` FROM tags'], | ||
['WHERE `tags`.`tag` LIKE :tag', 'if' => !empty($search), 'params' => ['tag' => '%' . $this->getData('search') . '%']], | ||
])->queryScalar(); | ||
} | ||
|
||
public function getRemoteData() | ||
{ | ||
$search = $this->search; | ||
return app()->pdo->createCommand([ | ||
['SELECT tags.*,COUNT(mtt.id) as `count` FROM tags LEFT JOIN map_torrents_tags mtt on tags.id = mtt.tag_id '], | ||
['WHERE `tags`.`tag` LIKE :tag', 'if' => !empty($search), 'params' => ['tag' => '%' . $search . '%']], | ||
['GROUP BY tags.id ORDER BY `tags`.`pinned`,`count` DESC '], | ||
['LIMIT :offset, :rows', 'params' => ['offset' => $this->offset, 'rows' => $this->limit]], | ||
])->queryAll(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters