Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Something
Friday, October 6th, 2006 at 11:29:45am MDT 

  1. <?php
  2.  
  3. require_once 'propel/engine/builder/om/php5/PHP5ComplexPeerBuilder.php';
  4.  
  5. class FasterPHP5ComplexPeerBuilder extends PHP5ComplexPeerBuilder {          
  6.  
  7.         /**
  8.          * Adds the doSelectJoin*() methods.
  9.          * @param string &$script The script will be modified in this method.
  10.          */
  11.         protected function addDoSelectJoin(&$script)
  12.         {
  13.                 $table = $this->getTable();
  14.                 $className = $table->getPhpName();
  15.                 $countFK = count($table->getForeignKeys());
  16.                
  17.                 if ($countFK >= 1) {
  18.                
  19.                         foreach ($table->getForeignKeys() as $fk) {
  20.                        
  21.                                 $joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
  22.                                
  23.                                 if (!$joinTable->isForReferenceOnly()) {
  24.                                
  25.                                         // FIXME - look into removing this next condition; it may not
  26.                                         // be necessary:
  27.                                         // --- IT is necessary because there needs to be a system for
  28.                                         // aliasing the table if it is the same table.
  29.                                         if ( $fk->getForeignTableName() != $table->getName() ) {
  30.                                                
  31.                                                
  32.                                                 $joinClassName = $joinTable->getPhpName();
  33.                                                
  34.                                                 $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
  35.                                                 $joinedTableObjectBuilder = OMBuilder::getNewObjectBuilder($joinTable);
  36.                                                 $joinedTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  37.                                                
  38.                                                 $script .= "
  39.  
  40.         /**
  41.          * Selects a collection of $className objects pre-filled with their $joinClassName objects.
  42.          *
  43.          * @return array Array of $className objects.
  44.          * @throws PropelException Any exceptions caught during processing will be
  45.          *             rethrown wrapped into a PropelException.
  46.          */
  47.         public static function doSelectJoin".$thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false)."(Criteria \$c, \$con = null)
  48.         {
  49.                 \$c = clone \$c;
  50.  
  51.                 // Set the correct dbName if it has not been overridden
  52.                 if (\$c->getDbName() == Propel::getDefaultDB()) {
  53.                         \$c->setDbName(self::DATABASE_NAME);
  54.                 }
  55.  
  56.                 ".$this->getPeerClassname()."::addSelectColumns(\$c);
  57.                 \$startcol = (".$this->getPeerClassname()."::NUM_COLUMNS - ".$this->getPeerClassname()."::NUM_LAZY_LOAD_COLUMNS) + 1;
  58.                 ".$joinedTablePeerBuilder->getPeerClassname()."::addSelectColumns(\$c);
  59. ";
  60.                
  61.                                                 $lfMap = $fk->getLocalForeignMapping();
  62.                                                 foreach ($fk->getLocalColumns() as $columnName ) {
  63.                                                         $column = $table->getColumn($columnName);
  64.                                                         $columnFk = $joinTable->getColumn( $lfMap[$columnName] );
  65.                                                         $script .= "
  66.                 \$c->addJoin(".$this->getColumnConstant($column).", ".$joinedTablePeerBuilder->getColumnConstant($columnFk).");"; //CHECKME
  67.  
  68.                                                 }
  69.  
  70.  
  71.                                                 if ($joinTable->getChildrenColumn()) {
  72.                                                         $script .= "
  73.                         \$clsjoin = Propel::import(".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$rs, \$startcol));
  74. ";
  75.                                                 } else {
  76.                                                         $script .= "
  77.                         \$clsjoin = Propel::import(".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass());
  78. ";
  79.                                                 }
  80.  
  81.                                                 if ($table->getChildrenColumn()) {
  82.                                                         $script .= "
  83.                         \$cls = Propel::import(".$this->getPeerClassname()."::getOMClass(\$rs, 1));
  84. ";
  85.                                                 } else {
  86.                                                         $script .= "
  87.                         \$cls = Propel::import(".$this->getPeerClassname()."::getOMClass());
  88. ";
  89.                                                 }
  90.  
  91.                                                 $script .= "
  92.                 \$rs = ".$this->basePeerClassname."::doSelect(\$c, \$con);
  93.                 \$results = array();
  94.                 \$map = array();
  95.  
  96.                 while(\$rs->next()) {
  97. ";
  98.                         $script .= "
  99.                         \$obj1 = new \$cls();
  100.                         \$obj1->hydrate(\$rs);
  101. ";
  102.                                                
  103.                                                 $script .= "
  104.                         \$obj2 = new \$clsjoin();
  105.                         \$obj2->hydrate(\$rs, \$startcol);
  106.  
  107.                         self::foreignMap(\$map, \$obj1, \$obj2);
  108.                         \$results[] = \$obj1;
  109.                 }
  110.                 return \$results;
  111.         }
  112. ";
  113.                                         } // if fk table name != this table name
  114.                                 } // if ! is reference only
  115.                         } // foreach column
  116.                 } // if count(fk) > 1
  117.                
  118.         } // addDoSelectJoin()
  119.        
  120.         /**
  121.          * Adds the doSelectJoinAll() method.
  122.          * @param string &$script The script will be modified in this method.
  123.          */
  124.         protected function addDoSelectJoinAll(&$script)
  125.         {
  126.                 $table = $this->getTable();
  127.                 $className = $table->getPhpName();
  128.  
  129.         //      $joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = true)."();
  130.         //      $joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false)."(\$obj1);
  131.  
  132.                 $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
  133.  
  134.                 $script .= "
  135.  
  136.         /**
  137.          * hash table function!
  138.          **/
  139.         static protected function foreignMap(array &\$map, \$obj1, \$hashObj) {
  140.  
  141.                 if (isset(\$map[\$hashObj->getPrimaryKey()])) {
  142.                         \$map[\$hashObj->getPrimaryKey()]->add$className(\$obj1);
  143.                 } else {
  144.                         \$hashObj->init{$className}s();
  145.                         \$hashObj->add$className(\$obj1);
  146.                         \$map[\$hashObj->getPrimaryKey()] = \$hashObj;
  147.                 }
  148.         }
  149.  
  150.  
  151.         /**
  152.          * Selects a collection of $className objects pre-filled with all related objects.
  153.          *
  154.          * @return array Array of $className objects.
  155.          * @throws PropelException Any exceptions caught during processing will be
  156.          *             rethrown wrapped into a PropelException.
  157.          */
  158.         public static function doSelectJoinAll(Criteria \$c, \$con = null)
  159.         {
  160.                 \$c = clone \$c;
  161.  
  162.                 // Set the correct dbName if it has not been overridden
  163.                 if (\$c->getDbName() == Propel::getDefaultDB()) {
  164.                         \$c->setDbName(self::DATABASE_NAME);
  165.                 }
  166.  
  167.                 ".$this->getPeerClassname()."::addSelectColumns(\$c);
  168.                 \$startcol2 = (".$this->getPeerClassname()."::NUM_COLUMNS - ".$this->getPeerClassname()."::NUM_LAZY_LOAD_COLUMNS) + 1;
  169. ";
  170.                 $index = 2;
  171.                 foreach ($table->getForeignKeys() as $fk) {
  172.                         // want to cover this case, but the code is not there yet.
  173.                         // FIXME: why "is the code not there yet" ?
  174.                         if ( $fk->getForeignTableName() != $table->getName() ) {
  175.                                 $joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
  176.                                 $joinClassName = $joinTable->getPhpName();
  177.                                 $new_index = $index + 1;
  178.                                
  179.                                 $joinedTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  180.                                                
  181.                                 $script .= "
  182.                 ".$joinedTablePeerBuilder->getPeerClassname()."::addSelectColumns(\$c);
  183.                 \$startcol$new_index = \$startcol$index + ".$joinedTablePeerBuilder->getPeerClassname()."::NUM_COLUMNS;
  184. ";
  185.                                 $index = $new_index;
  186.                         } // if fk->getForeignTableName != table->getName
  187.                 } // foreach [sub] foreign keys
  188.  
  189.  
  190.                 foreach ($table->getForeignKeys() as $fk) {
  191.                         // want to cover this case, but the code is not there yet.
  192.                         if ( $fk->getForeignTableName() != $table->getName() ) {
  193.                                 $joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
  194.                                 $joinedTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  195.                                
  196.                                 $joinClassName = $joinTable->getPhpName();
  197.                                 $lfMap = $fk->getLocalForeignMapping();
  198.                                 foreach ($fk->getLocalColumns() as $columnName ) {
  199.                                         $column = $table->getColumn($columnName);
  200.                                         $columnFk = $joinTable->getColumn( $lfMap[$columnName]);
  201.                                         $script .= "
  202.                 \$c->addJoin(".$this->getColumnConstant($column).", ".$joinedTablePeerBuilder->getColumnConstant($columnFk).");
  203. ";
  204.                             }
  205.                         }
  206.                 }
  207.  
  208.                 $index = 1;
  209.                 foreach ($table->getForeignKeys() as $fk ) {
  210.                         // want to cover this case, but the code is not there yet.
  211.                         // FIXME -- why not? -because we'd have to alias the tables in the JOIN
  212.                         if ( $fk->getForeignTableName() != $table->getName() ) {
  213.                                
  214.                                 $joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
  215.                                 $joinClassName = $joinTable->getPhpName();
  216.                                 $interfaceName = $joinTable->getPhpName();
  217.                                 if($joinTable->getInterface()) {
  218.                                         $interfaceName = $joinTable->getInterface();
  219.                                 }
  220.                                
  221.                                 $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
  222.                                 $joinedTableObjectBuilder = OMBuilder::getNewObjectBuilder($joinTable);
  223.                                 $joinedTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  224.                                 $cname = $joinedTablePeerBuilder->getPeerClassname();
  225.                                 $joinedPeerClassName = $joinedTablePeerBuilder->getPeerClassname();
  226.                                
  227.                                 $index++;
  228.                                 $script .= "
  229.                 \$om$joinedPeerClassName = Propel::import(".$joinedTablePeerBuilder->getPeerClassname()."::getOMClass(\$rs, \$startcol$index));
  230.                 \$map$joinedPeerClassName = array();
  231. ";
  232.                         }
  233.                 }
  234.  
  235.                 if ($table->getChildrenColumn()) {
  236.                         $script .= "
  237.                         \$omClass = ".$this->getPeerClassname()."::getOMClass(\$rs, 1);
  238. ";
  239.                 } else {
  240.                         $script .= "
  241.                         \$omClass = ".$this->getPeerClassname()."::getOMClass();
  242. ";
  243.                 }
  244.  
  245.                 $script .= "
  246.                 \$cls = Propel::import(\$omClass);
  247.                 \$rs = ".$this->basePeerClassname."::doSelect(\$c, \$con);
  248.                 \$results = array();
  249.  
  250.                 while(\$rs->next()) {
  251. ";
  252.        
  253.                 $script .= "
  254.                         \$obj1 = new \$cls();
  255.                         \$obj1->hydrate(\$rs);
  256. ";
  257.  
  258.                 $index = 1;
  259.                 foreach ($table->getForeignKeys() as $fk ) {
  260.                        
  261.                         // want to cover this case, but the code is not there yet.
  262.                         // FIXME -- why not? -because we'd have to alias the tables in the JOIN
  263.                         if ( $fk->getForeignTableName() != $table->getName() ) {
  264.                                
  265.                                 $joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
  266.                                 $joinClassName = $joinTable->getPhpName();
  267.                                 $interfaceName = $joinTable->getPhpName();
  268.                                 if($joinTable->getInterface()) {
  269.                                         $interfaceName = $joinTable->getInterface();
  270.                                 }
  271.                                
  272.                                 $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
  273.                                 $joinedTableObjectBuilder = OMBuilder::getNewObjectBuilder($joinTable);
  274.                                 $joinedTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  275.                                 $joinedPeerClassName = $joinedTablePeerBuilder->getPeerClassname();
  276.                                
  277.                                 $index++;
  278.                                
  279.                                 $script .= "
  280.                         // Add objects for joined $joinClassName rows
  281.                         \$obj".$index." = new \$om$joinedPeerClassName();
  282.                         \$obj".$index."->hydrate(\$rs, \$startcol$index);
  283.                         self::foreignMap(\$map$joinedPeerClassName, \$obj1, \$obj".$index.");
  284. ";
  285.  
  286.                         } // $fk->getForeignTableName() != $table->getName()
  287.                 } //foreach foreign key
  288.                
  289.                 $script .= "
  290.                         \$results[] = \$obj1;
  291.                 }
  292.                 return \$results;
  293.         }
  294. ";
  295.        
  296.         } // end addDoSelectJoinAll()
  297.        
  298.         /**
  299.          * Adds the doSelectJoinAllExcept*() methods.
  300.          * @param string &$script The script will be modified in this method.
  301.          */
  302.         protected function addDoSelectJoinAllExcept(&$script)
  303.         {
  304.                 $table = $this->getTable();
  305.                
  306.                 // ------------------------------------------------------------------------
  307.                 // doSelectJoinAllExcept*()
  308.                 // ------------------------------------------------------------------------
  309.                
  310.                 // 2) create a bunch of doSelectJoinAllExcept*() methods
  311.                 // -- these were existing in original Torque, so we should keep them for compatibility
  312.                
  313.                 $fkeys = $table->getForeignKeys()// this sep assignment is necessary otherwise sub-loops over
  314.                                                                                         // getForeignKeys() will cause this to only execute one time.
  315.                 foreach ($fkeys as $fk ) {
  316.                        
  317.                         $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
  318.  
  319.                         $excludedTable = $table->getDatabase()->getTable($fk->getForeignTableName());
  320.                         $excludedClassName = $excludedTable->getPhpName();
  321.                        
  322.                         $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table);
  323.                         $excludedTableObjectBuilder = OMBuilder::getNewObjectBuilder($excludedTable);
  324.                         $excludedTablePeerBuilder = OMBuilder::getNewPeerBuilder($excludedTable);
  325.                                
  326.                 $script .= "
  327.  
  328.         /**
  329.          * Selects a collection of ".$table->getPhpName()." objects pre-filled with all related objects except ".$thisTableObjectBuilder->getFKPhpNameAffix($fk).".
  330.          *
  331.          * @return array Array of ".$table->getPhpName()." objects.
  332.          * @throws PropelException Any exceptions caught during processing will be
  333.          *             rethrown wrapped into a PropelException.
  334.          */
  335.         public static function doSelectJoinAllExcept".$thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false)."(Criteria \$c, \$con = null)
  336.         {
  337.                 \$c = clone \$c;
  338.  
  339.                 // Set the correct dbName if it has not been overridden
  340.                 // \$c->getDbName() will return the same object if not set to another value
  341.                 // so == check is okay and faster
  342.                 if (\$c->getDbName() == Propel::getDefaultDB()) {
  343.                         \$c->setDbName(self::DATABASE_NAME);
  344.                 }
  345.  
  346.                 ".$this->getPeerClassname()."::addSelectColumns(\$c);
  347.                 \$startcol2 = (".$this->getPeerClassname()."::NUM_COLUMNS - ".$this->getPeerClassname()."::NUM_LAZY_LOAD_COLUMNS) + 1;
  348. ";     
  349.                         $index = 2;
  350.                         foreach ($table->getForeignKeys() as $subfk) {
  351.                                 // want to cover this case, but the code is not there yet.
  352.                                 // FIXME - why not?
  353.                                 if ( !($subfk->getForeignTableName() == $table->getName())) {
  354.                                         $joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
  355.                                         $joinClassName = $joinTable->getPhpName();
  356.                                         $joinTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  357.                
  358.                                         if ($joinClassName != $excludedClassName) {
  359.                                                 $new_index = $index + 1;
  360.                                                 $script .= "
  361.                 ".$joinTablePeerBuilder->getPeerClassname()."::addSelectColumns(\$c);
  362.                 \$startcol$new_index = \$startcol$index + ".$joinTablePeerBuilder->getPeerClassname()."::NUM_COLUMNS;
  363. ";
  364.                                         $index = $new_index;
  365.                                         } // if joinClassName not excludeClassName
  366.                                 } // if subfk is not curr table
  367.                         } // foreach [sub] foreign keys
  368.                                
  369.                         foreach ($table->getForeignKeys() as $subfk) {
  370.                                 // want to cover this case, but the code is not there yet.
  371.                                 if ( $subfk->getForeignTableName() != $table->getName() ) {
  372.                                         $joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
  373.                                         $joinClassName = $joinTable->getPhpName();
  374.                                         $joinTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  375.  
  376.                                         if($joinClassName != $excludedClassName)
  377.                                         {
  378.                                                 $lfMap = $subfk->getLocalForeignMapping();
  379.                                                 foreach ($subfk->getLocalColumns() as $columnName ) {
  380.                                                         $column = $table->getColumn($columnName);
  381.                                                         $columnFk = $joinTable->getColumn( $lfMap[$columnName]);
  382.                                                         $script .= "
  383.                 \$c->addJoin(".$this->getColumnConstant($column).", ".$joinTablePeerBuilder->getColumnConstant($columnFk).");
  384. ";
  385.                                                         if ($joinTable->getChildrenColumn()) {
  386.                                                                 $script .= "
  387.                 \$om$joinClassName = Propel::import(".$joinTablePeerBuilder->getPeerClassname()."::getOMClass(\$rs, \$startcol$index));";
  388.                                                         } else {
  389.                                                                 $script .= "
  390.                 \$om$joinClassName = Propel::import(".$joinTablePeerBuilder->getPeerClassname()."::getOMClass());";
  391.                                                         }
  392.                                 $script .= "
  393.                 \$map$joinClassName = array();
  394. ";
  395.                                                 }
  396.                                         }
  397.                                 }
  398.                         } // foreach fkeys
  399.  
  400.                         if ($table->getChildrenColumn()) {
  401.                                 $script .= "
  402.                 \$cls = Propel::import(".$this->getPeerClassname()."::getOMClass(\$rs, 1));
  403. ";
  404.                         } else {
  405.                                 $script .= "
  406.                 \$cls = Propel::import(".$this->getPeerClassname()."::getOMClass());
  407. ";
  408.  
  409.                         $script .= "
  410.  
  411.                 \$rs = ".$this->basePeerClassname ."::doSelect(\$c, \$con);
  412.                 \$results = array();
  413.                
  414.                 while(\$rs->next()) {
  415. ";
  416.                         }
  417.                        
  418.                         $script .= "
  419.                         \$obj1 = new \$cls();
  420.                         \$obj1->hydrate(\$rs);   
  421. ";
  422.                 $index = 1;
  423.                 foreach ($table->getForeignKeys() as $subfk ) {
  424.                   // want to cover this case, but the code is not there yet.
  425.                   if ( $subfk->getForeignTableName() != $table->getName() ) {
  426.                   
  427.                                 $joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
  428.                                 $joinClassName = $joinTable->getPhpName();
  429.                                 $interfaceName = $joinTable->getPhpName();
  430.                                 if($joinTable->getInterface()) {
  431.                                         $interfaceName = $joinTable->getInterface();
  432.                                 }
  433.        
  434.                                 if ($joinClassName != $excludedClassName) {
  435.                                        
  436.                                         $joinedTableObjectBuilder = OMBuilder::getNewObjectBuilder($joinTable);
  437.                                         $joinedTablePeerBuilder = OMBuilder::getNewPeerBuilder($joinTable);
  438.                                        
  439.                                         $index++;                     
  440.        
  441.                                         $script .= "
  442.        
  443.                         \$obj$index  = new \$om$joinClassName();
  444.                         \$obj".$index."->hydrate(\$rs, \$startcol$index);
  445.                                                
  446.                         self::foreignMap(\$map".$joinClassName.", \$obj1, \$obj".$index.");
  447. ";
  448.                                         } // if ($joinClassName != $excludedClassName) {
  449.                         } // $subfk->getForeignTableName() != $table->getName()
  450.                 } // foreach 
  451.                 $script .= "
  452.                         \$results[] = \$obj1;
  453.                 }
  454.                 return \$results;
  455.         }
  456. ";
  457.                 } // foreach fk
  458.  
  459.         } // addDoSelectJoinAllExcept
  460.        
  461. } // PHP5ComplexPeerBuilder

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

worth-right
fantasy-obligation