Code Duplication    Length = 17-18 lines in 3 locations

src/Chamilo/CoreBundle/Entity/Course.php 1 location

@@ 516-533 (lines=18) @@
513
     * @param CourseRelUser $subscription
514
     * @return bool
515
     */
516
    private function hasSubscription(CourseRelUser $subscription)
517
    {
518
        if ($this->getUsers()->count()) {
519
            $criteria = Criteria::create()->where(
520
                Criteria::expr()->eq("user", $subscription->getUser())
521
            )->andWhere(
522
                Criteria::expr()->eq("status", $subscription->getStatus())
523
            )->andWhere(
524
                Criteria::expr()->eq("relationType", $subscription->getRelationType())
525
            );
526
527
            $relation = $this->getUsers()->matching($criteria);
528
529
            return $relation->count() > 0;
530
        }
531
532
        return false;
533
    }
534
535
    /**
536
     * @param User $user

src/Chamilo/CoreBundle/Entity/Session.php 2 locations

@@ 371-388 (lines=18) @@
368
     * @param SessionRelUser $subscription
369
     * @return bool
370
     */
371
    public function hasUser(SessionRelUser $subscription)
372
    {
373
        if ($this->getUsers()->count()) {
374
            $criteria = Criteria::create()->where(
375
                Criteria::expr()->eq("user", $subscription->getUser())
376
            )->andWhere(
377
                Criteria::expr()->eq("session", $subscription->getSession())
378
            )->andWhere(
379
                Criteria::expr()->eq("relationType", $subscription->getRelationType())
380
            );
381
382
            $relation = $this->getUsers()->matching($criteria);
383
384
            return $relation->count() > 0;
385
        }
386
387
        return false;
388
    }
389
390
    /**
391
     * @return ArrayCollection
@@ 1018-1034 (lines=17) @@
1015
     * @param SessionRelCourseRelUser $subscription
1016
     * @return bool
1017
     */
1018
    public function hasUserCourseSubscription(SessionRelCourseRelUser $subscription)
1019
    {
1020
        if ($this->getUserCourseSubscriptions()->count()) {
1021
            $criteria = Criteria::create()->where(
1022
                Criteria::expr()->eq("user", $subscription->getUser())
1023
            )->andWhere(
1024
                Criteria::expr()->eq("course", $subscription->getCourse())
1025
            )->andWhere(
1026
                Criteria::expr()->eq("session", $subscription->getSession())
1027
            );
1028
            $relation = $this->getUserCourseSubscriptions()->matching($criteria);
1029
1030
            return $relation->count() > 0;
1031
        }
1032
1033
        return false;
1034
    }
1035
1036
    /**
1037
     * currentCourse is set in CourseListener