Should fix bug when hiding announcements in a session see #4463

skala
Julio Montoya 13 years ago
parent ae35d7f8ae
commit 477ad96203
  1. 3
      main/announcements/announcements.inc.php
  2. 30
      main/announcements/announcements.php
  3. 13
      main/inc/lib/main_api.lib.php

@ -88,7 +88,8 @@ class AnnouncementManager {
* @return bool False on failure, True on success * @return bool False on failure, True on success
*/ */
public static function change_visibility_announcement($_course, $id) { public static function change_visibility_announcement($_course, $id) {
$item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $id); $session_id = api_get_session_id();
$item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $id, $session_id);
if ($item_visibility == '1') { if ($item_visibility == '1') {
api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'invisible', api_get_user_id()); api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'invisible', api_get_user_id());
} else { } else {

@ -198,6 +198,7 @@ if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_ed
} }
if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])) { if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])) {
if ($ctok == $_GET['sec_token']) { if ($ctok == $_GET['sec_token']) {
AnnouncementManager::change_visibility_announcement($_course, $_GET['id']); AnnouncementManager::change_visibility_announcement($_course, $_GET['id']);
$message = get_lang('VisibilityChanged'); $message = get_lang('VisibilityChanged');
} }
@ -539,27 +540,26 @@ if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
//condition for the session //condition for the session
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id,true,true); $condition_session = api_get_session_condition($session_id, true, true);
if(api_is_allowed_to_edit(false,true)) { if (api_is_allowed_to_edit(false,true)) {
// check teacher status // check teacher status
if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') { if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
if (api_get_group_id() == 0) { if (api_get_group_id() == 0) {
$group_condition = ""; $group_condition = "";
} else { } else {
$group_condition = "AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0)"; $group_condition = " AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0)";
} }
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE WHERE announcement.c_id = $course_id AND
announcement.c_id = $course_id AND ip.c_id = $course_id AND
ip.c_id = $course_id AND announcement.id = ip.ref AND
announcement.id = ip.ref AND ip.tool = 'announcement' AND
ip.tool='announcement' AND ip.visibility <> '2'
ip.visibility<>'2' $group_condition
$group_condition $condition_session
$condition_session
GROUP BY ip.ref GROUP BY ip.ref
ORDER BY display_order DESC ORDER BY display_order DESC
LIMIT 0,$maximum"; LIMIT 0,$maximum";
@ -916,7 +916,7 @@ if ($display_announcement_list) {
// => see only the messages of this specific user + the messages of the group (s)he is member of. // => see only the messages of this specific user + the messages of the group (s)he is member of.
if (!empty($_SESSION['user'])) { if (!empty($_SESSION['user'])) {
if (is_array($group_memberships) && count($group_memberships)>0) { if (is_array($group_memberships) && count($group_memberships) > 0 ) {
$sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
FROM $tbl_announcement announcement, $tbl_item_property ip FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE announcement.c_id = $course_id AND WHERE announcement.c_id = $course_id AND
@ -976,7 +976,7 @@ if ($display_announcement_list) {
} else { } else {
// A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view) // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
// => see all the messages of all the users and groups with editing possibilities // => see all the messages of all the users and groups with editing possibilities
$sql="SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
FROM $tbl_announcement announcement, $tbl_item_property ip FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE announcement.c_id = $course_id AND WHERE announcement.c_id = $course_id AND
ip.c_id = $course_id AND ip.c_id = $course_id AND
@ -1113,6 +1113,9 @@ if ($display_announcement_list) {
/* DATE */ /* DATE */
$last_post_datetime = $myrow['end_date']; $last_post_datetime = $myrow['end_date'];
$item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $myrow['id'], $session_id);
$myrow['visibility'] = $item_visibility;
// the styles // the styles
if ($myrow['visibility'] == '0') { if ($myrow['visibility'] == '0') {
$style='invisible'; $style='invisible';
@ -1126,7 +1129,6 @@ if ($display_announcement_list) {
$attachment_list = array(); $attachment_list = array();
$attachment_list = AnnouncementManager::get_attachment($myrow['id']); $attachment_list = AnnouncementManager::get_attachment($myrow['id']);
$attachment = '';
$attachment_icon = ''; $attachment_icon = '';
if (count($attachment_list)>0) { if (count($attachment_list)>0) {
$attachment_icon = ' '.Display::return_icon('attachment.gif',get_lang('Attachment')); $attachment_icon = ' '.Display::return_icon('attachment.gif',get_lang('Attachment'));

@ -1817,16 +1817,20 @@ function api_get_session_image($session_id, $status_id) {
* @param bool optional, true to accept content with session=0 as well, false for strict session condition * @param bool optional, true to accept content with session=0 as well, false for strict session condition
* @return string condition of the session * @return string condition of the session
*/ */
function api_get_session_condition($session_id, $and = true, $with_base_content = false) { function api_get_session_condition($session_id, $and = true, $with_base_content = false, $session_field = "session_id") {
$session_id = intval($session_id); $session_id = intval($session_id);
if (empty($session_field)) {
$session_field = "session_id";
}
//condition to show resources by session //condition to show resources by session
$condition_session = ''; $condition_session = '';
$condition_add = $and ? " AND " : " WHERE "; $condition_add = $and ? " AND " : " WHERE ";
if ($with_base_content) { if ($with_base_content) {
$condition_session = $condition_add." (session_id = $session_id OR session_id = 0) "; $condition_session = $condition_add." ( $session_field = $session_id OR $session_field = 0) ";
} else { } else {
$condition_session = $condition_add." session_id = $session_id "; $condition_session = $condition_add." $session_field = $session_id ";
} }
return $condition_session; return $condition_session;
} }
@ -2755,9 +2759,10 @@ function api_item_property_update($_course, $tool, $item_id, $lastedit_type, $us
if (!empty($session_id)) { if (!empty($session_id)) {
$session_id = intval($session_id); $session_id = intval($session_id);
} else { } else {
$session_id = api_get_session_id(); $session_id = api_get_session_id();
} }
// Definition of tables. // Definition of tables.
$TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY); $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);

Loading…
Cancel
Save