本文整理汇总了PHP中EntityRepository类的典型用法代码示例。如果您正苦于以下问题:PHP EntityRepository类的具体用法?PHP EntityRepository怎么用?PHP EntityRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadSuggestions
/**
* 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);
}
示例2: showEntityNameAction
/**
* @param int $id
*
* @return Entity
*
* @throws \Exception
*/
public function showEntityNameAction($id)
{
if ($entity = $this->entityRepository->find($id)) {
return $entity->getName();
}
throw new \Exception();
}
示例3: findVotesByComment
/**
* 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;
}
示例4: findInvoiceItemsByInvoiceId
/**
* {@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;
}
示例5: setRepositoryLocale
/**
* 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);
}
}
}
示例6: processRepositoryLocale
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);
}
}
}
示例7: load
/**
* 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;
}
}
示例8: resolveTable
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;
}
示例9: pk
/**
*
* @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;
}
示例10: filterProduct
/**
* 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;
}
示例11: searchLocalAuthor
/**
* 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;
}
示例12: writeItem
/**
* {@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;
}
示例13: isOrgRestrictionMet
/**
* @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;
}
示例14: isGranted
/**
* 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;
}
示例15: findOrCreateItem
/**
* 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;
}