mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Add CategoryRegexesController
This commit is contained in:
+21
-15
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace Blacklight;
|
||||
|
||||
use App\Models\CategoryRegex;
|
||||
use App\Models\Group;
|
||||
use App\Models\ReleaseNamingRegex;
|
||||
use Blacklight\db\DB;
|
||||
use App\Models\Release;
|
||||
use App\Models\Category;
|
||||
@@ -113,24 +115,28 @@ class Regexes
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all regex.
|
||||
* @param string $group_regex
|
||||
*
|
||||
* @param string $group_regex Optional, a keyword to find a group.
|
||||
* @param int $limit Optional, amount of results to limit.
|
||||
* @param int $offset Optional, the offset to use when limiting the result set.
|
||||
*
|
||||
* @return array
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRegex($group_regex = '', $limit = 0, $offset = 0): array
|
||||
public function getRegex($group_regex = '')
|
||||
{
|
||||
return $this->pdo->query(
|
||||
sprintf(
|
||||
'SELECT * FROM %s %s ORDER BY id %s',
|
||||
$this->tableName,
|
||||
$this->_groupQueryString($group_regex),
|
||||
($limit ? ('LIMIT '.$limit.' OFFSET '.$offset) : '')
|
||||
)
|
||||
);
|
||||
if ($this->tableName === 'collection_regexes') {
|
||||
$table = CollectionRegex::class;
|
||||
} elseif ($this->tableName === 'category_regexes') {
|
||||
$table = CategoryRegex::class;
|
||||
} else {
|
||||
$table = ReleaseNamingRegex::class;
|
||||
}
|
||||
|
||||
$result = $table::query();
|
||||
if ($group_regex !== '') {
|
||||
$result->where('group_regex', 'LIKE', '%'.$group_regex.'%');
|
||||
}
|
||||
$result->orderBy('id');
|
||||
return $result->paginate(config('nntmux.items_per_page'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
2018-04-18 DariusIII
|
||||
* Chg: Add CategoryRegexesController
|
||||
2018-04-17 DariusIII
|
||||
* Chg: Rename admin to oldadmin folder
|
||||
* Chg: Update admin theme
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\BasePageController;
|
||||
use App\Models\Category;
|
||||
use Blacklight\Regexes;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CategoryRegexesController extends BasePageController
|
||||
{
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->setAdminPrefs();
|
||||
$regexes = new Regexes(['Settings' => $this->pdo, 'Table_Name' => 'category_regexes']);
|
||||
|
||||
$title = 'Category Regex List';
|
||||
|
||||
$group = $request->has('group') && ! empty($request->input('group')) ? $request->input('group') : '';
|
||||
$regex = $regexes->getRegex($group);
|
||||
|
||||
$this->smarty->assign(
|
||||
[
|
||||
'group' => $group,
|
||||
'regex' => $regex,
|
||||
]
|
||||
);
|
||||
|
||||
$content = $this->smarty->fetch('category_regexes-list.tpl');
|
||||
|
||||
$this->smarty->assign(
|
||||
[
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
]
|
||||
);
|
||||
|
||||
$this->adminrender();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function edit(Request $request)
|
||||
{
|
||||
$this->setAdminPrefs();
|
||||
$regexes = new Regexes(['Settings' => $this->pdo, 'Table_Name' => 'category_regexes']);
|
||||
|
||||
// Set the current action.
|
||||
$action = $request->input('action') ?? 'view';
|
||||
|
||||
$regex = [
|
||||
'id' => '',
|
||||
'group_regex' => '',
|
||||
'regex' => '',
|
||||
'description' => '',
|
||||
'ordinal' => '',
|
||||
'categories_id' => '',
|
||||
'status' => 1, ];
|
||||
|
||||
$this->smarty->assign('regex', $regex);
|
||||
|
||||
switch ($action) {
|
||||
case 'submit':
|
||||
if ($request->input('group_regex') === '') {
|
||||
$this->smarty->assign('error', 'Group regex must not be empty!');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($request->input('regex') === '') {
|
||||
$this->smarty->assign('error', 'Regex cannot be empty');
|
||||
break;
|
||||
}
|
||||
|
||||
if (! is_numeric($request->input('ordinal')) || $request->input('ordinal') < 0) {
|
||||
$this->smarty->assign('error', 'Ordinal must be a number, 0 or higher.');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($request->input('id') === '') {
|
||||
$regexes->addRegex($request->all());
|
||||
} else {
|
||||
$regexes->updateRegex($request->all());
|
||||
}
|
||||
|
||||
return redirect('category_regexes-list');
|
||||
break;
|
||||
|
||||
case 'view':
|
||||
default:
|
||||
if ($request->has('id')) {
|
||||
$title = 'Category Regex Edit';
|
||||
$id = $request->input('id');
|
||||
$regex = $regexes->getRegexByID($id);
|
||||
} else {
|
||||
$title = 'Category Regex Add';
|
||||
}
|
||||
$this->smarty->assign('regex', $regex);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->smarty->assign('status_ids', [Category::STATUS_ACTIVE, Category::STATUS_INACTIVE]);
|
||||
$this->smarty->assign('status_names', ['Yes', 'No']);
|
||||
|
||||
$categories_db = Category::query()
|
||||
->select(['c.id', 'c.title', 'cp.title as parent_title'])
|
||||
->from('categories as c')
|
||||
->join('categories as cp', 'c.parentid', '=', 'cp.id')
|
||||
->whereNotNull('c.parentid')
|
||||
->orderBy('c.id')
|
||||
->get();
|
||||
$categories = ['category_names', 'category_ids'];
|
||||
if ($categories_db) {
|
||||
foreach ($categories_db as $category_db) {
|
||||
$categories['category_names'][] = $category_db->parent_title.' '.$category_db->title.': '.$category_db->id;
|
||||
$categories['category_ids'][] = $category_db->id;
|
||||
}
|
||||
}
|
||||
$this->smarty->assign('category_names', $categories['category_names']);
|
||||
$this->smarty->assign('category_ids', $categories['category_ids']);
|
||||
|
||||
$content = $this->smarty->fetch('category_regexes-edit.tpl');
|
||||
$this->smarty->assign(
|
||||
[
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
]
|
||||
);
|
||||
$this->adminrender();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CategoryRegex extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CollectionRegex extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
+43
-41
@@ -196,45 +196,47 @@ Route::get('nzbvortex', 'QueueController@nzbvortex');
|
||||
Route::post('nzbvortex', 'QueueController@nzbvortex');
|
||||
|
||||
Route::prefix('admin')->group(function () {
|
||||
Route::get('index', 'Admin\AdminPageController@index');
|
||||
Route::get('anidb-delete/{id}', 'Admin\AnidbController@destroy');
|
||||
Route::post('anidb-delete/{id}', 'Admin\AnidbController@destroy');
|
||||
Route::get('anidb-edit/{id}', 'Admin\AnidbController@edit');
|
||||
Route::post('anidb-edit/{id}', 'Admin\AnidbController@edit');
|
||||
Route::get('anidb-list', 'Admin\AnidbController@index');
|
||||
Route::post('anidb-list', 'Admin\AnidbController@index');
|
||||
Route::get('binaryblacklist-list', 'Admin\BlacklistController@index');
|
||||
Route::post('binaryblacklist-list', 'Admin\BlacklistController@index');
|
||||
Route::get('binaryblacklist-edit', 'Admin\BlacklistController@edit');
|
||||
Route::post('binaryblacklist-edit', 'Admin\BlacklistController@edit');
|
||||
Route::get('book-list', 'Admin\BookController@index');
|
||||
Route::post('book-list', 'Admin\BookController@index');
|
||||
Route::get('book-edit', 'Admin\BookController@edit');
|
||||
Route::post('book-edit', 'Admin\BookController@edit');
|
||||
Route::get('category-list', 'Admin\CategoryController@index');
|
||||
Route::post('category-list', 'Admin\CategoryController@index');
|
||||
Route::get('category-edit', 'Admin\CategoryController@edit');
|
||||
Route::post('category-edit', 'Admin\CategoryController@edit');
|
||||
Route::get('user-list', 'Admin\UserController@index');
|
||||
Route::post('user-list', 'Admin\UserController@index');
|
||||
Route::get('user-edit', 'Admin\UserController@edit');
|
||||
Route::post('user-edit', 'Admin\UserController@edit');
|
||||
Route::get('user-delete', 'Admin\UserController@destroy');
|
||||
Route::post('user-delete', 'Admin\UserController@destroy');
|
||||
Route::get('site-edit', 'Admin\SiteController@edit');
|
||||
Route::post('site-edit', 'Admin\SiteController@edit');
|
||||
Route::get('site-stats', 'Admin\SiteController@stats');
|
||||
Route::post('site-stats', 'Admin\SiteController@stats');
|
||||
Route::get('role-list', 'Admin\RoleController@index');
|
||||
Route::post('role-list', 'Admin\RoleController@index');
|
||||
Route::get('role-edit', 'Admin\RoleController@edit');
|
||||
Route::post('role-edit', 'Admin\RoleController@edit');
|
||||
Route::get('role-delete', 'Admin\RoleController@destroy');
|
||||
Route::post('role-delete', 'Admin\RoleController@destroy');
|
||||
Route::get('content-list', 'Admin\ContentController@index');
|
||||
Route::post('content-list', 'Admin\ContentController@index');
|
||||
Route::get('content-add', 'Admin\ContentController@create');
|
||||
Route::post('content-add', 'Admin\ContentController@create');
|
||||
Route::get('content-delete', 'Admin\ContentController@destroy');
|
||||
Route::post('content-delete', 'Admin\ContentController@destroy');
|
||||
Route::namespace('Admin')->group(function () {
|
||||
Route::get('index', 'AdminPageController@index');
|
||||
Route::get('anidb-delete/{id}', 'AnidbController@destroy');
|
||||
Route::post('anidb-delete/{id}', 'AnidbController@destroy');
|
||||
Route::get('anidb-edit/{id}', 'AnidbController@edit');
|
||||
Route::post('anidb-edit/{id}', 'AnidbController@edit');
|
||||
Route::get('anidb-list', 'AnidbController@index');
|
||||
Route::post('anidb-list', 'AnidbController@index');
|
||||
Route::get('binaryblacklist-list', 'BlacklistController@index');
|
||||
Route::post('binaryblacklist-list', 'BlacklistController@index');
|
||||
Route::get('binaryblacklist-edit', 'BlacklistController@edit');
|
||||
Route::post('binaryblacklist-edit', 'BlacklistController@edit');
|
||||
Route::get('book-list', 'BookController@index');
|
||||
Route::post('book-list', 'BookController@index');
|
||||
Route::get('book-edit', 'BookController@edit');
|
||||
Route::post('book-edit', 'BookController@edit');
|
||||
Route::get('category-list', 'CategoryController@index');
|
||||
Route::post('category-list', 'CategoryController@index');
|
||||
Route::get('category-edit', 'CategoryController@edit');
|
||||
Route::post('category-edit', 'CategoryController@edit');
|
||||
Route::get('user-list', 'UserController@index');
|
||||
Route::post('user-list', 'UserController@index');
|
||||
Route::get('user-edit', 'UserController@edit');
|
||||
Route::post('user-edit', 'UserController@edit');
|
||||
Route::get('user-delete', 'UserController@destroy');
|
||||
Route::post('user-delete', 'UserController@destroy');
|
||||
Route::get('site-edit', 'SiteController@edit');
|
||||
Route::post('site-edit', 'SiteController@edit');
|
||||
Route::get('site-stats', 'SiteController@stats');
|
||||
Route::post('site-stats', 'SiteController@stats');
|
||||
Route::get('role-list', 'RoleController@index');
|
||||
Route::post('role-list', 'RoleController@index');
|
||||
Route::get('role-edit', 'RoleController@edit');
|
||||
Route::post('role-edit', 'RoleController@edit');
|
||||
Route::get('role-delete', 'RoleController@destroy');
|
||||
Route::post('role-delete', 'RoleController@destroy');
|
||||
Route::get('content-list', 'ContentController@index');
|
||||
Route::post('content-list', 'ContentController@index');
|
||||
Route::get('content-add', 'ContentController@create');
|
||||
Route::post('content-add', 'ContentController@create');
|
||||
Route::get('content-delete', 'ContentController@destroy');
|
||||
Route::post('content-delete', 'ContentController@destroy');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user