Skip to content

Commit

Permalink
Merge 1.0.0-alpha3
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Jun 27, 2013
2 parents 5d81c00 + fdef47f commit 27b03c5
Show file tree
Hide file tree
Showing 548 changed files with 39,338 additions and 11,781 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CHANGELOG for 1.0.0-alpha3
===================

This changelog references the relevant changes (new features, changes and bugs) done in 1.0.0-alpha3 versions.

* 1.0.0-alpha3 (2013-06-27)
* Placeholders
* Developer toolbar works with AJAX navigation requests
* Configuring hidden columns in a Grid
* Auto-complete form type
* Added Address Book
* Localized countries and regions
* Enhanced data change log with ability to save changes for collections
* Removed dependency on lib ICU

7 changes: 7 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
UPGRADE FROM 1.0.0-alpha2 to 1.0.0-alpha3
=======================

### General

* Upgrade to 1.0.0-alpha3 is not supported and full reinstall is required

9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"jms/serializer": "0.12.*@dev",
"jms/serializer-bundle": "0.12.*@dev",
"kriswallsmith/assetic": "1.1.*@dev",
"knplabs/knp-menu": "dev-master",
"knplabs/knp-menu-bundle": "dev-master",
"knplabs/knp-menu": "v2.0.0-alpha1",
"knplabs/knp-menu-bundle": "v2.0.0-alpha1",
"knplabs/knp-paginator-bundle": "dev-master",
"friendsofsymfony/rest-bundle": "0.11.*",
"friendsofsymfony/jsrouting-bundle": "1.1.*@dev",
Expand All @@ -39,10 +39,9 @@
"sonata-project/doctrine-orm-admin-bundle": "2.1.x-dev",
"liip/imagine-bundle": "dev-master",
"leafo/lessphp": "dev-master",
"symfony/icu": "1.2.*@dev",
"symfony/intl": "2.3.*@dev",
"willdurand/expose-translation-bundle": "0.2.*@dev",
"apy/jsfv-bundle": "dev-master#a27847b4e0e52212277c4759826328b3cfaa15dc"
"apy/jsfv-bundle": "dev-master#a27847b4e0e52212277c4759826328b3cfaa15dc",
"genemu/form-bundle": "2.1.*"
},
"repositories": [
{
Expand Down
20 changes: 2 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,10 @@
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "vendor/autoload.php">

bootstrap = "tests/bootstrap.php">
<testsuites>
<testsuite name="Project Unit Tests">
<directory suffix="Test.php">src/Oro/Bundle/AddressBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/ConfigBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/DataAuditBundle/Tests/Unit</directory>
<!--<directory suffix="Test.php">src/Oro/Bundle/DataFlowBundle/Tests/Unit</directory>-->
<directory suffix="Test.php">src/Oro/Bundle/FilterBundle/Tests/Unit</directory>
<!--<directory suffix="Test.php">src/Oro/Bundle/FlexibleEntityBundle/Tests/Unit</directory>-->
<directory suffix="Test.php">src/Oro/Bundle/GridBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/MeasureBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/NavigationBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/SearchBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/SegmentationTreeBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/SoapBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/TestFrameworkBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/UIBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/UserBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/Oro/Bundle/WindowsBundle/Tests/Unit</directory>
<directory suffix="Test.php">src/*/Bundle/*Bundle/Tests/Unit</directory>
</testsuite>
</testsuites>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace Oro\Bundle\AddressBundle\Controller\Api\Rest;

use Symfony\Component\HttpFoundation\Response;
use Doctrine\ORM\Query;
use FOS\Rest\Util\Codes;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Controller\Annotations\NamePrefix;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Response;

use Oro\Bundle\AddressBundle\Entity\Country;
use Oro\Bundle\AddressBundle\Entity\Repository\RegionRepository;

/**
* @RouteResource("country/regions")
Expand All @@ -18,21 +22,28 @@ class CountryRegionsController extends FOSRestController
/**
* REST GET regions by country
*
* @param string $id
* @param Country $country
*
* @ApiDoc(
* description="Get regions by country id",
* resource=true
* )
* @return Response
*/
public function getAction($id)
public function getAction(Country $country = null)
{
/** @var $item \Oro\Bundle\AddressBundle\Entity\Country */
$item = $this->getDoctrine()->getRepository('OroAddressBundle:Country')->find($id);
if (!$country) {
return $this->handleView(
$this->view(null, Codes::HTTP_NOT_FOUND)
);
}

/** @var $regionRepository RegionRepository */
$regionRepository = $this->getDoctrine()->getRepository('OroAddressBundle:Region');
$regions = $regionRepository->getCountryRegions($country);

return $this->handleView(
$this->view($item ? $item->getRegions() : null, $item ? Codes::HTTP_OK : Codes::HTTP_NOT_FOUND)
$this->view($regions, Codes::HTTP_OK)
);
}
}
231 changes: 231 additions & 0 deletions src/Oro/Bundle/AddressBundle/DataFixtures/ORM/LoadCountryData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
<?php

namespace Oro\Bundle\AddressBundle\DataFixtures\ORM;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Finder\Finder;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;

use Oro\Bundle\AddressBundle\Entity\Country;
use Oro\Bundle\AddressBundle\Entity\Region;

class LoadCountryData extends AbstractFixture implements ContainerAwareInterface
{
const COUNTRY_DOMAIN = 'countries';
const COUNTRY_FILE_REGEXP = '/^countries\.(.*?)\./';

/**
* @var ContainerInterface
*/
protected $container;

/**
* @var TranslatorInterface
*/
protected $translator;

/**
* @var EntityRepository
*/
protected $countryRepository;

/**
* @var EntityRepository
*/
protected $regionRepository;

/**
* @var string
*/
protected $translationDirectory = '/Resources/translations/';

/**
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$this->translator = $this->container->get('translator');

$fileName = $this->getFileName();
$countries = $this->getDataFromFile($fileName);
$this->saveCountryData($manager, $countries);
}

public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}

/**
* @return string
*/
protected function getFileName()
{
return __DIR__ . '/../data/countries.yml';
}

/**
* @param string $fileName
* @return bool
*/
protected function isFileAvailable($fileName)
{
return is_file($fileName) && is_readable($fileName);
}

/**
* @param string $fileName
* @return array
* @throws \LogicException
*/
protected function getDataFromFile($fileName)
{
if (!$this->isFileAvailable($fileName)) {
throw new \LogicException('File ' . $fileName . 'is not available');
}

$fileName = realpath($fileName);

return Yaml::parse($fileName);
}

/**
* @return array
*/
protected function getAvailableCountryLocales()
{
$translationDirectory = str_replace('/', DIRECTORY_SEPARATOR, $this->translationDirectory);
$translationDirectories = array();

foreach ($this->container->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
$bundleTranslationDirectory = dirname($reflection->getFilename()) . $translationDirectory;
if (is_dir($bundleTranslationDirectory) && is_readable($bundleTranslationDirectory)) {
$translationDirectories[] = realpath($bundleTranslationDirectory);
}
}

$finder = new Finder();
$finder->in($translationDirectories)->name(self::COUNTRY_FILE_REGEXP);

$countryLocales = array();
/** @var $file \SplFileInfo */
foreach ($finder as $file) {
preg_match(self::COUNTRY_FILE_REGEXP, $file->getFilename(), $matches);
if ($matches) {
$countryLocales[] = $matches[1];
}
}

return $countryLocales;
}

/**
* @param string $locale
* @param array $countryData
* @return null|Country
*/
protected function getCountry($locale, array $countryData)
{
if (empty($countryData['iso2Code']) || empty($countryData['iso3Code'])) {
return null;
}

/** @var $country Country */
$country = $this->countryRepository->findOneBy(array('iso2Code' => $countryData['iso2Code']));
if (!$country) {
$country = new Country($countryData['iso2Code']);
$country->setIso3Code($countryData['iso3Code']);
}

$countryName = $this->translator->trans(
$countryData['iso2Code'],
array(),
self::COUNTRY_DOMAIN,
$locale
);

$country->setLocale($locale)
->setName($countryName);

return $country;
}

/**
* @param string $locale
* @param Country $country
* @param array $regionData
* @return null|Region
*/
protected function getRegion($locale, Country $country, array $regionData)
{
if (empty($regionData['combinedCode']) || empty($regionData['code'])) {
return null;
}

/** @var $region Region */
$region = $this->regionRepository->findOneBy(array('combinedCode' => $regionData['combinedCode']));
if (!$region) {
$region = new Region($regionData['combinedCode']);
$region->setCode($regionData['code'])
->setCountry($country);
}

$regionName = $this->translator->trans(
$regionData['combinedCode'],
array(),
self::COUNTRY_DOMAIN,
$locale
);

$region->setLocale($locale)
->setName($regionName);

return $region;
}

/**
* Save countries and regions to DB
*
* @param ObjectManager $manager
* @param array $countries
*/
protected function saveCountryData(ObjectManager $manager, array $countries)
{
$this->countryRepository = $manager->getRepository('OroAddressBundle:Country');
$this->regionRepository = $manager->getRepository('OroAddressBundle:Region');

$countryLocales = $this->getAvailableCountryLocales();

foreach ($countryLocales as $locale) {
foreach ($countries as $countryData) {
$country = $this->getCountry($locale, $countryData);
if (!$country) {
continue;
}

$manager->persist($country);

if (!empty($countryData['regions'])) {
foreach ($countryData['regions'] as $regionData) {
$region = $this->getRegion($locale, $country, $regionData);
if (!$region) {
continue;
}

$manager->persist($region);
}
}
}

$manager->flush();
$manager->clear();
}
}
}
Loading

0 comments on commit 27b03c5

Please sign in to comment.