Commit 532c1157 authored by Penny Leach's avatar Penny Leach Committed by Nigel McNie
Browse files

more work on plugin stuff to support blocktypes.

parent 78f1a5c6
<TABLE NAME="artefact_installed_type">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="plugin" TYPE="char" LENGTH="255" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="artefact_installed" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="auth_installed">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="version" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="release" TYPE="text" LENGTH="small" NOTNULL="true" />
<FIELD NAME="active" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
<FIELD NAME="requires_config" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="requires_parent" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="auth_instance">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="instancename" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="priority" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="authname" TYPE="char" LENGTH="255" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="authnamefk" TYPE="foreign" FIELDS="authname" REFTABLE="auth_installed" REFFIELDS="name" />
<KEY NAME="institutionfk" TYPE="foreign" FIELDS="institution" REFTABLE="institution" REFFIELDS="name" />
</KEYS>
</TABLE>
<!-- auth plugin tables -->
<TABLE NAME="auth_config">
<FIELDS>
<FIELD NAME="plugin" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="field" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="value" TYPE="text" LENGTH="small" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="plugin,field" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="auth_installed" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="auth_instance_config">
<FIELDS>
<FIELD NAME="instance" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="field" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="value" TYPE="text" LENGTH="small" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="instance,field" />
<KEY NAME="instancefk" TYPE="foreign" FIELDS="instance" REFTABLE="auth_instance" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="auth_cron">
<FIELDS>
<FIELD NAME="plugin" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="callfunction" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="nextrun" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="minute" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="hour" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="day" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="month" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="dayofweek" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="plugin,callfunction" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="auth_installed" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="auth_event_subscription">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" SEQUENCE="true" NOTNULL="true" />
<FIELD NAME="plugin" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="event" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="callfunction" TYPE="char" LENGTH="255" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="auth_installed" REFFIELDS="name" />
<KEY NAME="eventfk" TYPE="foreign" FIELDS="event" REFTABLE="event_type" REFFIELDS="name" />
<KEY NAME="subscruk" TYPE="unique" FIELDS="plugin,event,callfunction" />
</KEYS>
</TABLE>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage blocktype
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
/**
* Base blocktype plugin class
* @abstract
*/
abstract class PluginBlocktype extends Plugin {
public static function extra_xmldb_substitution($xml) {
return str_replace(
'<!-- PLUGINTYPE_INSTALLED_EXTRAFIELDS -->',
' <FIELD NAME="artefactplugin" TYPE="int" LENGTH="10" NOTNULL="false" />',
str_replace(
'<!-- PLUGINTYPE_INSTALLED_EXTRAKEYS -->',
'<KEY NAME="artefactpluginfk" TYPE="foreign" FIELDS="artefactplugin" REFTABLE="artefact_installed" REFFIELDS="name" />',
$xml
)
);
}
public static abstract function get_title();
public static abstract function get_description();
public static abstract function get_categories();
/**
* This function must be implemented in the subclass if it has config
*/
public static function config_form($id=0) {
if ($this->has_config()) {
throw new Exception(get_string('blocktypemissingconfigform', 'error', get_class($this)));
}
return false;
}
/**
* This function must be implemented in the subclass if it has config
* $values must contain a hidden 'id' field.
*/
public function config_save(Pieform $form, $values) {
if ($this->has_config()) {
throw new Exception(get_string('blocktypemissingconfigsave', 'error', get_class($this)));
}
return false;
}
public static function has_config() {
return false;
}
}
class BlockInstance {
private $id;
private $blocktype;
private $title;
private $configdata;
private $dirty;
public function get($field) {
if (!property_exists($this, $field)) {
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
}
return $this->{$field};
}
public function set($field, $value) {
if (property_exists($this, $field)) {
if ($this->{$field} != $value) {
// only set it to dirty if it's changed
$this->dirty = true;
}
$this->{$field} = $value;
return true;
}
throw new InvalidArgumentException("Field $field wasn't found in class " . get_class($this));
}
public function __construct() {
// @todo
}
public static function factory($id) {
// @todo
}
}
?>
<TABLE NAME="__PLUGINTYPE___installed">
<FIELDS>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="version" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="release" TYPE="text" LENGTH="small" NOTNULL="true" />
<FIELD NAME="active" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
<!-- PLUGINTYPE_INSTALLED_EXTRAFIELDS -->
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="name" />
<!-- PLUGINTYPE_INSTALLED_EXTRAKEYS -->
</KEYS>
</TABLE>
<TABLE NAME="__PLUGINTYPE___config">
<FIELDS>
<FIELD NAME="plugin" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="field" TYPE="char" LENGTH="100" NOTNULL="true" />
<FIELD NAME="value" TYPE="text" LENGTH="small" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="plugin,field" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="__PLUGINTYPE___installed" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="__PLUGINTYPE___cron">
<FIELDS>
<FIELD NAME="plugin" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="callfunction" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="nextrun" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="minute" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="hour" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="day" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="month" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
<FIELD NAME="dayofweek" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="*" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="plugin,callfunction" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="__PLUGINTYPE___installed" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="__PLUGINTYPE___event_subscription">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" SEQUENCE="true" NOTNULL="true" />
<FIELD NAME="plugin" TYPE="char" LENGTH="255" NOTNULL="true" />
<FIELD NAME="event" TYPE="char" LENGTH="50" NOTNULL="true" />
<FIELD NAME="callfunction" TYPE="char" LENGTH="255" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
<KEY NAME="pluginfk" TYPE="foreign" FIELDS="plugin" REFTABLE="__PLUGINTYPE___installed" REFFIELDS="name" />
<KEY NAME="eventfk" TYPE="foreign" FIELDS="event" REFTABLE="event_type" REFFIELDS="name" />
<KEY NAME="subscruk" TYPE="unique" FIELDS="plugin,event,callfunction" />
</KEYS>
</TABLE>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment