From e08252ca8b81b6464d05c556ac0c65f58eae6524 Mon Sep 17 00:00:00 2001 From: Patrick Cool Date: Thu, 10 Apr 2008 10:10:19 +0200 Subject: [PATCH] [svn r14826] display group fora in group space allow automatic creation of groups --- main/forum/forumfunction.inc.php | 121 ++++++++++++++++++-- main/group/group_category.php | 16 +-- main/group/group_space.php | 29 +++-- main/inc/lib/add_course.lib.inc.php | 1 + main/inc/lib/groupmanager.lib.php | 44 ++++++- main/install/migrate-db-1.8.4-1.8.5-pre.sql | 2 +- 6 files changed, 185 insertions(+), 28 deletions(-) diff --git a/main/forum/forumfunction.inc.php b/main/forum/forumfunction.inc.php index 6914c8be2b..caa86683a6 100644 --- a/main/forum/forumfunction.inc.php +++ b/main/forum/forumfunction.inc.php @@ -439,9 +439,10 @@ function store_forumcategory($values) */ function store_forum($values) { - global $table_forums; global $_course; global $_user; + + $table_forums = Database::get_course_table(TABLE_FORUM); // find the max forum_order for the given category. The new forum is added at the end => max cat_order + & $sql="SELECT MAX(forum_order) as sort_max FROM ".$table_forums." WHERE forum_category=".Database::escape_string($values['forum_category']); @@ -494,7 +495,7 @@ function store_forum($values) api_item_property_update($_course, TOOL_FORUM, $last_id,"ForumCategoryAdded", api_get_user_id()); $return_message=get_lang('ForumAdded'); } - Display :: display_confirmation_message($return_message); + return $return_message; } /** @@ -521,18 +522,16 @@ function delete_forum_forumcategory_thread($content, $id) $tool_constant=TOOL_FORUM_CATEGORY; $return_message=get_lang('ForumCategoryDeleted'); } - if ($content=='forum') { $tool_constant=TOOL_FORUM; $return_message=get_lang('ForumDeleted'); } - if ($content=='thread') { $tool_constant=TOOL_FORUM_THREAD; $return_message=get_lang('ThreadDeleted'); - } + } api_item_property_update($_course,$tool_constant,$id,'delete',api_get_user_id()); // note: check if this returns a true and if so => return $return_message, if not => return false; //delete_attachment($post_id); return $return_message; @@ -569,9 +568,8 @@ function delete_post($post_id) $sql="UPDATE $table_threads SET thread_replies=thread_replies-1, thread_last_post='".Database::escape_string($last_post_of_thread['post_id'])."', thread_date='".Database::escape_string($last_post_of_thread['post_date'])."' - WHERE thread_id='".Database::escape_string($_GET['thread'])."'"; + WHERE thread_id='".Database::escape_string($_GET['thread'])."'"; api_sql_query($sql,__FILE__,__LINE__); - return 'PostDeleted'; } if ($last_post_of_thread==false) @@ -988,8 +986,8 @@ function class_visible_invisible($current_visibility_status) */ function get_forum_categories($id='') { - global $table_categories; - global $table_item_property; + $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY); + $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); if ($id=='') { @@ -2956,7 +2954,7 @@ function search_link() $url = $url.implode('&',$url_parameter); $return .= ''.Display::return_icon('delete.gif', get_lang('RemoveSearchResults')).''; } - return $return; + return $return; } /** @@ -3007,4 +3005,107 @@ function delete_attachment($id) @ unlink($file); } } +/** + * This function gets all the forum information of the all the forum of the group + * + * @param integer $group_id the id of the group we need the fora of (see forum.forum_of_group) + * @return array + * + * @todo this is basically the same code as the get_forums function. Consider merging the two. + */ +function get_forums_of_group($group_id) +{ + global $table_forums; + global $table_threads; + global $table_posts; + global $table_item_property; + global $table_users; + + //-------------- Student -----------------// + // select all the forum information of all forums (that are visible to students) + $sql="SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties + WHERE forum.forum_of_group = '".Database::escape_string($group_id)."' + AND forum.forum_id=item_properties.ref + AND item_properties.visibility=1 + AND item_properties.tool='".TOOL_FORUM."' + ORDER BY forum.forum_order ASC"; + // select the number of threads of the forums (only the threads that are visible) + $sql2="SELECT count(thread_id) AS number_of_threads, threads.forum_id FROM $table_threads threads, ".$table_item_property." item_properties + WHERE threads.thread_id=item_properties.ref + AND item_properties.visibility=1 + AND item_properties.tool='".TOOL_FORUM_THREAD."' + GROUP BY threads.forum_id"; + // select the number of posts of the forum (post that are visible and that are in a thread that is visible) + $sql3="SELECT count(post_id) AS number_of_posts, posts.forum_id FROM $table_posts posts, $table_threads threads, ".$table_item_property." item_properties + WHERE posts.visible=1 + AND posts.thread_id=threads.thread_id + AND threads.thread_id=item_properties.ref + AND item_properties.visibility=1 + AND item_properties.tool='".TOOL_FORUM_THREAD."' + GROUP BY threads.forum_id"; + + //-------------- Course Admin -----------------// + if (is_allowed_to_edit()) + { + // select all the forum information of all forums (that are not deleted) + $sql="SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties + WHERE forum.forum_of_group = '".Database::escape_string($group_id)."' + AND forum.forum_id=item_properties.ref + AND item_properties.visibility<>2 + AND item_properties.tool='".TOOL_FORUM."' + ORDER BY forum_order ASC"; + //echo $sql.'
'; + // select the number of threads of the forums (only the threads that are not deleted) + $sql2="SELECT count(thread_id) AS number_of_threads, threads.forum_id FROM $table_threads threads, ".$table_item_property." item_properties + WHERE threads.thread_id=item_properties.ref + AND item_properties.visibility<>2 + AND item_properties.tool='".TOOL_FORUM_THREAD."' + GROUP BY threads.forum_id"; + //echo $sql2.'
'; + // select the number of posts of the forum + $sql3="SELECT count(post_id) AS number_of_posts, forum_id FROM $table_posts GROUP BY forum_id"; + //echo $sql3.'
'; + } + + // handling all the forum information + $result=api_sql_query($sql, __FILE__, __LINE__); + while ($row=mysql_fetch_assoc($result)) + { + $forum_list[$row['forum_id']]=$row; + } + + // handling the threadcount information + $result2=api_sql_query($sql2, __FILE__, __LINE__); + while ($row2=mysql_fetch_assoc($result2)) + { + if (array_key_exists($row2['forum_id'],$forum_list)) + { + $forum_list[$row2['forum_id']]['number_of_threads']=$row2['number_of_threads']; + } + } + + // handling the postcount information + $result3=api_sql_query($sql3, __FILE__, __LINE__); + while ($row3=mysql_fetch_assoc($result3)) + { + if (array_key_exists($row3['forum_id'],$forum_list)) // this is needed because sql3 takes also the deleted forums into account + { + $forum_list[$row3['forum_id']]['number_of_posts']=$row3['number_of_posts']; + } + } + + // finding the last post information (last_post_id, last_poster_id, last_post_date, last_poster_name, last_poster_lastname, last_poster_firstname) + foreach ($forum_list as $key=>$value) + { + $last_post_info_of_forum=get_last_post_information($key,is_allowed_to_edit()); + $forum_list[$key]['last_post_id']=$last_post_info_of_forum['last_post_id']; + $forum_list[$key]['last_poster_id']=$last_post_info_of_forum['last_poster_id']; + $forum_list[$key]['last_post_date']=$last_post_info_of_forum['last_post_date']; + $forum_list[$key]['last_poster_name']=$last_post_info_of_forum['last_poster_name']; + $forum_list[$key]['last_poster_lastname']=$last_post_info_of_forum['last_poster_lastname']; + $forum_list[$key]['last_poster_firstname']=$last_post_info_of_forum['last_poster_firstname']; + } + + return $forum_list; +} ?> \ No newline at end of file diff --git a/main/group/group_category.php b/main/group/group_category.php index 3cdda791bb..a5f801b519 100644 --- a/main/group/group_category.php +++ b/main/group/group_category.php @@ -1,5 +1,5 @@ addRule('max_member_group',get_lang('InvalidMaxNumberOfMembers'),'callbac // Self registration $form->addElement('checkbox', 'self_reg_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1); $form->addElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1); -// Forum settings -//$form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); -//$form->addElement('radio', 'forum_state', null, get_lang('Public'), TOOL_PUBLIC); -//$form->addElement('radio', 'forum_state', null, get_lang('Private'), TOOL_PRIVATE); + // Documents settings $form->addElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); $form->addElement('radio', 'doc_state', null, get_lang('Public'), TOOL_PUBLIC); @@ -167,6 +164,11 @@ $form->addElement('radio', 'announcements_state', get_lang('GroupAnnouncements') $form->addElement('radio', 'announcements_state', null, get_lang('Public'), TOOL_PUBLIC); $form->addElement('radio', 'announcements_state', null, get_lang('Private'), TOOL_PRIVATE); +//Forum settings +$form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE); +$form->addElement('radio', 'forum_state', null, get_lang('Public'), TOOL_PUBLIC); +$form->addElement('radio', 'forum_state', null, get_lang('Private'), TOOL_PRIVATE); + // Submit $form->addElement('submit', 'submit', get_lang('Ok')); // If form validates -> save data @@ -186,12 +188,12 @@ if ($form->validate()) switch ($values['action']) { case 'update_settings' : - GroupManager :: update_category($values['id'], $values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']); + GroupManager :: update_category($values['id'], $values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $values['forum_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']); $msg = urlencode(get_lang("GroupPropertiesModified")); header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']); break; case 'add_category' : - GroupManager :: create_category($values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']); + GroupManager :: create_category($values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $values['forum_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']); $msg = urlencode(get_lang("CategoryCreated")); header('Location: group.php?action=show_msg&msg='.$msg); break; diff --git a/main/group/group_space.php b/main/group/group_space.php index b227885466..8148762b9b 100644 --- a/main/group/group_space.php +++ b/main/group/group_space.php @@ -1,4 +1,4 @@ -".Display::return_icon('forum.gif')." ".get_lang("Forums").""; + foreach ($forums_of_groups as $key => $value) + { + if($value['forum_group_public_private'] == 'public' || ($user_subscribe_to_current_group && $value['forum_group_public_private'] == 'private') || $user_is_tutor || api_is_allowed_to_edit()) + { + $tools.= Display::return_icon('forum.gif') . ' '.$value['forum_title'].'
'; + } + } } if( $current_group['doc_state'] != TOOL_NOT_AVAILABLE ) { @@ -190,10 +198,17 @@ if (api_is_allowed_to_edit() OR GroupManager :: is_user_in_group($_SESSION['_use else { $tools = ''; - if ($current_group['forum_state'] == TOOL_PUBLIC && !is_null($current_group['forum_id'])) + $forums_of_groups = get_forums_of_group($current_group['id']); + if (is_array($forums_of_groups)) { - $tools .= "".Display::return_icon('forum.gif')." ".get_lang("Forums")."
"; - } + foreach ($forums_of_groups as $key => $value) + { + if($value['forum_group_public_private'] == 'public' ) + { + $tools.= Display::return_icon('forum.gif') . ' '.$value['forum_title'].'
'; + } + } + } if( $current_group['doc_state'] == TOOL_PUBLIC ) { // link to the documents area of this group diff --git a/main/inc/lib/add_course.lib.inc.php b/main/inc/lib/add_course.lib.inc.php index 5e6ce32b03..01358154bf 100644 --- a/main/inc/lib/add_course.lib.inc.php +++ b/main/inc/lib/add_course.lib.inc.php @@ -789,6 +789,7 @@ function update_Db_course($courseDbName) calendar_state tinyint unsigned NOT NULL default 1, work_state tinyint unsigned NOT NULL default 1, announcements_state tinyint unsigned NOT NULL default 1, + forum_state tinyint unsigned NOT NULL default 0, max_student smallint unsigned NOT NULL default 8, self_reg_allowed tinyint unsigned NOT NULL default 0, self_unreg_allowed tinyint unsigned NOT NULL default 0, diff --git a/main/inc/lib/groupmanager.lib.php b/main/inc/lib/groupmanager.lib.php index f66b952c6c..5b2c9ac7dd 100644 --- a/main/inc/lib/groupmanager.lib.php +++ b/main/inc/lib/groupmanager.lib.php @@ -174,6 +174,42 @@ class GroupManager /* Stores the directory path into the group table */ $sql = "UPDATE ".$table_group." SET name = '".mysql_real_escape_string($name)."', secret_directory = '".$dir_name."' WHERE id ='".$lastId."'"; api_sql_query($sql,__FILE__,__LINE__); + + // create a forum if needed + if ($category['forum_state'] > 0) + { + include_once(api_get_path(SYS_CODE_PATH).'forum/forumconfig.inc.php'); + include_once(api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'); + + $forum_categories = get_forum_categories(); + $values['forum_title'] = get_lang('ForumOfGroup').' '.$name; + $counter = 0; + foreach ($forum_categories as $key=>$value) + { + if ($counter==0) + { + $forum_category_id = $key; + } + $counter++; + } + $values['forum_category'] = $forum_category_id; + $values['allow_anonymous_group']['allow_anonymous'] = 0; + $values['students_can_edit_group']['students_can_edit'] = 0; + $values['approval_direct_group']['approval_direct'] = 0; + $values['allow_attachments_group']['allow_attachments'] = 1; + $values['allow_new_threads_group']['allow_new_threads'] = 1; + $values['default_view_type_group']['default_view_type']=api_get_setting('default_forum_view'); + $values['group_forum'] = $lastId; + if ($category['forum_state'] == '1') + { + $values['public_private_group_forum_group']['public_private_group_forum']='public'; + } + else + { + $values['public_private_group_forum_group']['public_private_group_forum']='private'; + } + store_forum($values); + } return $lastId; } /** @@ -503,7 +539,7 @@ class GroupManager * @param int $max_number_of_students * @param int $groups_per_user */ - function create_category($title, $description, $doc_state, $work_state, $calendar_state, $announcements_state, $self_registration_allowed, $self_unregistration_allowed, $maximum_number_of_students, $groups_per_user) + function create_category($title, $description, $doc_state, $work_state, $calendar_state, $announcements_state, $forum_state, $self_registration_allowed, $self_unregistration_allowed, $maximum_number_of_students, $groups_per_user) { $table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY); $sql = "SELECT MAX(display_order)+1 as new_order FROM $table_group_category "; @@ -520,7 +556,8 @@ class GroupManager doc_state = '".$doc_state."', work_state = '".$work_state."', calendar_state = '".$calendar_state."', - announcements_state = '".$announcements_state."', + announcements_state = '".$announcements_state."', + forum_state = '".Database::escape_string($forum_state)."', groups_per_user = ".$groups_per_user.", self_reg_allowed = '".$self_registration_allowed."', self_unreg_allowed = '".$self_unregistration_allowed."', @@ -546,7 +583,7 @@ class GroupManager * @param int $max_number_of_students * @param int $groups_per_user */ - function update_category($id, $title, $description, $doc_state, $work_state, $calendar_state, $announcements_state, $self_registration_allowed, $self_unregistration_allowed, $maximum_number_of_students, $groups_per_user) + function update_category($id, $title, $description, $doc_state, $work_state, $calendar_state, $announcements_state, $forum_state, $self_registration_allowed, $self_unregistration_allowed, $maximum_number_of_students, $groups_per_user) { $table_group_category = Database :: get_course_table(TABLE_GROUP_CATEGORY); $sql = "UPDATE ".$table_group_category." @@ -556,6 +593,7 @@ class GroupManager work_state = '".$work_state."', calendar_state = '".$calendar_state."', announcements_state = '".$announcements_state."', + forum_state = '".Database::escape_string($forum_state)."', groups_per_user = ".$groups_per_user.", self_reg_allowed = '".$self_registration_allowed."', self_unreg_allowed = '".$self_unregistration_allowed."', diff --git a/main/install/migrate-db-1.8.4-1.8.5-pre.sql b/main/install/migrate-db-1.8.4-1.8.5-pre.sql index 4b8668b90a..a46612d369 100644 --- a/main/install/migrate-db-1.8.4-1.8.5-pre.sql +++ b/main/install/migrate-db-1.8.4-1.8.5-pre.sql @@ -114,4 +114,4 @@ ALTER TABLE document ADD readonly TINYINT UNSIGNED NOT NULL ; ALTER TABLE quiz ADD results_disabled TINYINT UNSIGNED NOT NULL DEFAULT 0; CREATE TABLE blog_attachment ( id int unsigned NOT NULL auto_increment, path varchar(255) NOT NULL COMMENT 'the real filename', comment text, size int NOT NULL default '0', post_id int NOT NULL, filename varchar(255) NOT NULL COMMENT 'the user s file name', blog_id int NOT NULL, comment_id int NOT NULL default '0', PRIMARY KEY (id)); CREATE TABLE forum_attachment (id int NOT NULL auto_increment, path varchar(255) NOT NULL, comment text, size int NOT NULL default 0, post_id int NOT NULL, filename varchar(255) NOT NULL, PRIMARY KEY (id)); - +ALTER TABLE group_category ADD forum_state TINYINT DEFAULT 0 AFTER announcements_state;