Code Duplication    Length = 26-27 lines in 2 locations

main/inc/lib/CourseChatUtils.php 2 locations

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