本文整理汇总了PHP中Doctrine\ORM\EntityRepository::findBy方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityRepository::findBy方法的具体用法?PHP EntityRepository::findBy怎么用?PHP EntityRepository::findBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityRepository
的用法示例。
在下文中一共展示了EntityRepository::findBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSimilarArticlesByCategory
/**
* Return a similar articles by category
* @param Article $article
* @return Article array
*/
public function getSimilarArticlesByCategory(Article $article)
{
$category = $article->getCategory();
$similarArticles = $this->articleRepository->findBy(array('category' => $category), array('date' => 'ASC'), 3);
unset($similarArticles[array_search($article, $similarArticles)]);
return $similarArticles;
}
示例2: uniqueAppKey
private function uniqueAppKey()
{
do {
$appKey = str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
$application = $this->userRepository->findBy(array('appKey' => $appKey));
} while ($application);
return $appKey;
}
示例3: buildMainMenu
public function buildMainMenu(Request $request, ItemInterface $root)
{
$root->addChild('Messages', ['route' => 'pjax_message_index'])->getParent()->addChild('New message', ['route' => 'pjax_message_new'])->getParent();
$latests = $root->addChild('latests', ['dropdown' => true]);
/** @var Message $message */
foreach ($this->messageRepository->findBy([], array(), 4) as $message) {
$latests->addChild($message->getId(), ['route' => 'pjax_message_show', 'routeParameters' => ['id' => $message->getId()], 'label' => 'message ' . $message->getId()]);
}
return $root;
}
示例4: findBy
/**
* Find objects by criteria
*
* @param array $criteria
* @param array $options
*
* @return array
*/
public function findBy($criteria = array(), $options = array())
{
$limit = $options["limit"] ? $options["limit"] : null;
$offset = $options["offset"] ? $options["offset"] : null;
$orderBy = array();
if ($options["sort"]) {
$orderBy = array($options["sort"], $options["order"]);
}
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
示例5: post
/**
* @return ResourceViewModel
*
* @throws ForbiddenException
* @throws NotFoundException
*/
public function post()
{
if (!$this->isGranted(UserMessagePermissions::START_CONVERSATION)) {
throw new ForbiddenException('User must be logged on to start a conversation');
}
$values = $this->validateIncomingData(ConversationInputFilter::class);
/* @var MessageUserInterface[] $user */
$users = $this->userRepository->findBy(['id' => $values['participants']]);
$conversation = new GroupConversationEntity($users);
$this->conversationService->create($conversation);
return new ResourceViewModel(['conversation' => $conversation], ['template' => 'conversations/conversation']);
}
示例6: accountDeleteAction
public function accountDeleteAction()
{
/**@var $campaign VkCampaigns*/
/**@var $vkAd VkAds*/
/**@var $vkAccount VkAccounts*/
/**@var $cabinet Cabinets*/
$vkAccountId = (int) $this->params()->fromRoute('vk_account_id', 0);
if (!$vkAccountId) {
return false;
}
$vkAccount = $this->vkAccountsRepository->findBy(['id' => $vkAccountId]);
$vkAccount = reset($vkAccount);
$this->getObjectManager()->remove($vkAccount);
$allCabinets = $this->cabinetsRepository->findBy(['vk_account_id' => $vkAccountId]);
$allClients = $this->getObjectManager()->getRepository('\\Socnet\\Entity\\VkClients')->findBy(['bidder_account_id' => $vkAccountId]);
$campaigns = $this->campaignsRepository->findBy(['vk_account_id' => $vkAccountId]);
foreach ($campaigns as $campaign) {
$vkAds = $this->vkAdsRepository->findBy(['campaign_id' => $campaign->getId()]);
foreach ($vkAds as $vkAd) {
$this->getObjectManager()->remove($vkAd);
}
$this->getObjectManager()->remove($campaign);
}
foreach ($allClients as $allClient) {
$this->getObjectManager()->remove($allClient);
}
foreach ($allCabinets as $allCabinet) {
$this->getObjectManager()->remove($allCabinet);
}
$this->getObjectManager()->flush();
return $this->redirect()->toRoute('home');
}
示例7: findByUids
public function findByUids($uids)
{
if (!is_array($uids)) {
$uids = [$uids];
}
return parent::findBy(['uid' => $uids]);
}
示例8: onKernelRequest
/**
* Filter the `kernel.request` event to catch redirect addresses
*
* @param GetResponseEvent $event
*
* @return void
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
// don't do anything if it's not the master request
return;
}
$request = $event->getRequest();
$redirects = $this->redirectRepository->findBy(array('enabled' => true), array('position' => 'ASC'));
/** @var Redirect $redirect */
foreach ($redirects as $redirect) {
if ($destinationUrl = $this->redirectMatchesRequest($redirect, $request)) {
$event->setResponse(new RedirectResponse($destinationUrl, $redirect->getType()));
return;
}
}
return;
}
示例9: findBy
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
if ($this->criteriaRequiresDql($criteria) === FALSE && $this->criteriaRequiresDql((array) $orderBy) === FALSE) {
return parent::findBy($criteria, $orderBy, $limit, $offset);
}
$qb = $this->createQueryBuilder('e')->whereCriteria($criteria)->autoJoinOrderBy((array) $orderBy);
return $qb->getQuery()->setMaxResults($limit)->setFirstResult($offset)->getResult();
}
示例10: findBy
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
if (!isset($criteria['enabled'])) {
$criteria['enabled'] = true;
}
return parent::findBy($criteria, $orderBy, $limit, $offset);
// TODO: Change the autogenerated stub
}
示例11: getVotesForImage
public function getVotesForImage(Img $image)
{
$votes = $this->voteRepository->findBy(array("img" => $image));
$votesSum = 0;
foreach ($votes as $vote) {
/** @var \Vendor\GalleryBundle\Entity\ImgVote $vote */
$votesSum += $vote->getValue();
}
return $votesSum;
}
示例12: findBy
/**
* Finds entities by a set of criteria with automatic join on section if need due to retro-compatibility.
*
* @param array $criteria An array of criteria ( field => value ).
* @param array|null $orderBy Optional, an array of ordering criteria ( [field => direction] ).
* @param integer|null $limit Optional, the max number of results.
* @param integer|null $offset Optional, The starting index of results.
*
* @return Page[] An array of matching pages.
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
if (false === PageQueryBuilder::hasJoinCriteria($criteria) && false === PageQueryBuilder::hasJoinCriteria($orderBy)) {
return parent::findBy($criteria, $orderBy, $limit, $offset);
}
$query = $this->createQueryBuilder('p')->addSearchCriteria($criteria);
if (false === empty($orderBy)) {
$query->addMultipleOrderBy($orderBy);
}
return $query->setMaxResults($limit)->setFirstResult($offset)->getQuery()->getResult();
}
示例13: getAll
/**
* {@inheritdoc}
*/
public function getAll($mediaId)
{
$media = $this->mediaManager->getEntityById($mediaId);
$fileVersion = $this->getFileVersionForMedia($media);
$formatOptions = $this->formatOptionsRepository->findBy(['fileVersion' => $fileVersion]);
$formatOptionsArray = [];
/** @var FormatOptions $formatOptionEntity */
foreach ($formatOptions as $formatOptionEntity) {
$formatOptionsArray[$formatOptionEntity->getFormatKey()] = $this->entityToArray($formatOptionEntity);
}
return $formatOptionsArray;
}
示例14: findBy
/**
* {@inheritdoc}
*
* @throws EntityNotFoundException
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
if (!array_key_exists('deletedAt', $criteria)) {
$criteria['deletedAt'] = null;
} elseif ($criteria['deletedAt'] === static::IGNORE_DELETE_AT) {
unset($criteria['deletedAt']);
}
$result = parent::findBy($criteria, $orderBy, $limit, $offset);
if (empty($result)) {
throw new EntityNotFoundException();
}
return $result;
}
示例15: getAllAsArray
/**
*
* @return array
*/
public function getAllAsArray($criteria = null)
{
$list = array();
if ($criteria === null) {
$list = parent::findAll();
} else {
if ($criteria instanceof Criteria) {
$list = parent::matching($criteria);
} else {
$list = parent::findBy($criteria);
}
}
$res = array();
foreach ($list as $element) {
$res[$element->getId()] = $element->getName();
}
return $res;
}