yit/geo-bridge-bundle

此包已被废弃且不再维护。没有建议的替代包。

安装: 483

依赖: 0

建议者: 0

安全性: 0

星星: 0

关注者: 13

分支: 0

开放性问题: 0

类型:symfony-bundle

v1.2.4 2015-07-06 11:22 UTC

This package is not auto-updated.

Last update: 2017-06-19 08:35:16 UTC


README

安装

步骤1:使用Composer下载GeoBridgeBundle

在您的composer.json中添加GeoBridgeBundle

{
    "require": {
        ...
        "yit/geo-bridge-bundle": "dev-master",
    }
}

现在更新composer.phar

Composer会将此包安装到您的项目的vendor/yit目录中。

步骤2:启用该包

在内核中启用该包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Yit\GeoBridgeBundle\YitGeoBridgeBundle(),
    );
}

如果您将在项目中使用geo_address表单字段

步骤3:在app/config/config.yml中添加以下配置

# app/config/config.yml
twig:
    /...
    form:
            resources:
                - 'YitGeoBridgeBundle:Geo:address.html.twig'

步骤4:导入GeoBridgeBundle路由文件

# app/config/routing.yml
yit_geo_bridge:
    resource: "@YitGeoBridgeBundle/Resources/config/routing.yml"
    prefix:   /

然后从Bower添加YitAutocomplete Angularjs模块

然后您可以添加一个新的表单字段`

$this->createFormBuilder()
             ...
             ->add('address', 'geo_address', array('attr' => array('data_id' => 1)))
             ...

data_id属性对于每个geo_address字段必须是唯一的。您也可以向表单字段添加其他属性。

$this->createFormBuilder()
             ...
             $transformer = $this->container->get('yit_geo_address_trasnformer');

             ->add(
             $builder->create('address', 'geo_address', array(
                'attr' => array(
                    'data_id'       => 1,                   //must be unique for each such field
                    'placeholder'   => 'text for input',    //placeholder text
                    'allow_new'     => true,                //set true to show new button when address not found
                    'button_name'   => 'buttonName',        //text to show on new button
                    'button_class'  => 'buttonClass',       //new button class
                    'input_class'   => 'inputClass'         //input class
                )))
                ->addModelTransformer($transformer))        //call address Data transformer
             ...

            // in controller call YourFormType
             $form = $this->createForm(new YourFormType($this->container));

然后您可以在Sonata Admin中添加地址表单字段

namespace Project\MyBundle\Admin;

    protected function configureFormFields(FormMapper $formMapper){

            $container = $this->configurationPool->getContainer();
            $transformer = $container->get('yit_geo_address_trasnformer');

            $formMapper
                ->add(
                    $formMapper->create('address', 'geo_address',  array(
                        'attr' => array(
                            'data_id'       => 1,
                            'placeholder'   => 'text for input',
                            'allow_new'     => true,
                            'button_name'   => 'buttonName',
                            'button_class'  => 'buttonClass',
                            'input_class'   => 'inputClass'
                        )))
                        ->addModelTransformer($transformer))
    }

    public function getFormTheme(){

            return array_merge(
                parent::getFormTheme(),
                array('YitGeoBridgeBundle:Admin:geo_admin.html.twig' )
            );
    }

在Sonata Admin模板中添加js

    <script src="{{ asset('app/bower_components/YitAutocomplete/yitAutocomplete.js') }}"></script>
    <script src="{{ asset('bundles/yitgeobridge/javascript/geo.js') }}" type="text/javascript"></script>
    <script src="{{ asset('bundles/yitgeobridge/javascript/yiInput.js') }}" type="text/javascript"></script>
    <script src="{{ asset('bundles/yitgeobridge/javascript/GeoAutocomplete.js') }}" type="text/javascript"></script>

步骤5:使用运行命令配置GeoBridgeBundle同步(在Composer安装或更新后)

在您的composer.json中添加RunManageGeoStoredProcedureCommand

{
 "scripts": {
        "post-install-cmd": [
            "Yit\\GeoBridgeBundle\\Command\\ManageGeoStoredProcedureCommand::manageGeoStoredProcedure"
        ],
        "post-update-cmd": [
            "Yit\\GeoBridgeBundle\\Command\\ManageGeoStoredProcedureCommand::manageGeoStoredProcedure"
        ]
    },
}

现在包已配置并准备好使用,如果您需要在实体地址、街道或区域中使用与GeoBundle地址、街道和区域相关联的功能,那么您将需要在您的实体中相应地实现AddressableInterface、StreetableInterface、MultiAddressableInterface、DistrictableInterface和其他接口。然后当您从数据库加载数据时,GeoBridgeBundle将自动调用接口函数与相应的参数,以设置所有必要的信息。

此处接口实现


namespace Yit\GeoBridgeBundle\Model;

//This interface is used when entity has an district_id field
interface DistrictableInterface
{
    //This function is used to get district id, the fields of which must be injected
    public function getDistrictId();

    //This function is used to inject district title
    public function setDistrictTitle($title);
}


namespace Yit\GeoBridgeBundle\Model;

//This interface is used when entity has street_id field
interface StreetableInterface
{
    //This function is used to get street id, the fields of which must be injected
    public function getStreetId();

    //This function is used to inject street arm_name
    public function setStreetArmName($armName);

    //This function is used to inject street eng_name
    public function setStreetEngName($engName);
}


namespace Yit\GeoBridgeBundle\Model;

//This interface is used when entity has an address_id and district_id
//fields to set district id based on address id
interface AddressDistrictableInterface
{
    //This function is used to get address id
    public function getAddressId();

    //This function is used to inject district id
    public function setDistrictId($id);

    //This function is used to get district id
    public function getDistrictId();
}


namespace Yit\GeoBridgeBundle\Model;

/**
 * This interface is used when entity has an address_id and district_id
 * fields to set district id based on address id
 * district id is set from geo project, and if it is empty persist it, if does not match only set district id without persist
 */
interface AddressDistrictAwareInterface extends AddressDistrictableInterface
{

}


namespace Yit\GeoBridgeBundle\Model;

/**
 * This interface is used when entity has an address_id and street_id
 * fields to set street id based on address id
 * street id is set from geo project and persist it is empty
 */
interface AddressStreetableInterface
{
    //This function is used to get address id
    public function getAddressId();

    //This function is used to inject street id
    public function setStreetId($id);

    //This function is used to get street id
    public function getStreetId();

    //This function is used to get streetId field name
    public function getStreetFieldName();
}


namespace Yit\GeoBridgeBundle\Model;

/**
 * This interface is used when entity has an address_id and street_id
 * fields to set street id based on address id
 * street id is set from geo project and persist it is empty, if does not match only set street id without persist
 */
interface AddressStreetAwareInterface extends AddressStreetableInterface
{

}

您还可以使用'yit_geo'服务来使用一些功能,这里有一些

//This function return address object from main Geo project by given id
//If there are not any address with such id return null
public function getAddressById($id)

//This function return address object by given id and create it in yit_geo_address table
//If there are not any address with such id return Exception('Address not found!')
public function getAddressObjectById($id)

//This function is used get address synonym ids
public function getSynonymIds($addressId)

//This function is used to get $limit addresses by $search string
//If there are not any address with such content return null
public function searchAddress($search, $limit = 0)

//This function is used to get $limit streets or addresses by $search string
//If there are not any address with such content return null
public function searchFlexibleAddress($search, $limit = 0)

//This function is used to create new address in Geo Project with $addressString title
//when access return id of created Address else return null
public function putAddress($addressString)

//This function is used to get addresses by given id's array
public function getAddresses(array $ids)

//This function is used to create new address in Geo Project with $street, $streetType, $district & $hNumber title
//when access return id of created Address else return null
public function putNewAddress($street, $streetType, $district, $hNumber)

//This function is used to get addresses by $street, $type and $hNumber string
//If there are not any address with such content return null
public function findAddress($street, $type, $hNumber)

//This function return district object by given id
//If there are not any district with such id return null
public function getDistrictById($id)

//This function is used to get districts
//If there are not any district return null
public function getDistricts()

//This function is used to get districts in array 'id' => 'title'
//If there are not any district return empty array
public function getDistrictList()

//This function is used to get all streets by district id
//If there are not any street return null
public function getStreetsByDistrict($districtID)

//This function is used to get district by $search string
//If there are not any district with such content return null
public function searchDistrict($search)

//This function is used get street by given id
//If there are not any street by given id return null
public function getStreetById($id)

//This function is used get street by given address id
//If there are not any address by given id return null
public function getStreetByAddressId($id)

//This function is used to get $limit streets by $search string
//If there are not any street with such content return null
public function searchStreet($search, $limit = 0)

//This function is used to get $limit streets by $search string
//If there are not any street with such content return null
public function searchStreetFlexible($search, $limit = 0)

//This function is used to get $limit streets by $search string and district id
//If there are not any street with such content return null
public function getSearchStreetsByDistrict($search, $district, $limit = 0)

此包使用apc_cache,默认情况下将地址缓存24小时,您可以通过在config.yml中添加以下内容来更改缓存时间

yit_geo_bridge:
    experience: experience_time_in_seconds

您还可以在配置中添加项目名称以将其保存到地理项目中,这通过在config.yml中添加以下内容来完成

yit_geo_bridge:
    project_name: your_project_name

您还可以在配置中添加Geo主项目域名。如果为空,此配置默认为http://geo.yerevan.am/

yit_geo_bridge:
    project_domain: your_project_domain_route