Source for file module_presenter.php
Documentation is available at module_presenter.php
// This file is part of the Sloodle project (www.sloodle.org)
* This file defines a Presenter module for Sloodle.
* @copyright Copyright (c) 2008 Sloodle (various contributors)
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
* @contributor Peter R. Bloomfield
/** The Sloodle module base. */
require_once(SLOODLE_LIBROOT.
'/modules/module_base.php');
/** General Sloodle functions. */
require_once(SLOODLE_LIBROOT.
'/general.php');
* The Sloodle presenter module class.
* Internal for Moodle only - course module instance.
* Corresponds to one record from the Moodle 'course_modules' table.
* Internal only - Sloodle module instance database object.
* Corresponds to one record from the Moodle 'mdl_sloodle' table.
* Internal only - a database objects representing the Presenter itself.
* Corresponds to one record from the Moodle 'mdl_sloodle_presenter' table.
parent::$constructor($_session);
* Loads data from the database.
* Note: even if the function fails, it may still have overwritten some or all existing data in the object.
* @param mixed $id The site-wide unique identifier for all modules. Type depends on VLE. On Moodle, it is an integer course module identifier ('id' field of 'course_modules' table)
* @return bool True if successful, or false otherwise
// Make sure the ID is valid
if ($id <=
0) return false;
// Fetch the course module data
if (!($this->cm =
get_coursemodule_from_id('sloodle', $id))) {
sloodle_debug("Failed to load course module instance #$id.<br/>");
// Make sure the module is visible
if ($this->cm->visible ==
0) {
sloodle_debug("Error: course module instance #$id not visible.<br/>");
// Load from the primary table: sloodle instance
sloodle_debug("Failed to load Sloodle module with instance ID #{$cm->instance}.<br/>
");
// Load from the secondary table: sloodle_presenter
if (!($this->presenter =
get_record('sloodle_presenter', 'sloodleid', $this->cm->instance))) {
sloodle_debug("Failed to load secondary module table with instance ID #{$cm->instance}.<br/>
");
* Gets an array of absolute URLs to images in this slideshow, all correctly ordered.
* @return 2d numeric array, each element associates an entry ID to a numeric array of URL string, the name of the source type, and the name of the slide.
// Search the database for entries
$recs =
get_records_select('sloodle_presenter_entry', "sloodleid = {$this->sloodle_instance->id}", 'ordering');
if (!$recs) return array();
// Format it all nicely into a simple array
// Substitute the URL for the name if the name has been left blank (this can particularly happen on Presenters upgraded from an alpha version)
if (empty($name)) $name =
$r->source;
$output[$r->id] =
array($r->source, $r->type, $name);
* Gets an ordered associative array of slides in presentation order.
* @return Array associating slide IDs to SloodlePresenterSlide objects if successful, or false if not.
// Make sure we have valid ordering
// Fetch the database records
$recs =
get_records_select('sloodle_presenter_entry', "sloodleid = {$this->sloodle_instance->id}", 'ordering');
if (!$recs) return array();
// Construct the array of objects
// Substitute the source data for the name if no name is given.
if (empty($name)) $name =
$r->source;
// Update legacy slide types
case 'image':
$type =
'PresenterSlideImage'; break;
case 'web':
$type =
'PresenterSlideWeb'; break;
case 'video':
$type =
'PresenterSlideVideo'; break;
// Remove the 'SloodlePlugin' prefix if necessary
// Add the slide to our list
$output[$r->id] =
new SloodlePresenterSlide($r->id, $this, $name, $r->source, $type, $r->ordering, $slideposition);
* Adds a new entry to the presentation.
* @param string $source A string containing the source address -- must start with http for absolute URLs
* @param string $type Name of the type of source, e.g. "web", "image", or "video"
* @param string $name Name of the slide
* @param integer $position Integer indicating the position of the new entry. If negative, then it is placed last in the presentation.
* @return True if successful, or false on failure.
function add_entry($source, $type, $name, $position = -
1)
// Make sure our entry ordering is valid before we start
// Construct and attempt to insert the new record
$num =
count_records('sloodle_presenter_entry', 'sloodleid', $this->sloodle_instance->id);
$rec->ordering =
((int)
$num +
1) *
10;
$rec->ordering =
($position *
10) -
1; // Ordering works in multiples of 10, starting at 10.
$result = (bool)
insert_record('sloodle_presenter_entry', $rec, false);
// Make sure our entry ordering is valid again now
* Edits an existing entry in the presentation.
* @param int $id The ID of the entry in the database.
* @param string $source A string containing the source address -- must start with http for absolute URLs
* @param string $type Name of the type of source, e.g. "web", "image", or "video"
* @param string $name Name of the slide
* @param integer $position Integer indicating the desired position of the entry. If negative, then its position is left unchanged.
* @return True if successful, or false on failure.
function edit_entry($id, $source, $type, $name, $position = -
1)
// Ensure we have valid ordering to begin with
// Attempt to fetch the existing entry from the database
$rec =
get_record('sloodle_presenter_entry', 'id', $id, 'sloodleid', $this->sloodle_instance->id);
// Apply the changes to the record
$rec->ordering =
($position *
10) -
1; // Ordering works in multiples of 10, starting at 10.
$result = (bool)
update_record('sloodle_presenter_entry', $rec);
// Make sure our entry ordering is valid
* Deletes the identified entry by ID.
* Only works if the entry is part of this presentation.
* @param int $id The ID of an entry record to delete
delete_records('sloodle_presenter_entry', 'sloodleid', $this->sloodle_instance->id, 'id', $id);
* Moves the ID'd entry forward or back in the presentation ordering.
* Only works if the entry is part of this presentation.
* @param int $id The ID of the entry to move.
* @param bool $forward TRUE to move the entry forward (closer to the beginning) or FALSE to push it back (closer to the end)
// Start by ensuring uniform ordering, starting at 10.
// Attempt to move the specified entry in the appropriate direction
$entry =
get_record('sloodle_presenter_entry', 'sloodleid', $this->sloodle_instance->id, 'id', $id);
// Avoid a negative ordering value.
if ($entry->ordering >=
20) $entry->ordering -=
15;
update_record('sloodle_presenter_entry', $entry);
// Re-validate the entry ordering
* Relocates the identified entry to the specified position in the presentation.
* Positions count from 1 upwards. If an entry already exists in that location, then the existing entry is pushed to the next position.
* @param int $id The ID of the entry to relocate
* @param int $pos The position in the presentation to move the slide to
// Start by ensuring uniform ordering, starting at 10.
// Calculate the ordering value for our entry.
// The first entry in a presentation has ordering 10, and subsequent entries increment by 10.
// Therefore, we can insert an entry before an existing slot by moving it to one BEFORE the appropriate multiple of 10.
$newordering =
($pos *
10) -
1;
// Write the new ordering to the database, and re-validate the order
$entry =
get_record('sloodle_presenter_entry', 'sloodleid', $this->sloodle_instance->id, 'id', $id);
$entry->ordering =
$newordering;
update_record('sloodle_presenter_entry', $entry);
* Validates the ordering value of all entries in the presenter.
* Gives each record an ordering value from 10 upwards, incrementing by 10 each time.
// Get all entries in this presentation
$entries =
get_records('sloodle_presenter_entry', 'sloodleid', $this->sloodle_instance->id, 'ordering');
if (!$entries ||
count($entries) <=
1) return;
// Go through each entry in our array, and give it a valid ordering value.
foreach ($entries as $entry) {
$entry->ordering =
$ordering;
update_record('sloodle_presenter_entry', $entry);
* Gets the width of the Presenter frame (for viewing in Moodle).
* @return int Width of the Presenter frame.
* Gets the height of the Presenter frame (for viewing in Moodle).
* @return int Height of the Presenter frame.
* Gets the name of this module instance.
* @return string The name of this module
* Gets the intro description of this module instance, if available.
* @return string The intro description of this controller
* Gets the identifier of the course this controller belongs to.
* @return mixed Course identifier. Type depends on VLE. (In Moodle, it will be an integer).
* Gets the time at which this instance was created, or 0 if unknown.
* Gets the time at which this instance was last modified, or 0 if unknown.
* Gets the short type name of this instance.
* Gets the full type name of this instance, according to the current language pack, if available.
* Note: should be overridden by sub-classes.
* @return string Full type name if possible, or the short name otherwise.
* Defines a single slide from a presentation, containing raw data.
* The data will usually need to interpreted by a slide plugin.
function SloodlePresenterSlide($id=
0, $presenter=
null, $name=
'', $source=
'', $type=
'', $ordering=
0, $slideposition=
0)
* The ID of this slide in the DB table of slides.
* The SloodleModulePresenter object relating the presentation this slide is in
* @var SloodleModulePresenter
* The source data for this slide. Normally this would be an absolute url (starting with a protocol specifier like HTTP),
* or a relative path, in which case it is treated as an internal Moodle file.
* Plugins may alternatively use this to store data which is to be rendered.
* The type of this slide. This will be the ID of a plugin, or it may be a legacy type, 'web', 'image', or 'video'.
* The ordering value for this slide. This should not generally be used. Refer to 'slideposition' instead.
* The position of this slide in the presentation. This is a 1-based count.
Documentation generated on Fri, 17 Jul 2009 11:02:05 +0100 by phpDocumentor 1.4.0