Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
added a getAlias() method, switch back to defaulting to 'a' as the alias
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Oct 8, 2013
1 parent 5525e7b commit c9c4902
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getRootPath()
*/
public function createQuery($context = 'list')
{
$query = $this->getModelManager()->createQuery($this->getClass(), 'a');
$query = $this->getModelManager()->createQuery($this->getClass());
$query->setRootPath($this->getRootPath());

foreach ($this->extensions as $extension) {
Expand Down
10 changes: 9 additions & 1 deletion Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ProxyQuery implements ProxyQueryInterface
* of the document.
* @throws \InvalidArgumentException if alias is not a string or an empty string
*/
public function __construct(QueryBuilder $queryBuilder, $alias = 'a')
public function __construct(QueryBuilder $queryBuilder, $alias)
{
if (!is_string($alias) || '' === $alias) {
throw new \InvalidArgumentException('$alias must be a non empty string');
Expand All @@ -87,6 +87,14 @@ public function __construct(QueryBuilder $queryBuilder, $alias = 'a')
$this->alias = $alias;
}

/**
* @return string
*/
public function getAlias()
{
return $this->alias;
}

/**
* @param string $root root path to restrict what documents to find.
*/
Expand Down
6 changes: 3 additions & 3 deletions Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class Filter extends BaseFilter
public function apply($queryBuilder, $value)
{
$this->value = $value;
$this->filter($queryBuilder, null, $this->getFieldName(), $value);
$this->filter($queryBuilder, $queryBuilder->getAlias(), $this->getFieldName(), $value);
}

/**
Expand All @@ -41,9 +41,9 @@ protected function getWhere(ProxyQuery $proxy)
$queryBuilder = $proxy->getQueryBuilder();
if ($this->getCondition() == self::CONDITION_OR) {
return $queryBuilder->orWhere();
} else {
return $queryBuilder->andWhere();
}

return $queryBuilder->andWhere();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Filter/NodeNameFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data)

switch ($data['type']) {
case ChoiceType::TYPE_EQUAL:
$where->eq()->localName('a')->literal($data['value']);
$where->eq()->localName($alias)->literal($data['value']);
break;
case ChoiceType::TYPE_CONTAINS:
default:
$where->like()->localName('a')->literal('%'.$data['value'].'%');
$where->like()->localName($alias)->literal('%'.$data['value'].'%');
}

// filter is active as we have now modified the query
Expand Down
7 changes: 3 additions & 4 deletions Model/ModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ public function getParentFieldDescription($parentAssociationMapping, $class)
/**
* @param string $class the fully qualified class name to search for
* @param string $alias alias to use for this class when accessing fields,
* defaults to 'o'.
* defaults to 'a'.
*
* @return ProxyQueryInterface
*
* @throws \InvalidArgumentException if alias is not a string or an empty string
*/
public function createQuery($class, $alias = 'o')
public function createQuery($class, $alias = 'a')
{
$qb = $this->getDocumentManager()->createQueryBuilder();
$qb->from()->document($class, $alias);
Expand Down Expand Up @@ -318,8 +318,7 @@ public function addIdentifiersToQuery($class, ProxyQueryInterface $queryProxy, a

foreach ($idx as $id) {
$path = $this->getBackendId($id);
// this selector depends on the default in self::createQuery not being changed
$orX->same($path, 'a');
$orX->same($path, $queryProxy->getAlias());
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Datagrid/ProxyQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function setUp()
->disableOriginalConstructor()
->getMock();

$this->pq = new ProxyQuery($this->qb);
$this->pq = new ProxyQuery($this->qb, 'a');
}

public function testConstructor()
Expand Down
10 changes: 5 additions & 5 deletions Tests/Filter/NodeNameFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public function getChoiceTypeForEmptyTests()

public function testFilterNullData()
{
$res = $this->filter->filter($this->proxyQuery, null, 'somefield', null);
$res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', null);
$this->assertNull($res);
$this->assertFalse($this->filter->isActive());
}

public function testFilterEmptyArrayData()
{
$res = $this->filter->filter($this->proxyQuery, null, 'somefield', array());
$res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', array());
$this->assertNull($res);
$this->assertFalse($this->filter->isActive());
}

public function testFilterEmptyArrayDataSpecifiedType()
{
$res = $this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => ChoiceType::TYPE_EQUAL));
$res = $this->filter->filter($this->proxyQuery, 'a', 'somefield', array('type' => ChoiceType::TYPE_EQUAL));
$this->assertNull($res);
$this->assertFalse($this->filter->isActive());
}
Expand All @@ -53,7 +53,7 @@ public function testFilterEmptyArrayDataWithMeaninglessValue()
$this->proxyQuery->expects($this->never())
->method('andWhere');

$this->filter->filter($this->proxyQuery, null, 'somefield', array('type' => ChoiceType::TYPE_EQUAL, 'value' => ' '));
$this->filter->filter($this->proxyQuery, 'a', 'somefield', array('type' => ChoiceType::TYPE_EQUAL, 'value' => ' '));
$this->assertFalse($this->filter->isActive());
}

Expand All @@ -78,7 +78,7 @@ public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue =

$this->filter->filter(
$this->proxyQuery,
null,
'a',
'somefield',
array('type' => $choiceType, 'value' => 'somevalue')
);
Expand Down

0 comments on commit c9c4902

Please sign in to comment.