Changeset 6514


Ignore:
Timestamp:
06/15/12 09:32:00 (12 years ago)
Author:
gustavo
Message:

Ticket #2766 - implementacao da dfd0065 e correcao de bugs da dfd0099

Location:
sandbox/2.4.1-3/prototype
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.4.1-3/prototype/api/datalayer.js

    r6361 r6514  
    195195     
    196196    send: function( url, type, data, callback, sync, extraOptions ){ 
    197        
     197 
    198198          var result = false, fired = false; 
    199199       
     
    243243 
    244244          $.ajax( envelope ); 
    245        
    246245          return( result ); 
    247246    }, 
     
    260259        //http://expressodev.prognus.com.br/cristiano/expresso-api/rest/maillast 
    261260        //return this.send( ('rest' + uri), [ 'get', accept || 'json' ], data, callback, !!!callback,  
     261console.log(this.dispatchPath+'../rest'+uri); 
    262262        return this.send( (this.dispatchPath + '../rest' + uri), [ 'get', accept || 'json' ], data, callback, !!!callback,  
    263263        {'beforeSend' : function (xhr){  
     
    277277     
    278278    create: function( uri, data, callback, accept ){ 
    279                 //return this.send( 'rest' + uri, [ 'post', accept || 'json' ], data, callback, !!!callback,  
    280                 return this.send( (this.dispatchPath + '../rest' + uri), [ 'post', accept || 'json' ], data, callback, !!!callback,  
    281                 {'beforeSend' : function (xhr){  
    282                         xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}  
    283                 });       
     279        //return this.send( 'rest' + uri, [ 'post', accept || 'json' ], data, callback, !!!callback,  
     280        return this.send( (this.dispatchPath + '../rest' + uri), [ 'post', accept || 'json' ], data, callback, !!!callback,  
     281        {'beforeSend' : function (xhr){  
     282                //xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}  
     283                xhr.setRequestHeader('Authorization', "OAUTH Bearer " + (DataLayer.me ? DataLayer.me.token : DataLayer.dispatch("../prototype/me").token))}  
     284        });       
    284285    }, 
    285286 
     
    298299        return this.send( (this.dispatchPath + '../rest' + uri), [ 'put', accept || 'json' ], data, callback, !!!callback,  
    299300        {'beforeSend' : function (xhr){  
    300             xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}  
     301            //xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}  
     302                xhr.setRequestHeader('Authorization', "OAUTH Bearer " + (DataLayer.me ? DataLayer.me.token : DataLayer.dispatch("../prototype/me").token))}  
    301303        }); 
    302304       
     
    312314    */ 
    313315 
    314     "delete": function( uri, callback, accept ){ 
    315        
     316    delete: function( uri, callback, accept ){ 
    316317        //return this.send( 'rest' + uri, [ 'delete', accept || 'json' ], false, callback, !!!callback,  
    317318        return this.send( (this.dispatchPath + '../rest' + uri), [ 'delete', accept || 'json' ], false, callback, !!!callback,  
    318319        {'beforeSend' : function (xhr){  
    319             xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}  
     320            //xhr.setRequestHeader('Authorization', "OAUTH Bearer " + DataLayer.me.token)}  
     321                xhr.setRequestHeader('Authorization', "OAUTH Bearer " + (DataLayer.me ? DataLayer.me.token : DataLayer.dispatch("../prototype/me").token))}  
    320322        }); 
    321323       
  • sandbox/2.4.1-3/prototype/services/PostgreSQL.php

    r6357 r6514  
    8989            $map = Config::get($uri['concept'], 'PostgreSQL.mapping'); 
    9090            $criteria = ($criteria !== false) ? $this->parseCriteria ( $criteria , $map , ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\'') : ' WHERE '.$map['id'].' = \''.addslashes( $uri['id'] ).'\''; 
     91 
    9192            return $this->execSql('UPDATE '.(Config::get($uri['concept'],'PostgreSQL.concept')).' '. self::parseUpdateData( $data ,$map).$criteria); 
    9293    } 
     
    199200                    $val[] = '\''.addslashes($v).'\''; 
    200201            } 
    201  
    202 //          return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING '.$map['id'].' as id';        
    203             return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING id';          
     202            return '('.implode(',', $ind).') VALUES ('.implode(',', $val).') RETURNING '.$map['id'].' as id';        
    204203    } 
    205204         
     
    247246                    $query .= ' GROUP BY '.( is_array($criteria["group"]) ? implode(', ', $criteria["group"]) : $criteria["group"] ).' '; 
    248247            } 
    249              
     248    
    250249            if( isset($criteria["order"]) ) 
    251250            { 
    252                     $query .= ' ORDER BY '.self::parseOrder( $criteria["order"], $map ).' '; 
    253             } 
     251                    //Verificar se os atributos para o ORDER BY serao ordenados em ordem decrescente [DESC] 
     252                    $orderDesc = ( isset($criteria["orderDesc"]) && count($criteria["order"]) == count($criteria["orderDesc"]) ) ? $criteria["orderDesc"] : false; 
     253                 
     254                    $query .= ' ORDER BY '.self::parseOrder( $criteria["order"], $map, $orderDesc ).' '; 
     255             
     256            } 
     257 
    254258            if( isset($criteria["limit"]) ) 
    255259            { 
     
    342346    } 
    343347 
    344    private static function parseOrder($order , &$map) 
     348    private static function parseOrder($order , &$map, $orderDesc=false) 
    345349    { 
    346                    
     350 
    347351        if($notArray = !is_array($order)) //Caso seja um full select pegar todas as keys 
    348352            $order = array( $order ); 
     353 
     354        //Caso seja feita ordenacao em ordem descrescente 
     355        //concatenar DESC em cada atributo 
     356        if($orderDesc !== false){ 
     357                if(!is_array($orderDesc)){ 
     358                        $orderDesc = array( $orderDesc ); 
     359                } 
     360 
     361                for($i=0; $i<count($order); $i++){ 
     362                        $order[$i] .= ($orderDesc[$i] === true) ? ' DESC' : ''; 
     363                } 
     364        } 
    349365 
    350366        $return = array(); 
     
    359375        return ( $notArray ?  $order[0] : implode(', ', $order) ); 
    360376    } 
     377 
    361378} 
    362379 
Note: See TracChangeset for help on using the changeset viewer.