Skip to content

Commit

Permalink
Добавлена корректный репорт, если к этому блогу пользователь
Browse files Browse the repository at this point in the history
присоединен + small fix
  • Loading branch information
adminnu committed Aug 21, 2012
1 parent a9a3fd0 commit 7a94bbe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 14 additions & 4 deletions protected/modules/blog/controllers/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function actionPosts($slug)
}

// "вступление" в блог
public function actionJoin()
public function actionJoin($blogId)
{
if(!Yii::app()->user->isAuthenticated())
{
Expand All @@ -73,10 +73,10 @@ public function actionJoin()
$this->redirect(array('/'));
}
}

$errorMessage = false;

$blogId = $_GET['blogId'];
$blogId = (int) $blogId;

if(!$blogId)
$errorMessage = Yii::t('blog', 'Не передан blogId!');
Expand Down Expand Up @@ -104,8 +104,18 @@ public function actionJoin()
else
{
Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('blog', 'Вы присоединились к блогу!'));
$this->redirect(array('/blog/blog/show/', 'slug' => $blog->slug));
$this->redirect(array('/blog/blog/index/'));
}
}
else
{
if(Yii::app()->request->isAjaxRequest)
Yii::app()->ajax->success(Yii::t('blog', 'Вы уже присоеденены к этому блогу!'));
else
{
Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('blog', 'Вы уже присоеденены к этому блогу!'));
$this->redirect(array('/blog/blog/index/'));
}
}
}
}
15 changes: 11 additions & 4 deletions protected/modules/blog/models/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,19 @@ public function join($userId)
{
$userToBlog = new UserToBlog;

$userToBlog->setAttributes(array(
if(!$userToBlog->find('user_id = :user_id AND blog_id = :blog_id', array(
'user_id' => Yii::app()->user->getId(),
'blog_id' => $this->id,
));

return $userToBlog->save();
)))
{
$userToBlog->setAttributes(array(
'user_id' => Yii::app()->user->getId(),
'blog_id' => $this->id,
));

return $userToBlog->save();
}
return false;
}

public function getMembers()
Expand Down

0 comments on commit 7a94bbe

Please sign in to comment.