Hello everyone,
I’ve been saying that I was going to post this for a long time, ever since my presentation at Fusion 2010: http://www.desire2learn.com/fusion/ and now I finally have.

I have written up two pages on code I developed for use with PHP and D2L’s web services. I have been using it at my work for the last year or so, and I finally polished it up a little, and created some installation and usage instructions. I’m not finished yet, but it is a start.

If you use D2L and want to extend it through Web Services (you need to purchase the web services package from D2L, and have it installed first), I encourage you to read over these pages:

If you have any comments, please post them below. Feel free to email me with any questions or problems you run into while working with the API or the testing framework. I’m eager to improve the code for everyone.

Introduction

One of the often requested features is to be able to bulk deactivate courses in D2L after they have completed. You can currently deactivate courses, but this is a one at a time effort. This has become more important as version 8.3 of D2L brought along a new My Courses widget, which allows users to see updates from each of their courses. Unfortunately, when course access ends, they can still see the updates. This has caused confusion for many users.
Another reason to deactivate courses is minimize the amount of clutter in the view of users. If course access has ended, and they cannot access the course, there is no need for the course to remain active (this could vary depending on how your roles are configured). A way around this is to script the bulk deactivation of courses. Through the use of some Javascript coding, we can instruct the web browser to visit each course, and deactivate it for us.

Update

Please see my new post on this topic. Available at: http://www.cornempire.net/2009/07/07/d2l-bulk-deactivation-part-2/

Introduction

One of the often requested features is to be able to bulk deactivate courses in D2L after they have completed. You can currently deactivate courses, but this is a one at a time effort. This has become more important as version 8.3 of D2L brought along a new My Courses widget, which allows users to see updates from each of their courses. Unfortunately, when course access ends, they can still see the updates. This has caused confusion for many users.

Another reason to deactivate courses is minimize the amount of clutter in the view of users. If course access has ended, and they cannot access the course, there is no need for the course to remain active (this could vary depending on how your roles are configured). A way around this is to script the bulk deactivation of courses. Through the use of some Javascript coding, we can instruct the web browser to visit each course, and deactivate it for us.

Instructions on Use

You will need to edit the file and modify line 5. This contains the URL to your learning environment, and the URL to your Course Offering Information screen.

This file will need to be placed in one of your courses in your learning environment in the Manage Files area.

You need to open the file from your Manage Files section and provide the script with the OU numbers of the courses you need to deactivate. (Take a read below to see how we get the ou numbers)

Once the OU numbers are loaded, you can click the Start Processing button and your web browser should go to all the courses and deactivate them.

Limitations

You are required to have administrative access to any courses you need to deactivate (I haven’t been able to figure out why this is, but a javascript error is thrown if you do not have admin access)

This has been tested in Firefox 3 on Windows XP and Ubuntu 9.04 as well as a Chrome Development Beta for Linux but may not work in other web browsers (especially IE).

This has been tested on D2L Version 8.3 MR01. I’d suspect it would work on any version of 8.3 but not sure about 8.4 yet, or any earlier versions.

I’m not responsible if this code melts your CPU. or causes any other horrible damage to your D2L installation (although it shouldn’t….it’s only about 35 lines of Javascript. :p)

Getting a List Of Courses

The tricky part in all of this is actually getting the OU numbers for each of the courses you need to deactivate. For those who don’t know, the OU number is the org unit number, and is an internal identifier for D2L. You will notice the ou number in the URL of courses as ou=#####.

We run a report using the reporting tool that gives us the ou numbers (in one, non-ideal form. Hopefully D2L web services will eliminate the need for this).

In the Reporting tool, create a report using the Org Units dataset. With in the report, include the column for the course Path. This path contains the OU number for the course. Under the filter tab, add a few filters that will narrow down your search to the information you require. Our organization adds a semester code to all of our courses, so all courses that end in 200802 are courses that ran in the last semester. We can query these courses, and get a list of the ou numbers through the course offering paths. See below for some images of our report in action.

Then you have to do some work in manipulating the report to filter out the OU numbers. I select the whole column using firefox, and dump it into OpenOffice. Customize the import to break the lines on all of the dividing characters, and then I have a column of ou numbers. Then take that, and add in commas after all of the entries using a find and replace. You will need a text editor that can find and replace on characters you cannot see. Replace the new lines with commas.

Hopefully you can find a better way to get your list of OU numbers ;). If you have a good way, leave a comment and let me know.

Introduction

The picture library built into Desire2Learn doesn’t allow for instructors to create their own libraries. Rather, all images are shared across all courses. I wrote this bit of javascript to simulate and extend the idea of a picture library in D2L (this code can also be used for any HTML page). There are two parts to the library:

The Widget Code (or HTML code for any page)

This code is the skeleton of the library. The javascript code modifies this code in order to display the images.

The Javascript Code

This is the brain of the library. It must be installed somewhere locally and linked to the widget/HTML page. There is a configuration section at the top of the file where you can configure the library.

Here is the widget/HTML code that must be displayed on the pages.
You should not edit this code as it will cause the library to malfunction.

Here is the javascript code: picturelibrary.js
You will need to right click this link and save the file to your computer before you can upload it to your D2L shell/website.

Notes About The Code

Not all the variables need to be set a certain way in order for the code to function. However, it is a good idea to set up any variables that you don’t want to use to be false. Some variables require others, so read the comments in the code carefully. I’ve also included them below:

/**
This script presents a picture library to the user. It has several configurable
options which are outlined below.
With this script, you can:
1) Present a slide show to users
2) Present a navigatable interface for users to scroll through the library
3) Release an image to them based on a set date/time
4) Release a random image from the library
**/
/**
=== CONFIG START ===
Here you need to specify the path to this script. To do this you must go to the
Edit Course section of the site, and go to Manage Files. Then, copy the URL for
this javascript file. Paste the URL into the variable below. Then remove the
filename at the end of the URL "picturelibrary.js". Replace the file name with
"piclibimages/" (no quotes)
*/
var path = "http://online.mun.ca/content/Sandbox/TT/Sp07/piclibimages/";
/**
List your images here. By default, it will look under the piclibimages folder
in your course files. Change the path above if you want to load from a different
location.
Place the file names in the array below. A comma must be placed after each entry
except for the last entry in the list.
*/
var images = new Array(
"dataspace-code.gif",
"MedSchoolCrestSmall.gif",
"crest-toothpaste.png"
);
/**
List your captions here.
If you enable captions below, you must have at least as many captions as you have images
above or you will probably get a javascript error when the script scrolls through the
images. You can have blank captions, denoted with "" in the array below.
*/
var captions = new Array(
"The icon I created for the phpLive -> Dataspace integration.",
"Medicine School Crest",
"Crest Toothpaste"
);
/**
This array contains dates for the date release function of this script. If you do not
want to use date release, you can leave this blank.
Each entry goes with an entry in the images array and should be formatted with
the startdate-enddate for the image. Only one image can be displayed at a time
with this method.
A sample entry is: 200809190000-200809222359
This will allow the image to be viewed on Friday the 19th until Monday the 22nd.
If you want your images to rotate through a day, you can place a * for the date and
just include the time.
A sample entry is: *0000-*1200
This will allow your image to appear on the site between midnight and noon every
day.
*/
var releasedates = new Array(
"*0000-*1230",
"*1231-*1300",
"*1301-*2359"
);
//var releasedates = new Array(
// "200809170000-200809182359",
// "200809190000-200809202359",
// "200809210000-200809222359"
//);
/**
Here you can set your options for the script.
resize = controls if images are automatically resized. If true, width and
height must be set. These are measured in pixels. Be careful using this
as it will likely distort your pictures horribly. It is much better to
resize your pictures before uploading them to the system.
navigation = controls if users can navigate through images, or if they see
a loop of images.
imagepause = the amount of time in milliseconds that an image appears before
changing. Only used if navigation is false. 4000 = 4 seconds
captionsdisplay = if this is set to true, the caption is pulled from the above array
and displayed with the picture.
daterelease = Shows an image on a specific date/for a specific time. The datearray
must store the dates in the format yearmonthday-yearmonthday or *time-*time.
the first date/time being when the image is displayed, and the second
when it ends.
imagestyle = This is a CSS style tag that will be added to the image tag.
captionstyle = This is a CSS style take that will be added to the caption.
widgetsytle = This is a CSS style tag that well be added to the div around the image
and caption.
randomstart = This variable controls whether or not the script begins on a random image.
singlerandom = If true, this displays a single random image when the page is loaded.
*/
var resize = false;
var width = "";
var height = "";
var navigation = true;
var imagepause = "5000";
var captionsdisplay = true;
var daterelease = true;
var imagestyle = "margin: 0 auto; display: block; padding: 2px;";
var captionstyle = "margin: 1px; text-size: 10px; text-align: center; border: 1px dashed gray;";
var widgetstyle = "border: 2px solid black;";
var randomstart = true;
var singlerandom = false;
/**
=== CONFIG END ===
This is the end of configurable items for this script. Do not edit the code below.
*/

Also of note is the use of CSS styles. I cannot figure out how to apply an arbitrary CSS style string to an HTML element. I can change specific things, but I cannot allow any style tags. If anyone knows how, please contact me.

Because of this limitation, the CSS code will only recognize:

border

text-align

font-size

margin

display

padding

You can add in your own code to the bottom by editing the doStyle function, or you can apply your own styles to the raw widget/HTML code. You must leave the style variables blank in this script.

Final Thoughts

I hope you find this useful, either for your D2L course, or for your personal homepage. I’ll probably post updates from time to time on this script depending on the feedback I receive. If you have any comments, you can leave them below. Take a look at some of the variable configurations below to see examples of how the code can be used.

Examples

This configuration allows you to display a slide show that updates every 5 seconds. It has a random starting point, and has captions enabled.