ContentModel.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%content_model}}".
  6. *
  7. * @property int $model_id ID
  8. * @property string $name 名称
  9. * @property string $table_name 对应表
  10. * @property string $description 描述
  11. * @property string|null $settings 配置信息
  12. * @property int $enable_search 是否开启全站搜索
  13. * @property string $default_theme 风格
  14. * @property string $category_template 栏目聚合页模板
  15. * @property string $list_template 列表页模板
  16. * @property string $show_template 详细页模板
  17. * @property string $wap_default_theme WAP风格
  18. * @property string $wap_category_template WAP栏目聚合页模板
  19. * @property string $wap_list_template WAP列表页模板
  20. * @property string $wap_show_template WAP详细页模板
  21. * @property int $items 信息数
  22. * @property int $type 模块类型 1:内容模型 2:会员模型
  23. * @property int $is_system 系统模块
  24. * @property int $disabled 禁用 1
  25. * @property int $create_time 添加时间
  26. * @property int $list_order 排序
  27. */
  28. class ContentModel extends \app\common\models\EActiveRecord
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName()
  34. {
  35. return '{{%content_model}}';
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['name', 'table_name','type'], 'required'],
  44. [['settings'], 'string'],
  45. [['enable_search', 'items', 'type', 'for_cms', 'is_system', 'disabled', 'create_time', 'list_order'], 'integer'],
  46. [['name', 'default_theme', 'category_template', 'list_template', 'show_template', 'wap_default_theme', 'wap_category_template', 'wap_list_template', 'wap_show_template'], 'string', 'max' => 30],
  47. [['table_name'], 'string', 'max' => 20],
  48. [['description'], 'string', 'max' => 100],
  49. ];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'model_id' => Yii::t('attr','content_model.model_id'),
  58. 'name' => Yii::t('attr','content_model.name'),
  59. 'table_name' => Yii::t('attr','content_model.table_name'),
  60. 'description' => Yii::t('attr','content_model.description'),
  61. 'settings' => Yii::t('attr','content_model.settings'),
  62. 'enable_search' => Yii::t('attr','content_model.enable_search'),
  63. 'default_theme' => Yii::t('attr','content_model.default_theme'),
  64. 'category_template' => Yii::t('attr','content_model.category_template'),
  65. 'list_template' => Yii::t('attr','content_model.list_template'),
  66. 'show_template' =>Yii::t('attr','content_model.show_template'),
  67. 'wap_default_theme' => Yii::t('attr','content_model.wap_default_theme'),
  68. 'wap_category_template' => Yii::t('attr','content_model.wap_category_template'),
  69. 'wap_list_template' => Yii::t('attr','content_model.wap_list_template'),
  70. 'wap_show_template' => Yii::t('attr','content_model.wap_show_template'),
  71. 'items' => Yii::t('attr','content_model.items'),
  72. 'type' => Yii::t('attr','content_model.type'),
  73. 'for_cms' => Yii::t('attr','content_model.for_cms'),
  74. 'is_system' => Yii::t('attr','content_model.is_system'),
  75. 'disabled' => Yii::t('attr','content_model.disabled'),
  76. 'create_time' => Yii::t('attr','content_model.create_time'),
  77. 'list_order' =>Yii::t('attr','content_model.list_order'),
  78. ];
  79. }
  80. //类型
  81. public static function typeOptions($k=null)
  82. {
  83. $options = array('1'=>'内容模型','2'=>'用户模型');
  84. if(is_numeric($k))return $options[$k];
  85. return $options;
  86. }
  87. //模型选项
  88. public static function userModelOptions($k=null)
  89. {
  90. $options = [];
  91. $resultList = ContentModel::find()->where("disabled=0 and type=2")->all();
  92. if(is_array($resultList))foreach($resultList as $result)
  93. {
  94. $options[$result->model_id] = $result->name;
  95. }
  96. if($k>0)return $options[$k];
  97. return $options;
  98. }
  99. //内容模型选项
  100. public static function modelOptions($k=null)
  101. {
  102. $options = [];
  103. $resultList = ContentModel::find()->where("disabled=0 and type=1")->all();
  104. if(is_array($resultList))foreach($resultList as $result)
  105. {
  106. $options[$result->model_id] = $result->name;
  107. }
  108. if($k>0)return $options[$k];
  109. return $options;
  110. }
  111. }