Code Duplication    Length = 26-27 lines in 2 locations

main/inc/lib/CourseChatUtils.php 2 locations

@@ 1755-1780 (lines=26) @@
1752
     * Get the number of users connected in chat
1753
     * @return mixed
1754
     */
1755
    public function countUsersOnline()
1756
    {
1757
        $date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
1758
        $date->modify('-5 seconds');
1759
1760
        $extraCondition = null;
1761
1762
        if ($this->groupId) {
1763
            $extraCondition = 'AND ccc.toGroupId = ' . intval($this->groupId);
1764
        } else {
1765
            $extraCondition = 'AND ccc.sessionId = ' . intval($this->sessionId);
1766
        }
1767
1768
        $number = Database::getManager()
1769
            ->createQuery("
1770
                SELECT COUNT(ccc.userId) FROM ChamiloCourseBundle:CChatConnected ccc
1771
                WHERE ccc.lastConnection > :date AND ccc.cId = :course $extraCondition
1772
            ")
1773
            ->setParameters([
1774
                'date' => $date,
1775
                'course' => $this->courseId
1776
            ])
1777
            ->getSingleScalarResult();
1778
1779
        return intval($number);
1780
    }
1781
1782
    /**
1783
     * Check if a user is connected in course chat
@@ 1787-1813 (lines=27) @@
1784
     * @param int $userId
1785
     * @return int
1786
     */
1787
    private function userIsConnected($userId)
1788
    {
1789
        $date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
1790
        $date->modify('-5 seconds');
1791
1792
        $extraCondition = null;
1793
1794
        if ($this->groupId) {
1795
            $extraCondition = 'AND ccc.toGroupId = ' . intval($this->groupId);
1796
        } else {
1797
            $extraCondition = 'AND ccc.sessionId = ' . intval($this->sessionId);
1798
        }
1799
1800
        $number = Database::getManager()
1801
            ->createQuery("
1802
                SELECT COUNT(ccc.userId) FROM ChamiloCourseBundle:CChatConnected ccc
1803
                WHERE ccc.lastConnection > :date AND ccc.cId = :course AND ccc.userId = :user $extraCondition
1804
            ")
1805
            ->setParameters([
1806
                'date' => $date,
1807
                'course' => $this->courseId,
1808
                'user' => $userId
1809
            ])
1810
            ->getSingleScalarResult();
1811
1812
        return intval($number);
1813
    }
1814
1815
    /**
1816
     * Get the users online data