[system] / trunk / wwmoodle / wwassignment / lib.php Repository:
ViewVC logotype

Diff of /trunk/wwmoodle/wwassignment/lib.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5108 Revision 5109
1<?php 1<?php
2// $Id: lib.php,v 1.16 2007-06-29 19:17:28 mleventi Exp $ 2// $Id: lib.php,v 1.17 2007-07-01 20:44:13 mleventi Exp $
3 3
4require_once("$CFG->libdir/soap/nusoap.php"); 4require_once("$CFG->libdir/soap/nusoap.php");
5 5
6define('WWASSIGNMENT_WEBWORK_URL', $CFG->wwassignment_webworkurl); 6define('WWASSIGNMENT_WEBWORK_URL', $CFG->wwassignment_webworkurl);
7define('WWASSIGNMENT_WEBWORK_WSDL', $CFG->wwassignment_rpc_wsdl); 7define('WWASSIGNMENT_WEBWORK_WSDL', $CFG->wwassignment_rpc_wsdl);
18 $webworkclient =& new webwork_client(); 18 $webworkclient =& new webwork_client();
19 $webworkcourse = _wwassignment_mapped_course($COURSE->id,false); 19 $webworkcourse = _wwassignment_mapped_course($COURSE->id,false);
20 $webworkset = _wwassignment_mapped_set($wwassignmentid,false); 20 $webworkset = _wwassignment_mapped_set($wwassignmentid,false);
21 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username); 21 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username);
22 if($webworkuser == -1) { 22 if($webworkuser == -1) {
23 error_log(get_string("user_not_mapped","wwassignment"));
24 $tempuser = $USER; 23 $tempuser = $USER;
25 $newuser = $webworkclient->create_user($webworkcourse,$tempuser); 24 $newuser = $webworkclient->create_user($webworkcourse,$tempuser);
26 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username,false); 25 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username,false);
27 } 26 }
28 27
29 $webworksetuser = $webworkclient->mapped_user_set($webworkcourse,$webworkuser,$webworkset); 28 $webworksetuser = $webworkclient->mapped_user_set($webworkcourse,$webworkuser,$webworkset);
30 if($webworksetuser == -1) { 29 if($webworksetuser == -1) {
31 error_log(get_string("set_user_not_mapped","wwassignment"));
32 //try and do it now 30 //try and do it now
33 $newsetuser = $webworkclient->create_user_set($webworkcourse,$webworkuser,$webworkset); 31 $newsetuser = $webworkclient->create_user_set($webworkcourse,$webworkuser,$webworkset);
34 //AGAIN FOR GOOD MEASURE 32 //AGAIN FOR GOOD MEASURE
35 $webworksetuser = $webworkclient->mapped_user_set($webworkcourse,$webworkuser,$webworkset,false); 33 $webworksetuser = $webworkclient->mapped_user_set($webworkcourse,$webworkuser,$webworkset,false);
36 } 34 }
55 $webworkset = _wwassignment_mapped_set($wwassignmentid,false); 53 $webworkset = _wwassignment_mapped_set($wwassignmentid,false);
56 //IS THE USER MAPPED? 54 //IS THE USER MAPPED?
57 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username); 55 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username);
58 if($webworkuser == -1) { 56 if($webworkuser == -1) {
59 //USER WAS NOT FOUND, wasnt mapped 57 //USER WAS NOT FOUND, wasnt mapped
60 error_log(get_string("user_not_mapped","wwassignment"));
61 //try and create a teacher 58 //try and create a teacher
62 $tempuser = $USER; 59 $tempuser = $USER;
63 $newuser = $webworkclient->create_user($webworkcourse,$tempuser,"10"); 60 $newuser = $webworkclient->create_user($webworkcourse,$tempuser,'10');
64 //AGAIN FOR GOOD MEASURE 61 //AGAIN FOR GOOD MEASURE
65 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username,false); 62 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username,false);
66 } 63 }
67 $key = $webworkclient->login_user($webworkcourse,$webworkuser,false); 64 $key = $webworkclient->login_user($webworkcourse,$webworkuser,false);
68 return _wwassignment_link_to_edit_set_auto_login($webworkcourse,$webworkset,$webworkuser,$key); 65 return _wwassignment_link_to_edit_set_auto_login($webworkcourse,$webworkset,$webworkuser,$key);
79 $webworkcourse = _wwassignment_mapped_course($COURSE->id,false); 76 $webworkcourse = _wwassignment_mapped_course($COURSE->id,false);
80 //IS THE USER MAPPED? 77 //IS THE USER MAPPED?
81 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username); 78 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username);
82 if($webworkuser == -1) { 79 if($webworkuser == -1) {
83 //USER WAS NOT FOUND, wasnt mapped 80 //USER WAS NOT FOUND, wasnt mapped
84 error_log(get_string("user_not_mapped","wwassignment"));
85 //try and create a teacher 81 //try and create a teacher
86 $tempuser = $USER; 82 $tempuser = $USER;
87 $newuser = $webworkclient->create_user($webworkcourse,$tempuser,"10"); 83 $newuser = $webworkclient->create_user($webworkcourse,$tempuser,'10');
88 //AGAIN FOR GOOD MEASURE 84 //AGAIN FOR GOOD MEASURE
89 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username,false); 85 $webworkuser = $webworkclient->mapped_user($webworkcourse,$USER->username,false);
90 } 86 }
91 $key = $webworkclient->login_user($webworkcourse,$webworkuser,false); 87 $key = $webworkclient->login_user($webworkcourse,$webworkuser,false);
92 88
100 global $COURSE,$SESSION,$USER; 96 global $COURSE,$SESSION,$USER;
101 97
102 98
103 if(isset($wwassignment->webwork_course)) { 99 if(isset($wwassignment->webwork_course)) {
104 //Attaching Moodle Course to WeBWorK Course 100 //Attaching Moodle Course to WeBWorK Course
105 if($wwassignment->webwork_course =="create") {
106 print_error("Creation is not yet supported.");
107 }
108 error_log("adding wwassignment_bridge record");
109 $wwassignment->course = $COURSE->id; 101 $wwassignment->course = $COURSE->id;
110 $returnid = insert_record("wwassignment_bridge",$wwassignment); 102 $returnid = insert_record('wwassignment_bridge',$wwassignment);
111 $wwassignment->webwork_set = "undefined"; 103 $wwassignment->webwork_set = 'undefined';
112 $returnid = insert_record("wwassignment",$wwassignment); 104 $returnid = insert_record('wwassignment',$wwassignment);
113 $webworkclient =& new webwork_client(); 105 $webworkclient =& new webwork_client();
114 if($webworkclient->mapped_user($wwassignment->webwork_course,$USER->username) == -1) { 106 if($webworkclient->mapped_user($wwassignment->webwork_course,$USER->username) == -1) {
115 $webworkclient->create_user($wwassignment->webwork_course,$USER,"10"); 107 $webworkclient->create_user($wwassignment->webwork_course,$USER,'10');
116 } 108 }
117 return $returnid; 109 return $returnid;
118 } 110 }
119 if(isset($wwassignment->webwork_set)) { 111 if(isset($wwassignment->webwork_set)) {
120 $webworkclient =& new webwork_client(); 112 $webworkclient =& new webwork_client();
121 if($wwassignment->webwork_set =="create") {
122 print_error("Creation is not yet supported.");
123 }
124 $webworkcourse = _wwassignment_mapped_course($COURSE->id); 113 $webworkcourse = _wwassignment_mapped_course($COURSE->id);
125 $webworksetdata = $webworkclient->get_assignment_data($webworkcourse,$wwassignment->webwork_set,false); 114 $webworksetdata = $webworkclient->get_assignment_data($webworkcourse,$wwassignment->webwork_set,false);
126 //Attaching Moodle Set to WeBWorK Set 115 //Attaching Moodle Set to WeBWorK Set
127 error_log("adding wwassignment record");
128 $wwassignment->course = $COURSE->id; 116 $wwassignment->course = $COURSE->id;
129 $wwassignment->name = get_string("set_name","wwassignment") . " " . $webworksetdata['set_id']; 117 $wwassignment->name = get_string('set_name','wwassignment') . ' ' . $webworksetdata['set_id'];
130 $returnid = insert_record("wwassignment",$wwassignment); 118 $returnid = insert_record('wwassignment',$wwassignment);
131 //GET TIMEDUE INFO AND ADD AN EVENT 119 //GET TIMEDUE INFO AND ADD AN EVENT
132 120
133 if(isset($webworksetdata)) { 121 if(isset($webworksetdata)) {
134 $event = NULL; 122 $event = NULL;
135 $event->name = get_string("set_name","wwassignment") . " " . $webworksetdata['set_id']; 123 $event->name = get_string('set_name','wwassignment') . ' ' . $webworksetdata['set_id'];
136 $event->description = ""; 124 $event->description = '';
137 $event->courseid = $COURSE->id; 125 $event->courseid = $COURSE->id;
138 $event->groupid = 0; 126 $event->groupid = 0;
139 $event->userod = 0; 127 $event->userod = 0;
140 $event->modulename = 'wwassignment'; 128 $event->modulename = 'wwassignment';
141 $event->instance = $returnid; 129 $event->instance = $returnid;
142 $event->eventtype = 'due'; 130 $event->eventtype = 'due';
143 $event->timestart = $webworksetdata['due_date']; 131 $event->timestart = $webworksetdata['due_date'];
144 $event->timeduration = 0; 132 $event->timeduration = 0;
145 if(!add_event($event)) { 133 if(!add_event($event)) {
146 error_log(get_string("event_creation_error","wwassignment")); 134 error_log(get_string('event_creation_error','wwassignment'));
147 } 135 }
148 } 136 }
149 } 137 }
150 return $returnid; 138 return $returnid;
151} 139}
159 $webworkclient =& new webwork_client(); 147 $webworkclient =& new webwork_client();
160 $webworkcourse = _wwassignment_mapped_course($COURSE->id); 148 $webworkcourse = _wwassignment_mapped_course($COURSE->id);
161 $webworkset = _wwassignment_mapped_set($wwassignment->instance,false); 149 $webworkset = _wwassignment_mapped_set($wwassignment->instance,false);
162 $webworksetdata = $webworkclient->get_assignment_data($webworkcourse,$webworkset,false); 150 $webworksetdata = $webworkclient->get_assignment_data($webworkcourse,$webworkset,false);
163 if(isset($webworksetdata)) { 151 if(isset($webworksetdata)) {
164 $wwassignment->name = get_string("set_name","wwassignment") . " " . $webworksetdata['set_id']; 152 $wwassignment->name = get_string('set_name','wwassignment') . ' ' . $webworksetdata['set_id'];
165 if($returnid = update_record("wwassignment",$wwassignment)) { 153 if($returnid = update_record('wwassignment',$wwassignment)) {
166 $event = NULL; 154 $event = NULL;
167 if($event->id = get_field('event','id','modulename','wwassignment','instance',$wwassignment->id)) { 155 if($event->id = get_field('event','id','modulename','wwassignment','instance',$wwassignment->id)) {
168 $event->name = get_string("set_name","wwassignment") . " " . $webworksetdata['set_id']; 156 $event->name = get_string('set_name','wwassignment') . ' ' . $webworksetdata['set_id'];
169 $event->timestart = $webworksetdata['due_date']; 157 $event->timestart = $webworksetdata['due_date'];
170 $rs = update_event($event); 158 $rs = update_event($event);
171 error_log("updating the event".$rs); 159 error_log('updating the event'.$rs);
172 } else { 160 } else {
173 $event = NULL; 161 $event = NULL;
174 $event->name = get_string("set_name","wwassignment") . " " . $webworksetdata['set_id']; 162 $event->name = get_string('set_name','wwassignment') . ' ' . $webworksetdata['set_id'];
175 $event->description = ""; 163 $event->description = '';
176 $event->courseid = $COURSE->id; 164 $event->courseid = $COURSE->id;
177 $event->groupid = 0; 165 $event->groupid = 0;
178 $event->userid = 0; 166 $event->userid = 0;
179 $event->modulename = 'wwassignment'; 167 $event->modulename = 'wwassignment';
180 $event->instance = $wwassignment->id; 168 $event->instance = $wwassignment->id;
194* @param integer $id The id of the assignment to delete. 182* @param integer $id The id of the assignment to delete.
195*/ 183*/
196function wwassignment_delete_instance($id) { 184function wwassignment_delete_instance($id) {
197 185
198 $result = true; 186 $result = true;
199 if (! $wwassignment = get_record("wwassignment", "id", "$id")) { 187 if (! $wwassignment = get_record('wwassignment', 'id', "$id")) {
200 return false; 188 return false;
201 } 189 }
202 190
203 # Delete any dependent records here # 191 # Delete any dependent records here #
204 192
205 if (! delete_records("wwassignment", "id", $wwassignment->id)) { 193 if (! delete_records('wwassignment', 'id', $wwassignment->id)) {
206 $result = false; 194 $result = false;
207 } 195 }
208 196
209 if (! delete_records('event', 'modulename', 'wwassignment', 'instance', $wwassignment->id)) { 197 if (! delete_records('event', 'modulename', 'wwassignment', 'instance', $wwassignment->id)) {
210 $result = false; 198 $result = false;
221 } 209 }
222 210
223 return $result; 211 return $result;
224} 212}
225 213
214/**
215* @desc Returns a small object with summary information about a wwassignment instance. Used for user activity repots.
216* @param string $course The ID of the course.
217* @param string $user The ID of the user.
218* @param string $wwassignment The ID of the wwassignment instance.
219* @return array Representing time, info pairing.
220*/
226function wwassignment_user_outline($course, $user, $mod, $wwassignment) { 221function wwassignment_user_outline($course, $user, $mod, $wwassignment) {
227/// Return a small object with summary information about what a
228/// user has done with a given particular instance of this module
229/// Used for user activity reports.
230/// $return->time = the time they did it
231/// $return->info = a short text description
232 $aLogs = get_logs("l.userid=$user AND l.course=$course AND l.cmid={$wwassignment->id}"); 222 $aLogs = get_logs("l.userid=$user AND l.course=$course AND l.cmid={$wwassignment->id}");
233 if( count($aLogs) > 0 ) { 223 if( count($aLogs) > 0 ) {
234 $return->time = $aLogs[0]->time; 224 $return->time = $aLogs[0]->time;
235 $return->info = $aLogs[0]->info; 225 $return->info = $aLogs[0]->info;
236 } 226 }
237 return $return; 227 return $return;
238} 228}
239 229
230/**
231* @desc Prints a detailed representation of what a user has done with a instance of this module.
232* @param string $course The ID of the course.
233* @param string $user The ID of the user.
234* @param string $wwassignment The ID of the wwassignment instance.
235* @return array Representing time, info pairing.
236*/
240function wwassignment_user_complete($course, $user, $mod, $wwassignment) { 237function wwassignment_user_complete($course, $user, $mod, $wwassignment) {
241/// Print a detailed representation of what a user has done with
242/// a given particular instance of this module, for user activity reports.
243
244 return true; 238 return true;
245} 239}
246 240
241/**
242* @desc Finds recent activity taht has occured in wwassignment activities.
243*/
247function wwassignment_print_recent_activity($course, $isteacher, $timestart) { 244function wwassignment_print_recent_activity($course, $isteacher, $timestart) {
248/// Given a course and a time, this module should find recent activity
249/// that has occurred in wwassignment activities and print it out.
250/// Return true if there was output, or false is there was none.
251
252 global $CFG; 245 global $CFG;
253 246
254 return false; // True if anything was printed, otherwise false 247 return false; // True if anything was printed, otherwise false
255} 248}
256 249
250/**
251* @desc Function that is run by the cron job.
252*/
257function wwassignment_cron () { 253function wwassignment_cron () {
258/// Function to be run periodically according to the moodle cron
259/// This function searches for things that need to be done, such
260/// as sending out mail, toggling flags etc ...
261
262 global $CFG;
263
264 return true; 254 return true;
265} 255}
256
266/** 257/**
267* @desc Contacts webwork to find out the completion status of a problem set for all users in a course. 258* @desc Contacts webwork to find out the completion status of a problem set for all users in a course.
268* @param integer $wwassignmentid The problem set 259* @param integer $wwassignmentid The problem set
269*/ 260*/
270function wwassignment_grades($wwassignmentid) { 261function wwassignment_grades($wwassignmentid) {
299 $finalgrade = 0.0; 290 $finalgrade = 0.0;
300 } 291 }
301 $studentgrades->grades[$student->id] = $finalgrade; 292 $studentgrades->grades[$student->id] = $finalgrade;
302 } 293 }
303 294
304 $studentgrades->maxgrade = $webworkclient->get_max_grade($webworkcourse,$webworkset); 295 $studentgrades->maxgrade = $webworkclient->get_max_grade($webworkcourse,$webworkset);
305 //error_log("all grades".print_r($studentgrades, true));
306
307 return $studentgrades; 296 return $studentgrades;
308} 297}
309 298
310/** 299/**
311* @desc Finds all the participants in the course 300* @desc Finds all the participants in the course
312* @param string $wwassignmentid The Moodle wwassignment ID. 301* @param string $wwassignmentid The Moodle wwassignment ID.
313* @return array An array of course users (IDs). 302* @return array An array of course users (IDs).
314*/ 303*/
315function wwassignment_get_participants($wwassignmentid) { 304function wwassignment_get_participants($wwassignmentid) {
316 $wwassignment = get_record("wwassignment", "id", $wwassignmentid); 305 $wwassignment = get_record('wwassignment', 'id', $wwassignmentid);
317 if(!isset($wwassignment)) { 306 if(!isset($wwassignment)) {
318 return array(); 307 return array();
319 } 308 }
320 return get_course_users($wwassignment->course); 309 return get_course_users($wwassignment->course);
321} 310}
322 311
323function wwassignment_refresh_events($courseid = 0) { 312function wwassignment_refresh_events($courseid = 0) {
324 error_log("wwassignment_refresh_events called"); 313 error_log('wwassignment_refresh_events called');
325 if ($courseid == 0) { 314 if ($courseid == 0) {
326 if (! $wwassignment = get_records("wwassignment")) { 315 if (! $wwassignment = get_records('wwassignment')) {
327 return true; 316 return true;
328 } 317 }
329 } else { 318 } else {
330 if (! $wwassignment = get_records("wwassignment", "course", $courseid)) { 319 if (! $wwassignment = get_records('wwassignment', 'course', $courseid)) {
331 return true; 320 return true;
332 } 321 }
333 } 322 }
334 $moduleid = get_field('modules', 'id', 'name', 'wwassignment'); 323 $moduleid = get_field('modules', 'id', 'name', 'wwassignment');
335 324
378 $wwassignmentbridge = get_record('wwassignment_bridge','course', $courseid); 367 $wwassignmentbridge = get_record('wwassignment_bridge','course', $courseid);
379 if((isset($wwassignmentbridge)) && (isset($wwassignmentbridge->webwork_course))) { 368 if((isset($wwassignmentbridge)) && (isset($wwassignmentbridge->webwork_course))) {
380 return $wwassignmentbridge->webwork_course; 369 return $wwassignmentbridge->webwork_course;
381 } 370 }
382 if(!$silent) { 371 if(!$silent) {
383 print_error(get_string("webwork_map_failure","wwassignment") . " No WeBWorK course is mapped for this course."); 372 print_error(get_string('webwork_course_map_failure','wwassignment'));
384 } 373 }
385 return -1; 374 return -1;
386} 375}
387 376
388/** 377/**
395 $wwassignment = get_record('wwassignment','id',$wwassignmentid); 384 $wwassignment = get_record('wwassignment','id',$wwassignmentid);
396 if((isset($wwassignment)) && (isset($wwassignment->webwork_set))) { 385 if((isset($wwassignment)) && (isset($wwassignment->webwork_set))) {
397 return $wwassignment->webwork_set; 386 return $wwassignment->webwork_set;
398 } 387 }
399 if(!$silent) { 388 if(!$silent) {
400 print_error(get_string("webwork_map_failure","wwassignment") . " No WeBWorK set is mapped for this set."); 389 print_error(get_string('webwork_set_map_failure','wwassignment'));
401 } 390 }
402 return -1; 391 return -1;
403} 392}
404 393
405//////////////////////////////////////////////////////////////// 394////////////////////////////////////////////////////////////////
485 if (!array_key_exists($class, $instances)) { 474 if (!array_key_exists($class, $instances)) {
486 // does not yet exist, save in array 475 // does not yet exist, save in array
487 $this->client = new soap_client(WWASSIGNMENT_WEBWORK_WSDL,'wsdl'); 476 $this->client = new soap_client(WWASSIGNMENT_WEBWORK_WSDL,'wsdl');
488 $err = $this->client->getError(); 477 $err = $this->client->getError();
489 if ($err) { 478 if ($err) {
490 print_error("Constructor Error $err"); 479 print_error(get_string('construction_error','wwassignment'));
491 } 480 }
492 $this->defaultparams = array(); 481 $this->defaultparams = array();
493 $this->defaultparams['authenKey'] = WWASSIGNMENT_WEBWORK_KEY; 482 $this->defaultparams['authenKey'] = WWASSIGNMENT_WEBWORK_KEY;
494 $this->datacache = array(); 483 $this->datacache = array();
495 $this->mappingcache = array(); 484 $this->mappingcache = array();
515 $params = array_merge($this->defaultparams,$params); 504 $params = array_merge($this->defaultparams,$params);
516 } 505 }
517 $result = $this->client->call($functioncall,$params); 506 $result = $this->client->call($functioncall,$params);
518 //$result = call_user_func_array(array(&$this->client,$functioncall),$params); 507 //$result = call_user_func_array(array(&$this->client,$functioncall),$params);
519 if($err = $this->client->getError()) { 508 if($err = $this->client->getError()) {
520 print_error(get_string("rpc_fault","wwassignment") . " " . $functioncall. " ". $err); 509 //print_error(get_string("rpc_fault","wwassignment') . " " . $functioncall. " ". $err);
510 print_error(get_string('rpc_error','wwassignment'));
521 } 511 }
522 return $result; 512 return $result;
523 } 513 }
524 514
525 /** 515 /**
531 */ 521 */
532 function mapped_user($webworkcourse,$webworkuser,$silent = true) { 522 function mapped_user($webworkcourse,$webworkuser,$silent = true) {
533 if(isset($this->mappingcache[$webworkcourse]['user'][$webworkuser])) { 523 if(isset($this->mappingcache[$webworkcourse]['user'][$webworkuser])) {
534 return $this->mappingcache[$webworkcourse]['user'][$webworkuser]; 524 return $this->mappingcache[$webworkcourse]['user'][$webworkuser];
535 } 525 }
536 $record = $this->handler('get_user',array("courseName" => $webworkcourse,"userID" => $webworkuser)); 526 $record = $this->handler('get_user',array('courseName' => $webworkcourse,'userID' => $webworkuser));
537 if($record != -1) { 527 if($record != -1) {
538 $this->mappingcache[$webworkcourse]['user'][$webworkuser] = $webworkuser; 528 $this->mappingcache[$webworkcourse]['user'][$webworkuser] = $webworkuser;
539 return $webworkuser; 529 return $webworkuser;
540 } 530 }
541 if(!$silent) { 531 if(!$silent) {
542 print_error(get_string("webwork_map_failure","wwassignment") . "The user $webworkuser was not found in the webwork course $webworkcourse."); 532 print_error(get_string('webwork_user_map_failure',"wwassignment"));
543 } 533 }
544 return -1; 534 return -1;
545 } 535 }
546 536
547 /** 537 /**
554 */ 544 */
555 function mapped_user_set($webworkcourse,$webworkuser,$webworkset,$silent = true) { 545 function mapped_user_set($webworkcourse,$webworkuser,$webworkset,$silent = true) {
556 if(isset($this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset])) { 546 if(isset($this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset])) {
557 return $this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset]; 547 return $this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset];
558 } 548 }
559 $record = $this->handler("get_user_set",array("courseName" => $webworkcourse,"userID" => $webworkuser,"setID" => $webworkset)); 549 $record = $this->handler('get_user_set',array('courseName' => $webworkcourse,'userID' => $webworkuser,'setID' => $webworkset));
560 if($record != -1) { 550 if($record != -1) {
561 $this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset] = 1; 551 $this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset] = 1;
562 return 1; 552 return 1;
563 } 553 }
564 554
565 if(!$silent) { 555 if(!$silent) {
566 print_error(get_string("webwork_map_failure","wwassignment") . "The user $webworkuser does not have copies of the set $webworkset in webwork course $webworkcourse."); 556 print_error(get_string('webwork_user_set_map_failure','wwassignment'));
567 } 557 }
568 return -1; 558 return -1;
569 } 559 }
570 560
571 /** 561 /**
574 * @param string $webworkset The webwork set name. 564 * @param string $webworkset The webwork set name.
575 * @param integer $silent whether to trigger an error message 565 * @param integer $silent whether to trigger an error message
576 * @return array Returns set information on success or -1 on failure. 566 * @return array Returns set information on success or -1 on failure.
577 */ 567 */
578 function get_assignment_data($webworkcourse,$webworkset,$silent = true) { 568 function get_assignment_data($webworkcourse,$webworkset,$silent = true) {
579 $record = $this->handler("get_global_set",array('courseName' => $webworkcourse, 'setID' => $webworkset)); 569 $record = $this->handler('get_global_set',array('courseName' => $webworkcourse, 'setID' => $webworkset));
580 if(isset($record)) { 570 if(isset($record)) {
581 $setinfo = array(); 571 $setinfo = array();
582 $setinfo['open_date'] = $record->open_date; 572 $setinfo['open_date'] = $record->open_date;
583 $setinfo['due_date'] = $record->due_date; 573 $setinfo['due_date'] = $record->due_date;
584 $setinfo['set_id'] = $record->set_id; 574 $setinfo['set_id'] = $record->set_id;
585 $setinfo['name'] = get_string("set_name","wwassignment") . " " . $record->set_id; 575 $setinfo['name'] = get_string('set_name','wwassignment') . ' ' . $record->set_id;
586 return $setinfo; 576 return $setinfo;
587 } 577 }
588 if(!$silent) { 578 if(!$silent) {
589 print_error(get_string("webwork_map_failure","wwassignment") . "The set $webworkset was not found in webwork course $webworkcourse."); 579 print_error(get_string('webwork_set_map_failure','wwassignment'));
590 } 580 }
591 return -1; 581 return -1;
592 582
593 } 583 }
594 584
599 * @param string $webworkset The webwork set name. 589 * @param string $webworkset The webwork set name.
600 * @param integer $silent whether to trigger an error message 590 * @param integer $silent whether to trigger an error message
601 * @return array Returns an array of problems on success or -1 on failure. 591 * @return array Returns an array of problems on success or -1 on failure.
602 */ 592 */
603 function get_user_problems($webworkcourse,$webworkuser,$webworkset,$silent = true) { 593 function get_user_problems($webworkcourse,$webworkuser,$webworkset,$silent = true) {
604 $record = $this->handler("get_all_user_problems",array("courseName" => $webworkcourse,"userID" => $webworkuser,"setID" => $webworkset)); 594 $record = $this->handler('get_all_user_problems',array('courseName' => $webworkcourse,'userID' => $webworkuser,'setID' => $webworkset));
605 if(isset($record)) { 595 if(isset($record)) {
606 return $record; 596 return $record;
607 } 597 }
608 if(!$silent) { 598 if(!$silent) {
609 print_error(get_string("webwork_map_failure","wwassignment") . "The user $webworkuser does not have copies of the set $webworkset in webwork course $webworkcourse."); 599 print_error(get_string('webwork_user_set_map_failure','wwassignment'));
610 } 600 }
611 return -1; 601 return -1;
612 } 602 }
613 603
614 /** 604 /**
617 * @param string $webworkset The webwork set name. 607 * @param string $webworkset The webwork set name.
618 * @param integer $silent whether to trigger an error message 608 * @param integer $silent whether to trigger an error message
619 * @return integer The max grade on success or -1 on failure. 609 * @return integer The max grade on success or -1 on failure.
620 */ 610 */
621 function get_max_grade($webworkcourse,$webworkset,$silent = true) { 611 function get_max_grade($webworkcourse,$webworkset,$silent = true) {
622 $record = $this->handler('list_global_problems',array("courseName" => $webworkcourse,"setID" => $webworkset)); 612 $record = $this->handler('list_global_problems',array('courseName' => $webworkcourse,'setID' => $webworkset));
623 if(isset($record)) { 613 if(isset($record)) {
624 return count($record); 614 return count($record);
625 } 615 }
626 if(!$silent) { 616 if(!$silent) {
627 print_error(get_string("webwork_map_failure","wwassignment") . "The set $webworkset does not exist in webwork course $webworkcourse."); 617 print_error(get_string('webwork_set_map_failure','wwassignment'));
628 } 618 }
629 return -1; 619 return -1;
630 620
631 } 621 }
632 /** 622 /**
635 * @param string $webworkuser The webwork users name. 625 * @param string $webworkuser The webwork users name.
636 * @param integer $silent whether to trigger an error message 626 * @param integer $silent whether to trigger an error message
637 * @return string The webwork key for URL on success or -1 on failure. 627 * @return string The webwork key for URL on success or -1 on failure.
638 */ 628 */
639 function login_user($webworkcourse,$webworkuser,$silent = true) { 629 function login_user($webworkcourse,$webworkuser,$silent = true) {
640 $key = $this->handler("login_user",array("courseName" => $webworkcourse,"userID" => $webworkuser)); 630 $key = $this->handler('login_user',array('courseName' => $webworkcourse,'userID' => $webworkuser));
641 if(isset($key)) { 631 if(isset($key)) {
642 return $key; 632 return $key;
643 } 633 }
644 if(!$silent) { 634 if(!$silent) {
645 print_error(get_string("webwork_map_failure","wwassignment") . "The user $webworkuser cannot login to $webworkcourse."); 635 print_error(get_string('webwork_user_map_failure','wwassignment'));
646 } 636 }
647 return -1; 637 return -1;
648 } 638 }
649 639
650 /** 640 /**
652 * @param string $webworkcourse The webwork course name. 642 * @param string $webworkcourse The webwork course name.
653 * @param integer $silent whether to trigger an error message 643 * @param integer $silent whether to trigger an error message
654 * @return array The form options. 644 * @return array The form options.
655 */ 645 */
656 function options_set($webworkcourse,$silent = true) { 646 function options_set($webworkcourse,$silent = true) {
657 $setlist = $this->handler('list_global_sets',array("courseName" => $webworkcourse)); 647 $setlist = $this->handler('list_global_sets',array('courseName' => $webworkcourse));
658 if(isset($setlist)) { 648 if(isset($setlist)) {
659 $setoptions = array(); 649 $setoptions = array();
660 foreach($setlist as $setid) { 650 foreach($setlist as $setid) {
661 $setoptions[$setid] = $setid; 651 $setoptions[$setid] = $setid;
662 } 652 }
663 return $setoptions; 653 return $setoptions;
664 } 654 }
665 if(!$silent) { 655 if(!$silent) {
666 print_error(get_string("webwork_map_failure","wwassignment") . "Could not get sets from the course $webworkcourse."); 656 print_error(get_string('webwork_course_map_failure','wwassignment'));
667 } 657 }
668 return -1; 658 return -1;
669 } 659 }
670 660
671 /** 661 /**
672 * @desc Retrieves a list of courses from a webwork course and converts it into form options format. 662 * @desc Retrieves a list of courses from a webwork course and converts it into form options format.
673 * @param integer $silent whether to trigger an error message 663 * @param integer $silent whether to trigger an error message
674 * @return array The form options. 664 * @return array The form options.
675 */ 665 */
676 function options_course($silent = true) { 666 function options_course($silent = true) {
677 $courselist = $this->handler("list_courses"); 667 $courselist = $this->handler('list_courses');
678 if(isset($courselist)) { 668 if(isset($courselist)) {
679 $courseoptions = array(); 669 $courseoptions = array();
680 foreach($courselist as $course) { 670 foreach($courselist as $course) {
681 $courseoptions[$course] = $course; 671 $courseoptions[$course] = $course;
682 } 672 }
683 return $courseoptions; 673 return $courseoptions;
684 } 674 }
685 if(!$silent) { 675 if(!$silent) {
686 print_error(get_string("webwork_map_failure","wwassignment") . "Could not get list of courses."); 676 print_error(get_string('webwork_course_list_map_failure','wwassignment'));
687 } 677 }
688 return -1; 678 return -1;
689 679
690 } 680 }
691 681
694 * @param string $webworkcourse The webwork course name. 684 * @param string $webworkcourse The webwork course name.
695 * @param array $userdata The user data to use in creation. 685 * @param array $userdata The user data to use in creation.
696 * @param string $permission The permissions of the new user, defaults to 0. 686 * @param string $permission The permissions of the new user, defaults to 0.
697 * @return Returns 1 on success. 687 * @return Returns 1 on success.
698 */ 688 */
699 function create_user($webworkcourse,&$userdata,$permission="0") { 689 function create_user($webworkcourse,&$userdata,$permission='0') {
700 $studentid = $userid; 690 $studentid = $userid;
701 $this->handler("add_user",array("courseName" => $webworkcourse, "record" => array( 691 $this->handler('add_user',array('courseName' => $webworkcourse, 'record' => array(
702 "user_id" => $userdata->username, 692 'user_id' => $userdata->username,
703 "first_name" => $userdata->firstname, 693 'first_name' => $userdata->firstname,
704 "last_name" => $userdata->lastname, 694 'last_name' => $userdata->lastname,
705 "email_address" => $userdata->emailaddress, 695 'email_address' => $userdata->emailaddress,
706 "student_id" => $studentid, 696 'student_id' => $studentid,
707 "status" => "C", 697 'status' => 'C',
708 "section" => "", 698 'section' => '',
709 "recitation" => "", 699 'recitation' => '',
710 "comment" => "moodle created user"))); 700 'comment' => 'moodle created user')));
711 $this->handler("add_permission",array("courseName" => $webworkcourse,"record" => array( 701 $this->handler('add_permission',array('courseName' => $webworkcourse,'record' => array(
712 "user_id" => $userdata->username, 702 'user_id' => $userdata->username,
713 "permission" => $permission))); 703 'permission' => $permission)));
714 $this->handler("add_password",array("courseName" => $webworkcourse,"record" => array( 704 $this->handler('add_password',array('courseName' => $webworkcourse,'record' => array(
715 "user_id" => $userdata->username, 705 'user_id' => $userdata->username,
716 "password" => $studentid))); 706 'password' => $studentid)));
717 return 1; 707 return 1;
718 } 708 }
719 709
720 /** 710 /**
721 * @desc Creates a user set in WeBWorK 711 * @desc Creates a user set in WeBWorK
723 * @param string $webworkuser The webwork user name. 713 * @param string $webworkuser The webwork user name.
724 * @param string $webworkset The webwork set name. 714 * @param string $webworkset The webwork set name.
725 * @return Returns 1 on success. 715 * @return Returns 1 on success.
726 */ 716 */
727 function create_user_set($webworkcourse,$webworkuser,$webworkset) { 717 function create_user_set($webworkcourse,$webworkuser,$webworkset) {
728 $this->handler("assign_set_to_user",array("courseName" => $webworkcourse,"userID" => $webworkuser, "setID" => $webworkset)); 718 $this->handler('assign_set_to_user',array('courseName' => $webworkcourse,'userID' => $webworkuser, 'setID' => $webworkset));
729 return 1; 719 return 1;
730 } 720 }
731}; 721};
732 722
733?> 723?>

Legend:
Removed from v.5108  
changed lines
  Added in v.5109

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9