-
Notifications
You must be signed in to change notification settings - Fork 45
Word filters #311
base: master
Are you sure you want to change the base?
Word filters #311
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* @author MyBB Group | ||
* @version 2.0.0 | ||
* @package mybb/core | ||
* @license http://www.mybb.com/licenses/bsd3 BSD-3 | ||
*/ | ||
|
||
namespace MyBB\Core\Database\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use McCool\LaravelAutoPresenter\HasPresenter; | ||
use MyBB\Core\Presenters\WordFilterPresenter; | ||
|
||
/** | ||
* @property int id | ||
*/ | ||
class WordFilter extends Model implements HasPresenter | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $table = 'parser_badwords'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'id' => 'int', | ||
'find' => 'string', | ||
'replace' => 'string', | ||
]; | ||
|
||
public function getID() : int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer this styled as |
||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getPresenterClass() : string | ||
{ | ||
return WordFilterPresenter::class; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* @author MyBB Group | ||
* @version 2.0.0 | ||
* @package mybb/core | ||
* @license http://www.mybb.com/licenses/bsd3 BSD-3 | ||
*/ | ||
|
||
namespace MyBB\Core\Database\Repositories\Eloquent; | ||
|
||
use MyBB\Core\Database\Repositories\Collection; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Group the two Repository classes together like: use MyBB\Core\Database\Repositories\{
Collection,
WordFilterRepositoryInterface
}; |
||
use MyBB\Core\Database\Models\WordFilter; | ||
use MyBB\Core\Database\Repositories\WordFilterRepositoryInterface; | ||
|
||
class WordFilterRepository implements WordFilterRepositoryInterface | ||
{ | ||
/** | ||
* @var WordFilter | ||
*/ | ||
protected $wordFilter; | ||
|
||
/** | ||
* @param WordFilter $wordFilter | ||
*/ | ||
public function __construct(WordFilter $wordFilter) | ||
{ | ||
$this->wordFilter = $wordFilter; | ||
} | ||
|
||
public function getAll() : \Illuminate\Database\Eloquent\Collection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a collection interface/contract, it's better to state that we return an interface rather than a concrete type. |
||
{ | ||
return $this->wordFilter->all(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* @author MyBB Group | ||
* @version 2.0.0 | ||
* @package mybb/core | ||
* @license http://www.mybb.com/licenses/bsd3 BSD-3 | ||
*/ | ||
|
||
namespace MyBB\Core\Database\Repositories; | ||
|
||
//use Illuminate\Support\Collection; | ||
use Illuminate\Database\Eloquent\Collection; | ||
use MyBB\Core\Database\Models\WordFilter; | ||
|
||
interface WordFilterRepositoryInterface | ||
{ | ||
// TODO: Implement this | ||
//public function find(int $id) : WordFilter; | ||
|
||
public function getAll() : \Illuminate\Database\Eloquent\Collection; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I think there's a collection interface/contract, it's better to state that we return an interface rather than a concrete type. It's probably also best to have a |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* @author MyBB Group | ||
* @version 2.0.0 | ||
* @package mybb/core | ||
* @license http://www.mybb.com/licenses/bsd3 BSD-3 | ||
*/ | ||
|
||
namespace MyBB\Core\Http\Controllers\Admin\Users; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\View\View; | ||
use DaveJamesMiller\Breadcrumbs\Manager as Breadcrumbs; | ||
use MyBB\Core\Database\Repositories\WordFilterRepositoryInterface; | ||
use MyBB\Core\Http\Controllers\Admin\AdminController; | ||
|
||
class WordFilterController extends AdminController | ||
{ | ||
/** | ||
* @var Breadcrumbs | ||
*/ | ||
private $breadcrumbs; | ||
|
||
/** | ||
* @var WordFilterRepositoryInterface | ||
*/ | ||
private $wordFilterRepository; | ||
|
||
public function __construct( | ||
Breadcrumbs $breadcrumbs, | ||
WordFilterRepositoryInterface $wordFilterRepository | ||
) { | ||
$this->breadcrumbs = $breadcrumbs; | ||
$this->wordFilterRepository = $wordFilterRepository; | ||
} | ||
|
||
public function index() : \Illuminate\View\View | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I prefer to return a response interface in the function signature, in case something changes in the future. |
||
{ | ||
$this->breadcrumbs->setCurrentRoute('admin.word_filters.index'); | ||
|
||
return view('admin.users.word_filters', [ | ||
'word_filter_items' => $this->wordFilterRepository->getAll(), | ||
])->withActive('word-filters'); | ||
} | ||
|
||
// TODO Implement this properly, this is a placeholder | ||
public function add() : \Illuminate\View\View | ||
{ | ||
$this->breadcrumbs->setCurrentRoute('admin.word_filters.index'); | ||
|
||
return view('admin.users.word_filters', [ | ||
'word_filter_items' => $this->wordFilterRepository->getAll(), | ||
])->withActive('word-filters'); | ||
} | ||
|
||
// TODO Implement this properly, this is a placeholder | ||
/*public function addSubmit(WordFilterRequest $request) : \Illuminate\View\View | ||
{ | ||
$this->breadcrumbs->setCurrentRoute('admin.word_filters.index'); | ||
|
||
return view('admin.users.word_filters', [ | ||
'word_filter_items' => $this->wordFilterRepository->getAll(), | ||
])->withActive('word-filters'); | ||
}*/ | ||
|
||
// TODO Implement this properly, this is a placeholder | ||
public function edit() : \Illuminate\View\View | ||
{ | ||
$this->breadcrumbs->setCurrentRoute('admin.word_filters.index'); | ||
|
||
return view('admin.users.word_filters', [ | ||
'word_filter_items' => $this->wordFilterRepository->getAll(), | ||
])->withActive('word-filters'); | ||
} | ||
|
||
// TODO Implement this properly, this is a placeholder | ||
public function delete() : \Illuminate\View\View | ||
{ | ||
$this->breadcrumbs->setCurrentRoute('admin.word_filters.index'); | ||
|
||
return view('admin.users.word_filters', [ | ||
'word_filter_items' => $this->wordFilterRepository->getAll(), | ||
])->withActive('word-filters'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* @author MyBB Group | ||
* @version 2.0.0 | ||
* @package mybb/core | ||
* @license http://www.mybb.com/licenses/bsd3 BSD-3 | ||
*/ | ||
|
||
namespace MyBB\Core\Presenters; | ||
|
||
use Illuminate\Contracts\Auth\Guard; | ||
use McCool\LaravelAutoPresenter\BasePresenter; | ||
use MyBB\Core\Database\Models\WordFilter as WordFilterModel; | ||
use MyBB\Core\Form\RenderableInterface; | ||
|
||
class WordFilterPresenter extends BasePresenter | ||
{ | ||
/** | ||
* @var Guard | ||
*/ | ||
protected $guard; | ||
|
||
public function __construct(WordFilterModel $resource, Guard $guard) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
parent::__construct($resource); | ||
$this->guard = $guard; | ||
} | ||
|
||
public function find() : string | ||
{ | ||
return $this->wrappedObject->find; | ||
} | ||
|
||
public function replace() : string | ||
{ | ||
return $this->wrappedObject->replace; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* @author MyBB Group | ||
* @version 2.0.0 | ||
* @package mybb/core | ||
* @license http://www.mybb.com/licenses/bsd3 BSD-3 | ||
*/ | ||
|
||
return [ | ||
'title' => 'Word Filters', | ||
'add_button' => 'Add Word Filter', | ||
'find_field' => 'Find', | ||
'replace_field' => 'Replacement', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't bother trying to line all the values up, it just gets annoying trying to maintain it later down the line 😉 |
||
'edit' => 'Edit', | ||
'delete' => 'Delete', | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% extends "layouts.admin" %} | ||
{% block title %}{% endblock %} | ||
{% block contents %} | ||
<div class="admin-body__header"> | ||
<h1 class="admin-body__header__title">{{ trans('admin::word_filters.title') }}</h1> | ||
<div class="admin-body__header__buttons"> | ||
<a href="{{ url_route('admin.word_filters.add') }}" class="button"><i class="fa fa-plus"></i> {{ trans('admin::word_filters.add_button') }}</a> | ||
</div> | ||
</div> | ||
<div class="admin-body__content" style="display: flex;flex-direction: row;"> | ||
<table class="admin-table admin-table--bordered users" style="width:79%;"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Paging @Eric-Jackson 😛 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mentioned to @Azareal in Discord, we will want to avoid inline style and tables. For now the classes already available on these elements should work fine for removing that inline stuff, the tables can be replaced later so I wouldn't worry about them at this moment. The class "users" should be replaced with something more appropriate |
||
<thead> | ||
<tr> | ||
<th>{{ trans('admin::word_filters.find_field') }}</th> | ||
<th>{{ trans('admin::word_filters.replace_field') }}</th> | ||
<th>{{ trans('admin::general.actions_field') }}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for filter in word_filter_items %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a good idea to use an |
||
<tr> | ||
<td>{{ filter.find }}</td> | ||
<td>{{ filter.replace }}</td> | ||
<td> | ||
<a href="{{ url_route('admin.word_filters.edit', {'id': filter.id}) }}" class="button button--secondary"><i class="fa fa-pencil"></i> {{ trans('admin::word_filters.edit') }}</a> | ||
|
||
{{ form_open({'route': ['admin.word_filters.delete'], 'method': 'post', 'style': 'display: inline;'}) }} | ||
<input type="hidden" name="word_filter_id" value="{{ filter.id }}"> | ||
<button type="submit" class="button button--secondary button--danger"><i class="fa fa-remove"></i> {{ trans('admin::word_filters.delete') }}</button> | ||
{{ form_close() }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
{% endblock %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation here is a little weird for some reason.