Beispiel #1
0
 public function post($title, $body, $user = null)
 {
     if (!Auth::check()) {
         return false;
     }
     if (!$user) {
         $user = Auth::user();
     }
     if ($user->canAccessForum($this->id)) {
         $topic = new ForumTopic();
         $topic->forum_id = $this->id;
         $topic->title = $title;
         $topic->save();
         $post = new ForumPost();
         $post->topic_id = $topic->id;
         $post->body = $body;
         $post->posted_by = $user->id;
         $post->save();
         $topic->first_post = $post->id;
         $topic->save();
         return $topic;
     } else {
         return false;
     }
 }
 /**
  * Создает новую модель Темы форума.
  * Если создание прошло успешно - перенаправляет на просмотр.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new ForumTopic();
     if (($data = Yii::app()->getRequest()->getPost('ForumTopic')) !== null) {
         $model->setAttributes($data);
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('ForumModule.forum', 'Record was created!'));
             $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
         }
     }
     $this->render('create', array('model' => $model));
 }
 function toggleTopicSticky(ForumTopic $topic)
 {
     if (Auth::user()->isStoryteller()) {
         $topic->is_sticky = $topic->is_sticky ? 0 : 1;
         $topic->save();
         return Redirect::to("/forums/topic/{$topic->id}");
     } else {
         return Response::json(["success" => false, "message" => "Unauthorized."]);
     }
 }