Exemplo n.º 1
0
 /**
  * Finds the PostMeta model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return PostMeta the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = PostMeta::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 public function run()
 {
     $nodes = [];
     $parents = ArrayHelper::map(PostMeta::find()->where(['parent' => null])->orWhere(['parent' => 0])->orderBy(['order' => SORT_ASC])->all(), 'id', 'name');
     foreach ($parents as $key => $value) {
         $nodes[$value] = PostMeta::find()->where(['parent' => $key])->asArray()->all();
     }
     return $this->render('node', ['nodes' => $nodes]);
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = PostMeta::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'count' => $this->count, 'order' => $this->order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 public function run()
 {
     $cacheKey = md5(__METHOD__);
     if (false === ($items = \Yii::$app->cache->get($cacheKey))) {
         $parents = ArrayHelper::map(PostMeta::find()->where(['parent' => null])->orWhere(['parent' => 0])->orderBy(['order' => SORT_ASC])->all(), 'id', 'name');
         foreach ($parents as $key => $value) {
             $nodes[$value] = PostMeta::find()->where(['parent' => $key])->asArray()->all();
         }
         $items = $nodes;
         //一天缓存
         \Yii::$app->cache->set($cacheKey, $items, 86400, new TagDependency(['tags' => [NamingHelper::getCommonTag(PostMeta::className())]]));
     }
     return $this->render('node', ['nodes' => $items]);
 }
Exemplo n.º 5
0
 /**
  * @param $params
  * @param array $conditions
  * @return ActiveDataProvider
  */
 public function search($params, $conditions = [])
 {
     $query = Post::find()->where($conditions);
     // 如果有无人区节点 帖子列表过滤无人区节点的帖子
     if (PostMeta::noManLandId() && (empty($params['PostSearch']['post_meta_id']) || $params['PostSearch']['post_meta_id'] != PostMeta::noManLandId())) {
         $query->andWhere(['!=', 'post_meta_id', PostMeta::noManLandId()]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 15], 'sort' => ['defaultOrder' => ['order' => SORT_ASC, 'updated_at' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'post_meta_id' => $this->post_meta_id, 'user_id' => $this->user_id, 'view_count' => $this->view_count, 'comment_count' => $this->comment_count, 'favorite_count' => $this->favorite_count, 'like_count' => $this->like_count, 'thanks_count' => $this->thanks_count, 'hate_count' => $this->hate_count, 'status' => $this->status, 'order' => $this->order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'type', $this->type])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'excerpt', $this->excerpt])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'tags', $this->tags]);
     return $dataProvider;
 }
Exemplo n.º 6
0
 /**
  * 话题列表
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostSearch();
     // 话题或者分类筛选
     $params = Yii::$app->request->queryParams;
     empty($params['tag']) ?: ($params['PostSearch']['tags'] = $params['tag']);
     if (isset($params['node'])) {
         $postMeta = PostMeta::findOne(['alias' => $params['node']]);
         $postMeta ? $params['PostSearch']['post_meta_id'] = $postMeta->id : '';
     }
     $dataProvider = $searchModel->search($params);
     $dataProvider->query->andWhere([Post::tableName() . '.type' => 'topic', 'status' => [Post::STATUS_ACTIVE, Post::STATUS_EXCELLENT]]);
     // 排序
     $sort = $dataProvider->getSort();
     $sort->attributes = array_merge($sort->attributes, ['hotest' => ['asc' => ['comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'excellent' => ['asc' => ['status' => SORT_DESC, 'comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'uncommented' => ['asc' => ['comment_count' => SORT_ASC, 'created_at' => SORT_DESC]]]);
     return $this->render('index', ['searchModel' => $searchModel, 'sorts' => $this->sorts, 'dataProvider' => $dataProvider]);
 }
Exemplo n.º 7
0
 public function run()
 {
     $tipsModel = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_TIPS])->all(), 'content', 'title');
     $tips = array_rand($tipsModel);
     $recommendResources = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_RSOURCES])->all(), 'title', 'url');
     $links = RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_LINKS])->all();
     $sameTopics = [];
     if ($this->node) {
         $sameTopics = ArrayHelper::map(Topic::find()->where('status >= :status', [':status' => Topic::STATUS_ACTIVE])->andWhere(['post_meta_id' => $this->node->id, 'type' => 'topic'])->limit(200)->all(), 'title', function ($e) {
             return Url::to(['/topic/default/view', 'id' => $e->id]);
         });
         if (count($sameTopics) > 10) {
             $sameTopics = Arr::arrayRandomAssoc($sameTopics, 10);
         }
     }
     return $this->render('topicSidebar', ['category' => PostMeta::blogCategory(), 'config' => ['type' => $this->type, 'node' => $this->node], 'sameTopics' => $sameTopics, 'tips' => $tips, 'recommendResources' => $recommendResources, 'links' => $links]);
 }
Exemplo n.º 8
0
 public function run()
 {
     $tipsModel = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_TIPS])->all(), 'content', 'title');
     $tips = array_rand($tipsModel);
     $recommendResources = ArrayHelper::map(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_RSOURCES])->all(), 'title', 'url');
     $links = RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_LINKS])->all();
     $sameTopics = [];
     if ($this->node) {
         $sameTopics = ArrayHelper::map(Topic::find()->where('status >= :status', [':status' => Topic::STATUS_ACTIVE])->andWhere(['post_meta_id' => $this->node->id, 'type' => 'topic'])->limit(200)->all(), 'title', function ($e) {
             return Url::to(['/topic/default/view', 'id' => $e->id]);
         });
         if (count($sameTopics) > 10) {
             $sameTopics = Arr::arrayRandomAssoc($sameTopics, 10);
         }
         if ($this->type == 'view' && (in_array($this->node->alias, params('donateNode')) || array_intersect(explode(',', $this->tags), params('donateTag')))) {
             $donate = Donate::findOne(['user_id' => Topic::findOne(['id' => request()->get('id')])->user_id, 'status' => Donate::STATUS_ACTIVE]);
         }
     }
     return $this->render('topicSidebar', ['category' => PostMeta::blogCategory(), 'config' => ['type' => $this->type, 'node' => $this->node], 'sameTopics' => $sameTopics, 'tips' => $tips, 'donate' => isset($donate) ? $donate : [], 'recommendResources' => $recommendResources, 'links' => $links]);
 }
Exemplo n.º 9
0
 public function getCategory()
 {
     return $this->hasOne(PostMeta::className(), ['id' => 'post_meta_id']);
 }
Exemplo n.º 10
0
 /**
  * Update meta data for current post.
  *
  * @param $meta_name
  * @param $meta_value
  *
  * @return bool
  */
 public function upMeta($meta_name, $meta_value)
 {
     $model = PostMeta::find()->andWhere(['meta_name' => $meta_name])->andWhere(['post_id' => $this->id])->one();
     if (is_array($meta_value) || is_object($meta_value)) {
         $meta_value = Json::encode($meta_value);
     }
     $model->meta_value = $meta_value;
     return $model->save();
 }
Exemplo n.º 11
0
<div class="list-group-item">

    <?php 
$form = ActiveForm::begin(['fieldConfig' => ['template' => "{input}\n{hint}\n{error}"]]);
?>

    <?php 
echo $form->errorSummary($model, ['class' => 'alert alert-danger']);
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 255, 'placeholder' => '标题']);
?>

    <?php 
echo $form->field($model, 'post_meta_id')->widget(Select2::classname(), ['data' => \common\models\PostMeta::topicCategory(), 'options' => ['placeholder' => '选择一个分类'], 'pluginOptions' => ['allowClear' => true, 'height' => '343%']]);
?>

    <?php 
echo $this->render('@frontend/views/partials/markdwon_help');
?>

    <div class="form-group" id="editor">
        <?php 
echo $form->field($model, 'content')->widget('trntv\\aceeditor\\AceEditor', ['id' => 'markdown', 'mode' => 'markdown', 'containerOptions' => ['style' => 'width: 100%; min-height: 350px'], 'theme' => 'github']);
?>
    </div>

    <?php 
echo SelectizeTextInput::widget(['name' => 'Topic[tags]', 'value' => $model->tags, 'loadUrl' => ['/post-tag/index'], 'clientOptions' => ['placeholder' => '标签(可选)', 'allowEmptyOption' => false, 'delimiter' => ',', 'valueField' => 'name', 'labelField' => 'name', 'searchField' => 'name', 'maxItems' => 5, 'plugins' => ['remove_button'], 'persist' => false, 'create' => true]]);
?>
Exemplo n.º 12
0
 /**
  * Update meta data for current post.
  *
  * @param $meta_name
  * @param $meta_value
  *
  * @return bool
  */
 public function upMeta($meta_name, $meta_value)
 {
     /* @var $model \common\models\PostMeta */
     $model = PostMeta::findOne(['meta_name' => $meta_name, 'post_id' => $this->id]);
     if (is_array($meta_value) || is_object($meta_value)) {
         $meta_value = Json::encode($meta_value);
     }
     $model->meta_value = $meta_value;
     return $model->save();
 }
Exemplo n.º 13
0
<?php

use yii\helpers\Html;
use yii\widgets\ListView;
use yii\widgets\Pjax;
use frontend\widgets\TopicSidebar;
use kartik\icons\Icon;
Icon::map($this);
$this->title = '社区';
$keyword = Yii::$app->request->getQueryParam('keyword');
if ($node = Yii::$app->request->getQueryParam('node')) {
    $node = \common\models\PostMeta::find()->where(['alias' => $node])->one();
}
?>
<div class="col-md-10 topic">
    <div class="panel panel-default">
        <?php 
if ($node) {
    ?>
            <div class="panel-heading clearfix">
                <?php 
    echo Icon::show('cloud-upload');
    ?>
 <?php 
    echo $node->name;
    ?>
                <?php 
    if (!empty($node->description)) {
        ?>
                    <br/>
                    <span style="color: #666666; font-size: 12px;"><?php 
Exemplo n.º 14
0
<div class="list-group-item">

    <?php 
$form = ActiveForm::begin(['fieldConfig' => ['template' => "{input}\n{hint}\n{error}"]]);
?>

    <?php 
echo $form->errorSummary($model, ['class' => 'alert alert-danger']);
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 255, 'placeholder' => '标题']);
?>

    <?php 
echo $form->field($model, 'post_meta_id')->dropDownList(\common\models\PostMeta::topicCategory(), ['prompt' => '选择一个分类']);
?>

    <?php 
echo $this->render('@frontend/views/partials/markdwon_help');
?>

    <?php 
echo $form->field($model, 'content', ['selectors' => ['input' => '#md-input']])->textarea(['placeholder' => '内容', 'id' => 'md-input', 'rows' => 10]);
?>

    <?php 
echo SelectizeTextInput::widget(['name' => 'Topic[tags]', 'value' => $model->tags, 'loadUrl' => ['/post-tag/index'], 'clientOptions' => ['placeholder' => '标签(可选)', 'allowEmptyOption' => false, 'delimiter' => ',', 'valueField' => 'name', 'labelField' => 'name', 'searchField' => 'name', 'maxItems' => 5, 'plugins' => ['remove_button'], 'persist' => false, 'create' => true]]);
?>

    <div class="form-group">