YUI.add('pnm-place', function (Y) {

var FLICKR_ENV = YUI.namespace('Env.Flickr'),

    Lang = Y.Lang,
    Place;

Place = Y.Base.create('place', Y.Model, [Y.ModelSync.YQL], {

    idAttribute: 'woeid',
    cache      : new Y.CacheOffline(),

    queries: {
        placeFromId    : 'SELECT {attrs} FROM geo.places WHERE woeid={id}',
        placeFromText  : 'SELECT {attrs} FROM geo.places WHERE text="{text}"',
        placeFromLatLon: 'SELECT {attrs} FROM geo.places WHERE woeid ' +
                            'IN (SELECT place.woeid FROM flickr.places ' +
                            'WHERE api_key={api_key} ' +
                            'AND lat={latitude} ' +
                            'AND lon={longitude})'
    },

    buildQuery: function (options) {
        if (this.isNew()) {
            if (options.text) {
                return Lang.sub(this.queries.placeFromText, {
                    text : options.text,
                    attrs: Place.YQL_ATTRS
                });
            }

            // assumes we at least have a lat/lon
            return Lang.sub(this.queries.placeFromLatLon, {
                api_key  : FLICKR_ENV.API_KEY || '',
                latitude : this.get('latitude'),
                longitude: this.get('longitude'),
                attrs    : Place.YQL_ATTRS
            });
        }

        return Lang.sub(this.queries.placeFromId, {
            id   : this.get('id'),
            attrs: Place.YQL_ATTRS
        });
    },

    parse: function (results) {
        if (!results) { return; }

        var place    = results.place,
            data     = Lang.isArray(place) ? place[0] : place,
            centroid = data.centroid,
            country  = data.country,
            region   = data.admin1,
            locality = data.locality1;

        return {
            woeid    : data.woeid,
            latitude : centroid.latitude,
            longitude: centroid.longitude,
            country  : country && country.content,
            region   : region && region.content,
            locality : locality && locality.content
        };
    },

    toString: function () {
        var country  = this.get('country'),
            region   = this.get('region'),
            locality = this.get('locality');

        if (locality) {
            return (locality + ', ' + region);
        }

        if (region) {
            return (region + ', ' + country);
        }

        return country || '';
    }

}, {

    ATTRS: {
        woeid    : {},
        latitude : {},
        longitude: {},
        country  : {},
        region   : {},
        locality : {}
    },

    YQL_ATTRS: ['woeid', 'centroid', 'country', 'admin1', 'locality1']

});

Y.namespace('PNM').Place = Place;

}, '0.6.0', {
    requires: [
        'cache-offline',
        'gallery-model-sync-yql',
        'model',
        'yql'
    ]
});

@@ -298,33 +298,38 @@
 %7D FROM geo.place
-s
+finder
  WHERE woeid=%7Bid
@@ -383,25 +383,30 @@
 OM geo.place
-s
+finder
  WHERE text=
@@ -471,17 +471,22 @@
 eo.place
-s
+finder
  WHERE w
@@ -490,16 +490,19 @@
 E woeid 
+IN 
 ' +%0A    
@@ -526,19 +526,16 @@
        '
-IN 
 (SELECT 
@@ -565,16 +565,22 @@
 .places 
+WHERE 
 ' +%0A    
@@ -604,22 +604,16 @@
        '
-WHERE 
 api_key=
@@ -626,93 +626,27 @@
 ey%7D 
-' +%0A                            'AND lat=%7Blatitude%7D ' +%0A                            '
+AND lat=%7Blatitude%7D 
 AND 
@@ -968,15 +968,14 @@
  // 
-a
+A
 ssume
-s
  we 
@@ -997,16 +997,17 @@
  lat/lon
+.
 %0A       
@@ -1508,19 +1508,16 @@
 r place 
-   
 = result
@@ -1522,226 +1522,14 @@
 lts.
-place,%0A            data     = Lang.isArray(place) ? place%5B0%5D : place,%0A            centroid = data.centroid,%0A            country  = data.country,%0A            region   = data.admin1,%0A            locality = data.locality1
+Result
 ;%0A%0A 
@@ -1571,12 +1571,13 @@
   : 
-data
+place
 .woe
@@ -1603,24 +1603,21 @@
 itude : 
-centroid
+place
 .latitud
@@ -1642,24 +1642,21 @@
 gitude: 
-centroid
+place
 .longitu
@@ -1686,34 +1686,21 @@
   : 
+place.
 country
- && country.content
 ,%0A  
@@ -1724,32 +1724,19 @@
   : 
-region && region.content
+place.state
 ,%0A  
@@ -1760,36 +1760,18 @@
 y : 
-locality && locality.content
+place.city
 %0A   
@@ -2339,50 +2339,57 @@
 ', '
-centroid', 'country', 'admin1', 'local
+latitude', 'longitude', 'country', 'state', 'c
 ity
-1
 '%5D%0A%0A

Update YQL queries for Place model.