[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } public function actionIndex($from = "", $to = "", $name = "", $type = "all", $gender = "all", $id = "") { $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 ($id !== "") $dataProvider->query->andWhere(["LIKE", "list_management.code", $id]); 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]); 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.'); } public function actionUseFeature($id) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = "json"; $model = $this->findModel($id); $listManagement = ListManagement::findOne($model->staff_id); if ($listManagement) { $url = $model->image; $images = json_decode($listManagement->image, true); if (count($images) >= \Yii::$app->params['maxPicture']) return ["status" => false, "text" => "Mỗi đối tượng chỉ nhận tối đa " . \Yii::$app->params['maxPicture'] . " hình ảnh mẫu"]; $add = true; foreach ($images as $key => $value) { if (isset($value['urlOld']) && $value['urlOld'] === $url) $add = false; } if ($add) { $RootFolder = Yii::getAlias('@webroot') . "/data/uploads"; $targetPath = $RootFolder . "/face"; FileHelper::createDirectory($targetPath, 0777); $fileName = "face_" . common::generateRandomString() . "_" . time() . ".png"; $img = file_get_contents("http://localhost/data/uploads/face/" . $url); $fileTarget = $targetPath . "/" . $fileName; if (!$this->resizeImg($img, $fileTarget)) $fileName = $url; $features = json_decode(common::requestToEngine("/get-feature", [ "image_paths" => [ ["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"] ] ]), true); $images[] = [ "url" => $fileName, "urlOld" => $url, "features" => $features['results'][0]['feature'], "features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : [] ]; $listManagement->image = json_encode($images); $listManagement->save(); common::updateFeature([ "cmd" => "update", "id" => $listManagement->id, "name" => common::convert_vi_to_en($listManagement->name), "features" => $listManagement->allFeatures ]); return ["status" => true]; } return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"]; } return ["status" => false, "text" => "Đối tượng không tồn tại!"]; } } public function resizeImg($img, $fileTarget) { $im = imagecreatefromstring($img); $width = imagesx($im); $height = imagesy($im); $newwidth = 224; $newheight = 224; if ($width > $newwidth && $height > $newheight) { $thumb = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($thumb, $fileTarget); imagedestroy($thumb); imagedestroy($im); return true; } return false; } }