| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * This file is part of the Sonata Project package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * (c) Thomas Rabaix <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | namespace Sonata\DoctrineORMAdminBundle\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Doctrine\Common\Util\ClassUtils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Doctrine\DBAL\DBALException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Doctrine\DBAL\LockMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Doctrine\DBAL\Platforms\AbstractPlatform; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Doctrine\DBAL\Types\Type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Doctrine\ORM\EntityManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Doctrine\ORM\Mapping\ClassMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Doctrine\ORM\OptimisticLockException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Doctrine\ORM\Query; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Doctrine\ORM\QueryBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Doctrine\ORM\UnitOfWork; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Sonata\AdminBundle\Admin\FieldDescriptionInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Sonata\AdminBundle\Datagrid\DatagridInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | use Sonata\AdminBundle\Exception\LockException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use Sonata\AdminBundle\Exception\ModelManagerException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use Sonata\AdminBundle\Model\LockInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use Sonata\AdminBundle\Model\ModelManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use Sonata\DoctrineORMAdminBundle\Admin\FieldDescription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use Sonata\DoctrineORMAdminBundle\Datagrid\OrderByToSelectWalker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use Sonata\Exporter\Source\DoctrineORMQuerySourceIterator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use Symfony\Bridge\Doctrine\RegistryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use Symfony\Component\Form\Exception\PropertyAccessDeniedException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | class ModelManager implements ModelManagerInterface, LockInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public const ID_SEPARATOR = '~'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @var RegistryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     protected $registry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @var EntityManager[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     protected $cache = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function __construct(RegistryInterface $registry) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->registry = $registry; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param string $class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return ClassMetadata | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function getMetadata($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return $this->getEntityManager($class)->getMetadataFactory()->getMetadataFor($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * Returns the model's metadata holding the fully qualified property, and the last | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * property name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param string $baseClass        The base class of the model holding the fully qualified property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @param string $propertyFullName The name of the fully qualified property (dot ('.') separated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      *                                 property string) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @return array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      *                \Doctrine\ORM\Mapping\ClassMetadata $parentMetadata, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      *                string $lastPropertyName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      *                array $parentAssociationMappings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      *                ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function getParentMetadataForProperty($baseClass, $propertyFullName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $nameElements = explode('.', $propertyFullName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $lastPropertyName = array_pop($nameElements); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $class = $baseClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $parentAssociationMappings = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         foreach ($nameElements as $nameElement) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             $metadata = $this->getMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             if (isset($metadata->associationMappings[$nameElement])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 $parentAssociationMappings[] = $metadata->associationMappings[$nameElement]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                 $class = $metadata->getAssociationTargetClass($nameElement); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $properties = \array_slice($nameElements, \count($parentAssociationMappings)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $properties[] = $lastPropertyName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         return [$this->getMetadata($class), implode('.', $properties), $parentAssociationMappings]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @param string $class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     public function hasMetadata($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         return $this->getEntityManager($class)->getMetadataFactory()->hasMetadataFor($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     public function getNewFieldDescriptionInstance($class, $name, array $options = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         if (!\is_string($name)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             throw new \RuntimeException('The name argument must be a string'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         if (!isset($options['route']['name'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             $options['route']['name'] = 'edit'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         if (!isset($options['route']['parameters'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             $options['route']['parameters'] = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         list($metadata, $propertyName, $parentAssociationMappings) = $this->getParentMetadataForProperty($class, $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $fieldDescription = new FieldDescription(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $fieldDescription->setName($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $fieldDescription->setOptions($options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $fieldDescription->setParentAssociationMappings($parentAssociationMappings); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         if (isset($metadata->associationMappings[$propertyName])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             $fieldDescription->setAssociationMapping($metadata->associationMappings[$propertyName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         if (isset($metadata->fieldMappings[$propertyName])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             $fieldDescription->setFieldMapping($metadata->fieldMappings[$propertyName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         return $fieldDescription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     public function create($object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             $entityManager = $this->getEntityManager($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |             $entityManager->persist($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             $entityManager->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         } catch (\PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             throw new ModelManagerException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |                 sprintf('Failed to create object: %s', ClassUtils::getClass($object)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |                 $e->getCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |                 $e | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         } catch (DBALException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             throw new ModelManagerException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |                 sprintf('Failed to create object: %s', ClassUtils::getClass($object)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |                 $e->getCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |                 $e | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     public function update($object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             $entityManager = $this->getEntityManager($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |             $entityManager->persist($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |             $entityManager->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |         } catch (\PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             throw new ModelManagerException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |                 sprintf('Failed to update object: %s', ClassUtils::getClass($object)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |                 $e->getCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                 $e | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         } catch (DBALException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |             throw new ModelManagerException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |                 sprintf('Failed to update object: %s', ClassUtils::getClass($object)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |                 $e->getCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |                 $e | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     public function delete($object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |             $entityManager = $this->getEntityManager($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |             $entityManager->remove($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             $entityManager->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         } catch (\PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             throw new ModelManagerException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |                 sprintf('Failed to delete object: %s', ClassUtils::getClass($object)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |                 $e->getCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |                 $e | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         } catch (DBALException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |             throw new ModelManagerException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |                 sprintf('Failed to delete object: %s', ClassUtils::getClass($object)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |                 $e->getCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |                 $e | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     public function getLockVersion($object) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         $metadata = $this->getMetadata(ClassUtils::getClass($object)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         if (!$metadata->isVersioned) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         return $metadata->reflFields[$metadata->versionField]->getValue($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |     public function lock($object, $expectedVersion) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         $metadata = $this->getMetadata(ClassUtils::getClass($object)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |         if (!$metadata->isVersioned) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |             $entityManager = $this->getEntityManager($object); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             $entityManager->lock($object, LockMode::OPTIMISTIC, $expectedVersion); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         } catch (OptimisticLockException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |             throw new LockException($e->getMessage(), $e->getCode(), $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     public function find($class, $id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         if (!isset($id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         $values = array_combine($this->getIdentifierFieldNames($class), explode(self::ID_SEPARATOR, (string) $id)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         return $this->getEntityManager($class)->getRepository($class)->find($values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     public function findBy($class, array $criteria = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         return $this->getEntityManager($class)->getRepository($class)->findBy($criteria); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |     public function findOneBy($class, array $criteria = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         return $this->getEntityManager($class)->getRepository($class)->findOneBy($criteria); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |      * @param string $class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * @return EntityManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     public function getEntityManager($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         if (\is_object($class)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |             $class = \get_class($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         if (!isset($this->cache[$class])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |             $em = $this->registry->getManagerForClass($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |             if (!$em) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |                 throw new \RuntimeException(sprintf('No entity manager defined for class %s', $class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |             $this->cache[$class] = $em; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         return $this->cache[$class]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |     public function getParentFieldDescription($parentAssociationMapping, $class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |         $fieldName = $parentAssociationMapping['fieldName']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         $metadata = $this->getMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         $associatingMapping = $metadata->associationMappings[$parentAssociationMapping]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         $fieldDescription = $this->getNewFieldDescriptionInstance($class, $fieldName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         $fieldDescription->setName($parentAssociationMapping); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         $fieldDescription->setAssociationMapping($associatingMapping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |         return $fieldDescription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |     public function createQuery($class, $alias = 'o') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |         $repository = $this->getEntityManager($class)->getRepository($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         return new ProxyQuery($repository->createQueryBuilder($alias)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 307 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 308 |  |  |     public function executeQuery($query) | 
            
                                                                        
                            
            
                                    
            
            
                | 309 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 310 |  |  |         if ($query instanceof QueryBuilder) { | 
            
                                                                        
                            
            
                                    
            
            
                | 311 |  |  |             return $query->getQuery()->execute(); | 
            
                                                                        
                            
            
                                    
            
            
                | 312 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 313 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 314 |  |  |         return $query->execute(); | 
            
                                                                        
                            
            
                                    
            
            
                | 315 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |     public function getModelIdentifier($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |         return $this->getMetadata($class)->identifier; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |     public function getIdentifierValues($entity) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |         // Fix code has an impact on performance, so disable it ... | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         //$entityManager = $this->getEntityManager($entity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |         //if (!$entityManager->getUnitOfWork()->isInIdentityMap($entity)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |         //    throw new \RuntimeException('Entities passed to the choice field must be managed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |         //} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |         $class = ClassUtils::getClass($entity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |         $metadata = $this->getMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |         $platform = $this->getEntityManager($class)->getConnection()->getDatabasePlatform(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |         $identifiers = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |         foreach ($metadata->getIdentifierValues($entity) as $name => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |             if (!\is_object($value)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |                 $identifiers[] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |             $fieldType = $metadata->getTypeOfField($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |             $type = $fieldType && Type::hasType($fieldType) ? Type::getType($fieldType) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |             if ($type) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |                 $identifiers[] = $this->getValueFromType($value, $type, $fieldType, $platform); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |                 continue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |             $metadata = $this->getMetadata(ClassUtils::getClass($value)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |             foreach ($metadata->getIdentifierValues($value) as $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |                 $identifiers[] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |         return $identifiers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |      * @param mix $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |     private function getValueFromType ($value, Type $type, string $fieldType, AbstractPlatform $platform)  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |         if ('binary' === $platform->getDoctrineTypeMapping($fieldType)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |             return (string) $type->convertToPHPValue($value, $platform); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |         return $type->convertToDatabaseValue($value, $platform); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |     public function getIdentifierFieldNames($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |         return $this->getMetadata($class)->getIdentifierFieldNames(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |     public function getNormalizedIdentifier($entity) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |         if (is_scalar($entity)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |             throw new \RuntimeException('Invalid argument, object or null required'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |         if (!$entity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |         if (\in_array($this->getEntityManager($entity)->getUnitOfWork()->getEntityState($entity), [ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |             UnitOfWork::STATE_NEW, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |             UnitOfWork::STATE_REMOVED, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |         ], true)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |         $values = $this->getIdentifierValues($entity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |         if (0 === \count($values)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |         return implode(self::ID_SEPARATOR, $values); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |      * The ORM implementation does nothing special but you still should use | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |      * this method when using the id in a URL to allow for future improvements. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |     public function getUrlsafeIdentifier($entity) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |         return $this->getNormalizedIdentifier($entity); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |     public function addIdentifiersToQuery($class, ProxyQueryInterface $queryProxy, array $idx) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |         $fieldNames = $this->getIdentifierFieldNames($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |         $qb = $queryProxy->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |         $prefix = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |         $sqls = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |         foreach ($idx as $pos => $id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |             $ids = explode(self::ID_SEPARATOR, $id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |             $ands = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |             foreach ($fieldNames as $posName => $name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |                 $parameterName = sprintf('field_%s_%s_%d', $prefix, $name, $pos); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |                 $ands[] = sprintf('%s.%s = :%s', current($qb->getRootAliases()), $name, $parameterName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |                 $qb->setParameter($parameterName, $ids[$posName]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |             $sqls[] = implode(' AND ', $ands); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |         $qb->andWhere(sprintf('( %s )', implode(' OR ', $sqls))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |     public function batchDelete($class, ProxyQueryInterface $queryProxy) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |         $queryProxy->select('DISTINCT '.current($queryProxy->getRootAliases())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |             $entityManager = $this->getEntityManager($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |             $i = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |             foreach ($queryProxy->getQuery()->iterate() as $pos => $object) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |                 $entityManager->remove($object[0]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |                 if (0 === (++$i % 20)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |                     $entityManager->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |                     $entityManager->clear(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |             $entityManager->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |             $entityManager->clear(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |         } catch (\PDOException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |             throw new ModelManagerException('', 0, $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |         } catch (DBALException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |             throw new ModelManagerException('', 0, $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |     public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |         $datagrid->buildPager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |         $query = $datagrid->getQuery(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |         $query->select('DISTINCT '.current($query->getRootAliases())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |         $query->setFirstResult($firstResult); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |         $query->setMaxResults($maxResult); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |         if ($query instanceof ProxyQueryInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |             $sortBy = $query->getSortBy(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |             if (!empty($sortBy)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |                 $query->addOrderBy($sortBy, $query->getSortOrder()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |                 $query = $query->getQuery(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |                 $query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, [OrderByToSelectWalker::class]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |                 $query = $query->getQuery(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |         return new DoctrineORMQuerySourceIterator($query, $fields); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |     public function getExportFields($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |         $metadata = $this->getEntityManager($class)->getClassMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |         return $metadata->getFieldNames(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |     public function getModelInstance($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |         $r = new \ReflectionClass($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |         if ($r->isAbstract()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |             throw new \RuntimeException(sprintf('Cannot initialize abstract class: %s', $class)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |         $constructor = $r->getConstructor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |         if (null !== $constructor && (!$constructor->isPublic() || $constructor->getNumberOfRequiredParameters() > 0)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |             return $r->newInstanceWithoutConstructor(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |         return new $class(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |     public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |         $values = $datagrid->getValues(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |         if ($fieldDescription->getName() === $values['_sort_by']->getName() || $values['_sort_by']->getName() === $fieldDescription->getOption('sortable')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |             if ('ASC' === $values['_sort_order']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |                 $values['_sort_order'] = 'DESC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |                 $values['_sort_order'] = 'ASC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |             $values['_sort_order'] = 'ASC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |         $values['_sort_by'] = \is_string($fieldDescription->getOption('sortable')) ? $fieldDescription->getOption('sortable') : $fieldDescription->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |         return ['filter' => $values]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |     public function getPaginationParameters(DatagridInterface $datagrid, $page) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |         $values = $datagrid->getValues(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |         $values['_sort_by'] = $values['_sort_by']->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |         $values['_page'] = $page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |         return ['filter' => $values]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |     public function getDefaultSortValues($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |             '_sort_order' => 'ASC', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |             '_sort_by' => implode(',', $this->getModelIdentifier($class)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |             '_page' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |             '_per_page' => 25, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |     public function modelTransform($class, $instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |         return $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |     public function modelReverseTransform($class, array $array = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  |         $instance = $this->getModelInstance($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |         $metadata = $this->getMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |         $reflClass = $metadata->reflClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |         foreach ($array as $name => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |             $reflection_property = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |             // property or association ? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |             if (\array_key_exists($name, $metadata->fieldMappings)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 567 |  |  |                 $property = $metadata->fieldMappings[$name]['fieldName']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 568 |  |  |                 $reflection_property = $metadata->reflFields[$name]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 569 |  |  |             } elseif (\array_key_exists($name, $metadata->associationMappings)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 570 |  |  |                 $property = $metadata->associationMappings[$name]['fieldName']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 571 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 572 |  |  |                 $property = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 573 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 574 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 575 |  |  |             $setter = 'set'.$this->camelize($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 576 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 577 |  |  |             if ($reflClass->hasMethod($setter)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 578 |  |  |                 if (!$reflClass->getMethod($setter)->isPublic()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 579 |  |  |                     throw new PropertyAccessDeniedException(sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 580 |  |  |                         'Method "%s()" is not public in class "%s"', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 581 |  |  |                         $setter, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 582 |  |  |                         $reflClass->getName() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 583 |  |  |                     )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 584 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 585 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 586 |  |  |                 $instance->$setter($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 587 |  |  |             } elseif ($reflClass->hasMethod('__set')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 588 |  |  |                 // needed to support magic method __set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 589 |  |  |                 $instance->$property = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 590 |  |  |             } elseif ($reflClass->hasProperty($property)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 591 |  |  |                 if (!$reflClass->getProperty($property)->isPublic()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 592 |  |  |                     throw new PropertyAccessDeniedException(sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 593 |  |  |                         'Property "%s" is not public in class "%s". Maybe you should create the method "set%s()"?', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 594 |  |  |                             $property, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 595 |  |  |                             $reflClass->getName(), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 596 |  |  |                             ucfirst($property) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 597 |  |  |                     )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 598 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 599 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 600 |  |  |                 $instance->$property = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 601 |  |  |             } elseif ($reflection_property) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 602 |  |  |                 $reflection_property->setValue($instance, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 603 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 604 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 605 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 606 |  |  |         return $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 607 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 608 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 609 |  |  |     public function getModelCollectionInstance($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 610 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 611 |  |  |         return new \Doctrine\Common\Collections\ArrayCollection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 612 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 613 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 614 |  |  |     public function collectionClear(&$collection) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 615 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 616 |  |  |         return $collection->clear(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 617 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 618 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 619 |  |  |     public function collectionHasElement(&$collection, &$element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 620 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 621 |  |  |         return $collection->contains($element); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 622 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 623 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 624 |  |  |     public function collectionAddElement(&$collection, &$element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 625 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 626 |  |  |         return $collection->add($element); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 627 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 628 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 629 |  |  |     public function collectionRemoveElement(&$collection, &$element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 630 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 631 |  |  |         return $collection->removeElement($element); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 632 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 633 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 634 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 635 |  |  |      * method taken from Symfony\Component\PropertyAccess\PropertyAccessor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 636 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 637 |  |  |      * @param string $property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 638 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 639 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 640 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 641 |  |  |     protected function camelize($property) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 642 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 643 |  |  |         return str_replace(' ', '', ucwords(str_replace('_', ' ', $property))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 644 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 645 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 646 |  |  |  | 
            
                        
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.