diff --git a/assets/ControlLogsAsset.php b/assets/ControlLogsAsset.php new file mode 100644 index 00000000..f3ea22b3 --- /dev/null +++ b/assets/ControlLogsAsset.php @@ -0,0 +1,23 @@ +create([ - "Staff" => 0, - "Time" => $time, - "Image" => $fileName - ]); - } + $model = new CaptureLogs(); + $model->create([ + "Staff" => $post["id"], + "Time" => $time, + "Image" => $fileName + ]); Yii::$app->response->format = "json"; return ["status" => "success"]; } diff --git a/controllers/CaptureLogsController.php b/controllers/CaptureLogsController.php index f22cadf4..12cba3ae 100644 --- a/controllers/CaptureLogsController.php +++ b/controllers/CaptureLogsController.php @@ -39,7 +39,8 @@ class CaptureLogsController extends Controller { $this->view->title = "Capture Log"; $searchModel = new CaptureLogsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); - $dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]); + $dataProvider->query->andWhere(["capture_logs.staff_id" => 0]); + $dataProvider->query->andWhere(["BETWEEN", "capture_logs.time", $f, $t]); $dataProvider->query->orderBy(["time" => SORT_DESC]); return $this->render('index', [ diff --git a/controllers/ControlLogsController.php b/controllers/ControlLogsController.php new file mode 100644 index 00000000..a01ad13f --- /dev/null +++ b/controllers/ControlLogsController.php @@ -0,0 +1,72 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + public function actionIndex($from = "", $to = "", $name = "", $type = "all", $gender = "all") { + $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'); + if ($from !== "" && $to !== "") { + $f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U'); + $t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U'); + } + + $this->view->title = "Control Log"; + $searchModel = new CaptureLogsSearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + $dataProvider->query->andWhere(["<>", "capture_logs.staff_id", 0]); + $dataProvider->query->andWhere(["BETWEEN", "capture_logs.time", $f, $t]); + if ($name !== "") + $dataProvider->query->andWhere(["LIKE", "list_management.name", $name]); + if ($type !== "all") + $dataProvider->query->andWhere(["list_management.type" => $type]); + if ($gender !== "all") + $dataProvider->query->andWhere(["list_management.gender" => $gender]); + $dataProvider->query->orderBy(["time" => SORT_DESC]); + + return $this->render('index', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + 'statusArray' => CaptureLogs::$statusArray, + 'f' => $f, + 't' => $t, + 'typeArray' => ListManagement::$typeArray, + 'genderArray' => ListManagement::$genderArray + ]); + } + + protected function findModel($id) { + if (($model = CaptureLogs::findOne($id)) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } + +} diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index 237c0ebc..be926383 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -87,7 +87,9 @@ class ListManagementController extends Controller { $images[] = ["url" => $url, "features" => $features['results'][0]['feature']]; $listManagement->image = json_encode($images); $listManagement->time = time(); - return $listManagement->save(); + $listManagement->save(); + file_get_contents("http://localhost:2305/update-feature"); + return ["status" => true]; } } else { $features = json_decode(common::requestToEngine("/get-feature", [ @@ -98,7 +100,9 @@ class ListManagementController extends Controller { $data['image'] = json_encode([ ["url" => $url, "features" => $features['results'][0]['feature']] ]); - return $model->create($data); + $model->create($data); + file_get_contents("http://localhost:2305/update-feature"); + return ["status" => true]; } } } @@ -116,7 +120,7 @@ class ListManagementController extends Controller { "birthday" => date("d/m/Y", $ListManagement->birthday), "telephone" => $ListManagement->telephone, "address" => $ListManagement->address, - "image" => "/BiFace/data/uploads/face/" . $images[0]['url'] + "image" => "/data/uploads/face/" . $images[0]['url'] ]; } } @@ -131,14 +135,18 @@ class ListManagementController extends Controller { $model->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'); $model->telephone = $data['telephone']; $model->address = $data['address']; - return $model->save(); + $model->save(); + file_get_contents("http://localhost:2305/update-feature"); + return true; } } public function actionDelete() { if (Yii::$app->request->post()) { $data = Yii::$app->request->post(); - return $this->findModel($data['id'])->delete(); + $this->findModel($data['id'])->delete(); + file_get_contents("http://localhost:2305/update-feature"); + return true; } } @@ -153,7 +161,9 @@ class ListManagementController extends Controller { $features[] = $value; } $model->image = json_encode($features); - return $model->save(); + $model->save(); + file_get_contents("http://localhost:2305/update-feature"); + return true; } } @@ -168,7 +178,9 @@ class ListManagementController extends Controller { public function actionBatchDelete() { if (Yii::$app->request->post()) { $data = Yii::$app->request->post(); - return ListManagement::deleteAll(["IN", "id", $data['lists']]); + ListManagement::deleteAll(["IN", "id", $data['lists']]); + file_get_contents("http://localhost:2305/update-feature"); + return true; } } diff --git a/helpers/CaptureLogsGrid.php b/helpers/CaptureLogsGrid.php index 02d9a537..6661c500 100644 --- a/helpers/CaptureLogsGrid.php +++ b/helpers/CaptureLogsGrid.php @@ -62,4 +62,22 @@ class CaptureLogsGrid { }; } + public static function birthday() { + return function($model) { + $staff = $model->listManagement; + return date("d/m/Y", $staff->birthday); + }; + } + + public static function registrationImage() { + return function($model) { + $staff = $model->listManagement; + $images = json_decode($staff->image, true); + return Html::img("/data/uploads/face/" . $images[0]['url'], [ + "class" => "img-thumbnail", + "style" => "width: 150px;height:150px;" + ]); + }; + } + } diff --git a/models/CaptureLogs.php b/models/CaptureLogs.php index e447f764..49ab8842 100644 --- a/models/CaptureLogs.php +++ b/models/CaptureLogs.php @@ -40,9 +40,11 @@ class CaptureLogs extends \yii\db\ActiveRecord { return [ 'id' => 'ID', 'time' => 'Time', - 'image' => 'Image', + 'image' => 'Live Image', 'status' => 'Status', 'remark' => 'Remark', + 'staff_name' => "Name", + 'staff_image' => "Registration Image" ]; } @@ -69,4 +71,8 @@ class CaptureLogs extends \yii\db\ActiveRecord { 1 => "List management" ]; + public function getListManagement() { + return $this->hasOne(ListManagement::className(), ["id" => "staff_id"]); + } + } diff --git a/models/CaptureLogsSearch.php b/models/CaptureLogsSearch.php index 91732989..4535c8c4 100644 --- a/models/CaptureLogsSearch.php +++ b/models/CaptureLogsSearch.php @@ -10,24 +10,24 @@ use app\models\CaptureLogs; /** * CaptureLogsSearch represents the model behind the search form of `app\models\CaptureLogs`. */ -class CaptureLogsSearch extends CaptureLogs -{ +class CaptureLogsSearch extends CaptureLogs { + + public $staff_name; + /** * {@inheritdoc} */ - public function rules() - { + public function rules() { return [ - [['id', 'time', 'status'], 'integer'], - [['image', 'remark'], 'safe'], + [['id', 'time', 'status'], 'integer'], + [['image', 'remark', 'staff_name'], 'safe'], ]; } /** * {@inheritdoc} */ - public function scenarios() - { + public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } @@ -39,9 +39,9 @@ class CaptureLogsSearch extends CaptureLogs * * @return ActiveDataProvider */ - public function search($params) - { + public function search($params) { $query = CaptureLogs::find(); + $query->joinWith("listManagement"); // add conditions that should always apply here @@ -65,8 +65,9 @@ class CaptureLogsSearch extends CaptureLogs ]); $query->andFilterWhere(['like', 'image', $this->image]) - ->andFilterWhere(['like', 'remark', $this->remark]); + ->andFilterWhere(['like', 'remark', $this->remark]); return $dataProvider; } + } diff --git a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php index ea5b0322..65b2b99b 100644 --- a/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php +++ b/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app/layouts/header.php @@ -41,11 +41,6 @@ use yii\widgets\ActiveForm; Cấu hình -