<?php
namespace ProjectBiz\DatabaseBundle\Database\Criteria;
use Doctrine\DBAL\Query\QueryBuilder;
use ProjectBiz\DatabaseBundle\Database\Column;
class CriteriaUnmappedColumn implements CriteriaBuilderInterface, \JsonSerializable
{
private $columnName;
public function __construct($columnName, $tableName = null)
{
$this->columnName = $columnName;
$this->tableName = $tableName;
}
public function buildCriteria(QueryBuilder $builder, array $columnMap, $processedView, $mt_name = 'mt')
{
$parts = explode(':', $this->columnName);
$numParts = count($parts);
switch ($numParts) {
case 1:
$column = new Column($this->columnName, 'view', $this->tableName ?? $mt_name);
return $column->getSelectName();
case 2:
$sourceColumnObj = new Column($parts[1], 'view', $columnMap[$parts[0]]['table']);
return $columnMap[$parts[0]]['table'] . '.' . $sourceColumnObj->getSelectName();
}
}
/**
* (PHP 5 >= 5.4.0)<br/>
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
public function jsonSerialize()
{
return [
'type' => 'unmapped_column',
'column_name' => $this->columnName
];
}
}