SammyK / LaravelFacebookSdk

Fully unit tested Facebook SDK v5 integration for Laravel & Lumen
MIT License
693 stars 201 forks source link

Nested field mappings #47

Closed azec-pdx closed 9 years ago

azec-pdx commented 9 years ago

Let's take a look at this from examples:

class Event extends Eloquent implements UserInterface { protected static $facebook_field_aliases = [ //'facebook_field_name' => 'database_column_name', 'description' => 'description', 'id' => 'facebookId', 'start_time' => 'beginTime' ]; }

Would it be possible to use nested fields from facebook graph object in this mapping? For example I have event graph object that in JSON looks like this:

{ "description": "Đorđe Balašević, jedan od najvećih kantautora u regiji, 25. aprila održat će koncert u Sarajevu, saznaje N1.Balašević će, četiri godine od posljednjeg koncerta u glavnom gradu BiH, ponovo napuniti Zetru.\nKantautor, reditelj, pjesnik i muzičar posljednji koncert u BiH održao je u Mostaru 5. jula 2013. godine. Nakon toga gostovao je diljem regije, a sada je ponovo odlučio \"uploviti\" u BiH sa svojom Panonskom mornaricom.Iako Đorđe Balašević koncerte održava dosta rijetko i selektivno, Sarajevo je grad koji ovaj vrhunski umjetnik uvijek odabere za domaćina svog nastupa. Brojni poklonici lika i djela ovog novosadskog pjesnika, kompozitora, pjevača…, 25. aprila će u Zetri moći uživati u velikom koncertu pod nazivom “Kad tamburama mangupi prepreče put...“ za koji u cijeloj regiji, ali i šire vlada ogromno interesovanje.Nastup će kao i uvijek pratiti besprijekorna tehnička podrška i nesvakidašnja scenografija.Organizator koncerta je Sarajevodisk.", "is_date_only": false, "location": "Zetra, Sarajevo", "name": "Đorđe Balašević \"Kad tamburama mangupi prepreče put...\"", "owner": { "id": "10205257889439204", "name": "Naser Luković" }, "privacy": "OPEN", "start_time": "2015-04-25T20:00:00+0200", "timezone": "Europe/Sarajevo", "updated_time": "2015-02-23T10:31:27+0000", "venue": { "city": "Kosevo", "country": "Bosnia and Herzegovina", "latitude": 43.871558867741, "located_in": "437777029566008", "longitude": 18.409353180232, "street": "22/5 chi lang TP pleiku ting gia lai", "zip": "71000", "id": "292150107482237" }, "id": "960026654009577" }

And I am interested in the venue.street field and want to map it to database field street. Is this possible?

SammyK commented 9 years ago

That's not possible right now, but that would be a super sweet feature to add in the next one. Maybe we could make use of JSONPath for nested field mappings. I'm thinking you could do something like this:

class Event extends Eloquent {
    protected static $facebook_field_aliases = [
        // Normal mapping
        'id' => 'facebook_id',
        // Deep mapping with JSONPath
        '$.venue.street' => 'street',
    ];
}

Does that sound about right? :)

SammyK commented 9 years ago

This is now a feature of 1.3. The JSONPath stuff was overkill for what we needed so I implemented nested parameter syntax for HTTP requests. Let me know if you have any trouble with it! :)