poster_id and core.submit_post_end event

Discussion forum for Extension Writers regarding Extension Development.
User avatar
caiocald
Registered User
Posts: 214
Joined: Mon Feb 26, 2018 9:32 pm
Name: B!

poster_id and core.submit_post_end event

Post by caiocald »

Hello friends

I'm adding a function for "text evaluation" for new topics in a certain section of my forum dedicated to writing.

When submitting a new text (new topic in this session), a response will be given with the evaluation of that text.

Everything is apparently working, the only thing I couldn't do was set the poster_id

When a user creates a new topic, the response given comes with the same poster_id as the topic creator when it should come with poster_id = 60 according to the code.

Something appears to be overwriting the poster_id

Am I using the correct event for this?

Code: Select all


	public static function getSubscribedEvents()
    {
        return [
            'core.submit_post_end' => 'reply_avaliator',
        ];
    }

    public function reply_avaliator($event)
    {
        $data = $event->get_data();
        $forum_id = (int) $data['data']['forum_id'];
        $post_mode = $data['mode'];
        $usergroup = (int) $this->user->data['group_id'];
        $this->new_reply($forum_id, $topic_id, $post_title, $response);
    }

    public function new_reply($forum_id, $topic_id, $post_title, $response)
    {
        $reply_data = [
            'forum_id'      => $forum_id,
            'topic_id'      => $topic_id,
            'topic_title'   => $post_title,
            'message'       => $response,
            'poster_id'     => 60, 
        ];

        $poll_ary = null; 

        submit_post('reply', $post_title, '', POST_NORMAL, $poll_ary, $reply_data);
    }
    
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 4030
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: poster_id and core.submit_post_end event

Post by Kailey »

Haven't tested, but I'm guessing it's because you've blanked out $username in your submit_post() call. Have you tried entering the escaped username of id 60?
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 28950
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier

Re: poster_id and core.submit_post_end event

Post by Paul »

Submit post will always use the current $user object as poster. You will temporary need to overwrige that. If you search in this forum there are multiple examples on that.

Return to “Extension Writers Discussion”