protected function get_other_values(renderer_base $output)
 {
     $result = new stdClass();
     if ($this->persistent->get_grade() === null) {
         $gradename = '-';
     } else {
         $gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1];
     }
     $result->gradename = $gradename;
     if ($this->persistent->get_proficiency() === null) {
         $proficiencyname = get_string('no');
     } else {
         $proficiencyname = get_string($this->persistent->get_proficiency() ? 'yes' : 'no');
     }
     $result->proficiencyname = $proficiencyname;
     $statusname = '-';
     if ($this->persistent->get_status() != user_competency::STATUS_IDLE) {
         $statusname = (string) user_competency::get_status_name($this->persistent->get_status());
     }
     $result->statusname = $statusname;
     $result->canrequestreview = $this->persistent->can_request_review();
     $result->canreview = $this->persistent->can_review();
     $result->isstatusidle = $this->persistent->get_status() == user_competency::STATUS_IDLE;
     $result->isstatusinreview = $this->persistent->get_status() == user_competency::STATUS_IN_REVIEW;
     $result->isstatuswaitingforreview = $this->persistent->get_status() == user_competency::STATUS_WAITING_FOR_REVIEW;
     $result->isrequestreviewallowed = $result->canrequestreview && $result->isstatusidle;
     $result->iscancelreviewrequestallowed = $result->canrequestreview && $result->isstatuswaitingforreview;
     $result->isstartreviewallowed = $result->canreview && $result->isstatuswaitingforreview;
     $result->isstopreviewallowed = $result->canreview && $result->isstatusinreview;
     if (!empty($result->isstatusinreview)) {
         // TODO Make this more efficient.
         $userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get_reviewerid(), '*', MUST_EXIST));
         $result->reviewer = $userexporter->export($output);
     }
     $result->url = url::user_competency($this->persistent->get_id())->out(false);
     return (array) $result;
 }
 /**
  * Returns relevant URL.
  *
  * @return \moodle_url
  */
 public function get_url()
 {
     return \core_competency\url::template($this->objectid, $this->contextid);
 }
Esempio n. 3
0
 /**
  * Commenting on a plan.
  */
 public function test_comment_add_plan()
 {
     $this->resetAfterTest();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $u1 = $dg->create_user();
     $u2 = $dg->create_user();
     $u3 = $dg->create_user();
     $userroleid = $dg->create_role();
     $reviewerroleid = $dg->create_role();
     assign_capability('moodle/competency:planviewowndraft', CAP_ALLOW, $userroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:planviewown', CAP_ALLOW, $userroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:planviewdraft', CAP_ALLOW, $reviewerroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:planmanage', CAP_ALLOW, $reviewerroleid, context_system::instance()->id, true);
     assign_capability('moodle/competency:plancomment', CAP_ALLOW, $reviewerroleid, context_system::instance()->id, true);
     $dg->role_assign($userroleid, $u1->id, context_user::instance($u1->id));
     $dg->role_assign($reviewerroleid, $u2->id, context_user::instance($u1->id));
     $dg->role_assign($reviewerroleid, $u3->id, context_system::instance());
     accesslib_clear_all_caches_for_unit_testing();
     $p1 = $lpg->create_plan(array('userid' => $u1->id));
     // Post a comment in own plan, no reviewer. Nobody is messaged.
     $this->setUser($u1);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(0, $messages);
     // Post a comment in plan as someone else, no reviewer. The owner is messages.
     $this->setUser($u3);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message->useridfrom);
     $this->assertEquals($u1->id, $message->useridto);
     // Post a comment in a plan with reviewer. The reviewer is messaged.
     $p1->set_reviewerid($u2->id);
     $p1->update();
     $this->setUser($u1);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message->useridfrom);
     $this->assertEquals($u2->id, $message->useridto);
     // Post a comment as reviewer in a plan being reviewed. The owner is messaged.
     $p1->set_reviewerid($u2->id);
     $p1->update();
     $this->setUser($u2);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message->useridfrom);
     $this->assertEquals($u1->id, $message->useridto);
     // Post a comment as someone else in a plan being reviewed. The owner and reviewer are messaged.
     $p1->set_reviewerid($u2->id);
     $p1->update();
     $this->setUser($u3);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(2, $messages);
     $message1 = array_shift($messages);
     $message2 = array_shift($messages);
     $this->assertEquals(core_user::get_noreply_user()->id, $message1->useridfrom);
     $this->assertEquals($u1->id, $message1->useridto);
     $this->assertEquals(core_user::get_noreply_user()->id, $message2->useridfrom);
     $this->assertEquals($u2->id, $message2->useridto);
     $p1->set_reviewerid(null);
     $p1->update();
     // Test message content.
     $this->setUser($u3);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('Hello world!');
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $expectedurlname = $p1->get_name();
     $expectedurl = url::plan($p1->get_id());
     $this->assertTrue(strpos($message->fullmessage, 'Hello world!') !== false);
     $this->assertTrue(strpos($message->fullmessagehtml, 'Hello world!') !== false);
     $this->assertEquals(FORMAT_MOODLE, $message->fullmessageformat);
     $this->assertEquals($expectedurl->out(false), $message->contexturl);
     $this->assertEquals($expectedurlname, $message->contexturlname);
     // Test message content as HTML.
     $this->setUser($u3);
     $comment = $p1->get_comment_object();
     $sink = $this->redirectMessages();
     $comment->add('<em>Hello world!</em>', FORMAT_HTML);
     $messages = $sink->get_messages();
     $sink->close();
     $this->assertCount(1, $messages);
     $message = array_pop($messages);
     $expectedurlname = $p1->get_name();
     $expectedurl = url::plan($p1->get_id());
     $this->assertTrue(strpos($message->fullmessage, '<em>Hello world!</em>') !== false);
     $this->assertTrue(strpos($message->fullmessagehtml, '<em>Hello world!</em>') !== false);
     $this->assertEquals(FORMAT_HTML, $message->fullmessageformat);
     $this->assertEquals($expectedurl->out(false), $message->contexturl);
     $this->assertEquals($expectedurlname, $message->contexturlname);
 }
 /**
  * Get URL related to the action
  *
  * @return \moodle_url
  */
 public function get_url()
 {
     return \core_competency\url::plan($this->objectid);
 }
 /**
  * Get URL related to the action
  *
  * @return \moodle_url
  */
 public function get_url()
 {
     return \core_competency\url::user_competency_in_plan($this->relateduserid, $this->other['competencyid'], $this->other['planid']);
 }
Esempio n. 6
0
 /**
  * Link a user evidence with a competency.
  *
  * @param  user_evidence|int $userevidenceorid User evidence or its ID.
  * @param  int $competencyid Competency ID.
  * @return user_evidence_competency
  */
 public static function create_user_evidence_competency($userevidenceorid, $competencyid)
 {
     global $USER;
     static::require_enabled();
     $userevidence = $userevidenceorid;
     if (!is_object($userevidence)) {
         $userevidence = self::read_user_evidence($userevidence);
     }
     // Perform user evidence capability checks.
     if (!$userevidence->can_manage()) {
         $context = $userevidence->get_context();
         throw new required_capability_exception($context, 'moodle/competency:userevidencemanage', 'nopermissions', '');
     }
     // Perform competency capability checks.
     $competency = self::read_competency($competencyid);
     // Get (and create) the relation.
     $relation = user_evidence_competency::get_relation($userevidence->get_id(), $competency->get_id());
     if (!$relation->get_id()) {
         $relation->create();
         $link = url::user_evidence($userevidence->get_id());
         self::add_evidence($userevidence->get_userid(), $competency, $userevidence->get_context(), evidence::ACTION_LOG, 'evidence_evidenceofpriorlearninglinked', 'core_competency', $userevidence->get_name(), false, $link->out(false), null, $USER->id);
     }
     return $relation;
 }
 /**
  * Returns relevant URL.
  *
  * @return \moodle_url
  */
 public function get_url()
 {
     return \core_competency\url::user_evidence($this->objectid);
 }
 /**
  * Get URL related to the action
  *
  * @return \moodle_url
  */
 public function get_url()
 {
     return \core_competency\url::user_competency_in_course($this->relateduserid, $this->other['competencyid'], $this->courseid);
 }
Esempio n. 9
0
 /**
  * Test evidence_created event.
  */
 public function test_evidence_created()
 {
     global $USER;
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $syscontext = context_system::instance();
     // Create a student.
     $student = $dg->create_user();
     // Create a competency for the course.
     $lpg = $dg->get_plugin_generator('core_competency');
     $framework = $lpg->create_framework();
     $comp = $lpg->create_competency(['competencyframeworkid' => $framework->get_id()]);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     // Add evidence.
     $recommend = false;
     $evidence = api::add_evidence($student->id, $comp, $syscontext, \core_competency\evidence::ACTION_OVERRIDE, 'commentincontext', 'core', null, $recommend, null, 1);
     // Get event.
     $events = $sink->get_events();
     $event = reset($events);
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\competency_evidence_created', $event);
     $this->assertEquals($evidence->get_contextid(), $event->contextid);
     $this->assertEquals($evidence->get_id(), $event->objectid);
     $this->assertEquals($evidence->get_actionuserid(), $event->userid);
     $this->assertEquals($student->id, $event->relateduserid);
     $this->assertEquals($evidence->get_usercompetencyid(), $event->other['usercompetencyid']);
     $this->assertEquals($comp->get_id(), $event->other['competencyid']);
     $this->assertEquals($evidence->get_action(), $event->other['action']);
     $this->assertEquals($recommend, $event->other['recommend']);
     // Test get_name().
     $this->assertEquals(get_string('eventevidencecreated', 'core_competency'), $event->get_name());
     // Test get_description().
     $description = "The user with id '{$USER->id}' created an evidence with id '{$evidence->get_id()}'.";
     $this->assertEquals($description, $event->get_description());
     // Test get_url().
     $url = url::user_competency($evidence->get_usercompetencyid());
     $this->assertEquals($url, $event->get_url());
     // Test get_objectid_mapping().
     $this->assertEquals(\core\event\base::NOT_MAPPED, $event->get_objectid_mapping());
     $this->assertEventContextNotUsed($event);
     $this->assertDebuggingNotCalled();
 }
Esempio n. 10
0
 protected function get_other_values(renderer_base $output)
 {
     $classname = static::define_class();
     $status = $this->persistent->get_status();
     $values = new stdClass();
     $values->statusname = $this->persistent->get_statusname();
     $values->isbasedontemplate = $this->persistent->is_based_on_template();
     $values->canmanage = $this->persistent->can_manage();
     $values->canrequestreview = $this->persistent->can_request_review();
     $values->canreview = $this->persistent->can_review();
     $values->canbeedited = $this->persistent->can_be_edited();
     $values->isactive = $status == $classname::STATUS_ACTIVE;
     $values->isdraft = $status == $classname::STATUS_DRAFT;
     $values->iscompleted = $status == $classname::STATUS_COMPLETE;
     $values->isinreview = $status == $classname::STATUS_IN_REVIEW;
     $values->iswaitingforreview = $status == $classname::STATUS_WAITING_FOR_REVIEW;
     $values->isreopenallowed = $values->canmanage && $values->iscompleted;
     $values->iscompleteallowed = $values->canmanage && $values->isactive;
     $values->isunlinkallowed = $values->canmanage && !$values->iscompleted && $values->isbasedontemplate;
     $values->isrequestreviewallowed = false;
     $values->iscancelreviewrequestallowed = false;
     $values->isstartreviewallowed = false;
     $values->isstopreviewallowed = false;
     $values->isapproveallowed = false;
     $values->isunapproveallowed = false;
     if (!$values->isbasedontemplate) {
         $values->isrequestreviewallowed = $values->canrequestreview && $values->isdraft;
         $values->iscancelreviewrequestallowed = $values->canrequestreview && $values->iswaitingforreview;
         $values->isstartreviewallowed = $values->canreview && $values->iswaitingforreview;
         $values->isstopreviewallowed = $values->canreview && $values->isinreview;
         $values->isapproveallowed = $values->canreview && !$values->iscompleted && !$values->isactive;
         $values->isunapproveallowed = $values->canreview && $values->isactive;
     }
     $values->duedateformatted = userdate($this->persistent->get_duedate());
     if ($this->persistent->is_based_on_template()) {
         $exporter = new template_exporter($this->related['template']);
         $values->template = $exporter->export($output);
     }
     if (!empty($values->isinreview)) {
         // TODO Make this more efficient.
         $userexporter = new user_summary_exporter(core_user::get_user($this->persistent->get_reviewerid(), '*', MUST_EXIST));
         $values->reviewer = $userexporter->export($output);
     }
     $commentareaexporter = new comment_area_exporter($this->persistent->get_comment_object());
     $values->commentarea = $commentareaexporter->export($output);
     $values->url = url::plan($this->persistent->get_id())->out(false);
     return (array) $values;
 }
 /**
  * Returns relevant URL.
  *
  * @return \moodle_url
  */
 public function get_url()
 {
     return \core_competency\url::framework($this->objectid, $this->contextid);
 }
Esempio n. 12
0
 /**
  * Export the data.
  *
  * @param renderer_base $output
  * @return stdClass
  */
 public function export_for_template(\renderer_base $output)
 {
     global $DB;
     $data = new stdClass();
     $missingmappings = $this->processor->get_missing_mappings();
     $data->pagecontextid = $this->pagecontext->id;
     $data->expectedccmigrations = $this->processor->get_expected_course_competency_migrations();
     $data->expectedmcmigrations = $this->processor->get_expected_module_competency_migrations();
     $data->ccmigrationscount = $this->processor->get_course_competency_migrations();
     $data->mcmigrationscount = $this->processor->get_module_competency_migrations();
     $data->ccremovalscount = $this->processor->get_course_competency_removals();
     $data->mcremovalscount = $this->processor->get_module_competency_removals();
     $data->unmappedfrom = array();
     $data->unmappedto = array();
     $exporter = new competency_framework_exporter($this->frameworkfrom);
     $data->frameworkfrom = $exporter->export($output);
     $exporter = new competency_framework_exporter($this->frameworkto);
     $data->frameworkto = $exporter->export($output);
     $fromcontext = $this->frameworkfrom->get_context();
     $tocontext = $this->frameworkto->get_context();
     $compcontext = null;
     foreach ($this->unmappedfrom as $comp) {
         $exporter = new competency_exporter($comp, array('context' => $fromcontext));
         $data->unmappedfrom[] = $exporter->export($output);
     }
     foreach ($this->unmappedto as $comp) {
         $exporter = new competency_exporter($comp, array('context' => $tocontext));
         $data->unmappedto[] = $exporter->export($output);
     }
     $data->coursesfound = $this->processor->get_courses_found_count();
     $data->cmsfound = $this->processor->get_cms_found_count();
     $data->mappingsmissingcount = count($missingmappings);
     $data->hasunmappedto = count($data->unmappedto) > 0;
     $data->hasunmappedfrom = count($data->unmappedfrom) > 0;
     $warnings = $this->processor->get_warnings();
     $data->warnings = array();
     $data->warningcount = count($warnings);
     $errors = $this->processor->get_errors();
     $data->errors = array();
     $data->errorcount = count($errors);
     foreach ($warnings as $warning) {
         $cmcontext = !empty($warning['cmid']) ? context_module::instance($warning['cmid']) : null;
         $coursecontext = context_course::instance($warning['courseid']);
         $warning['cm'] = $cmcontext ? $cmcontext->get_context_name() : null;
         $warning['course'] = $coursecontext->get_context_name();
         $warning['competency'] = $DB->get_field(competency::TABLE, 'idnumber', array('id' => $warning['competencyid']));
         $data->warnings[] = $warning;
     }
     foreach ($errors as $error) {
         $cmcontext = !empty($error['cmid']) ? context_module::instance($error['cmid']) : null;
         $coursecontext = context_course::instance($error['courseid']);
         $error['cm'] = $cmcontext ? $cmcontext->get_context_name() : null;
         $error['course'] = $coursecontext->get_context_name();
         $error['competency'] = $DB->get_field(competency::TABLE, 'idnumber', array('id' => $error['competencyid']));
         $data->errors[] = $error;
     }
     $data->pluginbaseurl = (new moodle_url('/admin/tool/lpmigrate'))->out(false);
     $data->frameworksurl = url::frameworks($this->pagecontext->id)->out(false);
     return $data;
 }
 /**
  * Returns relevant URL.
  *
  * @return \moodle_url
  */
 public function get_url()
 {
     return \core_competency\url::user_competency($this->other['usercompetencyid']);
 }
Esempio n. 14
0
 public function export_for_template(renderer_base $output)
 {
     $plans = array();
     foreach ($this->plans as $plan) {
         if (count($plans) >= 3) {
             break;
         }
         if ($plan->get_status() == plan::STATUS_ACTIVE) {
             $plans[] = $plan;
         }
     }
     $activeplans = array();
     foreach ($plans as $plan) {
         $planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
         $activeplans[] = $planexporter->export($output);
     }
     $compstoreview = array();
     foreach ($this->compstoreview['competencies'] as $compdata) {
         $ucexporter = new user_competency_exporter($compdata->usercompetency, array('scale' => $compdata->competency->get_scale()));
         $compexporter = new competency_exporter($compdata->competency, array('context' => $compdata->competency->get_context()));
         $userexporter = new user_summary_exporter($compdata->user);
         $compstoreview[] = array('usercompetency' => $ucexporter->export($output), 'competency' => $compexporter->export($output), 'user' => $userexporter->export($output));
     }
     $planstoreview = array();
     foreach ($this->planstoreview['plans'] as $plandata) {
         $planexporter = new plan_exporter($plandata->plan, array('template' => $plandata->template));
         $userexporter = new user_summary_exporter($plandata->owner);
         $planstoreview[] = array('plan' => $planexporter->export($output), 'user' => $userexporter->export($output));
     }
     $data = array('hasplans' => !empty($this->plans), 'hasactiveplans' => !empty($activeplans), 'hasmoreplans' => count($this->plans) > count($activeplans), 'activeplans' => $activeplans, 'compstoreview' => $compstoreview, 'hascompstoreview' => $this->compstoreview['count'] > 0, 'hasmorecompstoreview' => $this->compstoreview['count'] > 3, 'planstoreview' => $planstoreview, 'hasplanstoreview' => $this->planstoreview['count'] > 0, 'hasmoreplanstoreview' => $this->planstoreview['count'] > 3, 'plansurl' => url::plans($this->user->id)->out(false), 'pluginbaseurl' => (new \moodle_url('/blocks/lp'))->out(false), 'userid' => $this->user->id);
     return $data;
 }
Esempio n. 15
0
/**
 * Hook when a comment is added.
 *
 * @param  stdClass $comment The comment.
 * @param  stdClass $params The parameters.
 * @return array
 */
function core_competency_comment_add($comment, $params)
{
    global $USER;
    if (!get_config('core_competency', 'enabled')) {
        return;
    }
    if ($params->commentarea == 'user_competency') {
        $uc = new user_competency($params->itemid);
        // Message both the user and the reviewer, except when they are the author of the message.
        $recipients = array($uc->get_userid());
        if ($uc->get_reviewerid()) {
            $recipients[] = $uc->get_reviewerid();
        }
        $recipients = array_diff($recipients, array($comment->userid));
        if (empty($recipients)) {
            return;
        }
        // Get the sender.
        $user = $USER;
        if ($USER->id != $comment->userid) {
            $user = core_user::get_user($comment->userid);
        }
        $fullname = fullname($user);
        // Get the competency.
        $competency = $uc->get_competency();
        $competencyname = format_string($competency->get_shortname(), true, array('context' => $competency->get_context()));
        // We want to send a message for one plan, trying to find an active one first, or the last modified one.
        $plan = null;
        $plans = $uc->get_plans();
        foreach ($plans as $candidate) {
            if ($candidate->get_status() == plan::STATUS_ACTIVE) {
                $plan = $candidate;
                break;
            } else {
                if (!empty($plan) && $plan->get_timemodified() < $candidate->get_timemodified()) {
                    $plan = $candidate;
                } else {
                    if (empty($plan)) {
                        $plan = $candidate;
                    }
                }
            }
        }
        // Urls.
        // TODO MDL-52749 Replace the link to the plan with the user competency page.
        if (empty($plan)) {
            $urlname = get_string('userplans', 'core_competency');
            $url = url::plans($uc->get_userid());
        } else {
            $urlname = $competencyname;
            $url = url::user_competency_in_plan($uc->get_userid(), $uc->get_competencyid(), $plan->get_id());
        }
        // Construct the message content.
        $fullmessagehtml = get_string('usercommentedonacompetencyhtml', 'core_competency', array('fullname' => $fullname, 'competency' => $competencyname, 'comment' => format_text($comment->content, $comment->format, array('context' => $params->context->id)), 'url' => $url->out(true), 'urlname' => $urlname));
        if ($comment->format == FORMAT_PLAIN || $comment->format == FORMAT_MOODLE) {
            $format = FORMAT_MOODLE;
            $fullmessage = get_string('usercommentedonacompetency', 'core_competency', array('fullname' => $fullname, 'competency' => $competencyname, 'comment' => $comment->content, 'url' => $url->out(false)));
        } else {
            $format = FORMAT_HTML;
            $fullmessage = $fullmessagehtml;
        }
        $message = new \core\message\message();
        $message->courseid = SITEID;
        $message->component = 'moodle';
        $message->name = 'competencyusercompcomment';
        $message->notification = 1;
        $message->userfrom = core_user::get_noreply_user();
        $message->subject = get_string('usercommentedonacompetencysubject', 'core_competency', $fullname);
        $message->fullmessage = $fullmessage;
        $message->fullmessageformat = $format;
        $message->fullmessagehtml = $fullmessagehtml;
        $message->smallmessage = get_string('usercommentedonacompetencysmall', 'core_competency', array('fullname' => $fullname, 'competency' => $competencyname));
        $message->contexturl = $url->out(false);
        $message->contexturlname = $urlname;
        // Message each recipient.
        foreach ($recipients as $recipient) {
            $msgcopy = clone $message;
            $msgcopy->userto = $recipient;
            message_send($msgcopy);
        }
    } else {
        if ($params->commentarea == 'plan') {
            $plan = new plan($params->itemid);
            // Message both the user and the reviewer, except when they are the author of the message.
            $recipients = array($plan->get_userid());
            if ($plan->get_reviewerid()) {
                $recipients[] = $plan->get_reviewerid();
            }
            $recipients = array_diff($recipients, array($comment->userid));
            if (empty($recipients)) {
                return;
            }
            // Get the sender.
            $user = $USER;
            if ($USER->id != $comment->userid) {
                $user = core_user::get_user($comment->userid);
            }
            $fullname = fullname($user);
            $planname = format_string($plan->get_name(), true, array('context' => $plan->get_context()));
            $urlname = $planname;
            $url = url::plan($plan->get_id());
            // Construct the message content.
            $fullmessagehtml = get_string('usercommentedonaplanhtml', 'core_competency', array('fullname' => $fullname, 'plan' => $planname, 'comment' => format_text($comment->content, $comment->format, array('context' => $params->context->id)), 'url' => $url->out(true), 'urlname' => $urlname));
            if ($comment->format == FORMAT_PLAIN || $comment->format == FORMAT_MOODLE) {
                $format = FORMAT_MOODLE;
                $fullmessage = get_string('usercommentedonaplan', 'core_competency', array('fullname' => $fullname, 'plan' => $planname, 'comment' => $comment->content, 'url' => $url->out(false)));
            } else {
                $format = FORMAT_HTML;
                $fullmessage = $fullmessagehtml;
            }
            $message = new \core\message\message();
            $message->courseid = SITEID;
            $message->component = 'moodle';
            $message->name = 'competencyplancomment';
            $message->notification = 1;
            $message->userfrom = core_user::get_noreply_user();
            $message->subject = get_string('usercommentedonaplansubject', 'core_competency', $fullname);
            $message->fullmessage = $fullmessage;
            $message->fullmessageformat = $format;
            $message->fullmessagehtml = $fullmessagehtml;
            $message->smallmessage = get_string('usercommentedonaplansmall', 'core_competency', array('fullname' => $fullname, 'plan' => $planname));
            $message->contexturl = $url->out(false);
            $message->contexturlname = $urlname;
            // Message each recipient.
            foreach ($recipients as $recipient) {
                $msgcopy = clone $message;
                $msgcopy->userto = $recipient;
                message_send($msgcopy);
            }
        }
    }
}