BiFace_Server_Lite/models/ListManagement.php
2021-01-22 16:16:18 +07:00

166 lines
4.4 KiB
PHP

<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "list_management".
*
* @property int $id
* @property string $code
* @property string $type
* @property string $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'], 'string'],
[['birthday', 'time', 'last_modified'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'code' => 'ID',
'type' => 'Loại',
'name' => 'Tên',
'image' => 'Hình ảnh đăng kí',
'gender' => 'Giới tính',
'birthday' => 'Ngày sinh',
'telephone' => 'Điện thoại',
'address' => 'Đơn vị',
'time' => 'Thời gian đăng kí',
'last_modified' => 'Last Modified'
];
}
public function create($data) {
$r = $this->load([
'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'],
'time' => time(),
'last_modified' => time()
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
public static $typeArray = [
"wl" => "Whitelist",
"bl" => "Blacklist"
];
public static $genderArray = [
"Male" => "Nam",
"Female" => "Nữ"
];
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->code;
}
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
];
}
}