protected function addDoSelectWithI18n(&$script) { $table = $this->getTable(); $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table); $className = $table->getPhpName(); $pks = $table->getPrimaryKey(); $pk = PeerBuilder::getColumnName($pks[0], $className); // get i18n table name and culture column name foreach ($table->getReferrers() as $fk) { $tblFK = $fk->getTable(); if ($tblFK->getName() == $table->getAttribute('i18nTable')) { $i18nClassName = $tblFK->getPhpName(); // FIXME $i18nPeerClassName = $i18nClassName . 'Peer'; $i18nTable = $table->getDatabase()->getTable($tblFK->getName()); $i18nTableObjectBuilder = OMBuilder::getNewObjectBuilder($i18nTable); $i18nTablePeerBuilder = OMBuilder::getNewPeerBuilder($i18nTable); $i18nPks = $i18nTable->getPrimaryKey(); $i18nPk = PeerBuilder::getColumnName($i18nPks[0], $i18nClassName); $culturePhpName = ''; $cultureColumnName = ''; foreach ($tblFK->getColumns() as $col) { if ("true" === strtolower($col->getAttribute('isCulture'))) { $culturePhpName = $col->getPhpName(); $cultureColumnName = PeerBuilder::getColumnName($col, $i18nClassName); } } } } $script .= "\n\n /**\n * Selects a collection of {$className} objects pre-filled with their i18n objects.\n *\n * @return array Array of {$className} objects.\n * @throws PropelException Any exceptions caught during processing will be\n * rethrown wrapped into a PropelException.\n */\n public static function doSelectWithI18n(Criteria \$c, \$culture = null, \$con = null)\n {\n if (\$culture === null)\n {\n \$culture = sfPropel::getDefaultCulture();\n }\n"; if (DataModelBuilder::getBuildProperty('builderAddBehaviors')) { $script .= "\n\n foreach (sfMixer::getCallables('{$this->getClassname()}:doSelectJoin:doSelectJoin') as \$callable)\n {\n call_user_func(\$callable, '{$this->getClassname()}', \$c, \$con);\n }\n\n"; } $script .= "\n // Set the correct dbName if it has not been overridden\n if (\$c->getDbName() == Propel::getDefaultDB())\n {\n \$c->setDbName(self::DATABASE_NAME);\n }\n\n " . $this->getPeerClassname() . "::addSelectColumns(\$c);\n \$startcol = (" . $this->getPeerClassname() . "::NUM_COLUMNS - " . $this->getPeerClassname() . "::NUM_LAZY_LOAD_COLUMNS) + 1;\n\n " . $i18nPeerClassName . "::addSelectColumns(\$c);\n\n \$c->addJoin(" . $pk . ", " . $i18nPk . ");\n \$c->add(" . $cultureColumnName . ", \$culture);\n\n \$rs = " . $this->basePeerClassname . "::doSelect(\$c, \$con);\n \$results = array();\n\n while(\$rs->next()) {\n"; if ($table->getChildrenColumn()) { $script .= "\n \$omClass = " . $this->getPeerClassname() . "::getOMClass(\$rs, 1);\n"; } else { $script .= "\n \$omClass = " . $this->getPeerClassname() . "::getOMClass();\n"; } $script .= "\n \$cls = Propel::import(\$omClass);\n \$obj1 = new \$cls();\n \$obj1->hydrate(\$rs);\n \$obj1->setCulture(\$culture);\n"; // if ($i18nTable->getChildrenColumn()) { $script .= "\n \$omClass = " . $i18nTablePeerBuilder->getPeerClassname() . "::getOMClass(\$rs, \$startcol);\n"; // } else { // $script .= " // \$omClass = ".$i18nTablePeerBuilder->getPeerClassname()."::getOMClass(); //"; // } $script .= "\n \$cls = Propel::import(\$omClass);\n \$obj2 = new \$cls();\n \$obj2->hydrate(\$rs, \$startcol);\n\n \$obj1->set" . $i18nClassName . "ForCulture(\$obj2, \$culture);\n \$obj2->set" . $className . "(\$obj1);\n\n \$results[] = \$obj1;\n }\n return \$results;\n }\n"; }
protected function addI18nMethods(&$script) { $table = $this->getTable(); $pks = $table->getPrimaryKey(); $pk = $pks[0]->getPhpName(); foreach ($table->getReferrers() as $fk) { $tblFK = $fk->getTable(); if ($tblFK->getName() == $table->getAttribute('i18nTable')) { $className = $tblFK->getPhpName(); $culture = ''; $culture_peername = ''; foreach ($tblFK->getColumns() as $col) { if ("true" === strtolower($col->getAttribute('isCulture'))) { $culture = $col->getPhpName(); $culture_peername = PeerBuilder::getColumnName($col, $className); } } foreach ($tblFK->getColumns() as $col) { if ($col->isPrimaryKey()) { continue; } $script .= ' public function get' . $col->getPhpName() . '() { $obj = $this->getCurrent' . $className . '(); return ($obj ? $obj->get' . $col->getPhpName() . '() : null); } public function set' . $col->getPhpName() . '($value) { $this->getCurrent' . $className . '()->set' . $col->getPhpName() . '($value); } '; } $script .= ' protected $current_i18n = array(); public function getCurrent' . $className . '() { if (!isset($this->current_i18n[$this->culture])) { $obj = ' . $className . 'Peer::retrieveByPK($this->get' . $pk . '(), $this->culture); if ($obj) { $this->set' . $className . 'ForCulture($obj, $this->culture); } else { $this->set' . $className . 'ForCulture(new ' . $className . '(), $this->culture); $this->current_i18n[$this->culture]->set' . $culture . '($this->culture); } } return $this->current_i18n[$this->culture]; } public function set' . $className . 'ForCulture($object, $culture) { $this->current_i18n[$culture] = $object; $this->add' . $className . '($object); } '; } } }
protected function addDoSelectWithI18n(&$script) { $table = $this->getTable(); $thisTableObjectBuilder = OMBuilder::getNewObjectBuilder($table); $className = $table->getPhpName(); $pks = $table->getPrimaryKey(); $pk = PeerBuilder::getColumnName($pks[0], $className); // get i18n table name and culture column name foreach ($table->getReferrers() as $fk) { $tblFK = $fk->getTable(); if ($tblFK->getName() == $table->getAttribute('i18nTable')) { $i18nClassName = $tblFK->getPhpName(); // FIXME $i18nPeerClassName = $i18nClassName.'Peer'; $i18nTable = $table->getDatabase()->getTable($tblFK->getName()); $i18nTableObjectBuilder = OMBuilder::getNewObjectBuilder($i18nTable); $i18nTablePeerBuilder = OMBuilder::getNewPeerBuilder($i18nTable); $i18nPks = $i18nTable->getPrimaryKey(); $i18nPk = PeerBuilder::getColumnName($i18nPks[0], $i18nClassName); $culturePhpName = ''; $cultureColumnName = ''; foreach ($tblFK->getColumns() as $col) { if (('true' == trim(strtolower($col->getAttribute('isCulture'))))) { $culturePhpName = $col->getPhpName(); $cultureColumnName = PeerBuilder::getColumnName($col, $i18nClassName); } } } } $script .= " /** * Selects a collection of $className objects pre-filled with their i18n objects. * * @return array Array of $className objects. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doSelectWithI18n(Criteria \$c, \$culture = null, PropelPDO \$con = null) { // we're going to modify criteria, so copy it first \$c = clone \$c; if (\$culture === null) { \$culture = sfPropel::getDefaultCulture(); } "; if ($this->getBuildProperty('builderAddBehaviors')) { $script .= " foreach (sfMixer::getCallables('{$this->getClassname()}:doSelectJoin:doSelectJoin') as \$callable) { call_user_func(\$callable, '{$this->getClassname()}', \$c, \$con); } "; } $script .= " // Set the correct dbName if it has not been overridden if (\$c->getDbName() == Propel::getDefaultDB()) { \$c->setDbName(self::DATABASE_NAME); } ".$this->getPeerClassname()."::addSelectColumns(\$c); \$startcol = (".$this->getPeerClassname()."::NUM_COLUMNS - ".$this->getPeerClassname()."::NUM_LAZY_LOAD_COLUMNS); ".$i18nPeerClassName."::addSelectColumns(\$c); \$c->addJoin(".$pk.", ".$i18nPk."); \$c->add(".$cultureColumnName.", \$culture); \$stmt = ".$this->basePeerClassname."::doSelect(\$c, \$con); \$results = array(); while(\$row = \$stmt->fetch(PDO::FETCH_NUM)) { "; if ($table->getChildrenColumn()) { $script .= " \$omClass = ".$this->getPeerClassname()."::getOMClass(\$row, \$startcol); "; } else { $script .= " \$omClass = ".$this->getPeerClassname()."::getOMClass(); "; } $script .= " \$cls = Propel::importClass(\$omClass); \$obj1 = new \$cls(); \$obj1->hydrate(\$row); \$obj1->setCulture(\$culture); "; if ($i18nTable->getChildrenColumn()) { $script .= " \$omClass = ".$i18nTablePeerBuilder->getPeerClassname()."::getOMClass(\$row, \$startcol); "; } else { $script .= " \$omClass = ".$i18nTablePeerBuilder->getPeerClassname()."::getOMClass(); "; } $script .= " \$cls = Propel::importClass(\$omClass); \$obj2 = new \$cls(); \$obj2->hydrate(\$row, \$startcol); \$obj1->set".$i18nClassName."ForCulture(\$obj2, \$culture); \$obj2->set".$className."(\$obj1); \$results[] = \$obj1; } return \$results; } "; }