Group tool: Adding import/export categories and groups CSV see BT#6985

1.9.x
Julio Montoya 11 years ago
parent dcb0e581ca
commit 8e8ab981d9
  1. 9
      main/group/group.php
  2. 61
      main/group/group_category.php
  3. 80
      main/group/group_overview.php
  4. 59
      main/group/import.php
  5. 320
      main/inc/lib/groupmanager.lib.php

@ -173,8 +173,17 @@ if (api_is_allowed_to_edit(false, true)) {
echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
}
echo '<a href="import.php?'.api_get_cidreq().'&action=import">'.
Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
Display::return_icon('export_csv.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.
Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="../user/user.php?'.api_get_cidreq().'">'.
Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>';
}

@ -22,34 +22,38 @@ if (!api_is_allowed_to_edit(false,true) || !(isset ($_GET['id']) || isset ($_POS
/**
* Function to check the given max number of members per group
*/
function check_max_number_of_members($value) {
$max_member_no_limit = $value['max_member_no_limit'];
if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
return true;
}
$max_member = $value['max_member'];
return is_numeric($max_member);
function check_max_number_of_members($value)
{
$max_member_no_limit = $value['max_member_no_limit'];
if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
return true;
}
$max_member = $value['max_member'];
return is_numeric($max_member);
}
/**
* Function to check the number of groups per user
*/
function check_groups_per_user($value) {
$groups_per_user = $value['groups_per_user'];
if (isset ($_POST['id']) && intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT && GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) {
return false;
}
return true;
function check_groups_per_user($value)
{
$groups_per_user = $value['groups_per_user'];
if (isset($_POST['id']) &&
intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT &&
GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) {
return false;
}
return true;
}
if (api_get_setting('allow_group_categories') == 'true') {
if (isset ($_GET['id'])) {
$category = GroupManager :: get_category($_GET['id']);
$nameTools = get_lang('EditGroupCategory').': '.$category['title'];
} else {
$nameTools = get_lang('AddCategory');
// Default values for new category
$category = array(
if (isset ($_GET['id'])) {
$category = GroupManager::get_category($_GET['id']);
$nameTools = get_lang('EditGroupCategory').': '.$category['title'];
} else {
$nameTools = get_lang('AddCategory');
// Default values for new category
$category = array(
'groups_per_user' => 1,
'doc_state' => GroupManager::TOOL_PRIVATE,
'work_state' => GroupManager::TOOL_PRIVATE,
@ -58,11 +62,12 @@ if (api_get_setting('allow_group_categories') == 'true') {
'calendar_state' => GroupManager::TOOL_PRIVATE,
'announcements_state'=> GroupManager::TOOL_PRIVATE,
'forum_state' => GroupManager::TOOL_PRIVATE,
'max_student' => 0);
}
'max_student' => 0
);
}
} else {
$category = GroupManager :: get_category($_GET['id']);
$nameTools = get_lang('PropModify');
$category = GroupManager::get_category($_GET['id']);
$nameTools = get_lang('PropModify');
}
$htmlHeadXtra[] = '<script>
@ -87,8 +92,8 @@ if (isset ($_GET['id'])) {
} else {
// Checks if the field was created in the table Category. It creates it if is neccesary
$table_category = Database :: get_course_table(TABLE_GROUP_CATEGORY);
if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) {
Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id");
if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) {
Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id");
}
// Create a new category
$action = 'add_category';
@ -115,7 +120,7 @@ $group = array ();
$group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'));
$possible_values = array ();
for ($i = 1; $i <= 10; $i ++) {
$possible_values[$i] = $i;
$possible_values[$i] = $i;
}
$possible_values[GroupManager::GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
$group[] = $form->createElement('select', 'groups_per_user', null, $possible_values);
@ -187,7 +192,7 @@ $form->addElement('style_submit_button', 'submit', get_lang('PropModify'), 'clas
// If form validates -> save data
if ($form->validate()) {
$values = $form->exportValues();
$values = $form->exportValues();
if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
$max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
} else {

@ -35,12 +35,90 @@ include_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
if (isset($_GET['action'])) {
switch ($_GET['action']) {
case 'export':
case 'export_all':
$data = array();
$data[] = array(
'category',
'group',
'description',
'announcements_state',
'calendar_state',
'chat_state',
'doc_state',
'forum_state',
'work_state',
'wiki_state',
'max_student',
'self_reg_allowed',
'self_unreg_allowed',
'groups_per_user'
);
$groupCategories = array();
$categories = GroupManager::get_categories();
foreach ($categories as $categoryInfo) {
$data[] = array(
$categoryInfo['title'],
null,
$categoryInfo['description'],
$categoryInfo['announcements_state'],
$categoryInfo['calendar_state'],
$categoryInfo['chat_state'],
$categoryInfo['doc_state'],
$categoryInfo['forum_state'],
$categoryInfo['work_state'],
$categoryInfo['wiki_state'],
$categoryInfo['max_student'],
$categoryInfo['self_reg_allowed'],
$categoryInfo['self_unreg_allowed'],
$categoryInfo['groups_per_user']
);
}
$groups = GroupManager::get_group_list();
foreach ($groups as $index => $groupInfo) {
$categoryTitle = null;
$categoryInfo = GroupManager::get_category($groupInfo['category_id']);
$groupSettings = GroupManager::get_group_properties($groupInfo['id']);
if (!empty($categoryInfo)) {
$categoryTitle = $categoryInfo['title'];
}
$data[] = array(
$categoryTitle,
$groupSettings['name'],
$groupSettings['description'],
$groupSettings['announcements_state'],
$groupSettings['calendar_state'],
$groupSettings['chat_state'],
$groupSettings['doc_state'],
$groupSettings['forum_state'],
$groupSettings['work_state'],
$groupSettings['wiki_state'],
$groupSettings['maximum_number_of_students'],
$groupSettings['self_registration_allowed'],
$groupSettings['self_unregistration_allowed'],
);
}
Export::export_table_csv($data);
exit;
break;
case 'export':
$groupId = isset($_GET['id']) ? intval($_GET['id']) : null;
$groups = GroupManager::get_group_list();
$data = array();
foreach ($groups as $index => $group) {
if (!empty($groupId)) {
if ($group['id'] != $groupId) {
continue;
}
}
$users = GroupManager::get_users($group['id']);
foreach ($users as $index => $user) {
$row = array();

@ -0,0 +1,59 @@
<?php
// Name of the language file that needs to be included
$language_file = 'group';
require_once '../inc/global.inc.php';
$this_section = SECTION_COURSES;
$current_course_tool = TOOL_GROUP;
// Notice for unauthorized people.
api_protect_course_script(true);
$nameTools = get_lang('Import');
/* Libraries */
include_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
include_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
$interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups'));
Display::display_header($nameTools, 'Group');
$form = new FormValidator('import', api_get_self());
$form->addElement('header', get_lang('ImportGroups'));
$form->addElement('file', 'file', get_lang('File'));
$form->addElement('button', 'submit', get_lang('Import'));
if ($form->validate()) {
$groupData = Import::csv_reader($_FILES['file']['tmp_name']);
$result = GroupManager::importCategoriesAndGroupsFromArray($groupData);
//var_dump($result);
if (!empty($result)) {
$html = null;
foreach ($result as $status => $data) {
$html .= " <h3>".get_lang(ucfirst($status)).' </h3>';
if (!empty($data['category'])) {
$html .= "<h4> ".get_lang('Categories').':</h4>';
foreach ($data['category'] as $category) {
$html .= "<div>".$category['category']."</div>";
}
}
if (!empty($data['group'])) {
$html .= "<h4> ".get_lang('Groups').':</h4>';
foreach ($data['group'] as $group) {
$html .= "<div>".$group['group']."</div>";
}
}
}
echo $html;
}
}
$form->display();
Display::display_footer();

@ -96,7 +96,7 @@ class GroupManager
$my_status_of_user_in_course = CourseManager::get_user_in_course_status($my_user_id, $course_info['code']);
$is_student_in_session = false;
if (is_null($my_status_of_user_in_course) || $my_status_of_user_in_course=='') {//into session
if (is_null($my_status_of_user_in_course) || $my_status_of_user_in_course=='') {
if ($session_id>0) {
$is_student_in_session=true;
}
@ -180,7 +180,7 @@ class GroupManager
* @param int $tutor The user-id of the group's tutor
* @param int $places How many people can subscribe to the new group
*/
public static function create_group ($name, $category_id, $tutor, $places)
public static function create_group($name, $category_id, $tutor, $places)
{
global $_course;
$table_group = Database :: get_course_table(TABLE_GROUP);
@ -190,8 +190,9 @@ class GroupManager
$currentCourseRepository = $_course['path'];
$category = self :: get_category($category_id);
$places = intval($places);
if (intval($places) == 0) {
if ($places == 0) {
//if the amount of users per group is not filled in, use the setting from the category
$places = $category['max_student'];
} else {
@ -260,9 +261,9 @@ class GroupManager
$values['group_forum'] = $lastId;
if ($category['forum_state'] == '1') {
$values['public_private_group_forum_group']['public_private_group_forum']='public';
} elseif ($category['forum_state'] == '2') {
} elseif ($category['forum_state'] == '2') {
$values['public_private_group_forum_group']['public_private_group_forum']='private';
} elseif ($category['forum_state'] == '0') {
} elseif ($category['forum_state'] == '0') {
$values['public_private_group_forum_group']['public_private_group_forum']='unavailable';
}
store_forum($values);
@ -279,15 +280,15 @@ class GroupManager
* @param int $group_id The group from which subgroups have to be created.
* @param int $number_of_groups The number of groups that have to be created
*/
public static function create_subgroups ($group_id, $number_of_groups) {
public static function create_subgroups($group_id, $number_of_groups)
{
$course_id = api_get_course_int_id();
$table_group = Database :: get_course_table(TABLE_GROUP);
$category_id = self :: create_category('Subgroups', '', self::TOOL_PRIVATE, self::TOOL_PRIVATE, 0, 0, 1, 1);
$users = self :: get_users($group_id);
$group_ids = array ();
for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr ++)
{
for ($group_nr = 1; $group_nr <= $number_of_groups; $group_nr ++) {
$group_ids[] = self :: create_group('SUBGROUP '.$group_nr, $category_id, 0, 0);
}
$members = array ();
@ -300,10 +301,13 @@ class GroupManager
Database::query($sql);
}
}
/**
* Create groups from all virtual courses in the given course.
* @deprecated
*/
public static function create_groups_from_virtual_courses() {
public static function create_groups_from_virtual_courses()
{
self :: delete_category(self::VIRTUAL_COURSE_CATEGORY);
$id = self :: create_category(get_lang('GroupsFromVirtualCourses'), '', self::TOOL_NOT_AVAILABLE, self::TOOL_NOT_AVAILABLE, 0, 0, 1, 1);
$table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY);
@ -332,19 +336,18 @@ class GroupManager
}
return $ids;
}
/**
* Create a group for every class subscribed to the current course
* @param int $category_id The category in which the groups should be
* created
* @param int $category_id The category in which the groups should be created
*/
public static function create_class_groups ($category_id) {
global $_course;
public static function create_class_groups ($category_id)
{
$options['where'] = array(" usergroup.course_id = ? " => api_get_real_course_id());
$obj = new UserGroup();
$classes = $obj->get_usergroup_in_course($options);
$group_ids = array();
foreach($classes as $index => $class)
{
foreach ($classes as $class) {
$users_ids = $obj->get_users_by_usergroup($class['id']);
$group_id = self::create_group($class['name'],$category_id,0,count($users_ids));
self::subscribe_users($users_ids,$group_id);
@ -363,7 +366,8 @@ class GroupManager
* @param string $course_code Default is current course
* @return integer - number of groups deleted.
*/
public static function delete_groups($group_ids, $course_code = null) {
public static function delete_groups($group_ids, $course_code = null)
{
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
@ -376,13 +380,13 @@ class GroupManager
if (api_is_course_coach()) {
//a coach can only delete courses from his session
for($i=0 ; $i<count($group_ids) ; $i++) {
if(!api_is_element_in_the_session(TOOL_GROUP,$group_ids[$i])) {
for ($i=0 ; $i<count($group_ids) ; $i++) {
if (!api_is_element_in_the_session(TOOL_GROUP,$group_ids[$i])) {
array_splice($group_ids,$i,1);
$i--;
}
}
if(count($group_ids)==0)
if (count($group_ids)==0)
return 0;
}
@ -390,7 +394,7 @@ class GroupManager
self :: unsubscribe_all_users($group_ids);
$sql = "SELECT id, secret_directory, session_id FROM $group_table WHERE c_id = $course_id AND id IN (".implode(' , ', $group_ids).")";
$db_result = Database::query($sql);
$forum_ids = array ();
$forum_ids = array();
while ($group = Database::fetch_object($db_result)) {
// move group-documents to garbage
@ -431,9 +435,10 @@ class GroupManager
* @param int $group_id The group from which properties are requested.
* @return array All properties. Array-keys are name, tutor_id, description, maximum_number_of_students, directory and visibility of tools
*/
public static function get_group_properties($group_id) {
public static function get_group_properties($group_id)
{
$course_id = api_get_course_int_id();
if (empty($group_id) or !is_integer(intval($group_id)) ) {
if (empty($group_id) or !is_integer(intval($group_id))) {
return null;
}
$result = array();
@ -465,6 +470,34 @@ class GroupManager
return $result;
}
/**
* @param string $name
* @param string $courseCode
* @return array
*/
public static function getGroupByName($name, $courseCode = null)
{
$name = trim($name);
if (empty($name)) {
return array();
}
$course_info = api_get_course_info($courseCode);
$course_id = $course_info['real_id'];
$name = Database::escape_string($name);
$table_group = Database::get_course_table(TABLE_GROUP);
$sql = "SELECT * FROM $table_group
WHERE c_id = $course_id AND name = '$name' LIMIT 1";
$res = Database::query($sql);
$group = array();
if (Database::num_rows($res)) {
$group = Database::fetch_array($res, 'ASSOC');
}
return $group;
}
/**
* Set group properties
* Changes the group's properties.
@ -483,7 +516,21 @@ class GroupManager
* @param bool Whether self unregistration is allowed or not
* @return bool TRUE if properties are successfully changed, false otherwise
*/
public static function set_group_properties ($group_id, $name, $description, $maximum_number_of_students, $doc_state, $work_state, $calendar_state, $announcements_state, $forum_state, $wiki_state, $chat_state, $self_registration_allowed, $self_unregistration_allowed) {
public static function set_group_properties(
$group_id,
$name,
$description,
$maximum_number_of_students,
$doc_state,
$work_state,
$calendar_state,
$announcements_state,
$forum_state,
$wiki_state,
$chat_state,
$self_registration_allowed,
$self_unregistration_allowed
) {
$table_group = Database :: get_course_table(TABLE_GROUP);
$table_forum = Database :: get_course_table(TABLE_FORUM);
//$forum_id = get_forums_of_group($group_id);
@ -492,8 +539,8 @@ class GroupManager
$course_id = api_get_course_int_id();
$sql = "UPDATE ".$table_group."
SET name='".Database::escape_string(trim($name))."',
$sql = "UPDATE ".$table_group." SET
name='".Database::escape_string(trim($name))."',
doc_state = '".Database::escape_string($doc_state)."',
work_state = '".Database::escape_string($work_state)."',
calendar_state = '".Database::escape_string($calendar_state)."',
@ -502,10 +549,10 @@ class GroupManager
wiki_state = '".Database::escape_string($wiki_state)."',
chat_state = '".Database::escape_string($chat_state)."',
description='".Database::escape_string(trim($description))."',
max_student=".Database::escape_string($maximum_number_of_students).",
max_student= '".Database::escape_string($maximum_number_of_students)."',
self_registration_allowed='".Database::escape_string($self_registration_allowed)."',
self_unregistration_allowed='".Database::escape_string($self_unregistration_allowed)."'
WHERE c_id = $course_id AND id=".$group_id;
WHERE c_id = $course_id AND id=".$group_id;
$result = Database::query($sql);
//Here we are updating a field in the table forum_forum that perhaps duplicates the table group_info.forum_state cvargas
$forum_state = (int) $forum_state;
@ -517,15 +564,17 @@ class GroupManager
} elseif ($forum_state===0) {
$sql2 .= " forum_group_public_private='unavailable' ";
}
$sql2 .=" WHERE c_id = $course_id AND forum_of_group=".$group_id;
$result2 = Database::query($sql2);
$sql2 .=" WHERE c_id = $course_id AND forum_of_group=".$group_id;
Database::query($sql2);
return $result;
}
/**
* Get the total number of groups for the current course.
* @return int The number of groups for the current course.
*/
public static function get_number_of_groups() {
public static function get_number_of_groups()
{
$course_id = api_get_course_int_id();
$table_group = Database :: get_course_table(TABLE_GROUP);
$res = Database::query("SELECT COUNT(id) AS number_of_groups FROM $table_group WHERE c_id = $course_id ");
@ -533,13 +582,15 @@ class GroupManager
return $obj->number_of_groups;
}
//GROUPCATEGORY FUNCTIONS
// GROUP CATEGORY FUNCTIONS
/**
* Get all categories
* @param string $course_code The cours (default = current course)
* @return array
*/
public static function get_categories($course_code = null) {
public static function get_categories($course_code = null)
{
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY);
@ -551,12 +602,15 @@ class GroupManager
}
return $cats;
}
/**
* Get a group category
* @param int $id The category id
* @param string $course_code The course (default = current course)
* @param return array
*/
public static function get_category($id, $course_code = null) {
public static function get_category($id, $course_code = null)
{
if (empty($id)) {
return array();
}
@ -568,6 +622,35 @@ class GroupManager
$res = Database::query($sql);
return Database::fetch_array($res);
}
/**
* Get a group category
* @param string $title
* @param string $course_code The course (default = current course)
* @param return array
*/
public static function getCategoryByTitle($title, $course_code = null)
{
$title = trim($title);
if (empty($title)) {
return array();
}
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
$title = Database::escape_string($title);
$table_group_cat = Database::get_course_table(TABLE_GROUP_CATEGORY);
$sql = "SELECT * FROM $table_group_cat
WHERE c_id = $course_id AND title = '$title' LIMIT 1";
$res = Database::query($sql);
$category = array();
if (Database::num_rows($res)) {
$category = Database::fetch_array($res, 'ASSOC');
}
return $category;
}
/**
* Get the unique category of a given group
* @param int $group_id The id of the group
@ -575,7 +658,8 @@ class GroupManager
* current course)
* @return array The category
*/
public static function get_category_from_group ($group_id, $course_code = null) {
public static function get_category_from_group($group_id, $course_code = null)
{
$table_group = Database :: get_course_table(TABLE_GROUP);
$table_group_cat = Database :: get_course_table(TABLE_GROUP_CATEGORY);
@ -598,13 +682,15 @@ class GroupManager
}
return $cat;
}
/**
* Delete a group category
* @param int $cat_id The id of the category to delete
* @param string $course_code The code in which the category should be
* deleted (default = current course)
*/
public static function delete_category ($cat_id, $course_code = null) {
public static function delete_category($cat_id, $course_code = null)
{
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
@ -623,6 +709,7 @@ class GroupManager
$sql = "DELETE FROM $table_group_cat WHERE c_id = $course_id AND id='".$cat_id."'";
Database::query($sql);
}
/**
* Create group category
* @param string $title The title of the new category
@ -632,8 +719,21 @@ class GroupManager
* @param int $max_number_of_students
* @param int $groups_per_user
*/
public static function create_category ($title, $description, $doc_state, $work_state, $calendar_state, $announcements_state, $forum_state, $wiki_state,
$chat_state = 1, $self_registration_allowed = 0, $self_unregistration_allowed = 0, $maximum_number_of_students = 8, $groups_per_user = 0) {
public static function create_category(
$title,
$description,
$doc_state,
$work_state,
$calendar_state,
$announcements_state,
$forum_state,
$wiki_state,
$chat_state = 1,
$self_registration_allowed = 0,
$self_unregistration_allowed = 0,
$maximum_number_of_students = 8,
$groups_per_user = 0
) {
$table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY);
$course_id = api_get_course_int_id();
@ -652,8 +752,8 @@ class GroupManager
doc_state = '".Database::escape_string($doc_state)."',
work_state = '".Database::escape_string($work_state)."',
calendar_state = '".Database::escape_string($calendar_state)."',
announcements_state = '".Database::escape_string($announcements_state)."',
forum_state = '".Database::escape_string($forum_state)."',
announcements_state = '".Database::escape_string($announcements_state)."',
forum_state = '".Database::escape_string($forum_state)."',
wiki_state = '".Database::escape_string($wiki_state)."',
chat_state = '".Database::escape_string($chat_state)."',
groups_per_user = '".Database::escape_string($groups_per_user)."',
@ -661,13 +761,13 @@ class GroupManager
self_unreg_allowed = '".Database::escape_string($self_unregistration_allowed)."',
max_student = '".Database::escape_string($maximum_number_of_students)."' ";
Database::query($sql);
$id = Database::insert_id();
if ($id == self::VIRTUAL_COURSE_CATEGORY) {
$sql = "UPDATE ".$table_group_category." SET id = ". ($id +1)." WHERE c_id = $course_id AND id = $id";
$categoryId = Database::insert_id();
if ($categoryId == self::VIRTUAL_COURSE_CATEGORY) {
$sql = "UPDATE ".$table_group_category." SET id = ". ($categoryId +1)." WHERE c_id = $course_id AND id = $categoryId";
Database::query($sql);
return $id +1;
return $categoryId +1;
}
return $id;
return $categoryId;
}
/**
@ -719,14 +819,13 @@ class GroupManager
forum_state = '".Database::escape_string($forum_state)."',
wiki_state = '".Database::escape_string($wiki_state)."',
chat_state = '".Database::escape_string($chat_state)."',
groups_per_user = ".Database::escape_string($groups_per_user).",
groups_per_user = '".Database::escape_string($groups_per_user)."',
self_reg_allowed = '".Database::escape_string($self_registration_allowed)."',
self_unreg_allowed = '".Database::escape_string($self_unregistration_allowed)."',
max_student = ".Database::escape_string($maximum_number_of_students)."
WHERE c_id = $course_id AND id = $id";
Database::query($sql);
// Updating all groups inside this category
$groups = self::get_group_list($id);
@ -749,13 +848,11 @@ class GroupManager
);
}
}
}
/**
* Returns the number of groups of the user with the greatest number of
* subscribtions in the given category
* subscriptions in the given category
*/
public static function get_current_max_groups_per_user($category_id = null, $course_code = null)
{
@ -941,7 +1038,7 @@ class GroupManager
HAVING (nbPlaces > 0 OR g.max_student = ".self::MEMBER_PER_GROUP_NO_LIMIT.")
ORDER BY nbPlaces DESC";
$sql_result = Database::query($sql);
$group_available_place = array ();
$group_available_place = array();
while ($group = Database::fetch_array($sql_result, 'ASSOC')) {
$group_available_place[$group['gid']] = $group['nbPlaces'];
}
@ -1863,6 +1960,8 @@ class GroupManager
if (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && intval($this_group['session_id']) != $session_id)) {
$edit_actions = '<a href="group_edit.php?'.api_get_cidreq(true, false).'&gidReq='.$this_group['id'].'" title="'.get_lang('Edit').'">'.
Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
$edit_actions .= '<a href="group_overview.php?action=export&type=xls&'.api_get_cidreq(true, false).'&id='.$this_group['id'].'" title="'.get_lang('ExportUsers').'">'.
Display::return_icon('export_excel.png', get_lang('ExportUsers'),'', ICON_SIZE_SMALL).'</a>&nbsp;';
$edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(true, false).'&category='.$category_id.'&amp;action=empty_one&amp;id='.$this_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('EmptyGroup').'">'.
Display::return_icon('clean.png',get_lang('EmptyGroup'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
$edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq(true, false).'&category='.$category_id.'&amp;action=fill_one&amp;id='.$this_group['id'].'" onclick="javascript: if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('FillGroup').'">'.
@ -1903,4 +2002,125 @@ class GroupManager
}
$table->display();
}
/**
*
* @param array $groupData
* @return array
*/
public static function importCategoriesAndGroupsFromArray($groupData)
{
$result = array();
foreach ($groupData as $data) {
$isCategory = empty($data['group']) ? true : false;
if ($isCategory) {
$categoryTitle = $data['category'];
$categoryInfo = self::getCategoryByTitle($categoryTitle);
if (!empty($categoryInfo)) {
// Update
self::update_category(
$categoryInfo['id'],
$data['category'],
$data['description'],
$data['doc_state'],
$data['work_state'],
$data['calendar_state'],
$data['announcements_state'],
$data['forum_state'],
$data['wiki_state'],
$data['chat_state'],
$data['self_reg_allowed'],
$data['self_unreg_allowed'],
$data['max_student'],
$data['groups_per_user']
);
$data['category_id'] = $categoryInfo['id'];
$result['updated']['category'][] = $data;
} else {
// Add
$categoryId = self::create_category(
$data['category'],
$data['description'],
$data['doc_state'],
$data['work_state'],
$data['calendar_state'],
$data['announcements_state'],
$data['forum_state'],
$data['wiki_state'],
$data['chat_state'],
$data['self_reg_allowed'],
$data['self_unreg_allowed'],
$data['max_student'],
$data['groups_per_user']
);
if ($categoryId) {
$data['category_id'] = $categoryId;
$result['added']['category'][] = $data;
}
}
} else {
$groupInfo = self::getGroupByName($data['group']);
if (empty($groupInfo)) {
$categoryInfo = self::getCategoryByTitle($data['category']);
$categoryId = null;
if (!empty($categoryInfo)) {
$categoryId = $categoryInfo['id'];
}
// Add
$groupId = self::create_group(
$data['group'],
$categoryId,
null,
$data['max_students']
);
if ($groupId) {
self::set_group_properties(
$groupId,
$data['group'],
$data['description'],
$data['max_students'],
$data['doc_state'],
$data['work_state'],
$data['calendar_state'],
$data['announcements_state'],
$data['forum_state'],
$data['wiki_state'],
$data['chat_state'],
$data['self_reg_allowed'],
$data['self_unreg_allowed']
);
$data['group_id'] = $groupId;
$result['added']['group'][] = $data;
}
} else {
// Update
self::set_group_properties(
$groupInfo['id'],
$data['group'],
$data['description'],
$data['max_students'],
$data['doc_state'],
$data['work_state'],
$data['calendar_state'],
$data['announcements_state'],
$data['forum_state'],
$data['wiki_state'],
$data['chat_state'],
$data['self_reg_allowed'],
$data['self_unreg_allowed']
);
$data['group_id'] = $groupInfo['id'];
$result['updated']['group'][] = $data;
}
}
}
return $result;
}
}

Loading…
Cancel
Save