本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::createQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::createQuery方法的具体用法?PHP ObjectManager::createQuery怎么用?PHP ObjectManager::createQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::createQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findOneByAssetAndDimensions
/**
* Returns a thumbnail of the given asset with the specified dimensions.
*
* @param AssetInterface $asset The asset to render a thumbnail for
* @param string $ratioMode The thumbnail's ratio mode, see ImageInterface::RATIOMODE_* constants
* @param integer $maximumWidth The thumbnail's maximum width in pixels
* @param integer $maximumHeight The thumbnail's maximum height in pixels
* @param boolean $allowUpScaling Whether the resulting image should be upscaled
* @return \TYPO3\Media\Domain\Model\Thumbnail The thumbnail or NULL
*/
public function findOneByAssetAndDimensions(AssetInterface $asset, $ratioMode, $maximumWidth = NULL, $maximumHeight = NULL, $allowUpScaling = NULL)
{
/**
* @var $query \Doctrine\ORM\Query
*/
$query = $this->entityManager->createQuery('SELECT t FROM TYPO3\\Media\\Domain\\Model\\Thumbnail t WHERE t.originalAsset = :originalAsset AND t.ratioMode = :ratioMode');
$query->setParameter('originalAsset', $this->persistenceManager->getIdentifierByObject($asset));
$query->setParameter('ratioMode', $ratioMode);
if ($maximumWidth !== NULL) {
$query->setDQL($query->getDQL() . ' AND t.maximumWidth = :maximumWidth');
$query->setParameter('maximumWidth', $maximumWidth);
} else {
$query->setDQL($query->getDQL() . ' AND t.maximumWidth IS NULL');
}
if ($maximumHeight !== NULL) {
$query->setDQL($query->getDQL() . ' AND t.maximumHeight = :maximumHeight');
$query->setParameter('maximumHeight', $maximumHeight);
} else {
$query->setDQL($query->getDQL() . ' AND t.maximumHeight IS NULL');
}
if ($allowUpScaling !== NULL) {
$query->setDQL($query->getDQL() . ' AND t.allowUpScaling = :allowUpScaling');
$query->setParameter('allowUpScaling', $allowUpScaling);
} else {
$query->setDQL($query->getDQL() . ' AND t.allowUpScaling IS NULL');
}
$query->setMaxResults(1);
$result = $query->getOneOrNullResult();
return $result;
}
示例2: reverseTransform
/**
* Transforms a string (id) to an object (cathedra).
*
* @param string $string
*
* @return Cathedra|null
*
* @throws TransformationFailedException if object (cathedra) is not found.
*/
public function reverseTransform($string)
{
if (empty($string)) {
return null;
}
$cathedra = $this->om->createQuery('SELECT c FROM LearningMainBundle:Cathedra c WHERE c.title LIKE :letter')->setParameter('letter', $string)->getOneOrNullResult();
if (null === $cathedra) {
throw new TransformationFailedException(sprintf('Кафедра "%s" не найдена!', $string));
}
return $cathedra;
}
示例3: findOneByAssetAndThumbnailConfiguration
/**
* Returns a thumbnail of the given asset with the specified dimensions.
*
* @param AssetInterface $asset The asset to render a thumbnail for
* @param ThumbnailConfiguration $configuration
* @return \TYPO3\Media\Domain\Model\Thumbnail The thumbnail or NULL
*/
public function findOneByAssetAndThumbnailConfiguration(AssetInterface $asset, ThumbnailConfiguration $configuration)
{
/**
* @var $query \Doctrine\ORM\Query
*/
$query = $this->entityManager->createQuery('SELECT t FROM TYPO3\\Media\\Domain\\Model\\Thumbnail t WHERE t.originalAsset = :originalAsset AND t.configurationHash = :configurationHash');
$query->setParameter('originalAsset', $this->persistenceManager->getIdentifierByObject($asset));
$query->setParameter('configurationHash', $configuration->getHash());
$query->setMaxResults(1);
$result = $query->getOneOrNullResult();
return $result;
}
示例4: load
/**
* Load data fixtures with the passed EntityManager
*
* @param \Doctrine\Common\Persistence\ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$query = $manager->createQuery('SELECT COUNT(f) FROM \\Acme\\Bundle\\AppBundle\\Entity\\Fabric f');
if (0 === $query->getSingleScalarResult()) {
$stmt = $manager->getConnection()->prepare($this->getFabricsSql());
$stmt->execute();
}
$query = $manager->createQuery('SELECT COUNT(c) FROM \\Acme\\Bundle\\AppBundle\\Entity\\Color c');
if (0 === $query->getSingleScalarResult()) {
$stmt = $manager->getConnection()->prepare($this->getColorSql());
$stmt->execute();
}
}
示例5: isValid
/**
* Check if $value is valid. If it is not valid, needs to add an errorw
* to Result.
*
* @param AssetInterface $value
* @return void
*/
protected function isValid($value)
{
$fileName = $value->getTitle() ?: $value->getResource()->getFilename();
/** @var Query $query */
$query = $this->entityManager->createQuery('SELECT a FROM TYPO3\\Media\\Domain\\Model\\Asset a JOIN a.resource r WHERE (a.title = :fileName OR r.filename = :fileName) AND a.Persistence_Object_Identifier != :assetIdentifier');
$query->setParameter('fileName', $fileName);
$query->setParameter('assetIdentifier', $this->persistenceManager->getIdentifierByObject($value));
$result = $query->getArrayResult();
// We need to exclude ImageVariant objects, but can not do that in the DQL query
$result = array_filter($result, function ($value) {
return $value['dtype'] !== 'typo3_media_imagevariant';
});
if (count($result) > 0) {
$this->addError($this->translator->translateById('assetWithTitleAlreadyExists', [$fileName], null, $this->_localizationService->getConfiguration()->getCurrentLocale(), 'Main', 'Flownative.Neos.UniqueFilenames'), 1462705529);
}
}
示例6: removeAllInPath
/**
* Remove all nodes below a given path. Does not care about workspaces and dimensions.
*
* @param string $path Starting point path underneath all nodes are to be removed.
* @return void
*/
public function removeAllInPath($path)
{
$path = strtolower($path);
$query = $this->entityManager->createQuery('DELETE FROM TYPO3\\TYPO3CR\\Domain\\Model\\NodeData n WHERE n.path LIKE :path');
$query->setParameter('path', $path . '/%');
$query->execute();
}
示例7: reverseTransform
/**
* {@inheritdoc}
*/
public function reverseTransform($value)
{
if (null === $value || '' === $value) {
return null;
}
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
}
$dql = <<<DQL
SELECT i
FROM AppBundle:Core\\Invitation i
WHERE i.code = :code
AND NOT EXISTS(SELECT 1 FROM AppBundle:Core\\User u WHERE u.invitation = i)
DQL;
return $this->em->createQuery($dql)->setParameter('code', $value)->setMaxResults(1)->getOneOrNullResult();
}
示例8: findNextHigherIndex
/**
* Returns the next-higher-index seen from the given reference index in the
* level below the specified parent path. If no node with a higher than the
* given index exists at that level, the reference index is returned.
*
* The result is determined workspace-agnostic.
*
* @param string $parentPath Path of the parent node specifying the level in the node tree
* @param integer $referenceIndex Index of a known node
* @return integer The currently next higher index
*/
protected function findNextHigherIndex($parentPath, $referenceIndex)
{
$this->persistEntities();
/** @var \Doctrine\ORM\Query $query */
$query = $this->entityManager->createQuery('SELECT MIN(n.index) FROM TYPO3\\TYPO3CR\\Domain\\Model\\NodeData n WHERE n.parentPathHash = :parentPathHash AND n.index > :referenceIndex');
$query->setParameter('parentPathHash', md5($parentPath));
$query->setParameter('referenceIndex', $referenceIndex);
return $query->getSingleScalarResult() ?: NULL;
}
示例9: runDql
/**
* Run DQL and return the result as-is.
*
* @param string $dql
* @param integer $hydrationMode
* @param integer $firstResult
* @param integer $maxResult
* @return mixed
*/
public function runDql($dql, $hydrationMode = \Doctrine\ORM\Query::HYDRATE_OBJECT, $firstResult = null, $maxResult = null)
{
$query = $this->entityManager->createQuery($dql);
if ($firstResult !== null) {
$query->setFirstResult($firstResult);
}
if ($maxResult !== null) {
$query->setMaxResults($maxResult);
}
return $query->execute(array(), $hydrationMode);
}
示例10: incrementHitCount
/**
* @param RedirectInterface $redirect
* @return void
*/
public function incrementHitCount(RedirectInterface $redirect)
{
$host = $redirect->getHost();
/** @var Query $query */
if ($host === null) {
$query = $this->entityManager->createQuery('UPDATE Neos\\RedirectHandler\\DatabaseStorage\\Domain\\Model\\Redirect r SET r.hitCounter = r.hitCounter + 1, r.lastHit = CURRENT_TIMESTAMP() WHERE r.sourceUriPath = :sourceUriPath and r.host IS NULL');
} else {
$query = $this->entityManager->createQuery('UPDATE Neos\\RedirectHandler\\DatabaseStorage\\Domain\\Model\\Redirect r SET r.hitCounter = r.hitCounter + 1, r.lastHit = CURRENT_TIMESTAMP() WHERE r.sourceUriPath = :sourceUriPath and r.host = :host');
$query->setParameter('host', $host);
}
$query->setParameter('sourceUriPath', $redirect->getSourceUriPath())->execute();
}
示例11: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
/** @var EntityManager $manager */
/** @var EntityRepository $repository */
$repository = $manager->getRepository('OroCRMMagentoBundle:Customer');
$queryBuilder = $repository->createQueryBuilder('customer');
$queryBuilder->select('customer.id, SUM(customerOrder.subtotalAmount) as lifetime')->leftJoin('customer.orders', 'customerOrder', 'WITH', $queryBuilder->expr()->neq($queryBuilder->expr()->lower('customerOrder.status'), ':status'))->groupBy('customer.id')->orderBy('customer.id')->setParameter('status', Order::STATUS_CANCELED);
$updateQuery = 'UPDATE OroCRMMagentoBundle:Customer customer SET customer.lifetime = :lifetime WHERE customer.id = :id';
// update lifetime for all customers
$iterator = new BufferedQueryResultIterator($queryBuilder);
foreach ($iterator as $row) {
$customerId = $row['id'];
$lifetime = $row['lifetime'] ?: 0;
$manager->createQuery($updateQuery)->setParameter('id', $customerId)->setParameter('lifetime', $lifetime)->execute();
}
}
示例12: load
public function load(ObjectManager $manager)
{
$query = $manager->createQuery('SELECT i FROM GeneralBundle:Game i WHERE i.category IS NULL AND i.pair1 IS NULL AND i.pair2 IS NULL AND i.group IS NULL AND i.tournament IS NULL');
$games = $query->getResult();
foreach ($games as $game) {
if ($game instanceof Game) {
$manager->remove($game);
}
}
$manager->flush();
$repository = $manager->getRepository('GeneralBundle:Game');
$games = $repository->findAll('TournamentName1');
foreach ($games as $game) {
if ($game instanceof Game) {
$manager->remove($game);
}
}
$manager->flush();
$repository = $manager->getRepository('GeneralBundle:GroupCategory');
$groupA = $repository->findOneByName('Group A Test');
$groupB = $repository->findOneByName('Group B Test');
$groupC = $repository->findOneByName('Group C Test');
$Groups = array($groupA, $groupB, $groupC);
$repository = $manager->getRepository('GeneralBundle:Inscription');
foreach ($Groups as $group) {
if ($group instanceof GroupCategory) {
$inscriptions = $repository->findByGroup($group);
foreach ($inscriptions as $inscription) {
if ($inscription instanceof Inscription) {
$manager->remove($inscription);
}
}
}
}
$manager->flush();
$Users = array(array('email' => 'emailCategoryTest'), array('email' => 'User1Pair1'), array('email' => 'User2Pair1'), array('email' => 'User1Pair2'), array('email' => 'User2Pair2'), array('email' => 'User1Pair3'), array('email' => 'User2Pair3'), array('email' => 'User1Pair4'), array('email' => 'User2Pair4'), array('email' => 'User1Pair5'), array('email' => 'User2Pair5'), array('email' => 'User1Pair6'), array('email' => 'User2Pair6'), array('email' => 'User1Pair7'), array('email' => 'User2Pair7'), array('email' => 'User1Pair8'), array('email' => 'User2Pair8'), array('email' => 'User1Pair9'), array('email' => 'User2Pair9'), array('email' => 'User1Pair10'), array('email' => 'User2Pair10'));
$repository = $manager->getRepository('GeneralBundle:User');
foreach ($Users as $key) {
$entity = $repository->findOneByEmail($key['email']);
if ($entity instanceof User) {
$manager->remove($entity);
}
}
$manager->flush();
}
示例13: countBy
private function countBy($from, $to, $location, $addWhere, $datefield, $selectAndFrom, $groupAndOrder)
{
$constraints = array();
$to2 = $this->getTo($from, $to);
$constraints[] = $datefield . '>=:from';
$params['from'] = $from;
$constraints[] = $datefield . '<:to';
$params['to'] = $to2;
if (!empty($location)) {
$constraints[] = 'a.location=:loc';
$params['loc'] = $location;
}
$constraints[] = 'a.isDummy=0';
if ($addWhere != null) {
$constraints[] = $addWhere;
}
$where = ' WHERE ' . implode(' AND ', $constraints);
$query = $this->entityManager->createQuery('SELECT ' . $selectAndFrom . ' ' . $where . ' ' . $groupAndOrder);
$ret = $query->execute($params);
return $ret;
}
示例14: findJohnDoe
private function findJohnDoe(ObjectManager $manager)
{
$query = $manager->createQuery("SELECT u FROM Claroline\\CoreBundle\\Entity\\User u where u.username = 'JohnDoe'");
$query->setFetchMode("MyProject\\User", "address", "EXTRA_LAZY");
return $query->getSingleResult();
}
示例15: enableExistantUsers
/**
* Enable existant users
*
* @param Collection $users
*/
private function enableExistantUsers(Collection $users)
{
$query = $this->manager->createQuery('UPDATE Beloop\\Component\\User\\Entity\\User u SET u.enabled=:enabled WHERE u.email IN (:emails)');
$query->setParameter('enabled', true);
$query->setParameter('emails', $this->extractEmails($users)->toArray());
}