BiFace_Server_Lite/models/Schedule.php
2022-10-18 08:38:54 +07:00

81 lines
2.0 KiB
PHP

<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "schedule".
*
* @property int $id
* @property string $staff_id
* @property string $from_time
* @property string $to_time
* @property string $from_date
* @property string $to_date
* @property string $date_of_week
* @property int $id_door_calendar
*/
class Schedule extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'schedule';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['staff_id', 'from_time', 'to_time', 'from_date', 'to_date', 'date_of_week'], 'string'],
[['id_door_calendar'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'staff_id' => 'Staff ID',
'from_time' => 'From Time',
'to_time' => 'To Time',
'from_date' => 'From Date',
'to_date' => 'To Date',
'date_of_week' => 'Date Of Week',
'id_door_calendar' => 'id_door_calendar'
];
}
public function multiCreate($datas) {
$field = ['staff_id', 'from_time', 'to_time', 'from_date', 'to_date', 'date_of_week'];
static::getDb()->createCommand()->batchInsert($this->tableName(), $field, $datas)->execute();
return;
}
public function create($data) {
$r = $this->load([
'staff_id' => strval($data['staff_id']),
'from_time' => $data['from_time'],
'to_time' => $data['to_time'],
'from_date' => $data['from_date'],
'to_date' => $data['to_date'],
'date_of_week' => $data['date_of_week'],
'id_door_calendar' => $data['id_door_calendar']
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
}