| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace AbterPhp\Website\Databases\Queries; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use AbterPhp\Admin\Databases\Queries\IAuthLoader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use AbterPhp\Admin\Exception\Database; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Opulence\Databases\ConnectionPools\ConnectionPool; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Opulence\QueryBuilders\MySql\QueryBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** @phan-file-suppress PhanTypeMismatchArgument */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class PageCategoryAuthLoader implements IAuthLoader | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** @var ConnectionPool */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected $connectionPool; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * BlockCache constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @param ConnectionPool $connectionPool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public function __construct(ConnectionPool $connectionPool) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->connectionPool = $connectionPool; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     public function loadAll(): array | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $query = (new QueryBuilder()) | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             ->select('ug.identifier AS v0', 'pc.identifier AS v1') | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             ->from('user_groups_page_categories', 'ugpc') | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             ->innerJoin('page_categories', 'pc', 'ugpc.page_category_id = pc.id AND pc.deleted_at IS NULL') | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |             ->innerJoin('user_groups', 'ug', 'ugpc.user_group_id = ug.id AND ug.deleted_at IS NULL') | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         ; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         $connection = $this->connectionPool->getReadConnection(); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $statement  = $connection->prepare($query->getSql()); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $statement->bindValues($query->getParameters()); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         if (!$statement->execute()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             throw new Database($statement->errorInfo()); | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         return $statement->fetchAll(\PDO::FETCH_ASSOC); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  |