<?php
 namespace VnChocola\Model;
 use TCMS\Model;
 use TCMS\FieldModel;
 use FIELD_DATA_TYPE;
 class CarsModel extends Model {
 public $tableName = 'Cars';
 public function registerField() {
 $this->addField('id', FIELD_DATA_TYPE::STRING);
 $this->addField('name', FIELD_DATA_TYPE::STRING, function(FieldModel $field) {
 $field->displayName = lang('car_model.name_display');
 $field->required = true;
 }
);
 $this->addField('color', FIELD_DATA_TYPE::STRING, function(FieldModel $field) {
 $field->displayName = lang('car_model.color_display');
 $field->required = true;
 $field->extension = 'color-picker';
 }
);
 $this->addField('carmodel', FIELD_DATA_TYPE::STRING, function(FieldModel $field) {
 $field->displayName = lang('car_model.carmodel_display');
 $field->required = true;
 }
);
 $this->addField('type', FIELD_DATA_TYPE::STRING, function(FieldModel $field) {
 $field->displayName = lang('car_model.type_display');
 }
);
 $this->addField('storeID', FIELD_DATA_TYPE::STRING, function(FieldModel $field) {
 $field->required = true;
 $isShow = area_name() == 'super-admin';
 $field->showInCreatePage = $isShow;
 $field->showInUpdatePage = $isShow;
 $field->showInListPage = $isShow;
 if($isShow) {
 $field->displayName = lang('store_model.name');
 $field->setDataSource('StoresModel', 'name', 'id', lang('store_model.choose_default'));
 }
 else {
 $auth = load_auth();
 $field->defaultValue = $auth->getUser()->storeID;
 }
 }
);
 }
 }
