本文整理匯總了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;
}
示例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;
}
示例3: clearCustomerShoppingCarts
public function clearCustomerShoppingCarts()
{
$customer = $this->getCustomer();
$customer->setSessionId(new ArrayCollection());
$this->entityManager->persist($customer);
$this->entityManager->flush();
}
示例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();
}
示例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);
}
示例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;
}
示例7: save
/**
* @param ProviderLocation $providerLocation
* @param bool $withFlush
*/
public function save(ProviderLocation $providerLocation, $withFlush = true)
{
$this->entityManager->persist($providerLocation);
if ($withFlush) {
$this->entityManager->flush();
}
}
示例8: add
/**
* {@inheritdoc}
*/
public function add(TextNodeInterface $textNode, $save = false)
{
$this->em->persist($textNode);
if (true === $save) {
$this->save();
}
}
示例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;
}
示例10: updateAttendee
public function updateAttendee(AttendeeInterface $attendee)
{
$attendee->setUpdatedAt(new \DateTime());
$this->em->persist($attendee);
$this->em->flush();
return true;
}
示例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();
}
示例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);
}
示例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;
}
}
示例14: add
/**
* {@inheritdoc}
*/
public function add(SiteInterface $site, $save = false)
{
$this->em->persist($site);
if (true === $save) {
$this->save();
}
}
示例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();
}