本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectManager::getRepository方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectManager::getRepository方法的具体用法?PHP ObjectManager::getRepository怎么用?PHP ObjectManager::getRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectManager
的用法示例。
在下文中一共展示了ObjectManager::getRepository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reverseTransform
/**
* Transforms a collection os files on session on entities
*
* @throws TransformationFailedException if object (issue) is not found.
*/
public function reverseTransform($id)
{
// Pasar los ficheros almacenados en la sesión a la carpeta web y devolver el array de ficheros
$manager = $this->orphanageManager->get('gallery');
$images = $manager->uploadFiles();
if (count($images) == 0) {
return null;
} else {
if (count($images) == 1) {
$file = $this->om->getRepository('AppBundle:File')->findOneByPath('uploads/gallery/' . $images[0]->getFilename());
if ($file == null) {
$file = new File();
$file->setPath('uploads/gallery/' . $images[0]->getFilename());
$this->om->persist($file);
$this->om->flush();
}
$data = $file;
} else {
$data = array();
foreach ($images as $image) {
$file = $this->om->getRepository('AppBundle:File')->findOneByPath('uploads/gallery/' . $image->getFilename());
if ($file == null) {
$file = new File();
$file->setPath('uploads/gallery/' . $image->getFilename());
$this->om->persist($file);
$this->om->flush();
}
$data[] = $file;
}
$this->om->flush();
}
}
return $data;
}
示例2: __construct
/**
* @param string $class
* @param \Doctrine\Common\Persistence\ManagerRegistry $manager_registry
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
*/
public function __construct($class, ManagerRegistry $manager_registry, EventDispatcherInterface $event_dispatcher = null)
{
$this->class = $class;
$this->event_dispatcher = $event_dispatcher;
$this->entity_manager = $manager_registry->getManagerForClass($class);
$this->entity_repository = $this->entity_manager->getRepository($class);
}
示例3: load
/**
* Load data fixtures with the passed EntityManager
*
* @param \Doctrine\Common\Persistence\ObjectManager $manager
*/
function load(ObjectManager $manager)
{
$typeRepo = $manager->getRepository('GotChosenSiteBundle:NotificationCommType');
$general = $typeRepo->findOneBy(['typeName' => 'General Notifications']);
if (!$general) {
$general = new NotificationCommType();
$general->setTypeName('General Notifications');
$manager->persist($general);
}
$eg = $typeRepo->findOneBy(['typeName' => 'Evolution Games Notifications']);
if (!$eg) {
$eg = new NotificationCommType();
$eg->setTypeName('Evolution Games Notifications');
$manager->persist($eg);
}
$manager->flush();
$notificationTypes = [['Newsletters', $general, true], ['Scholarship Information', $general, false], ['Sponsor Notifications', $general, false], ['Developer Feedback Notifications', $eg, false], ['Scholarship Notifications', $eg, false], ['EG News', $eg, false]];
$repo = $manager->getRepository('GotChosenSiteBundle:NotificationType');
foreach ($notificationTypes as $nt) {
if (!$repo->findOneBy(['name' => $nt[0]])) {
$type = new NotificationType();
$type->setName($nt[0]);
$type->setCommType($nt[1]);
$type->setIsDefault($nt[2]);
$manager->persist($type);
}
}
$manager->flush();
}
示例4: execute
/**
* This method is executed after initialize(). It usually contains the logic
* to execute to complete this command task.
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$maxResults = $input->getOption('max-results');
// Use ->findBy() instead of ->findAll() to allow result sorting and limiting
$users = $this->entityManager->getRepository('AppBundle:User')->findBy(array(), array('id' => 'DESC'), $maxResults);
// Doctrine query returns an array of objects and we need an array of plain arrays
$usersAsPlainArrays = array_map(function (User $user) {
return array($user->getId(), $user->getUsername(), $user->getEmail(), implode(', ', $user->getRoles()));
}, $users);
// In your console commands you should always use the regular output type,
// which outputs contents directly in the console window. However, this
// particular command uses the BufferedOutput type instead.
// The reason is that the table displaying the list of users can be sent
// via email if the '--send-to' option is provided. Instead of complicating
// things, the BufferedOutput allows to get the command output and store
// it in a variable before displaying it.
$bufferedOutput = new BufferedOutput();
$table = new Table($bufferedOutput);
$table->setHeaders(array('ID', 'Username', 'Email', 'Roles'))->setRows($usersAsPlainArrays);
$table->render();
// instead of displaying the table of users, store it in a variable
$tableContents = $bufferedOutput->fetch();
if (null !== ($email = $input->getOption('send-to'))) {
$this->sendReport($tableContents, $email);
}
$output->writeln($tableContents);
}
示例5: load
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$countries = $manager->getRepository('SehBundle:Country')->findAll();
foreach ($countries as $country) {
$countryBrand = new Country();
$countryBrand->setCountry($country);
$manager->persist($countryBrand);
}
$regions = $manager->getRepository('SehBundle:Region')->findAll();
foreach ($regions as $region) {
$regionBrand = new Region();
$regionBrand->setRegion($region);
$manager->persist($regionBrand);
}
$departments = $manager->getRepository('SehBundle:Department')->findAll();
foreach ($departments as $department) {
$departmentBrand = new Department();
$departmentBrand->setDepartment($department);
$manager->persist($departmentBrand);
}
$thematics = $manager->getRepository('SehBundle:Thematic')->findAll();
foreach ($thematics as $thematic) {
$thematicBrand = new Thematic();
$thematicBrand->setThematic($thematic);
$manager->persist($thematicBrand);
}
$cities = $manager->getRepository('SehBundle:City')->findAll();
foreach ($cities as $city) {
$cityBrand = new City();
$cityBrand->setCity($city);
$manager->persist($cityBrand);
}
$manager->flush();
}
示例6: updateEmailActivityDescription
/**
* Update activity
* @param ObjectManager $manager
*/
public function updateEmailActivityDescription(ObjectManager $manager)
{
/** @var QueryBuilder $activityListBuilder */
$activityListBuilder = $manager->getRepository('OroActivityListBundle:ActivityList')->createQueryBuilder('e');
$iterator = new BufferedQueryResultIterator($activityListBuilder);
$iterator->setBufferSize(self::BATCH_SIZE);
$itemsCount = 0;
$entities = [];
$emailRepository = $manager->getRepository('OroEmailBundle:Email');
$activityProvider = $this->container->get('oro_email.activity_list.provider');
foreach ($iterator as $activity) {
$email = $emailRepository->find($activity->getRelatedActivityId());
if ($email) {
$itemsCount++;
$activity->setDescription($activityProvider->getDescription($email));
$entities[] = $activity;
}
if (0 === $itemsCount % self::BATCH_SIZE) {
$this->saveEntities($manager, $entities);
$entities = [];
}
}
if ($itemsCount % self::BATCH_SIZE > 0) {
$this->saveEntities($manager, $entities);
}
}
示例7: load
public function load(ObjectManager $manager)
{
// Obtener todas las ofertas y usuarios de la base de datos
$offers = $manager->getRepository('TestBundle:Offer')->findAll();
$users = $manager->getRepository('TestBundle:User')->findAll();
foreach ($users as $user) {
$shopping = rand(0, 3);
$bought = array();
for ($i = 0; $i < $shopping; $i++) {
$sale = new Sale();
$sale->setDate(new \DateTime('now - ' . rand(0, 250) . ' hours'));
// Sólo se añade una venta:
// - si este mismo usuario no ha comprado antes la misma oferta
// - si la oferta seleccionada ha sido revisada
// - si la fecha de publicación de la oferta es posterior a ahora mismo
$offer = $offers[array_rand($offers)];
while (in_array($offer->getId(), $bought) || $offer->getChecked() == false || $offer->getPublicationDate() > new \DateTime('now')) {
$offer = $offers[array_rand($offers)];
}
$bought[] = $offer->getId();
$sale->setOffer($offer);
$sale->setUser($user);
$manager->persist($sale);
$offer->setShopping($offer->getShopping() + 1);
$manager->persist($offer);
}
unset($bought);
}
$manager->flush();
}
示例8: __construct
/**
* WishlistManager constructor.
*
* @param ObjectManager $objectManager
* @param string $class
*/
public function __construct(ObjectManager $objectManager, string $class)
{
$this->objectManager = $objectManager;
$this->repository = $this->objectManager->getRepository($class);
$metadata = $objectManager->getClassMetadata($class);
$this->class = $metadata->getName();
}
示例9: load
public function load(ObjectManager $manager)
{
$conn = $manager->getConnection();
$stmt = $conn->prepare('select id from lots');
$stmt->execute();
$lotIds = [];
while ($lotId = $stmt->fetchColumn()) {
$lotIds[] = (int) $lotId;
}
$stmt = $conn->prepare('select id from users');
$stmt->execute();
$usrIds = [];
while ($usrId = $stmt->fetchColumn()) {
$usrIds[] = (int) $usrId;
}
for ($i = 0, $l = count($lotIds) * count($usrIds); $i < $l; $i++) {
$lot = $manager->getRepository('BankrotSiteBundle:Lot')->find($lotIds[array_rand($lotIds)]);
if ($lot->getBeginDate()) {
if (0 === rand(0, 2)) {
$lw = new LotWatch();
$lw->setOwner($manager->getRepository('BankrotSiteBundle:User')->find($usrIds[array_rand($usrIds)]));
$lw->setLot($lot);
$lw->setPrice(rand(0, 1000000));
$lw->setCutOffPrice(rand(10, 5000));
$lw->setDay(new \DateTime('@' . rand($lot->getBeginDate()->getTimestamp(), $lot->getEndDate()->getTimestamp())));
$manager->persist($lw);
}
}
}
$manager->flush();
}
示例10: importProjects
/**
* Import Projects
*/
private function importProjects()
{
$this->output->write(sprintf('%-30s', 'Importing projects'));
$previewProjects = $this->previewService->getProjects();
$created = 0;
$updated = 0;
foreach ($previewProjects as $previewProject) {
/**
* @var Project $project
*/
$project = $this->entityManager->getRepository('ProjectPreviewProjectBundle:Project')->find($previewProject->id);
if (is_null($project)) {
$project = new Project();
$project->setId($previewProject->id);
$created++;
} else {
$updated++;
}
$project->setName($previewProject->name);
$project->setArchived($previewProject->archived);
$this->entityManager->persist($project);
}
$this->output->writeln(sprintf('done (total: % 4d, created: % 4d, updated: % 4d)', $created + $updated, $created, $updated));
$this->entityManager->flush();
}
示例11: process
/**
* Prepare & process form
*
* @author Jeremie Samson <jeremie@ylly.fr>
*
* @return bool
*/
public function process()
{
if ($this->request->isMethod('POST')) {
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
/** @var ModelUserRole $model */
$model = $this->form->getData();
if (!$model->getUser() || !$model->getRole()) {
$this->form->addError(new FormError('Missing parameter(s)'));
}
/** @var User $user */
$user = $this->em->getRepository('UserBundle:User')->find($model->getUser());
/** @var Post $role */
$role = $this->em->getRepository('FaucondorBundle:Post')->find($model->getRole());
if (!$user) {
$this->form->get('user')->addError(new FormError('User with id ' . $model->getUser() . ' not found '));
}
if (!$role) {
$this->form->get('role')->addError(new FormError('Role with id ' . $model->getRole() . ' not found '));
}
$this->onSuccess($user, $role);
return true;
}
}
return false;
}
示例12: initAttachmentEntity
/**
* @param FormEvent $event
*
* @throws FormException
*/
public function initAttachmentEntity(FormEvent $event)
{
/** @var AttachmentModel $attachment */
$attachment = $event->getData();
// this check is necessary due to inability to capture file input dialog cancel event
if (!$attachment) {
return;
}
if (!$attachment->getEmailAttachment()) {
switch ($attachment->getType()) {
case AttachmentModel::TYPE_ATTACHMENT:
$repo = $this->em->getRepository('OroAttachmentBundle:Attachment');
$oroAttachment = $repo->find($attachment->getId());
$emailAttachment = $this->emailAttachmentTransformer->oroToEntity($oroAttachment);
break;
case AttachmentModel::TYPE_EMAIL_ATTACHMENT:
$repo = $this->em->getRepository('OroEmailBundle:EmailAttachment');
$emailAttachment = $repo->find($attachment->getId());
break;
case AttachmentModel::TYPE_UPLOADED:
$emailAttachment = $this->emailAttachmentTransformer->entityFromUploadedFile($attachment->getFile());
break;
default:
throw new FormException(sprintf('Invalid attachment type: %s', $attachment->getType()));
}
$attachment->setEmailAttachment($emailAttachment);
}
$event->setData($attachment);
}
示例13: getData
/**
* @return array
*/
public function getData()
{
/** @var ClientRepository $clientRepository */
$clientRepository = $this->manager->getRepository('CSBillClientBundle:Client');
$clients = $clientRepository->getRecentClients();
return ['clients' => $clients];
}
示例14: getData
/**
* @return array
*/
public function getData()
{
/** @var PaymentRepository $paymentRepository */
$paymentRepository = $this->manager->getRepository('CSBillPaymentBundle:Payment');
$payments = $paymentRepository->getRecentPayments();
return ['payments' => $payments];
}
示例15: getRepository
/**
* @return BaseFaqRepository
*/
public function getRepository()
{
if ($this->repository === null) {
$this->repository = $this->objectManager->getRepository($this->faqClass);
}
return $this->repository;
}