Author: Filip Procházka (filip@prochazka.su)
Inheritance: extends Doctrine\ORM\EntityManager, implements Kdyby\Persistence\QueryExecutor, implements Kdyby\Persistence\Queryable
示例#1
0
 /**
  * Check object status is enity
  *
  * @param object|string $entity
  * @return bool
  */
 protected function isEntity($entity)
 {
     if (is_object($entity)) {
         $entity = ClassUtils::getClass($entity);
     }
     return !$this->entityManager->getMetadataFactory()->isTransient($entity);
 }
示例#2
0
 public function renderDefault()
 {
     $this->template->anyVariable = 'any value';
     //		$dao = $this->articles;
     $this->template->articles = $this->articles->getArticles()->findAll();
     $posts = $this->EntityManager->getRepository(Posts::getClassName());
     $this->template->posts = $posts->findAll();
     $this->template->myparametr = $this->context->parameters['first_parametr'];
     //		$this->template->test = $this->doSomeRefactoring('Hello world from blog');
     //		$post = new Posts();
     //		$post->title = 'New title';
     //		$post->text = 'New text New textNew text';
     //		$post->created_at = new \Nette\Utils\DateTime;
     //
     //
     //		$this->EntityManager->persist($post);
     //		$this->EntityManager->flush();
     //		$dao = $this->EntityManager->getRepository(Posts::getClassName());
     //		$dao->setTitle('test');
     //		$dao->__call('set', ['title' => 'my title']);
     //		dump($dao->__isset('title'));
     //		$dao->__set('title', 'test');
     try {
         $this->checkNum(2);
         \Tracy\Debugger::barDump('If you see this, the number is 1 or below');
     } catch (Nette\Application\BadRequestException $e) {
         Debugger::log('Message: ' . $e->getMessage());
         var_dump($e->getMessage());
     }
     //		finally {
     //			\Tracy\Debugger::barDump('Got here Finally');
     //		}
 }
示例#3
0
文件: LogFacade.php 项目: blitzik/CMS
 public function findEventsByType($logTypeID)
 {
     return $this->cache->load('logEvents-' . $logTypeID, function (&$dependencies) use($logTypeID) {
         return array_column($this->em->createQuery('SELECT e.id, e.name FROM ' . EventLog::class . ' e INDEX BY e.id
              WHERE e.logType = :typeID')->setParameter('typeID', $logTypeID)->getArrayResult(), 'name', 'id');
     });
 }
 public function __construct(EntityManager $em)
 {
     $this->em = $em;
     $this->streetRepository = $em->getRepository(Street::class);
     $this->partCityRepository = $em->getRepository(PartCity::class);
     $this->cityRepository = $em->getRepository(City::class);
 }
 /**
  * @param User $user
  * @param array $albums
  */
 public function assignAlbums(User $user, array $albums)
 {
     $user->albums->clear();
     $user->setAlbums($albums);
     $this->em->persist($user);
     $this->em->flush();
 }
示例#6
0
 public function __construct(EntityManager $entityManager, IAdminGridFactory $adminGridFactory, ITranslator $translator, RegistrationFormService $registrationFormService)
 {
     $this->registrationRepository = $entityManager->getRepository(Registration::class);
     $this->adminGridFactory = $adminGridFactory;
     $this->translator = $translator;
     $this->registrationFormService = $registrationFormService;
 }
 public function initialize(IIdentity $identity)
 {
     if ($identity instanceof EntityIdentity && !$identity->isLoaded()) {
         $identity->load($this->em->getDao($identity->getEntityClass()));
     }
     return $identity;
 }
示例#8
0
 protected function createComponentGrid($name)
 {
     $grid = new Grid($this, $name);
     $repository = $this->database->getRepository('App\\Models\\Doctrine\\Entities\\User');
     $model = new \Grido\DataSources\Doctrine($repository->createQueryBuilder('a')->addSelect('c')->innerJoin('a.country', 'c'), array('country' => 'c.title'));
     // Map country column to the title of the Country entity
     $grid->model = $model;
     $grid->addColumnText('firstname', 'Firstname')->setFilterText()->setSuggestion();
     $grid->addColumnText('surname', 'Surname')->setSortable()->setFilterText()->setSuggestion();
     $grid->addColumnText('gender', 'Gender')->setSortable()->cellPrototype->class[] = 'center';
     $grid->addColumnDate('birthday', 'Birthday', \Grido\Components\Columns\Date::FORMAT_TEXT)->setSortable()->setFilterDate()->setCondition($grid->birthdayFilterCondition);
     $grid->getColumn('birthday')->cellPrototype->class[] = 'center';
     $grid->addColumnText('country', 'Country')->setSortable()->setCustomRender(function ($item) {
         $baseUri = $this->getBaseUri();
         $img = Html::el('img')->src("{$baseUri}/img/flags/{$item->country_code}.gif");
         return "{$img} {$item->country}";
     })->setFilterText()->setSuggestion();
     $grid->addColumnText('card', 'Card')->setSortable()->setColumn('cctype')->setReplacement(array('MasterCard' => Html::el('b')->setText('MasterCard')))->cellPrototype->class[] = 'center';
     $grid->addColumnEmail('emailaddress', 'Email')->setSortable()->setFilterText();
     $grid->getColumn('emailaddress')->cellPrototype->class[] = 'center';
     $grid->addColumnText('centimeters', 'Height')->setSortable()->setFilterNumber();
     $grid->getColumn('centimeters')->cellPrototype->class[] = 'center';
     $grid->addFilterSelect('gender', 'Gender', array('' => '', 'female' => 'female', 'male' => 'male'));
     $grid->addFilterSelect('card', 'Card', array('' => '', 'MasterCard' => 'MasterCard', 'Visa' => 'Visa'))->setColumn('cctype');
     $grid->addFilterCheck('preferred', 'Only preferred girls :)')->setCondition(array(TRUE => array(array('gender', 'AND', 'centimeters'), array('= ?', '>= ?'), array('female', 170))));
     $grid->addActionHref('edit', 'Edit')->setIcon('pencil');
     $grid->addActionHref('delete', 'Delete')->setIcon('trash')->setConfirm(function ($item) {
         return "Are you sure you want to delete {$item->firstname} {$item->surname}?";
     });
     $operation = array('print' => 'Print', 'delete' => 'Delete');
     $grid->setOperation($operation, $this->handleOperations)->setConfirm('delete', 'Are you sure you want to delete %i items?');
     $grid->filterRenderType = $this->filterRenderType;
     $grid->setExport();
 }
 /**
  * @param EntityManager $entityManager
  * @param Client $elastic
  */
 public function __construct(EntityManager $entityManager, Client $elastic)
 {
     parent::__construct();
     $this->entityManager = $entityManager;
     $this->elastic = $elastic;
     $this->seasonsRepository = $entityManager->getRepository(Season::class);
     $this->languagesRepository = $entityManager->getRepository(Language::class);
 }
示例#10
0
文件: TagFacade.php 项目: blitzik/CMS
 public function __construct(EntityManager $entityManager, TagPersister $tagPersister, TagRemover $tagRemover, Logger $logger)
 {
     $this->em = $entityManager;
     $this->tagPersister = $tagPersister;
     $this->logger = $logger->channel('Tags');
     $this->tagRepository = $this->em->getRepository(Tag::class);
     $this->tagRemover = $tagRemover;
 }
示例#11
0
 /**
  * @param Privilege $privilege
  * @param Role $role
  * @return $this
  */
 public function addDefinition(Privilege $privilege, Role $role)
 {
     $accessDefinition = new AccessDefinition($this->resource, $privilege);
     $this->em->persist($accessDefinition);
     $permission = new Permission($role, $this->resource, $privilege);
     $this->em->persist($permission);
     return $this;
 }
 private function getLastPosition(EntityManager $em)
 {
     $last = $em->getRepository(get_class($this))->findOneBy([], ["position" => "DESC"]);
     if ($last) {
         return $last->getPosition();
     }
     return 0;
 }
示例#13
0
 public function __construct(ImagesUploader $imagesUploader, ImagesRemover $imagesRemover, EntityManager $entityManager, Logger $logger)
 {
     $this->imagesUploader = $imagesUploader;
     $this->imagesRemover = $imagesRemover;
     $this->em = $entityManager;
     $this->logger = $logger->channel('images');
     $this->imageRepository = $this->em->getRepository(Image::class);
 }
示例#14
0
 /**
  * @param $entity1
  * @param $entity2
  */
 private function switchEntities($entity1, $entity2)
 {
     $x = $entity1->priority;
     $entity1->priority = $entity2->priority;
     $entity2->priority = $x;
     $this->entityManager->persist($entity1, $entity2);
     $this->entityManager->flush();
 }
示例#15
0
 private function createBasicQuery(Kdyby\Doctrine\EntityManager $entityManager)
 {
     $qb = $entityManager->createQueryBuilder();
     $qb->from(Comment::class, 'c');
     foreach ($this->filter as $modifier) {
         $modifier($qb);
     }
     return $qb;
 }
示例#16
0
 private function logDb($message, $status = NULL, $consumerTitle = NULL)
 {
     $log = new RmqLogConsumer();
     $log->consumerTitle = $consumerTitle;
     $log->message = $message;
     $log->status = $status;
     $this->em->persist($log);
     $this->em->flush();
 }
 /**
  * @param string
  * @return bool
  */
 private function isEntity($className)
 {
     try {
         $this->em->getClassMetadata($className);
         return TRUE;
     } catch (Doctrine\Common\Persistence\Mapping\MappingException $e) {
         return FALSE;
     }
 }
示例#18
0
 /**
  * @param Listing $listing
  * @throws \Exception
  */
 public function removeListing(Listing $listing)
 {
     try {
         $this->em->remove($listing)->flush();
     } catch (\Exception $e) {
         $this->onCritical(sprintf('Removal of Listing #id(%s) failed. [%s]', $listing->getId(), 'removeListing'), $e, self::class);
         throw $e;
     }
 }
示例#19
0
 public function __construct(\Kdyby\Doctrine\EntityManager $entityManager)
 {
     if (!$this->table_name) {
         throw new \Exception('Variable $db_nam must be filled!');
     }
     $this->em = $entityManager;
     $entits = new $this->table_name();
     $this->entit = $this->em->getRepository($entits);
 }
 public function addGenre(string $name)
 {
     if ($this->genreExists($name)) {
         return;
     }
     $genre = new Genre($name);
     $this->entityManager->persist($genre);
     $this->entityManager->flush($genre);
 }
示例#21
0
 /**
  * Executes the current command.
  *
  * This method is not abstract because you can use this class
  * as a concrete class. In this case, instead of defining the
  * execute() method, you set the code to execute by passing
  * a Closure to the setCode() method.
  *
  * @param InputInterface $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|int null or 0 if everything went fine, or an error code
  *
  * @throws LogicException When this abstract method is not implemented
  *
  * @see setCode()
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var QuestionHelper $helper */
     $helper = $this->getHelper('question');
     do {
         if (!isset($username)) {
             $username = $this->askUsername($helper, $input, $output);
         }
         if (!isset($password)) {
             $password = $this->askPassword($helper, $input, $output);
         }
         if (!isset($email)) {
             $email = $this->askEmail($helper, $input, $output);
         }
         $output->writeln(sprintf('Summary:
                 username: %s
                 password: %s
                 E-mail: %s', $username, $password, $email));
         // CONFIRMATION
         $question = new ConfirmationQuestion('Do you want to create this new User? ', true);
         if (!$helper->ask($input, $output, $question)) {
             $output->writeln('New user insertion has been CANCELED!');
             return;
         }
         try {
             $user = new User($username, $email, $password);
             $new_user = $this->em->safePersist($user);
             if ($new_user === false) {
                 $uname = $this->userRepository->findOneBy(['username' => $username]);
                 if ($uname !== null) {
                     $output->writeln(sprintf('User with username "%s" already exists', $username));
                     $username = null;
                 }
                 $umail = $this->userRepository->findOneBy(['email' => $email]);
                 if ($umail !== null) {
                     $output->writeln(sprintf('User with email "%s" already exists', $email));
                     $email = null;
                 }
                 unset($user);
                 continue;
             }
             $output->writeln('Your new User has been SUCCESSFULLY created!');
             $continue = new ConfirmationQuestion('Would you like to create another one?', true);
             if ($helper->ask($input, $output, $continue)) {
                 $username = null;
                 $password = null;
                 $email = null;
                 continue;
             }
             return 0;
         } catch (\Exception $e) {
             $output->writeLn("That's bad. An Error occurred: <error>{$e->getMessage()}</error>");
             return 1;
         }
     } while (true);
 }
示例#22
0
 /**
  * @param User $user
  * @return User
  * @throws \Exception
  */
 public function saveUser(User $user)
 {
     try {
         $this->em->persist($user)->flush();
         return $user;
     } catch (\Exception $e) {
         $this->onError(sprintf('Saving of user "%s" #id(%s) failed', $user->username, $user->getId()), $e, self::class);
         throw $e;
     }
 }
示例#23
0
 public function findAllLocales()
 {
     return $this->cache->load('locales', function () {
         $locales = $this->em->createQuery('SELECT l FROM ' . Locale::class . ' l INDEX BY l.name')->getArrayResult();
         if (empty($locales)) {
             return [];
         }
         return $locales;
     });
 }
示例#24
0
 public function delete($value)
 {
     // formating hours on date
     $date = new \DateTime(strtotime(time()));
     $date = $date->modify('-' . $value . 'hours')->format('Y-m-d H:i:s');
     // deleting rows by doctrine with cascade delete entity settings in db schema
     $qb = $this->em->createQueryBuilder();
     $q = $qb->delete(Search::getClassName(), 's')->where($qb->expr()->lt('s.date', '?1'))->setParameter(1, $date)->getQuery();
     return $numberDeleted = $q->getResult();
 }
示例#25
0
 public function emailFormSucceeded(Form $form, $values)
 {
     $settings = $this->EntityManager->getRepository(Settings::getClassName());
     $setting = $settings->find(1);
     $mail = new Message();
     $mail->setFrom($values['email'])->addTo($setting->admin_email)->setSubject('Zpráva z webu PeTr - ' . $values['subject'])->setBody('Zpráva od ' . $values['name'] . '<br /><br />' . $values['message']);
     $mailer = new SendmailMailer();
     //$mailer->send($mail);
     $this->redirect('Contact:sent');
 }
示例#26
0
 /**
  * @param string $searchString
  * @return Search
  */
 public function saveSearch($searchString)
 {
     if ($search = $this->search(Strings::webalize($searchString))) {
         return $search;
     }
     $search = new Search($searchString);
     $this->entityManager->persist($search);
     $this->entityManager->flush($search);
     return $search;
 }
示例#27
0
 /**
  * Odstraneni konkretniho tagu
  * @param \App\Model\Entities\Tag $tag
  * @return boolean
  */
 public function deleteTag(Entities\Tag $tag)
 {
     try {
         $this->em->remove($tag);
         $result = $this->em->flush();
     } catch (\Doctrine\ORM\ORMException $e) {
         Debugger::log($e, Debugger::INFO);
         $result = FALSE;
     }
     return $result;
 }
示例#28
0
 /**
  * Save entity into DB
  *
  * @param BaseEntity $baseEntity
  * @return BaseEntity
  * @throws \Exception
  */
 protected function saveEntity(BaseEntity $baseEntity)
 {
     $isPersisted = UnitOfWork::STATE_MANAGED === $this->entityManager->getUnitOfWork()->getEntityState($baseEntity);
     if ($isPersisted) {
         $this->entityManager->merge($baseEntity);
     } else {
         $this->entityManager->persist($baseEntity);
     }
     $this->entityManager->flush();
     return $baseEntity;
 }
示例#29
0
 /**
  * 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;
 }
示例#30
0
 /**
  * @param Role $role
  * @throws ForeignKeyConstraintViolationException
  */
 public function remove(Role $role)
 {
     try {
         $roleID = $role->getId();
         $this->em->remove($role);
         $this->em->flush();
         $this->onSuccessRoleRemoval($role, $roleID);
     } catch (ForeignKeyConstraintViolationException $e) {
         throw $e;
     }
 }