本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::createQueryBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::createQueryBuilder方法的具体用法?PHP EntityManager::createQueryBuilder怎么用?PHP EntityManager::createQueryBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kdyby\Doctrine\EntityManager
的用法示例。
在下文中一共展示了EntityManager::createQueryBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createQueryBuilder
/**
* @param string|null
* @param string|null
* @param string|null
* @return QueryBuilder
*/
public function createQueryBuilder($entityClass = NULL, $alias = NULL, $indexBy = NULL)
{
$qb = $this->entityManager->createQueryBuilder();
if ($entityClass) {
$qb->from($entityClass, $alias, $indexBy);
$qb->select($alias);
}
return $qb;
}
示例2: delete
public function delete($value)
{
// formating hours on date
$date = new \DateTime(strtotime(time()));
$date = $date->modify('-' . $value . 'hours')->format('Y-m-d H:i:s');
// deleting rows by doctrine with cascade delete entity settings in db schema
$qb = $this->em->createQueryBuilder();
$q = $qb->delete(Search::getClassName(), 's')->where($qb->expr()->lt('s.date', '?1'))->setParameter(1, $date)->getQuery();
return $numberDeleted = $q->getResult();
}
示例3: getNextPositionByEvent
/**
* @param \App\Model\Event\Entity\Event $event
*
* @return array
*/
public function getNextPositionByEvent(Entity\Event $event)
{
$query = $this->em->createQueryBuilder()->select('MAX(p.position)')->from(Entity\Performance::class, 'p')->whereCriteria(['p.event' => $event])->getQuery();
try {
$result = $query->getResult(AbstractQuery::HYDRATE_SINGLE_SCALAR);
$nextPosition = $result + 1;
} catch (NoResultException $e) {
$nextPosition = 1;
}
return $nextPosition;
}
示例4: generateAndPersistNewAddresses
private function generateAndPersistNewAddresses(int $count)
{
$qb = $this->entityManager->createQueryBuilder();
$qb->select('MAX(address.bip32index)')->from(Address::getClassName(), 'address');
$index = (int) $qb->getQuery()->getSingleScalarResult();
for ($i = 0; $i < $count; $i++) {
list($address, $index) = $this->generateNewAddress($index);
$addressEntity = new Address($address, $index);
$this->entityManager->persist($addressEntity);
}
$this->entityManager->flush();
file_put_contents($this->newAddressesFile, true);
}
示例5: getInvitation
/**
* @param string $email
* @param string|null $token
* @return Invitation|null
*/
public function getInvitation($email, $token = null)
{
$qb = $this->em->createQueryBuilder();
$qb->select('i, partial s.{id, username}')->from(Invitation::class, 'i')->leftJoin('i.sender', 's')->where('i.email = :email')->setParameter('email', $email);
if (isset($token)) {
$qb->andWhere('i.token = :token')->setParameter('token', $token);
}
try {
$invitation = $qb->getQuery()->getSingleResult();
} catch (NoResultException $e) {
$this->onInfo("Email: {$email} NOT found. [getInvitationByEmail]", $e, self::class);
return null;
}
return $invitation;
}
示例6: createBasicQuery
private function createBasicQuery(Kdyby\Doctrine\EntityManager $entityManager)
{
$qb = $entityManager->createQueryBuilder();
$qb->from(Comment::class, 'c');
foreach ($this->filter as $modifier) {
$modifier($qb);
}
return $qb;
}
示例7: getBasicDQL
/**
* @param int $listingID
* @return \Kdyby\Doctrine\QueryBuilder
*/
private function getBasicDQL($listingID = null)
{
$qb = $this->em->createQueryBuilder();
$qb->select('li, lo, wh')->from(ListingItem::class, 'li')->innerJoin('li.listing', 'l')->innerJoin('li.locality', 'lo')->innerJoin('li.workedHours', 'wh');
if (isset($listingID)) {
$qb->where('li.listing = :listingID')->setParameter('listingID', $listingID);
}
return $qb;
}
示例8: getEventsByUser
/**
* Získá události pro konkrétního uživatele
* @param \App\Model\Entity\User $user
* @return type
*/
function getEventsByUser($userEntity)
{
if ($userEntity) {
/** @var \App\Model\Entity\Client $client */
$client = $userEntity->getClient();
$qb = $this->em->createQueryBuilder();
$qb->from('\\App\\Model\\Entity\\Event', 'e')->join('\\App\\Model\\Entity\\User', 'u')->select('e')->where($qb->expr()->andX($qb->expr()->orX($qb->expr()->isNull('e.deletedAt'), $qb->expr()->gt('e.deletedAt', ':now')), $qb->expr()->eq('e.client', $client->id)))->setParameter('now', new \DateTime('now'));
return $qb->getQuery()->getResult();
}
return array();
}
示例9: getPage
/**
* @param int $pageID
* @param bool $withCommentsCount
* @return Page|null
*/
public function getPage($pageID, $withCommentsCount = false)
{
$pageQB = $this->em->createQueryBuilder();
$pageQB->select('p, u, l')->from(Page::class, 'p')->join('p.url', 'u')->join('p.locale', 'l')->where('p.id = :pageID')->setParameter('pageID', $pageID);
if ((bool) $withCommentsCount === true) {
$pageQB->addSelect('COUNT(c.page) AS commentsCount');
$pageQB->leftJoin(Comment::class, 'c', Join::WITH, 'c.page = p');
$pageQB->groupBy('p.id');
}
$page = $pageQB->getQuery()->getOneOrNullResult();
return $page;
}
示例10: getUrlEntity
/**
* @param $presenter
* @param $action
* @param $internal_id
* @return Url
*/
private function getUrlEntity($presenter, $action, $internal_id = null)
{
$qb = $this->em->createQueryBuilder();
$qb->select('u, rt')->from(Url::class, 'u')->leftJoin('u.actualUrlToRedirect', 'rt')->where('u.presenter = :p AND u.action = :a')->setParameters(['p' => $presenter, 'a' => $action]);
if ($internal_id !== null) {
$qb->andWhere('u.internalId = :i')->setParameter('i', $internal_id);
}
$url = $qb->getQuery()->setMaxResults(1)->getResult();
if (empty($url)) {
return null;
}
return $url[0];
}
示例11: isValueDuplicate
/**
* @param EntityManager $em
* @param string $entity
* @param string $attribute
* @param string $value
* @param string $locale
* @return BaseEntity|FALSE if value if not a duplicate
*/
public function isValueDuplicate(EntityManager $em, $entity, $attribute, $value, $locale = null)
{
$qb = $em->createQueryBuilder();
$qb->select('e')->from($entity, 'e');
if (empty($locale)) {
$qb->where('e.' . $attribute . ' = :' . $attribute);
$qb->setParameter($attribute, $value);
} else {
$qb->leftJoin('e.translations', 't');
$qb->where('t.' . $attribute . ' = :' . $attribute . ' AND t.locale = :locale');
$qb->setParameters([$attribute => $value, 'locale' => $locale]);
}
$result = $qb->getQuery()->getResult();
return !empty($result) ? $result[0] : false;
}
示例12: getMostReadedArticles
/**
* Vraci nejctenejsi clanky
* @param int $count
* @param DateTime|NULL $period
* @return Entities\Article[]
*/
public function getMostReadedArticles($count = 1, $period = NULL)
{
if ($period === NULL) {
$now = new DateTime();
$period = $now->modify("-2 month");
}
$cacheId = 'read-' . $count;
$query = $this->em->createQueryBuilder();
//vyhledavaci podminka
$whereConditon = $query->expr()->andX();
$whereConditon->add($query->expr()->gt('a.publishDate', ':period'));
$whereConditon->add($query->expr()->eq('a.published', 'TRUE'));
$result = $query->select('a')->from('App\\Model\\Entities\\Article', 'a')->where($whereConditon)->orderBy('a.counter', 'DESC')->setMaxResults($count)->getQuery()->useResultCache(TRUE, 600, $cacheId);
$result->setParameter('period', $period);
return $result->getResult();
}
示例13: getBasicDQL
private function getBasicDQL($id)
{
$qb = $this->em->createQueryBuilder();
$qb->select('l')->from(Listing::class, 'l')->where('l.id = :id')->setParameter('id', $id);
return $qb;
}
示例14: getAllGenreNames
/**
* @return string[]
*/
public function getAllGenreNames() : array
{
$qb = $this->entityManager->createQueryBuilder();
$qb->select('g.name')->from(Genre::getClassName(), 'g');
return array_column($qb->getQuery()->getScalarResult(), 'name');
}
示例15: findContentEntity
/**
* @param $namespace
* @param $name
* @param $locale
* @return DoctrineEntity
*/
private function findContentEntity($namespace, $name, $locale)
{
/** @var DoctrineEntity[] $result */
return $this->entityManager->createQueryBuilder()->select('c')->from(DoctrineEntity::class, 'c')->where('c.namespace = :namespace')->andWhere('c.name = :name')->andWhere('c.locale = :locale')->setParameters(['namespace' => $namespace, 'name' => $name, 'locale' => $locale])->getQuery()->getOneOrNullResult();
}