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() ]); } }