|
|
@ -1640,12 +1640,13 @@ class SocialManager extends UserManager |
|
|
|
"; |
|
|
|
"; |
|
|
|
|
|
|
|
|
|
|
|
if ($getCount) { |
|
|
|
if ($getCount) { |
|
|
|
$select = ' SELECT count(id) as count_items '; |
|
|
|
$select = ' SELECT count(id) count '; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$sqlBase = "$select FROM $tblMessage m WHERE "; |
|
|
|
$sql = "$select |
|
|
|
$sql = []; |
|
|
|
FROM $tblMessage m |
|
|
|
$sql[1] = $sqlBase."msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
|
|
|
WHERE |
|
|
|
|
|
|
|
msg_status <> ".MESSAGE_STATUS_WALL_DELETE.' AND '; |
|
|
|
|
|
|
|
|
|
|
|
// Get my own posts |
|
|
|
// Get my own posts |
|
|
|
$userReceiverCondition = ' ( |
|
|
|
$userReceiverCondition = ' ( |
|
|
@ -1654,25 +1655,22 @@ class SocialManager extends UserManager |
|
|
|
parent_id = '.$parentId.' |
|
|
|
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 |
|
|
|
// Get my group posts |
|
|
|
$groupCondition = ''; |
|
|
|
$groupCondition = ''; |
|
|
|
if (!empty($groupId)) { |
|
|
|
if (!empty($groupId)) { |
|
|
|
if (is_array($groupId)) { |
|
|
|
if (is_array($groupId)) { |
|
|
|
$groupId = array_map('intval', $groupId); |
|
|
|
$groupId = array_map('intval', $groupId); |
|
|
|
$groupId = implode(",", $groupId); |
|
|
|
$groupId = implode("','", $groupId); |
|
|
|
$groupCondition = " ( group_id IN ($groupId) "; |
|
|
|
$groupCondition = " OR ( group_id IN ('$groupId') "; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$groupId = (int) $groupId; |
|
|
|
$groupId = (int) $groupId; |
|
|
|
$groupCondition = " ( group_id = $groupId "; |
|
|
|
$groupCondition = " OR ( group_id = '$groupId' "; |
|
|
|
} |
|
|
|
} |
|
|
|
$groupCondition .= ' AND (msg_status = '.MESSAGE_STATUS_NEW.' OR msg_status = '.MESSAGE_STATUS_UNREAD.')) '; |
|
|
|
$groupCondition .= ' AND msg_status IN ('.MESSAGE_STATUS_NEW.', '.MESSAGE_STATUS_UNREAD.')) '; |
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($groupCondition)) { |
|
|
|
|
|
|
|
$sql[3] = $sqlBase.$groupCondition; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get my friend posts |
|
|
|
// Get my friend posts |
|
|
@ -1680,16 +1678,17 @@ class SocialManager extends UserManager |
|
|
|
if (!empty($friendId)) { |
|
|
|
if (!empty($friendId)) { |
|
|
|
if (is_array($friendId)) { |
|
|
|
if (is_array($friendId)) { |
|
|
|
$friendId = array_map('intval', $friendId); |
|
|
|
$friendId = array_map('intval', $friendId); |
|
|
|
$friendId = implode(",", $friendId); |
|
|
|
$friendId = implode("','", $friendId); |
|
|
|
$friendCondition = " ( user_receiver_id IN ($friendId) "; |
|
|
|
$friendCondition = " OR ( user_receiver_id IN ('$friendId') "; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$friendId = (int) $friendId; |
|
|
|
$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) '; |
|
|
|
$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)) { |
|
|
|
if (!empty($threadList)) { |
|
|
@ -1714,81 +1713,72 @@ class SocialManager extends UserManager |
|
|
|
$threadList = array_map('intval', $threadList); |
|
|
|
$threadList = array_map('intval', $threadList); |
|
|
|
$threadList = implode("','", $threadList); |
|
|
|
$threadList = implode("','", $threadList); |
|
|
|
$condition = " thread_id IN ('$threadList') "; |
|
|
|
$condition = " thread_id IN ('$threadList') "; |
|
|
|
$sql[5] = "$select |
|
|
|
$sql .= " |
|
|
|
|
|
|
|
UNION ( |
|
|
|
|
|
|
|
$select |
|
|
|
FROM c_forum_post |
|
|
|
FROM c_forum_post |
|
|
|
WHERE $condition |
|
|
|
WHERE $condition |
|
|
|
|
|
|
|
) |
|
|
|
"; |
|
|
|
"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($getCount) { |
|
|
|
if ($getCount) { |
|
|
|
$count = 0; |
|
|
|
$res = Database::query($sql); |
|
|
|
foreach ($sql as $oneQuery) { |
|
|
|
$row = Database::fetch_array($res); |
|
|
|
if (!empty($oneQuery)) { |
|
|
|
|
|
|
|
$res = Database::query($oneQuery); |
|
|
|
|
|
|
|
$row = Database::fetch_array($res); |
|
|
|
|
|
|
|
$count += (int) $row['count_items']; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $count; |
|
|
|
return (int) $row['count']; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$sqlOrder = ' ORDER BY send_date DESC '; |
|
|
|
$sql .= ' ORDER BY send_date DESC '; |
|
|
|
$sqlLimit = " LIMIT $start, $length "; |
|
|
|
$sql .= " LIMIT $start, $length "; |
|
|
|
|
|
|
|
|
|
|
|
$messages = []; |
|
|
|
$messages = []; |
|
|
|
foreach ($sql as $oneQuery) { |
|
|
|
$res = Database::query($sql); |
|
|
|
$oneQuery .= $sqlOrder.$sqlLimit; |
|
|
|
$em = Database::getManager(); |
|
|
|
$res = Database::query($oneQuery); |
|
|
|
if (Database::num_rows($res) > 0) { |
|
|
|
$em = Database::getManager(); |
|
|
|
$repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); |
|
|
|
if (Database::num_rows($res) > 0) { |
|
|
|
$repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
|
|
|
$repo = $em->getRepository('ChamiloCourseBundle:CForumPost'); |
|
|
|
$groups = []; |
|
|
|
$repoThread = $em->getRepository('ChamiloCourseBundle:CForumThread'); |
|
|
|
$userGroup = new UserGroup(); |
|
|
|
$groups = []; |
|
|
|
$urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; |
|
|
|
$userGroup = new UserGroup(); |
|
|
|
while ($row = Database::fetch_array($res, 'ASSOC')) { |
|
|
|
$urlGroup = api_get_path(WEB_CODE_PATH).'social/group_view.php?id='; |
|
|
|
$row['group_info'] = []; |
|
|
|
while ($row = Database::fetch_array($res, 'ASSOC')) { |
|
|
|
if (!empty($row['group_id'])) { |
|
|
|
$row['group_info'] = []; |
|
|
|
if (!in_array($row['group_id'], $groups)) { |
|
|
|
if (!empty($row['group_id'])) { |
|
|
|
$group = $userGroup->get($row['group_id']); |
|
|
|
if (!in_array($row['group_id'], $groups)) { |
|
|
|
$group['url'] = $urlGroup.$group['id']; |
|
|
|
$group = $userGroup->get($row['group_id']); |
|
|
|
$groups[$row['group_id']] = $group; |
|
|
|
$group['url'] = $urlGroup.$group['id']; |
|
|
|
$row['group_info'] = $group; |
|
|
|
$groups[$row['group_id']] = $group; |
|
|
|
} else { |
|
|
|
$row['group_info'] = $group; |
|
|
|
$row['group_info'] = $groups[$row['group_id']]; |
|
|
|
} else { |
|
|
|
|
|
|
|
$row['group_info'] = $groups[$row['group_id']]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Forums |
|
|
|
// Forums |
|
|
|
$row['post_title'] = ''; |
|
|
|
$row['post_title'] = ''; |
|
|
|
$row['forum_title'] = ''; |
|
|
|
$row['forum_title'] = ''; |
|
|
|
$row['thread_url'] = ''; |
|
|
|
$row['thread_url'] = ''; |
|
|
|
if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { |
|
|
|
if ($row['msg_status'] == MESSAGE_STATUS_FORUM) { |
|
|
|
/** @var CForumPost $post */ |
|
|
|
/** @var CForumPost $post */ |
|
|
|
$post = $repo->find($row['id']); |
|
|
|
$post = $repo->find($row['id']); |
|
|
|
/** @var CForumThread $thread */ |
|
|
|
/** @var CForumThread $thread */ |
|
|
|
$thread = $repoThread->find($row['thread_id']); |
|
|
|
$thread = $repoThread->find($row['thread_id']); |
|
|
|
if ($post && $thread) { |
|
|
|
if ($post && $thread) { |
|
|
|
$courseInfo = api_get_course_info_by_id($post->getCId()); |
|
|
|
$courseInfo = api_get_course_info_by_id($post->getCId()); |
|
|
|
$row['post_title'] = $post->getForumId(); |
|
|
|
$row['post_title'] = $post->getForumId(); |
|
|
|
$row['forum_title'] = $thread->getThreadTitle(); |
|
|
|
$row['forum_title'] = $thread->getThreadTitle(); |
|
|
|
$row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
|
|
|
$row['thread_url'] = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.http_build_query([ |
|
|
|
'cidReq' => $courseInfo['code'], |
|
|
|
'cidReq' => $courseInfo['code'], |
|
|
|
'forum' => $post->getForumId(), |
|
|
|
'forum' => $post->getForumId(), |
|
|
|
'thread' => $post->getThreadId(), |
|
|
|
'thread' => $post->getThreadId(), |
|
|
|
'post_id' => $post->getIid(), |
|
|
|
'post_id' => $post->getIid(), |
|
|
|
]).'#post_id_'.$post->getIid(); |
|
|
|
]).'#post_id_'.$post->getIid(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$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; |
|
|
|
return $messages; |
|
|
|
} |
|
|
|
} |
|
|
|