mirror of
https://github.com/espocrm/espocrm.git
synced 2026-07-01 08:26:04 +00:00
orm: DATE functions
This commit is contained in:
@@ -211,6 +211,15 @@ abstract class Base
|
||||
return "DATE_FORMAT({$part}, '%Y-%m')";
|
||||
case 'DAY':
|
||||
return "DATE_FORMAT({$part}, '%Y-%m-%d')";
|
||||
case 'MONTH_NUMBER':
|
||||
$function = 'MONTH';
|
||||
break;
|
||||
case 'DATE_NUMBER':
|
||||
$function = 'DATE';
|
||||
break;
|
||||
case 'YEAR_NUMBER':
|
||||
$function = 'YEAR';
|
||||
break;
|
||||
}
|
||||
if ($distinct) {
|
||||
$idPart = $this->toDb($entityName) . ".id";
|
||||
|
||||
@@ -256,12 +256,12 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||
'value' => array(
|
||||
array(
|
||||
'type' => 'equals',
|
||||
'field'=> 'date',
|
||||
'attribute'=> 'date',
|
||||
'value' => '2016-10-10'
|
||||
),
|
||||
array(
|
||||
'type' => 'after',
|
||||
'field'=> 'dateTime',
|
||||
'attribute'=> 'dateTime',
|
||||
'value' => '2016-10-10 10:10:00'
|
||||
)
|
||||
)
|
||||
@@ -273,4 +273,23 @@ class BaseTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals('2016-10-10', $selectParams['whereClause'][0]['NOT'][0]['date=']);
|
||||
}
|
||||
|
||||
function testBuildSelectParamsComplex()
|
||||
{
|
||||
$selectManager = new \Espo\Core\SelectManagers\Base($this->entityManager, $this->user, $this->acl, $this->aclManager, $this->metadata, $this->config);
|
||||
$selectManager->setEntityType('Test2');
|
||||
|
||||
$params = array(
|
||||
'where' => array(
|
||||
array(
|
||||
'type' => 'equals',
|
||||
'attribute'=> 'MONTH_NUMBER:dateTime',
|
||||
'value' => 2
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$selectParams = $selectManager->buildSelectParams($params);
|
||||
$this->assertEquals(2, $selectParams['whereClause'][0]['MONTH_NUMBER:dateTime=']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,6 +392,18 @@ class QueryTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expectedSql, $sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testFunction1()
|
||||
{
|
||||
$sql = $this->query->createSelectQuery('Comment', array(
|
||||
'select' => ['id'],
|
||||
'whereClause' => array(
|
||||
'MONTH_NUMBER:comment.created_at' => 2
|
||||
)
|
||||
));
|
||||
$expectedSql =
|
||||
"SELECT comment.id AS `id` FROM `comment` " .
|
||||
"WHERE MONTH(comment.created_at) = '2' AND comment.deleted = '0'";
|
||||
$this->assertEquals($expectedSql, $sql);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user