本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::getReference方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::getReference方法的具体用法?PHP EntityManager::getReference怎么用?PHP EntityManager::getReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kdyby\Doctrine\EntityManager
的用法示例。
在下文中一共展示了EntityManager::getReference方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIdentity
/**
* Returns current user identity, if any.
* @return IIdentity|NULL
*/
public function getIdentity()
{
$identity = parent::getIdentity();
// if we have our fake identity, we now want to
// convert it back into the real entity
// returning reference provides potentially lazy behavior
if ($identity instanceof FakeIdentity) {
return $this->entityManager->getReference($identity->getClass(), $identity->getId());
}
return $identity;
}
示例2: processPoll
/**
* @param Vote $vote
* @param array $requestInfo
* @param \Nette\Utils\ArrayHash $values
* @return boolean Ulozeni hlasovani
*/
protected function processPoll($vote, $requestInfo, $values)
{
$voter_id = \App\Model\Entities\Poll::generateVoteIdentificator();
$answers = $this->parsePoll($values);
foreach ($answers as $key => $value) {
if ($key != 'text') {
$myOption = $this->em->getReference(\App\Model\Entities\Option::class, $key);
} else {
$myOption = NULL;
}
$myNewPoll = new \App\Model\Entities\Poll($myOption, $value);
$myNewPoll->setVoterIdentification($voter_id);
$myNewPoll->setIp($requestInfo['ip']);
$myNewPoll->setAgent($requestInfo['agent']);
$myNewPoll->setCookie($requestInfo['cookie']);
$vote->addPoll($myNewPoll);
}
try {
$this->em->flush();
$result = TRUE;
} catch (\Exception $e) {
\Tracy\Debugger::log($e, \Tracy\Debugger::INFO);
$result = FALSE;
}
return $result;
}
示例3: addTags2Page
/**
* @param array $tags
* @param Page $page
*/
private function addTags2Page(array $tags, Page $page)
{
foreach ($tags as $tagId) {
/** @var Tag $tag */
$tag = $this->em->getReference(Tag::class, $tagId);
$page->addTag($tag);
}
}
示例4: restartJob
/**
* @throws TerminateException
*/
protected function restartJob(array $request, \Exception $exception = null, $message = null) : int
{
$this->logger->addError(sprintf('job requeue(%s) for order %d because of %s: %s', $request['retryCounter'], $request['orderId'], get_class($exception), $message ?: $exception->getMessage()));
$this->append($this->em->getReference(Order::class, $request['orderId']), $request['retryCounter'] + 1, $request['options']);
if (!$this->em->isOpen()) {
sleep(self::DELAY_ON_RESTART);
throw TerminateException::withResponse(self::MSG_REJECT);
}
return self::MSG_REJECT;
}
示例5: saveLog
/**
* @param string $message
* @param string $event
* @param int|null $userID
* @throws \Exception
*/
public function saveLog($message, $event, $userID = null)
{
$eventLog = $this->getEventLog($event);
if ($eventLog === null) {
return;
// todo monolog log
}
if (!$this->isEventLoggable($eventLog)) {
return;
}
try {
$user = null;
if (isset($userID)) {
$user = $this->em->getReference(User::class, $userID);
}
$newLog = new Log($message, $this->em->getReference(EventLog::class, $eventLog->getId()), $this->request->getRemoteAddress(), $user);
$this->em->persist($newLog)->flush();
} catch (ForeignKeyConstraintViolationException $e) {
// todo if user doesn't exist
$this->cache->remove(self::getEventLogCacheKey($event));
}
}
示例6: editArticle
/**
* @param Nette\Utils\ArrayHash $values Hodnoty z formulare
* @return boolean Editace provedena uspesne?
*/
protected function editArticle($values)
{
$result = TRUE;
try {
/** @var \App\Model\Entities\Article $editArticle */
$editArticle = $this->repository->getById($values->id);
if (!$editArticle) {
return FALSE;
}
// nastaveni atributu
$editArticle->setPublished($values->published);
$editArticle->setTitle($values->title);
$editArticle->setUpdateDate();
$editArticle->setPublishDate($values->publishDate);
$editArticle->setDescription($values->description);
$editArticle->setContent($values->content);
$tags = [];
foreach ($values->tags as $tagId) {
$tag = $this->em->getReference(\App\Model\Entities\Tag::class, $tagId);
$tags[$tagId] = $tag;
}
$editArticle->setTags($tags);
if ($values->image->isImage()) {
$this->imageStorage->setArticleImage($editArticle, $values->image->toImage(), $values->imageSource);
} elseif (!empty($values->imageSource)) {
$editImage = $editArticle->getImage();
if ($editImage !== NULL) {
$editImage->source = $values->imageSource;
}
}
//ulozeni zmeny
$this->em->flush();
} catch (\Exception $e) {
\Tracy\Debugger::log($e, \Tracy\Debugger::INFO);
$result = FALSE;
}
return $result;
}
示例7: editVote
/**
* @param Nette\Utils\ArrayHash $values Hodnoty z formulare
* @return boolean Editace provedena uspesne?
*/
protected function editVote($values)
{
$result = TRUE;
try {
/** @var \App\Model\Entities\Vote $editVote */
$editVote = $this->repository->getById($values->id);
if (!$editVote) {
return FALSE;
}
// nastaveni atributu
$editVote->setQuestion($values->question);
$editVote->setExpire($values->expiration);
if ($editVote->getTypeVote()->getId() !== $values->type) {
$typeVote = $this->em->getReference(\App\Model\Entities\TypeVote::class, $values->id);
$editVote->setTypeVote($typeVote);
}
$options = [];
foreach ($values->options as $option) {
if (empty($option->option)) {
continue;
}
$options[] = $option->option;
}
$result = $editVote->setOptions($options);
foreach ($result['remove'] as $removeOption) {
if ($removeOption === NULL) {
continue;
}
$this->em->remove($removeOption);
}
//ulozeni zmeny
$this->em->flush();
} catch (\Exception $e) {
\Tracy\Debugger::log($e, \Tracy\Debugger::INFO);
$result = FALSE;
}
return $result;
}