當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityManager::persist方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\EntityManager::persist方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::persist方法的具體用法?PHP EntityManager::persist怎麽用?PHP EntityManager::persist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\EntityManager的用法示例。


在下文中一共展示了EntityManager::persist方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: uploadImages

 /**
  * @param EntityManager $em
  * @param array $imagesArray
  * @param Advertisment $adv
  * @return array
  */
 public static function uploadImages(EntityManager $em, $imagesArray, $adv)
 {
     $dummyImage = '/resources/images/adv-default.png';
     $basePath = 'uploads/' . $adv->getId();
     $uploadedImages = array();
     $adv = $em->getRepository('NaidusvoeBundle:Advertisment')->find($adv->getId());
     $fs = new Filesystem();
     $counter = 1;
     if ($imagesArray) {
         foreach ($imagesArray as $image) {
             $image = (object) $image;
             if ($image->image !== null) {
                 $imagePath = $basePath . '/' . $counter . '.jpg';
                 $image = explode(',', $image->image);
                 $image = base64_decode($image[1]);
                 $fs->dumpFile($imagePath, $image);
                 $attachment = new Attachment();
                 $attachment->setAdvertisment($adv);
                 $attachment->setImage($imagePath);
                 $em->persist($attachment);
                 $uploadedImages[] = $attachment;
                 $counter++;
             }
         }
     }
     if ($counter === 1) {
         $attachment = new Attachment();
         $attachment->setAdvertisment($adv);
         $attachment->setImage($dummyImage);
         $em->persist($attachment);
         $uploadedImages[] = $attachment;
     }
     return $uploadedImages;
 }
開發者ID:riki343,項目名稱:naidusvoe,代碼行數:40,代碼來源:Attachment.php

示例2: createImage

 protected function createImage(LoaderResult $loaderResult, $mimeType) : ImageInterface
 {
     $image = ($image = new Image())->setPath($loaderResult->getPath())->setSize($loaderResult->getSize())->setMimeType($mimeType)->setUploadedAt(new \DateTime());
     $this->em->persist($image);
     $this->em->flush($image);
     return $image;
 }
開發者ID:Youshido,項目名稱:ApiImages,代碼行數:7,代碼來源:ORMProvider.php

示例3: clearCustomerShoppingCarts

 public function clearCustomerShoppingCarts()
 {
     $customer = $this->getCustomer();
     $customer->setSessionId(new ArrayCollection());
     $this->entityManager->persist($customer);
     $this->entityManager->flush();
 }
開發者ID:bamper,項目名稱:symfony2-webstore,代碼行數:7,代碼來源:CustomerModel.php

示例4: schedule

 public function schedule()
 {
     $licenseRepo = $this->em->getRepository('AppBundle:License');
     $drillSchemaEventsRepo = $this->em->getRepository('AppBundle:DrillSchemaEvent');
     $licensesWithoutSchema = $licenseRepo->findWithoutRegisteredSchema();
     foreach ($licensesWithoutSchema as $license) {
         $drillSchemaEvents = $drillSchemaEventsRepo->findByAddonKey($license->getAddonKey());
         if (empty($drillSchemaEvents)) {
             continue;
         }
         $drillRegisteredSchema = new DrillRegisteredSchema();
         $drillRegisteredSchema->setLicenseId($license->getLicenseId());
         $drillRegisteredSchema->setAddonKey($license->getAddonKey());
         $this->em->persist($drillRegisteredSchema);
         foreach ($drillSchemaEvents as $drillSchemaEvent) {
             $sendDate = $this->calculateSendDate($drillSchemaEvent, $license);
             $today = new \DateTime();
             // prevent creating events from past
             if ($sendDate < $today->modify('-2 days')) {
                 continue;
             }
             $drillRegisteredEvent = new DrillRegisteredEvent();
             $drillRegisteredEvent->setDrillRegisteredSchema($drillRegisteredSchema);
             $drillRegisteredEvent->setDrillSchemaEvent($drillSchemaEvent);
             // Calculate
             $drillRegisteredEvent->setSendDate($sendDate);
             $drillRegisteredEvent->setStatus('new');
             $this->em->persist($drillRegisteredEvent);
         }
     }
     $this->em->flush();
 }
開發者ID:rachetfoot,項目名稱:atlassian-vendor-tools,代碼行數:32,代碼來源:Scheduler.php

示例5: importUnits

 /**
  * Imports units.
  *
  * @return array An array with the keys "skipped" and "imported" which contain the number of units skipped and imported
  * @throws \Exception If an error occured
  */
 public function importUnits()
 {
     $path = $this->kernel->locateResource(self::UNIT_PATH . self::UNIT_DATA);
     $yaml = new Parser();
     $data = $yaml->parse(file_get_contents($path));
     $count = 0;
     $skipped = 0;
     foreach ($data as $unitName => $unitData) {
         $unit = $this->getUnit($unitName);
         if ($unit === null) {
             $unit = new Unit();
             $unit->setName($unitName);
             $unit->setSymbol($unitData["symbol"]);
             if (array_key_exists("prefixes", $unitData)) {
                 if (!is_array($unitData["prefixes"])) {
                     throw new \Exception($unitName . " doesn't contain a prefix list, or the prefix list is not an array.");
                 }
                 foreach ($unitData["prefixes"] as $name) {
                     $prefix = $this->getSiPrefix($name);
                     if ($prefix === null) {
                         throw new \Exception("Unable to find SI Prefix " . $name);
                     }
                     $unit->getPrefixes()->add($prefix);
                 }
             }
             $this->entityManager->persist($unit);
             $this->entityManager->flush();
             $count++;
         } else {
             $skipped++;
         }
     }
     return array("imported" => $count, "skipped" => $skipped);
 }
開發者ID:hephaestus9,項目名稱:PartKeepr,代碼行數:40,代碼來源:UnitSetupService.php

示例6: createWidgetState

 /**
  * @param Widget $widget
  * @param User $user
  * @return WidgetState
  */
 protected function createWidgetState(Widget $widget, User $user)
 {
     $state = new WidgetState();
     $state->setOwner($user)->setWidget($widget);
     $this->entityManager->persist($state);
     return $state;
 }
開發者ID:ramunasd,項目名稱:platform,代碼行數:12,代碼來源:StateManager.php

示例7: save

 /**
  * @param ProviderLocation $providerLocation
  * @param bool             $withFlush
  */
 public function save(ProviderLocation $providerLocation, $withFlush = true)
 {
     $this->entityManager->persist($providerLocation);
     if ($withFlush) {
         $this->entityManager->flush();
     }
 }
開發者ID:Appartin,項目名稱:CoreBundle,代碼行數:11,代碼來源:ProviderLocationManager.php

示例8: add

 /**
  * {@inheritdoc}
  */
 public function add(TextNodeInterface $textNode, $save = false)
 {
     $this->em->persist($textNode);
     if (true === $save) {
         $this->save();
     }
 }
開發者ID:silvestra,項目名稱:silvestra,代碼行數:10,代碼來源:TextNodeManager.php

示例9: onResponse

 /**
  * Process onReslonse event, updates user history information
  *
  * @param  FilterResponseEvent $event
  * @return bool|void
  */
 public function onResponse(FilterResponseEvent $event)
 {
     if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
         // Do not do anything
         return;
     }
     $request = $event->getRequest();
     $response = $event->getResponse();
     // do not process requests other than in html format
     // with 200 OK status using GET method and not _internal and _wdt
     if (!$this->matchRequest($response, $request)) {
         return false;
     }
     $postArray = ['url' => $request->getRequestUri(), 'user' => $this->user];
     /** @var $historyItem  NavigationHistoryItem */
     $historyItem = $this->em->getRepository('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationHistoryItem')->findOneBy($postArray);
     if (!$historyItem) {
         /** @var $historyItem \Oro\Bundle\NavigationBundle\Entity\NavigationItemInterface */
         $historyItem = $this->navItemFactory->createItem(NavigationHistoryItem::NAVIGATION_HISTORY_ITEM_TYPE, $postArray);
     }
     $historyItem->setTitle($this->titleService->getSerialized());
     // force update
     $historyItem->doUpdate();
     $this->em->persist($historyItem);
     $this->em->flush($historyItem);
     return true;
 }
開發者ID:abdeldayem,項目名稱:pim-community-dev,代碼行數:33,代碼來源:ResponseHistoryListener.php

示例10: updateAttendee

 public function updateAttendee(AttendeeInterface $attendee)
 {
     $attendee->setUpdatedAt(new \DateTime());
     $this->em->persist($attendee);
     $this->em->flush();
     return true;
 }
開發者ID:pguso,項目名稱:CalendarBundle,代碼行數:7,代碼來源:AttendeeManager.php

示例11: duplicate

 /**
  * Duplicate Jam entities
  *
  * For details see
  * {@link http://stackoverflow.com/questions/9071094/how-to-re-save-the-entity-as-another-row-in-doctrine-2}
  *
  * @param Jam $entity
  * @param integer $count
  */
 public function duplicate(Jam $entity, $count = 0)
 {
     for ($i = 0; $i < $count; $i++) {
         $this->em->persist($this->cloneService->cloneObject($entity));
     }
     $this->em->flush();
 }
開發者ID:e-moe,項目名稱:sonata,代碼行數:16,代碼來源:JamService.php

示例12: create

 public function create($data)
 {
     $person = new Person($data->first_name, $data->last_name);
     if (isset($data->middle_name)) {
         $person->setMiddleName($data->middle_name);
     }
     if (isset($data->display_name)) {
         $person->setDisplayName($data->display_name);
     }
     $account = new Account($person);
     switch ($data->status) {
         case 'active':
             $account->setStatus(AccountInterface::STATUS_ACTIVE);
             break;
         case 'inactive':
             $account->setStatus(AccountInterface::STATUS_INACTIVE);
             break;
         default:
             throw new RuntimeException('Invalid account status provided.');
     }
     $this->entityManager->persist($person);
     $this->entityManager->persist($account);
     $this->entityManager->flush($account);
     return new AccountEntity($account);
 }
開發者ID:zource,項目名稱:zource,代碼行數:25,代碼來源:AccountResource.php

示例13: postFlush

 /**
  * @param PostFlushEventArgs $args
  */
 public function postFlush(PostFlushEventArgs $args)
 {
     if ($this->isInProgress) {
         return;
     }
     $this->initializeFromEventArgs($args);
     if (count($this->queued) > 0) {
         $toOutDate = [];
         foreach ($this->queued as $customerIdentity => $groupedByEntityUpdates) {
             foreach ($groupedByEntityUpdates as $data) {
                 /** @var Account $account */
                 $account = is_object($data['account']) ? $data['account'] : $this->em->getReference('OroCRMAccountBundle:Account', $data['account']);
                 /** @var Channel $channel */
                 $channel = is_object($data['channel']) ? $data['channel'] : $this->em->getReference('OroCRMChannelBundle:Channel', $data['channel']);
                 $entity = $this->createHistoryEntry($customerIdentity, $account, $channel);
                 $toOutDate[] = [$account, $channel, $entity];
                 $this->em->persist($entity);
             }
         }
         $this->isInProgress = true;
         $this->em->flush();
         foreach (array_chunk($toOutDate, self::MAX_UPDATE_CHUNK_SIZE) as $chunks) {
             $this->lifetimeRepo->massStatusUpdate($chunks);
         }
         $this->queued = [];
         $this->isInProgress = false;
     }
 }
開發者ID:hugeval,項目名稱:crm,代碼行數:31,代碼來源:ChannelDoctrineListener.php

示例14: add

 /**
  * {@inheritdoc}
  */
 public function add(SiteInterface $site, $save = false)
 {
     $this->em->persist($site);
     if (true === $save) {
         $this->save();
     }
 }
開發者ID:silvestra,項目名稱:silvestra,代碼行數:10,代碼來源:SiteManager.php

示例15: makeSureMenusExist

 /**
  * Make sure the menu objects exist in the database for each locale.
  */
 public function makeSureMenusExist()
 {
     $locales = array_unique($this->getLocales());
     $required = array();
     foreach ($this->menuNames as $name) {
         $required[$name] = $locales;
     }
     $menuObjects = $this->em->getRepository('KunstmaanMenuBundle:Menu')->findAll();
     foreach ($menuObjects as $menu) {
         if (array_key_exists($menu->getName(), $required)) {
             $index = array_search($menu->getLocale(), $required[$menu->getName()]);
             if ($index !== false) {
                 unset($required[$menu->getName()][$index]);
             }
         }
     }
     foreach ($required as $name => $locales) {
         foreach ($locales as $locale) {
             $menu = new Menu();
             $menu->setName($name);
             $menu->setLocale($locale);
             $this->em->persist($menu);
         }
     }
     $this->em->flush();
 }
開發者ID:hyrmedia,項目名稱:KunstmaanBundlesCMS,代碼行數:29,代碼來源:MenuService.php


注:本文中的Doctrine\ORM\EntityManager::persist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。