BiFace_Server_Lite/models/ListManagement.php

120 lines
2.9 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' => 'Type',
'name' => 'Name',
'image' => 'Registration Image',
'gender' => 'Gender',
'birthday' => 'Birthday',
'telephone' => 'Telephone',
'address' => 'Department',
'time' => 'Registration time',
'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" => "Male",
"Female" => "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->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;
}
}