60 lines
2.1 KiB
PHP
60 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\helpers;
|
|
|
|
use app\models\Door;
|
|
use yii\helpers\Html;
|
|
use yii\helpers\Url;
|
|
|
|
class DeviceGrid extends CommonGrid {
|
|
|
|
public static function status($array) {
|
|
return function($model) use ($array) {
|
|
if ($model->status)
|
|
return "<i class='fa fa-check text-green'></i>";
|
|
return "<i class='fa fa-remove text-red'></i>";
|
|
};
|
|
}
|
|
|
|
public static function type($array) {
|
|
return function($model) use ($array) {
|
|
return isset($array[$model->type]) ? $array[$model->type] : "";
|
|
};
|
|
}
|
|
|
|
public static function area($array) {
|
|
return function($model) use ($array) {
|
|
return isset($array[$model->area_id]) ? $array[$model->area_id] : "";
|
|
};
|
|
}
|
|
|
|
public static function checkbox($type, $haveRoot = true) {
|
|
return function($model) use ($type) {
|
|
return "<input type='checkbox' value='{$model->id}' data='{$model->ip_address}' name='checkbox-{$type}' class='checkbox-{$type}'>";
|
|
};
|
|
}
|
|
|
|
public static function openDoor() {
|
|
return function($model) {
|
|
$doors = Door::find()->andWhere(["device_id" => $model->id])->count();
|
|
return Html::button("<i class='fa fa-list'></i> Danh sách cửa " . Html::label($doors, "", ["class" => "label label-danger"]), [
|
|
'class' => 'btn btn-info',
|
|
'data' => [
|
|
'href' => Url::to(['doors', 'id' => $model->id])
|
|
],
|
|
'onclick' => "common.form(this, '');"
|
|
]);
|
|
// foreach ($doors as $key => $value) {
|
|
// $html .= Html::button($value->code, [
|
|
// 'class' => 'btn btn-info',
|
|
// 'data' => ['toggle' => 'tooltip', 'href' => Url::to(['open-door', 'id' => $model->id, 'door' => $value->code])],
|
|
// 'title' => \Yii::t('app', 'Mở cửa'),
|
|
// 'onclick' => "openDoor(this);"
|
|
// ]) . " ";
|
|
// }
|
|
// return $html;
|
|
};
|
|
}
|
|
|
|
}
|