/**
  * @param int $id
  *
  * @return Entity
  *
  * @throws \Exception
  */
 public function showEntityNameAction($id)
 {
     if ($entity = $this->entityRepository->find($id)) {
         return $entity->getName();
     }
     throw new \Exception();
 }
Пример #2
0
 /**
  * Finds all votes belonging to a comment.
  *
  * @param  \FOS\CommentBundle\Model\VotableCommentInterface $comment
  * @return array|null
  */
 public function findVotesByComment(VotableCommentInterface $comment)
 {
     $qb = $this->repository->createQueryBuilder('v');
     $qb->join('v.comment', 'c');
     $qb->andWhere('c.id = :commentId');
     $qb->setParameter('commentId', $comment->getId());
     $votes = $qb->getQuery()->execute();
     return $votes;
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function findInvoiceItemsByInvoiceId($invoiceId)
 {
     $qb = $this->repository->createQueryBuilder('a');
     $qb->join('a.invoice', 't')->where('t.id = :invoiceId')->setParameter('invoiceId', $invoiceId);
     $invoiceiItems = $qb->getQuery()->execute();
     if (!$invoiceiItems) {
         return array();
     }
     return $invoiceiItems;
 }
 /**
  * Sets the repository request default locale
  *
  * @param ContainerInterface|null $container
  * 
  * @throws \InvalidArgumentException if repository is not an instance of TranslatableRepository
  */
 public function setRepositoryLocale($container)
 {
     if (null !== $container) {
         if (!$this->repository instanceof TranslatableRepository) {
             throw new \InvalidArgumentException('A TranslatableManager needs to be linked with a TranslatableRepository to sets default locale.');
         }
         if ($container->isScopeActive('request')) {
             $locale = $container->get('request')->getLocale();
             $this->repository->setDefaultLocale($locale);
         }
     }
 }
Пример #5
0
 public function processRepositoryLocale()
 {
     if (null !== $this->container) {
         if (!$this->repository instanceof \SKCMS\CoreBundle\Repository\TranslatableRepository) {
             dump($this->repository);
             die;
             throw new \InvalidArgumentException('A TranslatableManager needs to be linked with a TranslatableRepository to sets default locale.');
         }
         if ($this->container->isScopeActive('request')) {
             //                die('locale'. $this->container->get('request')->getLocale());
             $locale = $this->container->get('request')->getLocale();
             $this->repository->setDefaultLocale($locale);
         }
     }
 }
Пример #6
0
 /**
  * Lädt ein Bild aus der Datenbank
  * 
  * @params $input
  * 
  * @param int    $input die ID des Entities
  * @param string $input der gespeicherte sourcePath des Entities (muss / oder \ enthalten)
  * @param string $input der sha1 hash der Bildinformationen des OriginalBildes
  * @return Psc\Image\Image
  * @throws Psc\Image\NotFoundException
  */
 public function load($input)
 {
     try {
         if (is_numeric($input)) {
             $image = $this->imageRep->hydrate((int) $input);
         } elseif (is_string($input) && (mb_strpos($input, '/') !== FALSE || mb_strpos($input, '\\') !== FALSE)) {
             $image = $this->imageRep->hydrateBy(array('sourcePath' => (string) $input));
         } elseif (is_string($input)) {
             // hash
             $image = $this->imageRep->hydrateBy(array('hash' => (string) $input));
         } elseif ($input instanceof Image) {
             $image = $input;
         } elseif ($input instanceof ImagineImage) {
             throw new \Psc\Exception('von einer ImagineResource kann kein Bild geladen werden');
         } else {
             throw new \Psc\Exception('Input kann nicht analyisiert werden: ' . Code::varInfo($input));
         }
         $this->attach($image);
         return $image;
     } catch (\Psc\Doctrine\EntityNotFoundException $e) {
         $e = new NotFoundException('Image nicht gefunden: ' . Code::varInfo($input), 1, $e);
         $e->searchCriteria = $input;
         throw $e;
     }
 }
Пример #7
0
 private function resolveTable($arg)
 {
     if ($arg == '#') {
         $path = array('base');
     } else {
         $path = explode('.', trim($arg, '.#'));
         array_unshift($path, "base");
     }
     foreach ($path as $index => $item) {
         if ($item == 'base') {
             $metadata = $this->repository->getMetadata();
             $table = $metadata->getTable();
             $tableAs = 'base';
             if (!$this->getTableAs($tableAs)) {
                 $this->setTableAs($tableAs, $table, $metadata);
             }
         } else {
             //	tabulka
             $association = $metadata->getAssociation($item);
             $associationClassName = $association->getReferenceClass();
             $associationMetadata = $this->repository->getEntityManager()->getRepository($associationClassName)->getMetadata();
             $parentTable = $table;
             $parentTableAs = $tableAs;
             $table = $associationMetadata->getTable();
             $tableAs = $tableAs . self::ALIAS_SEPARATOR . $item;
             //	Nevytvaret novy stejny join. Jen, pokud je jina vazba, nebo jiny nazev.
             if (!$this->getTableAs($tableAs)) {
                 $this->setTableAs($tableAs, $table, $metadata, $parentTableAs, $association);
             }
         }
     }
     return $tableAs;
 }
Пример #8
0
 /**
  * 
  * @param type $pk
  * @return item|null
  */
 public function pk($pk)
 {
     $pkName = $this->repository->getMetadata()->getPrimaryColumn();
     foreach ($this as $item) {
         if ($item->{$pkName} == $pk) {
             return $item;
         }
     }
     return NULL;
 }
 /**
  * Filter a product (return null if the product got exported after his last edit)
  * @param AbstractProduct $product
  * @param JobInstance     $jobInstance
  *
  * @return AbstractProduct|null
  */
 public function filterProduct(AbstractProduct $product, JobInstance $jobInstance)
 {
     $productExport = $this->productExportRepository->findProductExportAfterEdit($product->getOriginalProduct(), $jobInstance, $product->getUpdated());
     if (0 === count($productExport)) {
         if ($this->productValueDelta) {
             $product = $this->filterProductValues($product);
         }
     } else {
         $product = null;
     }
     return $product;
 }
 /**
  * search local authors based of the parameters and filters given
  * @param array $params  []
  * @param array $filters []
  *
  * @return array
  */
 public function searchLocalAuthor($params, $filters)
 {
     $city = isset($params['city']) ? $params['city'] : 0;
     $country = isset($params['country']) ? $params['country'] : 0;
     $name = isset($filters['name']) ? $filters['name'] : '';
     $page = isset($filters['page']) ? $filters['page'] : 1;
     $limit = isset($filters['limit']) ? $filters['limit'] : 0;
     $search = array();
     //search all
     if ($country == 0 && $city == 0) {
         $data = $this->repository->findAllWithFilters($limit, ($page - 1) * $limit, $name);
         $totalCount = count($data);
         $search = array('count' => $totalCount, 'result' => $data);
     } else {
         if ($country > 0 && $city == 0) {
             //search by country
             $this->setRepository('BugglMainBundle:Location');
             $data = $this->repository->findAllByCountry($country, $limit, ($page - 1) * $limit, $name);
             $totalCount = count($data);
             $authors = array();
             foreach ($data as $each) {
                 $authors[] = $each->getLocalAuthor();
             }
             $search = array('count' => $totalCount, 'result' => $authors);
         } else {
             if ($country > 0 && $city > 0) {
                 //search by  city
                 $this->setRepository('BugglMainBundle:Location');
                 $data = $this->repository->findAllByCity($city, $limit, ($page - 1) * $limit, $name);
                 $totalCount = count($data);
                 $authors = array();
                 foreach ($data as $each) {
                     $authors[] = $each->getLocalAuthor();
                 }
                 $search = array('count' => $totalCount, 'result' => $authors);
             }
         }
     }
     return $search;
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 public function writeItem(array $item)
 {
     $this->counter++;
     $entity = null;
     // If the table was not truncated to begin with, find current entities
     // first
     if (false === $this->truncate) {
         if ($this->index) {
             // If the table has a composite key
             if (!empty($this->compositeKey) && is_array($this->compositeKey)) {
                 $composite = '';
                 foreach ($this->compositeKey as $key => $index) {
                     $composite .= $item[$index];
                 }
                 $value = $composite;
             } else {
                 $value = $item[$this->index];
             }
             $entity = $this->entityRepository->findOneBy(array($this->index => $value));
         } else {
             $entity = $this->entityRepository->find(current($item));
         }
     }
     if (!$entity) {
         $entity = $this->getNewInstance();
     }
     $fieldNames = array_merge($this->entityMetadata->getFieldNames(), $this->entityMetadata->getAssociationNames());
     foreach ($fieldNames as $fieldName) {
         $value = null;
         if (isset($item[$fieldName])) {
             $value = $item[$fieldName];
         } elseif (method_exists($item, 'get' . ucfirst($fieldName))) {
             $value = $item->{'get' . ucfirst($fieldName)};
         }
         if (null === $value) {
             continue;
         }
         if (!$value instanceof \DateTime || $value != $this->entityMetadata->getFieldValue($entity, $fieldName)) {
             $setter = 'set' . ucfirst($fieldName);
             $this->setValue($entity, $value, $setter);
         }
     }
     $this->entityManager->persist($entity);
     if ($this->counter % $this->batchSize == 0) {
         $this->entityManager->flush();
         $this->entityManager->clear($this->entityName);
     }
     return $this;
 }
 /**
  * @param array $organizationCodes
  *
  * @return bool
  */
 protected function isOrgRestrictionMet(array $organizationCodes)
 {
     if (false === $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         return false;
     }
     if (true === $this->authorizationChecker->isGranted('ROLE_ROOT')) {
         return true;
     }
     if (null === $this->orgRepo) {
         return false;
     }
     foreach ($organizationCodes as $code) {
         $organization = $this->orgRepo->findOneByCode($code);
         if (true === $this->authorizationChecker->isGranted('IS_ORGANIZATION_MANAGER', $organization)) {
             return true;
         }
     }
     return false;
 }
Пример #13
0
 /**
  * Is granted
  *
  * @param  string  $slug
  *
  * @return boolean
  */
 private function isGranted($slug)
 {
     $roles = $this->user->getRoles();
     /** @var Role $role */
     if (in_array('ROLE_ADMIN', $roles)) {
         return true;
     }
     $granted = false;
     $roleMenu = $this->repository->findOneBySlug($slug);
     if ($roleMenu instanceof RoleMenu) {
         if (count($roleMenu->getRoles())) {
             $granted = false;
             foreach ($roleMenu->getArrayRoles() as $role) {
                 if (in_array($role, $roles)) {
                     $granted = true;
                 }
             }
         }
     }
     return $granted;
 }
Пример #14
0
 /**
  * Finds existing entity or create a new instance
  */
 protected function findOrCreateItem(array $item)
 {
     $entity = null;
     // If the table was not truncated to begin with, find current entity
     // first
     if (false === $this->truncate) {
         if ($this->lookupFields) {
             $lookupConditions = array();
             foreach ($this->lookupFields as $fieldName) {
                 $lookupConditions[$fieldName] = $item[$fieldName];
             }
             $entity = $this->entityRepository->findOneBy($lookupConditions);
         } else {
             $entity = $this->entityRepository->find(current($item));
         }
     }
     if (!$entity) {
         return $this->getNewInstance();
     }
     return $entity;
 }
Пример #15
0
 /**
  * {@inheritDoc}
  */
 public function findAllInvoices()
 {
     return $this->repository->findAll();
 }
Пример #16
0
 public static function FindById($id)
 {
     $redBeanEntity = parent::FindById('post', $id);
     $entity = new Post($redBeanEntity->id, $redBeanEntity->title, $redBeanEntity->content, $redBeanEntity->date, $redBeanEntity->user_id);
     return $entity;
 }
Пример #17
0
 /**
  * {@inheritDoc}
  */
 public function findAll()
 {
     return $this->entityRepository->findAll();
 }
Пример #18
0
 /**
  * Find one comment by its ID
  *
  * @return Comment or null
  **/
 public function findCommentById($id)
 {
     return $this->repository->find($id);
 }
Пример #19
0
 /**
  * @param string $subscriptionId
  * @return array
  */
 public function findBySubscriptionCustomerId($subscriptionPlanId)
 {
     return $this->repository->findBy(array('subscriptionPlanId' => $subscriptionPlanId));
 }
Пример #20
0
 /**
  * Load Beer's Suggestions based on the color
  * @param EntityRepository $em
  * @param int $id
  * @param int $color
  * @return Beers
  */
 private function loadSuggestions($em, $id, $color)
 {
     return $em->getRepository('BBGCatalogBundle:Beer')->getSuggestions($id, $color);
 }
 /**
  * @param string $subscriptionId
  * @return array
  */
 public function findBySubscriptionTransactionId($subcriptionTransactionId)
 {
     return $this->repository->findBy(array('subcriptionTransactionId' => $subcriptionTransactionId));
 }
 /**
  * Returns entity found for given criteria
  *
  * @param array $criteria
  *
  * @return object
  */
 public function findOneBy(array $criteria)
 {
     return $this->repository->findOneBy($criteria);
 }
Пример #23
0
 /**
  * Finds all threads.
  *
  * @return array of ThreadInterface
  */
 public function findAllThreads()
 {
     return $this->repository->findAll();
 }
Пример #24
0
 public static function FindById($id)
 {
     return parent::FindById('apiary', $id);
 }
Пример #25
0
 /**
  * {@inheritDoc}
  */
 public function findUsers()
 {
     return $this->repository->findAll();
 }
 /**
  * Get the CalendarEvent entity.
  * 
  * @param integer $id
  * @return CalendarEventInterface
  */
 public function getEvent($id)
 {
     return $this->repository->find($id);
 }
 /**
  * 
  * @param EntityManager $em The EntityManager to use.
  * @param ClassMetadata $class The class descriptor.
  */
 public function __construct($em, $class)
 {
     parent::__construct($em, $class);
 }
Пример #28
0
 public static function FindById($id)
 {
     return parent::FindById('beehive', $id);
 }