本文整理汇总了PHP中common\models\Comment::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::find方法的具体用法?PHP Comment::find怎么用?PHP Comment::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Comment
的用法示例。
在下文中一共展示了Comment::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionArticle
/**
* 显示一个文章的信息
* @return type
*/
public function actionArticle()
{
$id = \Yii::$app->request->get('id');
$idTrue = true;
if (empty($id)) {
$idTrue = FALSE;
}
if ($idTrue) {
$articleInfo = Comment::find()->where('id=:id', [':id' => $id])->one();
if (!$articleInfo) {
$idTrue = FALSE;
} else {
if ($articleInfo->is_public === 0 && \Yii::$app->user->getId() !== $articleInfo->to_user_id && \Yii::$app->user->getId() !== $articleInfo->user_id) {
$idTrue = FALSE;
}
}
}
if (!$idTrue) {
$error = '当前评论不存在或者已经被禁止显示';
$notices = array('type' => 2, 'msgtitle' => '错误的访问', 'message' => $error, 'backurl' => Url::toRoute('/say/index'), 'backtitle' => '返回');
Yii::$app->getSession()->setFlash('wechat_fail', array($notices));
$this->redirect(Url::toRoute('/public/notices'));
}
return $this->render('article', ['articleInfo' => $articleInfo]);
}
示例2: actionAddComment
public function actionAddComment()
{
if (\Yii::$app->request->isAjax) {
$model = new Comment();
if (\Yii::$app->user->isGuest) {
$model->scenario = 'isGuest';
}
$data = ['error' => true];
if ($model->load(\Yii::$app->request->post())) {
$parentID = \Yii::$app->request->post('parent_id');
$root = $model->makeRootIfNotExist();
if (!$parentID) {
$model->appendTo($root);
} else {
$parent = Comment::find()->where(['id' => $parentID])->one();
$model->appendTo($parent);
}
$articleModel = Article::findOne($model->model_id);
$data = ['replaces' => [['what' => '#comments', 'data' => $this->renderAjax('@app/themes/basic/modules/article/views/default/_comments', ['model' => $articleModel])]]];
}
return Json::encode($data);
} else {
throw new NotFoundHttpException(\Yii::t('app', 'Page not found'));
}
}
示例3: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::find();
$commentTable = Comment::tableName();
$user = Yii::$app->getModule("user")->model("User");
// set up query with relation to `user.username`
$userTable = $user::tableName();
$query->joinWith(['user' => function ($query) use($userTable) {
$query->from(['user' => $userTable]);
}]);
$profileTable = \common\modules\user\models\Profile::tableName();
$query->joinWith(['profile' => function ($query) use($profileTable) {
$query->from(['profile' => $profileTable]);
}]);
$dataProvider = new ActiveDataProvider(['query' => $query]);
// enable sorting for the related columns
$addSortAttributes = ["user.username", 'profile.full_name'];
foreach ($addSortAttributes as $addSortAttribute) {
$dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
}
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$createdTime = strtotime($this->created_at);
$startDay = date("Y-m-d 00:00:00", $createdTime);
$endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24);
if ($this->created_at) {
$query->andFilterWhere(['between', 'created_at', $startDay, $endDay]);
}
$query->andFilterWhere(["{$commentTable}.id" => $this->id, "{$commentTable}.user_id" => $this->user_id, 'parent_id' => $this->parent_id]);
$query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')])->andFilterWhere(['like', 'profile.full_name', $this->getAttribute('profile.full_name')]);
return $dataProvider;
}
示例4: actionList
public function actionList($event_id)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
$dp = new ActiveDataProvider();
$dp->query = Comment::find()->with('user')->where(['event_id' => $event_id])->orderBy(['id' => SORT_DESC]);
$dp->pagination->pageSize = 6;
return ['items' => $dp->getModels(), 'pageCount' => $dp->getPagination()->getPageCount(), 'totalCount' => $dp->getTotalCount(), 'page' => $dp->pagination->page, 'count' => $dp->getCount()];
}
示例5: findComments
/**
*
* @param int $data
* @return \yii\data\ActiveDataProvider
*/
public static function findComments($data = array())
{
if (!isset($data['limit'])) {
$data['limit'] = 10;
}
$model = new Comment();
$dataProvider = new ActiveDataProvider(['query' => $model->find()->Where('is_public=:isp and top_id=0 and c_type="article" ', [':isp' => $data['is_public']])->orderBy(" id desc ")->limit($data['limit']), 'pagination' => ['pagesize' => $data['limit']]]);
return $dataProvider;
}
示例6: run
public function run()
{
$query = Comment::find();
if ($this->entity == Comment::ENTITY_ITEM || $this->entity == Comment::ENTITY_EVENT || $this->entity == Comment::ENTITY_SCHOOL) {
$query = $query->andWhere(['entity' => $this->entity, 'entity_id' => $this->entity_id])->orderBy('date_create DESC');
}
$commentsAll = $query->all();
$commentIds = [];
$comments = [];
$commentsParent = [];
$commentsLink = [];
/** @var Comment[] $commentsAll */
foreach ($commentsAll as $comment) {
if ($comment->parent_id == 0) {
// Главный комментарий
$commentsLink[$comment->id] = true;
$commentIds[] = $comment->id;
if ($comment->deleted == 0) {
$comments[] = $comment;
}
} else {
// Ответ на комментарий
$commentsLink[$comment->id] = $comment->parent_id;
}
}
foreach ($commentsAll as $comment) {
if ($comment->deleted == 0) {
$commentId = $comment->parent_id;
while (isset($commentsLink[$commentId])) {
if ($commentsLink[$commentId] === true) {
break;
} else {
if ($commentsLink[$commentId] != $commentId) {
$commentId = $commentsLink[$commentId];
} else {
$commentId = null;
}
}
}
if (!empty($commentId)) {
$commentsParent[$commentId][] = $comment;
$commentIds[] = $comment->id;
}
}
}
$thisUser = User::thisUser();
/** @var Vote[] $voteItemsAll */
$voteItemsAll = !empty($thisUser) ? $thisUser->getVotesByEntity(Vote::ENTITY_COMMENT, $commentIds) : [];
$voteItems = [];
foreach ($voteItemsAll as $voteItem) {
$voteItems[$voteItem->entity_id] = $voteItem;
}
return $this->render('commentsWidget/list', ['comments' => $comments, 'voteItems' => $voteItems, 'commentsParent' => $commentsParent, 'entity' => $this->entity, 'entity_id' => $this->entity_id, 'showDialog' => $this->showDialog]);
}
示例7: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::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, 'user_id' => $this->user_id, 'product_id' => $this->product_id, 'order_id' => $this->order_id, 'star' => $this->star, 'point' => $this->point, 'up' => $this->up, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
$query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'content', $this->content]);
return $dataProvider;
}
示例8: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::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, 'section_id' => $this->section_id, 'parent' => $this->parent, 'status' => $this->status, 'thumbsup' => $this->thumbsup, 'thumbsdown' => $this->thumbsdown, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
$query->andFilterWhere(['like', 'content', $this->content]);
return $dataProvider;
}
示例9: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::find()->orderBy('id DESC');
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
$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(['id' => $this->id, 'post_id' => $this->post_id, 'parent_id' => $this->parent_id, 'thumbsup' => $this->thumbsup, 'thumbsdown' => $this->thumbsdown, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
$query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email]);
return $dataProvider;
}
示例10: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::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(['id' => $this->id, 'article_id' => $this->article_id]);
$query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'comment', $this->comment]);
return $dataProvider;
}
示例11: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::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(['id' => $this->id, 'status' => $this->status, 'create_time' => $this->create_time, 'post_id' => $this->post_id]);
$query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url]);
return $dataProvider;
}
示例12: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Comment::find();
$dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
$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(['id' => $this->id, 'is_active' => $this->is_active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
$query->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'user_email', $this->user_email]);
return $dataProvider;
}
示例13: actionView
/**
* Displays a single Post model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$list_comment = new ActiveDataProvider(['query' => Comment::find()->where(['post_id' => $id, 'status' => 1])]);
$model_comment = new Comment();
if ($model_comment->load(Yii::$app->request->post())) {
$model_comment->post_id = $id;
$model_comment->status = 0;
if ($model_comment->save()) {
Yii::$app->session->setFlash('success', 'Ваш комментарий был отправлен администраторам сайта и будет опубликован после проверки..');
} else {
Yii::$app->session->setFlash('error', 'Ваш комментарий не был отправлен по техническим причинам. Попробуйте ещё раз.');
}
}
return $this->render('view', ['model' => $this->findModel($id), 'list_comment' => $list_comment, 'model_comment' => $model_comment]);
}
示例14: actionDm
public function actionDm()
{
\Yii::$app->response->format = Response::FORMAT_JSON;
$article_id = \Yii::$app->request->post('article_id');
$time = \Yii::$app->request->post('time');
$page = \Yii::$app->request->post('page');
$query = Comment::find()->where(['article_id' => $article_id]);
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$models = $query->offset($pages->offset)->orderBy('created_at desc')->limit($pages->limit)->with('user')->asArray()->all();
$hasNext = 0;
if ($page < $pages->pageCount) {
$hasNext = 1;
}
return ['list' => $models, 'hasNext' => $hasNext, 'time' => $time];
}
示例15: actionView
public function actionView($id)
{
$model = Article::find()->where(['id' => $id, 'status' => Article::STATUS_ACTIVE])->one();
if ($model === null) {
throw new NotFoundHttpException('not found');
}
// 浏览量变化
$model->addView();
$commentModel = new Comment();
$commentQuery = Comment::find()->where(['article_id' => $id, 'parent_id' => 0]);
$countCommentQuery = clone $commentQuery;
$pages = new Pagination(['totalCount' => $countCommentQuery->count()]);
$commentModels = $commentQuery->offset($pages->offset)->orderBy('created_at desc')->limit($pages->limit)->all();
$hots = Article::find()->where(['category_id' => $model->category_id])->limit(10)->orderBy('view desc')->all();
return $this->render('view', ['model' => $model, 'commentModel' => $commentModel, 'commentModels' => $commentModels, 'pages' => $pages, 'hots' => $hots]);
}