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 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
|
<?PHP // $Id: lib.php,v 1.1 23 Aug 2003
// workshop constants and standard Moodle functions plus the workshop functions
// called by the standard functions
// see also locallib.php for other non-standard workshop functions
include_once("$CFG->dirroot/files/mimetypes.php");
/*** Constants **********************************/
$WORKSHOP_TYPE = array (0 => get_string("notgraded", "workshop"),
1 => get_string("accumulative", "workshop"),
2 => get_string("errorbanded", "workshop"),
3 => get_string("criterion", "workshop"),
4 => get_string("rubric", "workshop") );
$WORKSHOP_SHOWGRADES = array (0 => get_string("dontshowgrades", "workshop"),
1 => get_string("showgrades", "workshop") );
$WORKSHOP_SCALES = array(
0 => array( 'name' => get_string("scaleyes", "workshop"), 'type' => 'radio',
'size' => 2, 'start' => get_string("yes"), 'end' => get_string("no")),
1 => array( 'name' => get_string("scalepresent", "workshop"), 'type' => 'radio',
'size' => 2, 'start' => get_string("present", "workshop"),
'end' => get_string("absent", "workshop")),
2 => array( 'name' => get_string("scalecorrect", "workshop"), 'type' => 'radio',
'size' => 2, 'start' => get_string("correct", "workshop"),
'end' => get_string("incorrect", "workshop")),
3 => array( 'name' => get_string("scalegood3", "workshop"), 'type' => 'radio',
'size' => 3, 'start' => get_string("good", "workshop"),
'end' => get_string("poor", "workshop")),
4 => array( 'name' => get_string("scaleexcellent4", "workshop"), 'type' => 'radio',
'size' => 4, 'start' => get_string("excellent", "workshop"),
'end' => get_string("verypoor", "workshop")),
5 => array( 'name' => get_string("scaleexcellent5", "workshop"), 'type' => 'radio',
'size' => 5, 'start' => get_string("excellent", "workshop"),
'end' => get_string("verypoor", "workshop")),
6 => array( 'name' => get_string("scaleexcellent7", "workshop"), 'type' => 'radio',
'size' => 7, 'start' => get_string("excellent", "workshop"),
'end' => get_string("verypoor", "workshop")),
7 => array( 'name' => get_string("scale10", "workshop"), 'type' => 'selection',
'size' => 10),
8 => array( 'name' => get_string("scale20", "workshop"), 'type' => 'selection',
'size' => 20),
9 => array( 'name' => get_string("scale100", "workshop"), 'type' => 'selection',
'size' => 100));
$WORKSHOP_EWEIGHTS = array( 0 => -4.0, 1 => -2.0, 2 => -1.5, 3 => -1.0, 4 => -0.75, 5 => -0.5, 6 => -0.25,
7 => 0.0, 8 => 0.25, 9 => 0.5, 10 => 0.75, 11=> 1.0, 12 => 1.5, 13=> 2.0,
14 => 4.0);
$WORKSHOP_FWEIGHTS = array( 0 => 0, 1 => 0.1, 2 => 0.25, 3 => 0.5, 4 => 0.75, 5 => 1.0, 6 => 1.5,
7 => 2.0, 8 => 3.0, 9 => 5.0, 10 => 7.5, 11=> 10.0, 12=>50.0);
if (!defined("COMMENTSCALE")) {
define("COMMENTSCALE", 20);
}
/*** Standard Moodle functions ******************
workshop_add_instance($workshop)
workshop_cron ()
workshop_delete_instance($id)
workshop_grades($workshopid)
workshop_print_recent_activity(&$logs, $isteacher=false)
workshop_refresh_events($workshop)
workshop_update_instance($workshop)
workshop_user_complete($course, $user, $mod, $workshop)
workshop_user_outline($course, $user, $mod, $workshop)
**********************************************/
///////////////////////////////////////////////////////////////////////////////
function workshop_add_instance($workshop) {
// 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.
$workshop->timemodified = time();
$workshop->deadline = make_timestamp($workshop->deadlineyear,
$workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour,
$workshop->deadlineminute);
if ($returnid = insert_record("workshop", $workshop)) {
$event = NULL;
$event->name = $workshop->name;
$event->description = $workshop->description;
$event->courseid = $workshop->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'workshop';
$event->instance = $returnid;
$event->eventtype = 'deadline';
$event->timestart = $workshop->deadline;
$event->timeduration = 0;
add_event($event);
}
return $returnid;
}
///////////////////////////////////////////////////////////////////////////////
function workshop_cron () {
// Function to be run periodically according to the moodle cron
global $CFG, $USER;
// Find all workshop notifications that have yet to be mailed out, and mails them
$cutofftime = time() - $CFG->maxeditingtime;
// look for new assessments
if ($assessments = workshop_get_unmailed_assessments($cutofftime)) {
$timenow = time();
foreach ($assessments as $assessment) {
echo "Processing workshop assessment $assessment->id\n";
// only process the entry once
if (! set_field("workshop_assessments", "mailed", "1", "id", "$assessment->id")) {
echo "Could not update the mailed field for id $assessment->id\n";
}
if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
if (! $workshop = get_record("workshop", "id", $submission->workshopid)) {
echo "Could not find workshop id $submission->workshopid\n";
continue;
}
if (! $course = get_record("course", "id", $workshop->course)) {
error("Could not find course id $workshop->course");
continue;
}
if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) {
error("Course Module ID was incorrect");
continue;
}
if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
echo "Could not find user $submission->userid\n";
continue;
}
if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) {
echo "Could not find user $assessment->userid\n";
continue;
}
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id,
$submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id,
$assessmentowner->id)) {
continue; // Not an active participant
}
// don't sent self assessment
if ($submissionowner->id == $assessmentowner->id) {
continue;
}
$strworkshops = get_string("modulenameplural", "workshop");
$strworkshop = get_string("modulename", "workshop");
// it's an assessment, tell the submission owner
$USER->lang = $submissionowner->lang;
$sendto = $submissionowner;
// "Your assignment \"$submission->title\" has been assessed by"
if (isstudent($course->id, $assessmentowner->id)) {
$msg = get_string("mail1", "workshop", $submission->title)." a $course->student.\n";
}
else {
$msg = get_string("mail1", "workshop", $submission->title).
" ".fullname($assessmentowner)."\n";
}
// "The comments and grade can be seen in the workshop assignment '$workshop->name'
$msg .= get_string("mail2", "workshop", $workshop->name)."\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
// "You can see it in your workshop assignment"
$posttext .= get_string("mail3", "workshop").":\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n";
$posttext .= "---------------------------------------------------------------------\n";
if ($sendto->mailformat == 1) { // HTML
$posthtml = "<P><FONT FACE=sans-serif>".
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A></FONT></P>";
$posthtml .= "<HR><FONT FACE=sans-serif>";
$posthtml .= "<P>$msg</P>";
$posthtml .= "<P>".get_string("mail3", "workshop").
" <A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A>.</P></FONT><HR>";
} else {
$posthtml = "";
}
if (!$teacher = get_teacher($course->id)) {
echo "Error: can not find teacher for course $course->id!\n";
}
if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) {
echo "Error: workshop cron: Could not send out mail for id $submission->id to
user $sendto->id ($sendto->email)\n";
}
}
}
// look for new assessments of resubmissions
if ($assessments = workshop_get_unmailed_resubmissions($cutofftime)) {
$timenow = time();
foreach ($assessments as $assessment) {
echo "Processing workshop assessment $assessment->id\n";
// only process the entry once
if (! set_field("workshop_assessments", "mailed", "1", "id", "$assessment->id")) {
echo "Could not update the mailed field for id $assessment->id\n";
}
if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
if (! $workshop = get_record("workshop", "id", $submission->workshopid)) {
echo "Could not find workshop id $submission->workshopid\n";
continue;
}
if (! $course = get_record("course", "id", $workshop->course)) {
error("Could not find course id $workshop->course");
continue;
}
if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) {
error("Course Module ID was incorrect");
continue;
}
if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
echo "Could not find user $submission->userid\n";
continue;
}
if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) {
echo "Could not find user $assessment->userid\n";
continue;
}
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id,
$submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id,
$assessmentowner->id)) {
continue; // Not an active participant
}
$strworkshops = get_string("modulenameplural", "workshop");
$strworkshop = get_string("modulename", "workshop");
// it's a resubission assessment, tell the assessment owner to (re)assess
$USER->lang = $assessmentowner->lang;
$sendto = $assessmentowner;
// "The assignment \"$submission->title\" is a revised piece of work. "
$msg = get_string("mail8", "workshop", $submission->title)."\n";
// "Please assess it in the workshop assignment '$workshop->name'
$msg .= get_string("mail9", "workshop", $workshop->name)."\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
// "You can assess it in your workshop assignment"
$posttext .= get_string("mail10", "workshop").":\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n";
$posttext .= "---------------------------------------------------------------------\n";
if ($sendto->mailformat == 1) { // HTML
$posthtml = "<P><FONT FACE=sans-serif>".
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A></FONT></P>";
$posthtml .= "<HR><FONT FACE=sans-serif>";
$posthtml .= "<P>$msg</P>";
$posthtml .= "<P>".get_string("mail3", "workshop").
" <A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A>.</P></FONT><HR>";
}
else {
$posthtml = "";
}
if (!$teacher = get_teacher($course->id)) {
echo "Error: can not find teacher for course $course->id!\n";
}
if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) {
echo "Error: workshop cron: Could not send out mail for id $submission->id to
user $sendto->id ($sendto->email)\n";
}
}
}
// look for new comments
if ($comments = workshop_get_unmailed_comments($cutofftime)) {
$timenow = time();
foreach ($comments as $comment) {
echo "Processing workshop comment $comment->id\n";
// only process the entry once
if (! set_field("workshop_comments", "mailed", "1", "id", "$comment->id")) {
echo "Could not update the mailed field for comment id $comment->id\n";
}
if (! $assessment = get_record("workshop_assessments", "id", "$comment->assessmentid")) {
echo "Could not find assessment $comment->assessmentid\n";
continue;
}
if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
if (! $workshop = get_record("workshop", "id", $submission->workshopid)) {
echo "Could not find workshop id $submission->workshopid\n";
continue;
}
if (! $course = get_record("course", "id", $workshop->course)) {
error("Could not find course id $workshop->course");
continue;
}
if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) {
error("Course Module ID was incorrect");
continue;
}
if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
echo "Could not find user $submission->userid\n";
continue;
}
if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) {
echo "Could not find user $assessment->userid\n";
continue;
}
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id,
$submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id,
$assessmentowner->id)) {
continue; // Not an active participant
}
$strworkshops = get_string("modulenameplural", "workshop");
$strworkshop = get_string("modulename", "workshop");
// see if the submission owner needs to be told
if ($comment->userid != $submission->userid) {
$USER->lang = $submissionowner->lang;
$sendto = $submissionowner;
// "A comment has been added to the assignment \"$submission->title\" by
if (isstudent($course->id, $assessmentowner->id)) {
$msg = get_string("mail4", "workshop", $submission->title)." a $course->student.\n";
}
else {
$msg = get_string("mail4", "workshop", $submission->title)." ".fullname($assessmentowner)."\n";
}
// "The new comment can be seen in the workshop assignment '$workshop->name'
$msg .= get_string("mail5", "workshop", $workshop->name)."\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
// "You can see it in your workshop assignment"
$posttext .= get_string("mail3", "workshop").":\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n";
$posttext .= "---------------------------------------------------------------------\n";
if ($sendto->mailformat == 1) { // HTML
$posthtml = "<P><FONT FACE=sans-serif>".
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A></FONT></P>";
$posthtml .= "<HR><FONT FACE=sans-serif>";
$posthtml .= "<P>$msg</P>";
$posthtml .= "<P>".get_string("mail3", "workshop").
" <A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A>
.</P></FONT><HR>";
}
else {
$posthtml = "";
}
if (!$teacher = get_teacher($course->id)) {
echo "Error: can not find teacher for course $course->id!\n";
}
if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) {
echo "Error: workshop cron: Could not send out mail for id $submission->id to user
$sendto->id ($sendto->email)\n";
}
}
// see if the assessor needs to to told
if ($comment->userid != $assessment->userid) {
$USER->lang = $assessmentowner->lang;
$sendto = $assessmentowner;
// "A comment has been added to the assignment \"$submission->title\" by
if (isstudent($course->id, $submissionowner->id)) {
$msg = get_string("mail4", "workshop", $submission->title)." a $course->student.\n";
}
else {
$msg = get_string("mail4", "workshop", $submission->title).
" ".fullname($submissionowner)."\n";
}
// "The new comment can be seen in the workshop assignment '$workshop->name'
$msg .= get_string("mail5", "workshop", $workshop->name)."\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
// "You can see it in your workshop assignment"
$posttext .= get_string("mail3", "workshop").":\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n";
$posttext .= "---------------------------------------------------------------------\n";
if ($sendto->mailformat == 1) { // HTML
$posthtml = "<P><FONT FACE=sans-serif>".
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A></FONT></P>";
$posthtml .= "<HR><FONT FACE=sans-serif>";
$posthtml .= "<P>$msg</P>";
$posthtml .= "<P>".get_string("mail3", "workshop").
" <A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A>.</P></FONT><HR>";
}
else {
$posthtml = "";
}
if (!$teacher = get_teacher($course->id)) {
echo "Error: can not find teacher for course $course->id!\n";
}
if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) {
echo "Error: workshop cron: Could not send out mail for id $submission->id to user
$sendto->id ($sendto->email)\n";
}
if (! set_field("workshop_comments", "mailed", "1", "id", "$comment->id")) {
echo "Could not update the mailed field for comment id $comment->id\n";
}
}
}
}
// look for new gradings
if ($assessments = workshop_get_unmailed_graded_assessments($cutofftime)) {
$timenow = time();
foreach ($assessments as $assessment) {
echo "Processing workshop assessment $assessment->id (graded)\n";
// only process the entry once
if (! set_field("workshop_assessments", "mailed", "1", "id", "$assessment->id")) {
echo "Could not update the mailed field for id $assessment->id\n";
}
if (! $submission = get_record("workshop_submissions", "id", "$assessment->submissionid")) {
echo "Could not find submission $assessment->submissionid\n";
continue;
}
if (! $workshop = get_record("workshop", "id", $submission->workshopid)) {
echo "Could not find workshop id $submission->workshopid\n";
continue;
}
if (! $course = get_record("course", "id", $workshop->course)) {
error("Could not find course id $workshop->course");
continue;
}
if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) {
error("Course Module ID was incorrect");
continue;
}
if (! $submissionowner = get_record("user", "id", "$submission->userid")) {
echo "Could not find user $submission->userid\n";
continue;
}
if (! $assessmentowner = get_record("user", "id", "$assessment->userid")) {
echo "Could not find user $assessment->userid\n";
continue;
}
if (! isstudent($course->id, $submissionowner->id) and !isteacher($course->id,
$submissionowner->id)) {
continue; // Not an active participant
}
if (! isstudent($course->id, $assessmentowner->id) and !isteacher($course->id,
$assessmentowner->id)) {
continue; // Not an active participant
}
$strworkshops = get_string("modulenameplural", "workshop");
$strworkshop = get_string("modulename", "workshop");
// it's a grading tell the assessment owner
$USER->lang = $assessmentowner->lang;
$sendto = $assessmentowner;
// Your assessment of the assignment \"$submission->title\" has by reviewed
$msg = get_string("mail6", "workshop", $submission->title).".\n";
// The comments given by the $course->teacher can be seen in the Workshop Assignment
$msg .= get_string("mail7", "workshop", $course->teacher)." '$workshop->name'.\n\n";
$postsubject = "$course->shortname: $strworkshops: $workshop->name";
$posttext = "$course->shortname -> $strworkshops -> $workshop->name\n";
$posttext .= "---------------------------------------------------------------------\n";
$posttext .= $msg;
// "You can see it in your workshop assignment"
$posttext .= get_string("mail3", "workshop").":\n";
$posttext .= " $CFG->wwwroot/mod/workshop/view.php?id=$cm->id\n";
$posttext .= "---------------------------------------------------------------------\n";
if ($sendto->mailformat == 1) { // HTML
$posthtml = "<P><FONT FACE=sans-serif>".
"<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/index.php?id=$course->id\">$strworkshops</A> ->".
"<A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A></FONT></P>";
$posthtml .= "<HR><FONT FACE=sans-serif>";
$posthtml .= "<P>$msg</P>";
$posthtml .= "<P>".get_string("mail3", "workshop").
" <A HREF=\"$CFG->wwwroot/mod/workshop/view.php?id=$cm->id\">$workshop->name</A>.</P></FONT><HR>";
} else {
$posthtml = "";
}
if (!$teacher = get_teacher($course->id)) {
echo "Error: can not find teacher for course $course->id!\n";
}
if (! email_to_user($sendto, $teacher, $postsubject, $posttext, $posthtml)) {
echo "Error: workshop cron: Could not send out mail for id $submission->id to user
$sendto->id ($sendto->email)\n";
}
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
function workshop_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 (! $workshop = get_record("workshop", "id", "$id")) {
return false;
}
// delete all the associated records in the workshop tables, start positive...
$result = true;
if (! delete_records("workshop_comments", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_grades", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_elements", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_assessments", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop_submissions", "workshopid", "$workshop->id")) {
$result = false;
}
if (! delete_records("workshop", "id", "$workshop->id")) {
$result = false;
}
if (! delete_records('event', 'modulename', 'workshop', 'instance', $workshop->id)) {
$result = false;
}
return $result;
}
///////////////////////////////////////////////////////////////////////////////
function workshop_grades($workshopid) {
/// Must return an array of grades, indexed by user, and a max grade.
/// only retruns grades in phase 6
global $CFG;
if ($workshop = get_record("workshop", "id", $workshopid)) {
if ($workshop->phase == 6) {
if ($bestsubmissions = get_records_sql("SELECT userid, max(finalgrade) finalgrade FROM
{$CFG->prefix}workshop_submissions WHERE workshopid = $workshopid GROUP
BY userid")) {
foreach ($bestsubmissions as $bestgrade) {
$return->grades[$bestgrade->userid] = $bestgrade->finalgrade;
}
}
}
$return->maxgrade = $workshop->grade;
}
return $return;
}
function workshop_is_recent_activity($course, $isteacher, $timestart) {//jlw1 added for adding mark to courses with activity in My Moodle
global $CFG;
// have a look for agreed assessments for this user (agree)
$agreecontent = false;
if (!$isteacher) { // teachers only need to see submissions
if ($logs = workshop_get_agree_logs($course, $timestart)) {
// got some, see if any belong to a visible module
foreach ($logs as $log) {
// Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$agreecontent = true;
break;
}
}
}
}
return false;
}
///////////////////////////////////////////////////////////////////////////////
function workshop_print_recent_activity($course, $isteacher, $timestart) {
global $CFG;
// have a look for agreed assessments for this user (agree)
$agreecontent = false;
if (!$isteacher) { // teachers only need to see submissions
if ($logs = workshop_get_agree_logs($course, $timestart)) {
// got some, see if any belong to a visible module
foreach ($logs as $log) {
// Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$agreecontent = true;
break;
}
}
// if we got some "live" ones then output them
if ($agreecontent) {
$strftimerecent = get_string("strftimerecent");
print_headline(get_string("workshopagreedassessments", "workshop").":");
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$date = userdate($log->time, $strftimerecent);
if (isteacher($course->id, $log->userid)) {
echo "<p><font size=1>$date - ".fullname($log)."<br />";
}
else { // don't break anonymous rule
echo "<p><font size=1>$date - A $course->student<br />";
}
echo "\"<a href=\"$CFG->wwwroot/mod/workshop/$log->url\">";
echo "$log->name";
echo "</a>\"</font></p>";
}
}
}
}
}
// have a look for new assessments for this user (assess)
$assesscontent = false;
if (!$isteacher) { // teachers only need to see submissions
if ($logs = workshop_get_assess_logs($course, $timestart)) {
// got some, see if any belong to a visible module
foreach ($logs as $log) {
// Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$assesscontent = true;
break;
}
}
// if we got some "live" ones then output them
if ($assesscontent) {
$strftimerecent = get_string("strftimerecent");
print_headline(get_string("workshopassessments", "workshop").":");
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$date = userdate($log->time, $strftimerecent);
if (isteacher($course->id, $log->userid)) {
echo "<p><font size=1>$date - ".fullname($log)."<br />";
}
else { // don't break anonymous rule
echo "<p><font size=1>$date - A $course->student<br />";
}
echo "\"<a href=\"$CFG->wwwroot/mod/workshop/$log->url\">";
echo "$log->name";
echo "</a>\"</font></p>";
}
}
}
}
}
// have a look for new comments for this user (comment)
$commentcontent = false;
if (!$isteacher) { // teachers only need to see submissions
if ($logs = workshop_get_comment_logs($course, $timestart)) {
// got some, see if any belong to a visible module
foreach ($logs as $log) {
// Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$commentcontent = true;
break;
}
}
// if we got some "live" ones then output them
if ($commentcontent) {
$strftimerecent = get_string("strftimerecent");
print_headline(get_string("workshopcomments", "workshop").":");
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$date = userdate($log->time, $strftimerecent);
echo "<p><font size=1>$date - A $course->student<br />";
echo "\"<a href=\"$CFG->wwwroot/mod/workshop/$log->url\">";
echo "$log->name";
echo "</a>\"</font></p>";
}
}
}
}
}
// have a look for new assessment gradings for this user (grade)
$gradecontent = false;
if ($logs = workshop_get_grade_logs($course, $timestart)) {
// got some, see if any belong to a visible module
foreach ($logs as $log) {
// Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$gradecontent = true;
break;
}
}
// if we got some "live" ones then output them
if ($gradecontent) {
$strftimerecent = get_string("strftimerecent");
print_headline(get_string("workshopfeedback", "workshop").":");
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$date = userdate($log->time, $strftimerecent);
echo "<p><font size=1>$date - $course->teacher<br />";
echo "\"<a href=\"$CFG->wwwroot/mod/workshop/$log->url\">";
echo "$log->name";
echo "</a>\"</font></p>";
}
}
}
}
// have a look for new submissions (only show to teachers) (submit)
$submitcontent = false;
if ($isteacher) {
if ($logs = workshop_get_submit_logs($course, $timestart)) {
// got some, see if any belong to a visible module
foreach ($logs as $log) {
// Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$submitcontent = true;
break;
}
}
// if we got some "live" ones then output them
if ($submitcontent) {
$strftimerecent = get_string("strftimerecent");
print_headline(get_string("workshopsubmissions", "workshop").":");
foreach ($logs as $log) {
//Create a temp valid module structure (only need courseid, moduleid)
$tempmod->course = $course->id;
$tempmod->id = $log->workshopid;
//Obtain the visible property from the instance
if (instance_is_visible("workshop",$tempmod)) {
$date = userdate($log->time, $strftimerecent);
echo "<p><font size=1>$date - ".fullname($log)."<br />";
echo "\"<a href=\"$CFG->wwwroot/mod/workshop/$log->url\">";
echo "$log->name";
echo "</a>\"</font></p>";
}
}
}
}
}
return $agreecontent or $assesscontent or $commentcontent or $gradecontent or $submitcontent;
}
///////////////////////////////////////////////////////////////////////////////
function workshop_refresh_events($courseid = 0) {
// This standard function will check all instances of this module
// and make sure there are up-to-date events created for each of them.
// If courseid = 0, then every workshop event in the site is checked, else
// only workshop events belonging to the course specified are checked.
// This function is used, in its new format, by restore_refresh_events()
if ($courseid == 0) {
if (! $workshops = get_records("workshop")) {
return true;
}
} else {
if (! $workshops = get_records("workshop", "course", $courseid)) {
return true;
}
}
$moduleid = get_field('modules', 'id', 'name', 'workshop');
foreach ($workshops as $workshop) {
$event = NULL;
$event->name = addslashes($workshop->name);
$event->description = addslashes($workshop->description);
$event->timestart = $workshop->deadline;
if ($event->id = get_field('event', 'id', 'modulename', 'workshop', 'instance', $workshop->id)) {
update_event($event);
} else {
$event->courseid = $workshop->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'workshop';
$event->instance = $workshop->id;
$event->eventtype = 'deadline';
$event->timeduration = 0;
$event->visible = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $workshop->id);
add_event($event);
}
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
function workshop_update_instance($workshop) {
// 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.
$workshop->timemodified = time();
$workshop->deadline = make_timestamp($workshop->deadlineyear,
$workshop->deadlinemonth, $workshop->deadlineday, $workshop->deadlinehour,
$workshop->deadlineminute);
$workshop->id = $workshop->instance;
if ($returnid = update_record("workshop", $workshop)) {
$event = NULL;
if ($event->id = get_field('event', 'id', 'modulename', 'workshop', 'instance', $workshop->id)) {
$event->name = $workshop->name;
$event->description = $workshop->description;
$event->timestart = $workshop->deadline;
update_event($event);
}
}
return $returnid;
}
///////////////////////////////////////////////////////////////////////////////
function workshop_user_complete($course, $user, $mod, $workshop) {
if ($submission = workshop_get_student_submission($workshop, $user)) {
if ($basedir = workshop_file_area($workshop, $user)) {
if ($files = get_directory_list($basedir)) {
$countfiles = count($files)." ".get_string("submissions", "workshop");
foreach ($files as $file) {
$countfiles .= "; $file";
}
}
}
print_simple_box_start();
//workshop_print_user_files($workshop, $user);
echo "Submission was made but no way to show you yet."; //xxx
//workshop_print_feedback($course, $submission);
print_simple_box_end();
} else {
print_string("notsubmittedyet", "workshop");
}
}
///////////////////////////////////////////////////////////////////////////////
function workshop_user_outline($course, $user, $mod, $workshop) {
if ($submissions = workshop_get_user_submissions($workshop, $user)) {
$result->info = count($submissions)." ".get_string("submissions", "workshop");
// workshop_get_user_submissions returns the newest one first
foreach ($submissions as $submission) {
$result->time = $submission->timecreated;
break;
}
return $result;
}
return NULL;
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_participants($workshopid) {
//Returns the users with data in one workshop
//(users with records in workshop_submissions, workshop_assessments and workshop_comments, students)
global $CFG;
//Get students from workshop_submissions
$st_submissions = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}workshop_submissions s
WHERE s.workshopid = '$workshopid' and
u.id = s.userid");
//Get students from workshop_assessments
$st_assessments = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}workshop_assessments a
WHERE a.workshopid = '$workshopid' and
u.id = a.userid");
//Get students from workshop_comments
$st_comments = get_records_sql("SELECT DISTINCT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}workshop_comments c
WHERE c.workshopid = '$workshopid' and
u.id = c.userid");
//Add st_assessments to st_submissions
if ($st_assessments) {
foreach ($st_assessments as $st_assessment) {
$st_submissions[$st_assessment->id] = $st_assessment;
}
}
//Add st_comments to st_submissions
if ($st_comments) {
foreach ($st_comments as $st_comment) {
$st_submissions[$st_comment->id] = $st_comment;
}
}
//Return st_submissions array (it contains an array of unique users)
return ($st_submissions);
}
function workshop_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid,
$workshop="0", $user="", $groupid="") {
// Returns all workshop posts since a given time. If workshop is specified then
// this restricts the results
global $CFG;
if ($workshop) {
$workshopselect = " AND cm.id = '$workshop'";
} else {
$workshopselect = "";
}
if ($user) {
$userselect = " AND u.id = '$user'";
} else {
$userselect = "";
}
$posts = get_records_sql("SELECT s.*, u.firstname, u.lastname,
u.picture, cm.instance, w.name, cm.section
FROM {$CFG->prefix}workshop_submissions s,
{$CFG->prefix}user u,
{$CFG->prefix}course_modules cm,
{$CFG->prefix}workshop w
WHERE s.timecreated > '$sincetime' $workshopselect
AND s.userid = u.id $userselect
AND w.course = '$courseid' $groupselect
AND cm.instance = w.id
AND cm.course = w.course
AND s.workshopid = w.id
ORDER BY s.id");
if (empty($posts)) {
return;
}
foreach ($posts as $post) {
if (empty($groupid) || ismember($groupid, $post->userid)) {
$tmpactivity->type = "workshop";
$tmpactivity->defaultindex = $index;
$tmpactivity->instance = $post->instance;
$tmpactivity->name = $post->name;
$tmpactivity->section = $post->section;
$tmpactivity->content->id = $post->id;
$tmpactivity->content->title = $post->title;
$tmpactivity->user->userid = $post->userid;
$tmpactivity->user->fullname = fullname($post);
$tmpactivity->user->picture = $post->picture;
$tmpactivity->timestamp = $post->timecreated;
$activities[] = $tmpactivity;
$index++;
}
}
return;
}
function workshop_print_recent_mod_activity($activity, $course, $detail=false) {
global $CFG;
echo '<table border="0" cellpadding="3" cellspacing="0">';
if ($activity->content->parent) {
$openformat = "<font size=\"2\"><i>";
$closeformat = "</i></font>";
} else {
$openformat = "<b>";
$closeformat = "</b>";
}
echo "<tr><td bgcolor=\"$THEME->cellcontent2\" class=\"workshoppostpicture\" width=\"35\" valign=\"top\">";
print_user_picture($activity->user->userid, $course, $activity->user->picture);
echo "</td><td>$openformat";
if ($detail) {
echo "<img src=\"$CFG->modpixpath/$activity->type/icon.gif\" ".
"height=16 width=16 alt=\"$activity->name\"> ";
}
echo "<a href=\"$CFG->wwwroot/mod/workshop/view.php?"
. "#" . $activity->content->id . "\">".$activity->content->title;
echo "</a>$closeformat";
echo "<br><font size=\"2\">";
echo "<a href=\"$CFG->wwwroot/user/view.php?id=" . $activity->user->userid . "&course=" . "$course\">"
. $activity->user->fullname . "</a>";
echo " - " . userdate($activity->timestamp) . "</font></td></tr>";
echo "</table>";
return;
}
//////////////////////////////////////////////////////////////////////////////////////
// Non-standard workshop functions
//////////////////////////////////////////////////////////////////////////////////////
function workshop_file_area($workshop, $submission) {
return make_upload_directory( workshop_file_area_name($workshop, $submission) );
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_file_area_name($workshop, $submission) {
// Creates a directory file name, suitable for make_upload_directory()
global $CFG;
return "$workshop->course/$CFG->moddata/workshop/$submission->id";
}
///////////////////////////////////////////////////////////////////////////////////////////////
function workshop_get_agree_logs($course, $timestart) {
// get the "agree" entries for this user (the assessment owner and add the first and last names
// the last two probably wont be used...
global $CFG, $USER;
if (empty($USER->id)) {
return false;
}
$timethen = time() - $CFG->maxeditingtime;
return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, a.userid, e.name
FROM {$CFG->prefix}log l,
{$CFG->prefix}workshop e,
{$CFG->prefix}workshop_submissions s,
{$CFG->prefix}workshop_assessments a,
{$CFG->prefix}user u
WHERE l.time > $timestart AND l.time < $timethen
AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'agree'
AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id
AND u.id = s.userid AND e.id = a.workshopid");
}
///////////////////////////////////////////////////////////////////////////////////////////////
function workshop_get_assess_logs($course, $timestart) {
// get the "assess" entries for this user and add the first and last names...
global $CFG, $USER;
if (empty($USER->id)) {
return false;
}
$timethen = time() - $CFG->maxeditingtime;
return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, a.userid, e.name
FROM {$CFG->prefix}log l,
{$CFG->prefix}workshop e,
{$CFG->prefix}workshop_submissions s,
{$CFG->prefix}workshop_assessments a,
{$CFG->prefix}user u
WHERE l.time > $timestart AND l.time < $timethen
AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'assess'
AND a.id = l.info AND s.id = a.submissionid AND s.userid = $USER->id
AND u.id = a.userid AND e.id = a.workshopid");
}
///////////////////////////////////////////////////////////////////////////////////////////////
function workshop_get_comment_logs($course, $timestart) {
// get the "comment" entries for this user and add the first and last names (which may not be used)...
global $CFG, $USER;
if (empty($USER->id)) {
return false;
}
$timethen = time() - $CFG->maxeditingtime;
return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, e.name
FROM {$CFG->prefix}log l,
{$CFG->prefix}workshop e,
{$CFG->prefix}workshop_submissions s,
{$CFG->prefix}workshop_assessments a,
{$CFG->prefix}workshop_comments c,
{$CFG->prefix}user u
WHERE l.time > $timestart AND l.time < $timethen
AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'comment'
AND c.id = l.info AND c.userid != $USER->id AND a.id = c.assessmentid
AND s.id = a.submissionid AND (s.userid = $USER->id OR a.userid = $USER->id)
AND u.id = a.userid AND e.id = a.workshopid");
}
///////////////////////////////////////////////////////////////////////////////////////////////
function workshop_get_grade_logs($course, $timestart) {
// get the "grade" entries for this user and add the first and last names (of submission owner,
// better to get name of teacher...
// ...but not available in assessment record...)
global $CFG, $USER;
if (empty($USER->id)) {
return false;
}
$timethen = time() - $CFG->maxeditingtime;
return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, a.workshopid, e.name
FROM {$CFG->prefix}log l,
{$CFG->prefix}workshop e,
{$CFG->prefix}workshop_submissions s,
{$CFG->prefix}workshop_assessments a,
{$CFG->prefix}user u
WHERE l.time > $timestart AND l.time < $timethen
AND l.course = $course->id AND l.module = 'workshop' AND l.action = 'grade'
AND a.id = l.info AND s.id = a.submissionid AND a.userid = $USER->id
AND u.id = s.userid AND e.id = a.workshopid");
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_student_submission($workshop, $user) {
// Return a submission for a particular user
global $CFG;
$submission = get_record("workshop_submissions", "workshopid", $workshop->id, "userid", $user->id);
if (!empty($submission->timecreated)) {
return $submission;
}
return NULL;
}
///////////////////////////////////////////////////////////////////////////////////////////////
function workshop_get_submit_logs($course, $timestart) {
// get the "submit" entries and add the first and last names...
global $CFG, $USER;
$timethen = time() - $CFG->maxeditingtime;
return get_records_sql("SELECT l.time, l.url, u.firstname, u.lastname, l.info as workshopid, e.name
FROM {$CFG->prefix}log l,
{$CFG->prefix}workshop e,
{$CFG->prefix}user u
WHERE l.time > $timestart AND l.time < $timethen
AND l.course = $course->id AND l.module = 'workshop'
AND l.action = 'submit'
AND e.id = l.info
AND u.id = l.userid");
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_unmailed_assessments($cutofftime) {
/// Return list of (ungraded) assessments that have not been mailed out
global $CFG;
return get_records_sql("SELECT a.*, g.course, g.name
FROM {$CFG->prefix}workshop_assessments a, {$CFG->prefix}workshop g
WHERE a.mailed = 0
AND a.timegraded = 0
AND a.timecreated < $cutofftime
AND g.id = a.workshopid");
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_unmailed_comments($cutofftime) {
/// Return list of comments that have not been mailed out
global $CFG;
return get_records_sql("SELECT c.*, g.course, g.name
FROM {$CFG->prefix}workshop_comments c, {$CFG->prefix}workshop g
WHERE c.mailed = 0
AND c.timecreated < $cutofftime
AND g.id = c.workshopid");
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_unmailed_graded_assessments($cutofftime) {
/// Return list of graded assessments that have not been mailed out
global $CFG;
return get_records_sql("SELECT a.*, g.course, g.name
FROM {$CFG->prefix}workshop_assessments a, {$CFG->prefix}workshop g
WHERE a.mailed = 0
AND a.timegraded < $cutofftime
AND a.timegraded > 0
AND g.id = a.workshopid");
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_unmailed_resubmissions($cutofftime) {
/// Return list of assessments of resubmissions that have not been mailed out
global $CFG;
return get_records_sql("SELECT a.*, w.course, w.name
FROM {$CFG->prefix}workshop_assessments a, {$CFG->prefix}workshop w
WHERE a.mailed = 0
AND a.resubmission = 1
AND w.id = a.workshopid");
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_student_submissions($workshop, $order = "title") {
// Return all ENROLLED student submissions
global $CFG;
if ($order == "title") {
$order = "s.title";
}
if ($order == "name") {
$order = "a.firstname, a.lastname";
}
if ($order == "grade") {
$order = "$workshop->teacherweight * s.teachergrade + $workshop->peerweight * s.peergrade DESC";
}
// make sure it works on the site course
$select = "u.course = '$workshop->course' AND";
$site = get_site();
if ($workshop->course == $site->id) {
$select = '';
}
return get_records_sql("SELECT s.* FROM {$CFG->prefix}workshop_submissions s,
{$CFG->prefix}user_students u, {$CFG->prefix}user a
WHERE $select s.userid = u.userid
AND a.id = u.userid
AND s.workshopid = $workshop->id
AND s.timecreated > 0
ORDER BY $order");
}
//////////////////////////////////////////////////////////////////////////////////////
function workshop_get_user_submissions($workshop, $user) {
// return real submissions of user newest first, oldest last. Ignores the dummy submissions
// which get created to hold the final grades for users for make no submissions)
return get_records_select("workshop_submissions", "workshopid = $workshop->id AND
userid = $user->id AND timecreated > 0", "timecreated DESC" );
}
?>
|