Code Duplication    Length = 26-27 lines in 2 locations

main/inc/lib/CourseChatUtils.php 2 locations

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