123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace app\models;
- use app\common\components\FormElements;
- use Yii;
- /**
- * This is the model class for table "{{%content_model_field}}".
- *
- * @property int $field_id ID
- * @property int|null $model_id 模型ID
- * @property string $field 字段名称
- * @property string $name 别名
- * @property string|null $tips 录入提示
- * @property string $css 样式
- * @property int $min_length 最小长度
- * @property int $max_length 最大长度
- * @property string $pattern 正则验证规则
- * @property string $error_tips 错误提示
- * @property string $form_type 表单类型
- * @property string|null $setting 设置
- * @property string $form_attribute 表单属性
- * @property string $unset_group_ids 禁止设置字段值的会员组
- * @property string $unset_role_ids 禁止设置字段值的角色
- * @property int $is_core 内部字段
- * @property int $is_system 系统字段
- * @property int $is_unique 值唯一
- * @property int $is_base 基础信息
- * @property int $is_search 作为搜索条件
- * @property int $is_order 作为排序条件
- * @property int $is_add 前台投稿中显示
- * @property int $is_add_admin 后台投稿中显示
- * @property int $is_fullsearch 作为全站搜索信息
- * @property int $is_position 在推荐位标签中调用
- * @property int $is_omnipotent 作为万能字段的附属字段
- * @property int $list_order 排序
- * @property int $disabled 状态
- */
- class ContentModelField extends \app\common\models\EActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%content_model_field}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['model_id', 'min_length', 'max_length', 'is_core', 'is_system', 'is_unique', 'is_base', 'is_search', 'is_order', 'is_add', 'is_add_admin', 'is_fullsearch', 'is_position', 'is_omnipotent', 'is_listshow', 'list_order', 'disabled'], 'integer'],
- [['field', 'name','form_type'], 'required'],
- [['tips', 'setting'], 'string'],
- [['field', 'form_type'], 'string', 'max' => 20],
- [['name', 'css'], 'string', 'max' => 30],
- [['pattern', 'error_tips', 'form_attribute', 'unset_group_ids', 'unset_role_ids'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'field_id' => Yii::t('attr','content_model_field.field_id'),
- 'model_id' => Yii::t('attr','content_model_field.model_id'),
- 'field' => Yii::t('attr','content_model_field.field'),
- 'name' => Yii::t('attr','content_model_field.name'),
- 'tips' => Yii::t('attr','content_model_field.tips'),
- 'css' => Yii::t('attr','content_model_field.css'),
- 'min_length' => Yii::t('attr','content_model_field.min_length'),
- 'max_length' => Yii::t('attr','content_model_field.max_length'),
- 'pattern' => Yii::t('attr','content_model_field.pattern'),
- 'error_tips' => Yii::t('attr','content_model_field.error_tips'),
- 'form_type' => Yii::t('attr','content_model_field.form_type'),
- 'setting' => Yii::t('attr','content_model_field.setting'),
- 'form_attribute' => Yii::t('attr','content_model_field.form_attribute'),
- 'unset_group_ids' => Yii::t('attr','content_model_field.unset_group_ids'),
- 'unset_role_ids' => Yii::t('attr','content_model_field.unset_role_ids'),
- 'is_core' => Yii::t('attr','content_model_field.is_core'),
- 'is_system' => Yii::t('attr','content_model_field.is_system'),
- 'is_unique' => Yii::t('attr','content_model_field.is_unique'),
- 'is_base' => Yii::t('attr','content_model_field.is_base'),
- 'is_search' =>Yii::t('attr','content_model_field.is_search'),
- 'is_order' => Yii::t('attr','content_model_field.is_order'),
- 'is_add' => Yii::t('attr','content_model_field.is_add'),
- 'is_add_admin' => Yii::t('attr','content_model_field.is_add_admin'),
- 'is_fullsearch' => Yii::t('attr','content_model_field.is_fullsearch'),
- 'is_position' => Yii::t('attr','content_model_field.is_position'),
- 'is_omnipotent' => Yii::t('attr','content_model_field.is_omnipotent'),
- 'is_listshow' => Yii::t('attr','content_model_field.is_listshow'),
- 'list_order' => Yii::t('attr','content_model_field.list_order'),
- 'disabled' => Yii::t('attr','content_model_field.disabled'),
- ];
- }
- /*返回可选择的字段类型
- * $_GET['id'] 不为空时是在修改字段
- */
- public function getFormTypes()
- {
- $all_field = array();
- $model_id = intval(Yii::$app->request->get('model_id'));
- if(empty($model_id))return;
- $f_datas = ContentModelField::find()->where("model_id=:model_id",[':model_id'=>$model_id])->orderBy(['list_order' => SORT_ASC])->all();;
- if(is_array($f_datas))foreach($f_datas as $o) {
- $exists_field[] = $o->field;
- }
- $all_field = array();
- $fields = FormElements::getFieldsInfo('types');
- $not_allow_fields = FormElements::getFieldsInfo('not_allow_fields');
- $unique_fields = FormElements::getFieldsInfo('unique_fields');
- if(empty($_GET['id']))
- {
- foreach($fields as $_k=>$_v) {
- if((is_array($not_allow_fields)&&in_array($_k,$not_allow_fields)) || (is_array($exists_field)&&in_array($_k,$exists_field)) && (is_array($unique_fields)&&in_array($_k,$unique_fields))) continue;
- $all_field[$_k] = $_v;
- }
- }
- else
- {
- foreach($fields as $_k=>$_v) {
- $all_field[$_k] = $_v;
- }
- }
- return $all_field;
- }
- }
|