diff --git a/.gitignore b/.gitignore index 7f9ce2a2..a5d18839 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /runtime /web/assets -/web/data \ No newline at end of file +/web/data +/nbproject/private/ \ No newline at end of file diff --git a/config/web.php b/config/web.php index eafcb66a..3a079447 100644 --- a/config/web.php +++ b/config/web.php @@ -110,7 +110,14 @@ $config = [ ], ], ], - 'db' => $db + 'db' => $db, + 'urlManager' => [ + 'enablePrettyUrl' => true, + 'showScriptName' => false, + 'enableStrictParsing' => false, + 'rules' => [ + ], + ], ], 'params' => $params, ]; diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 9e81c07b..05854ed8 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -5,14 +5,6 @@ namespace app\controllers; use Yii; use yii\web\Controller; use yii\filters\VerbFilter; -use yii\helpers\FileHelper; -use app\models\User; -use app\models\Gate; -use app\models\Camera; -use app\models\Card; -use app\models\CardGroup; -use app\models\Logs; -use app\models\Config; /** * CardController implements the CRUD actions for Card model. @@ -33,10 +25,13 @@ class ApiController extends Controller { ]; } - public function actionLogin() { + public function actionSaveLogs() { if (Yii::$app->request->post()) { $post = Yii::$app->request->bodyParams; - + $model = new \app\models\FaceLogs(); + $model->create($post); + Yii::$app->response->format = "json"; + return ["stt" => true]; } } diff --git a/controllers/DashboardController.php b/controllers/DashboardController.php index 3601cb0c..282d3198 100644 --- a/controllers/DashboardController.php +++ b/controllers/DashboardController.php @@ -3,8 +3,8 @@ namespace app\controllers; use Yii; -use app\models\Logs; -use app\models\LogsSearch; +use app\models\FaceLogs; +use app\models\FaceLogsSearch; use yii\web\Controller; use yii\filters\VerbFilter; use yii\helpers\Url; @@ -41,9 +41,109 @@ class DashboardController extends Controller { */ public function actionIndex() { $this->view->title = "Bảng tổng hợp"; + $searchModel = new FaceLogsSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, ]); } + public function actionExport() { + $lists = FaceLogs::find()->all(); + $objPHPExcel = new \PHPExcel(); + $count = 1; + $objPHPExcel->setActiveSheetIndex(0); + $toExcelFile[] = [ + "STT", + "camera_id", + "confidence", + "frametime", + "face_id", + "name", + "stt", + "timezone" + ]; + foreach ($lists as $k => $v) { + $ExportData[] = $count++; + $ExportData[] = $v->camera_id; + $ExportData[] = $v->confidence; + $ExportData[] = $v->frametime; + $ExportData[] = $v->face_id; + $ExportData[] = $v->name; + $ExportData[] = $v->stt; + $ExportData[] = $v->timezone; + $toExcelFile[] = $ExportData; + unset($ExportData); + } + $totals = count($lists) + 2; + $maxCol = "H"; + $activeSheet = $objPHPExcel->getActiveSheet(); + $activeSheet->setCellValue("A1", "DANH SÁCH CHẤM CÔNG"); + $activeSheet->mergeCells('A1:' . $maxCol . '1'); + $activeSheet->getRowDimension('1')->setRowHeight(50); + $activeSheet->getStyle("A2:" . $maxCol . "2")->getFont()->setBold(true); + $activeSheet->getStyle("A1")->getFont()->setBold(true)->setName('Time New Roman')->setSize(13); + $activeSheet->getStyle("A2:" . $maxCol . $totals)->getFont()->setName('Time New Roman')->setSize(10); + $activeSheet->getColumnDimension('A')->setWidth(5); + $activeSheet->getColumnDimension('B')->setWidth(15); + $activeSheet->getColumnDimension('C')->setWidth(15); + $activeSheet->getColumnDimension('D')->setWidth(25); + $activeSheet->getColumnDimension('E')->setWidth(10); + $activeSheet->getColumnDimension('F')->setWidth(20); + $activeSheet->getColumnDimension('G')->setWidth(10); + $activeSheet->getColumnDimension('H')->setWidth(15); + $style = array( + 'alignment' => array( + 'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER, + 'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER, + 'wrap' => true + ) + ); + $activeSheet->getStyle("A1:" . $maxCol . "2")->applyFromArray($style); + $activeSheet->getStyle("A2:" . $maxCol . "2")->applyFromArray([ + 'fill' => array( + 'type' => \PHPExcel_Style_Fill::FILL_SOLID, + 'color' => array('rgb' => '00c0ef') + ) + ]); + $rowCount = 2; + for ($i = 0; $i < count($toExcelFile); $i++) { + $column = 'A'; + $row = $toExcelFile[$i]; + for ($j = 0; $j < count($row); $j++) { + if (!isset($row[$j])) + $value = NULL; + elseif ($row[$j] != "") + $value = strip_tags($row[$j]); + else + $value = ""; + $activeSheet->setCellValue($column . $rowCount, $value); + $column = chr(ord($column) + 1); + } + $rowCount++; + } + + $activeSheet->getStyle("A2:" . $maxCol . $totals)->applyFromArray([ + 'alignment' => [ + 'horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER, + 'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER, + 'wrap' => true + ], + 'borders' => [ + 'allborders' => [ + 'style' => \PHPExcel_Style_Border::BORDER_THIN + ] + ] + ]); + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); + ob_end_clean(); + header('Content-type: application/vnd.ms-excel'); + header('Content-Disposition: attachment; filename="du-lieu.xlsx"'); + header('Cache-Control: max-age=0'); + $objWriter->save('php://output'); + exit(); + } + } diff --git a/db/app.db b/db/app.db index b94da2d6..3f4ca5b5 100644 Binary files a/db/app.db and b/db/app.db differ diff --git a/helpers/LogsGrid.php b/helpers/LogsGrid.php new file mode 100644 index 00000000..fe8641ae --- /dev/null +++ b/helpers/LogsGrid.php @@ -0,0 +1,32 @@ +app->app_name; + }; + } + + public static function getLayout() { + return "{items}