22
33namespace App \Repository ;
44
5+ use App \Entity \Calendar ;
56use App \Entity \CalendarInstance ;
7+ use App \Entity \CalendarObject ;
68use App \Entity \Principal ;
9+ use App \Entity \SchedulingObject ;
710use Doctrine \Bundle \DoctrineBundle \Repository \ServiceEntityRepository ;
811use Doctrine \Persistence \ManagerRegistry ;
912
@@ -37,11 +40,11 @@ public function findSharedInstancesOfInstance(int $calendarId, bool $withCalenda
3740 return $ query ->addSelect ('p.displayName ' , 'p.email ' )
3841 ->getQuery ()
3942 ->getArrayResult ();
40- } else {
41- // Returns CalendarInstances as objects
42- return $ query ->getQuery ()
43- ->getResult ();
4443 }
44+
45+ // Returns CalendarInstances as objects
46+ return $ query ->getQuery ()
47+ ->getResult ();
4548 }
4649
4750 /**
@@ -74,6 +77,23 @@ public function hasDifferentOwner(int $calendarId, string $principalUri): bool
7477 ->getSingleScalarResult () > 0 ;
7578 }
7679
80+
81+ public function findAllSchedulingObjectsForCalendar (int $ calendarInstanceId , string $ principalUri ): array
82+ {
83+ $ objectRepository = $ this ->getEntityManager ()->getRepository (SchedulingObject::class);
84+ return $ objectRepository ->createQueryBuilder ('s ' )
85+ ->leftJoin (CalendarObject::class, 'c ' , \Doctrine \ORM \Query \Expr \Join::WITH , 'c.uri = s.uri ' )
86+ ->leftJoin (CalendarInstance::class, 'ci ' , \Doctrine \ORM \Query \Expr \Join::WITH , 'ci.calendar = c.calendar ' )
87+ ->where ('ci.id = :id ' )
88+ // uri is not unique across calendars — two different calendars can have objects with the same uri.
89+ // The join should also filter by principaluri as a consequence
90+ ->andWhere ('s.principalUri = :principalUri ' )
91+ ->setParameter ('id ' , $ calendarInstanceId )
92+ ->setParameter ('principalUri ' , $ principalUri )
93+ ->getQuery ()
94+ ->getResult ();
95+ }
96+
7797 /**
7898 * Get counts of calendar objects by component type for a calendar instance.
7999 *
@@ -83,7 +103,7 @@ public function hasDifferentOwner(int $calendarId, string $principalUri): bool
83103 */
84104 public function getObjectCountsByComponentType (int $ calendarId ): array
85105 {
86- $ objectRepository = $ this ->getEntityManager ()->getRepository (\ App \ Entity \ CalendarObject::class);
106+ $ objectRepository = $ this ->getEntityManager ()->getRepository (CalendarObject::class);
87107
88108 // Instead of three separate queries, get all counts in a single query
89109 $ results = $ objectRepository ->createQueryBuilder ('o ' )
@@ -95,9 +115,9 @@ public function getObjectCountsByComponentType(int $calendarId): array
95115 ->getResult ();
96116
97117 $ componentTypeMap = [
98- \ App \ Entity \ Calendar::COMPONENT_EVENTS => 'events ' ,
99- \ App \ Entity \ Calendar::COMPONENT_NOTES => 'notes ' ,
100- \ App \ Entity \ Calendar::COMPONENT_TODOS => 'tasks ' ,
118+ Calendar::COMPONENT_EVENTS => 'events ' ,
119+ Calendar::COMPONENT_NOTES => 'notes ' ,
120+ Calendar::COMPONENT_TODOS => 'tasks ' ,
101121 ];
102122
103123 $ counts = [
0 commit comments