/[cvs]/nfo/php/libs/org.netfrag.glib/DataSource/Generic.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DataSource/Generic.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by joko, Fri Apr 11 00:55:49 2003 UTC revision 1.29 by jonen, Thu Aug 11 14:05:42 2005 UTC
# Line 9  Line 9 
9   */   */
10    
11  /**  /**
12   * <b>Cvs-Log:</b>   * Cvs-Log:
13   *   *
  * <pre>  
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
17     * Revision 1.29  2005/08/11 14:05:42  jonen
18     * + added arguments to query
19     *
20     * Revision 1.28  2004/10/07 14:11:28  jonen
21     * + added HACK related to DataList-filters which are mapped to backend now (page-control!)
22     *
23     * Revision 1.27  2004/06/15 12:50:48  joko
24     * disabled caching in "datasource_handler_call"
25     *
26     * Revision 1.26  2003/12/14 01:53:42  jonen
27     * implemented 'SELECT' mode for selecting existing object-refereneces as child-nodes
28     *
29     * Revision 1.25  2003/11/17 18:01:03  jonen
30     * bugfix: php cannot use perl-syntax!! ;-)
31     *
32     * Revision 1.23  2003/07/14 10:02:32  jonen
33     * removed debug dumper
34     *
35     * Revision 1.22  2003/06/06 04:25:45  joko
36     * fix: query args get encapsulated once more
37     *
38     * Revision 1.21  2003/05/10 18:14:50  jonen
39     * + implements 'create' of item (query mapping part)
40     *
41     * Revision 1.20  2003/04/19 16:07:15  jonen
42     * + added '_query[list_meta]' at 'queryData' needed for meta query args
43     *    (e.g. at UserManagment)
44     *
45     * Revision 1.19  2003/04/18 15:40:51  joko
46     * NEW: tree data handling
47     *   introduced new adapter: DataSource::Adapter::Free
48     *   enhanced datasource_handler_buildoptions: now handles a) case 'tree'  b) _query[filter]
49     *
50   * Revision 1.18  2003/04/11 00:55:49  joko   * Revision 1.18  2003/04/11 00:55:49  joko
51   * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'   * updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete'
52   *   *
# Line 97  Line 129 
129   *   *
130   * Revision 1.1  2003/03/01 03:10:40  joko   * Revision 1.1  2003/03/01 03:10:40  joko
131   * + initial commit   * + initial commit
  * </pre>  
132   *   *
133   */   */
134    
# Line 416  class DataSource_Generic extends DesignP Line 447  class DataSource_Generic extends DesignP
447                  */                  */
448                                    
449        //$this->set_locator( $locator );        //$this->set_locator( $locator );
450          //print "query: " . Dumper($query) . "<br>";
451        $this->set_query( $query );        $this->set_query( $query );
452    
453    
# Line 493  class DataSource_Generic extends DesignP Line 525  class DataSource_Generic extends DesignP
525          // ... resolves this._modules.adapter._id to this._modules.adapter._module          // ... resolves this._modules.adapter._id to this._modules.adapter._module
526                    
527          switch ($locator->_adapter_type) {          switch ($locator->_adapter_type) {
528    
529            case 'phpHtmlLib':            case 'phpHtmlLib':
530              //$adapter_arguments = $args[title];              //$adapter_arguments = $args[title];
   
531              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');              $this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource');
532                            
533              // in order to let the Adapter communicate with the Proxy,              // in order to let the Adapter communicate with the Proxy,
534              // instantiate a wrapper method in a third namespace via              // instantiate a wrapper method in a third namespace via
535              // Exporter::export_symbol(from, to)              // Exporter::export_symbol(from, to)
536              $this->set_adapter_options($this);              $this->set_adapter_options($this);
537                break;
538    
539              // NEW [2003-04-17]: Freedom for the adapter!
540              // phpHtmlLib didn't have a tree widget, but PEAR does.
541              // So: Free us from the phpHtmlLib-adapter in this case.
542              case 'free':
543                $this->set_adapter_module('DataSource::Adapter::Free');
544                $this->set_adapter_options($this);
545              break;              break;
546    
547            default:            default:
548              user_error("DataSource::Generic: no Adapter could be selected!");              user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'");
549              break;              break;
550          }          }
551    
# Line 669  class DataSource_Generic extends DesignP Line 708  class DataSource_Generic extends DesignP
708                
709                
710        //$this->set_component_name( $proxy_name );        //$this->set_component_name( $proxy_name );
711        $this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 1 ) ) );        $this->set_component_options( $cache_key, array( key => 1, command => $command, query => $query, remote => 1, rpcinfo => $rpcinfo, cache => array( db => 0, session => 0 ) ) );
712        //print Dumper($this);        //print Dumper($this);
713        //exit;        //exit;
714                
# Line 718  class DataSource_Generic extends DesignP Line 757  class DataSource_Generic extends DesignP
757              }              }
758   */   */
759              $query_args = array();              $query_args = array();
760                
761                 $msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: ";
762               switch ($this->_query[abstract_type]) {               switch ($this->_query[abstract_type]) {
763                  case 'item':
764                    if (!$this->_query[nodename] && $this->_query[action] != 'create') {
765                      $msg = "_query[vartype] == 'objects' requires _query[nodename]";
766                      user_error($msg_prefix . $msg);
767                    } elseif($this->_query[action] == 'create' && $this->_query[parent]) {
768                      if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
769                      if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
770                      $query_args[nodename] = $this->_query[ident];
771                      $query_args[parent][guid] = $this->_query[parent][guid];
772                      $query_args[parent][nodename] = $this->_query[parent][nodename];
773                    } elseif($this->_query[parent]) {
774                      $query_args[guid] = $this->_query[ident];
775                      $query_args[nodename] = $this->_query[nodename];
776                      $query_args[parent][guid] = $this->_query[parent][guid];
777                      $query_args[parent][nodename] = $this->_query[parent][nodename];
778                    } else {
779                      $query_args[guid] = $this->_query[ident];
780                      $query_args[nodename] = $this->_query[nodename];
781                      // 2003-11-17 NEW: use expand flag for real obj expand at backend
782                      if ($this->_query[expand]) {$query_args[expand] = 1; }
783                    }
784                    //print "generic_source->debug: args " . Dumper($query_args) . "<br>";
785                    break;
786                case 'list':                case 'list':
787                  if (!$this->_query[nodename]) {                  if (!$this->_query[nodename]) {
788                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
789                    user_error("DataSource::Generic: query_data() - failed: " . $msg);                    user_error($msg_prefix . $msg);
790                    } elseif($this->_query[parent]) {
791                      //if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; }
792                      //if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; }
793                      //$query_args[nodename] = $this->_query[ident];
794                      $query_args[parent][guid] = $this->_query[parent][guid];
795                      $query_args[parent][nodename] = $this->_query[parent][nodename];
796                  }                  }
797                  //array_push($query_args, $this->_query[nodename]);                  //array_push($query_args, $this->_query[nodename]);
798                  $query_args[nodename] = $this->_query[nodename];                  $query_args[nodename] = $this->_query[nodename];
799                    if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; }
800                    if(is_array($this->_query[owner])) { $query_args[owner] = $this->_query[owner]; }
801                  break;                  break;
802                case 'item':                case 'tree':
803                    /*
804                  if (!$this->_query[nodename]) {                  if (!$this->_query[nodename]) {
805                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";                    $msg = "_query[vartype] == 'objects' requires _query[nodename]";
806                    user_error("DataSource::Generic: query_data() - failed: " . $msg);                    user_error($msg_prefix . $msg);
807                  }                  }
808                    */
809                  $query_args[guid] = $this->_query[ident];                  $query_args[guid] = $this->_query[ident];
810                  $query_args[nodename] = $this->_query[nodename];                  //$query_args[nodename] = $this->_query[nodename];
811                  break;                                break;
812                  default:
813                    $msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'.";
814                    user_error($msg_prefix . $msg);
815                    break;
816                }
817                
818                // filter???
819                //print "Filter: " . Dumper($this->_query[filter]) . "<br>";
820                if ($this->_query[filter]) {
821                  $query_args[filter] = $this->_query[filter];
822              }              }
823                            
824              // dispatch action              // dispatch action
825                //print "Action: " . $this->_query[action] . "<br>";
826              if ($this->_query[action] == 'write') {              if ($this->_query[action] == 'write') {
827               $query_args[action] = $this->_query[action];               $query_args[action] = $this->_query[action];
828               $query_args[data] = $this->_query[data];               $query_args[data] = $this->_query[data];
829              } elseif ($this->_query[action] == 'delete') {              } elseif ($this->_query[action] == 'delete') {
830               $query_args[action] = $this->_query[action];               $query_args[action] = $this->_query[action];
831                } elseif ($this->_query[action] == 'create') {
832                   $query_args[action] = $this->_query[action];
833                } elseif ($this->_query[action] == 'select') {
834                   $query_args[action] = $this->_query[action];
835              }              }
836                
837              $args = array(              $args = array(
838                            'data_type' => $this->_query[abstract_type],                            'data_type' => $this->_query[abstract_type],
839                            'query_args' => $query_args                            'query_args' => $query_args
# Line 760  class DataSource_Generic extends DesignP Line 850  class DataSource_Generic extends DesignP
850            // remoteMethod            // remoteMethod
851            case 'method':            case 'method':
852              $command = $this->_query[method];              $command = $this->_query[method];
853              $args = $this->_query[args];              //$args = $this->_query[args];
854                // FIX
855                $args = array( $this->_query[args] );
856              break;              break;
857    
858          }          }
# Line 769  class DataSource_Generic extends DesignP Line 861  class DataSource_Generic extends DesignP
861          // FIXME: bad behaviour?          // FIXME: bad behaviour?
862          if (!is_array($args)) { $args = array( $args ); }          if (!is_array($args)) { $args = array( $args ); }
863                    
864            //print Dumper($args);
865            
866          /*          /*
867          $this->_query[rpc_command] = $command;          $this->_query[rpc_command] = $command;
868          $this->_query[rpc_args] = $command;          $this->_query[rpc_args] = $command;
# Line 803  class DataSource_Generic extends DesignP Line 897  class DataSource_Generic extends DesignP
897    
898    
899          function &fetch_result() {          function &fetch_result() {
900    
901          //print Dumper($this);
902                
903        $this->datasource_handler_buildoptions();        $this->datasource_handler_buildoptions();
904    
905        $call = $this->_locator->get_call();        $call = $this->_locator->get_call();
906    
907        //print Dumper($call);        //print Dumper($call);
908          //return;
909    
910        // pre-flight checks        // pre-flight checks
911          if (!$call[method]) {          if (!$call[method]) {
# Line 825  class DataSource_Generic extends DesignP Line 923  class DataSource_Generic extends DesignP
923                    
924          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result          // TODO: ... = $this->poll_handler_result  and  $this->get_handler_result
925          $proxy = $this->get_proxy();          $proxy = $this->get_proxy();
926          $this->_result = $proxy->getResult();            //HACK 2004-10-07: page-filter done by backend now,
927              //                 before offset values filled with empty arrays
928            //$this->_result = $proxy->getResult();
929            $result = $proxy->getResult();
930            if($result['total_rows']) {
931              // debug
932              //print "result: " . Dumper($result);
933              $this->_result_count = $result['total_rows'];
934              if($result[offset]) {
935                $result_new = array();
936                for($i=0;$i<$result[offset];$i++) {
937                  array_push($result_new, array());
938                }
939                foreach($result['payload'] as $key => $value) {
940                  array_push($result_new, $value);
941                }
942                $this->_result = $result_new;
943              } else {
944                $this->_result = $result['payload'];
945              }
946            } else {
947              $this->_result = $result;
948              $this->_result_count = sizeof($this->_result);
949            }
950            //print "result: " . Dumper($this->_result);
951          //print "result: " . Dumper($this->_result); exit;          //print "result: " . Dumper($this->_result); exit;
952    
         $this->_result_count = sizeof($this->_result);  
953    
954        // trace        // trace
955          //if (constants::get('VERBOSE') && $this->_debug[notice]) {          //if (constants::get('VERBOSE') && $this->_debug[notice]) {

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.29

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed