@param ObjectManager $manager
@param $entityOrDocument

@return DocumentGridSource|EntityGridSource|null
965115
protected function getGridSource($manager, $entityOrDocument)
    {
        $repository = $manager->getRepository($entityOrDocument);
        if ($repository) {
            $className = $repository->getClassName();
            $classMetadata = $manager->getClassMetadata($className);
            $name = $classMetadata->getName();
            $reflectionClass = $classMetadata->getReflectionClass();
            $annotation = $this->reader->getClassAnnotation($reflectionClass, 'Dtc\GridBundle\Annotation\Grid');
            if (!$annotation) {
                throw new \Exception("GridSource requested for '$entityOrDocument' but no Grid annotation found");
            }
            if ($manager instanceof EntityManagerInterface) {
                $gridSource = new EntityGridSource($manager, $name);
            } else {
                $gridSource = new DocumentGridSource($manager, $name);
            }
            $gridSource->setAnnotationReader($this->reader);
            $gridSource->setCacheDir($this->cacheDir);

            $gridSource->setDebug($this->debug);
            $gridSource->autoDiscoverColumns();
            $this->sourcesByName[$name] = $gridSource;
            $this->sourcesByClass[$className] = $gridSource;
            $gridSource->setId($className);

            return $gridSource;
        }

        return null;
    }
1092134
public function load(ObjectManager $manager)
    {
        $data = [
            [
                'language' => 'de',
                'original' => 'German',
                'localized' => 'Deutsch'
            ],
            [
                'language' => 'de',
                'original' => 'English',
                'localized' => 'Englisch'
            ],
            [
                'language' => 'fr',
                'original' => 'English',
                'localized' => 'Anglais'
            ],
            [
                'language' => 'es',
                'original' => 'English',
                'localized' => 'Inglés'
            ]
        ];

        foreach ($data as $record) {
            $translation = new Translation();
            $translation->setLanguage($record['language']);
            $translation->setOriginal($record['original']);
            $translation->setLocalized($record['localized']);
            $manager->persist($translation);
            $manager->flush();
        }
    }
1023568
public function generate($document, ClassMetadata $cm, DocumentManagerInterface $dm, $parent = null)
    {
        $id = $cm->getFieldValue($document, $cm->identifier);
        if (!$id) {
            throw new IdException('ID could not be read from the document instance using the AssignedIdGenerator.');
        }

        return $id;
    }
861997
public function load(ObjectManager $manager)
    {
        $gal = new Folder($manager);
        $gal->setName('Media');
        $gal->setTranslatableLocale('en');
        $gal->setRel('media');
        $manager->persist($gal);
        $manager->flush();
        $this->addReference('media-folder-en', $gal);

        $gal->setTranslatableLocale('nl');
        $manager->refresh($gal);
        $gal->setName('Media');
        $manager->persist($gal);
        $manager->flush();

        $gal->setTranslatableLocale('fr');
        $manager->refresh($gal);
        $gal->setName('Media');
        $manager->persist($gal);
        $manager->flush();

        $subgal = new Folder($manager);
        $subgal->setParent($gal);
        $subgal->setName('Images');
        $subgal->setTranslatableLocale('en');
        $subgal->setRel('image');
        $manager->persist($subgal);
        $manager->flush();
        $this->addReference('images-folder-en', $subgal);

        $subgal->setTranslatableLocale('nl');
        $manager->refresh($subgal);
        $subgal->setName('Afbeeldingen');
        $manager->persist($subgal);
        $manager->flush();

        $subgal->setTranslatableLocale('fr');
        $manager->refresh($subgal);
        $subgal->setName('Images');
        $manager->persist($subgal);
        $manager->flush();

        $subgal = new Folder($manager);
        $subgal->setParent($gal);
        $subgal->setName('Videos');
        $subgal->setTranslatableLocale('en');
        $subgal->setRel('video');
        $manager->persist($subgal);
        $manager->flush();
        $this->addReference('videos-folder-en', $subgal);

        $subgal->setTranslatableLocale('nl');
        $manager->refresh($subgal);
        $subgal->setName('Video\'s');
        $manager->persist($subgal);
        $manager->flush();

        $subgal->setTranslatableLocale('fr');
        $manager->refresh($subgal);
        $subgal->setName('Vidéos');
        $manager->persist($subgal);
        $manager->flush();

        $subgal = new Folder($manager);
        $subgal->setParent($gal);
        $subgal->setName('Slides');
        $subgal->setTranslatableLocale('en');
        $subgal->setRel('slideshow');
        $manager->persist($subgal);
        $manager->flush();
        $this->addReference('slides-folder-en', $subgal);

        $subgal->setTranslatableLocale('nl');
        $manager->refresh($subgal);
        $subgal->setName('Presentaties');
        $manager->persist($subgal);
        $manager->flush();

        $subgal->setTranslatableLocale('fr');
        $manager->refresh($subgal);
        $subgal->setName('Presentations');
        $manager->persist($subgal);
        $manager->flush();

        $subgal = new Folder($manager);
        $subgal->setParent($gal);
        $subgal->setName('Files');
        $subgal->setTranslatableLocale('en');
        $subgal->setRel('files');
        $manager->persist($subgal);
        $manager->flush();
        $this->addReference('files-folder-en', $subgal);

        $subgal->setTranslatableLocale('nl');
        $manager->refresh($subgal);
        $subgal->setName('Bestanden');
        $manager->persist($subgal);
        $manager->flush();

        $subgal->setTranslatableLocale('fr');
        $manager->refresh($subgal);
        $subgal->setName('Fichiers');
        $manager->persist($subgal);
        $manager->flush();
    }
767837
public function load(ObjectManager $manager)
    {
        $transitionDraftToPending = $this->createTransition('status-draft', 'status-pending');
        $transitionToTranslateToPending = $this->createTransition('status-toTranslate', 'status-pending');
        $transitionPendingToPublished = $this->createTransition('status-pending', 'status-published');
        $transitionPublishedToDraft = $this->createTransition('status-published', 'status-draft');
        $transitionDraftToPublished = $this->createTransition('status-draft', 'status-published');

        $profileContributor = $this->createProfile(
            array('en' => 'Contributor', 'fr' => 'Contributeur'),
            array('en' => 'Member which must submit his content to validation for publication', 'fr' => 'Membre qui doit soumettre son contenu à validation pour publication'),
            array($transitionDraftToPending, $transitionToTranslateToPending),
            'Contributor'
        );
        $profileValidator = $this->createProfile(
            array('en' => 'Validator', 'fr' => 'Validateur'),
            array('en' => 'Member which can publish', 'fr' => 'Membre qui peut publier un contenu'),
            array($transitionPendingToPublished, $transitionPublishedToDraft, $transitionDraftToPublished),
            'Validator'
        );

        $manager->persist($profileContributor);
        $manager->persist($profileValidator);

        $manager->flush();
    }
530999
public static function create(?Client $client = null, ?Configuration $config = null, ?EventManager $eventManager = null) : DocumentManager
    {
        return new static($client, $config, $eventManager);
    }
95430
public function getObjectManager()
    {
        if (!$this->objectManager instanceof ObjectManager) {
            $this->setObjectManager($this->getServiceManager()->get('doctrine.entitymanager.orm_default'));
        }
        return $this->objectManager;
    }
104119
public function delete($idOrDocument) 
    {
		$cache = $this->getServiceLocator()->get('ClassifiedCache');
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$classifiedService = $this->getServiceLocator()->get('document.service.classified');
		$entityManager = $main->getEntityManager();
		$documentRepository = $main->getDocumentEntityRepository();
		$entity = $documentRepository->getEntity($idOrDocument);
		// It can NOT exists when add a NEW classified (parent still doesn't exists)
		$parent = $entity->getParent(); 
		
		// checking for permission, only if we are in edit mode
		if(null !== $parent && !$classifiedService->checkIfOwnerOrAdmin($parent)) {
			throw new \Exception('Non possiedi i permessi per agire su questo documento');
		}
		
		$cacheKey = $parent ? $documentRepository->getEncryptedId($parent->getDocumentId()) : 'noCache';
		$imageModel = new ImageModel($entity, $this->getServiceLocator());

		// 1) Delete the image
		$phisical = $imageModel->deleteImages();
		
		// 3) Remove the document
		$entityManager->remove($entity);
		$entityManager->flush();
		
		// 4) Remove parent classified cache
		if($cache->hasItem($cacheKey)) {
			$cache->removeItem($cacheKey);
		}
		
		return $phisical;
    }
1355015
private function createCollection(DocumentManager $documentManager, ClassMetadata $classMetadata, $collectionName)
    {

        $database = $documentManager->getDatabase();

        $exists = false;
        foreach ($database->listCollections() as $collection) {
            if ($collection->getName() == $collectionName) {
                $exists = true;
            }
        }

        $creationOptions = $classMetadata->getCollectionCreationOptions();
        if (!empty($creationOptions) && !$exists) {
            $database->createCollection($collectionName, $creationOptions);
        }

        $collectionOptions = $classMetadata->getCollectionOptions();

        return $database->selectCollection($collectionName, $collectionOptions);
    }
1127575
public function load(ObjectManager $manager)
    {
        /**
         * @var ObjectDirector $categoryDirector
         */
        $categoryDirector = $this->getDirector('category');

        /**
         * Category.
         *
         * @var CategoryInterface $rootCategory
         */
        $rootCategory = $categoryDirector
            ->create()
            ->setName('root-category')
            ->setSlug('root-category')
            ->setEnabled(true)
            ->setRoot(true);

        $categoryDirector->save($rootCategory);
        $this->addReference('rootCategory', $rootCategory);

        /**
         * Category.
         *
         * @var CategoryInterface $category
         */
        $category = $categoryDirector
            ->create()
            ->setName('category')
            ->setSlug('category')
            ->setEnabled(true)
            ->setParent($rootCategory)
            ->setRoot(false);

        $categoryDirector->save($category);
        $this->addReference('category', $category);

        /**
         * Second level category.
         *
         * @var CategoryInterface $secondLevelCategory
         */
        $secondLevelCategory = $categoryDirector
            ->create()
            ->setName('Second level category')
            ->setSlug('second-level-category')
            ->setEnabled(true)
            ->setParent($category)
            ->setRoot(false);

        $categoryDirector->save($secondLevelCategory);
        $this->addReference('secondLevelCategory', $secondLevelCategory);
    }
63790
protected function createRepository(DocumentManagerInterface $dm, $documentName)
    {
        $metadata = $dm->getClassMetadata($documentName);
        $repositoryClassName = $metadata->customRepositoryClassName;

        if ($repositoryClassName === null) {
            $configuration = $dm->getConfiguration();
            $repositoryClassName = $configuration->getDefaultRepositoryClassName();
        }

        return new $repositoryClassName($dm, $metadata);
    }
235603
protected function createAttributes(\DOMNodeList $nodeList, ObjectManager $manager)
    {
        /** @var \DOMNode $element */
        foreach ($nodeList as $element) {
            $attribute = new Attribute();
            $children = $element->childNodes;

            /** @var \DOMNode $child */
            foreach ($children as $child) {
                if (isset($child->nodeName) && $child->nodeName === 'key') {
                    $attribute->setKey($child->nodeValue);
                    continue;
                }
                if (isset($child->nodeName) && $child->nodeName === 'type') {
                    $type = $this->getType($child->nodeValue);

                    $attribute->setType($type);
                    continue;
                }

                /** @var \DOMNode $childNode */
                foreach ($child->childNodes as $childNode) {
                    switch ($childNode->nodeName) {
                        case 'name':
                            $locale = $childNode->attributes->getNamedItem('locale')->nodeValue;
                            $translation = $this->createAttributeTranslation(
                                $childNode->nodeValue,
                                $locale,
                                $attribute
                            );
                            $manager->persist($translation);

                            break;
                        case 'value':
                            $this->createAttributeValue($attribute, $childNode, $manager);

                            break;
                    }
                }
            }
            $manager->persist($attribute);
        }

        $manager->flush();
    }
403614
public function getLoader(ObjectManager $manager, $queryBuilder, $class, $hints = [])
    {
        $loader = new ORMQueryBuilderLoader($queryBuilder, $manager, $class);

        foreach ($hints as $name => $value) {
            $loader->setHint($name, $value);
        }

        return $loader;
    }
48511
public function saveEntityMap($objectManagerName)
    {
        $moduleOptions =  $this->getModuleOptions();
        $originalFlag = $this->getModuleOptions()->getFlagDisableUseEntityMapDoctrineCache();
        $moduleOptions->setFlagDisableUseEntityMapDoctrineCache(true);

        $map = $this->getEntityMapBuilder()->buildEntityMapByObjectManagerName($objectManagerName);

        $key = $this->getCacheKeyForObjectManagerName($objectManagerName);
        $resultSaveCache = $this->getCache()->save($key, $map);
        $moduleOptions->setFlagDisableUseEntityMapDoctrineCache($originalFlag);

        return $resultSaveCache;
    }
464134
public function load(ObjectManager $manager)
    {
        for($i=1; $i <= 4; $i++)
        {

            $post = new Post();
            $post->setName('title'.$i);
            $post->setSlug('title-'.$i);
            $post->setContent('content '.$i);
            $post->setCreatedAt(new \DateTime());

            $manager->persist($post);
            $manager->flush();

        }
    }
725984
public function create(ResourceManager $resourceManager, ApiRequest $request, int $version, string $resource)
    {
        $resourceManager->version($version);

        /** @var HandlesPostRequest $handler */
        $handler = $this->initializeHandler($resourceManager, $resource, $request, HandlesPostRequest::class);

        $parameters = $request->asParameters();

        $result = $handler->store($request, $parameters);

        if ($result === null) {
            return $this->respondNoContent();
        }

        $document = $this->makeDocumentFromResource($resourceManager, $resource, $result, $parameters, $handler);

        return $this->respondCreated($document);
    }
567172
private static function createEntityManagerWithParameters(array $options, Configuration $config, EventManager $evm = null)
    {
        try {
            return EntityManager::create(self::randomizeServerPoolConnection($options), $config, $evm);
        } catch (\Exception $e) {
            throw new InvalidArgumentException(
                'Enable to create new EntityManager with provided parameters',
                InvalidArgumentException::INVALID_ARGUMENT,
                $e
            );
        }
    }