Fixing get_threads function

skala
Julio Montoya 13 years ago
parent b1f7da9cf1
commit 0efda85f7d
  1. 76
      main/forum/forumfunction.inc.php
  2. 18
      main/forum/viewforum.php
  3. 13
      main/forum/viewthread.php
  4. 6
      main/forum/viewthread_flat.inc.php
  5. 7
      main/webservices/cm_webservice_forum.php

@ -1354,6 +1354,32 @@ function get_forums($id='', $course_code = '') {
return $forum_list; return $forum_list;
} }
function get_last_post_by_thread($course_id, $thread_id, $forum_id, $show_visible = true) {
if (empty($thread_id) || empty($forum_id) || empty($course_id)) {
return false;
}
$thread_id = intval($thread_id);
$forum_id = intval($forum_id);
$course_id = intval($course_id);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$sql = "SELECT * FROM $table_posts
WHERE c_id = $course_id AND thread_id = $thread_id AND forum_id = $forum_id";
if ($show_visible == false) {
$sql .= " AND visible = 1 ";
}
$sql .= " ORDER BY post_id DESC LIMIT 1";
$result = Database::query($sql);
if (Database::num_rows($result)) {
return Database::fetch_array($result,'ASSOC');
} else {
return false;
}
}
/** /**
* This function gets all the last post information of a certain forum * This function gets all the last post information of a certain forum
* *
@ -1372,8 +1398,6 @@ function get_last_post_information($forum_id, $show_invisibles = false, $course_
$course_id = intval($course_id); $course_id = intval($course_id);
} }
$table_forums = Database :: get_course_table(TABLE_FORUM);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST); $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$table_users = Database :: get_main_table(TABLE_MAIN_USER); $table_users = Database :: get_main_table(TABLE_MAIN_USER);
@ -1437,7 +1461,6 @@ function get_threads($forum_id, $course_code = null) {
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD); $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST);
$table_users = Database :: get_main_table(TABLE_MAIN_USER); $table_users = Database :: get_main_table(TABLE_MAIN_USER);
$thread_list = array(); $thread_list = array();
@ -1446,47 +1469,46 @@ function get_threads($forum_id, $course_code = null) {
// since we are merging these we would have the post.locked value but in fact we want the thread.locked value // since we are merging these we would have the post.locked value but in fact we want the thread.locked value
// This is why it is added to the end of the field selection // This is why it is added to the end of the field selection
$sql = "SELECT thread.*, item_properties.*, post.*, users.firstname, users.lastname, users.user_id, $sql = "SELECT thread.*,
last_poster_users.firstname as last_poster_firstname , last_poster_users.lastname as last_poster_lastname, last_poster_users.user_id as last_poster_user_id, thread.locked as locked item_properties.*,
users.firstname,
users.lastname,
users.user_id,
thread.locked as locked
FROM $table_threads thread FROM $table_threads thread
INNER JOIN $table_item_property item_properties INNER JOIN $table_item_property item_properties
ON thread.thread_id=item_properties.ref ON thread.thread_id=item_properties.ref AND
AND item_properties.visibility='1' item_properties.c_id = $course_id AND
AND item_properties.tool='".TABLE_FORUM_THREAD."' thread.c_id = $course_id AND
item_properties.tool='".TABLE_FORUM_THREAD."'
LEFT JOIN $table_users users LEFT JOIN $table_users users
ON thread.thread_poster_id=users.user_id ON thread.thread_poster_id=users.user_id
LEFT JOIN $table_posts post
ON thread.thread_last_post = post.post_id
LEFT JOIN $table_users last_poster_users
ON post.poster_id= last_poster_users.user_id
WHERE WHERE
post.c_id = $course_id AND item_properties.visibility='1' AND
item_properties.c_id = $course_id AND
thread.c_id = $course_id AND
thread.forum_id='".Database::escape_string($forum_id)."' thread.forum_id='".Database::escape_string($forum_id)."'
ORDER BY thread.thread_sticky DESC, thread.thread_date DESC"; ORDER BY thread.thread_sticky DESC, thread.thread_date DESC";
if (is_allowed_to_edit()) { if (is_allowed_to_edit()) {
// important note: it might seem a little bit awkward that we have 'thread.locked as locked' in the sql statement // important note: it might seem a little bit awkward that we have 'thread.locked as locked' in the sql statement
// because we also have thread.* in it. This is because thread has a field locked and post also has the same field // because we also have thread.* in it. This is because thread has a field locked and post also has the same field
// since we are merging these we would have the post.locked value but in fact we want the thread.locked value // since we are merging these we would have the post.locked value but in fact we want the thread.locked value
// This is why it is added to the end of the field selection // This is why it is added to the end of the field selection
$sql = "SELECT thread.*, item_properties.*, post.*, users.firstname, users.lastname, users.user_id, $sql = "SELECT thread.*,
last_poster_users.firstname as last_poster_firstname , last_poster_users.lastname as last_poster_lastname, last_poster_users.user_id as last_poster_user_id, thread.locked as locked item_properties.*,
users.firstname,
users.lastname,
users.user_id,
thread.locked as locked
FROM $table_threads thread FROM $table_threads thread
INNER JOIN $table_item_property item_properties INNER JOIN $table_item_property item_properties
ON thread.thread_id=item_properties.ref ON thread.thread_id=item_properties.ref AND
AND item_properties.visibility<>2 item_properties.c_id = $course_id AND
AND item_properties.tool='".TABLE_FORUM_THREAD."' thread.c_id = $course_id AND
item_properties.tool='".TABLE_FORUM_THREAD."'
LEFT JOIN $table_users users LEFT JOIN $table_users users
ON thread.thread_poster_id=users.user_id ON thread.thread_poster_id=users.user_id
LEFT JOIN $table_posts post
ON thread.thread_last_post = post.post_id
LEFT JOIN $table_users last_poster_users
ON post.poster_id= last_poster_users.user_id
WHERE WHERE
post.c_id = $course_id AND item_properties.visibility<>2 AND
item_properties.c_id = $course_id AND
thread.c_id = $course_id AND
thread.forum_id='".Database::escape_string($forum_id)."' thread.forum_id='".Database::escape_string($forum_id)."'
ORDER BY thread.thread_sticky DESC, thread.thread_date DESC"; ORDER BY thread.thread_sticky DESC, thread.thread_date DESC";
} }

@ -327,9 +327,7 @@ echo '<td>'.get_lang('Actions').'</td>';
echo '</tr>'; echo '</tr>';
// Getting al the threads // Getting al the threads
$threads = get_threads($my_forum); // Note: This has to be cleaned first. $threads = get_threads($my_forum); // Note: This has to be cleaned first
$whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null; $whatsnew_post_info = isset($_SESSION['whatsnew_post_info']) ? $_SESSION['whatsnew_post_info'] : null;
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
@ -364,12 +362,22 @@ if (is_array($threads)) {
// display the author name // display the author name
$tab_poster_info = api_get_user_info($row['user_id']); $tab_poster_info = api_get_user_info($row['user_id']);
$poster_username = sprintf(get_lang('LoginX'), $tab_poster_info['username']); $poster_username = sprintf(get_lang('LoginX'), $tab_poster_info['username']);
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
echo '<td>'.display_user_link($row['user_id'], api_get_person_name($row['firstname'], $row['lastname']), '', $poster_username).'</td>'; echo '<td>'.display_user_link($row['user_id'], api_get_person_name($row['firstname'], $row['lastname']), '', $poster_username).'</td>';
} else { } else {
echo '<td>'.Display::tag('span', api_get_person_name($row['firstname'], $row['lastname']), array("title"=>api_htmlentities($poster_username, ENT_QUOTES))).'</td>'; echo '<td>'.Display::tag('span', api_get_person_name($row['firstname'], $row['lastname']), array("title"=>api_htmlentities($poster_username, ENT_QUOTES))).'</td>';
} }
$last_post_info = get_last_post_by_thread($row['c_id'], $row['thread_id'], $row['forum_id'], is_allowed_to_edit());
$last_post = null;
if ($last_post_info) {
$poster_info = api_get_user_info($last_post_info['poster_id']);
$post_date = api_convert_and_format_date($last_post_info['post_date']);
$last_post = $post_date.' '.get_lang('By').' '.display_user_link($last_post_info['poster_id'], $poster_info['complete_name'], '', $poster_info['user_name']);
}
/*
if ($row['last_poster_user_id'] == '0') { if ($row['last_poster_user_id'] == '0') {
$name = $row['poster_name']; $name = $row['poster_name'];
$last_poster_username = ""; $last_poster_username = "";
@ -380,7 +388,7 @@ if (is_array($threads)) {
} }
// If the last post is invisible and it is not the teacher who is looking then we have to find the last visible post of the thread. // If the last post is invisible and it is not the teacher who is looking then we have to find the last visible post of the thread.
if (($row['visible'] == '1' OR api_is_allowed_to_edit(false, true)) && $origin != 'learnpath') { if (($row['visible'] == '1' OR api_is_allowed_to_edit(false, true)) && $origin != 'learnpath') {
$last_post = api_convert_and_format_date($row['thread_date']).' '.get_lang('By').' '.display_user_link($row['last_poster_user_id'], $name, '', $last_poster_username); $last_post = $post_date.' '.get_lang('By').' '.display_user_link($row['last_poster_user_id'], $name, '', $last_poster_username);
} elseif ($origin != 'learnpath') { } elseif ($origin != 'learnpath') {
$last_post_sql = "SELECT post.*, user.firstname, user.lastname, user.username FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' AND post.c_id=".api_get_course_int_id()." ORDER BY post_id DESC"; $last_post_sql = "SELECT post.*, user.firstname, user.lastname, user.username FROM $table_posts post, $table_users user WHERE post.poster_id=user.user_id AND visible='1' AND thread_id='".$row['thread_id']."' AND post.c_id=".api_get_course_int_id()." ORDER BY post_id DESC";
$last_post_result = Database::query($last_post_sql); $last_post_result = Database::query($last_post_sql);
@ -395,7 +403,7 @@ if (is_array($threads)) {
$last_post_info_username = sprintf(get_lang('LoginX'), $last_post_row['username']); $last_post_info_username = sprintf(get_lang('LoginX'), $last_post_row['username']);
$name = api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']); $name = api_get_person_name($last_post_row['firstname'], $last_post_row['lastname']);
$last_post = api_convert_and_format_date($last_post_row['post_date']).' '.get_lang('By').' '.Display::tag('span', $name, array("title"=>api_htmlentities($last_post_info_username, ENT_QUOTES))); $last_post = api_convert_and_format_date($last_post_row['post_date']).' '.get_lang('By').' '.Display::tag('span', $name, array("title"=>api_htmlentities($last_post_info_username, ENT_QUOTES)));
} }*/
echo '<td>'.$last_post.'</td>'; echo '<td>'.$last_post.'</td>';
echo '<td class="td_actions">'; echo '<td class="td_actions">';

@ -38,6 +38,7 @@ if (isset($_GET['origin'])) {
// Note pcool: I tried to use only one sql statement (and function) for this, // Note pcool: I tried to use only one sql statement (and function) for this,
// but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table. // but the problem is that the visibility of the forum AND forum cateogory are stored in the item_property table.
$current_thread = get_thread_information($_GET['thread']); // Nnote: This has to be validated that it is an existing thread $current_thread = get_thread_information($_GET['thread']); // Nnote: This has to be validated that it is an existing thread
$current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum. $current_forum = get_forum_information($current_thread['forum_id']); // Note: This has to be validated that it is an existing forum.
$current_forum_category = get_forumcategory_information($current_forum['forum_category']); $current_forum_category = get_forumcategory_information($current_forum['forum_category']);
@ -66,8 +67,6 @@ if ($origin == 'group') {
$interbreadcrumb[] = array('url'=>'viewthread.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']), 'name' => Security::remove_XSS($current_thread['thread_title'])); $interbreadcrumb[] = array('url'=>'viewthread.php?forum='.Security::remove_XSS($_GET['forum']).'&amp;gradebook='.$gradebook.'&amp;thread='.Security::remove_XSS($_GET['thread']), 'name' => Security::remove_XSS($current_thread['thread_title']));
Display :: display_header(''); Display :: display_header('');
//api_display_tool_title($nameTools);
} else { } else {
$my_search = isset($_GET['search']) ? $_GET['search'] : ''; $my_search = isset($_GET['search']) ? $_GET['search'] : '';
if ($origin == 'learnpath') { if ($origin == 'learnpath') {
@ -81,7 +80,6 @@ if ($origin == 'group') {
$message = isset($message) ? $message : ''; $message = isset($message) ? $message : '';
// the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string // the last element of the breadcrumb navigation is already set in interbreadcrumb, so give empty string
Display :: display_header(''); Display :: display_header('');
//api_display_tool_title($nameTools);
} }
} }
@ -226,19 +224,18 @@ if ($my_message != 'PostDeletedSpecial') {
break; break;
} }
} }
switch ($viewmode) { switch ($viewmode) {
case 'flat': case 'flat':
include_once('viewthread_flat.inc.php'); include_once 'viewthread_flat.inc.php';
break; break;
case 'threaded': case 'threaded':
include_once('viewthread_threaded.inc.php'); include_once 'viewthread_threaded.inc.php';
break; break;
case 'nested': case 'nested':
include_once('viewthread_nested.inc.php'); include_once 'viewthread_nested.inc.php';
break; break;
default: default:
include_once('viewthread_flat.inc.php'); include_once 'viewthread_flat.inc.php';
break; break;
} }
} // if ($message != 'PostDeletedSpecial') // in this case the first and only post of the thread is removed. } // if ($message != 'PostDeletedSpecial') // in this case the first and only post of the thread is removed.

@ -9,16 +9,15 @@
if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) { if ((isset($_GET['action']) && $_GET['action']=='delete_attach') && isset($_GET['id_attach'])) {
delete_attachment(0,$_GET['id_attach']); delete_attachment(0,$_GET['id_attach']);
} }
if (isset($current_thread['thread_id'])){ if (isset($current_thread['thread_id'])){
$rows=get_posts($current_thread['thread_id']); $rows = get_posts($current_thread['thread_id']);
$increment=0; $increment=0;
$clean_forum_id = intval($_GET['forum']); $clean_forum_id = intval($_GET['forum']);
$clean_thread_id = intval($_GET['thread']); $clean_thread_id = intval($_GET['thread']);
$locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD); $locked = api_resource_is_locked_by_gradebook($clean_thread_id, LINK_FORUM_THREAD);
if (!empty($rows)) {
foreach ($rows as $row) { foreach ($rows as $row) {
echo '<table width="100%" class="forum_table" cellspacing="5" border="0">'; echo '<table width="100%" class="forum_table" cellspacing="5" border="0">';
@ -170,4 +169,5 @@ if (isset($current_thread['thread_id'])){
echo "</table>"; echo "</table>";
$increment++; $increment++;
} }
}
} }

@ -61,11 +61,8 @@ class WSCMForum extends WSCM {
public function get_forum_threads_id($username, $password, $course_code, $forum_id) public function get_forum_threads_id($username, $password, $course_code, $forum_id)
{ {
if($this->verifyUserPass($username, $password) == "valid") if($this->verifyUserPass($username, $password) == "valid") {
{ $threads_info = get_threads($forum_id, $course_code);
$course_db = CourseManager::get_course_information($course_code);
$threads_info = get_threads($forum_id, $course_db['db_name']);
$threads_id = '#'; $threads_id = '#';
foreach ($threads_info as $thread) foreach ($threads_info as $thread)
{ {

Loading…
Cancel
Save