Tuesday, January 13, 2009

Create Link From Drupal To Moodle

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("", "", "");
mysql_select_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("
$query");

$idquery = mysql_query($query);
if ($idarray = mysql_fetch_array($idquery))
{
$id = $idarray["id"];
$fullname = $idarray["fullname"];
$node_field[0]['value'] = "
$fullname";
}
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'] . "

";

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.

2 comments:

cms Design said...

Thanks for the posts we are the professional web design and development company offering an array of services like template customization,web designing, CMS solutions, eCommerce solutions, Search engine optimization and Internet marketing.
CMS DESIGN

Anonymous said...

Thanks for sharing this helpful stuff and I want to ask a question that how two companies can work together to help grow market share with Drupal?
Drupal Templates