81 lines
2.0 KiB
PHP
81 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace app\controllers;
|
|
|
|
use Yii;
|
|
use app\models\Logs;
|
|
use yii\web\Controller;
|
|
use yii\web\NotFoundHttpException;
|
|
use yii\filters\VerbFilter;
|
|
|
|
/**
|
|
* LogsController implements the CRUD actions for Logs model.
|
|
*/
|
|
class DashboardController extends Controller {
|
|
|
|
public function init() {
|
|
parent::init();
|
|
if (Yii::$app->user->isGuest) {
|
|
return $this->redirect(['/site/login']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function behaviors() {
|
|
return [
|
|
'verbs' => [
|
|
'class' => VerbFilter::className(),
|
|
'actions' => [
|
|
'delete' => ['POST'],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Lists all Logs models.
|
|
* @return mixed
|
|
*/
|
|
public function actionIndex() {
|
|
$this->view->title = "Bảng điều khiển";
|
|
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
|
|
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
|
|
|
|
$logs = Logs::find()->andWhere(["OR", ["BETWEEN", 'time_in', $f, $t], ["BETWEEN", 'time_out', $f, $t]])->orderBy(['time_in' => SORT_DESC, 'time_out' => SORT_DESC])->all();
|
|
|
|
$temp = [];
|
|
$in = 0;
|
|
$out = 0;
|
|
foreach ($logs as $k => $v) {
|
|
if ($v->time_out) {
|
|
$temp[$v->id] = $v->time_out;
|
|
} else {
|
|
$temp[$v->id] = $v->time_in;
|
|
}
|
|
if ($v->time_in)
|
|
$in++;
|
|
if ($v->time_out)
|
|
$out++;
|
|
}
|
|
arsort($temp);
|
|
|
|
$results = [];
|
|
foreach ($temp as $k => $v) {
|
|
foreach ($logs as $key => $value) {
|
|
if ($value->id == $k)
|
|
$results[] = $value;
|
|
}
|
|
}
|
|
|
|
return $this->render('index', [
|
|
"results" => $results,
|
|
"in" => $in,
|
|
"out" => $out,
|
|
"common" => new \app\models\common()
|
|
]);
|
|
}
|
|
|
|
}
|