Example #1
0
 public function run()
 {
     $query = BlogPost::find()->where(['status' => Status::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC])->limit($this->maxPosts);
     $cacheId = Yii::$app->params["domain"] . '_blog_post_' . md5(serialize($query));
     $posts = Yii::$app->cache->get($cacheId);
     if ($posts === false) {
         $posts = $query->all();
         Yii::$app->cache->set($cacheId, $posts, $this->cacheDuration);
     }
     return $this->render('recentPosts', ['title' => $this->title, 'posts' => $posts]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = BlogPost::find();
     $query->orderBy(['created_at' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'catalog_id' => $this->catalog_id, 'click' => $this->click, 'user_id' => $this->user_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'surname', $this->surname]);
     return $dataProvider;
 }
Example #3
0
 public function run()
 {
     $request = Yii::$app->getRequest();
     $post = BlogPost::findOne(['surname' => Yii::$app->request->get('surname')]);
     $post_id = $post->id;
     //$post = BlogPost::findOne($post_id);
     $this->modelComment = new BlogComment();
     if ($request->isAjax && $this->modelComment->load($request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $this->modelComment->status = Status::STATUS_INACTIVE;
         $errors = ActiveForm::validate($this->modelComment);
         if (count($errors) != 0) {
             Yii::$app->getSession()->setFlash('blog.commentAddError', json_encode($errors));
         } else {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 if (!$this->modelComment->save()) {
                     Yii::$app->getSession()->setFlash('blog.commentAddError', 'Ошибка');
                     //throw new ErrorException('Error!');
                 }
                 $transaction->commit();
                 Yii::$app->getSession()->setFlash('blog.commentAddSuccess', 'Отправлено на модерацию');
             } catch (ErrorException $e) {
                 $transaction->rollBack();
                 Yii::$app->getSession()->setFlash('blog.commentAddError', $e->getMessage());
             }
         }
         $this->modelComment = new BlogComment();
     }
     $commentsList = BlogComment::find()->where(['post_id' => $post_id, 'status' => Status::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC])->all();
     $this->modelComment->post_id = $post_id;
     if (!Yii::$app->user->isGuest) {
         $this->modelComment->email = Yii::$app->params['blogUserEMail'];
         $this->modelComment->author = Yii::$app->params['blogUserDisplayName'];
         $this->modelComment->user_id = Yii::$app->params['blogUserId'];
     }
     return $this->render('@sircovsw/blog/widgets/Comment/views/index', array('modelComment' => $this->modelComment, 'commentsList' => $commentsList));
 }
 public function actionRss()
 {
     $path = Yii::getAlias('@vendor/zelenin/rss-generator/Feed.php');
     require_once $path;
     $dataProvider = new \yii\data\ActiveDataProvider(['query' => \sircovsw\blog\models\BlogPost::find()->where(['status' => \sircovsw\blog\models\Status::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC]), 'pagination' => ['pageSize' => 10]]);
     $response = Yii::$app->getResponse();
     $headers = $response->getHeaders();
     $headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     echo \Zelenin\yii\extensions\Rss\RssView::widget(['dataProvider' => $dataProvider, 'channel' => ['title' => Yii::$app->name, 'link' => Url::toRoute('/', true), 'description' => 'Блог LinkOnAvt - помощь, справочные материалы, обсуждения', 'language' => function ($widget, \Zelenin\Feed $feed) {
         return Yii::$app->language;
     }, 'image' => function ($widget, \Zelenin\Feed $feed) {
         $feed->addChannelImage('http://' . Yii::$app->params["domain"] . '/img/logo.png', 'http://' . Yii::$app->params["domain"], 100, 100, 'Продвижение сайта самостоятельно');
     }], 'items' => ['title' => function ($model, $widget, \Zelenin\Feed $feed) {
         return $model->title;
     }, 'description' => function ($model, $widget, \Zelenin\Feed $feed) {
         return StringHelper::truncateWords($model->brief, 50);
     }, 'link' => function ($model, $widget, \Zelenin\Feed $feed) {
         $url = 'http://' . Yii::$app->params["domain"] . '/blog/view/' . $model->surname;
         return $url;
         //return Yii::$app->getUrlManager()->createUrl(['blog/default/view', 'surname' => $model->surname]);
         //return Url::toRoute(['blog/default/view', 'surname' => $model->surname], true);
     }, 'author' => function ($model, $widget, \Zelenin\Feed $feed) {
         return $model->user->email . ' (' . $model->user->username . ')';
     }, 'guid' => function ($model, $widget, \Zelenin\Feed $feed) {
         $date = date('d.m.Y H:i:s', $model->created_at);
         $url = 'http://' . Yii::$app->params["domain"] . '/blog/view/' . $model->surname;
         return $url;
         //.' '.\Datetime::createFromFormat('d.m.Y H:i:s', $date)->format(DATE_RSS);
         //return Url::toRoute(['blog/default/view', 'surname' => $model->surname], true).' '.\Datetime::createFromFormat('d.m.Y H:i:s', $date)->format(DATE_RSS);
     }, 'pubDate' => function ($model, $widget, \Zelenin\Feed $feed) {
         $date = date('d.m.Y H:i:s', $model->created_at);
         return \Datetime::createFromFormat('d.m.Y H:i:s', $date)->format(DATE_RSS);
     }]]);
 }
 /**
  * Finds the BlogPost model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BlogPost the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BlogPost::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #6
0
use yii\widgets\ActiveForm;
use sircovsw\blog\models\BlogPost;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model backend\modules\blog\models\BlogComment */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="blog-comment-form">

	<?php 
$form = ActiveForm::begin();
?>

	<?php 
echo $form->field($model, 'post_id')->dropDownList(ArrayHelper::map(BlogPost::find()->all(), 'id', 'title'));
?>

	<?php 
echo $form->field($model, 'content')->textarea(['rows' => 6]);
?>

	<?php 
echo $form->field($model, 'author')->textInput(['maxlength' => 128]);
?>

	<?php 
echo $form->field($model, 'email')->textInput(['maxlength' => 128]);
?>

	<?php 
Example #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBlogPost()
 {
     return $this->hasOne(BlogPost::className(), ['id' => 'post_id']);
 }
Example #8
0
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="blog-post-index">

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

	<p>
		<?php 
echo Html::a(Module::t('blog', 'Create ') . Module::t('blog', 'Blog Post'), ['create'], ['class' => 'btn btn-success']);
?>
	</p>

	<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn'], ['attribute' => 'catalog_id', 'value' => function ($model) {
    return $model->catalog->title;
}, 'filter' => Html::activeDropDownList($searchModel, 'catalog_id', \sircovsw\blog\models\BlogPost::getArrayCatalog(), ['class' => 'form-control', 'prompt' => Module::t('blog', 'Please Filter')])], 'title', 'commentsCount', ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) {
    if ($model->status === Status::STATUS_ACTIVE) {
        $class = 'label-success';
    } elseif ($model->status === Status::STATUS_INACTIVE) {
        $class = 'label-warning';
    } else {
        $class = 'label-danger';
    }
    return '<span class="label ' . $class . '">' . $model->getStatus()->label . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'status', Status::labels(), ['class' => 'form-control', 'prompt' => Module::t('blog', 'PROMPT_STATUS')])], 'created_at:date', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
 public function models()
 {
     return [['class' => BlogPost::className(), 'change' => Sitemap::WEEKLY, 'priority' => 0.8]];
 }
Example #10
0
 public function getPostsCount()
 {
     return $this->count(BlogPost::className(), ['catalog_id' => 'id']);
 }