Returns all forums.
767986
def _get_all_forums(self):
        
        if not hasattr(self, '_all_forums'):
            self._all_forums = list(Forum.objects.all())
        return self._all_forums
441873
def get_perms(self, forum):
        
        # An inactive user has no permissions.
        if not self.user.is_anonymous and not self.user.is_active:
            return []

        user_model = get_user_model()
        user_groups_related_name = user_model.groups.field.related_query_name()

        if forum.id not in self._forum_perms_cache:
            if self.user and self.user.is_superuser:
                # The superuser has all the permissions.
                perms = list(ForumPermission.objects.values_list('codename', flat=True))
            elif self.user:
                default_auth_forum_perms = (
                    machina_settings.DEFAULT_AUTHENTICATED_USER_FORUM_PERMISSIONS
                )

                user_kwargs_filter = (
                    {'anonymous_user': True} if self.user.is_anonymous
                    else {'user': self.user}
                )

                # Fetches the permissions of the considered user for the given forum.
                user_perms = (
                    UserForumPermission.objects.select_related()
                    .filter(**user_kwargs_filter)
                    .filter(Q(forum__isnull=True) | Q(forum=forum))
                )

                # Computes the list of permissions that are granted for all the forums.
                globally_granted_user_perms = list(
                    filter(lambda p: p.has_perm and p.forum_id is None, user_perms)
                )
                globally_granted_user_perms = [
                    p.permission.codename for p in globally_granted_user_perms
                ]

                # Computes the list of permissions that are granted on a per-forum basis.
                per_forum_granted_user_perms = list(
                    filter(lambda p: p.has_perm and p.forum_id is not None, user_perms)
                )
                per_forum_granted_user_perms = [
                    p.permission.codename for p in per_forum_granted_user_perms
                ]

                # Computes the list of permissions that are not granted on a per-forum basis.
                per_forum_nongranted_user_perms = list(
                    filter(lambda p: not p.has_perm and p.forum_id is not None, user_perms)
                )
                per_forum_nongranted_user_perms = [
                    p.permission.codename for p in per_forum_nongranted_user_perms
                ]

                # If the considered user have no global permissions, the permissions defined by the
                # DEFAULT_AUTHENTICATED_USER_FORUM_PERMISSIONS settings are used instead.
                if self.user.is_authenticated and not globally_granted_user_perms:
                    globally_granted_user_perms = default_auth_forum_perms

                # Finally computes the list of permission codenames that are granted to the user for
                # the considered forum.
                granted_user_perms = [
                    c for c in globally_granted_user_perms if
                    c not in per_forum_nongranted_user_perms
                ]
                granted_user_perms += per_forum_granted_user_perms
                granted_user_perms = set(granted_user_perms)

                perms = granted_user_perms

                # If the user is a registered user, we have to check the permissions of its groups
                # in order to determine the additional permissions they could have.
                if not self.user.is_anonymous:
                    group_perms = (
                        GroupForumPermission.objects.select_related()
                        .filter(**{'group__{}'.format(user_groups_related_name): self.user})
                        .filter(Q(forum__isnull=True) | Q(forum=forum))
                    )

                    globally_granted_group_perms = list(
                        filter(lambda p: p.has_perm and p.forum_id is None, group_perms)
                    )
                    globally_granted_group_perms = [
                        p.permission.codename for p in globally_granted_group_perms
                    ]

                    per_forum_granted_group_perms = list(
                        filter(lambda p: p.has_perm and p.forum_id is not None, group_perms)
                    )
                    per_forum_granted_group_perms = [
                        p.permission.codename for p in per_forum_granted_group_perms
                    ]

                    per_forum_nongranted_group_perms = list(
                        filter(lambda p: not p.has_perm and p.forum_id is not None, group_perms)
                    )
                    per_forum_nongranted_group_perms = [
                        p.permission.codename for p in per_forum_nongranted_group_perms
                    ]

                    granted_group_perms = [
                        c for c in globally_granted_group_perms if
                        c not in per_forum_nongranted_group_perms
                    ]
                    granted_group_perms += per_forum_granted_group_perms
                    granted_group_perms = filter(
                        lambda x: x not in per_forum_nongranted_user_perms, granted_group_perms
                    )
                    granted_group_perms = set(granted_group_perms)

                    # Includes the permissions granted for the user' groups in the initial set of
                    # permission codenames.
                    perms |= granted_group_perms

            self._forum_perms_cache[forum.id] = perms

        return self._forum_perms_cache[forum.id]
877446
private function get_forum_record() : stdClass {
        $forumdbdatamapper = $this->related['legacydatamapperfactory']->get_forum_data_mapper();
        return $forumdbdatamapper->to_legacy_object($this->forum);
    }
1333080
def get_post(self):
        
        pk = self.kwargs.get(self.post_pk_url_kwarg, None)
        if not pk:
            return
        if not hasattr(self, '_forum_post'):
            self._forum_post = get_object_or_404(Post, pk=pk)
        return self._forum_post
1151708
def all(self, res):
        ""
        B = get_backend()
        return B.get_objects(B.get_concrete(res))
451928
def from_forums(cls, forums):
        
        root_level = None
        current_path = []
        nodes = []

        # Ensures forums last posts and related poster relations are "followed" for better
        # performance (only if we're considering a queryset).
        forums = (
            forums.select_related('last_post', 'last_post__poster')
            if isinstance(forums, QuerySet) else forums
        )

        for forum in forums:
            level = forum.level

            # Set the root level to the top node level at the first iteration.
            if root_level is None:
                root_level = level

            # Initializes a visibility forum node associated with current forum instance.
            vcontent_node = ForumVisibilityContentNode(forum)

            # Computes a relative level associated to the node.
            relative_level = level - root_level
            vcontent_node.relative_level = relative_level

            # All children nodes will be stored in an array attached to the current node.
            vcontent_node.children = []

            # Removes the forum that are not in the current branch.
            while len(current_path) > relative_level:
                current_path.pop(-1)

            if level != root_level:
                # Update the parent of the current forum.
                parent_node = current_path[-1]
                vcontent_node.parent = parent_node
                parent_node.children.append(vcontent_node)

            # Sets visible flag if applicable. The visible flag is used to determine whether a forum
            # can be seen in a forum list or not. A forum can be seen if one of the following
            # statements is true:
            #
            # * the forum is a direct child of the starting forum for the considered level
            # * the forum have a parent which is a category and this category is a direct child of
            #   the starting forum
            # * the forum have its 'display_sub_forum_list' option set to True and have a parent
            #   which is another forum. The latter is a direct child of the starting forum
            # * the forum have its 'display_sub_forum_list' option set to True and have a parent
            #   which is another forum. The later have a parent which is a category and this
            #   category is a direct child of the starting forum
            #
            # If forums at the root level don't have parents, the visible forums are those that can
            # be seen from the root of the forums tree.
            vcontent_node.visible = (
                (relative_level == 0) or
                (forum.display_sub_forum_list and relative_level == 1) or
                (forum.is_category and relative_level == 1) or
                (
                    relative_level == 2 and
                    vcontent_node.parent.parent.obj.is_category and
                    vcontent_node.parent.obj.is_forum
                )
            )

            # Add the current forum to the end of the current branch and inserts the node inside the
            # final node dictionary.
            current_path.append(vcontent_node)
            nodes.append(vcontent_node)

        tree = cls(nodes=nodes)
        for node in tree.nodes:
            node.tree = tree

        return tree
1161592
public function getThreadCount()
    {
        try {
            $result = DB::select('SELECT COUNT(*) as count FROM `forum_posts` where forum_id = ?', [$this->id]);
            return $result[0]->count;
        } catch (\Exception $e) {
            return 0;
        }
    }
535899
@Override
	public List<CPInstance> findAll() {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}
565479
public function to_legacy_objects(array $forums) : array {
        return array_map(function(forum_entity $forum) {
            return (object) [
                'id' => $forum->get_id(),
                'course' => $forum->get_course_id(),
                'type' => $forum->get_type(),
                'name' => $forum->get_name(),
                'intro' => $forum->get_intro(),
                'introformat' => $forum->get_intro_format(),
                'assessed' => $forum->get_rating_aggregate(),
                'assesstimestart' => $forum->get_assess_time_start(),
                'assesstimefinish' => $forum->get_assess_time_finish(),
                'scale' => $forum->get_scale(),
                'maxbytes' => $forum->get_max_bytes(),
                'maxattachments' => $forum->get_max_attachments(),
                'forcesubscribe' => $forum->get_subscription_mode(),
                'trackingtype' => $forum->get_tracking_type(),
                'rsstype' => $forum->get_rss_type(),
                'rssarticles' => $forum->get_rss_articles(),
                'timemodified' => $forum->get_time_modified(),
                'warnafter' => $forum->get_warn_after(),
                'blockafter' => $forum->get_block_after(),
                'blockperiod' => $forum->get_block_period(),
                'completiondiscussions' => $forum->get_completion_discussions(),
                'completionreplies' => $forum->get_completion_replies(),
                'completionposts' => $forum->get_completion_posts(),
                'displaywordcount' => $forum->should_display_word_count(),
                'lockdiscussionafter' => $forum->get_lock_discussions_after(),
                'duedate' => $forum->get_due_date(),
                'cutoffdate' => $forum->get_cutoff_date()
            ];
        }, $forums);
    }
160738
def forum_id(self):
        """"""
        html = self.request(self.team_url).text
        soup = BeautifulSoup(html)
        return soup.find(id='forum_id').attrs['value']
856453
def get_messages(self):
        
        if not self._messages:  # if not already cached
            query = self._dbman.query('thread:' + self._id)
            thread = next(query.search_threads())

            def accumulate(acc, msg):
                M = Message(self._dbman, msg, thread=self)
                acc[M] = []
                r = msg.get_replies()
                if r is not None:
                    for m in r:
                        acc[M].append(accumulate(acc, m))
                return M

            self._messages = {}
            for m in thread.get_toplevel_messages():
                self._toplevel_messages.append(accumulate(self._messages, m))
        return self._messages
827109
def get_queryset(self):
        
        self.topic = self.get_topic()
        qs = (
            self.topic.posts
            .all()
            .exclude(approved=False)
            .select_related('poster', 'updated_by')
            .prefetch_related('attachments', 'poster__forum_profile')
        )
        return qs
785442
def get_urlpatterns(self):
        
        return [
            path(
                _('mark/forums/'),
                self.mark_forums_read_view.as_view(),
                name='mark_all_forums_read',
            ),
            path(
                _('mark/forums/<int:pk>/'),
                self.mark_forums_read_view.as_view(),
                name='mark_subforums_read',
            ),
            path(
                _('mark/forum/<int:pk>/topics/'),
                self.mark_topics_read_view.as_view(),
                name='mark_topics_read',
            ),
            path(
                _('unread-topics/'),
                self.unread_topics_view.as_view(),
                name='unread_topics',
            ),
        ]
1323808
public static function get_forum_discussions_parameters() {
        return new external_function_parameters (
            array(
                'forumid' => new external_value(PARAM_INT, 'forum instance id', VALUE_REQUIRED),
                'sortorder' => new external_value(PARAM_INT,
                    'sort by this element: numreplies, , created or timemodified', VALUE_DEFAULT, -1),
                'page' => new external_value(PARAM_INT, 'current page', VALUE_DEFAULT, -1),
                'perpage' => new external_value(PARAM_INT, 'items per page', VALUE_DEFAULT, 0),
                'groupid' => new external_value(PARAM_INT, 'group id', VALUE_DEFAULT, 0),
            )
        );
    }
968395
def get_top_level_forum_url(self):
        
        return (
            reverse('forum:index') if self.top_level_forum is None else
            reverse(
                'forum:forum',
                kwargs={'slug': self.top_level_forum.slug, 'pk': self.kwargs['pk']},
            )
        )
897199
protected function getThreadForGuests()
    {
        return $this->_query->joinWith([
                'forum' => function ($query) {
                    $query->andWhere([
                            Forum::tableName() . '.visible' => 1
                        ])->joinWith(['category' => function ($query) {
                            $query->andWhere([Category::tableName() . '.visible' => 1]);
                        }]);
                }
            ])->limit(1)->one();
    }
1038119
def get_context_data(self, **kwargs):
        
        context = super(IndexView, self).get_context_data(**kwargs)
        visiblity_content_tree = context['forums']

        # Computes some global values.
        context['total_posts_count'] = sum(n.posts_count for n in visiblity_content_tree.top_nodes)
        context['total_topics_count'] = sum(
            n.topics_count for n in visiblity_content_tree.top_nodes
        )

        return context