Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoordinatesPicker fix for virtual attributes #15

Merged
merged 2 commits into from
Feb 24, 2018
Merged

CoordinatesPicker fix for virtual attributes #15

merged 2 commits into from
Feb 24, 2018

Conversation

karvaka
Copy link
Contributor

@karvaka karvaka commented Feb 16, 2018

I had some problems using ActiveRecord virtual attributes with CoordinatesPicker.
This pull request enables usage of this feature and allows make things like following:

<?php
namespace common\models;

/**
 * Table schema attributes.
 * @property double $latitude
 * @property double $longitude
 *
 * Overloaded attribute.
 * @property string|null $coordinates
 */
class SomePlace extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['coordinates', 'required'],
            ['coordinates', 'string']
        ];
    }

    /**
     * @return null|string
     */
    public function getCoordinates()
    {
        if (!$this->latitude || !$this->longitude) {
            return null;
        }
        return $this->latitude . ',' . $this->longitude;
    }

    /**
     * @param $coordinates
     */
    public function setCoordinates($coordinates)
    {
        $parts = explode(',', $coordinates);
        if (count($parts) === 2) {
            list($this->latitude, $this->longitude) = $parts;
        }
    }
}

This approach seems very efficient for me.
Much easier to integrate in comparison with this one https://github.com/pigochu/yii2-jquery-locationpicker/blob/master/doc/TWO-FIELDS-CONVERSION.md.
Thanks.

@pigochu
Copy link
Owner

pigochu commented Feb 17, 2018

Could you pull to branch dev again ?
I will test it .
Thank you.

@karvaka karvaka changed the base branch from master to dev February 17, 2018 01:32
@pigochu pigochu merged commit 2e574db into pigochu:dev Feb 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants