Code Duplication    Length = 26-27 lines in 2 locations

main/inc/lib/CourseChatUtils.php 2 locations

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