/** * 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; }
/** * @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; }
/** * @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); } }
/** * @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; }
/** * @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)); } }
/** * @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; }
/** * @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; }