original_string: public function can_create_discussions(stdClass $user, int $groupid = null) : bool {
          if (isguestuser($user) or !isloggedin()) {
              return false;
          }
  
          if ($this->forum->is_cutoff_date_reached()) {
              if (!has_capability('mod/forum:canoverridecutoff', $this->get_context())) {
                  return false;
              }
          }
  
          switch ($this->forum->get_type()) {
              case 'news':
                  $capability = 'mod/forum:addnews';
                  break;
              case 'qanda':
                  $capability = 'mod/forum:addquestion';
                  break;
              default:
                  $capability = 'mod/forum:startdiscussion';
          }
  
          if (!has_capability($capability, $this->forum->get_context(), $user)) {
              return false;
          }
  
          if ($this->forum->get_type() == 'eachuser') {
              if (forum_user_has_posted_discussion($this->forum->get_id(), $user->id, $groupid)) {
                  return false;
              }
          }
  
          if ($this->forum->is_in_group_mode()) {
              return $groupid ? $this->can_access_group($user, $groupid) : $this->can_access_all_groups($user);
          } else {
              return true;
          }
      }
code: public function can_create_discussions(stdClass $user, int $groupid = null) : bool {
          if (isguestuser($user) or !isloggedin()) {
              return false;
          }
  
          if ($this->forum->is_cutoff_date_reached()) {
              if (!has_capability('mod/forum:canoverridecutoff', $this->get_context())) {
                  return false;
              }
          }
  
          switch ($this->forum->get_type()) {
              case 'news':
                  $capability = 'mod/forum:addnews';
                  break;
              case 'qanda':
                  $capability = 'mod/forum:addquestion';
                  break;
              default:
                  $capability = 'mod/forum:startdiscussion';
          }
  
          if (!has_capability($capability, $this->forum->get_context(), $user)) {
              return false;
          }
  
          if ($this->forum->get_type() == 'eachuser') {
              if (forum_user_has_posted_discussion($this->forum->get_id(), $user->id, $groupid)) {
                  return false;
              }
          }
  
          if ($this->forum->is_in_group_mode()) {
              return $groupid ? $this->can_access_group($user, $groupid) : $this->can_access_all_groups($user);
          } else {
              return true;
          }
      }
code_tokens: public function can_create_discussions ( stdClass $ user , int $ groupid = null ) : bool { if ( isguestuser ( $ user ) or ! isloggedin ( ) ) { return false ; } if ( $ this -> forum -> is_cutoff_date_reached ( ) ) { if ( ! has_capability ( 'mod/forum:canoverridecutoff' , $ this -> get_context ( ) ) ) { return false ; } } switch ( $ this -> forum -> get_type ( ) ) { case 'news' : $ capability = 'mod/forum:addnews' ; break ; case 'qanda' : $ capability = 'mod/forum:addquestion' ; break ; default : $ capability = 'mod/forum:startdiscussion' ; } if ( ! has_capability ( $ capability , $ this -> forum -> get_context ( ) , $ user ) ) { return false ; } if ( $ this -> forum -> get_type ( ) == 'eachuser' ) { if ( forum_user_has_posted_discussion ( $ this -> forum -> get_id ( ) , $ user -> id , $ groupid ) ) { return false ; } } if ( $ this -> forum -> is_in_group_mode ( ) ) { return $ groupid ? $ this -> can_access_group ( $ user , $ groupid ) : $ this -> can_access_all_groups ( $ user ) ; } else { return true ; } }
docstring: Can the user create discussions in this forum?
  
  @param stdClass $user The user to check
  @param int|null $groupid The current activity group id
  @return bool
docstring_tokens: Can the user create discussions in this forum?