Commit 3ac897fc authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Make grouptypes into plugins

parent fb4515ab
......@@ -46,14 +46,9 @@ if (!group_user_access($groupid)) {
define('TITLE', $group->name . ' - ' . get_string('groupfiles', 'artefact.file'));
require_once(get_config('docroot') . 'interaction/lib.php');
require_once(get_config('docroot') . 'lib/grouptype/' . $group->grouptype . '.php');
$groupdata = json_encode($group);
$grouproles = array();
foreach (call_static_method('GroupType' . $group->grouptype, 'get_roles') as $role) {
$grouproles[] = array('name' => $role, 'display' => get_string($role, 'grouptype.'.$group->grouptype));
}
$grouproles = json_encode($grouproles);
$grouproles = json_encode(array_values(group_get_role_info($groupid)));
$javascript .= <<<GROUPJS
var group = {$groupdata};
......
......@@ -580,8 +580,8 @@ abstract class ArtefactType {
return;
}
$type = get_field('group', 'grouptype', 'id', $group);
require_once(get_config('docroot') . 'lib/grouptype/' . $type . '.php');
$roles = call_static_method('GroupType' . $type, 'get_roles');
require_once(get_config('libroot') . 'group.php');
$roles = array_keys(group_get_role_info($group));
$id = $this->get('id');
db_begin();
delete_records('artefact_access_role', 'artefact', $id);
......
......@@ -33,7 +33,7 @@ define('TITLE', get_string('creategroup', 'group'));
$groupoptions = array();
foreach (group_get_grouptypes() as $grouptype) {
require_once('grouptype/' . $grouptype . '.php');
safe_require('grouptype', $grouptype);
if (call_static_method('GroupType' . $grouptype, 'can_be_created_by_user')) {
$grouptypename = get_string('name', 'grouptype.' . $grouptype);
foreach (call_static_method('GroupType' . $grouptype, 'allowed_join_types') as $jointype) {
......
......@@ -46,11 +46,11 @@ if (!$group_data) {
$groupoptions = array();
foreach (group_get_grouptypes() as $grouptype) {
require_once('grouptype/' . $grouptype . '.php');
safe_require('grouptype', $grouptype);
if (call_static_method('GroupType' . $grouptype, 'can_be_created_by_user')) {
$grouptypename = get_string('name', 'group.' . $grouptype);
$grouptypename = get_string('name', 'grouptype.' . $grouptype);
foreach (call_static_method('GroupType' . $grouptype, 'allowed_join_types') as $jointype) {
$groupoptions["$grouptype.$jointype"] = $grouptypename . ': ' . get_string($jointype, 'group');
$groupoptions["$grouptype.$jointype"] = $grouptypename . ': ' . get_string('membershiptype.'.$jointype, 'group');
}
}
}
......
......@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @subpackage grouptype-course
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
......@@ -26,7 +26,8 @@
defined('INTERNAL') || die();
require_once('group.php');
class PluginGrouptypeCourse extends PluginGrouptype {
}
class GroupTypeCourse extends GroupType {
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage grouptype-course
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
$config->version = 2008062307;
$config->release = '0.1';
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage notification
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
abstract class PluginGrouptype extends Plugin {
public static function postinst($prevversion) {
if ($prevversion == 0) {
$classname = get_class($this);
$type = substr($classname, strlen('PluginGrouptype'));
call_static_method('GroupType'.$type, 'install');
}
}
}
/**
* Where is the syntax error?
*/
abstract class GroupType {
public function install() {
// These tables may already be populated if the site is being
// upgraded from before grouptypes became plugins, so check
// before inserting these records.
if (record_exists('grouptype', 'name', 'standard')) {
return;
}
$classname = get_class($this);
$type = strtolower(substr($classname, strlen('GroupType')));
$assessingroles = $this->get_view_assessing_roles();
insert_record('grouptype', (object) array(
'name' => $type,
'submittableto' => !empty($assessingroles),
));
$roles = $this->get_roles();
if (!in_array('admin', $roles)) {
$roles[] = 'admin';
}
$editingroles = $this->get_view_editing_roles();
foreach ($roles as $r) {
insert_record('grouptype_roles', (object) array(
'grouptype' => $type,
'role' => $r,
'edit_views' => (int)in_array($r, $editingroles),
'see_submitted_views' => (int)in_array($r, $assessingroles),
));
}
}
public static abstract function allowed_join_types();
/**
* Returns whether the currently logged in user can create a group of this
* grouptype
*/
public static function can_be_created_by_user() {
return true;
}
/**
* Returns the roles this group type implements
*/
public static abstract function get_roles();
public static abstract function get_view_editing_roles();
public static abstract function get_view_assessing_roles();
}
?>
......@@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage core
* @subpackage grouptype-standard
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
......@@ -26,7 +26,8 @@
defined('INTERNAL') || die();
require_once('group.php');
class PluginGrouptypeStandard extends PluginGrouptype {
}
class GroupTypeStandard extends GroupType {
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage grouptype-standard
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
$config->version = 2008062307;
$config->release = '0.1';
?>
......@@ -1131,6 +1131,62 @@ function xmldb_core_upgrade($oldversion=0) {
execute_sql("UPDATE {grouptype_roles} SET see_submitted_views = 1 WHERE grouptype = 'course' AND role = 'tutor'");
}
if ($oldversion < 2008062307) {
// create grouptype tables
$table = new XMLDBTable('grouptype_installed');
$table->addFieldInfo('name', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('version', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('release', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL);
$table->addFieldInfo('active', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 1);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('name'));
create_table($table);
$table = new XMLDBTable('grouptype_cron');
$table->addFieldInfo('plugin', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('callfunction', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('minute', XMLDB_TYPE_CHAR, 25, null, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('hour', XMLDB_TYPE_CHAR, 25, null, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('day', XMLDB_TYPE_CHAR, 25, null, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('dayofweek', XMLDB_TYPE_CHAR, 25, null, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('month', XMLDB_TYPE_CHAR, 25, null, XMLDB_NOTNULL, null, null, null, '*');
$table->addFieldInfo('nextrun', XMLDB_TYPE_DATETIME, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('plugin', 'callfunction'));
$table->addKeyInfo('pluginfk', XMLDB_KEY_FOREIGN, array('plugin'), 'grouptype_installed', array('name'));
create_table($table);
$table = new XMLDBTable('grouptype_config');
$table->addFieldInfo('plugin', XMLDB_TYPE_CHAR, 100, null, XMLDB_NOTNULL);
$table->addFieldInfo('field', XMLDB_TYPE_CHAR, 100, null, XMLDB_NOTNULL);
$table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('plugin', 'field'));
$table->addKeyInfo('pluginfk', XMLDB_KEY_FOREIGN, array('plugin'), 'grouptype_installed', array('name'));
create_table($table);
$table = new XMLDBTable('grouptype_event_subscription');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null,
XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->addFieldInfo('plugin', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('event', XMLDB_TYPE_CHAR, 50, null, XMLDB_NOTNULL);
$table->addFieldInfo('callfunction', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('pluginfk', XMLDB_KEY_FOREIGN, array('plugin'), 'grouptype_installed', array('name'));
$table->addKeyInfo('eventfk', XMLDB_KEY_FOREIGN, array('event'), 'event_type', array('name'));
$table->addKeyInfo('subscruk', XMLDB_KEY_UNIQUE, array('plugin', 'event', 'callfunction'));
create_table($table);
if ($data = check_upgrades('grouptype.standard')) {
upgrade_plugin($data);
}
if ($data = check_upgrades('grouptype.course')) {
upgrade_plugin($data);
}
}
return $status;
}
......
......@@ -419,6 +419,7 @@ function group_get_role_info($groupid) {
WHERE g.id = ?', array($groupid));
foreach ($roles as $role) {
$role->display = get_string($role->role, 'grouptype.'.$role->grouptype);
$role->name = $role->role;
}
return $roles;
}
......@@ -463,54 +464,6 @@ function group_get_membersearch_data($group, $query, $offset, $limit) {
return array($html, $pagination, $results['count'], $offset);
}
/**
* Where is the syntax error?
*/
abstract class GroupType {
public function install() {
$classname = get_class($this);
$type = strtolower(substr($classname, strlen('GroupType')));
$assessingroles = $this->get_view_assessing_roles();
insert_record('grouptype', (object) array(
'name' => $type,
'submittableto' => !empty($assessingroles),
));
$roles = $this->get_roles();
if (!in_array('admin', $roles)) {
$roles[] = 'admin';
}
$editingroles = $this->get_view_editing_roles();
foreach ($roles as $r) {
insert_record('grouptype_roles', (object) array(
'grouptype' => $type,
'role' => $r,
'edit_views' => (int)in_array($r, $editingroles),
'see_submitted_views' => (int)in_array($r, $assessingroles),
));
}
}
public static abstract function allowed_join_types();
/**
* Returns whether the currently logged in user can create a group of this
* grouptype
*/
public static function can_be_created_by_user() {
return true;
}
/**
* Returns the roles this group type implements
*/
public static abstract function get_roles();
public static abstract function get_view_editing_roles();
public static abstract function get_view_assessing_roles();
}
/**
* Returns a list of available grouptypes
......@@ -519,19 +472,7 @@ function group_get_grouptypes() {
static $grouptypes = null;
if (is_null($grouptypes)) {
$grouptypes = array();
$grouptypedir = get_config('libroot') . 'grouptype/';
if ($dh = opendir($grouptypedir)) {
while (false !== ($file = readdir($dh))) {
if (!preg_match('/^[a-zA-Z0-9-]+\.php$/', $file)) {
continue;
}
if (is_file("$grouptypedir$file")) {
$grouptypes[] = substr($file, 0, -4);
}
}
}
$grouptypes = get_column('grouptype', 'name');
}
return $grouptypes;
......
......@@ -311,10 +311,6 @@ function get_string_location($identifier, $section, $variables, $replacefunc='fo
if (false === strpos($section, '.')) {
$langdirectory = 'lang/';
}
else if (strpos($section, 'grouptype.') === 0) {
$grouptypename = substr($section ,strlen('grouptype.'));
$langdirectory = 'lib/grouptype/lang/';
}
else {
$extras = plugin_types(); // more later..
foreach ($extras as $tocheck) {
......@@ -896,7 +892,7 @@ function plugin_types() {
static $pluginstocheck;
if (empty($pluginstocheck)) {
// ORDER MATTERS! artefact has to be first!
$pluginstocheck = array('artefact', 'auth', 'notification', 'search', 'blocktype', 'interaction');
$pluginstocheck = array('artefact', 'auth', 'notification', 'search', 'blocktype', 'interaction', 'grouptype');
}
return $pluginstocheck;
}
......
......@@ -585,14 +585,6 @@ function core_install_lastcoredata_defaults() {
insert_record('usr', $user);
}
// add standard and course group types
require_once(get_config('docroot') . 'lib/grouptype/standard.php');
$gt = new GroupTypeStandard;
$gt->install();
require_once(get_config('docroot') . 'lib/grouptype/course.php');
$gt = new GroupTypeCourse;
$gt->install();
// Insert the admin user
$user = new StdClass;
$user->username = 'admin';
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008062306;
$config->version = 2008062307;
$config->release = '1.1.0alpha';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
......@@ -88,7 +88,7 @@ class View {
$this->dirtycolumns = array();
if ($this->group) {
$group = get_record('group', 'id', $this->group);
require_once(get_config('docroot') . 'lib/grouptype/' . $group->grouptype . '.php');
safe_require('grouptype', $group->grouptype);
$this->editingroles = call_static_method('GroupType' . $group->grouptype, 'get_view_editing_roles');
}
}
......
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