Skip to content

Commit

Permalink
Add condition map.
Browse files Browse the repository at this point in the history
  • Loading branch information
JASchilz committed Oct 14, 2016
1 parent 5748f1d commit 821aef1
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/orm-wrapper/PropelQueryWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Athens\Propel\ORMWrapper;

use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Map\TableMap;
use Propel\Runtime\ActiveQuery\Criteria;

use Athens\Core\ORMWrapper\AbstractQueryWrapper;
use Athens\Core\ORMWrapper\ObjectWrapperInterface;
use Athens\Core\ORMWrapper\QueryWrapperInterface;
use AthensTest\Base\TestClassQuery;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\Map\TableMap;

/**
* Class PropelQueryWrapper
Expand All @@ -21,6 +23,19 @@ class PropelQueryWrapper extends AbstractQueryWrapper implements QueryWrapperInt
/** @var ModelCriteria */
protected $query;

/**
* @var string[]
*/
protected $conditionMap = [
QueryWrapperInterface::CONDITION_EQUAL => Criteria::EQUAL,
QueryWrapperInterface::CONDITION_NOT_EQUAL => Criteria::NOT_EQUAL,
QueryWrapperInterface::CONDITION_CONTAINS => Criteria::CONTAINS_SOME,
QueryWrapperInterface::CONDITION_GREATER_THAN => Criteria::GREATER_THAN,
QueryWrapperInterface::CONDITION_GREATER_THAN_OR_EQUAL => Criteria::GREATER_EQUAL,
QueryWrapperInterface::CONDITION_LESS_THAN => Criteria::LESS_THAN,
QueryWrapperInterface::CONDITION_LESS_THAN_OR_EQUAL => Criteria::LESS_EQUAL,
];

/**
* PropelQueryWrapper constructor.
*
Expand All @@ -46,7 +61,7 @@ public function findOneByPrimaryKey($primaryKeyValue)

$result = $this->query->{"findOneBy$primaryKeyPhpName"}($primaryKeyValue);

$result = $result === null ? null : new PropelObjectWrapper($result);
$result = $result === null ? null : PropelObjectWrapper::fromObject($result);

return $result;
}
Expand Down Expand Up @@ -79,6 +94,12 @@ public function orderBy($columnName, $condition)
*/
public function filterBy($columnName, $value, $comparison = QueryWrapperInterface::CONDITION_EQUAL)
{
if (strpos($columnName, '.') !== false) {
$columnName = explode('.', $columnName)[1];
}

$comparison = $this->conditionMap[$comparison];

$this->query->filterBy($columnName, $value, $comparison);
return $this;
}
Expand Down Expand Up @@ -109,7 +130,7 @@ public function limit($limit)
public function createObject()
{
$className = $this->query->getModelName();
return new PropelObjectWrapper(new $className());
return PropelObjectWrapper::fromObject(new $className());
}

/**
Expand Down

0 comments on commit 821aef1

Please sign in to comment.