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(Site): Add page Site/{Logs,Rules}
- Loading branch information
Showing
17 changed files
with
245 additions
and
203 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,30 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 8/17/2019 | ||
* Time: 2019 | ||
*/ | ||
|
||
namespace apps\controllers; | ||
|
||
|
||
use apps\models\form\Site; | ||
use Rid\Http\Controller; | ||
|
||
class SiteController extends Controller | ||
{ | ||
public function actionRules() | ||
{ | ||
return $this->render('site/rules'); | ||
} | ||
|
||
public function actionLogs() | ||
{ | ||
$logs = new Site\Logs(); | ||
if (!$logs->validate()) { | ||
return $this->render('action/action_fail',['msg'=>$logs->getError()]); | ||
} | ||
return $this->render('site/logs',['logs'=>$logs]); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 8/17/2019 | ||
* Time: 2019 | ||
*/ | ||
|
||
namespace apps\models\form\Site; | ||
|
||
|
||
use Rid\Validators\Pagination; | ||
|
||
class Logs extends Pagination | ||
{ | ||
|
||
protected $_levels; | ||
|
||
public static $MAX_LIMIT = 100; | ||
|
||
protected $_autoload = true; | ||
protected $_autoload_from = ['get']; | ||
|
||
public static function defaultData(): array | ||
{ | ||
return [ | ||
'page' => static::getDefaultPage(), | ||
'limit' => static::getDefaultLimit(), | ||
'level' => 'all' | ||
]; | ||
} | ||
|
||
public static function inputRules(): array | ||
{ | ||
$level_list = ['all', 'normal']; | ||
if (app()->auth->getCurUser()->isPrivilege('see_site_log_mod')) $level_list[] = 'mod'; | ||
if (app()->auth->getCurUser()->isPrivilege('see_site_log_leader')) $level_list[] = 'leader'; | ||
|
||
return [ | ||
'page' => 'Integer', 'limit' => 'Integer', | ||
'level' => [ | ||
['RequiredWith', ['item' => 'query']], | ||
['inList', ['list' => $level_list]] | ||
] | ||
]; | ||
} | ||
|
||
private function getLevels() { | ||
if (!is_null($this->_levels)) return $this->_levels; | ||
|
||
$input_level = $this->getInput('level'); | ||
if ($input_level == 'all') { | ||
$levels = ['normal']; | ||
if (app()->auth->getCurUser()->isPrivilege('see_site_log_mod')) $levels[] = 'mod'; | ||
if (app()->auth->getCurUser()->isPrivilege('see_site_log_leader')) $levels[] = 'leader'; | ||
} else { | ||
$levels = [$input_level]; | ||
} | ||
|
||
$this->_levels = $levels; | ||
return $this->_levels; | ||
} | ||
|
||
protected function getRemoteTotal(): int | ||
{ | ||
$search = $this->getInput('query'); | ||
return app()->pdo->createCommand([ | ||
['SELECT COUNT(*) FROM `site_log` WHERE 1=1 '], | ||
['AND `level` IN (:l) ', 'params' => ['l' => $this->getLevels()]], | ||
['AND `msg` LIKE :search ', 'if' => strlen($search), 'params' => ['search' => "%$search%"]] | ||
])->queryScalar(); | ||
} | ||
|
||
protected function getRemoteData(): array | ||
{ | ||
$search = $this->getInput('query'); | ||
return app()->pdo->createCommand([ | ||
['SELECT * FROM `site_log` WHERE 1=1 '], | ||
['AND `level` IN (:l) ', 'params' => ['l' => $this->getLevels()]], | ||
['AND `msg` LIKE :search ', 'if' => strlen($search), 'params' => ['search' => "%$search%"]], | ||
['ORDER BY create_at 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 8/17/2019 | ||
* Time: 2019 | ||
* | ||
* @var League\Plates\Template\Template $this | ||
* @var \apps\models\form\Site\Logs $logs | ||
*/ | ||
?> | ||
|
||
<?= $this->layout('layout/base') ?> | ||
|
||
<?php $this->start('title') ?>Site Logs<?php $this->end(); ?> | ||
|
||
<?php $this->start('container') ?> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="panel"> | ||
<div class="panel-heading">Search Daily Log</div> | ||
<div class="panel-body"> | ||
<form class="form form-inline" method="get"> | ||
<div class="form-group"> | ||
<label for="query"></label> | ||
<input id="query" class="form-control col-md-6" type="text" name="query" value="<?= $this->e(app()->request->get('query')) ?>" style="width: 500px"> | ||
</div> | ||
<div class="form-group"> | ||
<label for="level"> In </label> | ||
<select id="level" class="form-control" name="level"> | ||
<option value="all"<?= app()->request->get('level') == 'all' ? ' selected' : '' ?>>all</option> | ||
<option value="normal"<?= app()->request->get('level') == 'normal' ? ' selected' : '' ?>>normal</option> | ||
<?php if (app()->auth->getCurUser()->isPrivilege('see_site_log_mod')): ?> | ||
<option value="mod"<?= app()->request->get('level') == 'mod' ? ' selected' : '' ?>>mod</option> | ||
<?php endif; ?> | ||
<?php if (app()->auth->getCurUser()->isPrivilege('see_site_log_leader')): ?> | ||
<option value="leader"<?= app()->request->get('level') == 'leader' ? ' selected' : '' ?>>leader</option> | ||
<?php endif; ?> | ||
</select> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Search</button> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="panel"> | ||
<div class="panel-heading">Other rules</div> | ||
<div class="panel-body"> | ||
<table class="table table-striped table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Time</th> | ||
<th style="width: 99%;">Event</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($logs->getPagerData() as $log) : ?> | ||
<tr> | ||
<td><span class="nowrap"><?= $log['create_at'] ?></span></td> | ||
<td><?= $this->e($log['msg']) ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</tbody> | ||
</table> | ||
<div class="text-center"> | ||
<ul class="pager pager-unset-margin" data-ride="remote_pager" data-rec-total="<?= $logs->getTotal() ?>" data-rec-per-page="<?= $logs->getLimit() ?>"></ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<?php $this->end(); ?> | ||
|
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,37 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Rhilip | ||
* Date: 8/17/2019 | ||
* Time: 2019 | ||
*/ | ||
?> | ||
|
||
<?= $this->layout('layout/base') ?> | ||
|
||
<?php $this->start('title') ?>Subtitle<?php $this->end(); ?> | ||
|
||
<?php $this->start('container') ?> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="panel-group"> | ||
<div class="panel"> | ||
<div class="panel-heading">General rules - Breaking these rules can and will get you banned!</div> | ||
<div class="panel-body"> | ||
<ul> | ||
<li>Do not do things we forbid.</li> | ||
<li>Do not spam.</li> | ||
<li>Cherish your user account. Inactive accounts would be deleted based on the following </li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="panel"> | ||
<div class="panel-heading">Other rules</div> | ||
<div class="panel-body"> | ||
... | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<?php $this->end(); ?> |
Oops, something went wrong.