本文整理汇总了PHP中common\models\Comment::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::findOne方法的具体用法?PHP Comment::findOne怎么用?PHP Comment::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Comment
的用法示例。
在下文中一共展示了Comment::findOne方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findModel
/**
* Finds the Comment model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Comment the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Comment::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例2: getComment
/**
* Возвращает комментарий.
* @param int $id идентификатор комментария
* @throws NotFoundHttpException
* @return Comment
*/
public function getComment($id)
{
if (($model = Comment::findOne($id)) !== null && $model->isPublished()) {
return $model;
} else {
throw new NotFoundHttpException('The requested post does not exist.');
}
}
示例3: save
public function save()
{
$comment = Comment::findOne($this->commentID);
$comment->setAttributes(['author' => $this->author, 'text' => $this->text, 'email' => $this->email, 'published' => $this->published, 'deleted' => $this->deleted]);
if ($comment->save(false)) {
\Yii::$app->session->setFlash('saved', 'Комментарий сохранён!');
} else {
\Yii::$app->session->setFlash('error', 'Комментарий не сохранён!');
}
}
示例4: actionAlarm
public function actionAlarm()
{
$id = Yii::$app->request->post('id');
$msg = Yii::$app->request->post('msg');
$comment = Comment::findOne($id);
if ($comment && !empty($msg)) {
if (Alarm::addAlarm(Alarm::ENTITY_COMMENT, $comment->id, $msg)) {
return json_encode(['content' => \frontend\widgets\CommentsWidget::widget(['entity' => $comment->entity, 'entity_id' => $comment->entity_id, 'showDialog' => false]), 'anchor' => $comment->id]);
} else {
return json_encode(['content' => '', 'anchor' => '']);
}
}
}
示例5: addVote
public static function addVote($entity, $id, $voteAdd)
{
$user = User::thisUser();
$vote = Vote::findOne(['entity' => $entity, 'entity_id' => $id, 'user_id' => $user->id]);
if (empty($vote)) {
$vote = new Vote();
$vote->entity = $entity;
$vote->entity_id = $id;
$vote->user_id = $user->id;
}
/** @var VoteModel $model */
$model = null;
if ($entity == self::ENTITY_ITEM) {
$model = Item::findOne($id);
if ($user->reputation < Item::MIN_REPUTATION_ITEM_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
} else {
if ($entity == self::ENTITY_EVENT) {
$model = Event::findOne($id);
if ($user->reputation < Event::MIN_REPUTATION_EVENT_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
} else {
if ($entity == self::ENTITY_SCHOOL) {
$model = School::findOne($id);
if ($user->reputation < School::MIN_REPUTATION_SCHOOL_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
} else {
if ($entity == self::ENTITY_COMMENT) {
$model = Comment::findOne($id);
if ($user->reputation < Comment::MIN_REPUTATION_COMMENT_VOTE) {
// Если только пользователь не отменяет свои дизлайки
if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) {
return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')];
}
}
}
}
}
}
if (!empty($model)) {
if ($vote->vote == self::VOTE_UP) {
if ($voteAdd == self::VOTE_UP) {
// убираем up
$vote->vote = self::VOTE_NONE;
$model->addVote(-1);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
} else {
// ставим down
$vote->vote = self::VOTE_DOWN;
$model->addVote(-2);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP);
$model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
}
} elseif ($vote->vote == self::VOTE_DOWN) {
if ($voteAdd == self::VOTE_UP) {
// ставим up
$vote->vote = self::VOTE_UP;
$model->addVote(2);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
$model->addReputation(VoteModel::ADD_REPUTATION_UP);
} else {
// убираем down
$vote->vote = self::VOTE_NONE;
$model->addVote(1);
$model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN);
}
} else {
if ($voteAdd == self::VOTE_UP) {
// ставим up
$vote->vote = self::VOTE_UP;
$model->addVote(1);
$model->addReputation(VoteModel::ADD_REPUTATION_UP);
} else {
// ставим down
$vote->vote = self::VOTE_DOWN;
$model->addVote(-1);
$model->addReputation(VoteModel::ADD_REPUTATION_DOWN);
}
}
}
if ($vote->save()) {
if (!empty($model)) {
$model->save();
}
}
return ['vote' => $vote->vote, 'count' => $model->getVoteCount()];
}
示例6: actionComplain
/**
* Url: /complain/{$id}
* @param int $id Comment id
* @return mixed
* @throws BadRequestHttpException
* @throws NotFoundHttpException
*/
public function actionComplain($id)
{
$comment = Comment::findOne($id);
if (!isset($comment)) {
throw new NotFoundHttpException('Страница не найдена.');
}
if (Yii::$app->user->isGuest) {
throw new BadRequestHttpException('Для отправки жалобы авторизируйтесь.');
}
$claim = Claim::find()->where(['comment_id' => $comment->id, 'user_id' => Yii::$app->user->id])->one();
if (!isset($claim->id)) {
$claim = new Claim();
$claim->comment_id = $comment->id;
$claim->comment_author = $comment->user_id;
$claim->user_id = Yii::$app->user->id;
}
if ($claim->load(Yii::$app->request->post())) {
$claim->save();
}
return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Жалоба на комментарий', 'columnFirst' => ['claim' => ['view' => '@frontend/views/forms/complain_form', 'data' => compact('comment', 'claim')]], 'columnSecond' => ['photo_news' => SiteBlock::getPhotoNews(), 'banner1' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner2' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner3' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner4' => SiteBlock::getBanner(Banner::REGION_NEWS), 'banner5' => SiteBlock::getBanner(Banner::REGION_NEWS)]]);
}