177 lines
5.0 KiB
PHP
177 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace app\models;
|
|
|
|
use Yii;
|
|
|
|
/**
|
|
* This is the model class for table "list_management".
|
|
*
|
|
* @property int $id
|
|
* @property string $staff_id
|
|
* @property string $code
|
|
* @property string $type
|
|
* @property string $name
|
|
* @property string $abbreviated_name
|
|
* @property string $image
|
|
* @property string $gender
|
|
* @property int $birthday
|
|
* @property string $telephone
|
|
* @property string $address
|
|
* @property int $time
|
|
* @property int $last_modified
|
|
*/
|
|
class ListManagement extends \yii\db\ActiveRecord {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static function tableName() {
|
|
return 'list_management';
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules() {
|
|
return [
|
|
[['type', 'name', 'gender', 'telephone', 'address', 'image', 'code', 'abbreviated_name', 'staff_id'], 'string'],
|
|
[['birthday', 'time', 'last_modified'], 'integer'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function attributeLabels() {
|
|
return [
|
|
'id' => Yii::t("app", "ID"),
|
|
'code' => Yii::t("app", "ID"),
|
|
'type' => Yii::t("app", "LOAI"),
|
|
'name' => Yii::t("app", "TEN_HIEN_THI"),
|
|
'image' => Yii::t("app", "HINH_ANH_DANG_KI"),
|
|
'gender' => Yii::t("app", "GIOI_TINH"),
|
|
'birthday' => Yii::t("app", "NGAY_SINH"),
|
|
'telephone' => Yii::t("app", "DIEN_THOAI"),
|
|
'address' => Yii::t("app", "DON_VI"),
|
|
'time' => Yii::t("app", "THOI_GIAN_DANG_KI"),
|
|
'last_modified' => 'Last Modified',
|
|
'abbreviated_name' => Yii::t("app", "TEN"),
|
|
'staff_id' => Yii::t("app", "ID"),
|
|
];
|
|
}
|
|
|
|
public function create($data) {
|
|
$r = $this->load([
|
|
'staff_id' => $data['staff_id'],
|
|
'code' => $data['code'],
|
|
'type' => $data['type'],
|
|
'name' => $data['name'],
|
|
'image' => $data['image'],
|
|
'gender' => $data['gender'],
|
|
'birthday' => $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'),
|
|
'telephone' => $data['telephone'],
|
|
'address' => $data['address'],
|
|
'abbreviated_name' => $data['abbreviated_name'],
|
|
'time' => time(),
|
|
'last_modified' => time()
|
|
], '');
|
|
if ($r) {
|
|
try {
|
|
$this->save();
|
|
return $this->id;
|
|
} catch (\Exception $ex) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function typeArray() {
|
|
return [
|
|
"wl" => Yii::t("app", "WHITE_LIST"),
|
|
"bl" => Yii::t("app", "BLACK_LIST")
|
|
];
|
|
}
|
|
|
|
public static function genderArray() {
|
|
return [
|
|
"Male" => Yii::t("app", "MALE"),
|
|
"Female" => Yii::t("app", "FEMALE"),
|
|
];
|
|
}
|
|
|
|
public static function nameArray() {
|
|
$res = [""];
|
|
$ls = self::find()->all();
|
|
foreach ($ls as $key => $value) {
|
|
$res[] = $value->name;
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public static function getAllID() {
|
|
$res = [];
|
|
$ls = self::find()->all();
|
|
foreach ($ls as $key => $value) {
|
|
$res[] = $value->staff_id;
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public static function staffArray() {
|
|
$res = [];
|
|
$ls = self::find()->all();
|
|
foreach ($ls as $key => $value) {
|
|
$res[$value->code] = $value->code . " - " . $value->name;
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public function getAllFeatures() {
|
|
$features = json_decode($this->image, true);
|
|
// $f = [];
|
|
// foreach ($features as $k => $v) {
|
|
// $f[] = $v['features'];
|
|
// if (isset($v['features512']))
|
|
// if (count($v['features512']))
|
|
// $f[] = $v['features512'];
|
|
// }
|
|
$feature1 = $feature2 = [];
|
|
foreach ($features as $k => $v) {
|
|
$feature1[] = $v['features'];
|
|
if (isset($v['features512']))
|
|
if (count($v['features512']))
|
|
$feature2[] = $v['features512'];
|
|
}
|
|
return [
|
|
"feature1" => $feature1,
|
|
"feature2" => $feature2
|
|
];
|
|
}
|
|
|
|
public static function statisticFeatures() {
|
|
$lists = self::find()->all();
|
|
$total128 = $total512 = $totalImg = $img = 0;
|
|
foreach ($lists as $key => $value) {
|
|
$images = json_decode($value->image, true);
|
|
if (count($images) > 0)
|
|
$totalImg++;
|
|
$img += count($images);
|
|
foreach ($images as $k => $v) {
|
|
if (isset($v['features']) && count($v['features']) > 0)
|
|
$total128++;
|
|
if (isset($v['features512']) && count($v['features512']) > 0)
|
|
$total512++;
|
|
}
|
|
}
|
|
return [
|
|
"total" => count($lists),
|
|
"totalImg" => $totalImg,
|
|
"img" => $img,
|
|
"128" => $total128,
|
|
"512" => $total512
|
|
];
|
|
}
|
|
|
|
}
|