Server_AccessControl/helpers/CommonGrid.php
2020-10-10 16:11:19 +07:00

92 lines
2.9 KiB
PHP

<?php
namespace app\helpers;
use Yii;
use yii\helpers\Html;
use yii\helpers\Url;
use app\models\common;
class CommonGrid {
public static function engineNameFunc() {
return function ($data) {
return $data->app->app_name;
};
}
public static function getLayout() {
return "{items}<div class='row'><div class='col-md-4'>{summary}</div><div class='col-md-8 text-right'>{pager}</div></div>";
}
public static function actionTemplate() {
return "{update} {delete}";
}
public static function createdAt() {
return function($model) {
$common = new common();
return $common->formatTime($model->created_at, "H:i d/m/Y");
};
}
public static function modifiedAt() {
return function($model) {
$common = new common();
return $common->formatTime($model->modified_at, "H:i d/m/Y");
};
}
public static function update($obj) {
return function($url, $model) use ($obj) {
return Html::button("<i class='fa fa-pencil'></i>", [
'class' => 'btn btn-success btn-xs',
'data' => ['toggle' => 'tooltip', 'href' => Url::to(['update', 'id' => $model->id])],
'title' => Yii::t('app', 'Chỉnh sửa'),
'onclick' => "common.form(this, '{$obj}');"
]);
};
}
public static function delete($deleteConfirmMess) {
return function($url, $model) use ($deleteConfirmMess) {
return Html::a('<i class="fa fa-trash"></i>', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger btn-xs',
'title' => Yii::t("app", "Xóa"),
'data' => [
'toggle' => 'tooltip',
'confirm' => $deleteConfirmMess,
'method' => 'post'
]
]);
};
}
public static function checkbox($type, $haveRoot = true) {
return function($model) use ($type, $haveRoot) {
if ($model->id == 1 && $haveRoot)
return "";
return "<input type='checkbox' value='{$model->id}' name='checkbox-{$type}' class='checkbox-{$type}'>";
};
}
public static function rows($type, $bigSize = false) {
return function($model, $index, $widget, $grid) use ($type, $bigSize) {
return [
"ondblclick" => "common.form(this, '{$type}', {$bigSize});",
"style" => "cursor: pointer;",
"data" => [
"href" => Url::to(["update", "id" => $model->id])
]
];
};
}
public static function pid($array) {
return function($model) use ($array) {
return isset($array[$model->pid]) ? $array[$model->pid] : "";
};
}
}