public function actionTopics($username) { $user = $this->findUserModel($username, ['userInfo']); $pages = new Pagination(['totalCount' => $user['userInfo']['topic_count'], 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']); $topics = Topic::find()->select('id')->where(['user_id' => $user['id']])->orderBy(['id' => SORT_DESC])->offset($pages->offset)->with(['topic.node', 'topic.lastReply'])->limit($pages->limit)->asArray()->all(); return $this->render('topics', ['user' => $user, 'topics' => $topics, 'pages' => $pages]); }
public function actionFollowing() { $query = Topic::find()->innerJoinWith('authorFollowedBy')->where([Favorite::tableName() . '.source_id' => Yii::$app->getUser()->id, Favorite::tableName() . '.type' => Favorite::TYPE_USER]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(1), 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']); $topics = $query->select([Topic::tableName() . '.id'])->orderBy([Topic::tableName() . '.id' => SORT_DESC])->offset($pages->offset)->with(['topic.author', 'topic.node', 'topic.lastReply'])->limit($pages->limit)->all(); return $this->render('following', ['topics' => Util::convertModelToArray($topics), 'pages' => $pages]); }
public function getEdit($id){ $topic = Topic::find($id); return view('topics.form',[ 'topic' => $topic, 'update' => 'Обновить', 'teg' => $topic->with('teg')->get() ]); }
/** * @return array */ public function getTopicOptions() { $raw = Topic::find()->orderBy('Category_id')->all(); $arr = array(); foreach ($raw as $row) { $categpry = \app\models\Category::getCategoryById($row['Category_id']); $arr[$row['id']] = $categpry . ' - ' . $row['name']; } return $arr; }
protected function findTopicModel($id, $with = null) { $model = Topic::find()->where(['id' => $id]); if (!empty($with)) { $model = $model->with($with); } $model = $model->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('未找到id为[' . $id . ']的主题'); } }
/** * Lists all Topic models. * @return mixed */ public function actionIndex() { if (Yii::$app->user->can('topicIndex')) { $dataProvider = new ActiveDataProvider(['query' => Topic::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); } else { if (Yii::$app->user->isGuest) { Yii::$app->user->loginRequired(); } else { throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Topic::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(['topic_id' => $this->topic_id, 'blog_id' => $this->blog_id, 'user_id' => $this->user_id, 'topic_date_add' => $this->topic_date_add, 'topic_date_edit' => $this->topic_date_edit, 'topic_publish' => $this->topic_publish, 'topic_publish_draft' => $this->topic_publish_draft, 'topic_publish_index' => $this->topic_publish_index, 'topic_rating' => $this->topic_rating, 'topic_count_vote' => $this->topic_count_vote, 'topic_count_vote_up' => $this->topic_count_vote_up, 'topic_count_vote_down' => $this->topic_count_vote_down, 'topic_count_vote_abstain' => $this->topic_count_vote_abstain, 'topic_count_read' => $this->topic_count_read, 'topic_count_comment' => $this->topic_count_comment, 'topic_count_favourite' => $this->topic_count_favourite, 'topic_forbid_comment' => $this->topic_forbid_comment]); $query->andFilterWhere(['like', 'topic_type', $this->topic_type])->andFilterWhere(['like', 'topic_title', $this->topic_title])->andFilterWhere(['like', 'topic_tags', $this->topic_tags])->andFilterWhere(['like', 'topic_user_ip', $this->topic_user_ip])->andFilterWhere(['like', 'topic_cut_text', $this->topic_cut_text])->andFilterWhere(['like', 'topic_text_hash', $this->topic_text_hash]); return $dataProvider; }
public function actionIndex() { $query = Topic::find()->joinWith('topicContent')->joinWith('user')->orderBy('topic_date_add DESC'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $page = 1; if (isset($_GET["page"])) { $page = $_GET["page"]; } $limit = 10; $offset = $limit * ($page - 1); $pageSize = ceil($countQuery->count() / $limit); $pages->setPageSize($pageSize); $models = $query->offset($offset)->limit($limit)->all(); return $this->render('index', ['models' => $models, 'pages' => $pages]); }
private static function addComment($from) { $notice = Notice::findOne(['type' => self::TYPE_COMMENT, 'topic_id' => $from['topic_id'], 'status' => 0]); if ($notice) { return $notice->updateCounters(['notice_count' => 1]); } if (!($topic = Topic::find()->select(['user_id'])->where(['id' => $from['topic_id']])->asArray()->one())) { return false; } if ($topic['user_id'] == $from['source_id']) { return true; } $notice = new Notice($from); // $notice->attributes = $from; $notice->target_id = $topic['user_id']; return $notice->save(false); }
public function actionSearch($search) { $string = trim($search); $string = strip_tags($string); $string = stripslashes($string); $string = htmlspecialchars($string); if (is_string($string) && (string) $string && !empty($string)) { $topic = Topic::find(['title' => $string])->where(['like', 'title', $string])->all(); if ($topic && strlen($string) > 5) { return $this->render('search', ['model' => $topic]); } else { $topic = "Поисковик ничего не нашёл"; return $this->render('search', ['model' => $topic]); } } else { return $this->goBack(); } }
public function search($params) { $query = Topic::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'id'); $this->addCondition($query, 'title', true); $this->addCondition($query, 'content', true); $this->addCondition($query, 'source', true); $this->addCondition($query, 'node_id'); $this->addCondition($query, 'user_id'); $this->addCondition($query, 'created_at'); $this->addCondition($query, 'updated_at'); $this->addCondition($query, 'replies_count'); $this->addCondition($query, 'last_reply_user_id'); $this->addCondition($query, 'replied_at'); return $dataProvider; }
public function updateTopic(Request $request) { $input = $request->all(); //retrieve the relevant model with where condition $course = Topic::find($input['id_topik']); //$course->pertemuan_ke=$input['pertemuan_ke']; //$course->Kode_Matkul=$input['Kode_Matkul']; $course->tanggal = $input['tanggal']; $course->nama_topik = $input['nama_topik']; $course->jumlah_mhs = $input['jumlah_mhs']; $course->save(); return $this->showTopic(); }
public function actionIndex() { $topics = Topic::find()->with('user')->all(); return $this->render('index', ['topics' => $topics]); }
public function run() { $random = Topic::find()->orderBy(['rand()' => SORT_DESC])->one(); return $this->render('random', ['rand' => $random]); }