Review code style in main code for OpenMeetings plugin - refs BT#7046 refs #5491

1.9.x
Yannick Warnier 11 years ago
parent 09560313ef
commit 4736488e0b
  1. 72
      plugin/om_integration/lib/om_integration.lib.php
  2. 15
      plugin/om_integration/lib/om_integration_api.php
  3. 12
      plugin/om_integration/lib/om_integration_plugin.class.php

@ -1,4 +1,12 @@
<?php <?php
/**
* Chamilo-OpenMeetings integration plugin library, defining methods to connect
* to OpenMeetings from Chamilo by calling its web services
* @package chamilo.plugin.openmeetings
*/
/**
* Initialization
*/
include_once 'services/getSession/getSession.class.php'; include_once 'services/getSession/getSession.class.php';
include_once 'services/loginUser/loginUser.class.php'; include_once 'services/loginUser/loginUser.class.php';
include_once 'services/addRoomWithModerationAndExternalType/addRoomWithModerationAndExternalType.class.php'; include_once 'services/addRoomWithModerationAndExternalType/addRoomWithModerationAndExternalType.class.php';
@ -9,7 +17,8 @@ include_once 'services/getRoomById/getRoomById.class.php';
/** /**
* Open Meetings-Chamilo connector class * Open Meetings-Chamilo connector class
*/ */
class om_integration { class om_integration
{
var $url; var $url;
var $salt; var $salt;
@ -25,8 +34,8 @@ class om_integration {
* Constructor (generates a connection to the API and the Chamilo settings * Constructor (generates a connection to the API and the Chamilo settings
* required for the connection to the videoconference server) * required for the connection to the videoconference server)
*/ */
function __construct() { function __construct()
{
// initialize video server settings from global settings // initialize video server settings from global settings
$plugin = om_integrationPlugin::create(); $plugin = om_integrationPlugin::create();
@ -57,14 +66,16 @@ class om_integration {
* Checks whether a user is teacher in the current course * Checks whether a user is teacher in the current course
* @return bool True if the user can be considered a teacher in this course, false otherwise * @return bool True if the user can be considered a teacher in this course, false otherwise
*/ */
function is_teacher() { function is_teacher()
{
return api_is_course_admin() || api_is_coach() || api_is_platform_admin(); return api_is_course_admin() || api_is_coach() || api_is_platform_admin();
} }
/** /**
* Login the user with OM Server * Login the user with OM Server
* @return bool True if the user is correct and false when is incorrect * @return bool True if the user is correct and false when is incorrect
*/ */
function loginUser() { function loginUser()
{
try { try {
$objGetSession = new getSession(); $objGetSession = new getSession();
$objloginUser = new loginUser(); $objloginUser = new loginUser();
@ -79,10 +90,11 @@ class om_integration {
$luFn = $omServices->loginUser($objloginUser); $luFn = $omServices->loginUser($objloginUser);
if ( $luFn->return > 0 ) if ($luFn->return > 0) {
return true; return true;
else } else {
return false; return false;
}
} else { } else {
$this->sessionId = $_SESSION['sessOpenMeeting']; $this->sessionId = $_SESSION['sessOpenMeeting'];
return true; return true;
@ -98,7 +110,8 @@ class om_integration {
* Creating a Room for the meeting * Creating a Room for the meeting
* @return bool True if the user is correct and false when is incorrect * @return bool True if the user is correct and false when is incorrect
*/ */
function create_meeting( $params ) { function create_meeting($params)
{
//$id = Database::insert($this->table, $params); //$id = Database::insert($this->table, $params);
try { try {
$objAddRoom = new addRoomWithModerationAndExternalType(); $objAddRoom = new addRoomWithModerationAndExternalType();
@ -151,8 +164,8 @@ class om_integration {
* @assert ('') === false * @assert ('') === false
* @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false * @assert ('abcdefghijklmnopqrstuvwxyzabcdefghijklmno') === false
*/ */
function join_meeting($meetingid) { function join_meeting($meetingid)
{
if (empty($meetingid)) { if (empty($meetingid)) {
return false; return false;
} }
@ -183,7 +196,6 @@ class om_integration {
'&allowRecording=1'*/; '&allowRecording=1'*/;
printf("<iframe src='%s' width='%s' height = '%s' />", $iframe, "100%", 640); printf("<iframe src='%s' width='%s' height = '%s' />", $iframe, "100%", 640);
} }
/** /**
* Checks if the videoconference server is running. * Checks if the videoconference server is running.
@ -191,14 +203,16 @@ class om_integration {
* @return bool True if server is running, false otherwise * @return bool True if server is running, false otherwise
* @assert () === false * @assert () === false
*/ */
function is_server_running() { function is_server_running()
{
return true; return true;
} }
/** /**
* Gets the password for a specific meeting for the current user * Gets the password for a specific meeting for the current user
* @return string A moderator password if user is teacher, or the course code otherwise * @return string A moderator password if user is teacher, or the course code otherwise
*/ */
function get_user_meeting_password() { function get_user_meeting_password()
{
if ($this->is_teacher()) { if ($this->is_teacher()) {
return $this->get_mod_meeting_password(); return $this->get_mod_meeting_password();
} else { } else {
@ -209,7 +223,8 @@ class om_integration {
* Generated a moderator password for the meeting * Generated a moderator password for the meeting
* @return string A password for the moderation of the videoconference * @return string A password for the moderation of the videoconference
*/ */
function get_mod_meeting_password() { function get_mod_meeting_password()
{
return api_get_course_id().'mod'; return api_get_course_id().'mod';
} }
/** /**
@ -218,7 +233,8 @@ class om_integration {
* @return mixed Array of information on success, false on error * @return mixed Array of information on success, false on error
* @assert (array()) === false * @assert (array()) === false
*/ */
function get_meeting_info($params) { function get_meeting_info($params)
{
try { try {
$result = $this->api->getMeetingInfoArray($params); $result = $this->api->getMeetingInfoArray($params);
if ($result == null) { if ($result == null) {
@ -231,7 +247,8 @@ class om_integration {
} }
return false; return false;
} }
function setUserObjectAndGenerateRecordingHashByURL( $params ) { function setUserObjectAndGenerateRecordingHashByURL( $params )
{
$username = $_SESSION['_user']['username']; $username = $_SESSION['_user']['username'];
$firstname = $_SESSION['_user']['firstname']; $firstname = $_SESSION['_user']['firstname'];
$lastname = $_SESSION['_user']['lastname']; $lastname = $_SESSION['_user']['lastname'];
@ -253,10 +270,10 @@ class om_integration {
$orFn = $omServices->setUserObjectAndGenerateRecordingHashByURL( $objRec ); $orFn = $omServices->setUserObjectAndGenerateRecordingHashByURL( $objRec );
return $orFn->return; return $orFn->return;
} }
function setUserObjectAndGenerateRoomHashByURLAndRecFlag( $params ) { function setUserObjectAndGenerateRoomHashByURLAndRecFlag( $params )
{
$username = $_SESSION['_user']['username']; $username = $_SESSION['_user']['username'];
$firstname = $_SESSION['_user']['firstname']; $firstname = $_SESSION['_user']['firstname'];
@ -295,7 +312,8 @@ class om_integration {
* Gets all the course meetings saved in the plugin_bbb_meeting table * Gets all the course meetings saved in the plugin_bbb_meeting table
* @return array Array of current open meeting rooms * @return array Array of current open meeting rooms
*/ */
function get_course_meetings() { function get_course_meetings()
{
$new_meeting_list = array(); $new_meeting_list = array();
$item = array(); $item = array();
$pass = $this->get_user_meeting_password(); $pass = $this->get_user_meeting_password();
@ -352,12 +370,13 @@ class om_integration {
$meeting_om = $current_room; $meeting_om = $current_room;
if (empty( $meeting_om )) if (empty( $meeting_om )) {
if ($meeting_db['status'] == 1 && $this->is_teacher()) if ($meeting_db['status'] == 1 && $this->is_teacher()) {
$this->end_meeting($meeting_db['id']); $this->end_meeting($meeting_db['id']);
else }
} else {
$meeting_om['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_db['startTime']); $meeting_om['add_to_calendar_url'] = api_get_self().'?action=add_to_calendar&id='.$meeting_db['id'].'&start='.api_strtotime($meeting_db['startTime']);
}
$meeting_om['end_url'] = api_get_self().'?action=end&id='.$meeting_db['id']; $meeting_om['end_url'] = api_get_self().'?action=end&id='.$meeting_db['id'];
$record_array = array(); $record_array = array();
@ -425,7 +444,8 @@ class om_integration {
} }
return $new_meeting_list; return $new_meeting_list;
} }
function end_meeting( $meetingId ){ function end_meeting($meetingId )
{
try { try {
$this->loginUser(); $this->loginUser();
$urlWsdl = CONFIG_OMSERVER_BASE_URL . "/services/RoomService?wsdl"; $urlWsdl = CONFIG_OMSERVER_BASE_URL . "/services/RoomService?wsdl";
@ -435,9 +455,9 @@ class om_integration {
$objClose->room_id = $meetingId; $objClose->room_id = $meetingId;
$objClose->status = false; $objClose->status = false;
$crFn = $omServices->closeRoom( $objClose ); $crFn = $omServices->closeRoom( $objClose );
if( $crFn > 0 ) if ($crFn > 0) {
Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingId)); Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $meetingId));
}
} catch (SoapFault $e) { } catch (SoapFault $e) {
echo "<h1>Warning</h1> echo "<h1>Warning</h1>
<p>We have detected some problems </br> <p>We have detected some problems </br>

@ -1,13 +1,16 @@
<?php <?php
class OpenMeetings { class OpenMeetings
{
private $_securitySalt; private $_securitySalt;
private $_omServerBaseUrl; private $_omServerBaseUrl;
function __construct() { function __construct()
{
$this->_securitySalt = CONFIG_SECURITY_SALT; $this->_securitySalt = CONFIG_SECURITY_SALT;
$this->_omServerBaseUrl = CONFIG_SERVER_BASE_URL; $this->_omServerBaseUrl = CONFIG_SERVER_BASE_URL;
} }
function getMeetingInfoArray($infoParams) { function getMeetingInfoArray($infoParams)
{
$xml = $this->_processXmlResponse($this->getMeetingInfoUrl($infoParams)); $xml = $this->_processXmlResponse($this->getMeetingInfoUrl($infoParams));
if ($xml) { if ($xml) {
@ -19,8 +22,7 @@ class OpenMeetings {
'message' => $xml->message 'message' => $xml->message
); );
return $result; return $result;
} } else {
else {
// In this case, we have success and meeting info: // In this case, we have success and meeting info:
$result = array( $result = array(
'returncode' => $xml->returncode, 'returncode' => $xml->returncode,
@ -49,8 +51,7 @@ class OpenMeetings {
} }
return $result; return $result;
} }
} } else {
else {
return null; return null;
} }

@ -9,16 +9,19 @@ class om_integrationPlugin extends Plugin
array('name' => 'om_button_record_and_store', 'type' => 'checkbox') array('name' => 'om_button_record_and_store', 'type' => 'checkbox')
); );
static function create() { static function create()
{
static $result = null; static $result = null;
return $result ? $result : $result = new self(); return $result ? $result : $result = new self();
} }
protected function __construct() { protected function __construct()
{
parent::__construct('2.0', 'Francis Gonzales', array('tool_enable' => 'boolean', 'host' =>'text', 'user' => 'text', 'pass' => 'text')); parent::__construct('2.0', 'Francis Gonzales', array('tool_enable' => 'boolean', 'host' =>'text', 'user' => 'text', 'pass' => 'text'));
} }
function install() { function install()
{
$table = Database::get_main_table('plugin_om_meeting'); $table = Database::get_main_table('plugin_om_meeting');
$sql = "CREATE TABLE IF NOT EXISTS $table ( $sql = "CREATE TABLE IF NOT EXISTS $table (
id INT unsigned NOT NULL auto_increment PRIMARY KEY, id INT unsigned NOT NULL auto_increment PRIMARY KEY,
@ -38,7 +41,8 @@ class om_integrationPlugin extends Plugin
$this->install_course_fields_in_all_courses(); $this->install_course_fields_in_all_courses();
} }
function uninstall() { function uninstall()
{
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS); $t_options = Database::get_main_table(TABLE_MAIN_SETTINGS_OPTIONS);
$t_tool = Database::get_course_table(TABLE_TOOL_LIST); $t_tool = Database::get_course_table(TABLE_TOOL_LIST);

Loading…
Cancel
Save