| 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\DoctrinePHPCRAdminBundle\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Doctrine\Common\Collections\ArrayCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Doctrine\Common\Util\ClassUtils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Doctrine\ODM\PHPCR\DocumentManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Doctrine\ODM\PHPCR\Mapping\ClassMetadata; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Sonata\AdminBundle\Admin\FieldDescriptionInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Sonata\AdminBundle\Datagrid\DatagridInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Sonata\AdminBundle\Exception\ModelManagerException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Sonata\AdminBundle\Model\ModelManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Sonata\DoctrinePHPCRAdminBundle\Admin\FieldDescription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Sonata\DoctrinePHPCRAdminBundle\Datagrid\ProxyQuery; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | class ModelManager implements ModelManagerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @var DocumentManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     protected $dm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function __construct(DocumentManager $dm) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->dm = $dm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * Returns the related model's metadata. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @param string $class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @return ClassMetadata | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function getMetadata($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return $this->dm->getMetadataFactory()->getMetadataFor($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * Returns true is the model has some metadata. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param string $class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function hasMetadata($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         return $this->dm->getMetadataFactory()->hasMetadataFor($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @throws ModelManagerException if the document manager throws any exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     public function create($object): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $this->dm->persist($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $this->dm->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             throw new ModelManagerException('', 0, $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @throws ModelManagerException if the document manager throws any exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     public function update($object): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             $this->dm->persist($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             $this->dm->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             throw new ModelManagerException('', 0, $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @throws ModelManagerException if the document manager throws any exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     public function delete($object): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             $this->dm->remove($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             $this->dm->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             throw new ModelManagerException('', 0, $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * Find one object from the given class repository. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     public function find($class, $id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         if (!isset($id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         if (null === $class) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             return $this->dm->find(null, $id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         return $this->dm->getRepository($class)->find($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * @throws \RunTimeException if $name is not a string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * @return FieldDescription | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     public function getNewFieldDescriptionInstance($class, $name, array $options = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         if (!\is_string($name)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |             throw new \RunTimeException('The name argument must be a string'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         $metadata = $this->getMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $fieldDescription = new FieldDescription(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |         $fieldDescription->setName($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         $fieldDescription->setOptions($options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         if (isset($metadata->associationMappings[$name])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |             $fieldDescription->setAssociationMapping($metadata->associationMappings[$name]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         if (isset($metadata->fieldMappings[$name])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             $fieldDescription->setFieldMapping($metadata->fieldMappings[$name]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         return $fieldDescription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     public function findBy($class, array $criteria = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         return $this->dm->getRepository($class)->findBy($criteria); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     public function findOneBy($class, array $criteria = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         return $this->dm->getRepository($class)->findOneBy($criteria); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * @return DocumentManager The PHPCR-ODM document manager responsible for | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      *                         this model | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     public function getDocumentManager() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         return $this->dm; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      * @return FieldDescriptionInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     public function getParentFieldDescription($parentAssociationMapping, $class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         $fieldName = $parentAssociationMapping['fieldName']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         $metadata = $this->getMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         $associatingMapping = $metadata->associationMappings[$parentAssociationMapping]; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $fieldDescription = $this->getNewFieldDescriptionInstance($class, $fieldName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         $fieldDescription->setName($parentAssociationMapping); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         $fieldDescription->setAssociationMapping($associatingMapping); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         return $fieldDescription; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |      * @param string $class the fully qualified class name to search for | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      * @param string $alias alias to use for this class when accessing fields, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |      *                      defaults to 'a' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      * @throws \InvalidArgumentException if alias is not a string or an empty string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      * @return ProxyQueryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     public function createQuery($class, $alias = 'a') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         $qb = $this->getDocumentManager()->createQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         $qb->from()->document($class, $alias); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         return new ProxyQuery($qb, $alias); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |      * @param ProxyQuery $query | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |     public function executeQuery($query) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         return $query->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     public function getModelIdentifier($classname) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         return $this->getMetadata($classname)->identifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |      * Transforms the document into the PHPCR path. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |      * Note: This is returning an array because Doctrine ORM for example can | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |      * have multiple identifiers, e.g. if the primary key is composed of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      * several columns. We only ever have one, but return that wrapped into an | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |      * array to adhere to the interface. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     public function getIdentifierValues($document) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         $class = $this->getMetadata(ClassUtils::getClass($document)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $path = $class->reflFields[$class->identifier]->getValue($document); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         return [$path]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |     public function getIdentifierFieldNames($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         return [$this->getModelIdentifier($class)]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * This is just taking the id out of the array again. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |      * @throws \InvalidArgumentException if $document is not an object or null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |     public function getNormalizedIdentifier($document) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         if (is_scalar($document)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |             throw new \InvalidArgumentException('Invalid argument, object or null required'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |         // the document is not managed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         if (!$document || !$this->getDocumentManager()->contains($document)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         $values = $this->getIdentifierValues($document); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |         return $values[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |      * Currently only the leading slash is removed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |      * @param object $document | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |      * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |     public function getUrlsafeIdentifier($document) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         $id = $this->getNormalizedIdentifier($document); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |         if (null !== $id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |             return substr($id, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |     public function addIdentifiersToQuery($class, ProxyQueryInterface $queryProxy, array $idx): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         /* @var $queryProxy ProxyQuery */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |         $qb = $queryProxy->getQueryBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |         $orX = $qb->andWhere()->orX(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |         foreach ($idx as $id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |             $path = $this->getBackendId($id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |             $orX->same($path, $queryProxy->getAlias()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |      * Add leading slash to construct valid phpcr document id. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |      * The phpcr-odm QueryBuilder uses absolute paths and expects id´s to start with a forward slash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |      * because SonataAdmin uses object id´s for constructing URL´s it has to use id´s without the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |      * leading slash. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |      * @param string $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 328 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 329 |  |  |     public function getBackendId($id) | 
            
                                                                        
                            
            
                                    
            
            
                | 330 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 331 |  |  |         return '/' === substr($id, 0, 1) ? $id : '/'.$id; | 
            
                                                                        
                            
            
                                    
            
            
                | 332 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |      * @throws ModelManagerException if anything goes wrong during query execution | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |     public function batchDelete($class, ProxyQueryInterface $queryProxy): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |             $i = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |             $res = $queryProxy->execute(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |             foreach ($res as $object) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |                 $this->dm->remove($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |                 if (0 === (++$i % 20)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |                     $this->dm->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |                     $this->dm->clear(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |             $this->dm->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |             $this->dm->clear(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |             throw new ModelManagerException('', 0, $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |      * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 364 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 365 |  |  |     public function getModelInstance($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 366 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 367 |  |  |         return new $class(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 368 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 369 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 370 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 371 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 372 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 373 |  |  |     public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 374 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 375 |  |  |         $values = $datagrid->getValues(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 376 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 377 |  |  |         if ($this->isFieldAlreadySorted($fieldDescription, $datagrid)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 378 |  |  |             if ('ASC' === $values['_sort_order']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 379 |  |  |                 $values['_sort_order'] = 'DESC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 380 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 381 |  |  |                 $values['_sort_order'] = 'ASC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 382 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 383 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 384 |  |  |             $values['_sort_by'] = $fieldDescription->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 385 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 386 |  |  |             $values['_sort_order'] = 'ASC'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 387 |  |  |             $values['_sort_by'] = $fieldDescription->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 388 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 389 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 390 |  |  |         return ['filter' => $values]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 391 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 392 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 393 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 394 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 395 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 396 |  |  |     public function getPaginationParameters(DatagridInterface $datagrid, $page) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 397 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 398 |  |  |         $values = $datagrid->getValues(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 399 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 400 |  |  |         if (isset($values['_sort_by']) && $values['_sort_by'] instanceof FieldDescriptionInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 401 |  |  |             $values['_sort_by'] = $values['_sort_by']->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 402 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 403 |  |  |         $values['_page'] = $page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 404 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 405 |  |  |         return ['filter' => $values]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 406 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 407 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 408 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 409 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 410 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 411 |  |  |     public function getDefaultSortValues($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 412 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 413 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 414 |  |  |             '_sort_order' => 'ASC', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 415 |  |  |             '_sort_by' => $this->getModelIdentifier($class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 416 |  |  |             '_page' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 417 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 418 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 419 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 420 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 421 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 422 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 423 |  |  |      * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 424 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 425 |  |  |     public function modelTransform($class, $instance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 426 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 427 |  |  |         return $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 428 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 429 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 430 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 431 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 432 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 433 |  |  |      * @throws NoSuchPropertyException if the class has no magic setter and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 434 |  |  |      *                                 public property for a field in array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 435 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 436 |  |  |      * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 437 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 438 |  |  |     public function modelReverseTransform($class, array $array = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 439 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 440 |  |  |         $instance = $this->getModelInstance($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 441 |  |  |         $metadata = $this->getMetadata($class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 442 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 443 |  |  |         $reflClass = $metadata->reflClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 444 |  |  |         foreach ($array as $name => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 445 |  |  |             $reflection_property = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 446 |  |  |             // property or association ? | 
            
                                                                                                            
                            
            
                                    
            
            
                | 447 |  |  |             if (\array_key_exists($name, $metadata->fieldMappings)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 448 |  |  |                 $property = $metadata->fieldMappings[$name]['fieldName']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 449 |  |  |                 $reflection_property = $metadata->reflFields[$name]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 450 |  |  |             } elseif (\array_key_exists($name, $metadata->associationMappings)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 451 |  |  |                 $property = $metadata->associationMappings[$name]['fieldName']; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 452 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 453 |  |  |                 $property = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 454 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 455 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 456 |  |  |             // TODO: use PropertyAccess https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/187 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 457 |  |  |             $setter = 'set'.$this->camelize($name); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 458 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 459 |  |  |             if ($reflClass->hasMethod($setter)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 460 |  |  |                 if (!$reflClass->getMethod($setter)->isPublic()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 461 |  |  |                     throw new NoSuchPropertyException(sprintf('Method "%s()" is not public in class "%s"', $setter, $reflClass->getName())); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 462 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 463 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 464 |  |  |                 $instance->$setter($value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 465 |  |  |             } elseif ($reflClass->hasMethod('__set')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 466 |  |  |                 // needed to support magic method __set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 467 |  |  |                 $instance->$property = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 468 |  |  |             } elseif ($reflClass->hasProperty($property)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 469 |  |  |                 if (!$reflClass->getProperty($property)->isPublic()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 470 |  |  |                     throw new NoSuchPropertyException(sprintf('Property "%s" is not public in class "%s". Maybe you should create the method "set%s()"?', $property, $reflClass->getName(), ucfirst($property))); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 471 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 472 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 473 |  |  |                 $instance->$property = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 474 |  |  |             } elseif ($reflection_property) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 475 |  |  |                 $reflection_property->setValue($instance, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 476 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 477 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 478 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 479 |  |  |         return $instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 480 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 481 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 482 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 483 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 484 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 485 |  |  |     public function getModelCollectionInstance($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 486 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 487 |  |  |         return new ArrayCollection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 488 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 489 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 490 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 491 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 492 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 493 |  |  |     public function collectionClear(&$collection) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 494 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 495 |  |  |         return $collection->clear(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 496 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 497 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 498 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 499 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 500 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 501 |  |  |     public function collectionHasElement(&$collection, &$element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 502 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 503 |  |  |         return $collection->contains($element); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 504 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 505 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 506 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 507 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 508 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 509 |  |  |     public function collectionAddElement(&$collection, &$element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 510 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 511 |  |  |         return $collection->add($element); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 512 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 513 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 514 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 515 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 516 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 517 |  |  |     public function collectionRemoveElement(&$collection, &$element) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 518 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 519 |  |  |         return $collection->removeElement($element); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 520 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 521 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 522 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 523 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 524 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 525 |  |  |     public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 526 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 527 |  |  |         throw new \RuntimeException('Datasourceiterator not implemented.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 528 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 529 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 530 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 531 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 532 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 533 |  |  |      * Not really implemented. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 534 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 535 |  |  |     public function getExportFields($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 536 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 537 |  |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 538 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 539 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 540 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 541 |  |  |      * Method taken from PropertyPath. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 542 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 543 |  |  |      * NEXT_MAJOR: remove when doing https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/187 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 544 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 545 |  |  |      * @param string $property | 
            
                                                                                                            
                            
            
                                    
            
            
                | 546 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 547 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 548 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 549 |  |  |      * @deprecated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 550 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 551 |  |  |     protected function camelize($property) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 552 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 553 |  |  |         return preg_replace(['/(^|_)+(.)/e', '/\.(.)/e'], ["strtoupper('\\2')", "'_'.strtoupper('\\1')"], $property); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 554 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 555 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 556 |  |  |     private function isFieldAlreadySorted(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 557 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 558 |  |  |         $values = $datagrid->getValues(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 559 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 560 |  |  |         if (!isset($values['_sort_by']) || !$values['_sort_by'] instanceof FieldDescriptionInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 561 |  |  |             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 562 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 563 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 564 |  |  |         return $values['_sort_by']->getName() === $fieldDescription->getName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 565 |  |  |             || $values['_sort_by']->getName() === $fieldDescription->getOption('sortable'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 566 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 567 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 568 |  |  |  | 
            
                        
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.