Variable for Course Link

Variable for Course Link

by Alan Kmiecik -
Number of replies: 5

Is there a variable for the link that goes directly to the course?

eg something like $a->courselink?

Average of ratings: -
In reply to Alan Kmiecik

Re: Variable for Course Link

by Stephen Mc Guinness -

You might be looking for:

global $CFG;

$courselink = $CFG->wwwroot . "/course/view.php?id=" . $course_id;

Stephen Mc Guinness
Enovation Solutions

Average of ratings: Useful (1)
In reply to Stephen Mc Guinness

Re: Variable for Course Link

by Alan Kmiecik -

Thanks Stephen, I am not quite good enough at the syntax to get what you are saying:

  • So, the variable does not already exist (like it does for $a->sitename)?
  • I need to define it using the two lines you have listed, but where?

Goal it to have link to course in welcome to course email, thanks.

In reply to Alan Kmiecik

Re: Variable for Course Link

by Derick Turner -
Picture of Core developers

You are correct that the variable does not exist.  However what you can do is either create the URL on the fly using the above method within the PHP code or simply add the link to the email text as, and please correct me if I am wrong, you appear to be wanting to do.

If you are concerned about the welcome course being updated and its unique course ID getting changed, you can also reference it using the course's shortname.  E.g. if the shortname for the welcome course is "welcome" the URL would look something like

http://my.site.com/course/view.php?name=welcome

The course shortname needs to be unique in any case, but this also allows you to have a new course which you can swap in by changing the shortname without having to then update the email text.

Hope this helps

Derick

In reply to Alan Kmiecik

Re: Variable for Course Link

by Stephen Mc Guinness -

Hi Alan,

The language string for the course welcome email (in 1.9) is:

$string['welcometocoursetext'] = 'Welcome to $a->coursename!

If you have not done so already, you should edit your profile page so that we can learn more about you:

$a->profileurl';

I that case $a is an object that is being passed as a parameter to the get_string call which is retrieving the welcometocoursetext language string.

You need to locate the get_string call and add your course link to the object which is passed as a parameter to that call.

In Moodle 1.9 the call to get_string is around lines 4711 - 4718 in lib/moodlelib.php

4711     if (!empty($course->welcomemessage)) {
4712         $message = $course->welcomemessage;
4713     } else {
4714         $a = new Object();
4715         $a->coursename = $course->fullname;
4716         $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
4717         $message = get_string("welcometocoursetext", "", $a);
4718     }

You need to modify that code to add your course link:

4711     if (!empty($course->welcomemessage)) {
4712         $message = $course->welcomemessage;
4713     } else {
4714         $a = new Object();
4715         $a->coursename = $course->fullname;
//Add the course link to $a so it can be used in the language string
$a->courselink = "{$CFG->wwwroot}/course/view.php?id={$course->id}";

4716         $a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
4717         $message = get_string("welcometocoursetext", "", $a);
4718     }

$a->courselink would then be available in the language file for you to use in your modification of the course welcome email

Stephen Mc Guinness
Enovation Solutions

In reply to Alan Kmiecik

Re: Variable for Course Link

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
From where?

As has been pointed out, you can construct a link to a course page using either the course id or the course shortname (depending on preference or what information you have available). However, it depends on what exactly you are trying to do and where you are doing this "from" (what bit of code you are writing or modifying).