本文整理匯總了PHP中Doctrine\ORM\EntityManager::getRepository方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::getRepository方法的具體用法?PHP EntityManager::getRepository怎麽用?PHP EntityManager::getRepository使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManager
的用法示例。
在下文中一共展示了EntityManager::getRepository方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onBagdeCreateValidationLink
/**
* @DI\Observe("badge-resource-icap_dropzone-correction_delete-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-correction_end-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-correction_start-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-correction_update-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-correction_validation_change-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-criterion_create-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-criterion_delete-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-criterion_update-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-document_create-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-document_delete-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-document_open-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-drop_end-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-drop_evaluate-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-drop_start-generate_validation_link")
* @DI\Observe("badge-resource-icap_dropzone-dropzone_configure-generate_validation_link")
*/
public function onBagdeCreateValidationLink($event)
{
$content = null;
$log = $event->getLog();
switch ($log->getAction()) {
case LogCorrectionDeleteEvent::ACTION:
case LogCorrectionEndEvent::ACTION:
case LogCorrectionStartEvent::ACTION:
case LogCorrectionUpdateEvent::ACTION:
case LogCorrectionValidationChangeEvent::ACTION:
case LogCriterionCreateEvent::ACTION:
case LogCriterionDeleteEvent::ACTION:
case LogCriterionUpdateEvent::ACTION:
case LogDocumentCreateEvent::ACTION:
case LogDocumentDeleteEvent::ACTION:
case LogDocumentOpenEvent::ACTION:
case LogDropEndEvent::ACTION:
case LogDropEvaluateEvent::ACTION:
case LogDropStartEvent::ACTION:
case LogDropzoneConfigureEvent::ACTION:
$logDetails = $event->getLog()->getDetails();
$parameters = array('resourceId' => $logDetails['dropzone']['id']);
$url = $this->router->generate('icap_dropzone_open', $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
/** @var Dropzone $dropzone */
$dropzone = $this->entityManager->getRepository('IcapDropzoneBundle:Dropzone')->findOneById($logDetails['dropzone']['id']);
$title = $dropzone->getResourceNode()->getName();
$content = sprintf('<a href="%s" title="%s">%s</a>', $url, $title, $title);
break;
}
$event->setContent($content);
$event->stopPropagation();
}
示例2: prepareSummary
/**
* @param RebalancerAction $rebalancerAction
* @return array
*/
public function prepareSummary(RebalancerAction $rebalancerAction)
{
/** @var SecurityTransactionRepository $securityTransactionRepo */
$securityTransactionRepo = $this->em->getRepository('WealthbotAdminBundle:SecurityTransaction');
$rebalancerQueue = $this->repository->findByRebalancerAction($rebalancerAction, false);
$client = $rebalancerAction->getClientPortfolioValue()->getClientPortfolio()->getClient();
$result = array('rebalance_total' => 0, 'short_term_gains' => 0, 'long_term_gains' => 0, 'short_term_losses' => 0, 'long_term_losses' => 0, 'transactions_costs' => 0, 'tlh_savings' => 0);
/** @var RebalancerQueue $item */
foreach ($rebalancerQueue as $item) {
$result['rebalance_total'] += $item->getAmount();
if ($item->getLot()) {
if ($item->getLot()->isShortTerm()) {
$prefix = 'short';
} else {
$prefix = 'long';
}
if ($item->getLot()->getShortTermGain() > 0) {
$suffix = 'gains';
} else {
$suffix = 'losses';
}
$result[$prefix . '_term_' . $suffix] += abs($item->getLot()->getRealizedGain());
}
/** @var SecurityTransaction $securityTransaction */
$securityTransaction = $securityTransactionRepo->findOneByRebalancerQueue($item);
if ($securityTransaction) {
$result['transactions_costs'] += $securityTransaction->getTransactionFee();
}
}
// $result['tlh_savings'] = ($result['short_term_losses'] * $client->getProfile()->getEstimatedIncomeTax()) + ($result['long_term_losses'] * 0.15 - $result['transactions_costs']) / beginning balance
return $result;
}
示例3: transform
/**
* {@inheritdoc}
*
* @throws TransformationFailedException if object is not found.
*/
public function transform($id)
{
if (!$this->isArray) {
if (!$id) {
return null;
}
$column = is_numeric($id) ? 'id' : 'utmtag';
$entity = $this->em->getRepository($this->repository)->findOneBy(array($column => $id));
if ($entity === null) {
throw new TransformationFailedException(sprintf('UtmTag with "%s" does not exist!', $id));
}
return $entity;
}
if (empty($id) || !is_array($id)) {
return array();
}
$column = is_numeric($id[0]) ? 'id' : 'utmtag';
$repo = $this->em->getRepository($this->repository);
$prefix = $repo->getTableAlias();
$entities = $repo->getEntities(array('filter' => array('force' => array(array('column' => $prefix . '.' . $column, 'expr' => 'in', 'value' => $id))), 'ignore_paginator' => true));
if (!count($entities)) {
throw new TransformationFailedException(sprintf('UtmTags for "%s" does not exist!', $id[0]));
}
return $entities;
}
示例4: translate
/**
* @param object $entity
* @param string $field
* @param string $locale
* @param mixed $fieldData
* @throws \Bigfoot\Bundle\CoreBundle\Exception\InvalidArgumentException
*/
public function translate($entity, $field, $locale, $fieldData)
{
$em = $this->em;
$meta = $em->getClassMetadata(get_class($entity));
$listener = $this->getTranslatableListener();
$persistDefaultLocaleTransInEntity = $listener->getPersistDefaultLocaleTranslation();
if (is_object($entity)) {
$entityClass = $entity instanceof Proxy ? get_parent_class($entity) : get_class($entity);
} else {
throw new InvalidArgumentException('Argument 1 passed to TranslationRepository::translate must be an object');
}
$reflectionClass = new \ReflectionClass($entityClass);
$entityTranslationClass = $this->isPersonnalTranslationRecursive($reflectionClass)->class;
if ($locale === $listener->getTranslatableLocale($entity, $meta)) {
$meta->getReflectionProperty($field)->setValue($entity, $fieldData);
$em->persist($entity);
} elseif (!$persistDefaultLocaleTransInEntity && $locale === $listener->getDefaultLocale()) {
$trans = new $entityTranslationClass($locale, $field, $fieldData);
$listener->setTranslationInDefaultLocale(spl_object_hash($entity), $field, $trans);
} else {
$translationClassRepository = $this->em->getRepository($entityTranslationClass);
$meta = $em->getClassMetadata(get_class($entity));
$identifier = $meta->getSingleIdentifierFieldName();
$translation = null;
if ($entity && $this->propertyAccessor->getValue($entity, $identifier)) {
$translation = $translationClassRepository->findOneBy(array('locale' => $locale, 'field' => $field, 'object' => $entity));
}
if ($translation) {
$translation->setContent($fieldData);
} elseif ($fieldData !== null) {
$entity->addTranslation(new $entityTranslationClass($locale, $field, $fieldData));
}
}
}
示例5: __construct
/**
* @DI\InjectParams({
* "em" = @DI\Inject("doctrine.orm.entity_manager"),
* "wallItemManager" = @DI\Inject("icap_socialmedia.manager.wall_item")
* })
* @param EntityManager $em
* @param WallItemManager $wallItemManager
*/
public function __construct(EntityManager $em, WallItemManager $wallItemManager)
{
$this->em = $em;
$this->wallItemManager = $wallItemManager;
$this->commentActionRepository = $em->getRepository('IcapSocialmediaBundle:CommentAction');
$this->resourceNodeRepository = $em->getRepository('ClarolineCoreBundle:Resource\\ResourceNode');
}
示例6: process
/**
* {@inheritDoc}
*/
public function process(DatagridInterface $grid, array $config)
{
$this->datagrid = $grid;
if (isset($config['query'])) {
$queryConfig = array_intersect_key($config, array_flip(['query']));
$converter = new YamlConverter();
$this->qb = $converter->parse($queryConfig, $this->em->createQueryBuilder());
} elseif (isset($config['entity']) && isset($config['repository_method'])) {
$entity = $config['entity'];
$method = $config['repository_method'];
$repository = $this->em->getRepository($entity);
if (method_exists($repository, $method)) {
$qb = $repository->{$method}();
if ($qb instanceof QueryBuilder) {
$this->qb = $qb;
} else {
throw new DatasourceException(sprintf('%s::%s() must return an instance of Doctrine\\ORM\\QueryBuilder, %s given', get_class($repository), $method, is_object($qb) ? get_class($qb) : gettype($qb)));
}
} else {
throw new DatasourceException(sprintf('%s has no method %s', get_class($repository), $method));
}
} else {
throw new DatasourceException(get_class($this) . ' expects to be configured with query or repository method');
}
if (isset($config['hints'])) {
$this->queryHints = $config['hints'];
}
$grid->setDatasource(clone $this);
}
示例7: __construct
/**
* Costructor
*
* @param string $productClass
* @param ProductRepositoryInterface $productRepository
* @param EntityManager $entityManager
* @param string $assocTypeClass
* @param string $groupClass
*/
public function __construct($productClass, ProductRepositoryInterface $productRepository, EntityManager $entityManager, $assocTypeClass, $groupClass)
{
$this->productClass = $productClass;
$this->productRepository = $productRepository;
$this->groupRepository = $entityManager->getRepository($groupClass);
$this->assocTypeRepository = $entityManager->getRepository($assocTypeClass);
}
示例8: __construct
public function __construct(\Doctrine\ORM\EntityManager $em)
{
$this->nodeRepo = $em->getRepository(':Node');
$this->propRepo = $em->getRepository(':Property');
$this->relRepo = $em->getRepository(':Relation');
$this->em = $em;
}
示例9: __construct
public function __construct(EntityManager $em)
{
$this->userRepo = $em->getRepository('TerAelisUserBundle:User');
$this->nonVuRepo = $em->getRepository('TerAelisForumBundle:NonVu');
$this->commentRepo = $em->getRepository('TerAelisCommentBundle:Comment');
$this->em = $em;
}
示例10: getRepository
/**
* @return EntityRepository
*/
public function getRepository()
{
if ($this->repository === null) {
$this->repository = $this->em->getRepository(get_class(new Menu()));
}
return $this->repository;
}
示例11: sendCountNotReadMessage
/**
* Отправляем метку количества не прочитанных сообщений
*
* @param int $user
*
* @return integer
*/
protected function sendCountNotReadMessage($user)
{
$notReadMessage = $this->em->getRepository("UserMessagesBundle:Dialog")->findOneByNotReadMessage($user);
if ($notReadMessage > 0) {
$this->redis->publish('not-read', json_encode(['username' => 'username_' . $user, 'count' => $notReadMessage]));
}
}
示例12: init
/**
* Estrategia:
* - recuperar la lista de bundles
* - confeccionar una lista completa de bundles con los locales y remotos
* - recorrer la lista de bundles
* - recuperar la lista de claves del bundle
* - confeccionar una lista completa de claves con los locales y remotos del bundle
* - enviar un if-newest de cada clave/idioma
*
*/
protected function init()
{
/** @var EntityManager $em */
$this->em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
$this->srcDir = realpath($this->getApplication()->getKernel()->getRootDir() . '/../src/') . '/';
$this->translationRepository = $this->em->getRepository('TranslationsApiBundle:Translation');
}
示例13: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$id_media = null;
// get the id of media
if ($builder->getData()->getMedia() instanceof \Sfynx\MediaBundle\Entity\Mediatheque) {
$id_media = $builder->getData()->getMedia()->getId();
}
if (isset($_POST['piapp_gedmobundle_organigramtype']['media'])) {
$id_media = $_POST['piapp_gedmobundle_organigramtype']['media'];
}
$choiceList = $this->_em->getRepository("PiAppGedmoBundle:Organigram")->getArrayAllByField('category');
if (!isset($choiceList) || !count($choiceList)) {
$choiceList = array();
}
$builder->add('enabled', 'checkbox', array('data' => true))->add('page', 'entity', array('class' => 'SfynxCmfBundle:Page', 'query_builder' => function (EntityRepository $er) {
return $er->getAllPageHtml();
}, 'property' => 'route_name', 'empty_value' => 'pi.form.label.select.choose.option', "label" => "pi.form.label.field.url", 'multiple' => false, 'required' => false, "attr" => array("class" => "pi_simpleselect")))->add('category', 'choice', array('choices' => $choiceList, 'multiple' => false, 'required' => false, 'empty_value' => 'pi.form.label.select.choose.category', 'label' => "pi.form.label.field.category", "attr" => array("class" => "pi_simpleselect")))->add('categoryother', 'text', array("label" => "pi.form.label.field.or", 'required' => false))->add('parent', 'entity', array('class' => 'PiAppGedmoBundle:Organigram', 'query_builder' => function (EntityRepository $er) {
$translatableListener = $this->_container->get('gedmo.listener.translatable');
$translatableListener->setTranslationFallback(true);
return $er->createQueryBuilder('k')->select('k')->orderBy('k.lft', 'ASC');
}, 'empty_value' => 'pi.form.label.select.choose.option', 'multiple' => false, 'required' => false, "attr" => array("class" => "pi_simpleselect")))->add('title', 'text', array('label' => "pi.form.label.field.title"))->add('descriptif', 'textarea', array('label' => 'pi.form.label.field.description'))->add('question')->add('content', 'textarea', array('label' => "pi.form.label.field.content", "attr" => array("class" => "pi_editor_simple_easy")))->add('media', 'entity', array('class' => 'SfynxMediaBundle:Mediatheque', 'query_builder' => function (EntityRepository $er) use($id_media) {
$translatableListener = $this->_container->get('gedmo.listener.translatable');
$translatableListener->setTranslationFallback(true);
return $er->createQueryBuilder('a')->select('a')->where("a.id IN (:id)")->setParameter('id', $id_media);
}, 'empty_value' => 'pi.form.label.select.choose.media', 'label' => "Media", 'multiple' => false, 'required' => false, 'constraints' => array(), "label_attr" => array("class" => 'bg_image_collection'), "attr" => array("class" => "pi_simpleselect ajaxselect", "data-url" => $this->_container->get('sfynx.tool.route.factory')->getRoute("admin_gedmo_media_selectentity_ajax", array('type' => 'image')), "data-selectid" => $id_media, "data-max" => 50), 'widget_suffix' => '<a class="button-ui-mediatheque button-ui-dialog"
title="Ajouter une image à la médiatheque"
data-title="Mediatheque"
data-href="' . $this->_container->get('sfynx.tool.route.factory')->getRoute("admin_gedmo_media_new", array("NoLayout" => "false", "category" => '', 'status' => 'image')) . '"
data-selectid="#sfynx_mediabundle_mediatype_id"
data-selecttitle="#sfynx_mediabundle_mediatype_title"
data-insertid="#piapp_gedmobundle_blocktype_media"
data-inserttype="multiselect"
></a>'));
}
示例14: populateUser
/**
* Dodajanje skupin
* @param EntityManager $em
* @param array $valarray
*/
public function populateUser($em, $val)
{
$rep = $em->getRepository('\\Aaa\\Entity\\User');
$rr = $em->getRepository('\\Aaa\\Entity\\Role');
$o = $rep->findOneByEmail($val['email']);
$nov = false;
if (!$o) {
$o = new User();
$o->setEmail($val['email']);
$nov = true;
$password = 'AaBbCc1' . uniqid() . uniqid();
$o->setPassword($password);
echo "User {$val['name']} geslo {$password}\n";
}
$o->setName($val['name']);
$o->setEnabled($val['enabled']);
if ($val['roles']) {
$rr->azurirajNames($o, $val['roles']);
}
if ($nov) {
$rep->create($o);
} else {
$rep->update($o);
}
$this->addReference('User-' . $val['email'], $o);
return;
}
示例15: removeEntity
/**
* @param $entity
*/
public function removeEntity($entity)
{
$this->em->remove($entity);
$this->em->flush();
$isFound = $this->em->getRepository(get_class($entity))->findOneBy(['id' => $entity->getId()]);
$this->assertNull($isFound);
}