本文整理汇总了PHP中EntityRepository::findOneBy方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityRepository::findOneBy方法的具体用法?PHP EntityRepository::findOneBy怎么用?PHP EntityRepository::findOneBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityRepository
的用法示例。
在下文中一共展示了EntityRepository::findOneBy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateProductExport
/**
* Update product export date for the given product
* @param string $identifier
* @param JobInstance $jobInstance
*/
public function updateProductExport($identifier, JobInstance $jobInstance)
{
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$product = $this->productRepository->findByReference((string) $identifier);
if (class_exists('\\PimEnterprise\\Bundle\\WorkflowBundle\\Model\\PublishedProduct')) {
if ($product instanceof \PimEnterprise\Bundle\WorkflowBundle\Model\PublishedProduct) {
/**@var \PimEnterprise\Bundle\WorkflowBundle\Model\PublishedProduct $product **/
$productId = $product->getOriginalProduct()->getId();
$product = $product->getOriginalProduct();
}
}
if (null != $product) {
$productExport = $this->productExportRepository->findOneBy(array('product' => $product, 'jobInstance' => $jobInstance));
$conn = $this->entityManager->getConnection();
$jobInstance->getId();
$product->getId();
if (null === $productExport) {
$sql = '
INSERT INTO pim_delta_product_export
(product_id, job_instance_id, date)
VALUES (:product_id, :job_instance_id, :date)
';
} else {
$sql = '
UPDATE pim_delta_product_export
SET date = :date
WHERE product_id = :product_id AND job_instance_id = :job_instance_id
';
}
$q = $conn->prepare($sql);
$date = $now->format('Y-m-d H:i:s');
$productId = $product->getId();
$jobInstanceId = $jobInstance->getId();
$q->bindParam(':date', $date, PDO::PARAM_STR);
$q->bindParam(':product_id', $productId, PDO::PARAM_INT);
$q->bindParam(':job_instance_id', $jobInstanceId, PDO::PARAM_INT);
$q->execute();
}
}
示例2: 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;
}
示例3: 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;
}
示例4: findOneBy
/**
* Returns entity found for given criteria
*
* @param array $criteria
*
* @return object
*/
public function findOneBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}