In order for us to track a one-to-one relationship between a Moodle course and an Elgg community we first need to create a mapping table. The table definition I used is as follows:
The eportid column corresponds to the Elgg community id for a particular course; the courseid is the one that tracks the Moodle course.<TABLE NAME="block_eportfolio_course_map" COMMENT=""> <FIELDS> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="courseid"/> <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="eportid"/> <FIELD NAME="eportid" TYPE="char" LENGTH="128" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="courseid"/> </FIELDS> <KEYS> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for block_eportfolio_course_map" NEXT="courseid"/> <KEY NAME="courseid" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id" NEXT="courseid_uniq" PREVIOUS="primary"/> <KEY NAME="courseid_uniq" TYPE="uniq" FIELDS="courseid" PREVIOUS="courseid"/> </KEYS> </TABLE>
Since our code already supports single sign-on, we just add to that to track whether an Elgg community needs to be created. Let us reuse the signupredirect.php page and just add an extra variable that tells the system to create a corresponding community. The significant section is as follows:
if (!$course = get_record('block_eportfolio_course_map', 'courseid', $this->courseid)) {
if (has_capability('moodle/course:update', $context)) {
$this->content->text = '<form action="'.$CFG->wwwroot.'/blocks/eportfolio/signupredirect.php" method="post">'."\n";
$this->content->text .= get_string('createelggcomm','block_eportfolio');
// flag to create community
$postdata['createcomm'] = 1;
foreach($postdata as $key => $value) {
$this->content->text .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />'."\n";
}
$this->content->text .= '<input type="submit" value="Create" />'."\n".'</form>'."\n";
} else {
$this->content = '';
}
return $this->content;
}
The signupredirect.php file is modified so that it knows what to do with this new variable. It also passes in the coursename and fullname to Elgg so that they can be used as credentials for creating the community. This is shown below.
foreach ($data as $key => $value) {
// if the key is signature, rewrite it to contain additional signup stuff.
if ($key == 'signature') {
echo '<input type="hidden" name="'.$key.'" value="'.eportfolio_create_hash($USER,true).'" />';
} elseif ($key == 'createcomm' && !empty($courseid)) {
if ($COURSE = get_record('course', 'id', $courseid)) {
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
if (has_capability('moodle/course:update', $context)) {
echo '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
$coursename = $COURSE->shortname;
// allow only alphanumeric and space but replace space with underscore
$coursename = preg_replace("/[^\da-zA-z]/","",$coursename);
$coursename = substr(strtolower($coursename), 0, 12);
echo '<input type="hidden" name="coursename" value="'.$coursename.'" />';
echo '<input type="hidden" name="coursefullname" value="'.$COURSE->fullname.'" />';
}
}
} else {
echo '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
}
}
On the Elgg side, the file elgg/lms/createorlogin.php that we initially created for single sign-on is now aware of the createcom variable and it creates the community when necessary. We added the community id variable to the pingback code so that when Elgg is done with the operation and posts status to Moodle, it is able to store the association into our block_eportfolio_course_map table. The relevant change in eportfolio's confirm.php is as follows:
case 'commcreateconfirmation':
if ($user = get_record('user','username',$username,'','','','','id,username,firstname,lastname,email')) {
// check the signature
$goodsig = eportfolio_create_hash($user,true);
if ($goodsig == $signature) {
if (!$coursemap = get_record('block_eportfolio_course_map','course_id',$courseid)) {
$maprec = new StdClass;
$maprec->courseid = $courseid;
$maprec->eportid = $commid;
insert_record('block_eportfolio_course_map',$maprec);
echo "OK";
}
} else {
echo "no sig";
}
} else {
echo "no user";
}
break;
As mentioned in part 1, the new code doesn't restrict tracked portfolio activity to Elgg blog posts that the user has marked as favorite. We need to make changes to Elgg to show all activities done by other members of the community and return that as the rss items. For now the system only tracks weblog posts but this can be modified in the future to return other items as well. For this we just created a new file inside elgg/lms/commrss.php and call that to fetch the items instead of the stock elgg/lms/rss.php.
One of our requirements for the project was to eliminate login directly to Elgg and have all access come from the Moodle side. For this we want to be able to present a link to go directly to the community page from within the eportfolio block and have Elgg automatically handle adding the user to the community when necessary. There is a new file elgg/lms/gotocomm.php that handles this and the relevant change in block_eportfolio.php is as follows:
if ($item['title'] != 'No activity') {
// check if first_rec is one after passing through the record
// this means that there is activity
if ($first_rec == 1) {
$eportlink = $CFG->block_eportfolio_baseurl.'/_activity/';
if (empty($USER->eportfolioauthed["$COURSE->id"])) {
$eportlink = $CFG->wwwroot.'/blocks/eportfolio/authredirect.php?courseid='.$COURSE->id.'&sesskey='.sesskey().'&url='.$eportlink;
}
$returnstring .= '<div class="link" style="padding-bottom: 10px;"><a href="'.$eportlink.'" target="_blank">Your e-Portfolio</a>' ."\n";
if (!empty($commid)) {
$commlink = $CFG->block_eportfolio_baseurl.'/lms/gotocomm.php?commid='.$commid;
if (empty($USER->eportfolioauthed["$COURSE->id"])) {
$commlink = $CFG->wwwroot.'/blocks/eportfolio/authredirect.php?courseid='.$COURSE->id.'&sesskey='.sesskey().'&url='.$commlink;
}
$returnstring .= ' | <a href="'.$commlink.'" target="_blank">Community</a></div>' ."\n";
} else {
$returnstring .= '</div>' ."\n";
}
}
$returnstring .= '<div style="padding-bottom: 5px;"><div class="link"><a href="". $item['link'] .'" target="_blank">'. $item['title'] . '</a></div>' ."\n";
if (!empty($item['description'])) {
$item['description'] = break_up_long_words($item['description'], 30);
$returnstring .= '<div class="description">'.
format_text($item['description'], FORMAT_MOODLE, $formatoptions) . '</div>' ."\n";
}
$returnstring .= "</div>";
} elseif ($first_rec == 1) {
$returnstring .= '<div class="link" style="padding-bottom: 10px;"><a href="". $item['link'] .'" target="_blank">Your e-Portfolio</a></div>' ."\n";
}
I hope this post presents a clear picture of how we approached the mapping of Moodle courses to Elgg communities. I did not post the modifications on all the Elgg files as well as all the new files created as they are hard to single out but you should be able to find them in these updated zip files of the eportfolio block and the relevant files in Elgg that we are making available for download. As always, this is according to our requirements so your mileage may vary when you try them out.
Subscribe to notificaitons