|
|
|
@ -1640,12 +1640,13 @@ class SocialManager extends UserManager |
|
|
|
|
"; |
|
|
|
|
|
|
|
|
|
if ($getCount) { |
|
|
|
|
$select = ' SELECT count(id) as count_items '; |
|
|
|
|
$select = ' SELECT count(id) count '; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sqlBase = "$select FROM $tblMessage m WHERE "; |
|
|
|
|
$sql = []; |
|
|
|
|
$sql[1] = $sqlBase."msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
|
|
|
|
$sql = "$select |
|
|
|
|
FROM $tblMessage m |
|
|
|
|
WHERE |
|
|
|
|
msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
|
|
|
|
|
|
|
|
|
// Get my own posts |
|
|
|
|
$userReceiverCondition = ' ( |
|
|
|
@ -1654,25 +1655,22 @@ class SocialManager extends UserManager |
|
|
|
|
parent_id = '.$parentId.' |
|
|
|
|
)'; |
|
|
|
|
|
|
|
|
|
$sql[1] .= $userReceiverCondition; |
|
|
|
|
$sql .= $userReceiverCondition; |
|
|
|
|
|
|
|
|
|
$sql[2] = $sqlBase.' msg_status = '.MESSAGE_STATUS_PROMOTED.' '; |
|
|
|
|
$sql .= ' OR ( msg_status = '.MESSAGE_STATUS_PROMOTED.' ) '; |
|
|
|
|
|
|
|
|
|
// Get my group posts |
|
|
|
|
$groupCondition = ''; |
|
|
|
|
if (!empty($groupId)) { |
|
|
|
|
if (is_array($groupId)) { |
|
|
|
|
$groupId = array_map('intval', $groupId); |
|
|
|
|
$groupId = implode(",", $groupId); |
|
|
|
|
$groupCondition = " ( group_id IN ($groupId) "; |
|
|
|
|
$groupId = implode("','", $groupId); |
|
|
|
|
$groupCondition = " OR ( group_id IN ('$groupId') "; |
|
|
|
|
} else { |
|
|
|
|
$groupId = (int) $groupId; |
|
|
|
|
$groupCondition = " ( group_id = $groupId "; |
|
|
|
|
} |
|
|
|
|
$groupCondition .= ' AND (msg_status = '.MESSAGE_STATUS_NEW.' OR msg_status = '.MESSAGE_STATUS_UNREAD.')) '; |
|
|
|
|
$groupCondition = " OR ( group_id = '$groupId' "; |
|
|
|
|
} |
|
|
|
|
if (!empty($groupCondition)) { |
|
|
|
|
$sql[3] = $sqlBase.$groupCondition; |
|
|
|
|
$groupCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_NEW.', '.MESSAGE_STATUS_UNREAD.')) '; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get my friend posts |
|
|
|
@ -1680,16 +1678,17 @@ class SocialManager extends UserManager |
|
|
|
|
if (!empty($friendId)) { |
|
|
|
|
if (is_array($friendId)) { |
|
|
|
|
$friendId = array_map('intval', $friendId); |
|
|
|
|
$friendId = implode(",", $friendId); |
|
|
|
|
$friendCondition = " ( user_receiver_id IN ($friendId) "; |
|
|
|
|
$friendId = implode("','", $friendId); |
|
|
|
|
$friendCondition = " OR ( user_receiver_id IN ('$friendId') "; |
|
|
|
|
} else { |
|
|
|
|
$friendId = (int) $friendId; |
|
|
|
|
$friendCondition = " ( user_receiver_id = $friendId "; |
|
|
|
|
$friendCondition = " OR ( user_receiver_id = '$friendId' "; |
|
|
|
|
} |
|
|
|
|
$friendCondition .= ' AND msg_status = '.MESSAGE_STATUS_WALL_POST.' AND parent_id = 0) '; |
|
|
|
|
} |
|
|
|
|
if (!empty($friendCondition)) { |
|
|
|
|
$sql[4] = $sqlBase.$friendCondition; |
|
|
|
|
|
|
|
|
|
if (!empty($groupCondition) || !empty($friendCondition)) { |
|
|
|
|
$sql .= " $groupCondition $friendCondition "; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($threadList)) { |
|
|
|
@ -1714,31 +1713,27 @@ class SocialManager extends UserManager |
|
|
|
|
$threadList = array_map('intval', $threadList); |
|
|
|
|
$threadList = implode("','", $threadList); |
|
|
|
|
$condition = " thread_id IN ('$threadList') "; |
|
|
|
|
$sql[5] = "$select |
|
|
|
|
$sql .= " |
|
|
|
|
UNION ( |
|
|
|
|
$select |
|
|
|
|
FROM c_forum_post |
|
|
|
|
WHERE $condition |
|
|
|
|
) |
|
|
|
|
"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($getCount) { |
|
|
|
|
$count = 0; |
|
|
|
|
foreach ($sql as $oneQuery) { |
|
|
|
|
if (!empty($oneQuery)) { |
|
|
|
|
$res = Database::query($oneQuery); |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$row = Database::fetch_array($res); |
|
|
|
|
$count += (int) $row['count_items']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $count; |
|
|
|
|
return (int) $row['count']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sqlOrder = ' ORDER BY send_date DESC '; |
|
|
|
|
$sqlLimit = " LIMIT $start, $length "; |
|
|
|
|
$sql .= ' ORDER BY send_date DESC '; |
|
|
|
|
$sql .= " LIMIT $start, $length "; |
|
|
|
|
|
|
|
|
|
$messages = []; |
|
|
|
|
foreach ($sql as $oneQuery) { |
|
|
|
|
$oneQuery .= $sqlOrder.$sqlLimit; |
|
|
|
|
$res = Database::query($oneQuery); |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
if (Database::num_rows($res) > 0) { |
|
|
|
|
$repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); |
|
|
|
@ -1781,14 +1776,9 @@ class SocialManager extends UserManager |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$messages[$row['id']] = $row; |
|
|
|
|
} |
|
|
|
|
$messages[] = $row; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Reordering messages by ID (reverse order) is enough to have the |
|
|
|
|
// latest first, as there is currently no option to edit messages |
|
|
|
|
// afterwards |
|
|
|
|
krsort($messages); |
|
|
|
|
|
|
|
|
|
return $messages; |
|
|
|
|
} |
|
|
|
|