|
<?php |
|
|
|
namespace XLite\Module\RealData\Related\Model\Repo; |
|
|
|
/** |
|
* Profile relations repository |
|
*/ |
|
class ProfileRelation extends \XLite\Model\Repo\ARepo |
|
{ |
|
/** |
|
* Allowable search params |
|
*/ |
|
const P_LEFT_PROFILE_ID = 'leftProfileId'; |
|
const P_RIGHT_PROFILE_ID = 'rightProfileId'; |
|
const P_LIMIT = 'limit'; |
|
|
|
/** |
|
* Common search |
|
* |
|
* @param \XLite\Core\CommonCell $cnd Search condition |
|
* @param boolean $countOnly Return items list or only its size OPTIONAL |
|
* |
|
* @return \Doctrine\ORM\PersistentCollection|integer |
|
*/ |
|
/*public function search(\XLite\Core\CommonCell $cnd, $countOnly = false) |
|
{ |
|
$queryBuilder = $this->createQueryBuilder('pr'); |
|
$this->currentSearchCnd = $cnd; |
|
|
|
foreach ($this->currentSearchCnd as $key => $value) { |
|
if (self::P_LIMIT != $key || !$countOnly) { |
|
$this->callSearchConditionHandler($value, $key, $queryBuilder); |
|
} |
|
} |
|
|
|
$result = $queryBuilder->getOnlyEntities(); |
|
|
|
return $countOnly ? count($result) : $result; |
|
}*/ |
|
|
|
/** |
|
* Return list of handling search params |
|
* |
|
* @return array |
|
*/ |
|
/* protected function getHandlingSearchParams() |
|
{ |
|
return array( |
|
static::P_LEFT_PROFILE_ID, |
|
static::P_RIGHT_PROFILE_ID, |
|
static::P_LIMIT, |
|
); |
|
}*/ |
|
|
|
/** |
|
* Check if param can be used for search |
|
* |
|
* @param string $param Name of param to check |
|
* |
|
* @return boolean |
|
*/ |
|
/* protected function isSearchParamHasHandler($param) |
|
{ |
|
return in_array($param, $this->getHandlingSearchParams()); |
|
}*/ |
|
|
|
/** |
|
* Call corresponded method to handle a serch condition |
|
* |
|
* @param mixed $value Condition data |
|
* @param string $key Condition name |
|
* @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare |
|
* |
|
* @return void |
|
*/ |
|
/* protected function callSearchConditionHandler($value, $key, \Doctrine\ORM\QueryBuilder $queryBuilder) |
|
{ |
|
if ($this->isSearchParamHasHandler($key)) { |
|
$methodName = 'prepareCnd' . ucfirst($key); |
|
// $methodName is assembled from 'prepareCnd' + key |
|
$this->$methodName($queryBuilder, $value); |
|
|
|
} else { |
|
// TODO - add logging here |
|
} |
|
}*/ |
|
|
|
/** |
|
* Prepare certain search condition |
|
* |
|
* @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare |
|
* @param integer $value Condition data |
|
* |
|
* @return void |
|
*/ |
|
protected function prepareCndLeftProfileId(\Doctrine\ORM\QueryBuilder $queryBuilder, $value) |
|
{ |
|
$left_profile = \XLite\Core\Database::getRepo('XLite\Model\Profile')->find($value); |
|
$queryBuilder->andWhere('pr.leftProfile = :left_profile') |
|
->setParameter('left_profile', $left_profile); |
|
} |
|
|
|
/** |
|
* Prepare certain search condition |
|
* |
|
* @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare |
|
* @param integer $value Condition data |
|
* |
|
* @return void |
|
*/ |
|
protected function prepareCndRightProfileId(\Doctrine\ORM\QueryBuilder $queryBuilder, $value) |
|
{ |
|
$right_profile = \XLite\Core\Database::getRepo('XLite\Model\Profile')->find($value); |
|
$queryBuilder->andWhere('pr.rightProfile = :right_profile') |
|
->setParameter('right_profile', $right_profile); |
|
} |
|
|
|
/** |
|
* Prepare certain search condition |
|
* |
|
* @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare |
|
* @param array $value Condition data |
|
* |
|
* @return void |
|
*/ |
|
/* protected function prepareCndLimit(\Doctrine\ORM\QueryBuilder $queryBuilder, array $value) |
|
{ |
|
$queryBuilder->setFrameResults($value); |
|
}*/ |
|
} |