Code Duplication    Length = 26-27 lines in 2 locations

main/inc/lib/CourseChatUtils.php 2 locations

@@ 1715-1740 (lines=26) @@
1712
     * Get the number of users connected in chat
1713
     * @return mixed
1714
     */
1715
    public function countUsersOnline()
1716
    {
1717
        $date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
1718
        $date->modify('-5 seconds');
1719
1720
        $extraCondition = null;
1721
1722
        if ($this->groupId) {
1723
            $extraCondition = 'AND ccc.toGroupId = ' . intval($this->groupId);
1724
        } else {
1725
            $extraCondition = 'AND ccc.sessionId = ' . intval($this->sessionId);
1726
        }
1727
1728
        $number = Database::getManager()
1729
            ->createQuery("
1730
                SELECT COUNT(ccc.userId) FROM ChamiloCourseBundle:CChatConnected ccc
1731
                WHERE ccc.lastConnection > :date AND ccc.cId = :course $extraCondition
1732
            ")
1733
            ->setParameters([
1734
                'date' => $date,
1735
                'course' => $this->courseId
1736
            ])
1737
            ->getSingleScalarResult();
1738
1739
        return intval($number);
1740
    }
1741
1742
    /**
1743
     * Check if a user is connected in course chat
@@ 1747-1773 (lines=27) @@
1744
     * @param int $userId
1745
     * @return int
1746
     */
1747
    private function userIsConnected($userId)
1748
    {
1749
        $date = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC'));
1750
        $date->modify('-5 seconds');
1751
1752
        $extraCondition = null;
1753
1754
        if ($this->groupId) {
1755
            $extraCondition = 'AND ccc.toGroupId = ' . intval($this->groupId);
1756
        } else {
1757
            $extraCondition = 'AND ccc.sessionId = ' . intval($this->sessionId);
1758
        }
1759
1760
        $number = Database::getManager()
1761
            ->createQuery("
1762
                SELECT COUNT(ccc.userId) FROM ChamiloCourseBundle:CChatConnected ccc
1763
                WHERE ccc.lastConnection > :date AND ccc.cId = :course AND ccc.userId = :user $extraCondition
1764
            ")
1765
            ->setParameters([
1766
                'date' => $date,
1767
                'course' => $this->courseId,
1768
                'user' => $userId
1769
            ])
1770
            ->getSingleScalarResult();
1771
1772
        return intval($number);
1773
    }
1774
1775
    /**
1776
     * Get the users online data