From b858e3835f58edb52c0f6602e2af11d4da5253da Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 28 Aug 2018 14:09:27 +0200 Subject: [PATCH] Minor - update from 1.11.x --- .../Repository/BranchSyncRepository.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/CoreBundle/Repository/BranchSyncRepository.php b/src/CoreBundle/Repository/BranchSyncRepository.php index 2bd3a5d4e3..135c1996a6 100644 --- a/src/CoreBundle/Repository/BranchSyncRepository.php +++ b/src/CoreBundle/Repository/BranchSyncRepository.php @@ -37,4 +37,30 @@ class BranchSyncRepository extends NestedTreeRepository return $q->execute(); } + + /** + * Gets the first branch with parent_id = NULL. + * + * @return mixed + */ + public function getTopBranch() + { + $qb = $this->createQueryBuilder('a'); + + //Selecting user info + $qb->select('DISTINCT b'); + + $qb->from('Chamilo\CoreBundle\Entity\BranchSync', 'b'); + $qb->where('b.parentId IS NULL'); + $qb->add('orderBy', 'b.id ASC'); + $qb->setMaxResults(1); + $q = $qb->getQuery()->getResult(); + if (empty($q)) { + return null; + } else { + foreach ($q as $result) { + return $result; + } + } + } }