/** * Load meta object by provided type and parameters. * * @MetaLoaderDoc( * description="Article Loader loads articles from Content Repository", * parameters={ * contentPath="SINGLE|required content path", * slug="SINGLE|required content slug", * pageName="COLLECTiON|name of Page for required articles" * } * ) * * @param string $type object type * @param array $parameters parameters needed to load required object type * @param int $responseType response type: single meta (LoaderInterface::SINGLE) or collection of metas (LoaderInterface::COLLECTION) * * @return Meta|Meta[]|bool false if meta cannot be loaded, a Meta instance otherwise */ public function load($type, $parameters, $responseType = LoaderInterface::SINGLE) { $article = null; if (empty($parameters)) { $parameters = []; } if ($responseType === LoaderInterface::SINGLE) { if (array_key_exists('contentPath', $parameters)) { $article = $this->dm->find('SWP\\ContentBundle\\Document\\Article', $parameters['contentPath']); } elseif (array_key_exists('slug', $parameters)) { $article = $this->dm->getRepository('SWP\\ContentBundle\\Document\\Article')->findOneBy(array('slug' => $parameters['slug'])); } if (!is_null($article)) { return new Meta($this->rootDir . '/Resources/meta/article.yml', $article); } } elseif ($responseType === LoaderInterface::COLLECTION) { if (array_key_exists('pageName', $parameters)) { $page = $this->em->getRepository('SWP\\ContentBundle\\Model\\Page')->getByName($parameters['pageName'])->getOneOrNullResult(); if ($page) { $articlePages = $this->em->getRepository('SWP\\ContentBundle\\Model\\PageContent')->getForPage($page)->getResult(); $articles = []; foreach ($articlePages as $articlePage) { $article = $this->dm->find('SWP\\ContentBundle\\Document\\Article', $articlePage->getContentPath()); if (!is_null($article)) { $articles[] = new Meta($this->rootDir . '/Resources/meta/article.yml', $article); } } return $articles; } } } return false; }
public function testResetEvents() { $page = new CmsPage(); $page->title = "my-page"; $pageContent = new CmsPageContent(); $pageContent->id = 1; $pageContent->content = "long story"; $pageContent->formatter = "plaintext"; $page->content = $pageContent; $this->dm->persist($page); $this->assertEquals(serialize(array('id' => $pageContent->id)), $page->content); $this->dm->flush(); $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content); // This is required as the originalData in the UnitOfWork doesn’t set the node of the Document $this->dm->clear(); $pageLoaded = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsPage')->find($page->id); $pageLoaded->title = "my-page-changed"; $this->assertEquals('my-page-changed', $pageLoaded->title); $this->dm->flush(); $this->assertEquals('my-page', $pageLoaded->title); $pageLoaded->content = $pageContent; $this->dm->persist($pageLoaded); $this->dm->flush(); $this->assertInstanceOf('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\CmsPageContent', $page->content); }
public function testGetByIdsFilter() { $qb = $this->dm->getRepository('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument')->createQueryBuilder('e'); $qb->where()->eq()->field('e.text')->literal('thiswillnotmatch'); $loader = new PhpcrOdmQueryBuilderLoader($qb, $this->dm); $documents = $loader->getEntitiesByIds('id', array('/test/doc')); $this->assertCount(0, $documents); }
public function testFiltered() { $qb = $this->dm->getRepository('Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument')->createQueryBuilder('e'); $qb->where()->eq()->field('e.text')->literal('thiswillnotmatch'); $formBuilder = $this->createFormBuilder($this->referrer); $formBuilder->add('single', $this->legacy ? 'phpcr_document' : 'Doctrine\\Bundle\\PHPCRBundle\\Form\\Type\\DocumentType', array('class' => 'Doctrine\\Bundle\\PHPCRBundle\\Tests\\Resources\\Document\\TestDocument', 'query_builder' => $qb)); $html = $this->renderForm($formBuilder); $this->assertContains('<select id="form_single" name="form[single]"', $html); $this->assertNotContains('<option', $html); }
/** * {@inheritdoc} */ public function load($sitemap) { $documentsCollection = $this->manager->getRepository('nvbooster\\StarterBundle\\Document\\SeoContent')->findAll(); $documents = array(); foreach ($documentsCollection as $document) { /* @var $document SeoContent */ if (count($document->getRoutes())) { $documents[] = $document; } } return $documents; }
/** * @dataProvider queryRepositoryStatements */ public function testRepositoryQuery($statement, $rowCount) { if ($rowCount == -1) { // magic to tell this is an invalid query $this->setExpectedException('PHPCR\\Query\\InvalidQueryException'); } $repository = $this->dm->getRepository($this->type); $query = $repository->createQuery($statement, \PHPCR\Query\QueryInterface::JCR_SQL2); $this->assertInstanceOf('Doctrine\\ODM\\PHPCR\\Query\\Query', $query); $result = $query->execute(); $this->assertCount($rowCount, $result); }
/** * @param object $document * @param ClassMetadata $cm * @param DocumentManager $dm * @return string */ public function generate($document, ClassMetadata $cm, DocumentManager $dm) { $repository = $dm->getRepository($cm->name); if (!$repository instanceof RepositoryIdInterface) { throw new \RuntimeException("ID could not be determined. Make sure the that the Repository '" . get_class($repository) . "' implements RepositoryIdInterface"); } $id = $repository->generateId($document); if (!$id) { throw new \RuntimeException("ID could not be determined. Repository was unable to generate an ID"); } return $id; }
/** * Use a repository that implements RepositoryIdGenerator to generate the id. * * {@inheritDoc} */ public function generate($document, ClassMetadata $class, DocumentManager $dm, $parent = null) { if (null === $parent) { $parent = $class->parentMapping ? $class->getFieldValue($document, $class->parentMapping) : null; } $repository = $dm->getRepository($class->name); if (!$repository instanceof RepositoryIdInterface) { throw new IdException("ID could not be determined. Make sure the that the Repository '" . ClassUtils::getClass($repository) . "' implements RepositoryIdInterface"); } $id = $repository->generateId($document, $parent); if (!$id) { throw new IdException("ID could not be determined. Repository was unable to generate an ID"); } return $id; }
/** * Construct a PHPCR-ODM Query Builder Loader. * * @param QueryBuilder|\Closure $queryBuilder * @param DocumentManager $manager * @param string $class */ public function __construct($queryBuilder, DocumentManager $manager = null, $class = null) { // If a query builder was passed, it must be a closure or QueryBuilder // instance if (!($queryBuilder instanceof QueryBuilder || $queryBuilder instanceof \Closure)) { throw new UnexpectedTypeException($queryBuilder, 'Doctrine\\Common\\Persistence\\ObjectManager or \\Closure'); } if ($queryBuilder instanceof \Closure) { $queryBuilder = $queryBuilder($manager->getRepository($class)); if (!$queryBuilder instanceof QueryBuilder) { throw new UnexpectedTypeException($queryBuilder, 'Doctrine\\Common\\Persistence\\ObjectManager'); } } $this->manager = $manager; $this->queryBuilder = $queryBuilder; }
public function testFindOneBy() { $user1 = new CmsUser(); $user1->username = "******"; $user1->status = "active"; $user1->name = "Benjamin"; $user2 = new CmsUser(); $user2->username = "******"; $user2->status = "active"; $user2->name = "Lukas"; $this->dm->persist($user1); $this->dm->persist($user2); $this->dm->flush(); $users1 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'beberlei')); $this->assertEquals($user1->username, $users1->username); $users2 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'obama')); $this->assertEquals(null, $users2); }
protected function findOneBy($class, Request $request, $options) { if (!$options['mapping']) { $keys = $request->attributes->keys(); $options['mapping'] = $keys ? array_combine($keys, $keys) : array(); } foreach ($options['exclude'] as $exclude) { unset($options['mapping'][$exclude]); } if (!$options['mapping']) { return false; } $criteria = array(); $metadata = $this->manager->getClassMetadata($class); foreach ($options['mapping'] as $attribute => $field) { if ($metadata->hasField($field) || $metadata->hasAssociation($field) && $metadata->isSingleValuedAssociation($field)) { $criteria[$field] = $request->attributes->get($attribute); } } if (!$criteria) { return false; } return $this->manager->getRepository($class)->findOneBy($criteria); }
/** * {@inheritDoc} */ public function findOneBy($class, array $criteria = array()) { return $this->dm->getRepository($class)->findOneBy($criteria); }
protected function getPostRepo() { return $this->dm->getRepository('Symfony\\Cmf\\Bundle\\BlogBundle\\Document\\Post'); }
private function verifyProducts() { $tasks = $this->documentManager->getRepository('\\Hautelook\\AliceBundle\\Tests\\SymfonyApp\\TestBundle\\Document\\Task')->findAll(); $this->assertCount(10, $tasks); }
public function listGreetingsAction() { $greetings = $this->documentManager->getRepository('ZfPhpcrOdmSample\\Document\\Greeting')->getDocumentsByQuery($this->documentManager->getRepository('ZfPhpcrOdmSample\\Document\\Greeting')->createQuery('SELECT * FROM [nt:unstructured]', QueryInterface::JCR_SQL2)); return array('greetings' => $greetings); }