[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 4380 Revision 4381
1<?php 1<?php
2// $Id: lib.php,v 1.6 2006-07-26 21:27:27 gage Exp $ 2// $Id: lib.php,v 1.7 2006-08-14 19:34:14 sh002i Exp $
3//require_once("DB.php"); 3//require_once("DB.php");
4function debug_log($obj) { 4function debug_log($obj) {
5 $fh = fopen("/home/gage/moodle_debug", "w"); 5 $fh = fopen("/home/gage/moodle_debug", "w");
6 //fwrite($fh, "wwmoodle\n"); 6 //fwrite($fh, "wwmoodle\n");
7 $struct = print_r($obj, true); 7 $struct = print_r($obj, true);
107function wwassignment_add_instance($wwassignment) { 107function wwassignment_add_instance($wwassignment) {
108/// Given an object containing all the necessary data, 108/// Given an object containing all the necessary data,
109/// (defined by the form in mod.html) this function 109/// (defined by the form in mod.html) this function
110/// will create a new instance and return the id number 110/// will create a new instance and return the id number
111/// of the new instance. 111/// of the new instance.
112 $record = get_record("wwassignment_bridge", "course",$wwassignment->course);
113 if (! $record ) { #add bridge entry
114 // check if bridge exists
115 $wwassignment_bridge->timemodified = time();
116 $wwassignment_bridge->course = $wwassignment->course;
117 $wwassignment_bridge->coursename = _wwassignment_courseIdToShortName($wwassignment->course);
118 $wwassignment_bridge->name = $wwassignment_bridge->coursename;
119 if (! isset($wwassignment_bridge->coursename) ){
120 $wwassignment_bridge->coursename = "foo";
121 }
122// error_log("add entry to wwmoodle");
123// error_log(print_r($wwassignment, true));
124 $returnid = insert_record("wwassignment_bridge",$wwassignment_bridge);
125 error_log("inserting new entry to wwassignment_bridge id= $returnid");
126 }
127 # create set 112 # create set
128 $aSetInfo = _wwrpc_getSetInfo($wwassignment->set_id, wwassignment_courseIdToShortName($wwassignment->course)); 113 $aSetInfo = _wwrpc_getSetInfo($wwassignment->set_id, wwassignment_courseIdToShortName($wwassignment->course));
129 114
130 $wwassignment->timemodified = time(); 115 $wwassignment->timemodified = time();
131 $wwassignment->id = $wwassignment->instance; 116 $wwassignment->id = $wwassignment->instance;
488 //debug_log(print_r($row,true)); 473 //debug_log(print_r($row,true));
489 474
490 $res->free(); 475 $res->free();
491 return $row; 476 return $row;
492} 477}
478
493//////////////////////////////////////////////////////////////////////////////////// 479////////////////////////////////////////////////////////////////////////////////////
494// internal functions start with _wwassignment 480// internal functions start with _wwassignment
495/////////////////////////////////////////////////////////////////////////////////// 481///////////////////////////////////////////////////////////////////////////////////
496 482
497/** 483/**
561 } 547 }
562 $shortname = preg_replace("/[^a-zA-Z0-9]/", "", $c->shortname); 548 $shortname = preg_replace("/[^a-zA-Z0-9]/", "", $c->shortname);
563 return $shortname; 549 return $shortname;
564} 550}
565 551
566
567/** 552/**
568 * Returns a URL to the specified set. 553 * Returns a URL to the specified set.
569 * @param int $iSetId The set ID to link to. 554 * @param int $iSetId The set ID to link to.
570 * @param string $sCourseName The name of this course. 555 * @param string $sCourseName The name of this course.
571 * @return string The URL to the specified set. This might be absolute, or relative. However, it is assured of working. 556 * @return string The URL to the specified set. This might be absolute, or relative. However, it is assured of working.
572 */ 557 */
573function _wwassignment_linkToSet($iSetId, $sCourseName) { 558function _wwassignment_linkToSet($iSetId, $sCourseName) {
574 // TODO: Verify me. 559 // TODO: Verify me.
575 return WWASSIGNMENT_WEBWORK_URL."/$sCourseName/$iSetId"; 560 return WWASSIGNMENT_WEBWORK_URL."/$sCourseName/$iSetId";
576} 561}
562
563/**
564 * Checks for a wwassignment_bridge record for the given course, creates one if it does not exist.
565 * @param int $iCourseID The ID of the course.
566 * @return void
567 */
568function _wwassignment_ensureBridgeExists($iCourseID) {
569 $wwassignment_bridge = get_record("wwassignment_bridge", "course", $iCourseID);
570 if (!$wwassignment_bridge) {
571 $wwassignment_bridge->timemodified = time();
572 $wwassignment_bridge->course = $iCourseID;
573 $wwassignment_bridge->coursename = _wwassignment_courseIdToShortName($iCourseID);
574 $wwassignment_bridge->name = $wwassignment_bridge->coursename;
575 if (!isset($wwassignment_bridge->coursename)) {
576 $wwassignment_bridge->coursename = "foo";
577 }
578 $returnid = insert_record("wwassignment_bridge",$wwassignment_bridge);
579 error_log("inserting new entry to wwassignment_bridge id=$returnid");
580 }
581}
582
577?> 583?>

Legend:
Removed from v.4380  
changed lines
  Added in v.4381

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9