Fix queries in order to fix post visibility

1.10.x
Julio Montoya 11 years ago
parent f81d630c58
commit df97c4e878
  1. 48
      main/forum/forumfunction.inc.php

@ -23,6 +23,7 @@
*/
use ChamiloSession as Session;
use Doctrine\Common\Collections\Criteria;
define('FORUM_NEW_POST', 0);
@ -900,8 +901,9 @@ function delete_post($post_id)
// Get parent_post_id of deleted post.
$tab_post_info = get_post_information($post_id);
if ($tab_post_info) {
$post_parent_id_of_deleted_post = $tab_post_info['post_parent_id'];
$post_parent_id_of_deleted_post = intval($tab_post_info['post_parent_id']);
$thread_id_of_deleted_post = $tab_post_info['thread_id'];
$forum_if_of_deleted_post = $tab_post_info['forum_id'];
$sql = "UPDATE $table_posts
@ -910,7 +912,8 @@ function delete_post($post_id)
c_id = $course_id AND
post_parent_id=$post_id AND
thread_id=$thread_id_of_deleted_post AND
forum_id=$forum_if_of_deleted_post;";
forum_id=$forum_if_of_deleted_post";
Database::query($sql);
// Note: This has to be a recursive function that deletes all of the posts in this block.
@ -931,6 +934,7 @@ function delete_post($post_id)
thread_date='".Database::escape_string($last_post_of_thread['post_date'])."'
WHERE c_id = $course_id AND thread_id = ".intval($_GET['thread'])."";
Database::query($sql);
return 'PostDeleted';
}
if (!$last_post_of_thread) {
@ -938,6 +942,7 @@ function delete_post($post_id)
$sql = "DELETE FROM $table_threads
WHERE c_id = $course_id AND thread_id = ".intval($_GET['thread'])."";
Database::query($sql);
return 'PostDeletedSpecial';
}
}
@ -1906,6 +1911,8 @@ function get_threads($forum_id, $course_code = null)
* @param boolean $recursive Optional. If the list is recursive
* @param int $postId Optional. The post ID for recursive list
* @param int $depth Optional. The depth to indicate the indent
* @todo move to a repository
*
* @return array containing all the information about the posts of a given thread
*/
function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postId = 0, $depth = -1)
@ -1914,20 +1921,29 @@ function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postI
$em = Database::getManager();
$whereCondition = [
'threadId' => $threadId,
'cId' => api_get_course_int_id(),
'visible' => 1
];
if (api_is_allowed_to_edit(false, true)) {
$visibleCriteria = Criteria::expr()->neq('visible', 2);
} else {
$visibleCriteria = Criteria::expr()->eq('visible', 1);
}
$criteria = Criteria::create();
$criteria
->where(Criteria::expr()->eq('threadId', $threadId))
->andWhere(Criteria::expr()->eq('cId', api_get_course_int_id()))
->andWhere($visibleCriteria)
;
if ($recursive) {
$whereCondition['postParentId'] = $postId;
$criteria->andWhere(Criteria::expr()->eq('postParentId', $postId));
}
$posts = $em->getRepository('ChamiloCourseBundle:CForumPost')->findBy(
$whereCondition,
['postId' => $orderDirection]
);
$qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p');
$qb->select('p')
->addCriteria($criteria)
->addOrderBy('p.postId', $orderDirection);
$posts = $qb->getQuery()->getResult();
$depth++;
@ -1961,7 +1977,13 @@ function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postI
$list = array_merge(
$list,
getPosts($threadId, $orderDirection, $recursive, $post->getPostId(), $depth)
getPosts(
$threadId,
$orderDirection,
$recursive,
$post->getPostId(),
$depth
)
);
}

Loading…
Cancel
Save