ContentModelField.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace app\models;
  3. use app\common\components\FormElements;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%content_model_field}}".
  7. *
  8. * @property int $field_id ID
  9. * @property int|null $model_id 模型ID
  10. * @property string $field 字段名称
  11. * @property string $name 别名
  12. * @property string|null $tips 录入提示
  13. * @property string $css 样式
  14. * @property int $min_length 最小长度
  15. * @property int $max_length 最大长度
  16. * @property string $pattern 正则验证规则
  17. * @property string $error_tips 错误提示
  18. * @property string $form_type 表单类型
  19. * @property string|null $setting 设置
  20. * @property string $form_attribute 表单属性
  21. * @property string $unset_group_ids 禁止设置字段值的会员组
  22. * @property string $unset_role_ids 禁止设置字段值的角色
  23. * @property int $is_core 内部字段
  24. * @property int $is_system 系统字段
  25. * @property int $is_unique 值唯一
  26. * @property int $is_base 基础信息
  27. * @property int $is_search 作为搜索条件
  28. * @property int $is_order 作为排序条件
  29. * @property int $is_add 前台投稿中显示
  30. * @property int $is_add_admin 后台投稿中显示
  31. * @property int $is_fullsearch 作为全站搜索信息
  32. * @property int $is_position 在推荐位标签中调用
  33. * @property int $is_omnipotent 作为万能字段的附属字段
  34. * @property int $list_order 排序
  35. * @property int $disabled 状态
  36. */
  37. class ContentModelField extends \app\common\models\EActiveRecord
  38. {
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public static function tableName()
  43. {
  44. return '{{%content_model_field}}';
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function rules()
  50. {
  51. return [
  52. [['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'],
  53. [['field', 'name','form_type'], 'required'],
  54. [['tips', 'setting'], 'string'],
  55. [['field', 'form_type'], 'string', 'max' => 20],
  56. [['name', 'css'], 'string', 'max' => 30],
  57. [['pattern', 'error_tips', 'form_attribute', 'unset_group_ids', 'unset_role_ids'], 'string', 'max' => 255],
  58. ];
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function attributeLabels()
  64. {
  65. return [
  66. 'field_id' => Yii::t('attr','content_model_field.field_id'),
  67. 'model_id' => Yii::t('attr','content_model_field.model_id'),
  68. 'field' => Yii::t('attr','content_model_field.field'),
  69. 'name' => Yii::t('attr','content_model_field.name'),
  70. 'tips' => Yii::t('attr','content_model_field.tips'),
  71. 'css' => Yii::t('attr','content_model_field.css'),
  72. 'min_length' => Yii::t('attr','content_model_field.min_length'),
  73. 'max_length' => Yii::t('attr','content_model_field.max_length'),
  74. 'pattern' => Yii::t('attr','content_model_field.pattern'),
  75. 'error_tips' => Yii::t('attr','content_model_field.error_tips'),
  76. 'form_type' => Yii::t('attr','content_model_field.form_type'),
  77. 'setting' => Yii::t('attr','content_model_field.setting'),
  78. 'form_attribute' => Yii::t('attr','content_model_field.form_attribute'),
  79. 'unset_group_ids' => Yii::t('attr','content_model_field.unset_group_ids'),
  80. 'unset_role_ids' => Yii::t('attr','content_model_field.unset_role_ids'),
  81. 'is_core' => Yii::t('attr','content_model_field.is_core'),
  82. 'is_system' => Yii::t('attr','content_model_field.is_system'),
  83. 'is_unique' => Yii::t('attr','content_model_field.is_unique'),
  84. 'is_base' => Yii::t('attr','content_model_field.is_base'),
  85. 'is_search' =>Yii::t('attr','content_model_field.is_search'),
  86. 'is_order' => Yii::t('attr','content_model_field.is_order'),
  87. 'is_add' => Yii::t('attr','content_model_field.is_add'),
  88. 'is_add_admin' => Yii::t('attr','content_model_field.is_add_admin'),
  89. 'is_fullsearch' => Yii::t('attr','content_model_field.is_fullsearch'),
  90. 'is_position' => Yii::t('attr','content_model_field.is_position'),
  91. 'is_omnipotent' => Yii::t('attr','content_model_field.is_omnipotent'),
  92. 'is_listshow' => Yii::t('attr','content_model_field.is_listshow'),
  93. 'list_order' => Yii::t('attr','content_model_field.list_order'),
  94. 'disabled' => Yii::t('attr','content_model_field.disabled'),
  95. ];
  96. }
  97. /*返回可选择的字段类型
  98. * $_GET['id'] 不为空时是在修改字段
  99. */
  100. public function getFormTypes()
  101. {
  102. $all_field = array();
  103. $model_id = intval(Yii::$app->request->get('model_id'));
  104. if(empty($model_id))return;
  105. $f_datas = ContentModelField::find()->where("model_id=:model_id",[':model_id'=>$model_id])->orderBy(['list_order' => SORT_ASC])->all();;
  106. if(is_array($f_datas))foreach($f_datas as $o) {
  107. $exists_field[] = $o->field;
  108. }
  109. $all_field = array();
  110. $fields = FormElements::getFieldsInfo('types');
  111. $not_allow_fields = FormElements::getFieldsInfo('not_allow_fields');
  112. $unique_fields = FormElements::getFieldsInfo('unique_fields');
  113. if(empty($_GET['id']))
  114. {
  115. foreach($fields as $_k=>$_v) {
  116. 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;
  117. $all_field[$_k] = $_v;
  118. }
  119. }
  120. else
  121. {
  122. foreach($fields as $_k=>$_v) {
  123. $all_field[$_k] = $_v;
  124. }
  125. }
  126. return $all_field;
  127. }
  128. }