<?php
 namespace Model;
 use FIELD_DATA_TYPE;
 use TCMS\FieldModel;
 use TCMS\Model;
 class UserModel extends Model {
 public $tableName = 'users';
 public function registerField() {
 $this->addField('id', FIELD_DATA_TYPE::STRING);
 $this->addField('name', FIELD_DATA_TYPE::STRING, function(FieldModel $field){
 $field->displayName = lang('usermodel.name');
 $field->required = true;
 }
);
 $this->addField('username', FIELD_DATA_TYPE::STRING, function(FieldModel $field){
 $field->displayName = lang('usermodel.username');
 $field->required = true;
 $field->validate = [ 'unique' => 'Username đã tồn tại' ];
 }
);
 $this->addField('password', FIELD_DATA_TYPE::PASSWORD, function(FieldModel $field){
 $field->displayName = lang('usermodel.password');
 $field->showInListPage = false;
 }
);
 $this->addField('repassword', FIELD_DATA_TYPE::PASSWORD, function(FieldModel $field){
 $field->displayName = lang('usermodel.repassword');
 $field->showInListPage = false;
 $field->isCustomField = true;
 }
);
 $this->addField('staffId', FIELD_DATA_TYPE::SELECT, function(FieldModel $field){
 $field->displayName = lang('usermodel.staff');
 $field->required = true;
 $field->validate = [ 'unique' => lang('usermodel.exist_staff') ];
 $field->extension = 'chocola-select';
 $field->extensionOption = [ 'key' => 'branchID' ];
 $field->setDataSource('StaffsModel', 'name', 'id', lang('usermodel.choose_staff'));
 }
);
 $this->addField('groupId', FIELD_DATA_TYPE::SELECT, function(FieldModel $field){
 $field->displayName = lang('usermodel.group');
 $field->required = true;
 $field->extension = 'chocola-select';
 $field->extensionOption = [ 'key' => 'branchID' ];
 $field->setDataSource('GroupUserModel', 'name', 'id', '- Chọn nhóm người dùng -');
 }
);
 $this->addField('storeID', FIELD_DATA_TYPE::STRING, function(FieldModel $field){
 $field->showInCreatePage = false;
 $field->showInListPage = false;
 $field->showInUpdatePage = false;
 }
);
 $this->addField('branchID', FIELD_DATA_TYPE::STRING, function(FieldModel $field){
 $field->showInCreatePage = false;
 $field->showInListPage = false;
 $field->showInUpdatePage = false;
 }
);
 $this->addField('avatar', FIELD_DATA_TYPE::STRING, function(FieldModel $field){
 $field->showInCreatePage = false;
 $field->showInListPage = false;
 $field->showInUpdatePage = false;
 }
);
 }
 }
