Beispiel #1
0
 /**
  * @param Request $request
  * @param $matches
  * @return mixed
  */
 public function new_topic(Request $request, $matches)
 {
     if ($access = $this->authenticated_only()) {
         return $access;
     }
     $subject = $matches->get('id');
     $subject = \Forum::find($subject);
     if (!$subject || !$subject->forum_id) {
         return $this->error404($request);
     }
     if ($request->isMethod('post') && $this->user->can('write_forum')) {
         $data = ['description' => trim($request->get('edit')), 'title' => trim($request->get('title')), 'author_id' => $this->user->id, 'forum_id' => $subject->id];
         $this->view->assign('data', $data);
         $errors = [];
         if (strlen($data['title']) < 3) {
             $errors[] = $this->lang->translate('forum.topic.title_len');
         }
         if (strlen($data['description']) < 3) {
             $errors[] = $this->lang->translate('forum.topic.body_len');
         }
         if (count($errors)) {
             $this->view->assign('errors', $errors);
         } else {
             $topic = new \ForumTheme($data);
             if ($topic->save()) {
                 /** @var Ping $ping */
                 $ping = NCService::load('SocialMedia.Ping');
                 return static::redirect_response($this->map->reverse('topic', ['id' => $topic->id]));
             } else {
                 $this->view->assign('errors', [$this->lang->translate('forum.topic.new_failed')]);
             }
         }
     }
     return $this->view->render('forum/create.twig', ['title' => $this->lang->translate('forum.topic.new'), 'subject' => $subject->to_array()]);
 }