Example #1
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]);
 }
Example #2
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]);
 }
Example #3
0
 /**
  * 最近主题
  * @param string $username
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionPost($username = '')
 {
     $user = $this->user($username);
     $dataProvider = new ActiveDataProvider(['query' => Topic::find()->where(['user_id' => $user->id, 'type' => Topic::TYPE])->andWhere('status > :status ', [':status' => Topic::STATUS_DELETED])->orderBy(['created_at' => SORT_DESC])]);
     return $this->render('show', ['user' => $user, 'dataProvider' => $dataProvider]);
 }