Example #1
0
 /**
  * (non-PHPdoc)
  * @see \yii\db\BaseActiveRecord::beforeSave($insert)
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             //创建
         } else {
             //更新
             //判断是否为删除动作的非单页面
             //当前分类下,有子分类,有没有内容
             if ($this->getOldAttribute('deleted') != $this->getAttribute('deleted')) {
                 //当前分类下有没有子分类
                 if ($this->deleted && Column::find()->where(['parent_id' => $this->id])->alive()->exists()) {
                     Yii::$app->getSession()->setFlash('warning', Yii::t('cms', 'Under this column subtopic, are not allowed to delete directly!'));
                     return false;
                 }
                 if ($this->type != static::CMS_TYPE_PAGE) {
                     //判断当前分类下有没有内容
                     $class = static::getRelativeClass()[$this->type];
                     //由type关联到相应的模型
                     $class = 'common\\models\\cms\\' . $class;
                     if ($this->deleted && $class::find()->where(['column_id' => $this->id])->alive()->exists()) {
                         Yii::$app->getSession()->setFlash('warning', Yii::t('cms', 'Under this category contains content, cannot be deleted!'));
                         return false;
                     }
                 }
             }
         }
         return true;
     } else {
         return false;
     }
 }
Example #2
0
 /**
  * Finds the Page model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Page the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($name)
 {
     if (($model = Column::find()->with('page')->active()->andWhere(['short_code' => trim($name)])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('该请求对应的页面不存在。');
     }
 }
Example #3
0
 /**
  * Lists all Column models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Column::find()->alive(), 'pagination' => ['pageSize' => static::MAX_PAGE_SIZE], 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]);
     //递归处理
     $dataProvider->models = General::recursiveObj($dataProvider->models, 0, 0, '', '<span class="bank"></span>', false);
     $keys = General::getModelsKeys($dataProvider->models, 'id');
     $dataProvider->setKeys($keys);
     // 		fb($keys);
     // 		fb($dataProvider->getKeys());
     // 		fb($dataProvider->models);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Example #4
0
 /**
  * 首页
  * @return string
  */
 public function actionIndex()
 {
     $columns = Column::find()->where(['type' => Column::CMS_TYPE_LIST])->active()->orderBy('order ASC')->all();
     //关于我们单页
     $about = Column::find()->where(['short_code' => 'about-brief'])->active()->one();
     //首页主广告
     $mainAdType = AdType::find()->where(['short_code' => 'home_main'])->active()->one();
     //in查询
     $mainAds = $mainAdType->getAd()->active()->orderBy('order ASC')->all();
     //底部广告
     $adBottom = Ad::find()->where(['short_code' => 'home_bottom'])->active()->one();
     //搬家现场,推荐
     $scenes = Img::find()->select(Img::tableName() . '.*')->where(['like', Img::tableName() . '.flag', 'c'])->joinWith(['column' => function ($query) {
         $query->where([Column::tableName() . '.short_code' => 'xianchang']);
     }])->active()->all();
     //搬家现场推荐
     return $this->render('index', ['columns' => $columns, 'about' => $about, 'mainAdType' => $mainAdType, 'mainAds' => $mainAds, 'adBottom' => $adBottom, 'scenes' => $scenes]);
 }
Example #5
0
use kartik\file\FileInput;
use common\helpers\General;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model common\models\cms\Column */
/* @var $form yii\widgets\ActiveForm */
$this->registerJs("\n\t\$('.upload_picture').css(\"cursor\",\"pointer\");\n");
if ($model->isNewRecord) {
    $model->status = true;
    $model->order = 10;
}
//指定了父级栏目
if (isset($id) && $id !== false) {
    $model->parent_id = $id;
}
$parentIds = ArrayHelper::merge(['0' => Yii::t('cms', 'Top Column')], ArrayHelper::map(General::recursiveObj(Column::find()->orderBy(['order' => SORT_ASC])->all()), 'id', 'name'));
?>

<div class="row cms-class-form">
    <div class="col-md-12">
        <?php 
//广泛布局
$form = ActiveForm::begin(['layout' => 'horizontal', 'fieldConfig' => ['template' => "{label} {beginWrapper} {input} {hint} {error} {endWrapper}", 'horizontalCssClasses' => ['label' => 'col-sm-2', 'offset' => 'col-sm-offset-2', 'wrapper' => 'col-sm-8', 'error' => '', 'hint' => '']]]);
?>
        
        <?php 
if ($model->isNewRecord) {
    $model->type = Column::CMS_TYPE_PAGE;
    echo $form->field($model, 'type')->dropDownList(ArrayHelper::merge(Column::getType(), [Column::CMS_TYPE_STRUCT => Yii::t('cms', 'Struct')]));
    echo $form->field($model, 'short_code')->hint('<i class="fa fa-info-circle"></i> ' . Yii::t('cms', 'Used for the frontend call.'))->textInput(['maxlength' => true]);
}
Example #6
0
                            <?php 
echo Html::a(Yii::t('cms', 'Create Img'), ['create'], ['class' => 'btn btn-success']);
?>
                        </p>
                     -->
            		<?php 
Pjax::begin();
?>
					<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'options' => ['class' => 'grid-view box-body table-responsive no-padding'], 'tableOptions' => ['class' => 'table table-hover table-striped table-bordered'], 'headerRowOptions' => [], 'footerRowOptions' => [], 'showHeader' => true, 'showFooter' => false, 'layout' => "{summary}\n{errors}\n{items}\n{pager}", 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'title', 'format' => 'raw', 'value' => function ($model) {
    $length = Yii::$app->params['config']['config_site_title_length'];
    $options = ['style' => ''];
    Html::addCssStyle($options, ['color' => $model->colorval, 'font-weight' => $model->boldval]);
    $title = '<span title="' . $model->title . '" style="' . $options['style'] . '">' . StringHelper::truncate($model->title, $length) . '</span>';
    return Html::a($title, ['update', 'id' => $model->id], ['data-pjax' => '0']);
}], ['attribute' => 'column_id', 'filter' => ArrayHelper::map(Column::find()->where(['type' => Column::CMS_TYPE_IMG])->alive()->all(), 'id', 'name'), 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    return $model->column->name;
}], ['attribute' => 'flag', 'filter' => ArrayHelper::map(Flag::find()->orderBy('order')->all(), 'id', 'name'), 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    return $model->flagModel->flag;
}], 'hits', ['attribute' => 'status', 'format' => 'html', 'filter' => [Img::STATUS_YES => Yii::t('cms', 'Yes'), Img::STATUS_NO => Yii::t('cms', 'No')], 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    $on = Html::a('<small class="label bg-green">' . Yii::t('common', 'Yes') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']);
    $off = Html::a('<small class="label bg-red">' . Yii::t('common', 'No') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']);
    return $model->status ? $on : $off;
}], 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {delete}', 'header' => Yii::t('common', 'Opration')]]]);
?>
					<?php 
Pjax::end();
?>
     
                </div>
                
Example #7
0
					<?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>
                        
                    <!-- 
                        <p>
                            <?php 
echo Html::a(Yii::t('cms', 'Create Page'), ['create'], ['class' => 'btn btn-success']);
?>
                        </p>
                     -->
            		<?php 
Pjax::begin();
?>
					<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'options' => ['class' => 'grid-view box-body table-responsive no-padding'], 'tableOptions' => ['class' => 'table table-hover table-striped table-bordered'], 'headerRowOptions' => [], 'footerRowOptions' => [], 'showHeader' => true, 'showFooter' => false, 'layout' => "{summary}\n{errors}\n{items}\n{pager}", 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'column_id', 'format' => 'raw', 'filter' => ArrayHelper::map(Column::find()->where(['type' => Column::CMS_TYPE_PAGE])->alive()->all(), 'id', 'name'), 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    return Html::a($model->column->name, ['update', 'id' => $model->id], ['data-pjax' => '0']);
}], ['attribute' => 'order', 'format' => 'raw', 'value' => function ($model) {
    return Html::activeTextInput($model, 'order', ['style' => 'width:50px', 'data-id' => $model->id]);
}], ['attribute' => 'status', 'format' => 'html', 'filter' => [Page::STATUS_YES => Yii::t('cms', 'Yes'), Page::STATUS_NO => Yii::t('cms', 'No')], 'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => Yii::t('common', 'All')], 'value' => function ($model) {
    $on = Html::a('<small class="label bg-green">' . Yii::t('common', 'Yes') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']);
    $off = Html::a('<small class="label bg-red">' . Yii::t('common', 'No') . '</small>', ['switch-status', 'id' => $model->id], ['title' => Yii::t('cms', 'Update Status'), 'data-pjax' => '0']);
    return $model->status ? $on : $off;
}], 'created_at:datetime']]);
?>
					<?php 
Pjax::end();
?>
 
                </div>
                
Example #8
0
    $model->publish_at = date('Y-m-d H:i', $model->publish_at);
    $model->flag = explode(',', $model->flag);
}
$languge = Yii::$app->language;
$this->registerJs("\n// \t\$('input[type=\"checkbox\"].minimal, input[type=\"radio\"].minimal').iCheck({\n// \t\tcheckboxClass: 'icheckbox_minimal-blue',\n// \t\tradioClass: 'icheckbox_minimal-blue'\n// \t});\n\t\n\t//select2\n// \t\$('#download-column_id').select2({\n//         theme: 'classic',\n//         width: '400px',\n//     });\n\n\tvar title = \$('#download-title');\n\tvar colorval = \$('#download-colorval');\n\tvar boldval = \$('#download-boldval');\n\t\$('.title-colorpicker').colorpicker().on('changeColor', function(obColor){\n\t\tvar weight = title.css('font-weight');\n\t\ttitle.css({\"color\": obColor.color.toHex(), \"font-weight\": weight});\n\t\tcolorval.val(obColor.color.toHex());\n\t});\n\t\$('.field-download-title').on('click' ,'.blod', function(){\n\t\tvar color = title.css('color');\n\t\tvar bold = title.css('font-weight');\n\t\tbold = (bold == '700')?'400':'700';\n\t\ttitle.css({\"color\": color, \"font-weight\": bold});\n\t\tboldval.val(bold);\n\t}).on('click' ,'.clear', function(){\n\t\ttitle.css({\"color\": '#333', \"font-weight\": '400'});\n\t\tcolorval.val('#333');\n\t\tboldval.val('400');\n\t});\n\t\t\n\t//时间插件\n\t\$('#download-publish_at').datetimepicker({\n\t\tlanguage:  '{$languge}',\n\t\tformat: 'yyyy-mm-dd hh:ii',// P\n\t\tshowMeridian: 1,//开启上下午选择项\n\t\ttodayBtn:  1,\n\t\ttodayHighlight: 1,\n\t\tautoclose: 1,//选中后,自动关闭\n\t\tpickerPosition: \"top-left\",//面板位置\n// \t\tstartDate: '',//开始日期\n// \t\tendDate: '',//结束日期\n// \t\tstartView: '',//首次显示的是哪个面板:年/月/日/上午下午/时/分\n// \t\tinitialDate: '',//初始化默认日期\n//      weekStart: 1,//显示多少周\n// \t\tforceParse: 0,//强制转化\n// \t\tlinkField: \"mirror_field\",//关联表单\n//      linkFormat: \"yyyy-mm-dd hh:ii\",//关联表单的显示格式\n\t});\n");
?>

<div class="row cms-download-form">
	<div class="col-md-12">
        <?php 
//广泛布局
$form = ActiveForm::begin(['layout' => 'horizontal', 'fieldConfig' => ['template' => "{label} {beginWrapper} {input} {hint} {error} {endWrapper}", 'horizontalCssClasses' => ['label' => 'col-sm-2', 'offset' => 'col-sm-offset-2', 'wrapper' => 'col-sm-8', 'error' => '', 'hint' => '']]]);
?>
    	
        <?php 
echo $form->field($model, 'column_id')->dropDownList(ArrayHelper::map(Column::find()->where(['type' => Column::CMS_TYPE_DOWNLOAD])->alive()->all(), 'id', 'name'));
?>
        
        <?php 
//局部布局
echo $form->field($model, 'title', ['horizontalCssClasses' => ['wrapper' => 'col-sm-8'], 'inputTemplate' => '<div class="input-group">{input}<span class="input-group-addon"><span class="color title-colorpicker" title="' . Yii::t('cms', 'Title Color') . '"><i style="background-color: rgb(0, 170, 187);"></i></span> <span class="blod" title="' . Yii::t('cms', 'Title Bold') . '"><i class="fa fa-bold"></i></span> <span class="clear" title="' . Yii::t('cms', 'Clear') . '"><i class="fa fa-eraser"></i></span></span></div>'])->hint('<i class="fa fa-info-circle"></i> ' . Yii::t('cms', 'Title is required'), ['class' => 'help-block error-none'])->textInput(['maxlength' => true, 'style' => !empty($titleOptions) ? $titleOptions['style'] : '']);
//直接对长度限制
?>
	
	    <?php 
echo Html::activeHiddenInput($model, 'colorval');
?>
	    <?php 
echo Html::activeHiddenInput($model, 'boldval');
?>