Get the url to view a discussion from a discussion id and post id.

@param int $discussionid The discussion id
@param int $postid The post id
@return moodle_url
10419
public function get_view_post_url_from_post_id(int $discussionid, int $postid) : moodle_url {
        $url = $this->get_discussion_view_url_from_discussion_id($discussionid);
        $url->set_anchor('p' . $postid);
        return $url;
    }
272054
public function get_view_isolated_post_url_from_post(post_entity $post) : moodle_url {
        return $this->get_view_isolated_post_url_from_post_id($post->get_discussion_id(), $post->get_id());
    }
761480
public function get_forum_view_url_from_course_module_id(int $coursemoduleid, ?int $pageno = null,
            ?int $sortorder = null) : moodle_url {

        $url = new moodle_url('/mod/forum/view.php', [
            'id' => $coursemoduleid,
        ]);

        if (null !== $pageno) {
            $url->param('p', $pageno);
        }

        if (null !== $sortorder) {
            $url->param('o', $sortorder);
        }

        return $url;
    }
66687
protected function fill_discussion_cache($discussionids) {
        global $DB;

        if (empty($discussionids)) {
            $this->discussion = [];
        } else {

            $requiredfields = [
                    'id',
                    'groupid',
                    'firstpost',
                    'timestart',
                    'timeend',
                ];

            list($in, $params) = $DB->get_in_or_equal($discussionids);
            $this->discussions = $DB->get_records_select(
                    'forum_discussions', "id $in", $params, '', implode(', ', $requiredfields));
        }
    }
914710
def get_discussion_post(discussion_id, post_id, params = nil)
      raise Error, "Discussion ID is required" unless discussion_id.is_a? Numeric
      raise Error, "Discussion Post ID is required" unless post_id.is_a? Numeric
      get("/#{workroom_check(params)}discussions/#{discussion_id}/discussion_posts/#{post_id}.json")
    end
356626
public static function view_choice($choiceid) {
        global $CFG;

        $params = self::validate_parameters(self::view_choice_parameters(),
                                            array(
                                                'choiceid' => $choiceid
                                            ));
        $warnings = array();

        // Request and permission validation.
        if (!$choice = choice_get_choice($params['choiceid'])) {
            throw new moodle_exception("invalidcoursemodule", "error");
        }
        list($course, $cm) = get_course_and_cm_from_instance($choice, 'choice');

        $context = context_module::instance($cm->id);
        self::validate_context($context);

        // Trigger course_module_viewed event and completion.
        choice_view($choice, $course, $cm, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
704120
public function get(int $conversationId, int $attachmentId): Attachment
    {
        $conversationResource = $this->restClient->getResource(
            Attachment::class,
            sprintf('/v2/conversations/%d/attachments/%d/data', $conversationId, $attachmentId)
        );

        return $conversationResource->getEntity();
    }
897994
protected function forumsEndpoint($id = null)
    {
        return $id === null ? $this->forumsEndpoint : $this->forumsEndpoint . '/' . $id;
    }
1315122
public function getBlogUrl($blogId)
    {
        if (isset($this->blogUrl[$blogId])) {

            return $this->blogUrl[$blogId];

        } else {

            $url = appSetting('url', 'blog-' . $blogId);
            $url = $url ? $url : 'blog/';
            $url = site_url($url);

            $this->blogUrl[$blogId] = $url;

            return $this->blogUrl[$blogId];
        }
    }
13573
public function GetCommentCountSince($DiscussionID, $DateAllViewed) {
		// Only for members
		if(!Gdn::Session()->IsValid()) return;
		
		// Validate DiscussionID
		$DiscussionID = (int) $DiscussionID;
		if (!$DiscussionID)
			throw new Exception('A valid DiscussionID is required in GetCommentCountSince.');
		
		// Get new comment count
		return Gdn::Database()->SQL()
			->From('Comment c')
			->Where('DiscussionID', $DiscussionID)
			->Where('DateInserted >', Gdn_Format::ToDateTime($DateAllViewed))
			->GetCount();
	}
1020025
public function get_from_post_id(int $id) : ?forum_entity {
        $alias = $this->get_table_alias();
        $thistable = new dml_table(self::TABLE, $alias, $alias);
        $coursemoduletable = new dml_table('course_modules', 'cm', 'cm_');
        $coursetable = new dml_table('course', 'c', 'c_');

        $tablefields = $thistable->get_field_select();
        $coursemodulefields = $coursemoduletable->get_field_select();
        $coursefields = $coursetable->get_field_select();

        $fields = implode(', ', [
            $tablefields,
            context_helper::get_preload_record_columns_sql('ctx'),
            $coursemodulefields,
            $coursefields,
        ]);

        $tables = "{forum_posts} p";
        $tables .= " JOIN {forum_discussions} d ON d.id = p.discussion";
        $tables .= ' JOIN {' . self::TABLE . "} {$alias} ON {$alias}.id = d.forum";
        $tables .= " JOIN {modules} m ON m.name = 'forum'";
        $tables .= " JOIN {course_modules} cm ON cm.module = m.id AND cm.instance = {$alias}.id";
        $tables .= ' JOIN {context} ctx ON ctx.contextlevel = ' . CONTEXT_MODULE .  ' AND ctx.instanceid = cm.id';
        $tables .= " JOIN {course} c ON c.id = {$alias}.course";

        $sql = "SELECT {$fields} FROM {$tables} WHERE p.id = :postid";
        $records = $this->get_db()->get_records_sql($sql, [
            'postid' => $id,
        ]);

        $records = $this->transform_db_records_to_entities($records);
        return count($records) ? array_shift($records) : null;
    }
732448
public function GetID($ConversationID, $ViewingUserID = FALSE) {
      // Get the conversation.
      $Conversation = $this->GetWhere(array('ConversationID' => $ConversationID))->FirstRow(DATASET_TYPE_ARRAY);

      if ($ViewingUserID) {
         $Data = $this->SQL->GetWhere(
            'UserConversation',
            array('ConversationID' => $ConversationID, 'UserID' => $ViewingUserID))
            ->FirstRow(DATASET_TYPE_ARRAY);

         // Convert the array.
         $UserConversation = ArrayTranslate($Data, array('LastMessageID', 'CountReadMessages', 'DateLastViewed', 'Bookmarked'));
         $UserConversation['CountNewMessages'] = $Conversation['CountMessages'] - $Data['CountReadMessages'];
      } else {
         $UserConversation = array('CountNewMessages' => 0, 'CountReadMessages' => $Conversation['CountMessages'], 'DateLastViewed' => $Conversation['DateUpdated']);
      }
      $Conversation = array_merge($Conversation, $UserConversation);
      return (object)$Conversation;
   }
133231
public function removeComment($id, $commentId)
    {
        return $this->delete($this->getPath($id).'/comments/'.rawurlencode($commentId));
    }
374533
protected static function get_subcontext($forum, $discussion = null, $post = null) {
        $subcontext = [];
        if (null !== $discussion) {
            $subcontext += self::get_discussion_area($discussion);

            if (null !== $post) {
                $subcontext[] = get_string('posts', 'mod_forum');
                $subcontext = array_merge($subcontext, static::get_post_area_for_parent($post));
            }
        }

        return $subcontext;

    }
550502
public static function view_wiki($wikiid) {

        $params = self::validate_parameters(self::view_wiki_parameters(),
                                            array(
                                                'wikiid' => $wikiid
                                            ));
        $warnings = array();

        // Get wiki instance.
        if (!$wiki = wiki_get_wiki($params['wikiid'])) {
            throw new moodle_exception('incorrectwikiid', 'wiki');
        }

        // Permission validation.
        list($course, $cm) = get_course_and_cm_from_instance($wiki, 'wiki');
        $context = context_module::instance($cm->id);
        self::validate_context($context);

        // Check if user can view this wiki.
        // We don't use wiki_user_can_view because it requires to have a valid subwiki for the user.
        if (!has_capability('mod/wiki:viewpage', $context)) {
            throw new moodle_exception('cannotviewpage', 'wiki');
        }

        // Trigger course_module_viewed event and completion.
        wiki_view($wiki, $course, $cm, $context);

        $result = array();
        $result['status'] = true;
        $result['warnings'] = $warnings;
        return $result;
    }
113557
public function addComment($postId, $comment)
	{
		$token = $this->oauth->getToken();

		// Set parameters.
		$parameters = array(
			'oauth_token' => $token['key'],
		);

		// Set the success response code.
		$this->oauth->setOption('success_code', 201);

		// Set the API base
		$base = '/v1/posts/' . $postId . '/comments';

		// Build xml.
		$xml = '<comment><text>' . $comment . '</text></comment>';

		// Build the request path.
		$path = $this->getOption('api.url') . $base;

		$header['Content-Type'] = 'text/xml';

		// Send the request.
		$response = $this->oauth->oauthRequest($path, 'POST', $parameters, $xml, $header);

		// Return the comment id.
		$response = explode('comments/', $response->headers['Location']);

		return $response[1];
	}
853612
public function getPostLink($topic_id, $closed, $post_replies, $is_admmod)
    {
        $closed = Container::get('hooks')
            ->fire('model.topic.getPostLinkStart', $closed, $topic_id, $post_replies, $is_admmod);

        if ($closed == '0') {
            if (($post_replies == '' && User::get()->g_post_replies == '1') || $post_replies == '1' || $is_admmod) {
                $post_link = "\t\t\t".'<p class="postlink conr"><a class="btn btn-primary btn-sm" href="'.
                    Router::pathFor('newReply', ['tid' => $topic_id]).'">'.__('Post reply').'</a></p>'."\n";
            } else {
                $post_link = '';
            }
        } else {
            $post_link = __('Topic closed');

            if ($is_admmod) {
                $post_link .= ' / <a class="btn btn-primary btn-sm" href="'.
                    Router::pathFor('newReply', ['tid' => $topic_id]).'">'. __('Post reply').'</a>';
            }

            $post_link = "\t\t\t".'<p class="postlink conr">'.$post_link.'</p>'."\n";
        }

        $post_link = Container::get('hooks')
            ->fire('model.topic.getPostLinkFinish', $post_link, $topic_id, $closed, $post_replies, $is_admmod);

        return $post_link;
    }