|
22 | 22 | use Doctrine\DBAL\Exception; |
23 | 23 | use Doctrine\ORM\Query\ResultSetMappingBuilder; |
24 | 24 | use Illuminate\Support\Facades\Config; |
25 | | -use Doctrine\DBAL\ParameterType; |
26 | 25 | use LaravelDoctrine\ORM\Facades\EntityManager; |
27 | 26 | use models\summit\Presentation; |
28 | 27 | use models\summit\SummitMetric; |
@@ -1861,14 +1860,38 @@ public function getActiveSummitsSponsorMemberships() |
1861 | 1860 | return []; |
1862 | 1861 | } |
1863 | 1862 |
|
1864 | | - // Step 2 — load all sponsors in a single IN query. findBy() uses PK-based hydration |
1865 | | - // which avoids the ORM 3 assertion failure triggered by the OneToOne inverse associations |
1866 | | - // on Sponsor (lead_report_setting, sponsorservices_statistics) that DQL/native-query |
1867 | | - // hydration hits. The result set is then re-sorted to match the SQL ORDER BY. |
1868 | | - $position = array_flip($ids); |
1869 | | - $sponsors = EntityManager::getRepository(Sponsor::class)->findBy(['id' => $ids]); |
1870 | | - usort($sponsors, fn($a, $b) => $position[$a->getId()] <=> $position[$b->getId()]); |
1871 | | - return $sponsors; |
| 1863 | + return $this->loadSponsorsByIds($ids); |
| 1864 | + } |
| 1865 | + |
| 1866 | + /** |
| 1867 | + * @param Summit $summit |
| 1868 | + * @return ArrayCollection |
| 1869 | + * @throws Exception |
| 1870 | + */ |
| 1871 | + public function getAccessibleSponsorsBySummit(Summit $summit): ArrayCollection |
| 1872 | + { |
| 1873 | + $ids = $this->getSponsorMembershipIds($summit); |
| 1874 | + |
| 1875 | + return new ArrayCollection($this->loadSponsorsByIds($ids)); |
| 1876 | + } |
| 1877 | + |
| 1878 | + /** |
| 1879 | + * Loads Sponsor entities by PK using DQL rather than native-query hydration. |
| 1880 | + * findBy()-style PK hydration avoids the ORM 3 assertion failure triggered by |
| 1881 | + * the OneToOne inverse associations on Sponsor (lead_report_setting, |
| 1882 | + * sponsorservices_statistics) that DQL/native-query hydration hits. |
| 1883 | + * |
| 1884 | + * @param int[] $ids |
| 1885 | + * @return Sponsor[] |
| 1886 | + */ |
| 1887 | + private function loadSponsorsByIds(array $ids): array |
| 1888 | + { |
| 1889 | + if (empty($ids)) return []; |
| 1890 | + |
| 1891 | + return $this->getEM() |
| 1892 | + ->createQuery('SELECT s FROM ' . Sponsor::class . ' s WHERE s.id IN (:ids) ORDER BY s.id ASC') |
| 1893 | + ->setParameter('ids', $ids) |
| 1894 | + ->getResult(); |
1872 | 1895 | } |
1873 | 1896 |
|
1874 | 1897 | /** |
@@ -1991,41 +2014,6 @@ public function addSummitRegistrationOrder(SummitOrder $summit_order) |
1991 | 2014 | $summit_order->setOwner($this); |
1992 | 2015 | } |
1993 | 2016 |
|
1994 | | - /** |
1995 | | - * @param Summit $summit |
1996 | | - * @return ArrayCollection |
1997 | | - * @throws Exception |
1998 | | - */ |
1999 | | - public function getAllowedSponsorsBySummit(Summit $summit): ArrayCollection |
2000 | | - { |
2001 | | - $sql = <<<SQL |
2002 | | -SELECT su.SponsorID |
2003 | | -FROM Sponsor_Users su |
2004 | | -INNER JOIN Sponsor s ON s.ID = su.SponsorID |
2005 | | -WHERE su.MemberID = :member_id |
2006 | | - AND s.SummitID = :summit_id |
2007 | | - AND ( |
2008 | | - JSON_CONTAINS(COALESCE(su.Permissions, '[]'), JSON_QUOTE(:slug_sponsors)) |
2009 | | - OR JSON_CONTAINS(COALESCE(su.Permissions, '[]'), JSON_QUOTE(:slug_external)) |
2010 | | - ) |
2011 | | -SQL; |
2012 | | - $ids = $this->prepareRawSQL($sql, [ |
2013 | | - 'member_id' => $this->getId(), |
2014 | | - 'summit_id' => $summit->getId(), |
2015 | | - 'slug_sponsors' => IGroup::Sponsors, |
2016 | | - 'slug_external' => IGroup::SponsorExternalUsers, |
2017 | | - ])->executeQuery()->fetchFirstColumn(); |
2018 | | - |
2019 | | - if (empty($ids)) { |
2020 | | - return new ArrayCollection(); |
2021 | | - } |
2022 | | - |
2023 | | - $position = array_flip($ids); |
2024 | | - $sponsors = $this->getEM()->getRepository(Sponsor::class)->findBy(['id' => $ids]); |
2025 | | - usort($sponsors, fn($a, $b) => $position[$a->getId()] <=> $position[$b->getId()]); |
2026 | | - return new ArrayCollection($sponsors); |
2027 | | - } |
2028 | | - |
2029 | 2017 | /** |
2030 | 2018 | * @param Summit $summit |
2031 | 2019 | * @param int $sponsor_id |
|
0 commit comments