/**
  * Updates an existing Article model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'ads' => Ad::find()->all(), 'articles' => Article::find()->all()]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ArticleCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ArticleCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ArticleCategory::find();
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'domain_id' => $this->domain_id]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied.
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ArticleCategory::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 30]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
Ejemplo n.º 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ArticleCategory::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Ejemplo n.º 7
0
 /**
  * @param string $category
  * @return string
  */
 public function actionIndex($category)
 {
     $model = ArticleCategory::find()->andWhere(['slug' => $category])->one();
     if (!$model) {
         throw new NotFoundHttpException();
     }
     //Мета-теги
     foreach (['description', 'keywords'] as $name) {
         $attr = 'meta_' . $name;
         \Yii::$app->view->registerMetaTag(['name' => $name, 'content' => strlen($model->{$attr}) > 0 ? $model->{$attr} : Yii::$app->keyStorage->get('frontend.' . $attr)], $name);
     }
     $searchModel = new ArticleSearch();
     $searchModel->category_id = $model->id;
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $dataProvider->sort = ['defaultOrder' => ['created_at' => SORT_DESC]];
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
Ejemplo n.º 8
0
 public function actionIndex()
 {
     $catID = Yii::$app->request->get('category');
     // Вывести список статей
     $pageSize = 9;
     $query = Article::find();
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => $pageSize]);
     if ($catID) {
         $models = $query->offset($pages->offset)->where(['article_category' => $catID])->orderBy('created_at DESC')->limit($pages->limit)->all();
     } else {
         $models = $query->offset($pages->offset)->orderBy('created_at DESC')->limit($pages->limit)->all();
     }
     $modelLastArticle = Article::find()->orderBy('id DESC')->limit(3)->all();
     $modeMostWatched = Article::find()->orderBy('view DESC')->limit(3)->all();
     $ArticleCategoryModel = ArticleCategory::find()->leftJoin('article', '`article`.`article_category` = `article_category`.`id`')->where(['<>', 'article.article_category', 111])->with('article')->all();
     return $this->render('index', ['model' => $models, 'modelLastArticle' => $modelLastArticle, 'modeMostWatched' => $modeMostWatched, 'pages' => $pages, 'pageSize' => $pageSize, 'ArticleCategoryModel' => $ArticleCategoryModel]);
 }
Ejemplo n.º 9
0
 /**
  * Generate menu items for yii\widgets\Menu
  *
  * @param null|array $models
  * @return array
  */
 public static function getMenuItems(array $models = null)
 {
     $items = [];
     if ($models === null) {
         $models = ArticleCategory::find()->where(['parent_id' => null])->with('childs')->orderBy(['id' => SORT_ASC])->active()->all();
     }
     foreach ($models as $model) {
         $items[] = ['url' => ['article/category', 'slug' => $model->slug], 'label' => $model->title, 'items' => self::getMenuItems($model->childs)];
     }
     return $items;
 }
Ejemplo n.º 10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getParent()
 {
     return $this->hasMany(ArticleCategory::className(), ['id' => 'parent_id']);
 }
Ejemplo n.º 11
0
    echo StringHelper::truncate($article->description, 20, '...');
    ?>
</p>
							</li>
						<?php 
}
?>

					</ul>
					<!-- End Latest Links -->

					<div class="headline-v2"><h2>标签</h2></div>
					<!-- Tags v2 -->
					<ul class="list-inline tags-v2 margin-bottom-50">
						<?php 
foreach (\common\models\ArticleCategory::find()->all() as $articleCat) {
    ?>
							<li><?php 
    echo Html::a($articleCat->title, ['index', 'ArticleSearch[category_id]' => $articleCat->id]);
    ?>
</li>
						<?php 
}
?>
					</ul>
					<!-- End Tags v2 -->
				</div>
				<!-- End Blog Sidebar -->
			</div>
		</div>
	</div>
Ejemplo n.º 12
0
 /**
  * Updates an existing Article model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $firstModel = $this->findModel($id);
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Article::getLocaleInstance($key);
         $dataModel = $currentModel::find()->andWhere(['locale_group_id' => $firstModel->locale_group_id, 'locale' => $key])->one();
         $dataModel->categoriesList = $this->getCategoriesListIds($dataModel->id);
         if (!empty($dataModel->domain)) {
             $dataModel->domain = explode(',', $dataModel->domain);
         }
         $models[$key] = $dataModel;
         if (!$models[$key]) {
             $currentModel->attributes = $firstModel->attributes;
             $currentModel->attachments = $firstModel->attachments;
             $currentModel->thumbnail = $firstModel->thumbnail;
             $currentModel->image = $firstModel->image;
             $currentModel->categoriesList = $firstModel->categoriesList;
             //$currentModel->video = $firstModel->video;
             $currentModel->locale_group_id = $firstModel->locale_group_id;
             $currentModel->locale = $key;
             $currentModel->title = 'title ' . $key . ' ' . time();
             $currentModel->slug = '';
             $models[$key] = $currentModel;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Article::multiSaveUpdate($model)) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
Ejemplo n.º 13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getArticleCategories()
 {
     return $this->hasMany(ArticleCategory::className(), ['article_id' => 'id']);
 }
Ejemplo n.º 14
0
<?php

use yii\bootstrap\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use common\models\ArticleCategory;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\ArticleCategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Article categories');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="article-category-index">

    <p>
        <?php 
echo Html::a(Yii::t('backend', 'Create article category'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['title', 'comment', ['attribute' => 'parent_id', 'value' => function ($model) {
    return $model->parent ? $model->parent->title : null;
}, 'filter' => ArrayHelper::map(ArticleCategory::find()->noParents()->all(), 'id', 'title')], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) {
    return $model->status ? '<span class="glyphicon glyphicon-ok text-success"></span>' : '<span class="glyphicon glyphicon-remove text-danger"></span>';
}, 'filter' => [ArticleCategory::STATUS_DRAFT => Yii::t('backend', 'Not active'), ArticleCategory::STATUS_ACTIVE => Yii::t('backend', 'Active')]], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
?>

</div>
Ejemplo n.º 15
0
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\ArticleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Articles');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="article-index">

    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => 'Article']), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', 'slug', 'title', ['attribute' => 'category_id', 'value' => function ($model) {
    return $model->category ? $model->category->title : null;
}, 'filter' => \yii\helpers\ArrayHelper::map(\common\models\ArticleCategory::find()->all(), 'id', 'title')], ['attribute' => 'author_id', 'value' => function ($model) {
    return $model->author->username;
}], ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => [Yii::t('backend', 'Not Published'), Yii::t('backend', 'Published')]], 'published_at:datetime', 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
?>

</div>
Ejemplo n.º 16
0
 /**
  * Gets used category switches
  * @return array
  */
 protected function getCategoryBoxes()
 {
     return $this->item_id ? ArticleCategory::find()->select('category_id')->andWhere(['article_id' => $this->item_id])->column() : [Category::getMainCategory($this->language_id)];
 }
Ejemplo n.º 17
0
<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
use common\models\User;
use common\models\ArticleCategory;
/* @var $this yii\web\View */
/* @var $model common\models\ArticlesSearch */
/* @var $form yii\widgets\ActiveForm */
$authors = User::find()->all();
$items = ArrayHelper::map($authors, 'id', 'username');
$params = ['prompt' => 'Укажите автора'];
$category = ArticleCategory::find()->all();
$categoryItem = ArrayHelper::map($category, 'id', 'title');
$categoryParams = ['prompt' => 'Укажите категорию'];
?>

<div class="articles-search">

    <?php 
$form = ActiveForm::begin(['action' => ['articles'], 'method' => 'get']);
?>

    <?php 
// $form->field($model, 'id')
?>

    <?php 
echo $form->field($model, 'title');
?>
Ejemplo n.º 18
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['label', 'alias', 'content', 'date'], 'required'], [['category_id', 'views', 'published', 'position'], 'integer'], [['announce', 'content'], 'string'], [['date'], 'date', 'format' => 'yyyy-MM-dd'], [['label', 'alias', 'tags'], 'string', 'max' => 255], [['category_id'], 'exist', 'targetClass' => \common\models\ArticleCategory::className(), 'targetAttribute' => 'id'], [['views'], 'default', 'value' => 0], [['published'], 'default', 'value' => 1], [['position'], 'default', 'value' => 0], [['alias'], 'unique']];
 }
Ejemplo n.º 19
0
use common\grid\EnumColumn;
use common\models\ArticleCategory;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\ArticleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Articles');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="article-index">

    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => 'Article']), ['create'], ['class' => 'btn btn-success']);
?>
    </p>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'options' => ['class' => 'grid-view table-responsive'], 'columns' => ['id', 'slug', 'title', ['attribute' => 'category_id', 'value' => function ($model) {
    return $model->category ? $model->category->title : null;
}, 'filter' => ArrayHelper::map(ArticleCategory::find()->all(), 'id', 'title')], ['attribute' => 'created_by', 'value' => function ($model) {
    return $model->author->username;
}], ['class' => EnumColumn::className(), 'attribute' => 'status', 'enum' => [Yii::t('backend', 'Not Published'), Yii::t('backend', 'Published')]], 'published_at:datetime', 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
?>
</div>
Ejemplo n.º 20
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(ArticleCategory::className(), ['id' => 'category_id']);
 }
Ejemplo n.º 21
0
 /**
  * @return array
  */
 public function getFormConfig()
 {
     return ['label' => ['type' => ActiveFormBuilder::INPUT_TEXT, 'options' => ['maxlength' => true, 'class' => 's_name']], 'alias' => ['type' => ActiveFormBuilder::INPUT_TEXT, 'options' => ['maxlength' => true, 'class' => 's_alias']], 'category_id' => ['type' => ActiveFormBuilder::INPUT_DROPDOWN_LIST, 'items' => \common\models\ArticleCategory::getItems(), 'options' => ['prompt' => '']], 'announce' => ['type' => ActiveFormBuilder::INPUT_WIDGET, 'widgetClass' => \backend\components\ImperaviContent::className(), 'options' => ['model' => $this, 'attribute' => 'announce']], 'content' => ['type' => ActiveFormBuilder::INPUT_WIDGET, 'widgetClass' => \backend\components\ImperaviContent::className(), 'options' => ['model' => $this, 'attribute' => 'content']], 'date' => ['type' => ActiveFormBuilder::INPUT_WIDGET, 'widgetClass' => \metalguardian\dateTimePicker\Widget::className(), 'options' => ['mode' => \metalguardian\dateTimePicker\Widget::MODE_DATE, 'options' => ['class' => 'form-control']]], 'titleImage' => ['type' => ActiveFormBuilder::INPUT_RAW, 'value' => ImageUpload::widget(['model' => $this, 'attribute' => 'titleImage', 'saveAttribute' => EntityToFile::TYPE_ARTICLE_TITLE_IMAGE, 'multiple' => false, 'aspectRatio' => 848 / 350, 'uploadUrl' => ImagesUploadModel::uploadUrl(['model_name' => static::className(), 'attribute' => 'titleImage', 'entity_attribute' => EntityToFile::TYPE_ARTICLE_TITLE_IMAGE])])], 'tags' => ['type' => ActiveFormBuilder::INPUT_TEXT, 'options' => ['maxlength' => true]], 'views' => ['type' => ActiveFormBuilder::INPUT_TEXT], 'published' => ['type' => ActiveFormBuilder::INPUT_CHECKBOX], 'position' => ['type' => ActiveFormBuilder::INPUT_TEXT], 'sign' => ['type' => ActiveFormBuilder::INPUT_RAW, 'value' => Html::activeHiddenInput($this, 'sign')]];
 }
Ejemplo n.º 22
0
 /**
  * Finds the ArticleCategory model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return ArticleCategory the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ArticleCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 23
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getModel()
 {
     return $this->hasOne(ArticleCategory::className(), ['id' => 'model_id']);
 }