1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
|
<?PHP // $Id: lib.php,v 1.4 2006/02/08 06:00:24 fyang1024 Exp $
/// Library of functions and constants for module lams
require_once($CFG->dirroot.'/lib/datalib.php');
require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->dirroot.'/lib/soap/nusoap.php');
function lams_add_instance($lams) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// will create a new instance and return the id number
/// of the new instance.
global $USER;
$lams->timemodified = time();
$lams->learning_session_id = lams_get_lesson($USER->username,$lams->sequence,$lams->course,$lams->name,$lams->introduction,"normal");
return insert_record("lams", $lams);
}
function lams_update_instance($lams) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// will update an existing instance with new data.
//echo "enter lams_update_instance<BR>";
$lams->timemodified = time();
$lams->id = $lams->instance;
lams_delete_lesson($USER->username,$lams->learning_session_id);
$lams->learning_session_id = lams_get_lesson($USER->username,$lams->sequence,$lams->course,$lams->name,$lams->introduction,"normal");
if(!$lams->learning_session_id){
return false;
}
# May have to add extra stuff in here #
//echo $lams->id."<BR>";
//echo $lams->sequence."<BR>";
//echo $lams->course."<BR>";
//echo $lams->name."<BR>";
//echo $lams->introduction."<BR>";
//echo $lams->learning_session_id."<BR>";
//echo "exit lams_update_instance<BR>";
return update_record("lams", $lams);
}
function lams_delete_instance($id) {
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
if (! $lams = get_record("lams", "id", "$id")) {
return false;
}
$result = true;
# Delete any dependent records here #
lams_delete_lesson($USER->username,$lams->learning_session_id);
if (! delete_records("lams", "id", "$lams->id")) {
$result = false;
}
return $result;
}
function lams_user_outline($course, $user, $mod, $lams) {
/// Return a small object with summary information about what a
/// user has done with a given particular instance of this module
/// Used for user activity reports.
/// $return->time = the time they did it
/// $return->info = a short text description
return $return;
}
function lams_user_complete($course, $user, $mod, $lams) {
/// Print a detailed representation of what a user has done with
/// a given particular instance of this module, for user activity reports.
return true;
}
function lams_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a time, this module should find recent activity
/// that has occurred in lams activities and print it out.
/// Return true if there was output, or false is there was none.
global $CFG;
return false; // True if anything was printed, otherwise false
}
function lams_cron () {
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
global $CFG;
return true;
}
function lams_grades($lamsid) {
/// Must return an array of grades for a given instance of this module,
/// indexed by user. It also returns a maximum allowed grade.
///
/// $return->grades = array of grades;
/// $return->maxgrade = maximum allowed grade;
///
/// return $return;
return NULL;
}
function lams_get_participants($lamsid) {
//Must return an array of user records (all data) who are participants
//for a given instance of lams. Must include every user involved
//in the instance, independient of his role (student, teacher, admin...)
//See other modules as example.
return false;
}
function lams_scale_used ($lamsid,$scaleid) {
//This function returns if a scale is being used by one lams
//it it has support for grading and scales. Commented code should be
//modified if necessary. See forum, glossary or journal modules
//as reference.
$return = false;
//$rec = get_record("lams","id","$lamsid","scale","-$scaleid");
//
//if (!empty($rec) && !empty($scaleid)) {
// $return = true;
//}
return $return;
}
//////////////////////////////////////////////////////////////////////////////////////
/// Any other lams functions go here. Each of them must have a name that
/// starts with lams_
function lams_get_soap_client($relativeurl) {
global $CFG;
if(!isset($CFG->lams_serverurl))
{
return NULL;
}
$wsdl = $CFG->lams_serverurl.$relativeurl;
$s = new soap_client($wsdl,true,false,false,false,false,2,3);
return $s;
}
/**
* Get sequences(learning designs) for the user in LAMS
*
* @param string $username The username of the user. Set this to "" if you would just like to get sequences for the currently logged in user.
* @return Array sequence array
* @TODO complete the documentation of this function
*/
function lams_get_sequences($username,$courseid) {
global $CFG,$USER;
if(!isset($CFG->lams_serverid)||!isset($CFG->lams_serverkey)||!isset($CFG->lams_serverurl))
{
return get_string("notsetup", "lams");
}
$relativeurl="/services/LearningDesignService?wsdl";
$s = lams_get_soap_client($relativeurl);
if(is_null($s)){
return NULL;
}
$datetime = date("F d,Y g:i a");
/*
$login = lams_get_user($username,$courseid);
if(empty($login)){
return NULL;
}
*/
if(!isset($username)){
$username = $USER->username;
}
$rawstring = trim($datetime).trim($username).trim($CFG->lams_serverid).trim($CFG->lams_serverkey);
$hashvalue = sha1(strtolower($rawstring));
$parameters = array($CFG->lams_serverid,$datetime,$hashvalue,$username);
$result = $s->call('getAllLearningDesigns',$parameters);//Array of simpleLearningDesign objects
if($s->getError()){//if some exception happened
$result = $s->getError();//return the string describing the error
}
unset($s);
return $result;
}
/**
* Get learning session(lesson) id from LAMS
*
* @param string $username The username of the user. Set this to "" if you would just like the currently logged in user to create the lesson
* @param int $ldid The id of the learning design that the lesson is based on
* @param int $courseid The id of the course that the lesson is associated with.
* @param string $title The title of the lesson
* @param string $desc The description of the lesson
* @param string $type The type of the lesson. Two types: normal, preview
* @return int lesson id
*/
function lams_get_lesson($username,$ldid,$courseid,$title,$desc,$type) {
//echo "enter lams_get_lesson<BR>";
global $CFG,$USER;
if(!isset($CFG->lams_serverid)||!isset($CFG->lams_serverkey))
{
//echo "serverid or serverkey is not set<BR>";
return NULL;
}
$relativeurl="/services/LearningSessionService?wsdl";
$s = lams_get_soap_client($relativeurl);
if(is_null($s)){
//echo "soap client is null<BR>";
return NULL;
}
$datetime = date("F d,Y g:i a");
if(!isset($username)){
$username = $USER->username;
}
$plaintext = $datetime.$username.$CFG->lams_serverid.$CFG->lams_serverkey;
//echo $plaintext;
$hashvalue = sha1(strtolower($plaintext));
//echo $hashvalue;
$parameters = array($CFG->lams_serverid,$datetime,$hashvalue,$username,$ldid,$courseid,$title,$desc,$type);
$result = $s->call('createLearningSession',$parameters);
//echo "result:".$result."<BR>";
//echo "exit lams_get_lesson<BR>";
if($s->getError()){
$result = $s->getError();
}
unset($s);
return $result;
}
/**
* Delete learning session(lesson) from LAMS
*
* @param string $username The username of the user. Set this to "" if you would just like the currently logged in user to create the lesson
* @param int $lsid The id of the learning session(lesson)
* @return true or false
*/
function lams_delete_lesson($username,$lsid) {
//echo "enter lams_get_lesson<BR>";
global $CFG,$USER;
if(!isset($CFG->lams_serverid)||!isset($CFG->lams_serverkey))
{
return "The LAMS serverId and serverKey have not been set up";
}
$relativeurl="/services/LearningSessionService?wsdl";
$s = lams_get_soap_client($relativeurl);
if(is_null($s)){
return "Failed to get soap client based on:".$relativeurl;
}
$datetime = date("F d,Y g:i a");
if(!isset($username)){
$username = $USER->username;
}
$plaintext = $datetime.$username.$CFG->lams_serverid.$CFG->lams_serverkey;
//echo $plaintext;
$hashvalue = sha1(strtolower($plaintext));
//echo $hashvalue;
$parameters = array($CFG->lams_serverid,$datetime,$hashvalue,$username,$lsid);
$result = $s->call('deleteLearningSession',$parameters);
if($s->getError()){
$result = $s->getError();
}
unset($s);
return $result;
}
/**
* Get class in LAMS
* @param int courseid
* @return int class id
* @TODO complete the documentation of this function
*/
/*
function lams_get_class($courseid) {
global $CFG,$USER;
//echo "enter lams_get_class"."<BR>";
$orgId = lams_get_organisation();
if(empty($orgId)){
return NULL;
}
$lams_course = get_record("lams_course","course", $courseid);
if(empty($lams_course)){//LAMS class hasn't been created
//create LAMS class
$relativeurl="/services/UserManagementService?wsdl";
$s = lams_get_soap_client($relativeurl);
if(is_null($s)){
return NULL;
}
$datetime = date("F d,Y g:i a");
$rawstring = $datetime.$CFG->lams_serverid.$CFG->lams_serverkey;
$hashvalue = sha1(strtolower($rawstring));
$parameters = array($CFG->lams_serverid,$datetime,$hashvalue);
$result = $s->call('createClass',$parameters);
//echo "<xmp/>".$s->request."</xmp>";
//echo "<xmp/>".$s->response."</xmp>";
//echo "result:".$result."<BR>";
$lams_course->course = $courseid;
$lams_course->classid = $result;
insert_record("lams_course",$lams_course);
//echo "exit lams_get_class"."<BR>";
return $result;
}else{
//echo "exit lams_get_class"."<BR>";
return $lams_course->classid;
}
}
*/
/**
* Get organisation in LAMS
*
* @return int organisation id
* @TODO complete the documentation of this function
*/
/*
function lams_get_organisation() {
global $CFG,$USER;
//echo "enter lams_get_organisaiton"."<BR>";
if(!isset($CFG->lams_serverid)||!isset($CFG->lams_serverkey))
{
return NULL;
}
if(!isset($CFG->lams_orgid)){
$relativeurl="/services/UserManagementService?wsdl";
$s = lams_get_soap_client($relativeurl);
if(empty($s)){
return NULL;
}
$datetime = date("F d,Y g:i a");
$rawstring = $datetime.$CFG->lams_serverid.$CFG->lams_serverkey;
$hashvalue = sha1(strtolower($rawstring));
$parameters = array($CFG->lams_serverid,$datetime,$hashvalue);
$result = $s->call('createOrganisation',$parameters);
//echo "<xmp/>".$s->request."</xmp>";
//echo "<xmp/>".$s->response."</xmp>";
set_config("lams_orgid",$result);
//echo "result:".$result."<BR>";
//echo "exit lams_get_organisaiton"."<BR>";
return $result;
}else{
//echo "exit lams_get_organisaiton"."<BR>";
return $CFG->lams_orgid;
}
}
*/
/**
* Get user in LAMS
*
* @param string $username The username of the user. Set this to "" if you would just like to create LAMS user for the currently logged in user
* @param string $roles The user's roles in LAMS
* @param int $classid The id of the class that the user belongs to. The class should be already created in LAMS by calling lams_create_class()
* @param int $orgid The id of the organisation that the user belongs to. The organisation should be already created in LAMS by calling lams_create_organisation()
* @return user login in LAMS if the user is successfully created
* @TODO complete the documentation of this function
*/
/*
function lams_get_user($username,$courseid) {
global $CFG,$USER;
//echo "enter lams_get_user"."<BR>";
if(!isset($CFG->lams_serverid)||!isset($CFG->lams_serverkey))
{
return NULL;
}
$lams_user = get_record("lams_user","username",$username);
if(empty($lams_user)){//LAMS user hasn't been created
$classid = lams_get_class($courseid);
if(empty($classid)){//Can't get class id from lams_course table. Something wrong!
return NULL;
}
$orgid = lams_get_organisation();//It won't be NULL. See lams_get_class function
$user = get_record("user","username",$username);
if(empty($user)){//Something wrong
return NULL;
}
$roles = lams_get_user_roles($user->id,$courseid);
$relativeurl="/services/UserManagementService?wsdl";
$s = lams_get_soap_client($relativeurl);
if(empty($s)){
return NULL;
}
$datetime = date("F d,Y g:i a");
$login = $username;
$rawstring = $datetime.$login.$CFG->lams_serverid.$CFG->lams_serverkey;
$hashvalue = sha1(strtolower($rawstring));
$parameters = array($CFG->lams_serverid,$datetime,$hashvalue,$login,"password",$roles,$classid,$orgid);
$result = $s->call('createUser',$parameters);
//echo "<xmp/>".$s->request."</xmp>";
//echo "<xmp/>".$s->response."</xmp>";
$lams_user->username = $username;
$lams_user->login = $result;
insert_record("lams_user",$lams_user);
//echo "result:".$result."<BR>";
//echo "exit lams_get_user"."<BR>";
return $result;
}else{
//echo "exit lams_get_user"."<BR>";
return $lams_user->login;
}
}
*/
/**
* Mapping moodle roles to LAMS roles
*
* @param int $courseid The id of the course that is being viewed
* @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
* @return formatted string describing LAMS roles
* @TODO fill the gap of roles mapping between moodle and LAMS
*/
/*
function lams_get_user_roles($userid=0, $courseid){
$roles = "";
if(isadmin($userid)){
$roles = "administrator"."|"."auhtor"."|"."staff";
}else if(isteacheredit($courseid,$userid)){
$roles = "auhtor"."|"."staff";
}else if(isteacher($courseid,$userid)){
$roles = "staff";
}
if(isstudent($courseid,$userid)){
if(empty($roles)){
$roles = "learner";
}else{
$roles .= "|"."learner";
}
}
//echo $roles."<BR>";
return $roles;
}
*/
?>
|