Format code, move URL into functions

1.10.x
jmontoyaa 9 years ago
parent b603d25e43
commit d2bf4a3b35
  1. 2
      plugin/bbb/index.php
  2. 5
      plugin/bbb/install.php
  3. 3
      plugin/bbb/lang/english.php
  4. 3
      plugin/bbb/lang/french.php
  5. 3
      plugin/bbb/lang/spanish.php
  6. 4
      plugin/bbb/lib/VM.php
  7. 155
      plugin/bbb/lib/bbb.lib.php
  8. 23
      plugin/bbb/lib/bbb_plugin.class.php
  9. 16
      plugin/bbb/listing.php
  10. 2
      plugin/bbb/plugin.php
  11. 3
      plugin/bbb/readme.txt
  12. 9
      plugin/bbb/start.php
  13. 7
      plugin/bbb/uninstall.php

@ -4,9 +4,6 @@
* includes things to execute in the main database (settings_current table)
* @package chamilo.plugin.bigbluebutton
*/
/**
* Initialization
*/
require_once dirname(__FILE__).'/config.php';
require_once __DIR__.'/config.php';
BBBPlugin::create()->install();

@ -5,8 +5,7 @@
* @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
* @author Laurent Opprecht <laurent@opprecht.info>
*/
//Needed in order to show the plugin title
// Needed in order to show the plugin title
$strings['plugin_title'] = "Videoconference";
$strings['plugin_comment'] = "Add a videoconference room in a Chamilo course using BigBlueButton (BBB)";

@ -1,4 +1,5 @@
<?php /* License: see /license.txt */
<?php
/* License: see /license.txt */
//Needed in order to show the plugin title
$strings['plugin_title'] = "Vidéoconférence";
$strings['plugin_comment'] = "Ajoutez un espace de vidéoconférences aux cours de Chamilo avec BigBlueButton (BBB)";

@ -1,4 +1,5 @@
<?php /* License: see /license.txt */
<?php
/* License: see /license.txt */
//Needed in order to show the plugin title
$strings['plugin_title'] = "Videoconferencia";
$strings['plugin_comment'] = "Añade una sala de videoconferencia en los cursos de Chamilo con BigBlueButton (BBB)";

@ -9,6 +9,10 @@ class VM
protected $config;
public $virtualMachine;
/**
* VM constructor.
* @param $config
*/
public function __construct($config)
{
$this->config = $config;

@ -51,7 +51,7 @@ class bbb
$bbb_salt = $salt;
}
$this->logout_url = api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq();
$this->logout_url = $this->getListingUrl();
$this->table = Database::get_main_table('plugin_bbb_meeting');
if ($bbb_plugin == true) {
@ -184,8 +184,7 @@ class bbb
$result = $this->api->createMeetingWithXmlResponseArray(
$bbbParams
);
if (isset($result) && strval($result['returncode']) == 'SUCCESS'
) {
if (isset($result) && strval($result['returncode']) == 'SUCCESS') {
if ($this->debug) {
error_log(
"create_meeting result: " . print_r($result, 1)
@ -373,7 +372,18 @@ class bbb
public function getCourseMeetings()
{
$pass = $this->getUserMeetingPassword();
$meetingList = Database::select('*', $this->table, array('where' => array('c_id = ? AND session_id = ? ' => array(api_get_course_int_id(), api_get_session_id()))));
$meetingList = Database::select(
'*',
$this->table,
array(
'where' => array(
'c_id = ? AND session_id = ? ' => array(
api_get_course_int_id(),
api_get_session_id(),
),
),
)
);
$newMeetingList = array();
$item = array();
@ -395,14 +405,14 @@ class bbb
if ($meetingDB['visibility'] == 0 and $this->isTeacher() == false) {
continue;
}
$meetingBBB['end_url'] = api_get_self().'?'.api_get_cidreq().'&action=end&id='.$meetingDB['id'];
$meetingBBB['end_url'] = $this->endUrl($meetingDB);
if ((string)$meetingBBB['returncode'] == 'FAILED') {
if ($meetingDB['status'] == 1 && $this->isTeacher()) {
$this->endMeeting($meetingDB['id']);
}
} else {
$meetingBBB['add_to_calendar_url'] = api_get_self().'?'.api_get_cidreq().'&action=add_to_calendar&id='.$meetingDB['id'].'&start='.api_strtotime($meetingDB['created_at']);
$meetingBBB['add_to_calendar_url'] = $this->addToCalendarUrl($meetingDB);
}
$recordArray = array();
@ -438,9 +448,7 @@ class bbb
array(),
ICON_SIZE_MEDIUM
),
api_get_self().'?'.
api_get_cidreq().
'&action=publish&id='.$meetingDB['id']
$this->publishUrl($meetingDB)
);
} else {
$actionLinksArray[] = Display::url(
@ -450,9 +458,7 @@ class bbb
array(),
ICON_SIZE_MEDIUM
),
api_get_self().'?'.
api_get_cidreq().
'&action=unpublish&id='.$meetingDB['id']
$this->unPublishUrl($meetingDB)
);
}
} else {
@ -477,29 +483,21 @@ class bbb
'link.gif',
get_lang('CopyToLinkTool')
),
api_get_self().'?'.
api_get_cidreq().
'&action=copy_record_to_link_tool&id='.$meetingDB['id']
$this->copyToRecordToLinkTool($meetingDB)
);
$actionLinks .= Display::url(
Display::return_icon(
'agenda.png',
get_lang('AddToCalendar')
),
api_get_self().'?'.
api_get_cidreq().
'&action=add_to_calendar&id='.$meetingDB['id'].
'&start='.api_strtotime($meetingDB['created_at']).
'&url='.$record['playbackFormatUrl']
$this->addToCalendarUrl($meetingDB, $record)
);
$actionLinks .= Display::url(
Display::return_icon(
'delete.png',
get_lang('Delete')
),
api_get_self().'?'.
api_get_cidreq().
'&action=delete_record&id='.$meetingDB['id']
$this->deleteRecordUrl($meetingDB)
);
if ($meetingDB['visibility'] == 0) {
$actionLinks .= Display::url(
@ -509,9 +507,7 @@ class bbb
array(),
ICON_SIZE_MEDIUM
),
api_get_self().'?'.
api_get_cidreq().
'&action=publish&id='.$meetingDB['id']
$this->publishUrl($meetingDB)
);
} else {
$actionLinks .= Display::url(
@ -521,9 +517,7 @@ class bbb
array(),
ICON_SIZE_MEDIUM
),
api_get_self().'?'.
api_get_cidreq().
'&action=unpublish&id='.$meetingDB['id']
$this->unPublishUrl($meetingDB)
);
}
}
@ -565,9 +559,7 @@ class bbb
array(),
ICON_SIZE_MEDIUM
),
api_get_self().'?'.
api_get_cidreq().
'&action=publish&id='.$meetingDB['id']
$this->publishUrl($meetingDB)
);
} else {
$actionLinks .= Display::url(
@ -577,9 +569,7 @@ class bbb
array(),
ICON_SIZE_MEDIUM
),
api_get_self().'?'.
api_get_cidreq().
'&action=unpublish&id='.$meetingDB['id']
$this->unPublishUrl($meetingDB)
);
}
}
@ -595,8 +585,8 @@ class bbb
//created_at
$meetingDB['created_at'] = $item['created_at']; //avoid overwrite in array_merge() below
$item['publish_url'] = api_get_self().'?'.api_get_cidreq().'&action=publish&id='.$meetingDB['id'];
$item['unpublish_url'] = api_get_self().'?'.api_get_cidreq().'&action=unpublish&id='.$meetingDB['id'];
$item['publish_url'] = $this->publishUrl($meetingDB);
$item['unpublish_url'] = $this->unPublishUrl($meetingBBB);
if ($meetingDB['status'] == 1) {
$joinParams = array(
@ -612,6 +602,7 @@ class bbb
$item = array_merge($item, $meetingDB, $meetingBBB);
$newMeetingList[] = $item;
}
return $newMeetingList;
}
@ -622,10 +613,12 @@ class bbb
{
//return BigBlueButtonBN::setPublishRecordings($id, 'true', $this->url, $this->salt);
if (empty($id)) {
return false;
}
$id = intval($id);
Database::update($this->table, array('visibility' => 1), array('id = ? ' => $id));
return true;
}
@ -640,6 +633,7 @@ class bbb
}
$id = intval($id);
Database::update($this->table, array('visibility' => 0), array('id = ? ' => $id));
return true;
}
@ -663,7 +657,11 @@ class bbb
'password' => $pass, // REQUIRED - Must match moderator pass for meeting.
);
$this->api->endMeetingWithXmlResponseArray($endParams);
Database::update($this->table, array('status' => 0, 'closed_at' => api_get_utc_datetime()), array('id = ? ' => $id));
Database::update(
$this->table,
array('status' => 0, 'closed_at' => api_get_utc_datetime()),
array('id = ? ' => $id)
);
}
/**
@ -697,7 +695,12 @@ class bbb
{
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$meetingData = Database::select('*', $this->table, array('where' => array('c_id = ? AND session_id = ? AND status = 1 ' => array($courseId, $sessionId))), 'first');
$meetingData = Database::select(
'*',
$this->table,
array('where' => array('c_id = ? AND session_id = ? AND status = 1 ' => array($courseId, $sessionId))),
'first'
);
if (empty($meetingData)) {
return 0;
}
@ -786,7 +789,6 @@ class bbb
$records = $this->api->getRecordingsWithXmlResponseArray(array('meetingId' => $meetingData['remote_id']));
if (!empty($records)) {
$count = 1;
if (isset($records['message']) && !empty($records['message'])) {
if ($records['messageKey'] == 'noRecordings') {
$recordArray[] = get_lang('NoRecording');
@ -858,4 +860,77 @@ class bbb
echo '</script>';
exit;*/
}
/**
* @return string
*/
public function getConferenceUrl()
{
return api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.api_get_cidreq();
}
/**
* @return string
*/
public function getListingUrl()
{
return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq();
}
/**
* @param array $meeting
* @return string
*/
public function endUrl($meeting)
{
return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq().'&action=end&id='.$meeting['id'];
}
/**
* @param array $meeting
* @param array $record
* @return string
*/
public function addToCalendarUrl($meeting, $record = [])
{
$url = isset($record['playbackFormatUrl']) ? $record['playbackFormatUrl'] : '';
return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq().'&action=add_to_calendar&id='.$meeting['id'].'&start='.api_strtotime($meeting['created_at']).'&url='.$url;
}
/**
* @param array $meeting
* @return string
*/
public function publishUrl($meeting)
{
return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq().'&action=publish&id='.$meeting['id'];
}
/**
* @param array $meeting
* @return string
*/
public function unPublishUrl($meeting)
{
return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq().'&action=unpublish&id='.$meeting['id'];
}
/**
* @param array $meeting
* @return string
*/
public function deleteRecordUrl($meeting)
{
return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq().'&action=delete_record&id='.$meeting['id'];
}
/**
* @param array $meeting
* @return string
*/
public function copyToRecordToLinkTool($meeting)
{
return api_get_path(WEB_PLUGIN_PATH).'bbb/listing.php?'.api_get_cidreq().'&action=copy_record_to_link_tool&id='.$meeting['id'];
}
}

@ -24,17 +24,27 @@ class BBBPlugin extends Plugin
)
);
public static function create()
/**
* BBBPlugin constructor.
*/
protected function __construct()
{
static $result = null;
return $result ? $result : $result = new self();
parent::__construct(
'2.2',
'Julio Montoya, Yannick Warnier',
array('tool_enable' => 'boolean', 'host' => 'text', 'salt' => 'text')
);
}
protected function __construct()
public static function create()
{
parent::__construct('2.2', 'Julio Montoya, Yannick Warnier', array('tool_enable' => 'boolean', 'host' =>'text', 'salt' => 'text'));
static $result = null;
return $result ? $result : $result = new self();
}
/**
* Install
*/
public function install()
{
$table = Database::get_main_table('plugin_bbb_meeting');
@ -61,6 +71,9 @@ class BBBPlugin extends Plugin
$this->install_course_fields_in_all_courses();
}
/**
* Uninstall
*/
public function uninstall()
{
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);

@ -1,14 +1,12 @@
<?php
/**
* This script initiates a videoconference session, calling the BigBlueButton API
* This script initiates a video conference session, calling the BigBlueButton API
* @package chamilo.plugin.bigbluebutton
*/
/**
* Initialization
*/
$course_plugin = 'bbb'; //needed in order to load the plugin lang variables
require_once dirname(__FILE__).'/config.php';
require_once __DIR__.'/config.php';
$plugin = BBBPlugin::create();
$tool_name = $plugin->get_lang('Videoconference');
$tpl = new Template($tool_name);
@ -17,6 +15,7 @@ $bbb = new bbb();
$action = isset($_GET['action']) ? $_GET['action'] : null;
$teacher = $bbb->isTeacher();
$courseInfo = api_get_course_info();
api_protect_course_script(true);
$message = null;
@ -32,7 +31,7 @@ if ($teacher) {
$title = sprintf(get_lang('VideoConferenceXCourseX'), $id, $course_info['name']);
$content = Display::url(get_lang('GoToTheVideoConference'), $_GET['url']);
$event_id = $agenda->addEvent(
$eventId = $agenda->addEvent(
$_REQUEST['start'],
null,
'true',
@ -40,7 +39,7 @@ if ($teacher) {
$content,
array('everyone')
);
if (!empty($event_id)) {
if (!empty($eventId)) {
$message = Display::return_message(get_lang('VideoConferenceAddedToTheCalendar'), 'success');
} else {
$message = Display::return_message(get_lang('Error'), 'error');
@ -112,13 +111,12 @@ if ($meeting_exists || $teacher) {
$tpl->assign('allow_to_edit', $teacher);
$tpl->assign('meetings', $meetings);
$conferenceUrl = api_get_path(WEB_PLUGIN_PATH).'bbb/start.php?launch=1&'.api_get_cidreq();
$conferenceUrl = $bbb->getConferenceUrl();
$tpl->assign('conference_url', $conferenceUrl);
$tpl->assign('users_online', $users_online);
$tpl->assign('bbb_status', $status);
$tpl->assign('show_join_button', $show_join_button);
//$tpl->assign('actions', $actions);
$tpl->assign('message', $message);
$listing_tpl = 'bbb/listing.tpl';
$content = $tpl->fetch($listing_tpl);

@ -1,5 +1,5 @@
<?php
require_once dirname(__FILE__).'/config.php';
require_once __DIR__.'/config.php';
$plugin_info = BBBPlugin::create()->get_info();

@ -1 +1,2 @@
This plugin will create a link in existing and new courses for the teachers to start a videoconference room, as well as the administration settings to configure this tool.
This plugin will create a link in existing and new courses for the teachers to start a videoconference room,
as well as the administration settings to configure this tool.

@ -1,5 +1,4 @@
<?php
/**
* This script initiates a video conference session, calling the BigBlueButton API
* @package chamilo.plugin.bigbluebutton
@ -8,7 +7,7 @@
require __DIR__ . '/../../vendor/autoload.php';
$course_plugin = 'bbb'; //needed in order to load the plugin lang variables
require_once dirname(__FILE__).'/config.php';
require_once __DIR__.'/config.php';
$tool_name = get_lang('Videoconference');
$tpl = new Template($tool_name);
@ -16,8 +15,6 @@ $tpl = new Template($tool_name);
$vmIsEnabled = false;
$host = null;
$salt = null;
$bbb = new bbb();
if ($bbb->plugin_enabled) {
@ -64,12 +61,12 @@ if ($bbb->plugin_enabled) {
$url = $bbb->createMeeting($meeting_params);
$bbb->redirectToBBB($url);
} else {
$url = 'listing.php?'.api_get_cidreq();
$url = $bbb->getListingUrl();
$bbb->redirectToBBB($url);
}
}
} else {
$url = 'listing.php?'.api_get_cidreq();
$url = $bbb->getListingUrl();
header('Location: ' . $url);
exit;
}

@ -1,13 +1,10 @@
<?php
/**
* This script is included by main/admin/settings.lib.php when unselecting a plugin
* and is meant to remove things installed by the install.php script in both
* the global database and the courses tables
* @package chamilo.plugin.bigbluebutton
*/
/**
* Queries
*/
require_once dirname(__FILE__).'/config.php';
require_once __DIR__.'/config.php';
BBBPlugin::create()->uninstall();
Loading…
Cancel
Save