Esempio n. 1
0
 /**
  * Finds the RightLink model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return RightLink the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = RightLink::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 public function actionIndex()
 {
     $topics = Post::find()->limit(20)->where(['status' => 2])->orderBy(['created_at' => SORT_DESC])->all();
     $users = UserService::findActiveUser(12);
     $headline = Arr::getColumn(RightLink::find()->where(['type' => RightLink::RIGHT_LINK_TYPE_HEADLINE])->all(), 'content');
     $statistics = [];
     $statistics['post_count'] = Post::find()->count();
     $statistics['comment_count'] = PostComment::find()->count();
     $statistics['online_count'] = Session::find()->where(['>', 'expire', time()])->count();
     return $this->render('index', ['topics' => $topics, 'users' => $users, 'statistics' => $statistics, 'headline' => Arr::arrayRandomAssoc($headline)]);
 }
Esempio n. 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = RightLink::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'created_user', $this->created_user]);
     return $dataProvider;
 }
Esempio n. 4
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]);
 }
Esempio n. 5
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]);
 }