lyssal/geographie-bundle

此包已被废弃且不再维护。作者建议使用lyssal/geography-bundle包。

用于管理地点(城市、省份、地区、国家)的包

安装: 464

依赖: 2

建议者: 0

安全性: 0

星标: 5

关注者: 2

分支: 6

开放问题: 1

类型:symfony-bundle

0.1.4 2016-05-01 14:51 UTC

This package is auto-updated.

Last update: 2021-05-10 19:10:58 UTC


README

LyssalGeographieBundle 允许操作不同地理数据和语言。

SensioLabsInsight

实体

所有实体都拥有其管理器和可选的行政(如果使用Sonata)。

实体包括:

  • 国家
  • 地区
  • 省份
  • 城市
  • 邮编
  • 语言

使用方法

您必须创建一个继承自LyssalGeographieBundle的bundle。

namespace Acme\GeographieBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeGeographieBundle extends Bundle
{
    public function getParent()
    {
        return 'LyssalGeographieBundle';
    }
}

然后,您必须在您的bundle中创建继承自LyssalGeographieBundle的实体并重新定义某些属性。

namespace Acme\GeographieBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Lyssal\GeographieBundle\Entity\Pays as BasePays;
use Doctrine\ORM\Mapping\UniqueConstraint;

/**
 * Pays du monde.
 * 
 * @ORM\Entity()
 * @ORM\Table
 * (
 *     name="acme_pays",
 *     uniqueConstraints=
 *     {
 *         @UniqueConstraint(name="CODE_ALPHA_2", columns={ "pays_code_alpha_2" }),
 *         @UniqueConstraint(name="CODE_ALPHA_3", columns={ "pays_code_alpha_3" })
 *     }
 * )
 */
class Pays extends BasePays
{
    /**
     * @var array<\Acme\GeographieBundle\Entity\Region>
     * 
     * @ORM\OneToMany(targetEntity="Region", mappedBy="pays")
     */
    protected $regions;
}
namespace Acme\GeographieBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Lyssal\GeographieBundle\Entity\Region as BaseRegion;

/**
 * Région d'un pays.
 * 
 * @ORM\Entity()
 * @ORM\Table(name="acme_region")
 */
class Region extends BaseRegion
{
    /**
     * @var \Acme\GeographieBundle\Entity\Pays
     * 
     * @ORM\ManyToOne(targetEntity="Pays", inversedBy="regions")
     * @ORM\JoinColumn(name="pays_id", referencedColumnName="pays_id", nullable=false, onDelete="CASCADE")
     */
    protected $pays;
    
    /**
     * @ORM\OneToMany(targetEntity="Departement", mappedBy="region")
     */
    protected $departements;
}
namespace Acme\GeographieBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Lyssal\GeographieBundle\Entity\Departement as BaseDepartement;
use Doctrine\ORM\Mapping\UniqueConstraint;

/**
 * Département d'une région.
 * 
 * @ORM\Entity(repositoryClass="\Lyssal\GeographieBundle\Repository\DepartementRepository")
 * @ORM\Table
 * (
 *     name="acme_departement",
 *     uniqueConstraints=
 *     {
 *         @UniqueConstraint(name="REGION_CODE", columns={ "region_id", "departement_code" })
 *     }
 * )
 */
class Departement extends BaseDepartement
{
    /**
     * @var \Acme\GeographieBundle\Entity\Region
     * 
     * @ORM\ManyToOne(targetEntity="Region", inversedBy="departements")
     * @ORM\JoinColumn(name="reg_id", referencedColumnName="reg_id", nullable=false, onDelete="CASCADE")
     */
    protected $region;
    
    /**
     * @var array<\Acme\GeographieBundle\Entity\Ville>
     * 
     * @ORM\OneToMany(targetEntity="Ville", mappedBy="departement")
     */
    protected $villes;
}
namespace Acme\GeographieBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Lyssal\GeographieBundle\Entity\Ville as BaseVille;

/**
 * Ville.
 * 
 * @ORM\Entity()
 * @ORM\Table(name="acme_ville")
 */
class Ville extends BaseVille
{
    /**
     * @var \Acme\GeographieBundle\Entity\Departement
     * 
     * @ORM\ManyToOne(targetEntity="Departement", inversedBy="villes")
     * @ORM\JoinColumn(name="dep_id", referencedColumnName="dep_id", nullable=false, onDelete="CASCADE")
     */
    protected $departement;
}
namespace Acme\GeographieBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Lyssal\GeographieBundle\Entity\CodePostal as BaseCodePostal;

/**
 * Code postal.
 * 
 * @ORM\Entity()
 * @ORM\Table(name="acme_code_postal", uniqueConstraints={@ORM\UniqueConstraint(name="UNIQUE_VILLE_CODE", columns={"ville_id", "code_postal_code"})})
 */
class CodePostal extends BaseCodePostal
{
    
}
namespace Acme\GeographieBundle\Entity;

use Lyssal\GeographieBundle\Entity\Langue as BaseLangue;
use Doctrine\ORM\Mapping as ORM;

/**
 * Langue.
 * 
 * @ORM\Entity()
 * @ORM\Table(name="acme_langue")
 */
class Langue extends BaseLangue
{
    
}

您必须重新定义以下参数:

  • lyssal.geographie.entity.departement.class : Acme\GeographieBundle\Entity\Departement
  • lyssal.geographie.entity.pays.class : Acme\GeographieBundle\Entity\Pays
  • lyssal.geographie.entity.region.class : Acme\GeographieBundle\Entity\Region
  • lyssal.geographie.entity.ville.class : Acme\GeographieBundle\Entity\Ville
  • lyssal.geographie.entity.code_postal.class : Acme\GeographieBundle\Entity\CodePostal
  • lyssal.geographie.entity.langue.class : Acme\GeographieBundle\Entity\Langue

示例见 Acme/GeographieBundle/Resources/config/services.xml

<?xml version="1.0" ?>
<container xmlns="https://symfony.com.cn/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://symfony.com.cn/schema/dic/services https://symfony.com.cn/schema/dic/services/services-1.0.xsd">
    <parameters>
        <parameter key="lyssal.geographie.entity.ville.class">Acme\GeographieBundle\Entity\Ville</parameter>
        <parameter key="lyssal.geographie.entity.code_postal.class">Acme\GeographieBundle\Entity\CodePostal</parameter>
        <parameter key="lyssal.geographie.entity.departement.class">Acme\GeographieBundle\Entity\Departement</parameter>
        <parameter key="lyssal.geographie.entity.region.class">Acme\GeographieBundle\Entity\Region</parameter>
        <parameter key="lyssal.geographie.entity.pays.class">Acme\GeographieBundle\Entity\Pays</parameter>
        <parameter key="lyssal.geographie.entity.langue.class">Acme\GeographieBundle\Entity\Langue</parameter>
    </parameters>
</container>

您必须配置

在您的 AppKernel.php

new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),

在您的 config.yml

doctrine:
    # ...
    orm:
        # ...
        mappings:
            translatable:
                type: annotation
                alias: Gedmo
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"

stof_doctrine_extensions:
    default_locale: "%locale%"
    orm:
        default:
            translatable: true
            sluggable: true

管理器

服务包括

  • lyssal.geographie.manager.departement
  • lyssal.geographie.manager.pays
  • lyssal.geographie.manager.region
  • lyssal.geographie.manager.ville
  • lyssal.geographie.manager.code_postal
  • lyssal.geographie.manager.langue

使用示例

在您的控制器中

$tousLesPays = $this->container->get('lyssal.geographie.manager.pays')->findAll();

使用从LyssalGeographieBundle继承的管理器

如果您使用继承自LyssalGeographieBundle的管理器,您可以重新定义以下参数

  • lyssal.geographie.manager.departement.class
  • lyssal.geographie.manager.pays.class
  • lyssal.geographie.manager.region.class
  • lyssal.geographie.manager.ville.class
  • lyssal.geographie.manager.code_postal.class
  • lyssal.geographie.manager.langue.class

自定义管理器的XML示例

<parameters>
    <parameter key="lyssal.geographie.manager.departement.class">Acme\GeographieBundle\Manager\DepartementManager</parameter>
</parameters>

SonataAdmin

如果您已安装SonataAdmin,实体将自动集成。

如果您想重新定义Admin类,只需覆盖以下参数

  • lyssal.geographie.admin.departement.class
  • lyssal.geographie.admin.pays.class
  • lyssal.geographie.admin.region.class
  • lyssal.geographie.admin.ville.class
  • lyssal.geographie.admin.code_postal.class
  • lyssal.geographie.admin.langue.class

安装

LyssalTourismeBundle 使用 StofDoctrineExtensions,您需要配置它以进行翻译(gedmo_translatable)。

  1. 更新您的 composer.json
"require": {
    "lyssal/geographie-bundle": "*"
}
  1. 安装bundle
php composer.phar update
  1. 更新 AppKernel.php
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new Lyssal\StructureBundle\LyssalStructureBundle(),
new Lyssal\GeographieBundle\LyssalGeographieBundle(),
new Acme\GeographieBundle\AcmeGeographieBundle(),
  1. 更新您的 config.yml
doctrine:
    orm:
        auto_mapping: true
        mappings:
            translatable:
                type: annotation
                alias: Gedmo
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"

stof_doctrine_extensions:
    default_locale: "%locale%"
    orm:
        default:
            translatable: true
            sluggable: true
  1. 在数据库中创建表
php app/console doctrine:schema:update --force

命令

导入数据

清空并导入数据

php app/console lyssal:geographie:database:import

注意:调用此命令时,表格将自动清空。

基础数据填充包括

  • 所有名称为法语和英语的国家
  • 法国的所有地区,名称为法语
  • 法国的所有省份,名称为法语
  • 法国的所有城市,名称为法语和邮编

CSV

为了填充数据库,LyssalGeographieBundle 使用 sql.sh 的 CSV 文件来处理国家、省份和城市。

此作品由 http://sql.sh 提供,遵循 Creative Commons Attribution – Partage dans les Mêmes Conditions 4.0 International 许可协议(http://creativecommons.org/licenses/by-sa/4.0/)。