forked from openwebwork/wwassignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocallib.php
More file actions
707 lines (640 loc) · 28.4 KB
/
locallib.php
File metadata and controls
707 lines (640 loc) · 28.4 KB
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
<?php
global $CFG,$DB;
#require_once("$CFG->libdir/soap/nusoap.php");
require_once("$CFG->libdir/soaplib.php");
define('WWASSIGNMENT_DEBUG',0);
// define('WWASSIGNMENT_DEBUG',1);
//////////////////////////////////////////////////////////////////
//Utility functions
//////////////////////////////////////////////////////////////////
/**
* @desc prints message to the apache log
* @param string message
**/
function debugLog($message) {
if (WWASSIGNMENT_DEBUG) {
error_log($message);
var_dump($message);
}
}
/** (reference from accesslib.php )
* @desc gets all the users assigned this role in this context or higher
* @param int roleid (can also be an array of ints!)
* @param int contextid
* @param bool parent if true, get list of users assigned in higher context too
* @param string fields - fields from user (u.) , role assignment (ra) or role (r.)
* @param string sort - sort from user (u.) , role assignment (ra) or role (r.)
* @param bool gethidden - whether to fetch hidden enrolments too
* @return array()
*/
//function get_role_users($roleid, $context, $parent=false, $fields='', $sort='u.lastname ASC', $gethidden=true, $group='', $limitfrom='', $limitnum='') {
/**
* @desc Finds all of the users in the course
* @param $courseid -- the course id
* @return record containing user information ( username, userid)
*/
function _wwassignment_get_course_students($courseid) {
debugLog("Begin get_course_students($courseid )");
debugLog("courseID is ". print_r($courseid, true));
$context = context_course::instance($courseid);
debugLog("context is ". print_r($context, true));
$users = array();
$roles_used_in_context = get_roles_used_in_context($context);
//debugLog("roles used ". print_r($roles_used_in_context, true));
foreach($roles_used_in_context as $role) {
$roleid = $role->id;
debugLog( "roleid should be 5 for a student $roleid");
//debugLog(get_role_users($roleid, $context, true) );
if ($new_users = get_role_users($roleid, $context, true) ) {
$users = array_merge($users, $new_users );//FIXME a user could be liseted twice
}
debugLog("display users ".print_r($users,true));
}
debugLog("display users in course--on");
debugLog("users again".print_r($users, true));
debugLog("End get_course_students($courseid )");
return $users;
}
//////////////////////////////////////////////////////////////////
//EVENT CREATION AND DELETION
//////////////////////////////////////////////////////////////////
/**
* @desc Creates the corresponding events for a wwassignment.
* @param $wwsetname string The name of the set.
* @param $wwassignmentid string The ID of the wwassignment record.
* @param $opendate integer The UNIX timestamp of the open date.
* @param $duedate integer The UNIX timestamp of the due date.
* @return integer 0 on success. -1 on error.
*/
function _wwassignment_create_events($wwassignment,$wwsetdata ) {
// error_log("enter create_events for set ".$wwassignment->name." id ".$wwassignment->id." date ".$wwsetdata['open_date']." ".$wwsetdata['due_date'] );
global $COURSE;
//error_log("set data".print_r($wwsetdata,true));
if (! $opendate = $wwsetdata['open_date'] ) {
// error_log(" undefined open date ");
}
if (! $duedate = $wwsetdata["due_date"] ){
// error_log(" undefined due date ");
}
if (! $wwassignmentid = $wwassignment->id ) {
// error_log(" undefined ww id ");
}
if (! $name = $wwassignment->name ) {
// error_log(" undefined set name ");
}
$courseid = $wwassignment->course;
if (!$courseid) {
$courseid =$COURSE->id;
}
unset($event);
$event = new \stdClass();
$event->name = $name;
$event->description = 'WeBWorK Set Event';
$event->courseid = $courseid;
$event->groupid = 0;
$event->userid = 0;
$event->format = 1;
$event->modulename = 'wwassignment';
$event->instance = $wwassignmentid;
$event->visible = 1;
$event->eventtype = 'due';
$event->timestart = $duedate;
$event->timeduration = 1;
// error_log("adding a due event");
$result = 0;
// $calendareventid = add_event($event); //calendar_event::create($event);//
global $CFG;
require_once("$CFG->dirroot/calendar/lib.php");
$calendareventid = calendar_event::create($event);
// error_log("calendareventid $calendareventid created");
if(!$calendareventid) {
// error_log("can't create calendarevent for set $wwsetname wwid $wwassignmentid date $opendate $duedate course $courseid");
$result = -1;
}
return $result;
}
/**
* @desc Deletes all events relating to the wwassignment passed in.
* @param $wwassignmentid integer The wwassignment ID.
* @return integer 0 on success
*/
function _wwassignment_delete_events($wwassignmentid) {
global $DB, $CFG;
if ($events = $DB->get_records_select('event', "modulename = 'wwassignment' and instance = '$wwassignmentid'")) {
foreach($events as $event) {
// error_log("deleting event ".$event->id);
require_once("$CFG->dirroot/calendar/lib.php");
$calEvent = new calendar_event($event);
$calEvent->delete(true);
//delete_event($event->id);
}
}
return 0;
}
function _wwassignment_refresh_event($wwassignment) {
global $DB;
$cid = $wwassignment->course;
$wwcoursename = _wwassignment_mapped_course($cid,false);
if ( $wwcoursename== -1) {
error_log("Can't connect course $cid to webwork");
return false;
}
$wwclient = new wwassignment_client();
$wwsetname = $wwassignment->webwork_set;
error_log("updating events for $wwcoursename $wwsetname");
//get data from WeBWorK
$wwsetdata = $wwclient->get_assignment_data($wwcoursename,$wwsetname,false);
$wwassignment->grade = $wwclient->get_max_grade($wwcoursename,$wwsetname,false);
$wwassignment->timemodified = time();
$returnid = $DB->update_record('wwassignment',$wwassignment);
// update event
_wwassignment_delete_events($wwassignment->id);
_wwassignment_create_events($wwassignment,$wwsetdata);
return true;
}
//////////////////////////////////////////////////////////////////
//Functions that ensure creation of WeBWorK Data
//////////////////////////////////////////////////////////////////
/**
* @desc Checks whether a user exists in a WW course. If it doesnt creates the user using the currently logged in one.
* @param $wwcoursename string The WW course.
* @param $username string The username to check.
* @param $permission string The permission the user needs if created.
* @return string the new username.
*/
function _wwassignment_mapcreate_user($wwcoursename,$username,$permission = '0') {
$wwclient = new wwassignment_client();
$exists = $wwclient->mapped_user($wwcoursename,$username);
if($exists == -1) {
global $USER;
$tempuser = $USER;
$newusername = $wwclient->create_user($wwcoursename,$tempuser,$permission);
return $newusername;
}
return $username;
}
/**
* @desc Checks whether a set exists for a user in a WW course. If it doesnt autocreates.
* @param $wwcoursename string The WW course.
* @param $wwusername string The WW user.
* @param $wwsetname string The WW set.
* @return integer 0.
*/
function _wwassignment_mapcreate_user_set($wwcoursename,$wwusername,$wwsetname) {
$wwclient = new wwassignment_client();
$exists = $wwclient->mapped_user_set($wwcoursename,$wwusername,$wwsetname);
if($exists == -1) {
$wwclient->create_user_set($wwcoursename,$wwusername,$wwsetname);
}
return 0;
}
/**
* @desc Makes sure that a user is logged in to WW.
* @param $wwcoursename string The course to login to.
* @param $wwusername string The user to login.
* @return string The users key for WW.
*/
function _wwassignment_login_user($wwcoursename,$wwusername) {
$wwclient = new wwassignment_client();
return $wwclient->login_user($wwcoursename,$wwusername,false);
}
////////////////////////////////////////////////////////////////
//functions that check mapping existance in the local db
////////////////////////////////////////////////////////////////
/**
@desc Find the id of the wwassignment module class
*@param none
*@return id
*/
function _wwassignment_cmid() {
global $DB;
$wwassignment = $DB->get_record('modules', array( 'name'=>'wwassignment' ));
return $wwassignment->id;
}
/**
* @desc Finds the webwork course name from a moodle course id.
* @param integer $courseid Moodle Course ID.
* @param integer $silent whether to trigger an error message.
* @return string the name of the webwork course on success and -1 on failure.
*/
function _wwassignment_mapped_course($courseid,$silent = true) {
global $DB;
$blockinstance = $DB->get_record('block_instances', array(
'blockname'=>'wwlink',
'parentcontextid'=>context_course::instance($courseid)->id,
'pagetypepattern'=>'course-view-*' ));
//error_log("block instance".print_r($blockinstance,true));
$block_config = unserialize(base64_decode($blockinstance->configdata));
//error_log("config_data ".print_r($block_config,true));
if ( isset($block_config) && isset($block_config->wwlink_id) ) {
return $block_config->wwlink_id;
} else {
return -1;
}
}
/**
* @desc Finds the webwork set name from a wwassignment id.
* @param integer $wwassignmentid Moodle wwassignment ID.
* @param integer $silent whether to trigger an error message.
* @return string the name of the webwork set on success and -1 on failure.
*/
function _wwassignment_mapped_set($wwassignmentid,$silent = true) {
global $DB;
$wwassignment = $DB->get_record('wwassignment', array('id'=>$wwassignmentid ));
if((isset($wwassignment)) && (isset($wwassignment->webwork_set))) {
return $wwassignment->webwork_set;
}
if(!$silent) {
print_error('webwork_set_map_failure','wwassignment');
}
return -1;
}
////////////////////////////////////////////////////////////////
//functions that create links to the webwork site.
////////////////////////////////////////////////////////////////
/**
* @desc Returns URL link to a webwork course logging the user in.
* @param string $webworkcourse The webwork course.
* @param string $webworkset The webwork set.
* @param string $webworkuser The webwork user.
* @param string $key The key used to login the user.
* @return URL.
*/
function _wwassignment_link_to_edit_set_auto_login($webworkcourse,$webworkset,$username,$key) {
return _wwassignment_link_to_course($webworkcourse) . "instructor/sets/$webworkset/?effectiveUser=$username&user=$username&key=$key";
}
/**
* @desc Returns URL link to a webwork course logging the user in.
* @param string $webworkcourse The webwork course.
* @param string $webworkuser The webwork user.
* @param string $key The key used to login the user.
* @return URL.
*/
function _wwassignment_link_to_instructor_auto_login($webworkcourse,$username,$key) {
return _wwassignment_link_to_course($webworkcourse) . "instructor/?effectiveUser=$username&user=$username&key=$key";
}
/**
* @desc Returns the URL link to a webwork course and a particular set logged in.
* @param string $webworkcourse The webwork course.
* @param string $webworkset The webwork set.
* @param string $webworkuser The webwork user.
* @param string $key The key used to login the user.
* @return URL.
*/
function _wwassignment_link_to_set_auto_login($webworkcourse,$webworkset,$webworkuser,$key) {
return _wwassignment_link_to_set($webworkcourse,$webworkset) . "?effectiveUser=$webworkuser&user=$webworkuser&key=$key";
}
/**
* @desc Returns the URL link to a webwork course and a particular set.
* @param string $webworkcourse The webwork course.
* @param string $webworkset The webwork set.
* @return URL.
*/
function _wwassignment_link_to_set($webworkcourse,$webworkset) {
return _wwassignment_link_to_course($webworkcourse) . "$webworkset/";
}
/**
* @desc Returns the URL link to a webwork course.
* @param string $webworkcourse The webwork course.
* @return URL.
*/
function _wwassignment_link_to_course($webworkcourse) {
global $CFG;
return $CFG->wwassignment_webworkurl."/$webworkcourse/";
}
///////////////////////////////////////////////////////////////
//wwassignment client class
///////////////////////////////////////////////////////////////
/**
* @desc This singleton class acts as the gateway for all communication from the Moodle Client to the WeBWorK SOAP Server.
* It encapsulates an instance of a SoapClient.
*/
class wwassignment_client {
var $client;
var $defaultparams;
var $datacache;
var $mappingcache;
/**
* @desc Constructs a singleton webwork_client.
*/
function __construct()
{
global $CFG;
// static associative array containing the real objects, key is classname
static $instances=array();
// get classname
$class = get_class($this);
if (!array_key_exists($class, $instances)) {
// does not yet exist, save in array
# $this->client = new SoapClient($CFG->wwassignment_rpc_wsdl,'wsdl');
$this->client = soap_connect($CFG->wwassignment_rpc_wsdl);
# $err = $this->client->getError();
# if ($err) {
# error_log($err);
# error_log($CFG->wwassignment_rpc_wsdl);
# print_error('construction_error','wwassignment');
# }
$this->defaultparams = array();
$this->defaultparams['authenKey'] = $CFG->wwassignment_rpc_key;
$this->datacache = array();
$this->mappingcache = array();
$instances[$class] = $this;
}
foreach (get_class_vars($class) as $var => $value) {
$this->$var =& $instances[$class]->$var;
}
}
/**
*@desc Calls a SOAP function and passes (authenkey,course) automatically in the parameter list.
*@param string $functioncall The function to call
*@param array $params The parameters to the function.
*@param integer $override=false whether to override the default parameters that are passed to the soap function (authenKey).
*@return Result of the soap function.
*/
function handler($functioncall,$params=array(),$override=false) {
if(!is_array($params)) {
$params = array($params);
}
if(!$override) {
$params = array_merge($this->defaultparams,$params);
}
if(WWASSIGNMENT_DEBUG) {
echo "Called: $functioncall <br>";
echo "Params: ";
var_dump($params);
echo "<br>";
}
$result = $this->client->__soapCall($functioncall,$params);
//$result = call_user_func_array(array(&$this->client,$functioncall),$params);
# if($err = $this->client->getError()) {
# //print_error(get_string("rpc_fault","wwassignment') . " " . $functioncall. " ". $err);
# print_error('rpc_error','wwassignment');
# }
return $result;
}
/**
* @desc Checks whether a user is in a webwork course.
* @param string $webworkcourse The webwork course name.
* @param string $webworkuser The webwork user name.
* @param integer $silent whether to trigger an error message
* @return string Returns the webwork user on success and -1 on failure.
*/
function mapped_user($webworkcourse,$webworkuser,$silent = true) {
if(isset($this->mappingcache[$webworkcourse]['user'][$webworkuser])) {
return $this->mappingcache[$webworkcourse]['user'][$webworkuser];
}
$record = $this->handler('get_user',array('courseName' => $webworkcourse,'userID' => $webworkuser));
if( is_a($record,'stdClass') ) {
$this->mappingcache[$webworkcourse]['user'][$webworkuser] = $webworkuser;
return $webworkuser;
}
if(!$silent) {
print_error('webwork_user_map_failure',"wwassignment");
}
return -1;
}
/**
* @desc Checks whether a user has his own copy of a set built in a webwork course.
* @param string $webworkcourse The webwork course name.
* @param string $webworkuser The webwork user name.
* @param string $webworkset The webwork set name.
* @param integer $silent whether to trigger an error message
* @return integer Returns 1 on success and -1 on failure.
*/
function mapped_user_set($webworkcourse,$webworkuser,$webworkset,$silent = true) {
if(isset($this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset])) {
return $this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset];
}
$record = $this->handler('get_user_set',array('courseName' => $webworkcourse,'userID' => $webworkuser,'setID' => $webworkset));
if(is_a($record,'stdClass')) {
$this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset] = 1;
return 1;
}
if(!$silent) {
print_error('webwork_user_set_map_failure','wwassignment');
}
return -1;
}
/**
* @desc Gets the record of the global set for a webwork course and set name.
* @param string $webworkcourse The webwork course name.
* @param string $webworkset The webwork set name.
* @param integer $silent whether to trigger an error message
* @return array Returns set information on success or -1 on failure.
*/
function get_assignment_data($webworkcourse,$webworkset,$silent = true) {
$record = $this->handler('get_global_set',array('courseName' => $webworkcourse, 'setID' => $webworkset));
if(isset($record)) {
$setinfo = array();
$setinfo['open_date'] = $record->open_date;
$setinfo['due_date'] = $record->due_date;
$setinfo['set_id'] = $record->set_id;
$setinfo['name'] = $record->set_id;
return $setinfo;
}
if(!$silent) {
print_error('webwork_set_map_failure','wwassignment');
}
return -1;
}
/**
* @desc Gets all the user problems for a specfic course, user and set.
* @param string $webworkcourse The webwork course name.
* @param string $webworkuser The webwork users name.
* @param string $webworkset The webwork set name.
* @param integer $silent whether to trigger an error message
* @return array Returns an array of problems on success or -1 on failure.
*/
function get_user_problems($webworkcourse,$webworkuser,$webworkset,$silent = true) {
$record = $this->handler('get_all_user_problems',array('courseName' => $webworkcourse,'userID' => $webworkuser,'setID' => $webworkset));
if(isset($record)) {
return $record;
}
if(!$silent) {
print_error('webwork_user_set_map_failure','wwassignment');
}
return -1;
}
/**
* @desc Calculates the max grade on a set by counting the number of problems in the set.
* @param string $webworkcourse The webwork course name.
* @param string $webworkset The webwork set name.
* @param integer $silent whether to trigger an error message
* @return integer The max grade on success or -1 on failure.
*/
//FIXME -- this assumes each problem gets 1 point which is false
// function get_max_grade($webworkcourse,$webworkset,$silent = true) {
// $record = $this->handler('list_global_problems',array('courseName' => $webworkcourse,'setID' => $webworkset));
// if(isset($record)) {
// return count($record);
// }
// if(!$silent) {
// print_error('webwork_set_map_failure','wwassignment');
// }
// return -1;
//
// }
function get_max_grade($webworkcourse,$webworkset,$silent = true) {
$record = $this->handler('get_all_global_problems',array('courseName' => $webworkcourse,'setID' => $webworkset));
$totalpoints =0;
if(isset($record)) {
foreach ($record as $set) {
$totalpoints = $totalpoints + $set->value;
}
return $totalpoints;
}
if(!$silent) {
print_error('webwork_set_map_failure','wwassignment');
}
return -1;
}
/**
* @desc Forces a login of a user into a course.
* @param string $webworkcourse The webwork course name.
* @param string $webworkuser The webwork users name.
* @param integer $silent whether to trigger an error message
* @return string The webwork key for URL on success or -1 on failure.
*/
function login_user($webworkcourse,$webworkuser,$silent = true) {
$key = $this->handler('login_user',array('courseName' => $webworkcourse,'userID' => $webworkuser));
if(isset($key)) {
return $key;
}
if(!$silent) {
print_error('webwork_user_map_failure','wwassignment');
}
return -1;
}
/**
* @desc Retrieves a list of sets from a webwork course and converts it into form options format.
* @param string $webworkcourse The webwork course name.
* @param integer $silent whether to trigger an error message
* @return array The form options.
*/
function options_set($webworkcourse,$silent = true) {
$setlist = $this->handler('list_global_sets',array('courseName' => $webworkcourse));
if(isset($setlist)) {
$setoptions = array();
foreach($setlist as $setid) {
$setoptions[$setid] = $setid;
}
return $setoptions;
}
if(!$silent) {
print_error('webwork_course_map_failure','wwassignment');
}
return -1;
}
/**
* @desc Retrieves a list of courses from a webwork course and converts it into form options format.
* @param integer $silent whether to trigger an error message
* @return array The form options.
*/
function options_course($silent = true) {
$courselist = $this->handler('list_courses');
sort($courselist);
if(isset($courselist)) {
$courseoptions = array();
foreach($courselist as $course) {
$courseoptions[$course] = $course;
}
return $courseoptions;
}
if(!$silent) {
print_error('webwork_course_list_map_failure','wwassignment');
}
return -1;
}
/**
* @desc Creates a user in the WeBWorK course.
* @param string $webworkcourse The webwork course name.
* @param array $userdata The user data to use in creation.
* @param string $permission The permissions of the new user, defaults to 0.
* @return Returns username on success.
*/
function create_user($webworkcourse,&$userdata,$permission='0') {
$studentid = $userid;
# FIXME: find permission for this user and set permissions appropriately in webwork
# FIXME: find the group(s) that this person is a member of
# FIXME: I have used the following scheme: gage_SEC use groups ending like this to determine sections in webwork
# FIXME: use ordinary groups taName to correspond to recitation sections in WeBWorK
#
# FIXME: make it so an update_user function is called whenever the user data in moodle is changed
# FIXME: so if a student switches groups this is reflected in WeBWorK
$this->handler('add_user',array('courseName' => $webworkcourse, 'record' => array(
'user_id' => $userdata->username,
'first_name' => $userdata->firstname,
'last_name' => $userdata->lastname,
'email_address' => $userdata->email,
'student_id' => $studentid,
'status' => 'C',
'section' => '',
'recitation' => '',
'comment' => 'moodle created user')));
$this->handler('add_permission',array('courseName' => $webworkcourse,'record' => array(
'user_id' => $userdata->username,
'permission' => $permission)));
$this->handler('add_password',array('courseName' => $webworkcourse,'record' => array(
'user_id' => $userdata->username,
'password' => $userdata->password)));
return $userdata->username;
}
/** NOT yet ready!!!!!!!!!
* @desc Updates data for a user in the WeBWorK course.
* @param string $webworkcourse The webwork course name.
* @param array $userdata The user data to use in creation.
* @param string $permission The permissions of the new user, defaults to 0.
* @return Returns username on success.
*/
function update_user($webworkcourse,&$userdata,$permission='0') {
error_log("update_user called -- not yet ready");
$studentid = $userid;
# FIXME: find permission for this user and set permissions appropriately in webwork
# FIXME: find the group(s) that this person is a member of
# FIXME: I have used the following scheme: gage_SEC use groups ending like this to determine sections in webwork
# FIXME: use ordinary groups taName to correspond to recitation sections in WeBWorK
#
# FIXME: make it so an update_user function is called whenever the user data in moodle is changed
# FIXME: so if a student switches groups this is reflected in WeBWorK
# do get_user first to get current status then update this??
$this->handler('put_user',array('courseName' => $webworkcourse, 'record' => array(
//'user_id' => $userdata->username, // can't update this
'first_name' => $userdata->firstname,
'last_name' => $userdata->lastname,
'email_address' => $userdata->email,
'student_id' => $studentid,
//'status' => 'C', //can you update this from moodle?
'section' => '',
'recitation' => '',
'comment' => 'moodle updated user')));
$this->handler('add_permission',array('courseName' => $webworkcourse,'record' => array(
'user_id' => $userdata->username,
'permission' => $permission)));
$this->handler('add_password',array('courseName' => $webworkcourse,'record' => array(
'user_id' => $userdata->username,
'password' => $userdata->password)));
return $userdata->username;
}
/**
* @desc Creates a user set in WeBWorK
* @param string $webworkcourse The webwork course name.
* @param string $webworkuser The webwork user name.
* @param string $webworkset The webwork set name.
* @return Returns 1 on success.
*/
function create_user_set($webworkcourse,$webworkuser,$webworkset) {
$this->handler('assign_set_to_user',array('courseName' => $webworkcourse,'userID' => $webworkuser, 'setID' => $webworkset));
return 1;
}
/**
* @desc Finds grades of many users for one set.
* @param string $webworkcourse The webwork course name.
* @param array $webworkusers A list of webwork users
* @param string $webworkset The webwork set name
* @return array Returns an array of grades
*/
function grade_users_sets($webworkcourse,$webworkusers,$webworkset) {
return $this->handler('grade_users_sets',array('courseName' => $webworkcourse, 'userIDs' => $webworkusers, 'setID' => $webworkset));
}
};
?>