public static function block_user(int $userid, int $usertoblockid) {
        global $DB;

        $blocked = new \stdClass();
        $blocked->userid = $userid;
        $blocked->blockeduserid = $usertoblockid;
        $blocked->timecreated = time();
        $blocked->id = $DB->insert_record('message_users_blocked', $blocked);

        // Trigger event for blocking a contact.
        $event = \core\event\message_user_blocked::create(array(
            'objectid' => $blocked->id,
            'userid' => $userid,
            'relateduserid' => $usertoblockid,
            'context' => \context_user::instance($userid)
        ));
        $event->add_record_snapshot('message_users_blocked', $blocked);
        $event->trigger();
    }
public static function block_user(int $userid, int $usertoblockid) {
        global $DB;

        $blocked = new \stdClass();
        $blocked->userid = $userid;
        $blocked->blockeduserid = $usertoblockid;
        $blocked->timecreated = time();
        $blocked->id = $DB->insert_record('message_users_blocked', $blocked);

        // Trigger event for blocking a contact.
        $event = \core\event\message_user_blocked::create(array(
            'objectid' => $blocked->id,
            'userid' => $userid,
            'relateduserid' => $usertoblockid,
            'context' => \context_user::instance($userid)
        ));
        $event->add_record_snapshot('message_users_blocked', $blocked);
        $event->trigger();
    }
public static function block_user ( int $ userid , int $ usertoblockid ) { global $ DB ; $ blocked = new \ stdClass ( ) ; $ blocked -> userid = $ userid ; $ blocked -> blockeduserid = $ usertoblockid ; $ blocked -> timecreated = time ( ) ; $ blocked -> id = $ DB -> insert_record ( 'message_users_blocked' , $ blocked ) ; // Trigger event for blocking a contact. $ event = \ core \ event \ message_user_blocked :: create ( array ( 'objectid' => $ blocked -> id , 'userid' => $ userid , 'relateduserid' => $ usertoblockid , 'context' => \ context_user :: instance ( $ userid ) ) ) ; $ event -> add_record_snapshot ( 'message_users_blocked' , $ blocked ) ; $ event -> trigger ( ) ; }
Handles blocking a user.

@param int $userid The id of the user who is blocking
@param int $usertoblockid The id of the user being blocked
Handles blocking a user .