original_string: public static function add_contact(int $userid, int $contactid) {
          global $DB;
  
          $messagecontact = new \stdClass();
          $messagecontact->userid = $userid;
          $messagecontact->contactid = $contactid;
          $messagecontact->timecreated = time();
          $messagecontact->id = $DB->insert_record('message_contacts', $messagecontact);
  
          $eventparams = [
              'objectid' => $messagecontact->id,
              'userid' => $userid,
              'relateduserid' => $contactid,
              'context' => \context_user::instance($userid)
          ];
          $event = \core\event\message_contact_added::create($eventparams);
          $event->add_record_snapshot('message_contacts', $messagecontact);
          $event->trigger();
      }
code: public static function add_contact(int $userid, int $contactid) {
          global $DB;
  
          $messagecontact = new \stdClass();
          $messagecontact->userid = $userid;
          $messagecontact->contactid = $contactid;
          $messagecontact->timecreated = time();
          $messagecontact->id = $DB->insert_record('message_contacts', $messagecontact);
  
          $eventparams = [
              'objectid' => $messagecontact->id,
              'userid' => $userid,
              'relateduserid' => $contactid,
              'context' => \context_user::instance($userid)
          ];
          $event = \core\event\message_contact_added::create($eventparams);
          $event->add_record_snapshot('message_contacts', $messagecontact);
          $event->trigger();
      }
code_tokens: public static function add_contact ( int $ userid , int $ contactid ) { global $ DB ; $ messagecontact = new \ stdClass ( ) ; $ messagecontact -> userid = $ userid ; $ messagecontact -> contactid = $ contactid ; $ messagecontact -> timecreated = time ( ) ; $ messagecontact -> id = $ DB -> insert_record ( 'message_contacts' , $ messagecontact ) ; $ eventparams = [ 'objectid' => $ messagecontact -> id , 'userid' => $ userid , 'relateduserid' => $ contactid , 'context' => \ context_user :: instance ( $ userid ) ] ; $ event = \ core \ event \ message_contact_added :: create ( $ eventparams ) ; $ event -> add_record_snapshot ( 'message_contacts' , $ messagecontact ) ; $ event -> trigger ( ) ; }
docstring: Handles adding a contact.
  
  @param int $userid The id of the user who requested to be a contact
  @param int $contactid The id of the contact
docstring_tokens: Handles adding a contact .