Ignore:
Timestamp:
01/27/12 15:37:21 (12 years ago)
Author:
cristiano
Message:

Ticket #2434 - Atualização modulo agenda e API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/prototype/api/controller.php

    r5415 r5437  
    6363            return self::$cache->put( $id, $data, $expires, $compressed ); 
    6464        } 
    65  
    66         public static function put( $URI, $data, $txIds = false ) 
    67         { 
    68             try 
    69             { 
    70                 $URI = self::serviceName( $URI ); 
    71  
    72                 if( $commit = !$txIds ) 
    73                             $txIds = array(); 
    74  
    75                 if( !isset( self::$tx[ $URI['service'] ] ) ) 
    76                 { 
    77                             self::call( 'begin', $URI ); 
    78                             self::$tx[ $txIds[] = $URI['service'] ] = array(); 
    79             } 
    80  
    81                 $method = $data ? isset( $data['id'] ) ? 
    82                           'update' : 'create' : 'delete'; 
    83  
    84                 $links = self::links( $URI['concept'] ); 
    85  
    86                 $Tx = array( 'order' => self::$txID++ ); 
    87  
    88                 $postpone = array(); 
    89  
    90                 if( $data ) 
    91                 { 
    92                     $URI['id'] = isset( $data['id'] ) ? $data['id'] : false; 
    93  
    94                     foreach( $links as $linkName => $linkTarget ) 
    95                     { 
    96                                 if( isset( $data[$linkName] ) && is_array( $data[$linkName] ) ) 
    97                                 { 
    98                                         if( self::isConcept( $linkName ) ) 
    99                                                 $data[$linkName] = self::put( array( 'concept' => $linkTarget ), $data[$linkName], &$txIds ); 
    100                                         else 
    101                                                 $postpone[$linkTarget] = $data[$linkName]; 
    102                                 } 
    103         } 
    104                 } 
    105                 else 
    106                   $URI['id'] = isset( $data['id'] ) ? $data['id'] : $URI['id']; 
    107  
    108                 $result = Controller::call( $method, $URI, $data, false, false, true ); 
    109  
    110                 if( !is_bool( $result ) && !is_string( $result ) && isset( $result['id'] ) ) 
    111                       $URI['id'] = $result['id']; 
    112  
    113                 self::$tx[ $URI['service'] ][] = array_merge( $Tx, array( 'id' => $URI['id'], 'concept' => $URI['concept'], 'method' => $method, 'service' => $URI['service'], 'rollback' => !!!$result ) ); 
    114  
    115                 foreach( $postpone as $linkTarget => $dt ) 
    116                       foreach( $dt as $ii => $value ) 
    117         { 
    118                           if( !is_array( $value ) ) 
    119                             $value = array( 'id' => $value ); 
    120  
    121                           $value[ $URI['concept'] ] = $URI['id']; 
    122  
    123                           self::put( array( 'concept' => $linkTarget ), $value, &$txIds ); 
    124         } 
    125  
    126                 if( $commit ) 
    127         { 
    128                       $result = array(); 
    129  
    130                       for( $i = count( $txIds ) - 1; $i >= 0; $i-- ) 
    131                       { 
    132                               $currentTx = self::$tx[ $txIds[$i] ]; 
    133                               unset( self::$tx[ $txIds[$i] ] ); 
    134  
    135                               if( !self::commit( array( 'service' => $txIds[$i] ), $currentTx ) ) 
    136                               { 
    137                                   self::rollback( array( 'service' => $txIds[$i] ), $currentTx ); 
    138  
    139                                   foreach( $currentTx as $i => $st ) 
    140                                       $currentTx[$i][ 'rollback' ] = true; 
    141         } 
    142  
    143                               $result = array_merge( $result, $currentTx ); 
    144                       } 
    145                            
    146                           self::$txID = 0; 
    147  
    148                       return( $result ); 
    149                 } 
    150  
    151             } 
    152             catch( Exception $e ) 
    153         { 
    154                 if( !self::fallback( $e ) ) 
    155                     self::closeAll(); 
    156  
    157                 return( false ); 
    158             } 
    159          
    160             return( $URI['id'] ); 
    161         } 
    162          
    163         public static function get() 
    164             { 
    165              
    166             } 
    16765 
    16866        public static function find( $URI, $params = false, $criteria = false ) 
     
    462360            $result = array( $eventType => array() ); 
    463361         
    464         if( is_array( $commitList ) ) 
     362            if( is_array( $commitList ) ) 
    465363                foreach( $commitList as $i => $tx ) 
    466364                { 
     
    536434 
    537435        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmos nas options passadas 
    538         public static function call( $method, $URI, $properties = false, $options = false, $service = false, $noTX = false ) 
     436        public static function call( $method, $URI, $properties = false, $options = false, $service = false ) 
    539437        { 
    540438            try 
     
    550448                    return( empty($params['properties']) ? false : $params['properties'] ); 
    551449 
     450                 
     451 
    552452                if( $params && !$params['service'] ) 
    553453                { 
     
    559459                if( isset($params['URI']['service']) ) 
    560460                { 
    561                     if( $commit = (!isset(self::$tx[ $params['URI']['service'] ]) && ( $method === 'create' || 
    562                                                                                        $method === 'update' || 
    563                                                                                        $method === 'delete' )) ) 
     461                    if( $method === 'create' || $method === 'update' || $method === 'delete' ) 
    564462                    { 
    565                         self::call( 'begin', $params['URI'] ); 
    566                         self::$tx[ $params['URI']['service'] ] = true; 
     463                        if( $commit = !isset(self::$tx[ $params['URI']['service'] ])  ) 
     464                        { 
     465                            self::call( 'begin', $params['URI'] ); 
     466                        } 
     467 
     468                        $TX = array(); 
    567469                    } 
    568470 
     
    573475                if( $params['service'] ) 
    574476                    switch( $method ) 
    575             {  
     477                    {  
    576478                        case 'find': $return = $params['service']->find( $params['URI'], $params['properties'], $params['criteria'] ); break; 
    577479 
     
    596498                        case 'parse': $return = $params['service']->parse( $params['properties'], $params['criteria'] ); break; 
    597499 
     500                        case 'analize': $return = $params['service']->analize( $params['properties'], $params['criteria'] ); break; 
     501 
    598502                        case 'format': $return = $params['service']->format( $params['properties'], $params['criteria'] ); break; 
    599                          
    600                         default:  $return = $params['service']->$method( $params['properties'], $params['criteria'] ); break; 
    601             } 
     503 
     504                        default : $return = $params['service']->$method( $params['properties'], $params['criteria'] ); 
     505                    } 
    602506 
    603507                if( isset($return) && $return !== false ) 
     
    605509 
    606510                if( isset($params['URI']['service']) ) 
    607                 { 
    608511                    if( !self::fire( 'after', $method, $params, $original, true ) ) 
    609512                        return( empty($params['properties']) ? false : $params['properties'] ); 
    610513 
    611                     if( $commit ) 
     514                if( isset($URI['concept']) ) 
     515                    self::fire( 'after', $method, $params, $original ); 
     516 
     517                if( empty($params['properties']) ) 
     518                    $params['properties'] = false; 
     519 
     520                if( isset( $TX ) ) 
     521                { 
     522                    $TX['rollback'] = !!!$params['properties']; 
     523 
     524                    if( $params['properties'] && isset($params['properties']['id']) ) 
     525                        $TX['id'] = $params['properties']['id']; 
     526 
     527                    self::$tx[ $params['URI']['service'] ][] = array_merge( $TX, $original['URI'], array( 'service' => $params['URI']['service'], 'method' => $method ) ); 
     528 
     529                    if( isset($commit) && $commit ) 
    612530                    { 
    613531                        if( !self::call( 'commit', $params['URI'], false, self::$tx[ $params['URI']['service'] ] ) ) 
     
    617535                    } 
    618536                } 
    619  
    620                 if( isset($URI['concept']) && !self::fire( 'after', $method, $params, $original ) ) 
    621                     return( empty($params['properties']) ? false : $params['properties'] ); 
    622537            } 
    623538            catch( Exception $e ) 
     
    629544            } 
    630545 
    631             return( empty($params['properties']) ? false : $params['properties'] ); 
     546            return( $params['properties'] );  
    632547        } 
    633548 
     
    637552            return( true ); 
    638553        } 
     554 
     555        public static function put( $URI, $data, $txIds = false ) 
     556        { 
     557            try 
     558            { 
     559                $URI = self::serviceName( $URI ); 
     560 
     561                if( $commit = !$txIds ) 
     562                    $txIds = array(); 
     563 
     564                if( !isset( self::$tx[ $URI['service'] ] ) ) 
     565                { 
     566                    self::call( 'begin', $URI ); 
     567                    self::$tx[ $txIds[] = $URI['service'] ] = array(); 
     568                } 
     569 
     570                $method = $data ? isset( $data['id'] ) ? 
     571                          'update' : 'create' : 'delete'; 
     572 
     573                $links = self::links( $URI['concept'] ); 
     574 
     575                $order = self::$txID++; 
     576 
     577                $postpone = array(); 
     578 
     579                if( $data ) 
     580                { 
     581                    $URI['id'] = isset( $data['id'] ) ? $data['id'] : false; 
     582 
     583                    foreach( $links as $linkName => $linkTarget ) 
     584                    { 
     585                        if( isset( $data[$linkName] ) && is_array( $data[$linkName] ) ) 
     586                        { 
     587                            if( self::isConcept( $linkName ) ) 
     588                                    $data[$linkName] = self::put( array( 'concept' => $linkTarget ), $data[$linkName], &$txIds ); 
     589                            else 
     590                                    $postpone[$linkTarget] = $data[$linkName]; 
     591                        } 
     592                    } 
     593                } 
     594                else 
     595                  $URI['id'] = isset( $data['id'] ) ? $data['id'] : $URI['id']; 
     596 
     597                $result = Controller::call( $method, $URI, $data, false, false, true ); 
     598 
     599                if( !is_bool( $result ) && !is_string( $result ) && isset( $result['id'] ) ) 
     600                      $URI['id'] = $result['id']; 
     601 
     602                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['order'] = $order; 
     603                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['id'] = $URI['id']; 
     604 
     605                foreach( $postpone as $linkTarget => $dt ) 
     606                      foreach( $dt as $ii => $value ) 
     607                      { 
     608                          if( !is_array( $value ) ) 
     609                            $value = array( 'id' => $value ); 
     610 
     611                          $value[ $URI['concept'] ] = $URI['id']; 
     612 
     613                          self::put( array( 'concept' => $linkTarget ), $value, &$txIds ); 
     614                      } 
     615 
     616                if( $commit ) 
     617                { 
     618                      $result = array(); 
     619 
     620                      for( $i = count( $txIds ) - 1; $i >= 0; $i-- ) 
     621                      { 
     622                              $currentTx = self::$tx[ $txIds[$i] ]; 
     623                              unset( self::$tx[ $txIds[$i] ] ); 
     624 
     625                              if( !self::commit( array( 'service' => $txIds[$i] ), $currentTx ) ) 
     626                              { 
     627                                  self::rollback( array( 'service' => $txIds[$i] ), $currentTx ); 
     628 
     629                                  foreach( $currentTx as $i => $st ) 
     630                                      $currentTx[$i][ 'rollback' ] = true; 
     631                              } 
     632 
     633                              $result = array_merge( $result, $currentTx ); 
     634                      } 
     635 
     636                      self::$txID = 0; 
     637 
     638                      return( $result ); 
     639                } 
     640 
     641            } 
     642            catch( Exception $e ) 
     643            { 
     644                if( !self::fallback( $e ) ) 
     645                    self::closeAll(); 
     646 
     647                return( false ); 
     648            } 
     649         
     650            return( $URI['id'] ); 
     651        } 
     652         
     653        public static function get() 
     654        { 
     655         
     656        } 
    639657} 
    640658 
Note: See TracChangeset for help on using the changeset viewer.