Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Converted block to run in Moodle 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenserJ committed Apr 11, 2011
1 parent cf2cfce commit ca89357
Show file tree
Hide file tree
Showing 19 changed files with 509 additions and 523 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Panopto CourseCast for Moodle 2

## What is it?

This is a block for Moodle 2, that allows courses in Moodle to link directly to Panopto Courses, and to display recordings in the sidebar. It also allows for SSO between Moodle and Panopto CourseCast, and automatically syncs user permissions between both systems

## Credits

The original Panopto CourseCast plugin was written by Panopto for Moodle 1.9. It has since been rewritten for Moodle 2, by [Spenser Jones](http://spenserjones.com), and subsequently made open-source for collaboration between the open-source community and Panopto.

## How can I help?

Fork the block, fix a bug or add a new feature, and send us a pull-request. Or, if you're not a developer, but you've found a bug, add it to our [issue tracker](https://github.com/SpenserJ/Moodle2-Panopto/issues).

## To do:
* Rewrite SSO.php
* Optimize lib/PanoptoSoapClient.php
* Rewrite db/install.xml to support Moodle 2
* Hook saving the block_config form, to auto-provision the course
* Convert role_(un)assigned event to only adjust single user in the course
* Move language-specific strings into lang/en/block_panopto.php
5 changes: 2 additions & 3 deletions SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
require_logout();

// Return to this page, minus the "action=relogin" parameter.
redirect($CFG->wwwroot .
$_SERVER['SCRIPT_NAME'] .
redirect($CFG->wwwroot . "/blocks/panopto/SSO.php" .
"?authCode=$request_auth_code" .
"&serverName=$server_name" .
"&expiration=$expiration" .
Expand All @@ -49,7 +48,7 @@
$separator = (strpos($callback_url, "?") ? "&" : "?");
$redirect_url = $callback_url . $separator . $response_params . "&authCode=" . $response_auth_code;

// Redirect to Panopto CourseCast login page.
// Redirect to Panopto Focus login page.
redirect($redirect_url);
}
else
Expand Down
31 changes: 10 additions & 21 deletions block_panopto.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class block_panopto extends block_base
// Set system properties of plugin.
function init()
{
$this->title = "Panopto CourseCast";
$this->version = 2010012730;
$this->title = "Panopto Focus";
}

// Block has global config (display "Settings" link on blocks admin page)
Expand Down Expand Up @@ -77,17 +76,17 @@ function get_content()
{
if(!$panopto_data->sessiongroup_id)
{
$this->content->text .= "No CourseCast course selected.";
$this->content->text .= "No Panopto course selected.";
}
else
{
// Get course info from SOAP service.
$course_info = $panopto_data->get_course();

// CourseCast course was deleted, or an exception was thrown while retrieving course data.
// Panopto course was deleted, or an exception was thrown while retrieving course data.
if($course_info->Access == "Error")
{
$this->content->text .= "<span class='error'>Error retrieving CourseCast course.</span>";
$this->content->text .= "<span class='error'>Error retrieving Panopto course.</span>";
}
else
{
Expand Down Expand Up @@ -193,7 +192,8 @@ function get_content()
</div>";
}
}
if(isteacheredit($COURSE->id))
$context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
if(has_capability('moodle/course:update', $context))
{
$this->content->text .= "<div class='sectionHeader'><b>Links</b></div>
<div class='listItem'>
Expand All @@ -211,13 +211,13 @@ function get_content()

$this->content->text .= '
<script type="text/javascript">
// Function to pop up CourseCast live note taker.
// Function to pop up Panopto live note taker.
function launchNotes(url)
{
// Open empty notes window, then POST SSO form to it.
var notesWindow = window.open("", "CourseCastNotes", "width=500,height=800,resizable=1,scrollbars=0,status=0,location=0");
var notesWindow = window.open("", "PanoptoNotes", "width=500,height=800,resizable=1,scrollbars=0,status=0,location=0");
document.SSO.action = url;
document.SSO.target = "CourseCastNotes";
document.SSO.target = "PanoptoNotes";
document.SSO.submit();
// Ensure the new window is brought to the front of the z-order.
Expand Down Expand Up @@ -255,18 +255,7 @@ function toggleHiddenLectures()
}
}
catch(Exception $e){
$this->content->text .= "<br><br><span class='error'>Error getting CourseCast course content.</span>";
}

// Block instance configuration convenience link.
// Duplicates "edit" icon for discoverability.
if(isteacheredit($COURSE->id))
{
$this->content->text .= "<div id='instanceConfigLink'>
<a href='$CFG->wwwroot/course/view.php?id=$COURSE->id&instanceid={$this->instance->id}&sesskey=$USER->sesskey&blockaction=config'>
Configure Block...
</a>
</div>";
$this->content->text .= "<br><br><span class='error'>Error getting Panopto course content.</span>";
}

$this->content->footer = '';
Expand Down
30 changes: 0 additions & 30 deletions config_global.html

This file was deleted.

46 changes: 0 additions & 46 deletions config_instance.html

This file was deleted.

55 changes: 55 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
//
// Capability definitions for the rss_client block.
//
// The capabilities are loaded into the database table when the block is
// installed or updated. Whenever the capability definitions are updated,
// the module version number should be bumped up.
//
// The system has four possible values for a capability:
// CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set).
//
//
// CAPABILITY NAMING CONVENTION
//
// It is important that capability names are unique. The naming convention
// for capabilities that are specific to modules and blocks is as follows:
// [mod/block]/<plugin_name>:<capabilityname>
//
// component_name should be the same as the directory name of the mod or block.
//
// Core moodle capabilities are defined thus:
// moodle/<capabilityclass>:<capabilityname>
//
// Examples: mod/forum:viewpost
// block/recent_activity:view
// moodle/site:deleteuser
//
// The variable name for the capability definitions array is $capabilities


$capabilities = array(

'block/panopto:provision_course' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
),

'block/panopto:provision_multiple' => array(

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'manager' => CAP_ALLOW
)
)

);


11 changes: 11 additions & 0 deletions db/events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$sync_users = array (
'handlerfile' => '/blocks/panopto/event_callbacks.php',
'handlerfunction' => 'sync_users',
'schedule' => 'instant'
);

$handlers = array (
'role_assigned' => $sync_users,
'roll_unassigned' => $sync_users
);
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="blocks/panopto/db" VERSION="20090610" COMMENT="XMLDB file for Panopto CourseCast block"
<XMLDB PATH="blocks/panopto/db" VERSION="20090610" COMMENT="XMLDB file for Panopto Focus block"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down
26 changes: 26 additions & 0 deletions edit_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
require_once("lib/panopto_data.php");

class block_panopto_edit_form extends block_edit_form {
protected function specific_definition($mform) {
global $COURSE, $CFG;

// Construct the Panopto data proxy object
$panopto_data = new panopto_data($COURSE->id);

if(!empty($panopto_data->servername) && !empty($panopto_data->instancename) && !empty($panopto_data->applicationkey))
{
$mform->addElement('header', 'configheader', 'Select the Panopto CourseCast course to display in this block.');

$params->course_ids = $COURSE->id;
$params->return_url = urlencode($_SERVER['REQUEST_URI']);
$query_string = http_build_query($params);
$provision_url = "$CFG->wwwroot/blocks/panopto/provision_course.php?" . $query_string;
$course_list = $panopto_data->get_course_options($provision_url);
$mform->addElement('selectgroups', 'config_course', 'Course', $course_list['courses']);
$mform->setDefault('config_course', $course_list['selected']);
} else {
$mform->addElement('static', 'error', '', 'Cannot configure block instance: Global configuration incomplete. Please contact your system administrator.');
}
}
}
19 changes: 19 additions & 0 deletions event_callbacks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
require_once('lib/panopto_data.php');

// Called by event handlers in Moodle 2
// Written by Spenser Jones (http://spenserjones.com) on behalf of Ambrose University College
function sync_users($ra) {
print_r($ra);
$context = get_context_instance_by_id($ra->contextid);
print_r($context);
$panopto_data = new panopto_data(null);

// Set the current Moodle course to retrieve info for / provision.
$panopto_data->moodle_course_id = $context->instanceid;
$provisioning_data = $panopto_data->get_provisioning_info();
print_r($provisioning_data);
$provisioned_data = $panopto_data->provision_course($provisioning_data);
print_r($provisioned_data);
return !empty($provisioned_data);
}
6 changes: 6 additions & 0 deletions lang/en/block_panopto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
$string['pluginname'] = 'Panopto';
$string['panopto:provision_course'] = 'Provision a course';
$string['panopto:provision_multiple'] = 'Provision multiple courses at once';
$string['provisioncourseselect'] = 'Select Courses to Provision.';
$string['provisioncourseselect_help'] = 'Multiple selections are possible by Ctrl-clicking (Windows) or Cmd-clicking (Mac).';
2 changes: 1 addition & 1 deletion lib/PanoptoSoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PanoptoSoapClient extends SoapClient
public function PanoptoSoapClient($server_name, $apiuser_userkey, $apiuser_authcode)
{
// Instantiate SoapClient in non-WSDL mode.
parent::__construct(null, array('location' => "http://$server_name/CourseCast/Services/ClientData.svc",
parent::__construct(null, array('location' => "http://$server_name/Panopto/Services/ClientData.svc",
'uri' => "http://services.panopto.com"));

// Cache web service credentials for all calls requiring authentication.
Expand Down
Loading

0 comments on commit ca89357

Please sign in to comment.