2017 © Pedro Peláez
 

kohana-module jam-locations

Geoip and IP integration

image

openbuildings/jam-locations

Geoip and IP integration

  • Wednesday, August 9, 2017
  • by hkdobrev
  • Repository
  • 12 Watchers
  • 2 Stars
  • 42,950 Installations
  • PHP
  • 2 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 11 % Grown

The README.md

Jam Locations

Build Status Coverage Status Latest Stable Version, (*1)

This module adds hierarchical locations (continents, countries, cities), by leveraging openbuildings/jam-closuretable. As well as auto initialized ip field and countries / cities set automatically through geolocation., (*2)

Usage

Using ip field is as easy as just defining it:, (*3)

class Model_User extends Jam_Model {

    public static function initialize(Jam_Meta $meta)
    {
        $meta
            ->fields(array(
                // ...
                'ip' => Jam::field('ip'),
            ));
    }
}

$user = Jam::build('user');
echo $user->ip; // will return the current ip address (from Request::$clent_ip)

Auto Location is a bit more involved:, (*4)

class Model_User extends Jam_Model {

    public static function initialize(Jam_Meta $meta)
    {
        $meta
            ->behaviors(array(
                'location_auto' => Jam::behavior('location_auto', array(
                    'locations' => array(
                        // association => geoip record name
                        'city' => 'city',
                        'country' => 'country_name',
                    )
                )),
            ))
            ->associations(array(
                'country' => Jam::association('belongsto', array('foreign_model' => 'location')),
                'city' => Jam::association('belongsto', array('foreign_model' => 'location')),
            ))
            ->fields(array(
                'id' => Jam::field('primary'),
                'ip' => Jam::field('ip'),
            ));
    }
}

Then if you do not set city or country association, it would use the ip field to get a geoip record, and from there try to find / create the appropriate location., (*5)

Lastly the location_parent behavior is used to assign a parent to a location association if both the child and the parent are present in the model:, (*6)

class Model_Address extends Jam_Model {

    public static function initialize(Jam_Meta $meta)
    {
        $meta
            ->behaviors(array(
                'location_parent' => Jam::behavior('location_parent', array(
                    'parents' => array(
                        // child => parent
                        'city' => 'country',
                    )
                )),
            ))
            ->associations(array(
                'country' => Jam::association('belongsto', array('foreign_model' => 'location')),
                'city' => Jam::association('belongsto', array('foreign_model' => 'location')),
            ))
            ->fields(array(
                'id' => Jam::field('primary'),
            ));
    }
}

$address = Jam::build('address');

$address->country = Jam::find('location', 'France');
$address->city = Jam::build('location', array('name' => 'Paris'));

$address->save();

echo $address->city->parent->name(); // will return "France"

Requirement

This module requires php geoip extension., (*7)

License

Copyright (c) 2012-2013, OpenBuildings Ltd. Developed by Ivan Kerin as part of clippings.com, (*8)

Under BSD-3-Clause license, read LICENSE file., (*9)

The Versions

16/04 2014

0.1.2

0.1.2.0 https://github.com/OpenBuildings/jam-locations

Geoip and IP integration

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

geoip city country kohana location

16/04 2014

dev-clippings-commission-fix

dev-clippings-commission-fix https://github.com/OpenBuildings/jam-locations

Geoip and IP integration

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

geoip city country kohana location

26/09 2013

0.1.1

0.1.1.0 https://github.com/OpenBuildings/jam-locations

Geoip and IP integration

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

geoip city country kohana location

25/09 2013

0.1.0

0.1.0.0 https://github.com/OpenBuildings/jam-locations

Geoip and IP integration

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

geoip city country kohana location