| @@ 36-60 (lines=25) @@ | ||
| 33 | * Get the connected users for a chat |
|
| 34 | * @return array |
|
| 35 | */ |
|
| 36 | public function getConnectedUsers() |
|
| 37 | { |
|
| 38 | $date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC')); |
|
| 39 | $date->modify('-5 minutes'); |
|
| 40 | ||
| 41 | $extraCondition = null; |
|
| 42 | ||
| 43 | if ($this->groupId) { |
|
| 44 | $extraCondition = 'AND ccc.toGroupId = ' . intval($this->groupId); |
|
| 45 | } else { |
|
| 46 | $extraCondition = 'AND ccc.sessionId = ' . intval($this->sessionId); |
|
| 47 | } |
|
| 48 | ||
| 49 | return Database::getManager() |
|
| 50 | ->createQuery(" |
|
| 51 | SELECT u FROM ChamiloCourseBundle:CChatConnected ccc |
|
| 52 | INNER JOIN ChamiloUserBundle:User u WITH ccc.userId = u |
|
| 53 | WHERE ccc.lastConnection > :date AND ccc.cId = :course $extraCondition |
|
| 54 | ") |
|
| 55 | ->setParameters([ |
|
| 56 | 'date' => $date, |
|
| 57 | 'course' => $this->courseId |
|
| 58 | ]) |
|
| 59 | ->getResult(); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Prepare a message. Clean and insert emojis |
|
| @@ 1743-1768 (lines=26) @@ | ||
| 1740 | * Get the number of users connected in chat |
|
| 1741 | * @return mixed |
|
| 1742 | */ |
|
| 1743 | public function countUsersOnline() |
|
| 1744 | { |
|
| 1745 | $date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC')); |
|
| 1746 | $date->modify('-5 minutes'); |
|
| 1747 | ||
| 1748 | $extraCondition = null; |
|
| 1749 | ||
| 1750 | if ($this->groupId) { |
|
| 1751 | $extraCondition = 'AND ccc.toGroupId = ' . intval($this->groupId); |
|
| 1752 | } else { |
|
| 1753 | $extraCondition = 'AND ccc.sessionId = ' . intval($this->sessionId); |
|
| 1754 | } |
|
| 1755 | ||
| 1756 | $number = Database::getManager() |
|
| 1757 | ->createQuery(" |
|
| 1758 | SELECT COUNT(ccc.userId) FROM ChamiloCourseBundle:CChatConnected ccc |
|
| 1759 | WHERE ccc.lastConnection > :date AND ccc.cId = :course $extraCondition |
|
| 1760 | ") |
|
| 1761 | ->setParameters([ |
|
| 1762 | 'date' => $date, |
|
| 1763 | 'course' => $this->courseId |
|
| 1764 | ]) |
|
| 1765 | ->getSingleScalarResult(); |
|
| 1766 | ||
| 1767 | return intval($number); |
|
| 1768 | } |
|
| 1769 | ||
| 1770 | /** |
|
| 1771 | * Get the users online data |
|