Commit a5bb37f0 authored by Penny Leach's avatar Penny Leach
Browse files

more work on artefact api, now the plugin class behaves properly and

does postinst and stuff
parent f2dc771e
<?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 artefact/internal
* @author Your Name <you@example.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
require_once(get_config('docroot') . 'artefact/lib.php');
class PluginArtefactInternal extends PluginArtefact {
public static function get_artefact_types() {
return array('profile', 'file', 'folder', 'image');
}
public static function get_plugin_name() {
return 'internal';
}
public static function postinst() {
$types = self::get_artefact_types();
$plugin = self::get_plugin_name();
$ph = array();
if (is_array($types)) {
foreach ($types as $type) {
$ph[] = '?';
if (!record_exists('installed_artefact_type', 'plugin', $plugin, 'name', $type)) {
$t = new StdClass;
$t->name = $type;
$t->plugin = $plugin;
insert_record('installed_artefact_type',$t);
}
// @todo handle case that two plugins provide artefacts with the same name.
}
delete_records_select('installed_artefact_type','(plugin = ? AND name NOT IN (' . implode(',', $ph) . '))',
array_merge(array($plugin),$types));
}
}
}
?>
...@@ -40,7 +40,7 @@ class UndefinedArtefactFieldException extends Exception {} ...@@ -40,7 +40,7 @@ class UndefinedArtefactFieldException extends Exception {}
* Base artefact plugin class * Base artefact plugin class
* @abstract * @abstract
*/ */
abstract class ArtefactPlugin { abstract class PluginArtefact extends Plugin {
/** /**
* This function returns a list of classnames * This function returns a list of classnames
...@@ -49,6 +49,13 @@ abstract class ArtefactPlugin { ...@@ -49,6 +49,13 @@ abstract class ArtefactPlugin {
*/ */
public static abstract function get_artefact_types(); public static abstract function get_artefact_types();
/**
* This function returns the name of the plugin.
* @return string
*/
public static abstract function get_plugin_name();
/** /**
* This function returns an array of menu items * This function returns an array of menu items
* to be displayed * to be displayed
...@@ -61,6 +68,7 @@ abstract class ArtefactPlugin { ...@@ -61,6 +68,7 @@ abstract class ArtefactPlugin {
return array(); return array();
} }
/** /**
* This function handles an event that has been * This function handles an event that has been
* generated, that the plugin has asked to be * generated, that the plugin has asked to be
...@@ -150,16 +158,34 @@ abstract class ArtefactType { ...@@ -150,16 +158,34 @@ abstract class ArtefactType {
// @todo // @todo
} }
/**
* This function returns the db rows
* from the artefact table that have this
* artefact as the parent.
* If you want instances, use {@link get_children_instances}
* but bear in mind this will have a performance impact.
*
* @return array
*/
public function get_children_metadata() { public function get_children_metadata() {
// @todo return get_records('artefact','parentid',$this->id);
} }
public function get_parent_instance() { public function get_parent_instance() {
// @todo // @todo
} }
/**
* This function returns the db row
* (if there is one) of the parent
* artefact for this instance.
* If you want the instance, use
* {@link get_parent_instance} instead.
*
* @return object (db row)
*/
public function get_parent_metadata() { public function get_parent_metadata() {
// @todo return get_record('artefact','id',$this->parentid);
} }
public function get($field) { public function get($field) {
...@@ -205,7 +231,6 @@ abstract class ArtefactType { ...@@ -205,7 +231,6 @@ abstract class ArtefactType {
// @todo // @todo
} }
public static abstract function get_render_list($format); public static abstract function get_render_list($format);
public static abstract function can_render_to($format); public static abstract function can_render_to($format);
......
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