You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							207 lines
						
					
					
						
							5.7 KiB
						
					
					
				
			
		
		
	
	
							207 lines
						
					
					
						
							5.7 KiB
						
					
					
				<?php
 | 
						|
/* For licensing terms, see /license.txt */
 | 
						|
 | 
						|
namespace Chamilo\PluginBundle\Zoom;
 | 
						|
 | 
						|
use Chamilo\CoreBundle\Entity\Course;
 | 
						|
use Chamilo\CoreBundle\Entity\Session;
 | 
						|
use Chamilo\PageBundle\Entity\User;
 | 
						|
use DateTime;
 | 
						|
use Doctrine\Common\Collections\ArrayCollection;
 | 
						|
use Doctrine\Common\Collections\Collection;
 | 
						|
use Doctrine\Common\Collections\Criteria;
 | 
						|
use Doctrine\ORM\EntityRepository;
 | 
						|
use Doctrine\ORM\QueryBuilder;
 | 
						|
 | 
						|
/**
 | 
						|
 * Class MeetingEntityRepository.
 | 
						|
 */
 | 
						|
class MeetingEntityRepository extends EntityRepository
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Retrieves information about meetings having a start_time between two dates.
 | 
						|
     *
 | 
						|
     * @param DateTime $startDate
 | 
						|
     * @param DateTime $endDate
 | 
						|
     *
 | 
						|
     * @return MeetingEntity[]
 | 
						|
     */
 | 
						|
    public function periodMeetings($startDate, $endDate)
 | 
						|
    {
 | 
						|
        $matching = [];
 | 
						|
        $all = $this->findAll();
 | 
						|
        foreach ($all as $candidate) {
 | 
						|
            if ($candidate->startDateTime >= $startDate && $candidate->startDateTime <= $endDate) {
 | 
						|
                $matching[] = $candidate;
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        return $matching;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return ArrayCollection|Collection|MeetingEntity[]
 | 
						|
     */
 | 
						|
    public function globalMeetings()
 | 
						|
    {
 | 
						|
        return $this->matching(
 | 
						|
            Criteria::create()->where(
 | 
						|
                Criteria::expr()->andX(
 | 
						|
                    Criteria::expr()->eq('course', null),
 | 
						|
                    Criteria::expr()->eq('user', null)
 | 
						|
                )
 | 
						|
            )
 | 
						|
        );
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return ArrayCollection|Collection|MeetingEntity[]
 | 
						|
     */
 | 
						|
    public function unfinishedGlobalMeetings()
 | 
						|
    {
 | 
						|
        return $this->globalMeetings()->filter(
 | 
						|
            function ($meeting) {
 | 
						|
                return 'finished' !== $meeting->getMeetingInfoGet()->status;
 | 
						|
            }
 | 
						|
        );
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Returns either a user's meetings or all user meetings.
 | 
						|
     *
 | 
						|
     * @param User|null $user
 | 
						|
     *
 | 
						|
     * @return QueryBuilder
 | 
						|
     */
 | 
						|
    public function userMeetings($user = null)
 | 
						|
    {
 | 
						|
        $qb = $this->createQueryBuilder('m');
 | 
						|
        $qb
 | 
						|
            ->select('m')
 | 
						|
            ->leftJoin('m.registrants', 'r');
 | 
						|
 | 
						|
        //$qb->select('m');
 | 
						|
        /*$criteria = Criteria::create()->where(
 | 
						|
            Criteria::expr()->andX(
 | 
						|
                Criteria::expr()->isNull('course'),
 | 
						|
                Criteria::expr()->orX(
 | 
						|
                    Criteria::expr()->isNull('user'),
 | 
						|
                    Criteria::expr()->eq('user', $user)
 | 
						|
                )
 | 
						|
            ));*/
 | 
						|
 | 
						|
        /*$qb->where(Criteria::expr()->andX(
 | 
						|
            Criteria::expr()->isNull('course'),
 | 
						|
            Criteria::expr()->orX(
 | 
						|
                Criteria::expr()->isNull('user'),
 | 
						|
                Criteria::expr()->eq('user', $user)
 | 
						|
            )
 | 
						|
        ));*/
 | 
						|
 | 
						|
        $qb
 | 
						|
            ->andWhere('m.course IS NULL')
 | 
						|
            ->andWhere('m.user IS NULL OR m.user = :user OR r.user = :user');
 | 
						|
 | 
						|
        $qb->setParameters(['user' => $user]);
 | 
						|
 | 
						|
        return $qb;
 | 
						|
 | 
						|
        /*return $this->matching(
 | 
						|
            ,
 | 
						|
                Criteria::expr()->andX(
 | 
						|
                    Criteria::expr()->eq('registrants', null),
 | 
						|
                    Criteria::expr()->orX(
 | 
						|
                        Criteria::expr()->eq('user', null),
 | 
						|
                        Criteria::expr()->eq('user', $user)
 | 
						|
                    )
 | 
						|
                )
 | 
						|
            )
 | 
						|
        );*/
 | 
						|
 | 
						|
        /*return $this->matching(
 | 
						|
            Criteria::create()->where(
 | 
						|
                Criteria::expr()->andX(
 | 
						|
                    Criteria::expr()->eq('course', null),
 | 
						|
                    Criteria::expr()->orX(
 | 
						|
                        Criteria::expr()->eq('user', null),
 | 
						|
                        Criteria::expr()->eq('user', $user)
 | 
						|
                    )
 | 
						|
                )
 | 
						|
            )
 | 
						|
        );*/
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @param User|null $user
 | 
						|
     *
 | 
						|
     * @return MeetingEntity[]
 | 
						|
     */
 | 
						|
    public function unfinishedUserMeetings($user = null)
 | 
						|
    {
 | 
						|
        /*return $this->userMeetings($user)->filter(
 | 
						|
           function ($meeting) {
 | 
						|
               return 'finished' !== $meeting->getMeetingInfoGet()->status;
 | 
						|
           }
 | 
						|
       );*/
 | 
						|
 | 
						|
        $results = @$this->userMeetings($user)->getQuery()->getResult();
 | 
						|
        $list = [];
 | 
						|
        foreach ($results as $meeting) {
 | 
						|
            if ('finished' === $meeting->getMeetingInfoGet()->status) {
 | 
						|
                $list[] = $meeting;
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        return $list;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @param DateTime $start
 | 
						|
     * @param DateTime $end
 | 
						|
     * @param User     $user
 | 
						|
     *
 | 
						|
     * @return ArrayCollection|Collection|MeetingEntity[]
 | 
						|
     */
 | 
						|
    public function periodUserMeetings($start, $end, $user = null)
 | 
						|
    {
 | 
						|
        /*return $this->userMeetings($user)->filter(
 | 
						|
            function ($meeting) use ($start, $end) {
 | 
						|
                return $meeting->startDateTime >= $start && $meeting->startDateTime <= $end;
 | 
						|
            }
 | 
						|
        );*/
 | 
						|
 | 
						|
        $results = @$this->userMeetings($user)->getQuery()->getResult();
 | 
						|
        $list = [];
 | 
						|
        if ($results) {
 | 
						|
            foreach ($results as $meeting) {
 | 
						|
                if ($meeting->startDateTime >= $start && $meeting->startDateTime <= $end) {
 | 
						|
                    $list[] = $meeting;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        return $list;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Returns either a course's meetings or all course meetings.
 | 
						|
     *
 | 
						|
     * @param Course|null  $course
 | 
						|
     * @param Session|null $session
 | 
						|
     *
 | 
						|
     * @return ArrayCollection|Collection|MeetingEntity[]
 | 
						|
     */
 | 
						|
    public function courseMeetings($course = null, $session = null)
 | 
						|
    {
 | 
						|
        return $this->matching(
 | 
						|
            Criteria::create()->where(
 | 
						|
                null === $course
 | 
						|
                    ? Criteria::expr()->neq('course', null)
 | 
						|
                    : Criteria::expr()->andX(
 | 
						|
                    Criteria::expr()->eq('course', $course),
 | 
						|
                    Criteria::expr()->eq('session', $session)
 | 
						|
                )
 | 
						|
            )
 | 
						|
        );
 | 
						|
    }
 | 
						|
}
 | 
						|
 |