[Hw4mdl-svn] SF.net SVN: hw4mdl: [9] trunk/moodle/mod
Brought to you by:
jhlinder,
trollinger
From: <hu...@us...> - 2006-04-21 13:42:55
|
Revision: 9 Author: hugues Date: 2006-04-21 06:42:47 -0700 (Fri, 21 Apr 2006) ViewCVS: http://svn.sourceforge.net/hw4mdl/?rev=9&view=rev Log Message: ----------- Voice Direct can now be updated from within moodle. Modified Paths: -------------- trunk/moodle/mod/voicedirect/lib.php trunk/moodle/mod/voicedirect/view.php trunk/moodle/mod/voicetoolapi.php Modified: trunk/moodle/mod/voicedirect/lib.php =================================================================== --- trunk/moodle/mod/voicedirect/lib.php 2006-04-21 08:26:27 UTC (rev 8) +++ trunk/moodle/mod/voicedirect/lib.php 2006-04-21 13:42:47 UTC (rev 9) @@ -33,7 +33,7 @@ //print_r($data); - if (!$result = voicedirect_create_resource ($data)) { + if (!$result = voicetool_create_resource ($data)) { error('Cannot create the resource on the VT server'); } @@ -46,7 +46,7 @@ $voicedirect->rid = $rid; - return insert_record("voicedirect", $voicedirect); + return insert_record('voicedirect', $voicedirect); } @@ -54,13 +54,29 @@ /// 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. + global $USER; $voicedirect->timemodified = time(); $voicedirect->id = $voicedirect->instance; + $data = voicedirect_create_rsc_data ($voicedirect); + + if (empty ($data)) { + error('Data not created correctly'); + } + +///print_r($data); +///error (info); + + if (! $result = voicetool_modify_resource ($data)) { + error('Cannot modify the resource on the VT server'); + } + # May have to add extra stuff in here # - return update_record("voicedirect", $voicedirect); +///print_r($voicedirect); + + return update_record('voicedirect', $voicedirect); } @@ -176,7 +192,7 @@ function voicedirect_create_rsc_data ($voicedirect) { global $VT_API_VDIRECT; - add_to_log($voicedirect->course, "voicedirect", "", "", "Creating Data for Voice Direct"); + //add_to_log($voicedirect->course, "voicedirect", "", "", "Creating Data for Voice Direct"); $result = new PairSet (); @@ -193,47 +209,14 @@ $options = new PairSet (); $options->addPairSet('audio_format', $audioformat); - - if ($voicedirect->type == 'voicedirect') { - $options->addNameValuePair('archive', (($voicedirect->archive == 'on')?'true':'false')); - } + $options->addNameValuePair('archive', (($voicedirect->archive == 'on')?'true':'false')); $result->addPairSet ('options', $options); return $result->getData(); } -/** - * Send an SDK request to the VT server to create the resource. - * @param $resource_data - the resource to create - * @return - the object returned by the call, or false if something goes wrong - */ -function voicedirect_create_resource ($resource_data) { - global $CFG, - $VT_API_SERVICES, - $VT_API_CREATE_RESOURCE; - $soapclient = new soapclient($CFG->voicetool_servername.$VT_API_SERVICES,true); - - $resource = array ($CFG->voicetool_adminusername, - $CFG->voicetool_adminpassword, - $resource_data); - //print_r($resource); - - $result = $soapclient->call($VT_API_CREATE_RESOURCE, $resource); - - //print_r ($result); - - if (empty($result)){ - error ("Empty result after call to $VT_API_SERVICES"); - return false; - } - - return $result; -} - - - /** * Create the data structure for a resource * @param $voicedirect - the information incoming from the mod.html form @@ -267,46 +250,4 @@ 'rights' => $rights->getData() ); } -/** - * Create the session for a voice direct applet. - * @param - the voicedirect information - * @return - the mid to insert into the html - */ -function voicedirect_create_session ($voicedirect) { - global $CFG, - $VT_API_SERVICES, - $VT_API_CREATE_SESSION; - - - $sessiondata = voicedirect_create_session_data($voicedirect); - - $soapclient = new soapclient($CFG->voicetool_servername.$VT_API_SERVICES,true); - - $resource = array ($CFG->voicetool_adminusername, - $CFG->voicetool_adminpassword, - $sessiondata['user'], - $sessiondata['resource'], - $sessiondata['message'], - $sessiondata['rights']); - - //print_r($resource); - - $result = $soapclient->call($VT_API_CREATE_SESSION, $resource); - - //print_r ($result); - - if (empty($result)){ - error ("Empty result after call to $VT_API_SERVICES"); - return false; - } - - foreach ($result['values'] as $item) { - $values[$item['name']] = $item['value']; - } - - return $values['nid']; -} - - - ?> Modified: trunk/moodle/mod/voicedirect/view.php =================================================================== --- trunk/moodle/mod/voicedirect/view.php 2006-04-21 08:26:27 UTC (rev 8) +++ trunk/moodle/mod/voicedirect/view.php 2006-04-21 13:42:47 UTC (rev 9) @@ -3,8 +3,9 @@ /// This page prints a particular instance of voicedirect /// (Replace voicedirect with the name of your module) - require_once("../../config.php"); - require_once("lib.php"); + require_once('../../config.php'); + require_once('lib.php'); + require_once('../voicetoolapi.php'); optional_variable($id); // Course Module ID, or optional_variable($a); // voicedirect ID @@ -38,7 +39,7 @@ add_to_log($course->id, "voicedirect", "view", "view.php?id=$cm->id", "$voicedirect->id"); - if (!$nid = voicedirect_create_session ($voicedirect)) { + if (!$nid = voicetool_create_session ($voicedirect)) { error(get_string ('cannotgetsession', 'voicedirect')); } @@ -53,17 +54,18 @@ $strvoicedirects = get_string("modulenameplural", "voicedirect"); $strvoicedirect = get_string("modulename", "voicedirect"); - global $CFG; - - $servername = $CFG->voicetool_servername; - print_header("$course->shortname: $voicedirect->name", "$course->fullname", "$navigation <A HREF=index.php?id=$course->id>$strvoicedirects</A> -> $voicedirect->name", "", "", true, update_module_button($cm->id, $course->id, $strvoicedirect), navmenu($course, $cm)); /// Print the main part of the page + global $CFG; + + $servername = $CFG->voicetool_servername; + ?> +<p><em><strong><?php p($voicedirect->description) ?></strong></em></p> <SCRIPT type="text/javascript"> this.focus(); </SCRIPT> Modified: trunk/moodle/mod/voicetoolapi.php =================================================================== --- trunk/moodle/mod/voicetoolapi.php 2006-04-21 08:26:27 UTC (rev 8) +++ trunk/moodle/mod/voicetoolapi.php 2006-04-21 13:42:47 UTC (rev 9) @@ -17,10 +17,143 @@ $VT_API_SERVICES = '/services/Broker?wsdl'; $VT_API_CREATE_RESOURCE = 'createResource'; +$VT_API_MODIFY_RESOURCE = 'modifyResource'; $VT_API_CREATE_SESSION = 'createSession'; + +/** + * Send an SDK request to the VT server to create the resource. + * @uses CFG + * @uses VT_API_SERVICES + * @uses VT_API_CREATE_RESOURCE + * @param $resource_data - the resource to create + * @return - the object returned by the call, or false if something goes wrong + */ +function voicetool_create_resource ($resource_data) { + global $CFG, + $VT_API_SERVICES, + $VT_API_CREATE_RESOURCE; + + $soapclient = new soapclient($CFG->voicetool_servername.$VT_API_SERVICES,true); + + $resource = array ($CFG->voicetool_adminusername, + $CFG->voicetool_adminpassword, + $resource_data); + //print_r($resource); + + $result = $soapclient->call($VT_API_CREATE_RESOURCE, $resource); + + //print_r ($result); + + if (!voicetool_check_result ($result)) { + return false; + } + + return $result; +} + +/** + * Send an SDK request to the VT server to create the resource. + * @uses CFG + * @uses VT_API_SERVICES + * @uses VT_API_MODIFY_RESOURCE + * @param $resource_data - the resource to create + * @return - the object returned by the call, or false if something goes wrong + */ +function voicetool_modify_resource ($resource_data) { + global $CFG, + $VT_API_SERVICES, + $VT_API_MODIFY_RESOURCE; + + $soapclient = new soapclient($CFG->voicetool_servername.$VT_API_SERVICES,true); + + $resource = array ($CFG->voicetool_adminusername, + $CFG->voicetool_adminpassword, + $resource_data); + //print_r($resource); + + $result = $soapclient->call($VT_API_MODIFY_RESOURCE, $resource); + + //print_r ($result); + + if (!voicetool_check_result ($result)) { + return false; + } + + return $result; +} + + + +/** + * Create the session for a voice direct applet. + * @uses CFG + * @uses VT_API_SERVICES + * @uses VT_API_CREATE_SESSION + * @param - the voicedirect information + * @return - the mid to insert into the html + */ +function voicetool_create_session ($voicedirect) { + global $CFG, + $VT_API_SERVICES, + $VT_API_CREATE_SESSION; + + + $sessiondata = voicedirect_create_session_data($voicedirect); + + $soapclient = new soapclient($CFG->voicetool_servername.$VT_API_SERVICES,true); + + $resource = array ($CFG->voicetool_adminusername, + $CFG->voicetool_adminpassword, + $sessiondata['user'], + $sessiondata['resource'], + $sessiondata['message'], + $sessiondata['rights']); + + //print_r($resource); + + $result = $soapclient->call($VT_API_CREATE_SESSION, $resource); + + //print_r ($result); + + if (!voicetool_check_result ($result)) { + return false; + } + + foreach ($result['values'] as $item) { + $values[$item['name']] = $item['value']; + } + + return $values['nid']; +} + + +/** + * Return true if the result does not contain an error code, or false wise. + * @param $result - a pairset resulting from an API call to $soapclient->call() + * @return true f $result does not contain an error code, false otherwise. + */ +function voicetool_check_result ($result) { + if (empty($result)){ + //error ("Empty result after call to $VT_API_SERVICES"); + error_log( "voicetool_check_result: Empty result after call to $VT_API_SERVICES"); + return false; + } + + foreach ($result['values'] as $item) { + if ($item['name'] == 'error_message') { + error_log( "voicetool_check_result: ".$item['name'].': '.$item['value']); + return false; + } + } + + return true; +} + + + //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// @@ -56,13 +189,4 @@ } } - - -class NameSetPair { - var $data = array ('name' => false, 'pairSet' => array ()); - -} - - - ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |