当前位置: 首页>>代码示例>>PHP>>正文


PHP ObjectManager::createQueryBuilder方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::createQueryBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::createQueryBuilder方法的具体用法?PHP ObjectManager::createQueryBuilder怎么用?PHP ObjectManager::createQueryBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\ObjectManager的用法示例。


在下文中一共展示了ObjectManager::createQueryBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findUngeneratedIterator

 /**
  * Find ungenerated objects and return an IterableResult
  *
  * @return IterableResult
  */
 public function findUngeneratedIterator()
 {
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $this->entityManager->createQueryBuilder();
     $queryBuilder->select('t')->from($this->getEntityClassName(), 't')->where('t.resource IS NULL AND t.staticResource IS NULL');
     return $queryBuilder->getQuery()->iterate();
 }
开发者ID:neos,项目名称:neos-development-collection,代码行数:12,代码来源:ThumbnailRepository.php

示例2: cleanupTerms

 private function cleanupTerms(Treatment $treatment)
 {
     // find terms for this treatment
     $qb = $this->om->createQueryBuilder();
     $qb->select('t2')->from('TermBundle:Term', 't2')->innerJoin('t2.termDocuments', 'td', Join::WITH, 'td.type = :treatmentType')->setParameter('treatmentType', TermDocument::TYPE_TREATMENT)->where('td.documentId = :treatmentId')->setParameter('treatmentId', $treatment->getId());
     $terms = $qb->getQuery()->getResult();
     $this->output->writeln('Cleaning terms for treatment #' . $treatment->getId() . ' [' . $treatment->getName() . ']');
     if (\count($terms)) {
         $hasInternal = false;
         foreach ($terms as $term) {
             $this->output->write($this->indent() . $term->getName() . " [#{$term->getId()}]" . $this->indent());
             if (!$term->getInternal()) {
                 // if this has not been flagged as internal yet, flag it
                 $term->setInternal(\strtolower($term->getName()) == \strtolower($treatment->getName()));
             }
             if (!$hasInternal) {
                 $hasInternal = $term->getInternal();
             }
             $this->om->persist($term);
             $this->output->writeln('[OK]');
         }
         if (!$hasInternal) {
             $term = $this->createTermFromTreatment($treatment);
             $this->om->persist($term);
             $this->output->writeln($this->indent() . 'Added internal term');
         }
     } else {
         $this->output->write($this->indent() . "Found no terms: ");
         $term = $this->createTermFromTreatment($treatment);
         $this->om->persist($term);
         $this->output->writeln('[OK]');
     }
 }
开发者ID:TMBaay,项目名称:MEDTrip---Healthcareabroad,代码行数:33,代码来源:CleanUpTreatmentTermsCommand.php

示例3: find

 /**
  * Find users by given query
  *
  * @param string $q
  * @param int $limit
  * @return array
  */
 public function find($q, $limit = 25)
 {
     if (empty($q)) {
         return array();
     }
     $query = $this->em->createQueryBuilder()->select('u')->from('Newscoop\\Entity\\User', 'u')->where('u.email LIKE ?0')->orWhere('u.username LIKE ?0')->orderBy('u.id', 'asc')->setMaxResults($limit)->getQuery();
     $query->setParameter(0, "%{$q}%");
     return $query->getResult();
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:16,代码来源:UserSearchService.php

示例4: reverseTransform

 /**
  * Transform single id value to an entity
  *
  * @param string $value
  * @return mixed|null|object
  */
 public function reverseTransform($value)
 {
     if (empty($value)) {
         return null;
     }
     try {
         $entity = $this->em->createQueryBuilder()->select('entity')->from($this->className, 'entity')->where('entity.' . $this->primaryKey . ' = :id')->setParameter('id', $value)->getQuery()->getSingleResult();
     } catch (\Exception $ex) {
         // this will happen if the form submits invalid data
         throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));
     }
     if (!$entity) {
         return null;
     }
     return $entity;
 }
开发者ID:tetranz,项目名称:select2entity-bundle,代码行数:22,代码来源:EntityToPropertyTransformer.php

示例5: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     // get already present
     $qb = $manager->createQueryBuilder();
     $qb->from(SecurityType::class, 's', 's.id');
     $qb->select('s');
     $present = $qb->getQuery()->getResult();
     // load xml
     $file = $this->container->getParameter('sulu_security.security_types.fixture');
     $doc = new \DOMDocument();
     $doc->load($file);
     $xpath = new \DOMXpath($doc);
     $elements = $xpath->query('/security-types/security-type');
     if (!is_null($elements)) {
         /** @var $element \DOMNode */
         foreach ($elements as $element) {
             /** @var $child \DOMNode */
             foreach ($element->childNodes as $child) {
                 if (isset($child->nodeName)) {
                     if ($child->nodeName == 'id') {
                         $typeId = $child->nodeValue;
                     }
                     if ($child->nodeName == 'name') {
                         $typeName = $child->nodeValue;
                     }
                 }
             }
             $securityType = array_key_exists($typeId, $present) ? $present[$typeId] : new SecurityType();
             $securityType->setId($typeId);
             $securityType->setName($typeName);
             $manager->persist($securityType);
         }
     }
     $manager->flush();
 }
开发者ID:sulu,项目名称:sulu,代码行数:38,代码来源:LoadSecurityTypes.php

示例6: createQueryBuilder

 /**
  *
  * @param array $workspaces
  * @return QueryBuilder
  */
 protected function createQueryBuilder(array $workspaces)
 {
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $this->entityManager->createQueryBuilder();
     $queryBuilder->select('n')->from(NodeData::class, 'n')->where('n.workspace IN (:workspaces)')->setParameter('workspaces', $workspaces);
     return $queryBuilder;
 }
开发者ID:robertlemke,项目名称:neos-development-collection,代码行数:12,代码来源:NodeDataRepository.php

示例7: createQueryBuilder

 /**
  *
  * @param array $workspaces
  * @return QueryBuilder
  */
 protected function createQueryBuilder(array $workspaces)
 {
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $this->entityManager->createQueryBuilder();
     $queryBuilder->select('n')->from('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData', 'n')->where('n.workspace IN (:workspaces)')->setParameter('workspaces', $workspaces);
     return $queryBuilder;
 }
开发者ID:testbird,项目名称:neos-development-collection,代码行数:12,代码来源:NodeDataRepository.php

示例8: findByWorkspace

 /**
  * Find all NodeData objects inside a given workspace sorted by path to be used
  * in publishing. The order makes sure that parent nodes are published first.
  *
  * @param Workspace $workspace
  * @return array<NodeData>
  */
 public function findByWorkspace(Workspace $workspace)
 {
     /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
     $queryBuilder = $this->entityManager->createQueryBuilder();
     $queryBuilder->select('n')->distinct()->from('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData', 'n')->where('n.workspace = :workspace')->orderBy('n.path', 'ASC')->setParameter('workspace', $workspace);
     return $queryBuilder->getQuery()->getResult();
 }
开发者ID:radmiraal,项目名称:TYPO3.TYPO3CR,代码行数:14,代码来源:NodeDataRepository.php

示例9: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     // get already stored countries
     $qb = $manager->createQueryBuilder();
     $qb->from(Country::class, 'c', 'c.code');
     $qb->select('c');
     $existingCountries = $qb->getQuery()->getResult();
     // load xml
     $file = dirname(__FILE__) . '/../countries.xml';
     $doc = new \DOMDocument();
     $doc->load($file);
     $xpath = new \DOMXpath($doc);
     $elements = $xpath->query('/Countries/Country');
     if (!is_null($elements)) {
         /** @var $element DOMNode */
         foreach ($elements as $element) {
             /** @var $child DOMNode */
             foreach ($element->childNodes as $child) {
                 if (isset($child->nodeName)) {
                     if ($child->nodeName == 'Name') {
                         $countryName = $child->nodeValue;
                     }
                     if ($child->nodeName == 'Code') {
                         $countryCode = $child->nodeValue;
                     }
                 }
             }
             $country = array_key_exists($countryCode, $existingCountries) ? $existingCountries[$countryCode] : new Country();
             $country->setName($countryName);
             $country->setCode($countryCode);
             $manager->persist($country);
         }
     }
     $manager->flush();
 }
开发者ID:sulu,项目名称:sulu,代码行数:38,代码来源:LoadCountries.php

示例10: reverseTransform

 /**
  * Transform array to a collection of entities
  *
  * @param array $values
  * @return array
  */
 public function reverseTransform($values)
 {
     if (!is_array($values) || empty($values)) {
         return array();
     }
     // add new tag entries
     $newObjects = array();
     $tagPrefixLength = strlen($this->newTagPrefix);
     foreach ($values as $key => $value) {
         $cleanValue = substr($value, $tagPrefixLength);
         $valuePrefix = substr($value, 0, $tagPrefixLength);
         if ($valuePrefix == $this->newTagPrefix) {
             $object = new $this->className();
             $this->accessor->setValue($object, $this->textProperty, $cleanValue);
             $newObjects[] = $object;
             unset($values[$key]);
         }
     }
     try {
         // get multiple entities with one query
         $entities = $this->em->createQueryBuilder()->select('entity')->from($this->className, 'entity')->where('entity.' . $this->primaryKey . ' IN (:ids)')->setParameter('ids', $values)->getQuery()->getResult();
     } catch (\Exception $ex) {
         // this will happen if the form submits invalid data
         throw new TransformationFailedException('One or more id values are invalid');
     }
     return array_merge($entities, $newObjects);
 }
开发者ID:tetranz,项目名称:select2entity-bundle,代码行数:33,代码来源:EntitiesToPropertyTransformer.php

示例11: reverseTransform

 /**
  * Transforms a string (id) to an object (city).
  */
 public function reverseTransform($string)
 {
     if (empty($string)) {
         return null;
     }
     $titles = explode(', ', $string);
     $cityTitle = $titles[0];
     $countryTitle = count($titles) > 1 ? $titles[1] : null;
     $builder = $this->om->createQueryBuilder();
     $builder->select('city')->from('LearningMainBundle:City', 'city')->leftJoin('LearningMainBundle:Country', 'country', 'WITH', 'country = city.country')->where('city.title = :cityTitle')->orderBy('country.id', 'ASC')->setParameter('cityTitle', $cityTitle)->setMaxResults(1);
     if ($countryTitle) {
         $builder->andWhere('country.title LIKE :countryTitle')->setParameter('countryTitle', '%' . $countryTitle . '%');
     }
     $city = $builder->getQuery()->getOneOrNullResult();
     if (empty($city)) {
         throw new TransformationFailedException(sprintf('Город "%s" не найден!', $string));
     }
     return $city;
 }
开发者ID:Quiss,项目名称:RNMoT,代码行数:22,代码来源:CityToStringTransformer.php

示例12: findAll

 /**
  * Finds all objects and return an IterableResult
  *
  * @param string $host Full qualified host name
  * @param callable $callback
  * @return \Generator<Redirect>
  */
 public function findAll($host = null, callable $callback = null)
 {
     /** @var QueryBuilder $queryBuilder */
     $queryBuilder = $this->entityManager->createQueryBuilder();
     $query = $queryBuilder->select('r')->from($this->getEntityClassName(), 'r');
     if ($host !== null) {
         $query->andWhere('r.host = :host')->setParameter('host', $host);
     } else {
         $query->andWhere('r.host IS NULL');
     }
     $query->orderBy('r.host', 'ASC');
     $query->addOrderBy('r.sourceUriPath', 'ASC');
     return $this->iterate($query->getQuery()->iterate(), $callback);
 }
开发者ID:neos,项目名称:redirecthandler-databasestorage,代码行数:21,代码来源:RedirectRepository.php

示例13: repairCommand

 /**
  * Repair votes action
  *
  * Compare number of votes between nodes and vote log and repair, if not dryRun
  *
  * @param boolean $dryRun Don't do anything, but report actions
  * @return string
  */
 public function repairCommand($dryRun = TRUE)
 {
     if ($dryRun) {
         echo "Dry run, not making any changes\n";
     }
     $q = new FlowQuery(array($this->context->getRootNode()));
     $answerNodes = $q->find('[instanceof Sfi.Encult:Answer]')->get();
     foreach ($answerNodes as $answerNode) {
         /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
         $queryBuilder = $this->entityManager->createQueryBuilder();
         $nodes = $queryBuilder->select('v')->from('Sfi\\Encult\\Domain\\Model\\Vote', 'v')->andWhere('v.answerIdentifier = :answerIdentifier')->setParameters(array('answerIdentifier' => $answerNode->getIdentifier()))->getQuery()->getArrayResult();
         $dbCount = count($nodes);
         $crCount = $answerNode->getProperty('voteCount');
         $path = $answerNode->getPath();
         if ($dbCount !== $crCount) {
             echo "Found mistake for {$path} (db: {$dbCount} vs. cr: {$crCount})\n";
             if (!$dryRun) {
                 echo "Fixed\n";
                 $answerNode->setProperty('voteCount', $dbCount);
             }
         }
     }
     return "Done!\n";
 }
开发者ID:alexkuklin,项目名称:EncultDistr,代码行数:32,代码来源:VoteCommandController.php

示例14: reverseTransform

 /**
  * Transforms a string (id) to an object (city).
  */
 public function reverseTransform($string)
 {
     if (empty($string)) {
         return null;
     }
     $titles = explode(',', $string);
     $city = trim($titles[0]);
     $region = null;
     $country = null;
     if (isset($titles[2])) {
         $region = trim($titles[1]);
         $country = trim($titles[2]);
     }
     $builder = $this->om->createQueryBuilder();
     $builder->select('city')->from('VidalMainBundle:City', 'city')->leftJoin('VidalMainBundle:Country', 'country', 'WITH', 'country = city.country')->where('city.title = :city')->orderBy('country.id', 'ASC')->setParameter('city', $city)->setMaxResults(1);
     if ($country) {
         $builder->leftJoin('city.country', 'c')->leftJoin('city.region', 'r')->andWhere('c.title LIKE :country')->andWhere('r.title LIKE :region')->setParameter('country', $country)->setParameter('region', $region);
     }
     $city = $builder->getQuery()->getOneOrNullResult();
     if (empty($city)) {
         throw new TransformationFailedException(sprintf('Город "%s" не найден!', $string));
     }
     return $city;
 }
开发者ID:Evrika,项目名称:Vidal,代码行数:27,代码来源:CityToStringTransformer.php

示例15: persistNodeData

 /**
  * Saves the given array as a node data entity without using the ORM.
  *
  * If the node data already exists (same dimensions, same identifier, same workspace)
  * it is replaced.
  *
  * @param array $nodeData node data to save as an associative array ( $column_name => $value )
  * @throws ImportException
  * @return void
  */
 protected function persistNodeData($nodeData)
 {
     if ($nodeData['workspace'] !== 'live') {
         throw new ImportException('Saving NodeData with workspace != "live" using direct SQL not supported yet. Workspace is "' . $nodeData['workspace'] . '".');
     }
     if ($nodeData['path'] === '/') {
         return;
     }
     // cleanup old data
     /** @var \Doctrine\DBAL\Connection $connection */
     $connection = $this->entityManager->getConnection();
     // prepare node dimensions
     $dimensionValues = $nodeData['dimensionValues'];
     $dimensionsHash = Utility::sortDimensionValueArrayAndReturnDimensionsHash($dimensionValues);
     $jsonPropertiesDataTypeHandler = JsonArrayType::getType(JsonArrayType::FLOW_JSON_ARRAY);
     // post-process node data
     $nodeData['dimensionsHash'] = $dimensionsHash;
     $nodeData['dimensionValues'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($dimensionValues, $connection->getDatabasePlatform());
     $nodeData['properties'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($nodeData['properties'], $connection->getDatabasePlatform());
     $nodeData['accessRoles'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($nodeData['accessRoles'], $connection->getDatabasePlatform());
     $connection->executeQuery('DELETE FROM typo3_typo3cr_domain_model_nodedimension' . ' WHERE nodedata IN (' . '   SELECT persistence_object_identifier FROM typo3_typo3cr_domain_model_nodedata' . '   WHERE identifier = :identifier' . '   AND workspace = :workspace' . '   AND dimensionshash = :dimensionsHash' . ' )', array('identifier' => $nodeData['identifier'], 'workspace' => $nodeData['workspace'], 'dimensionsHash' => $nodeData['dimensionsHash']));
     /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
     $queryBuilder = $this->entityManager->createQueryBuilder();
     $queryBuilder->delete()->from('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData', 'n')->where('n.identifier = :identifier')->andWhere('n.dimensionsHash = :dimensionsHash')->andWhere('n.workspace = :workspace')->setParameter('identifier', $nodeData['identifier'])->setParameter('workspace', $nodeData['workspace'])->setParameter('dimensionsHash', $nodeData['dimensionsHash']);
     $queryBuilder->getQuery()->execute();
     // insert new data
     // we need to use executeUpdate to execute the INSERT -- else the data types are not taken into account.
     // That's why we build a DQL INSERT statement which is then executed.
     $queryParts = array();
     $queryArguments = array();
     $queryTypes = array();
     foreach ($this->nodeDataPropertyNames as $propertyName => $propertyConfig) {
         if (isset($nodeData[$propertyName])) {
             $queryParts[$propertyName] = ':' . $propertyName;
             $queryArguments[$propertyName] = $nodeData[$propertyName];
             if (isset($propertyConfig['columnType'])) {
                 $queryTypes[$propertyName] = $propertyConfig['columnType'];
             }
         }
     }
     $connection->executeUpdate('INSERT INTO typo3_typo3cr_domain_model_nodedata (' . implode(', ', array_keys($queryParts)) . ') VALUES (' . implode(', ', $queryParts) . ')', $queryArguments, $queryTypes);
     foreach ($dimensionValues as $dimension => $values) {
         foreach ($values as $value) {
             $nodeDimension = array('persistence_object_identifier' => Algorithms::generateUUID(), 'nodedata' => $nodeData['Persistence_Object_Identifier'], 'name' => $dimension, 'value' => $value);
             $connection->insert('typo3_typo3cr_domain_model_nodedimension', $nodeDimension);
         }
     }
 }
开发者ID:hlubek,项目名称:neos-development-collection,代码行数:58,代码来源:NodeImportService.php


注:本文中的Doctrine\Common\Persistence\ObjectManager::createQueryBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。