[Hw4mdl-svn] SF.net SVN: hw4mdl: [51] trunk/moodle/mod/liveclassroom
Brought to you by:
jhlinder,
trollinger
From: <sh...@us...> - 2006-08-28 09:59:01
|
Revision: 51 Author: shazan Date: 2006-08-28 02:58:46 -0700 (Mon, 28 Aug 2006) ViewCVS: http://svn.sourceforge.net/hw4mdl/?rev=51&view=rev Log Message: ----------- New classes added to manage the exception with the connection to the server and with the database Modified Paths: -------------- trunk/moodle/mod/liveclassroom/api.php trunk/moodle/mod/liveclassroom/db/mysql.sql trunk/moodle/mod/liveclassroom/lib.php trunk/moodle/mod/liveclassroom/mod.html Added Paths: ----------- trunk/moodle/mod/liveclassroom/DbException.php trunk/moodle/mod/liveclassroom/LCHttpException.php Added: trunk/moodle/mod/liveclassroom/DbException.php =================================================================== --- trunk/moodle/mod/liveclassroom/DbException.php (rev 0) +++ trunk/moodle/mod/liveclassroom/DbException.php 2006-08-28 09:58:46 UTC (rev 51) @@ -0,0 +1,47 @@ +<?PHP + + +class DbException extends Exception { + + public function __construct($message) { + + parent::__construct($message); + } + + + /** + * Builds a Live Classroom HTTP Exception. + * @param message the detail message. + * @param cause the cause (null if there is no cause). + */ + public function DbException($message, $cause) + { + super($message, $cause); + } + + + // cha\xEEne personnalis\xE9 repr\xE9sentant l'objet + public function __toString() { + return __CLASS__ . ": {$this->message}\n"; + } + + + public function getError() { + + // On retourne un message d'erreur complet pour nos besoins. + // avec le numero de ligne + // $return = 'Une exception a \xE9t\xE9 g\xE9r\xE9e :<br/>'; + $return .= '<strong>Message : ' . $this->getMessage() . '</strong><br/>'; + + return $return; + } + +} + + + + + +?> + + Property changes on: trunk/moodle/mod/liveclassroom/DbException.php ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Date Revision Author Id Name: svn:eol-style + native Added: trunk/moodle/mod/liveclassroom/LCHttpException.php =================================================================== --- trunk/moodle/mod/liveclassroom/LCHttpException.php (rev 0) +++ trunk/moodle/mod/liveclassroom/LCHttpException.php 2006-08-28 09:58:46 UTC (rev 51) @@ -0,0 +1,47 @@ +<?PHP + + +class LCHttpException extends Exception { + + public function __construct($message) { + + parent::__construct($message); + } + + + /** + * Builds a Live Classroom HTTP Exception. + * @param message the detail message. + * @param cause the cause (null if there is no cause). + */ + public function LCHttpException($message, $cause) + { + super($message, $cause); + } + + + // cha\xEEne personnalis\xE9 repr\xE9sentant l'objet + public function __toString() { + return __CLASS__ . ": {$this->message}\n"; + } + + + public function getError() { + + // On retourne un message d'erreur complet pour nos besoins. + // avec le numero de ligne + $return = 'Une exception a \xE9t\xE9 g\xE9r\xE9e :<br/>'; + $return .= '<strong>Message : ' . $this->getMessage() . '</strong><br/>'; + + return $return; + } + +} + + + + + +?> + + Property changes on: trunk/moodle/mod/liveclassroom/LCHttpException.php ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Date Revision Author Id Name: svn:eol-style + native Modified: trunk/moodle/mod/liveclassroom/api.php =================================================================== --- trunk/moodle/mod/liveclassroom/api.php 2006-08-25 14:15:36 UTC (rev 50) +++ trunk/moodle/mod/liveclassroom/api.php 2006-08-28 09:58:46 UTC (rev 51) @@ -42,6 +42,7 @@ */ require_once('System.php'); +require_once("LCHttpException.php"); $LIVECLASSROOM_API_ADMIN = '/admin/api/api.pl?'; $LIVECLASSROOM_API_FUNCTION_NOOP = 'function=NOOP'; @@ -168,6 +169,15 @@ return true; } + + +function liveclassroom_api_create_group() { + +} + + + + /** * Returns a session id (hzA) to be inserted in URLs to access the LC server * @uses CFG, USER @@ -223,6 +233,7 @@ //error ("Did not find authToken, data=<pre>$data</pre>"); return false; } + $authtoken= substr($currentline, 10); @@ -243,7 +254,8 @@ global $LIVECLASSROOM_API_ADMIN, $LIVECLASSROOM_API_FUNCTION_CREATE_CLASS; - + $data = liveclassroom_api_send_query($ch,$LIVECLASSROOM_API_FUNCTION_CREATE_CLASS,"&target=$roomid&longname=$roomname"); +/* if (!$ch = liveclassroom_api_authenticate()) { return false; } @@ -266,7 +278,7 @@ print curl_error($ch); return false; } - +*/ preg_match("(\d*)", $data, $matches); $respcode = $matches[0]; @@ -505,22 +517,28 @@ if (!$ch = liveclassroom_api_authenticate()) { return false; - } - - $url = $CFG->liveclassroom_servername. - $LIVECLASSROOM_API_ADMIN. - $const. - $attribute; - - curl_setopt($ch, CURLOPT_URL,$url); - $data = curl_exec($ch); + } + try { + $url = $CFG->liveclassroom_servername. + $LIVECLASSROOM_API_ADMIN. + $const. + $attribute; + + curl_setopt($ch, CURLOPT_URL,$url); + $data = curl_exec($ch); + + if (curl_errno($ch)) { + print curl_error($ch); + return false; + } - if (curl_errno($ch)) { - print curl_error($ch); - return false; - } - - return $data; + return $data; + + } + catch (LCHttpException $e) { + throw new LCHttpException("Bad URL"); + } + } function liveclassroom_api_set_query_attribute($query,$attribute) { Modified: trunk/moodle/mod/liveclassroom/db/mysql.sql =================================================================== --- trunk/moodle/mod/liveclassroom/db/mysql.sql 2006-08-25 14:15:36 UTC (rev 50) +++ trunk/moodle/mod/liveclassroom/db/mysql.sql 2006-08-28 09:58:46 UTC (rev 51) @@ -52,8 +52,18 @@ PRIMARY KEY (`id`) ) COMMENT='Defines liveclassroom rooms'; -INSERT INTO prefix_liveclassroom_rooms VALUES ('', '0', 'LectureHall', '0',''); -INSERT INTO prefix_liveclassroom_rooms VALUES ('', '0', 'BreackOut', '0',''); +CREATE TABLE `prefix_liveclassroom_type_rooms` ( + `id` int(10) unsigned NOT NULL auto_increment, + `course` int(10) unsigned NOT NULL default '0', + `name` varchar(255) NOT NULL default '', + `lc_id` int(10) unsigned NOT NULL default '0', + `room_id` varchar(255) NOT NULL default '', + PRIMARY KEY (`id`) +) COMMENT='Defines liveclassroom rooms'; + + +INSERT INTO prefix_liveclassroom_type_rooms VALUES ('', '0', 'LectureHall', '0',''); +INSERT INTO prefix_liveclassroom_type_rooms VALUES ('', '0', 'BreackOut', '0',''); # -------------------------------------------------------- # INSERT INTO prefix_log_display VALUES ('liveclassroom', 'view', 'liveclassroom', 'name'); Modified: trunk/moodle/mod/liveclassroom/lib.php =================================================================== --- trunk/moodle/mod/liveclassroom/lib.php 2006-08-25 14:15:36 UTC (rev 50) +++ trunk/moodle/mod/liveclassroom/lib.php 2006-08-28 09:58:46 UTC (rev 51) @@ -32,6 +32,7 @@ require_once($CFG->libdir.'/datalib.php'); require_once("api.php"); +require_once("DbException.php"); //Suffixes used when creting the profiles account on the LC server $LIVECLASSROOM_TEACHER_SUFFIX = "_T"; //Teachers will use the user $CFG->liveclassroom_settinguniqueid + $course->id + $LIVECLASSROOM_TEACHER_SUFFIX @@ -337,39 +338,55 @@ */ function liveclassroom_get_list_type_rooms() { - //$sql = "SELECT u.name FROM mdl_liveclassroom_rooms u WHERE u.course=0"; - //$n = count_records_sql($sql); - //$list0 = get_records_sql($sql); + try { + if (!($list = get_records('liveclassroom_type_rooms','course',0) )) { + throw new DbException("Connection to db liveclassroom_type_rooms failed"); + } + + + for($i=0;$i<sizeof($list);$i++) { + $list_name[$i] = $list[$i+1]->name; + } - $list = get_records('liveclassroom_type_rooms','course',0); - - - for($i=0;$i<sizeof($list);$i++) { - $list_name[$i] = $list[$i+1]->name; + return $list_name; + + }catch(DbException $e) { + echo $e->getError(); } - - return $list_name; } function liveclassroom_get_list_type_rooms_per_course($course) { + try { + if(!($list = get_records('liveclassroom_rooms','course',$course->id))) { + throw new DbException("Connection to db liveclassroom_rooms failed"); + } - $list = get_records('liveclassroom_rooms','course',$course->id); + for($i=0;$i<sizeof($list);$i++) { + $list_name[$i] = $list[$i+1]->name; + } - for($i=0;$i<sizeof($list);$i++) { - $list_name[$i] = $list[$i+1]->name; + return $list_name; + + }catch(DbException $e) { + echo $e->getError(); } - - return $list_name; } function liveclassroom_rooms_add_instance($liveclassroom_rooms) { $liveclassroom_rooms->timemodified = time(); - + + try { + + if(!(insert_record("liveclassroom_rooms", $liveclassroom_rooms))) { + throw new DbException("Insertion to liveclassroom_rooms failed"); + } + } + catch(DbException $e) { + $e->getError(); + } - return insert_record("liveclassroom_rooms", $liveclassroom_rooms); - } function liveclassroom_rooms_add_new_type($name) { @@ -380,30 +397,55 @@ $liveclassroom_type_room->lc_id = 0 ; $liveclassroom_type_room->name = $name ; - return insert_record("liveclassroom_type_rooms", $liveclassroom_type_room); - + try { + if(!(insert_record("liveclassroom_type_rooms", $liveclassroom_type_room))) { + throw new DbException("Insertion to liveclassroom_type_room failed"); + } + } + catch(DbException $e) { + $e->getError(); + } } /* * Get the type number of liveclassroom */ function liveclassroom_get_type($liveclassroom) { - if($lc = get_record('liveclassroom','id',$liveclassroom->id)) { - return $lc->type; + + try { + + if(!($lc = get_record('liveclassroom','id',$liveclassroom->id))) { + throw new DbException("Connection to db liveclassroom failed"); + } + else { + return $lc->type; + } + + } + catch(DbException $e) { + echo $e->getError(); } - else return false; + } /** * Give the name of the room for the course */ function liveclassroom_get_room_name($course,$type) { - $lc = get_record('liveclassroom_type_rooms','id',$type+1); - $name = $course->shortname; - $typename = $lc->name; - - return $name.'_'.$typename; + try { + if(!($lc = get_record('liveclassroom_type_rooms','id',$type+1))) { + throw new DbException("Connection to db liveclassroom_type_rooms failed"); + } + else { + $name = $course->shortname; + $typename = $lc->name; + + return $name.'_'.$typename; + } + }catch(DbException $e) { + echo $e->getError(); + } } /* @@ -413,11 +455,10 @@ function liveclassroom_rooms_exists($liveclassroom) { - if(!get_records('liveclassroom_rooms','lc_id',$liveclassroom->id)) { - return false; - } - else return true; - + if(!get_records('liveclassroom_rooms','lc_id',$liveclassroom->id)) { + return false; + } + else return true; } Modified: trunk/moodle/mod/liveclassroom/mod.html =================================================================== --- trunk/moodle/mod/liveclassroom/mod.html 2006-08-25 14:15:36 UTC (rev 50) +++ trunk/moodle/mod/liveclassroom/mod.html 2006-08-28 09:58:46 UTC (rev 51) @@ -27,7 +27,7 @@ include_once($CFG->dirroot.'/mod/liveclassroom/lib.php'); //recuperation de la liste des types de rooms $list_type_rooms = liveclassroom_get_list_type_rooms(); - // asort($LIVECLASSROOM_TYPES); + //sort($list_type_rooms); //$list_type_rooms[sizeof($list_type_rooms)] = get_string('otherroom', 'liveclassroom'); choose_from_menu($list_type_rooms, 'type', $form->type, ''); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |