update export excel
This commit is contained in:
parent
2c38348e19
commit
c2e025d1d9
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
/runtime
|
/runtime
|
||||||
/web/assets
|
/web/assets
|
||||||
/web/data
|
/web/data
|
||||||
|
/nbproject/private/
|
|
@ -110,7 +110,14 @@ $config = [
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'db' => $db
|
'db' => $db,
|
||||||
|
'urlManager' => [
|
||||||
|
'enablePrettyUrl' => true,
|
||||||
|
'showScriptName' => false,
|
||||||
|
'enableStrictParsing' => false,
|
||||||
|
'rules' => [
|
||||||
|
],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'params' => $params,
|
'params' => $params,
|
||||||
];
|
];
|
||||||
|
|
|
@ -5,14 +5,6 @@ namespace app\controllers;
|
||||||
use Yii;
|
use Yii;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
use yii\filters\VerbFilter;
|
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.
|
* 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()) {
|
if (Yii::$app->request->post()) {
|
||||||
$post = Yii::$app->request->bodyParams;
|
$post = Yii::$app->request->bodyParams;
|
||||||
|
$model = new \app\models\FaceLogs();
|
||||||
|
$model->create($post);
|
||||||
|
Yii::$app->response->format = "json";
|
||||||
|
return ["stt" => true];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
namespace app\controllers;
|
namespace app\controllers;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
use app\models\Logs;
|
use app\models\FaceLogs;
|
||||||
use app\models\LogsSearch;
|
use app\models\FaceLogsSearch;
|
||||||
use yii\web\Controller;
|
use yii\web\Controller;
|
||||||
use yii\filters\VerbFilter;
|
use yii\filters\VerbFilter;
|
||||||
use yii\helpers\Url;
|
use yii\helpers\Url;
|
||||||
|
@ -41,9 +41,109 @@ class DashboardController extends Controller {
|
||||||
*/
|
*/
|
||||||
public function actionIndex() {
|
public function actionIndex() {
|
||||||
$this->view->title = "Bảng tổng hợp";
|
$this->view->title = "Bảng tổng hợp";
|
||||||
|
$searchModel = new FaceLogsSearch();
|
||||||
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
|
|
||||||
return $this->render('index', [
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
32
helpers/LogsGrid.php
Normal file
32
helpers/LogsGrid.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\helpers;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\helpers\Html;
|
||||||
|
use yii\helpers\Url;
|
||||||
|
use app\models\common;
|
||||||
|
|
||||||
|
class LogsGrid {
|
||||||
|
|
||||||
|
static $path = "";
|
||||||
|
|
||||||
|
public static function path() {
|
||||||
|
return self::$path;
|
||||||
|
}
|
||||||
|
|
||||||
|
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}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
88
models/FaceLogs.php
Normal file
88
models/FaceLogs.php
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the model class for table "face_logs".
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property string $camera_id
|
||||||
|
* @property string $confidence
|
||||||
|
* @property string $enable_door
|
||||||
|
* @property string $encoded_person_image
|
||||||
|
* @property string $frametime
|
||||||
|
* @property string $face_id
|
||||||
|
* @property string $person_id
|
||||||
|
* @property string $image
|
||||||
|
* @property string $status
|
||||||
|
* @property string $stt
|
||||||
|
* @property string $timezone
|
||||||
|
* @property string $name
|
||||||
|
*/
|
||||||
|
class FaceLogs extends \yii\db\ActiveRecord {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public static function tableName() {
|
||||||
|
return 'face_logs';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function rules() {
|
||||||
|
return [
|
||||||
|
[['camera_id', 'confidence', 'enable_door', 'encoded_person_image', 'frametime', 'face_id', 'person_id', 'image', 'status', 'stt', 'timezone', 'name'], 'string'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function attributeLabels() {
|
||||||
|
return [
|
||||||
|
'id' => 'ID',
|
||||||
|
'camera_id' => 'Camera ID',
|
||||||
|
'confidence' => 'Confidence',
|
||||||
|
'enable_door' => 'Enable Door',
|
||||||
|
'encoded_person_image' => 'Encoded Person Image',
|
||||||
|
'frametime' => 'Frametime',
|
||||||
|
'face_id' => 'Face ID',
|
||||||
|
'person_id' => 'Person ID',
|
||||||
|
'image' => 'Image',
|
||||||
|
'status' => 'Status',
|
||||||
|
'stt' => 'Stt',
|
||||||
|
'timezone' => 'Timezone',
|
||||||
|
'name' => 'Name'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create($data) {
|
||||||
|
$r = $this->load([
|
||||||
|
'camera_id' => $data['camera_id'],
|
||||||
|
'confidence' => $data['confidence'],
|
||||||
|
'enable_door' => $data['enable_door'],
|
||||||
|
'encoded_person_image' => $data['encoded_person_image'],
|
||||||
|
'frametime' => $data['frametime'],
|
||||||
|
'face_id' => $data['face_id'],
|
||||||
|
'person_id' => $data['person_id'],
|
||||||
|
'image' => $data['image'],
|
||||||
|
'status' => $data['status'],
|
||||||
|
'stt' => $data['stt'],
|
||||||
|
'timezone' => $data['timezone'],
|
||||||
|
'name' => $data['name']
|
||||||
|
], '');
|
||||||
|
if ($r) {
|
||||||
|
try {
|
||||||
|
$this->save();
|
||||||
|
return $this->id;
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
78
models/FaceLogsSearch.php
Normal file
78
models/FaceLogsSearch.php
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\models;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
|
use yii\base\Model;
|
||||||
|
use yii\data\ActiveDataProvider;
|
||||||
|
use app\models\FaceLogs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FaceLogsSearch represents the model behind the search form of `app\models\FaceLogs`.
|
||||||
|
*/
|
||||||
|
class FaceLogsSearch extends FaceLogs {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function rules() {
|
||||||
|
return [
|
||||||
|
[['id'], 'integer'],
|
||||||
|
[['camera_id', 'confidence', 'enable_door', 'encoded_person_image', 'frametime', 'face_id', 'person_id', 'image', 'status', 'stt', 'timezone', 'name'], 'safe'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function scenarios() {
|
||||||
|
// bypass scenarios() implementation in the parent class
|
||||||
|
return Model::scenarios();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates data provider instance with search query applied
|
||||||
|
*
|
||||||
|
* @param array $params
|
||||||
|
*
|
||||||
|
* @return ActiveDataProvider
|
||||||
|
*/
|
||||||
|
public function search($params) {
|
||||||
|
$query = FaceLogs::find();
|
||||||
|
|
||||||
|
// add conditions that should always apply here
|
||||||
|
|
||||||
|
$dataProvider = new ActiveDataProvider([
|
||||||
|
'query' => $query,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->load($params);
|
||||||
|
|
||||||
|
if (!$this->validate()) {
|
||||||
|
// uncomment the following line if you do not want to return any records when validation fails
|
||||||
|
// $query->where('0=1');
|
||||||
|
return $dataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
// grid filtering conditions
|
||||||
|
$query->andFilterWhere([
|
||||||
|
'id' => $this->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$query->andFilterWhere(['like', 'camera_id', $this->camera_id])
|
||||||
|
->andFilterWhere(['like', 'confidence', $this->confidence])
|
||||||
|
->andFilterWhere(['like', 'enable_door', $this->enable_door])
|
||||||
|
->andFilterWhere(['like', 'encoded_person_image', $this->encoded_person_image])
|
||||||
|
->andFilterWhere(['like', 'frametime', $this->frametime])
|
||||||
|
->andFilterWhere(['like', 'face_id', $this->face_id])
|
||||||
|
->andFilterWhere(['like', 'person_id', $this->person_id])
|
||||||
|
->andFilterWhere(['like', 'image', $this->image])
|
||||||
|
->andFilterWhere(['like', 'status', $this->status])
|
||||||
|
->andFilterWhere(['like', 'stt', $this->stt])
|
||||||
|
->andFilterWhere(['like', 'timezone', $this->timezone])
|
||||||
|
->andFilterWhere(['like', 'name', $this->name]);
|
||||||
|
|
||||||
|
return $dataProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -4,5 +4,33 @@
|
||||||
{use class="app\assets\DashboardAsset"}
|
{use class="app\assets\DashboardAsset"}
|
||||||
{DashboardAsset::register($this)|void}
|
{DashboardAsset::register($this)|void}
|
||||||
{block name='content'}
|
{block name='content'}
|
||||||
<div class="container">abc</div>
|
<div class="container-fluid">
|
||||||
|
<div style="margin-top: 20px;">
|
||||||
|
<div>
|
||||||
|
<a class="btn btn-success" href='{Url::to(['/dashboard/export'])}'>
|
||||||
|
<i class="fa fa-download"></i> Xuất dữ liệu
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
{GridView::widget([
|
||||||
|
'dataProvider' => $dataProvider,
|
||||||
|
'filterModel' => $searchModel,
|
||||||
|
'layout'=> \app\helpers\LogsGrid::getLayout(),
|
||||||
|
'tableOptions' => [
|
||||||
|
'class' => 'table table-striped table-bordered',
|
||||||
|
'style' => 'background:#fff;min-width:700px;'
|
||||||
|
],
|
||||||
|
'columns' => [
|
||||||
|
['class' => 'yii\grid\SerialColumn'],
|
||||||
|
'camera_id',
|
||||||
|
'confidence',
|
||||||
|
'frametime',
|
||||||
|
'face_id',
|
||||||
|
'name',
|
||||||
|
'stt',
|
||||||
|
'timezone'
|
||||||
|
]
|
||||||
|
])}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/block}
|
{/block}
|
Loading…
Reference in New Issue
Block a user