<?php
// src/AppBundle/Entity/EshopRepo.php
namespace App\EntityRepo;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
class EshopRepo extends EntityRepository
{
public function getEshopList()
{
$eshopCollection = $this->getEntityManager()
->createQuery('SELECT e FROM App:Eshop e')
->getResult();
return $eshopCollection;
}
public function getEshopListByUser($userId)
{
$eshopCollection = $this->getEntityManager()
->createQuery('SELECT e FROM App:Eshop e WHERE e.userId = :userId')
->setParameter('userId',$userId)
->getResult();
return $eshopCollection;
}
public function getEshop($eshopId)
{
$eshop = $this->getEntityManager()
->createQuery('SELECT e FROM App:Eshop e WHERE e.eshopId = :eshopId')
->setParameter('eshopId',$eshopId)
->getResult();
if (isset($eshop[0])) {
return $eshop[0];
}
else {
return null;
}
}
public function unsetCurrentEshop($userId)
{
/* we unset all e-shops of the user as not current */
$this->getEntityManager()
->createQuery('UPDATE App:Eshop e SET e.eshopCurrent = false WHERE e.userId = :userId')
->setParameter('userId',$userId)
->getResult();
return true;
}
public function setCurrentEshop($userId, $eshopId)
{
/* we unset all e-shops of the user as not current */
$this->unsetCurrentEshop($userId);
/* we set selected e-shop as current */
$this->getEntityManager()
->createQuery('UPDATE App:Eshop e SET e.eshopCurrent = true WHERE e.eshopId = :eshopId')
->setParameter('eshopId',$eshopId)
->getResult();
//print("<br>QQW setEshop: ".$eshopId);
return true;
}
public function getCurrentEshop($userId)
{
$eshop = $this->getEntityManager()
->createQuery('SELECT e FROM App:Eshop e WHERE e.eshopCurrent = true AND e.userId = :userId')
->setParameter('userId',$userId)
->getResult();
// print("<br>QQW getEshop: ");
// print_r($eshop[0]->getEshopId());
if (isset($eshop[0])) {
return $eshop[0];
}
else {
return null;
}
}
public function getCategoryList($eshop)
{
// print('<br>qqw eshop: ');
// \Doctrine\Common\Util\Debug::dump($eshop);
$categoryCollection = $this->getEntityManager()
->createQuery('SELECT c FROM App:Category c')
->getResult();
/*
foreach($categoryCollection as $category)
{
print("<br>QQW category: ");
print_r($category);
}
*/
return $categoryCollection;
}
public function getCategoryListByEshop($eshopId)
{
$categoryCollection = $this->getEntityManager()
->createQuery('SELECT c FROM App:Category c WHERE c.eshopId = :eshopId')
->setParameter('eshopId',$eshopId)
->getResult();
/*
$categoryCollection = $this->getEntityManager()
->createQuery('SELECT c FROM AppBundle:Category c')
->getResult();
*/
/*
foreach($categoryCollection as $category)
{
print("<br>QQW category: ");
print_r($category);
}
*/
return $categoryCollection;
}
public function getRootCategoryListByEshop($eshopId)
{
$parentId = null;
$categoryCollection = $this->getEntityManager()
->createQuery('SELECT c FROM App:Category c WHERE c.eshopId = :eshopId')
->setParameter('eshopId', $eshopId)
// ->setParameter('parentId', $parentId)
->getResult();
// print('<br>cat collection: ');
// \Doctrine\Common\Util\Debug::dump($categoryCollection);
return $categoryCollection;
}
public function getCategory($categoryId)
{
$category = $this->getEntityManager()
->createQuery('SELECT c FROM App\Entity\Category c WHERE c.categoryId = :categoryId')
->setParameter('categoryId',$categoryId)
->getResult();
/*
print("<hr>QQW getCategory: ".$categoryId);
\Doctrine\Common\Util\Debug::dump($category[0]);
*/
if (isset($category[0])) {
return $category[0];
}
else {
return null;
}
}
public function getCategoryByErpKey($erpKey)
{
$entity = $this->getEntityManager()
->createQuery('SELECT c FROM App\Entity\Category c WHERE c.ERPKey = :erpKey')
->setParameter('erpKey',$erpKey)
->getResult();
if (isset($entity[0])) {
return $entity[0];
}
else {
return null;
}
}
public function getEshopHeader($eshopId)
{
$pageType = 2;
$webPage = $this->getEntityManager()
->createQuery('SELECT w FROM App\Entity\WebPage w WHERE w.eshopId = :eshopId AND w.webPageType = :webPageType')
->setParameter('eshopId',$eshopId)
->setParameter('webPageType',$pageType)
->getResult();
if (isset($webPage[0])) {
return $webPage[0];
}
else {
return null;
}
}
public function getEshopFooter($eshopId)
{
$pageType = 3;
$webPage = $this->getEntityManager()
->createQuery('SELECT w FROM App\Entity\WebPage w WHERE w.eshopId = :eshopId AND w.webPageType = :webPageType')
->setParameter('eshopId',$eshopId)
->setParameter('webPageType',$pageType)
->getResult();
if (isset($webPage[0])) {
return $webPage[0];
}
else {
return null;
}
}
public function getHomePage($eshopId)
{
$pageType = 1;
$webPage = $this->getEntityManager()
->createQuery('SELECT w FROM App\Entity\WebPage w WHERE w.eshopId = :eshopId AND w.webPageType = :webPageType')
->setParameter('eshopId',$eshopId)
->setParameter('webPageType',$pageType)
->getResult();
if (isset($webPage[0])) {
return $webPage[0];
}
else {
return null;
}
}
public function getCategoryListBySearch($eshopId, $searchString)
{
$collection = $this->getEntityManager()
->createQuery('SELECT c FROM App\Entity\Category c
WHERE c.eshopId = :eshopId
AND (c.categoryName LIKE :searchString OR c.categoryDescription LIKE :searchString)
ORDER BY c.categoryId ')
->setParameter('eshopId',$eshopId)
->setParameter('searchString', '%'.addcslashes($searchString, '%_').'%')
->getResult();
return $collection;
}
public function getCategoryListByName($eshopId, $categoryName)
{
$collection = $this->getEntityManager()
->createQuery('SELECT c FROM App\Entity\Category c
WHERE c.eshopId = :eshopId
AND (c.categoryName = :categoryName)
ORDER BY c.categoryId ')
->setParameter('eshopId',$eshopId)
->setParameter('categoryName', $categoryName)
->getResult();
return $collection;
}
}
?>