source: sandbox/2.4.1-3/prototype/api/controller.php @ 6357

Revision 6357, 23.3 KB checked in by gustavo, 12 years ago (diff)

Ticket #2768 - Melhorias na inserção de destinatários na criacao de mensagem

Line 
1<?php
2/**
3 *
4 * Copyright (C) 2012 Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
5 *
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by
8 * the Free Software Foundation with the addition of the following permission
9 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
10 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
11 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program; if not, see www.gnu.org/licenses or write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA.
22 *
23 * This code is based on the OpenXchange Connector and on the Prognus pSync
24 * Connector both developed by the community and licensed under the GPL
25 * version 2 or above as published by the Free Software Foundation.
26 *
27 * You can contact Prognus Software Livre headquarters at Av. Tancredo Neves,
28 * 6731, PTI, Edifício do Saber, 3º floor, room 306, Foz do Iguaçu - PR - Brasil or at
29 * e-mail address prognus@prognus.com.br.
30 *
31 * Classe de controle que faz manipulações de fluxo de informações para toda
32 * a API a partir de vários métodos.
33 *
34 * @package    Prototype
35 * @license    http://www.gnu.org/copyleft/gpl.html GPL
36 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
37 * @version    2.4
38 * @sponsor    Caixa Econômica Federal
39 * @since      Arquivo disponibilizado na versão 2.4
40 */
41
42if( !defined( 'ROOTPATH' ) )
43    define( 'ROOTPATH', dirname(__FILE__).'/..' );
44
45require_once(ROOTPATH.'/api/config.php');
46use prototype\api\Config as Config;
47
48/**
49TODO list:
50
51  * definir de forma centralizada os caminhos e as constantes necessárias;
52  * criar um User Agent detect e um OS server detect para customizações espeçíficas de cada browser / servidor;
53  * criar um registrador para fallback handlers;
54  * criar um dependency manager na configuração dos serviços, para poder gerenciar os imports corretamente
55  * criar um login e a recuperação da sessão;
56
57*/
58
59/**
60 *
61 * @package    Prototype
62 * @license    http://www.gnu.org/copyleft/gpl.html GPL
63 * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
64 * @version    2.4
65 * @sponsor    Caixa Econômica Federal
66 * @since      Classe disponibilizada na versão 2.4
67 */
68class Controller {
69
70        static $cache;
71        static $services = array();
72        static $interceptors = array();
73        static $config = array();
74        static $includes = array();
75        static $tx = array();
76        static $isConcept = array();
77        static $hasOne = array();
78        static $fallbackHandlers = array();
79        static $txID = 0;
80        static $wallet;
81
82        public function __destruct()
83        {
84//          if( $this->service )
85//              $this->service->close();
86//          else
87            self::closeAll();
88        }
89
90        public static function closeAll()
91        {
92            if( self::$services )
93                foreach( self::$services as $serviceName => $service )
94                    if( self::$config[ $serviceName ]['type'] === 'service' )
95                      $service->close();
96        }
97
98        public static function clearAll()
99            {
100            return self::$cache->clearAll();
101            }
102
103        public static function clear( $id )
104        {
105            return self::$cache->clear( $id );
106        }
107
108        public static function check( $id )
109        {
110            return self::$cache->get( $id );
111        }
112
113        public static function store( $id, $data, $expires, $compressed )
114        {
115            return self::$cache->put( $id, $data, $expires, $compressed );
116        }
117
118        public static function find( $URI, $params = false, $criteria = false )
119        {
120            if( isset($URI['id']) && $URI['id'] )
121                return self::read( $URI, $params, $criteria );
122           
123            return self::call( 'find', $URI, $params, $criteria );
124        }
125
126        public static function read( $URI, $params = false, $criteria = false )
127        {
128            if( !isset($URI['id']) || !$URI['id'] )
129                return self::find( $URI, $params, $criteria );
130
131            return self::call( 'read', $URI, $params, $criteria );
132        }
133
134        public static function deleteAll( $URI, $params = false, $criteria = false )
135        {
136            if( isset($URI['id']) && $URI['id'] )
137                return self::delete( $URI, $params, $criteria );
138
139            return self::call( 'deleteAll', $URI, $params, $criteria );
140        }
141
142        public static function delete( $URI, $params = false, $criteria = false )
143        {
144            if( !isset($URI['id']) || !$URI['id'] )
145                return self::deleteAll( $URI, $params, $criteria );
146
147            return self::call( 'delete', $URI, $params, $criteria );
148        }
149
150        public static function replace( $URI, $params, $criteria = false )
151        {
152            if( isset($URI['id']) && $URI['id'] )
153                return self::update( $URI, $params, $criteria );
154
155            return self::call( 'replace', $URI, $params, $criteria );
156        }
157
158        public static function update( $URI, $params, $criteria = false )
159        {
160            if( !isset($URI['id']) || !$URI['id'] )
161                return self::replace( $URI, $params, $criteria );
162
163            return self::call( 'update', $URI, $params, $criteria );
164        }
165
166        public static function create( $URI, $params, $criteria = false )
167        {
168            return self::call( 'create', $URI, $params, $criteria );
169        }
170
171        public static function begin( $URI, $params = false, $criteria = false )
172        {
173            return self::call( 'begin', $URI, $params, $criteria );
174        }
175
176        public static function commit( $URI, $criteria = false )
177            {
178            return self::call( 'commit', $URI, false, $criteria );
179        }
180
181        public static function rollback( $URI, $criteria = false )
182        {
183            return self::call( 'rollback', $URI, false, $criteria );
184        }
185
186        public static function format( $URI, $params, $criteria = false )
187        {
188            return self::call( 'format', $URI, $params, $criteria );
189        }
190
191        public static function parse( $URI, $data, $criteria = false )
192        {
193            return self::call( 'parse', $URI, $data, $criteria );
194            }
195
196        public static function URI( $className, $id = false, $service = false )
197        {
198            return array( 'concept' => $className,
199                          'service' => $service ? $service : false,
200                          'id' => $id ? $id : '' );
201        }
202
203        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
204        public static function links( $concept = false, $linkage = false )
205        {
206           
207
208            if( !isset(self::$config[ $concept ]) )
209              self::$config[ $concept ] = self::loadConfig( $concept );
210
211            $links = array();
212            self::$isConcept[ $concept ] = array();
213            self::$hasOne[ $concept ] = array();
214
215            if( isset(self::$config[ $concept ][ 'model.hasOne' ]) )
216                foreach( self::$config[ $concept ][ 'model.hasOne' ] as $linkName => $linkTarget )
217                {
218                    list( $target, $link ) = explode( '.', $linkTarget );
219
220                    if( $linkage === $linkName )
221                        $return = $link;
222
223                    $links[$linkName] = $target;
224                    self::$hasOne[ $concept ][ $linkName ] = true;
225                }
226            if( isset(self::$config[ $concept ][ 'model.depends' ]) )
227                foreach( self::$config[ $concept ][ 'model.depends' ] as $linkName => $linkTarget )
228                {
229                    list( $target, $link ) = explode( '.', $linkTarget );
230
231                     if( $linkage === $linkName )
232                        $return = $link;
233
234                    $links[$linkName] = $target;
235                    self::$hasOne[ $concept ][ $linkName ] = true;
236                    self::$isConcept[ $concept ][ $linkName ] = true;
237                }
238            if( isset(self::$config[ $concept ][ 'model.hasMany' ]) )
239                foreach( self::$config[ $concept ][ 'model.hasMany' ] as $linkName => $linkTarget )
240                {
241                    list( $target, $link ) = explode( '.', $linkTarget );
242
243                     if( $linkage === $linkName )
244                        $return = $link;
245
246                    $links[$linkName] = $target;
247                }
248
249            return( isset($return) ? $return : $links );
250        }
251
252        public static function isConcept( $concept, $linkName )
253        {
254            if( !isset( self::$isConcept[ $concept ] ) )
255                self::links( $concept );
256
257            return( isset(self::$isConcept[ $concept ][ $linkName ]) );
258        }
259
260        public static function hasOne( $concept, $linkName )
261        {
262            if( !isset( self::$hasOne[ $concept ] ) )
263                self::links( $concept );
264
265            return( isset(self::$hasOne[ $concept ][ $linkName ]) );
266        }
267
268        public static function getConcept( $concept, $moduleName = false )
269        {
270            if( isset( self::$config[ $concept ] ) )
271                return( self::$config[ $concept ] );
272
273            return( self::$config[ $concept ] = self::loadConfig( $concept, $moduleName ) );
274        }
275
276        public static function loadCache( $cacheType = 'Memory' )
277        {
278            include_once( "cache/MemoryCache.php" );
279            return new MemoryCache();
280        }
281
282        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
283        public static function loadConfig( $className, $isService = false)
284        {
285            $fileName = $className.'.'.($isService ? 'srv' : 'ini');
286
287            $config = self::$cache->get( $fileName );
288       
289            if( !$config )
290            {
291                $config = parse_ini_file( ROOTPATH.'/config/'.$fileName, true );
292
293                self::$cache->put( $fileName, $config );
294            }
295
296            return( $config );
297        }
298
299        public static function import( $path, $ext = ".php" )
300        {
301            if( !isset(self::$includes[$path]) )
302        {
303                require_once( ROOTPATH.'/'.$path.$ext );
304                self::$includes[$path] = false;
305            }
306
307            return( self::$includes[$path] );
308        }
309
310        public static function load( $path, $class = false )
311            {
312            if( $return = self::import( $path, "" ) )
313                return( $return );
314
315            if( !$class ){
316                preg_match( '/^\/?.*\/([^\/]+).php$/', $path, $class );
317                $class = $class[1];
318            }
319
320            $object =  self::$cache->get( $class );
321
322            if( !$object )
323            {
324                $object = new $class();
325                 self::$cache->put( $class, $object );
326            }
327
328            self::$includes[$path] = $object;
329
330            return( $object );
331        }
332
333        public static function wallet( $serviceName )
334        {
335            if( !isset( self::$wallet ) )
336            {
337                //// Hack //// TODO: passar o init da sessão no login do expresso
338                Config::init();
339
340                if(isset($_SESSION['wallet']))
341                    self::$wallet = $_SESSION['wallet'];
342                /////////////
343            }
344
345            return isset( self::$wallet[ $serviceName ] )? self::$wallet[ $serviceName ] : false;
346        }
347               
348        public static function connect( $service, $config )
349            {
350            $result = $service->open( $config );
351
352            if( is_string( $result ) )
353                throw new Exception( $result );
354
355            return( true );
356        }
357
358        public static function configure( $config, $newConfig )
359        {
360            foreach( $newConfig as $key => $value )
361                $config[$key] = $value;
362
363            return( $config );
364            }
365
366        public static function dispatch( $dispatcher, $data, $optionsMap = false )
367        {
368//          if( $mappedTo )
369//              $data = array( $mappedTo => $data );
370//
371//          foreach( $data as $method => $params )
372//          {
373// //           foreach( $data[ $method ] as $name => $value )
374//          }
375//
376//          self::import( "$dispatcher.php" );
377        }
378
379        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
380        public static function service( $serviceName, $concept = false )
381        {
382            if( isset( self::$services[ $serviceName ] ) )
383                return self::$services[ $serviceName ];
384
385            if( !isset(self::$config[ $serviceName ]) )
386                 self::$config[ $serviceName ] = self::loadConfig( $serviceName, true );
387
388            if( !isset(self::$config[ $serviceName ]) )
389                return( false );
390
391            if( !isset(self::$config[ $serviceName ]['type']) )
392                self::$config[ $serviceName ]['type'] = 'service';
393
394            self::import( 'api/'.self::$config[ $serviceName ]['type'] );   //TODO: Item 4
395
396            $service = self::load( self::$config[ $serviceName ]['path'],
397                                   self::$config[ $serviceName ]['class'] );
398
399              $srvConfig = array();
400
401            if( isset(self::$config[ $serviceName ][ 'config' ]) )
402                $srvConfig = self::configure( $srvConfig, self::$config[ $serviceName ][ 'config' ] );
403            if( $wallet = self::wallet( $serviceName ) )
404                $srvConfig = self::configure( $srvConfig, $wallet );
405            if( $concept && isset(self::$config[ $concept ]['service.config']) )
406                $srvConfig = self::configure( $srvConfig, self::$config[ $concept ]['service.config'] );
407
408            if( empty( $srvConfig ) )
409                $srvConfig = false;
410
411            if( $service && self::$config[ $serviceName ]['type'] === 'service' )
412                self::connect( $service, $srvConfig );
413
414            return( self::$services[ $serviceName ] = $service );
415        }
416
417        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
418        public static function interceptor( $method, $concept = false, $serviceName = false, $isService = false )
419        {
420            if( $concept && !isset(self::$config[ $concept ]) )
421              self::$config[ $concept ] = self::loadConfig( $concept );
422
423            if( !$concept ) $concept = 'global';
424            if( !$isService || !$serviceName ) $serviceName = 'global';
425
426            if( !isset( self::$interceptors[ $concept ] ) )
427                self::$interceptors[ $concept ] = array();
428
429            if( !isset( self::$interceptors[ $concept ][ $serviceName ] ) )
430                self::$interceptors[ $concept ][ $serviceName ] = array();
431
432            if( !isset( self::$interceptors[ $concept ][ $serviceName ][ $method ] ) )
433            {
434                $events = array( 'before', 'after' );
435                $interceptors = array();
436
437                $prefix = ( $isService )? "$serviceName." : "";
438
439                foreach( $events as $i => $event )
440                {
441                    $interceptors[$event] = array();
442
443                    if( !isset(self::$config[$concept]["$prefix$event.$method"]) )
444                      continue;
445
446                    foreach( self::$config[$concept]["$prefix$event.$method"] as $intercept => $interceptor )
447                            $interceptors[$event][$intercept] = self::load( $interceptor );
448                }
449
450                self::$interceptors[ $concept ][ $serviceName ][ $method ] = $interceptors;
451            }
452
453            return( self::$interceptors[ $concept ][ $serviceName ][ $method ] );
454        }
455
456        public static function interceptorCommit( $eventType, $commitList, $isService = false )
457        {
458            $result = array( $eventType => array() );
459       
460            if( is_array( $commitList ) )
461                foreach( $commitList as $i => $tx )
462                {
463                    $interceptors = self::interceptor( 'commit', $tx['concept'], $tx['service'], $isService );
464     
465                    $result[$eventType] = array_merge( $result[$eventType], $interceptors[$eventType] );
466                }
467
468            return( $result );
469        }
470
471        public static function fire( $eventType, $method, &$params, $original, $isService = false )
472        {
473            if( $method === 'commit' )
474                $interceptors = self::interceptorCommit( $eventType, $params['criteria'], $isService );
475
476            else
477                $interceptors = self::interceptor( $method,
478                                                   isset($original['URI']['concept']) ? $original['URI']['concept'] : false,
479                                                   isset($params['URI']['service']) ? $params['URI']['service'] : false, $isService );
480
481            if( $interceptors && isset($interceptors[ $eventType ]) )
482                foreach( $interceptors[ $eventType ] as $intercept => $interceptor )
483                {
484                    $return = $interceptor->$intercept( $params['URI'], $params['properties'], $params['criteria'], $original /*, $params['service'] */);
485
486                    if( $return === false )
487                return( false );
488
489                    if( isset($return) )
490                        $params['properties'] = $return;
491                }
492
493              return( $params );
494        }
495
496        /*
497          * ex: array
498          *             (
499          *                     [0] array( 'OR', array( array( '=', 'campo', 'valor' ),
500                                                          array( 'OR', array( array( '=', 'campo', 'valor' ) ) ) )
501          *                     [1] array( '=', 'campo' , 'valor' )
502          *                     [2] array( 'OR' , array( array( '=' , campo', 'valor' ) ) )
503          *                     [3] array( 'IN', 'campo', array( '1' , '2' , '3' ) )
504          *             )
505          * OR
506          *         array( '=' , 'campo' , 'valor' )
507        */
508
509        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmo nos parametros passados
510        public static function serviceName( $URI, $original = false )
511        {
512             $concept = "";
513
514            if( $original && isset($original['concept']) && $original['concept'] )
515                $concept = $original['concept'];
516            elseif( isset($URI['concept']) && $URI['concept'] )
517                $concept = $URI['concept'];
518
519            if( ( !isset($URI['service']) || !$URI['service'] ) && $concept )
520            {
521                if( !isset(self::$config[ $concept ]) )
522                    self::$config[ $concept ] = self::loadConfig( $concept );
523
524                $URI['service'] = self::$config[ $concept ][ 'service' ];
525            }
526
527            if( !isset($URI['service']) )
528                throw new Exception( "CONFIGURATION ERROR: service name from concept '$concept' not found" );
529
530            return( $URI );
531        }
532
533        //TODO: Compatibilizar as configs relativas aos modulos, adicionando os mesmos nas options passadas
534        public static function call( $method, $URI, $properties = false, $options = false, $service = false )
535        {
536            try
537            {
538                if( !isset($URI['concept']) ) $URI['concept'] = false;
539
540                $original = $params = array( 'properties' => $properties,
541                                             'criteria' => $options,
542                                             'URI' => $URI,
543                                             'service' => $service );
544
545                if( isset($params['URI']['concept'])  && !self::fire( 'before', $method, $params, $original ) )
546                    return( empty($params['properties']) ? false : $params['properties'] );
547
548               
549
550                if( $params && !$params['service'] )
551                {
552                    $params['URI'] = self::serviceName( $params['URI'], $original['URI'] );
553
554                    $params['service'] = self::service( $params['URI']['service'], $params['URI']['concept'] );
555                }
556
557                if( isset($params['URI']['service']) )
558                {
559                    if( $method === 'create' || $method === 'update' || $method === 'delete' )
560                    {
561                        if( $commit = !isset(self::$tx[ $params['URI']['service'] ])  )
562                        {
563                            self::call( 'begin', $params['URI'] );
564                        }
565
566                        $TX = array();
567                    }
568
569                    if( !self::fire( 'before', $method, $params, $original, true ) )
570                        return( empty($params['properties']) ? false : $params['properties'] );
571                }
572
573                if( $params['service'] )
574                    switch( $method )
575                    {
576                        case 'find': $return = $params['service']->find( $params['URI'], $params['properties'], $params['criteria'] ); break;
577
578                        case 'read': $return = $params['service']->read( $params['URI'], $params['properties'] , $params['criteria'] ); break;
579
580                        case 'create': $return = $params['service']->create( $params['URI'], $params['properties']/*, $criteria*/ ); break;
581
582                        case 'delete': $return = $params['service']->delete( $params['URI'], $params['properties'], $params['criteria'] ); break;
583
584                        case 'deleteAll': $return = $params['service']->deleteAll( $params['URI'], $params['properties'], $params['criteria'] ); break;
585
586                        case 'update': $return = $params['service']->update( $params['URI'], $params['properties'], $params['criteria'] ); break;
587
588                        case 'replace': $return = $params['service']->replace( $params['URI'], $params['properties'], $params['criteria'] ); break;
589
590                        case 'begin': $return = $params['service']->begin( $params['URI'] ); break;
591
592                        case 'commit': $return = $params['service']->commit( $params['URI'], $params['criteria'] ); break;
593
594                        case 'rollback': $return = $params['service']->rollback( $params['URI'], $params['criteria'] ); break;
595
596                        case 'parse': $return = $params['service']->parse( $params['properties'], $params['criteria'] ); break;
597
598                        case 'analize': $return = $params['service']->analize( $params['properties'], $params['criteria'] ); break;
599
600                        case 'format': $return = $params['service']->format( $params['properties'], $params['criteria'] ); break;
601
602                        default : $return = $params['service']->$method( $params['properties'], $params['criteria'] );
603                    }
604
605                if( isset($return) && $return !== false )
606                    $params['properties'] = $return;
607
608                if( isset($params['URI']['service']) )
609                    if( !self::fire( 'after', $method, $params, $original, true ) )
610                        return( empty($params['properties']) ? false : $params['properties'] );
611
612                if( isset($URI['concept']) )
613                    self::fire( 'after', $method, $params, $original );
614
615                if( empty($params['properties']) )
616                    $params['properties'] = false;
617
618                if( isset( $TX ) )
619                {
620                    $TX['rollback'] = !!!$params['properties'];
621
622                    if( $params['properties'] && is_array($params['properties']) && isset($params['properties']['id']) )
623                        $TX['id'] = $params['properties']['id'];
624
625                    self::$tx[ $params['URI']['service'] ][] = array_merge( $TX, $original['URI'], array( 'service' => $params['URI']['service'], 'method' => $method ) );
626
627                    if( isset($commit) && $commit )
628                    {
629                        if( !self::call( 'commit', $params['URI'], false, self::$tx[ $params['URI']['service'] ] ) )
630                            self::call( 'rollback', $params['URI'] , false, self::$tx[ $params['URI']['service'] ] );
631
632                        unset( self::$tx[ $params['URI']['service'] ] );
633                    }
634                }
635            }
636            catch( Exception $e )
637            {
638                if( !self::fallback( $e ) )
639                    self::closeAll();
640
641                return( false );
642            }
643
644            return( $params['properties'] );
645        }
646
647        public static function fallback( $exception )
648        {
649            $code = $exception->getCode();
650
651            if( isset( self::$fallbackHandlers[ $code ] ) )
652                {
653                        $fn = self::$fallbackHandlers[ $code ];
654                        return $fn( $exception );
655                }
656
657            error_log( $exception->getMessage() );
658            return( true );
659        }
660
661        public static function addFallbackHandler( $code, $function )
662        {
663            self::$fallbackHandlers[ $code ] = $function;
664        }
665        /*
666         *NULL evita erros caso não seja passado nenhuma variavel por referência
667        */
668        public static function put( $URI, $data, &$txIds = NULL )
669        {
670            try
671            {
672                $URI = self::serviceName( $URI );
673
674                if( $commit = !$txIds )
675                    $txIds = array();
676
677                if( !isset( self::$tx[ $URI['service'] ] ) )
678                {
679                    self::call( 'begin', $URI );
680                    self::$tx[ $txIds[] = $URI['service'] ] = array();
681                }
682
683                $method = $data ? isset( $data['id'] ) ?
684                          'update' : 'create' : 'delete';
685
686                $links = self::links( $URI['concept'] );
687
688                $order = self::$txID++;
689
690                $postpone = array();
691                $linkNames = array();
692
693                if( $data )
694                {
695                    $URI['id'] = isset( $data['id'] ) ? $data['id'] : false;
696
697                    foreach( $links as $linkName => $linkTarget )
698                    {
699                        if( isset( $data[$linkName] ) && is_array( $data[$linkName] ) )
700                        {
701                                if( self::isConcept( $URI['concept'], $linkName ) )
702                                    $data[$linkName] = self::put( array( 'concept' => $linkTarget ), $data[$linkName], $txIds );
703                            else
704                            {
705                                    $postpone[ $linkTarget ] =  $data[$linkName];
706                                    $linkNames[ $linkTarget ] = $linkName;
707                            }
708                        }
709                    }
710                }
711                else
712                  $URI['id'] = isset( $data['id'] ) ? $data['id'] : $URI['id'];
713
714                $result = Controller::call( $method, $URI, $data, false, false, true );
715
716                if( is_array( $result ) && isset( $result['id'] ) )
717                      $URI['id'] = $result['id'];
718
719                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['order'] = $order;
720                self::$tx[ $URI['service'] ][ count(self::$tx[ $URI['service'] ]) - 1 ]['id'] = $URI['id'];
721
722                foreach( $postpone as $linkTarget => $dt )
723                {
724                      if( Controller::hasOne( $URI['concept'], $linkNames[ $linkTarget ] ) )
725                          $dt = array( $dt );
726
727                      foreach( $dt as $ii => $value )
728                      {
729                          if( !is_array( $value ) )
730                            $value = array( 'id' => $value );
731
732                          $value[ self::links( $URI['concept'], $linkNames[ $linkTarget ] ) ] = $URI['id'];
733 
734                          self::put( array( 'concept' => $linkTarget ), $value, $txIds );
735                      }
736                }
737                if( $commit )
738                {
739                      $result = array();
740
741                      for( $i = count( $txIds ) - 1; $i >= 0; $i-- )
742                      {
743                              $currentTx = self::$tx[ $txIds[$i] ];
744                              unset( self::$tx[ $txIds[$i] ] );
745
746                              if( !self::commit( array( 'service' => $txIds[$i] ), $currentTx ) )
747                              {
748                                  self::rollback( array( 'service' => $txIds[$i] ), $currentTx );
749
750                                  foreach( $currentTx as $i => $st )
751                                      $currentTx[$i][ 'rollback' ] = true;
752                              }
753
754                              $result = array_merge( $result, $currentTx );
755                      }
756
757                      self::$txID = 0;
758
759                      return( $result );
760                }
761
762            }
763            catch( Exception $e )
764            {
765                if( !self::fallback( $e ) )
766                    self::closeAll();
767
768                return( false );
769            }
770       
771            return( $URI['id'] );
772        }
773       
774        public static function get()
775        {
776       
777        }
778}
779
780Controller::$cache = Controller::loadCache();
781// ?>
Note: See TracBrowser for help on using the repository browser.