original_string: protected function generate_message($subscriptionid, \stdClass $eventobj) {
  
          try {
              $subscription = subscription_manager::get_subscription($subscriptionid);
          } catch (\dml_exception $e) {
              // Race condition, someone deleted the subscription.
              return false;
          }
          $user = \core_user::get_user($subscription->userid);
          if (empty($user)) {
              // User doesn't exist. Should never happen, nothing to do return.
              return false;
          }
          $context = \context_user::instance($user->id, IGNORE_MISSING);
          if ($context === false) {
              // User context doesn't exist. Should never happen, nothing to do return.
              return false;
          }
  
          $template = $subscription->template;
          $template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
          $htmlmessage = format_text($template, $subscription->templateformat, array('context' => $context));
          $msgdata = new \core\message\message();
          $msgdata->courseid          = empty($subscription->courseid) ? SITEID : $subscription->courseid;
          $msgdata->component         = 'tool_monitor'; // Your component name.
          $msgdata->name              = 'notification'; // This is the message name from messages.php.
          $msgdata->userfrom          = \core_user::get_noreply_user();
          $msgdata->userto            = $user;
          $msgdata->subject           = $subscription->get_name($context);
          $msgdata->fullmessage       = html_to_text($htmlmessage);
          $msgdata->fullmessageformat = FORMAT_PLAIN;
          $msgdata->fullmessagehtml   = $htmlmessage;
          $msgdata->smallmessage      = '';
          $msgdata->notification      = 1; // This is only set to 0 for personal messages between users.
  
          return $msgdata;
      }
code: protected function generate_message($subscriptionid, \stdClass $eventobj) {
  
          try {
              $subscription = subscription_manager::get_subscription($subscriptionid);
          } catch (\dml_exception $e) {
              // Race condition, someone deleted the subscription.
              return false;
          }
          $user = \core_user::get_user($subscription->userid);
          if (empty($user)) {
              // User doesn't exist. Should never happen, nothing to do return.
              return false;
          }
          $context = \context_user::instance($user->id, IGNORE_MISSING);
          if ($context === false) {
              // User context doesn't exist. Should never happen, nothing to do return.
              return false;
          }
  
          $template = $subscription->template;
          $template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
          $htmlmessage = format_text($template, $subscription->templateformat, array('context' => $context));
          $msgdata = new \core\message\message();
          $msgdata->courseid          = empty($subscription->courseid) ? SITEID : $subscription->courseid;
          $msgdata->component         = 'tool_monitor'; // Your component name.
          $msgdata->name              = 'notification'; // This is the message name from messages.php.
          $msgdata->userfrom          = \core_user::get_noreply_user();
          $msgdata->userto            = $user;
          $msgdata->subject           = $subscription->get_name($context);
          $msgdata->fullmessage       = html_to_text($htmlmessage);
          $msgdata->fullmessageformat = FORMAT_PLAIN;
          $msgdata->fullmessagehtml   = $htmlmessage;
          $msgdata->smallmessage      = '';
          $msgdata->notification      = 1; // This is only set to 0 for personal messages between users.
  
          return $msgdata;
      }
code_tokens: protected function generate_message ( $ subscriptionid , \ stdClass $ eventobj ) { try { $ subscription = subscription_manager :: get_subscription ( $ subscriptionid ) ; } catch ( \ dml_exception $ e ) { // Race condition, someone deleted the subscription. return false ; } $ user = \ core_user :: get_user ( $ subscription -> userid ) ; if ( empty ( $ user ) ) { // User doesn't exist. Should never happen, nothing to do return. return false ; } $ context = \ context_user :: instance ( $ user -> id , IGNORE_MISSING ) ; if ( $ context === false ) { // User context doesn't exist. Should never happen, nothing to do return. return false ; } $ template = $ subscription -> template ; $ template = $ this -> replace_placeholders ( $ template , $ subscription , $ eventobj , $ context ) ; $ htmlmessage = format_text ( $ template , $ subscription -> templateformat , array ( 'context' => $ context ) ) ; $ msgdata = new \ core \ message \ message ( ) ; $ msgdata -> courseid = empty ( $ subscription -> courseid ) ? SITEID : $ subscription -> courseid ; $ msgdata -> component = 'tool_monitor' ; // Your component name. $ msgdata -> name = 'notification' ; // This is the message name from messages.php. $ msgdata -> userfrom = \ core_user :: get_noreply_user ( ) ; $ msgdata -> userto = $ user ; $ msgdata -> subject = $ subscription -> get_name ( $ context ) ; $ msgdata -> fullmessage = html_to_text ( $ htmlmessage ) ; $ msgdata -> fullmessageformat = FORMAT_PLAIN ; $ msgdata -> fullmessagehtml = $ htmlmessage ; $ msgdata -> smallmessage = '' ; $ msgdata -> notification = 1 ; // This is only set to 0 for personal messages between users. return $ msgdata ; }
docstring: Generates the message object for a give subscription and event.
  
  @param int $subscriptionid Subscription instance
  @param \stdClass $eventobj Event data
  
  @return false|\stdClass message object
docstring_tokens: Generates the message object for a give subscription and event .