update CRUD list-management

This commit is contained in:
2020-12-04 10:11:56 +07:00
parent efb4113001
commit 6030ccd0a5
11 changed files with 428 additions and 43 deletions

View File

@@ -7,6 +7,7 @@ use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\helpers\FileHelper;
use app\models\CaptureLogs;
use app\models\ListManagement;
/**
* CardController implements the CRUD actions for Card model.
@@ -76,6 +77,25 @@ class ApiController extends Controller {
}
}
public function actionGetAllFeatures() {
$listManagement = ListManagement::find()->all();
$allFeatures = [];
foreach ($listManagement as $key => $value) {
$features = json_decode($value->image, true);
$f = [];
foreach ($features as $k => $v) {
$f[] = $v['features'];
}
$allFeatures[] = [
"id" => $value->id,
"name" => $value->name,
"features" => $f
];
}
Yii::$app->response->format = "json";
return $allFeatures;
}
public function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);

View File

@@ -8,6 +8,8 @@ use app\models\ListManagementSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\models\CaptureLogs;
use app\models\common;
/**
* ListMamagementController implements the CRUD actions for ListMamagement model.
@@ -28,7 +30,7 @@ class ListManagementController extends Controller {
];
}
public function actionIndex($from = "", $to = "") {
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 !== "") {
@@ -39,13 +41,20 @@ class ListManagementController extends Controller {
$searchModel = new ListManagementSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->query->andWhere(["BETWEEN", "time", $f, $t]);
if ($name !== "")
$dataProvider->query->andWhere(["LIKE", "name", $name]);
if ($type !== "all")
$dataProvider->query->andWhere(["type" => $type]);
if ($gender !== "all")
$dataProvider->query->andWhere(["gender" => $gender]);
$dataProvider->query->orderBy(["time" => SORT_DESC]);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'f' => $f,
't' => $t,
'typeArray' => ListManagement::$typeArray
'typeArray' => ListManagement::$typeArray,
'genderArray' => ListManagement::$genderArray
]);
}
@@ -57,29 +66,95 @@ class ListManagementController extends Controller {
public function actionCreate() {
$model = new ListManagement();
Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$data['image'] = \app\models\CaptureLogs::findOne($data['id'])->image;
return $model->create($data);
$listManagement = ListManagement::findOne(['name' => $data['name']]);
$url = CaptureLogs::findOne($data['id'])->image;
if ($listManagement) {
$images = json_decode($listManagement->image, true);
$add = true;
foreach ($images as $key => $value) {
if ($value['url'] === $url)
$add = false;
}
if ($add) {
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/home/sonhh/Pictures/10929_HongBI.jpg", "type" => "raw"]
]
]), true);
$images[] = ["url" => $url, "features" => $features['results'][0]['feature']];
$listManagement->image = json_encode($images);
$listManagement->time = time();
return $listManagement->save();
}
} else {
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "sex.png", "type" => "raw"]
]
]), true);
$data['image'] = json_encode([
["url" => $url, "features" => $features['results'][0]['feature']]
]);
return $model->create($data);
}
}
}
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
public function actionFormUpdate() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$ListManagement = $this->findModel($data['id']);
$images = json_decode($ListManagement->image, true);
Yii::$app->response->format = "json";
return [
"type" => $ListManagement->type,
"name" => $ListManagement->name,
"gender" => $ListManagement->gender,
"birthday" => date("d/m/Y", $ListManagement->birthday),
"telephone" => $ListManagement->telephone,
"address" => $ListManagement->address,
"image" => "/BiFace/data/uploads/face/" . $images[0]['url']
];
}
return $this->render('update', [
'model' => $model,
]);
}
public function actionDelete($id) {
$this->findModel($id)->delete();
public function actionUpdate() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$model = $this->findModel($data['id']);
$model->type = $data['type'];
$model->name = $data['name'];
$model->gender = $data['gender'];
$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();
}
}
return $this->redirect(['index']);
public function actionDelete() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
return $this->findModel($data['id'])->delete();
}
}
public function actionDeleteFeature() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
$model = $this->findModel($data['id']);
$images = json_decode($model->image, true);
$features = [];
foreach ($images as $key => $value) {
if ($value['url'] !== $data['image'])
$features[] = $value;
}
$model->image = json_encode($features);
return $model->save();
}
}
protected function findModel($id) {
@@ -90,4 +165,11 @@ class ListManagementController extends Controller {
throw new NotFoundHttpException('The requested page does not exist.');
}
public function actionBatchDelete() {
if (Yii::$app->request->post()) {
$data = Yii::$app->request->post();
return ListManagement::deleteAll(["IN", "id", $data['lists']]);
}
}
}