Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.6' into 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Apr 28, 2015
2 parents 08ceb8e + 0a4e166 commit afba7a9
Show file tree
Hide file tree
Showing 27 changed files with 626 additions and 57 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"guzzle/guzzle": "3.7.*",
"lexik/maintenance-bundle": "v1.0.3",
"sylius/flow-bundle": "0.6.*",
"composer/composer": "1.0.0-alpha8",
"composer/composer": "1.0.0-p1",
"akeneo/batch-bundle": "~0.3",
"luxifer/doctrine-functions": "1.2.1",
"nesbot/Carbon": "1.8.*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public function guessFormatter($class, $property, $type)
case 'datetime':
$frontendType = Property::TYPE_DATETIME;
break;
case 'time':
$frontendType = Property::TYPE_TIME;
break;
case 'money':
$frontendType = Property::TYPE_CURRENCY;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ protected function convertValue($value)
}
$result = (string)$value;
break;
case self::TYPE_TIME:
if ($value instanceof \DateTime) {
$value = $value->format('H:i:s');
}
$result = (string)$value;
break;
case self::TYPE_STRING:
$result = (string)$value;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface PropertyInterface
{
const TYPE_DATE = 'date';
const TYPE_DATETIME = 'datetime';
const TYPE_TIME = 'time';
const TYPE_DECIMAL = 'decimal';
const TYPE_INTEGER = 'integer';
const TYPE_PERCENT = 'percent';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ protected function applyFrontendFormatting($val = null, $formatter = null)
case PropertyInterface::TYPE_DATETIME:
$val = $this->dateTimeFormatter->format($val);
break;
case PropertyInterface::TYPE_TIME:
$val = $this->dateTimeFormatter->formatTime($val);
break;
case PropertyInterface::TYPE_DECIMAL:
$val = $this->numberFormatter->formatDecimal($val);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ protected function applyFrontendFormatting($val, $options)
case PropertyInterface::TYPE_DATETIME:
$val = $this->dateTimeFormatter->format($val);
break;
case PropertyInterface::TYPE_TIME:
$val = $this->dateTimeFormatter->formatTime($val);
break;
case PropertyInterface::TYPE_DECIMAL:
$val = $this->numberFormatter->formatDecimal($val);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ config:
'oro/datagrid/cell/html-cell': 'bundles/orodatagrid/js/datagrid/cell/html-cell.js'
'oro/datagrid/cell/date-cell': 'bundles/orodatagrid/js/datagrid/cell/date-cell.js'
'oro/datagrid/cell/datetime-cell': 'bundles/orodatagrid/js/datagrid/cell/datetime-cell.js'
'oro/datagrid/cell/time-cell': 'bundles/orodatagrid/js/datagrid/cell/time-cell.js'
'oro/datagrid/cell/number-cell': 'bundles/orodatagrid/js/datagrid/cell/number-cell.js'
'oro/datagrid/cell/select-cell': 'bundles/orodatagrid/js/datagrid/cell/select-cell.js'
'oro/datagrid/cell/select-row-cell': 'bundles/orodatagrid/js/datagrid/cell/select-row-cell.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*global define*/
define([
'./string-cell'
], function (StringCell) {
'use strict';

var TimeCell;

/**
* Time column cell
*
* @export oro/datagrid/cell/time-cell
* @class oro.datagrid.cell.TimeCell
* @extends oro.datagrid.cell.StringCell
*/
TimeCell = StringCell.extend({
type: 'time',
className: 'time-cell'
});

return TimeCell;
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function guessFormatterProvider()
['boolean', ['frontend_type' => Property::TYPE_BOOLEAN]],
['date', ['frontend_type' => Property::TYPE_DATE]],
['datetime', ['frontend_type' => Property::TYPE_DATETIME]],
['time', ['frontend_type' => Property::TYPE_TIME]],
['money', ['frontend_type' => Property::TYPE_CURRENCY]],
['percent', ['frontend_type' => Property::TYPE_PERCENT]],
['string', ['frontend_type' => Property::TYPE_STRING]],
Expand Down
2 changes: 1 addition & 1 deletion src/Oro/Bundle/EntityExtendBundle/Form/Type/FieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ protected function isAvailableRelation(

if ($fieldId
&& $extendProvider->hasConfigById($fieldId)
&& !$extendProvider->getConfigById($fieldId)->is('state', ExtendScope::STATE_DELETE)
&& $extendProvider->getConfigById($fieldId)->is('state', ExtendScope::STATE_DELETE)
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,26 @@ class Entity implements \Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterf

public function setRel1($value)
{
$this->rel1 = $value; return $this;
if ((!$value instanceof \Traversable && !is_array($value) && !$value instanceof \ArrayAccess) ||
!$this->rel1 instanceof \Doctrine\Common\Collections\Collection) {
$this->rel1 = $value;
return $this;
}
foreach ($this->rel1 as $item) {
$this->removeRel1($item);
}
foreach ($value as $item) {
$this->addRel1($item);
}
return $this;
}

public function removeRel1($value)
{
if ($this->rel1 && $this->rel1->contains($value)) {
$this->rel1->removeElement($value);
$value->setTarget1(null);
}
}

public function getRel2()
Expand All @@ -25,7 +44,16 @@ class Entity implements \Oro\Bundle\EntityExtendBundle\Entity\ExtendEntityInterf
return $this->rel1;
}

public function addRel1($value)
{
if (!$this->rel1->contains($value)) {
$this->rel1->add($value);
$value->setTarget1($this);
}
}

public function __construct()
{
$this->rel1 = new \Doctrine\Common\Collections\ArrayCollection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ public function testProperties()
$this->assertGeneration('properties.txt', $schema);
}

public function testRelations()
{
$schema = [
'type' => 'Extend',
'property' => [],
'relation' => ['rel1' => 'rel1', 'rel_2' => 'rel_2'],
'default' => [],
'addremove' => []
];
$this->assertGeneration('relations.txt', $schema);
}

public function testDefaults()
{
$schema = [
Expand Down Expand Up @@ -159,6 +147,24 @@ public function testCollections()
$this->assertGeneration('collections.txt', $schema);
}

public function testRelations()
{
$schema = [
'type' => 'Extend',
'property' => [],
'relation' => ['rel1' => 'rel1', 'rel_2' => 'rel_2'],
'default' => [],
'addremove' => [
'rel1' => [
'self' => 'rel1',
'is_target_addremove' => false,
'target' => 'target1',
],
]
];
$this->assertGeneration('relations.txt', $schema);
}

public function testCollectionsWithoutTarget()
{
$schema = [
Expand Down Expand Up @@ -195,6 +201,14 @@ protected function assertGeneration($expectedFile, $schema, $dump = false)
}
$expectedBody = file_get_contents(__DIR__ . '/../Fixtures/' . $expectedFile);

$this->assertEquals(trim($expectedBody), $classBody);
/**
* Support different line endings.
*/
$expectedBody = str_replace(PHP_EOL, "\n", $expectedBody);
$classBody = str_replace(PHP_EOL, "\n", $classBody);
$expectedBody = trim($expectedBody);
$classBody = trim($classBody);

$this->assertEquals($expectedBody, $classBody);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function generateToStringMethod(array $schema, PhpClass $class)
$toString = [];
foreach ($schema['property'] as $fieldName => $config) {
if ($schema['doctrine'][$schema['entity']]['fields'][$fieldName]['type'] == 'string') {
$toString[] = '$this->get' . ucfirst(Inflector::camelize($fieldName)) . '()';
$toString[] = '$this->' . $this->generateGetMethodName($fieldName) . '()';
}
}

Expand All @@ -113,20 +113,50 @@ protected function generateProperties($propertyType, array $schema, PhpClass $cl
->setProperty(PhpProperty::create($fieldName)->setVisibility('protected'))
->setMethod(
$this->generateClassMethod(
'get' . ucfirst(Inflector::camelize($fieldName)),
$this->generateGetMethodName($fieldName),
'return $this->' . $fieldName . ';'
)
)
->setMethod(
$this->generateClassMethod(
'set' . ucfirst(Inflector::camelize($fieldName)),
'$this->' . $fieldName . ' = $value; return $this;',
$this->generateSetMethodName($fieldName),
$this->getSetterBody($fieldName, $schema),
['value']
)
);
}
}

/**
* @param string $fieldName
* @param array $schema
* @return string
*/
protected function getSetterBody($fieldName, array $schema)
{
if (!isset($schema['addremove'][$fieldName])) {
return '$this->' . $fieldName . ' = $value; return $this;';
} else {
$addMethodName = $this->generateAddMethodName($fieldName);
$removeMethodName = $this->generateRemoveMethodName($fieldName);
$body = <<<METHOD_BODY
if ((!\$value instanceof \Traversable && !is_array(\$value) && !\$value instanceof \ArrayAccess) ||
!\$this->$fieldName instanceof \Doctrine\Common\Collections\Collection) {
\$this->$fieldName = \$value;
return \$this;
}
foreach (\$this->$fieldName as \$item) {
\$this->$removeMethodName(\$item);
}
foreach (\$value as \$item) {
\$this->$addMethodName(\$item);
}
return \$this;
METHOD_BODY;
return $body;
}
}

/**
* @param array $schema
* @param PhpClass $class
Expand All @@ -143,30 +173,68 @@ protected function generateCollectionMethods(array $schema, PhpClass $class)
' $this->' . $fieldName . '->removeElement($value);',
];
if (isset($config['target'])) {
$addMethodBody[] = ' $value->' . ($config['is_target_addremove'] ? 'add' : 'set')
. ucfirst(Inflector::camelize($config['target'])) . '($this);';
$removeMethodBody[] = ' $value->' . ($config['is_target_addremove'] ? 'remove' : 'set')
. ucfirst(Inflector::camelize($config['target']))
. '(' . ($config['is_target_addremove'] ? '$this' : 'null') . ');';
if ($config['is_target_addremove']) {
$addMethodBody[] = " \$value->{$this->generateAddMethodName($config['target'])}(\$this);";
$removeMethodBody[] = " \$value->{$this->generateRemoveMethodName($config['target'])}(\$this);";
} else {
$addMethodBody[] = " \$value->{$this->generateSetMethodName($config['target'])}(\$this);";
$removeMethodBody[] = " \$value->{$this->generateSetMethodName($config['target'])}(null);";
}
}
$addMethodBody[] = '}';
$removeMethodBody[] = '}';

$class
->setMethod(
$this->generateClassMethod(
'add' . ucfirst(Inflector::camelize($config['self'])),
$this->generateAddMethodName($config['self']),
implode("\n", $addMethodBody),
['value']
)
)
->setMethod(
$this->generateClassMethod(
'remove' . ucfirst(Inflector::camelize($config['self'])),
$this->generateRemoveMethodName($config['self']),
implode("\n", $removeMethodBody),
['value']
)
);
}
}

/**
* @param string $fieldName
* @return string
*/
protected function generateGetMethodName($fieldName)
{
return 'get' . ucfirst(Inflector::camelize($fieldName));
}

/**
* @param string $fieldName
* @return string
*/
protected function generateSetMethodName($fieldName)
{
return 'set' . ucfirst(Inflector::camelize($fieldName));
}

/**
* @param string $fieldName
* @return string
*/
protected function generateAddMethodName($fieldName)
{
return 'add' . ucfirst(Inflector::camelize($fieldName));
}

/**
* @param string $fieldName
* @return string
*/
protected function generateRemoveMethodName($fieldName)
{
return 'remove' . ucfirst(Inflector::camelize($fieldName));
}
}
Loading

0 comments on commit afba7a9

Please sign in to comment.