Skip to content

Instantly share code, notes, and snippets.

@whatafunc
Created March 20, 2018 11:50
Show Gist options
  • Save whatafunc/d9c918101d31bad564fc2f860c215f08 to your computer and use it in GitHub Desktop.
Save whatafunc/d9c918101d31bad564fc2f860c215f08 to your computer and use it in GitHub Desktop.
XC5 module for marking customers related when needed so that the admin knows which clients are in fact from the same company
<?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);
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment