Commit 94e7bfd8 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Initial commit of grouptype work. Yay!

A directory structure has been added in lib/ for grouptypes, and the skeletons for the standard and course ones are in place.

The group creation page shows the dropdown used for selecting group type/join type. Although currently creation itself is broken.
parent a42d292e
......@@ -425,15 +425,6 @@ class User {
return isset($a[$institution]);
}
/**
* There is currently no difference in privileges of site staff
* and institutional staff
*/
public function can_create_controlled_groups() {
return $this->get('admin') || $this->get('staff') || $this->is_institutional_admin()
|| $this->is_institutional_staff();
}
public function can_edit_institution($institution = null) {
return $this->get('admin') || $this->is_institutional_admin($institution);
}
......
......@@ -28,15 +28,18 @@ define('INTERNAL', 1);
define('MENUITEM', 'groups/groupsiown');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('pieforms/pieform.php');
require_once('group.php');
define('TITLE', get_string('creategroup', 'group'));
$joinoptions = array(
'invite' => get_string('membershiptype.invite', 'group'),
'request' => get_string('membershiptype.request', 'group'),
'open' => get_string('membershiptype.open', 'group'),
);
if ($USER->can_create_controlled_groups()) {
$joinoptions['controlled'] = get_string('membershiptype.controlled', 'group');
$groupoptions = array();
foreach (group_get_grouptypes() as $grouptype) {
require_once('grouptype/' . $grouptype . '.php');
if (call_static_method('GroupType' . $grouptype, 'can_be_created_by_user')) {
$grouptypename = get_string('name', 'group.' . $grouptype);
foreach (call_static_method('GroupType' . $grouptype, 'allowed_join_types') as $jointype) {
$groupoptions["$grouptype.$jointype"] = $grouptypename . ': ' . get_string($jointype, 'group');
}
}
}
$creategroup = pieform(array(
......@@ -56,11 +59,11 @@ $creategroup = pieform(array(
'rows' => 10,
'cols' => 55,
),
'membershiptype' => array(
'grouptype' => array(
'type' => 'select',
'title' => get_string('membershiptype', 'group'),
'options' => $joinoptions,
'defaultvalue' => 'open',
'title' => get_string('grouptype', 'group'),
'options' => $groupoptions,
'defaultvalue' => 'standard.open',
'help' => true,
),
'submit' => array(
......@@ -70,13 +73,16 @@ $creategroup = pieform(array(
),
));
function creategroup_validate(Pieform $form, $values) {
global $USER;
global $SESSION;
$smarty = smarty();
$smarty->assign('creategroup', $creategroup);
$smarty->display('group/create.tpl');
$cid = get_field('group', 'id', 'name', $values['name']);
if ($cid) {
function creategroup_validate(Pieform $form, $values) {
//global $USER;
//global $SESSION;
if (get_field('group', 'id', 'name', $values['name'])) {
$form->set_error('name', get_string('groupalreadyexists', 'group'));
}
}
......@@ -98,8 +104,8 @@ function creategroup_submit(Pieform $form, $values) {
(object) array(
'name' => $values['name'],
'description' => $values['description'],
'grouptype' => $values['grouptype'],
'jointype' => $values['membershiptype'],
'owner' => $USER->get('id'),
'ctime' => $now,
'mtime' => $now,
),
......@@ -107,29 +113,19 @@ function creategroup_submit(Pieform $form, $values) {
true
);
// If the user is a staff member, they should be added as a tutor automatically
if ($values['membershiptype'] == 'controlled' && $USER->can_create_controlled_groups()) {
insert_record(
'group_member',
(object) array(
'group' => $id,
'member' => $USER->get('id'),
'ctime' => $now,
'tutor' => 1
)
);
}
else {
insert_record(
'group_member',
(object) array(
'group' => $id,
'member' => $USER->get('id'),
'ctime' => $now,
'tutor' => 0
)
);
}
// Clone role instances for group type and put in the right table
// TODO
// Make the user an admin (must have some way of establishing the 'admin' role instance)
//insert_record(
// 'group_member',
// (object) array(
// 'group' => $id,
// 'member' => $USER->get('id'),
// 'roleinstance' => ?
// 'ctime' => $now,
// )
//);
$SESSION->add_ok_msg(get_string('groupsaved', 'group'));
......@@ -138,10 +134,4 @@ function creategroup_submit(Pieform $form, $values) {
redirect('/group/mygroups.php');
}
$smarty = smarty();
$smarty->assign('creategroup', $creategroup);
$smarty->display('group/create.tpl');
?>
......@@ -978,6 +978,19 @@ function xmldb_core_upgrade($oldversion=0) {
insert_record('cron', $cron);
}
if ($oldversion < 2008061700) {
// Group type refactor part one: changes to the group table
// TODO: write this xmldb style, with upgrade path!
// ALTER TABLE "group" DROP owner;
// ALTER TABLE "group" ADD grouptype CHARACTER VARYING(20) NOT NULL;
// ALTER TABLE "group_member" DROP tutor;
//
// unperformed yet:
// ALTER TABLE "group_member" ADD roleinstance FK group_role_instance(id);
// ?? ALTER TABLE "group_member" RENAME member TO usr;
}
return $status;
}
......
......@@ -113,9 +113,10 @@ function get_owned_groups($userid=0, $jointype=null) {
$userid = optional_userid($userid);
// TODO: select groups where role in group is admin
$sql = 'SELECT g.* FROM {group} g
WHERE g.owner = ? AND g.deleted = ?';
$values = array($userid, 0);
WHERE g.deleted = ? LIMIT 1';
$values = array(0);
if (!empty($jointype)) {
$sql .= ' AND jointype = ?';
......@@ -419,4 +420,46 @@ function group_invite_submit(Pieform $form, $values) {
}
}
/**
* Where is the syntax error?
*/
abstract class GroupType {
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 a list of available grouptypes
*/
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);
}
}
}
}
return $grouptypes;
}
?>
<?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 core
* @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();
class GroupTypeCourse extends GroupType {
public static function allowed_join_types() {
return array('controlled');
}
public static function can_be_created_by_user() {
global $USER;
return $USER->get('admin') || $USER->get('staff') || $USER->is_institutional_admin()
|| $USER->is_institutional_staff();
}
}
?>
<?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 core
* @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();
class GroupTypeStandard extends GroupType {
public static function allowed_join_types() {
return array('open', 'request', 'invite');
}
}
?>
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