[Be aware -- this is by FAR the geekiest post I've written in a long, long time.]
Thought I'd share this for anyone who is trying to use both Moodle and Drupal. We just figured out a quick way to create a link on a
DrupalEd Group page to a corresponding Moodle course.
Here's how:
This assumes that a) you have
CCK and
Computed Field installed
First, give every DrupalEd course an automatic alias that is the same as your Moodle short-course name. (Yes, right now, we have to do that by hand. That needs to change eventually.)
Then, in Content Management -> Content Types -> Course -- create a new field called field_moodle_link (or something like that) and select Field Type -- Computed and create the field.
In the next page that pops up, fill in the Label with whatever you want the label to be on the Drupal Group page. Then I chose "Required" under data settings, but I'm not 100% sure that's necessary. And under Computed Code, enter this:
$db = mysql_connect("<machine>", "<moodle_username>", "<moodle_password>");
mysql_select_db("<moodle_db>",$db);
#Enter base moodle website here
$website = "http://www.yourwebsitehere.org/moodle";
$nodepath = "node/";
$nodepath .= arg(1);
$shortname = drupal_get_path_alias($nodepath);
$query = "SELECT id,fullname from mdl_course where shortname='$shortname'";
# Standard debug test
# print("<br>$query");
$idquery = mysql_query($query);
if ($idarray = mysql_fetch_array($idquery))
{
$id = $idarray["id"];
$fullname = $idarray["fullname"];
$node_field[0]['value'] = "<br><a href=$website/course/view.php?id=$id>$fullname</a>";
}
else
{
$node_field[0]['value'] = "No Moodle Course w/ shortname: $shortname";
}
?>
Make sure "Display this field" is checked, and I use this as my display format:
$display = $node_field_item['value'] . "<br><br>";
And then save it.
Once it's saved, click "Manage Fields" and make sure that your new field has a lower numerical value than the Highlighted Content Field, so that it's at the top of the Drupal page.
What I'd like to do eventually, is figure out how to make that link appear in the Group Details block, but I haven't figured out how to edit that. Anyone who knows, I'd love to know.
In the meantime, drop me a note if you find this useful... or make it better.
(And now, off to figure out Moodle blocks. And yes, I'm still a principal, why do you ask?)
Tags: killerapp, drupal, programming
Comments
Mon, 25.03.2013 14:05
Jon Goldman was both my
English Teacher in 9th
grade and Advisory Mentor
for my four years at
[...]
Karen Greenberg about Saving Lives v. Changing Lives
Tue, 14.08.2012 11:13
Perhaps a more apt term
would be "altering
trajectories". Think
physics - two objects in
motion [...]
Amethyst about Saving Lives v. Changing Lives
Mon, 13.08.2012 22:51
I really appreciate this
blog entry. Our roles as
teachers require, at our
best, a deep [...]
Mark Ahlness about The Long Haul
Mon, 13.08.2012 22:33
Chris, thanks. Pete is my
hero, and has been for a
while, but now that I'm
retired, after 31 years
[...]
Gary Stager about Saving Lives v. Changing Lives
Mon, 13.08.2012 22:15
Chris,
No need to worry about
semantic arguments.
Others all around us are
debasing our [...]