Example #1
0
 /**
  * Gets the package for the [base] object classes.
  * @return     string
  */
 public function getPackage()
 {
     return parent::getPackage() . ".Om";
 }
 /**
  * Adds the addInitialize() method to the  table map class.
  * @param      string &$script The script will be modified in this method.
  */
 protected function addInitialize(&$script)
 {
     $table = $this->getTable();
     $platform = $this->getPlatform();
     $script .= "\n    /**\n     * Initialize the table attributes, columns and validators\n     * Relations are not initialized by this method since they are lazy loaded\n     *\n     * @return     void\n     * @throws     PropelException\n     */\n    public function initialize()\n    {\n        // attributes\n        \$this->setName('" . $table->getName() . "');\n        \$this->setPhpName('" . $table->getPhpName() . "');\n        \$this->setClassname('" . addslashes($this->getStubObjectBuilder()->getFullyQualifiedClassname()) . "');\n        \$this->setPackage('" . parent::getPackage() . "');";
     if ($table->getIdMethod() == "native") {
         $script .= "\n        \$this->setUseIdGenerator(true);";
     } else {
         $script .= "\n        \$this->setUseIdGenerator(false);";
     }
     if ($table->getIdMethodParameters()) {
         $params = $table->getIdMethodParameters();
         $imp = $params[0];
         $script .= "\n        \$this->setPrimaryKeyMethodInfo('" . $imp->getValue() . "');";
     } elseif ($table->getIdMethod() == IDMethod::NATIVE && ($platform->getNativeIdMethod() == PropelPlatformInterface::SEQUENCE || $platform->getNativeIdMethod() == PropelPlatformInterface::SERIAL)) {
         $script .= "\n        \$this->setPrimaryKeyMethodInfo('" . $platform->getSequenceName($table) . "');";
     }
     if ($this->getTable()->getChildrenColumn()) {
         $script .= "\n        \$this->setSingleTableInheritance(true);";
     }
     // Add columns to map
     $script .= "\n        // columns";
     foreach ($table->getColumns() as $col) {
         $cup = strtoupper($col->getName());
         $cfc = $col->getPhpName();
         if (!$col->getSize()) {
             $size = "null";
         } else {
             $size = $col->getSize();
         }
         $default = $col->getDefaultValueString();
         if ($col->isPrimaryKey()) {
             if ($col->isForeignKey()) {
                 foreach ($col->getForeignKeys() as $fk) {
                     $script .= "\n        \$this->addForeignPrimaryKey('{$cup}', '{$cfc}', '" . $col->getType() . "' , '" . $fk->getForeignTableName() . "', '" . strtoupper($fk->getMappedForeignColumn($col->getName())) . "', " . ($col->isNotNull() ? 'true' : 'false') . ", " . $size . ", {$default});";
                 }
             } else {
                 $script .= "\n        \$this->addPrimaryKey('{$cup}', '{$cfc}', '" . $col->getType() . "', " . var_export($col->isNotNull(), true) . ", " . $size . ", {$default});";
             }
         } else {
             if ($col->isForeignKey()) {
                 foreach ($col->getForeignKeys() as $fk) {
                     $script .= "\n        \$this->addForeignKey('{$cup}', '{$cfc}', '" . $col->getType() . "', '" . $fk->getForeignTableName() . "', '" . strtoupper($fk->getMappedForeignColumn($col->getName())) . "', " . ($col->isNotNull() ? 'true' : 'false') . ", " . $size . ", {$default});";
                 }
             } else {
                 $script .= "\n        \$this->addColumn('{$cup}', '{$cfc}', '" . $col->getType() . "', " . var_export($col->isNotNull(), true) . ", " . $size . ", {$default});";
             }
         }
         // if col-is prim key
         if ($col->isEnumType()) {
             $script .= "\n        \$this->getColumn('{$cup}', false)->setValueSet(" . var_export($col->getValueSet(), true) . ");";
         }
         if ($col->isPrimaryString()) {
             $script .= "\n        \$this->getColumn('{$cup}', false)->setPrimaryString(true);";
         }
     }
     // foreach
     // validators
     $script .= "\n        // validators";
     foreach ($table->getValidators() as $val) {
         $col = $val->getColumn();
         $cup = strtoupper($col->getName());
         foreach ($val->getRules() as $rule) {
             if ($val->getTranslate() !== Validator::TRANSLATE_NONE) {
                 $script .= "\n        \$this->addValidator('{$cup}', '" . $rule->getName() . "', '" . $rule->getClass() . "', '" . str_replace("'", "\\'", $rule->getValue()) . "', " . $val->getTranslate() . "('" . str_replace("'", "\\'", $rule->getMessage()) . "'));";
             } else {
                 $script .= "\n        \$this->addValidator('{$cup}', '" . $rule->getName() . "', '" . $rule->getClass() . "', '" . str_replace("'", "\\'", $rule->getValue()) . "', '" . str_replace("'", "\\'", $rule->getMessage()) . "');";
             }
             // if ($rule->getTranslation() ...
         }
         // foreach rule
     }
     // foreach validator
     $script .= "\n    } // initialize()\n";
 }
 /**
  * Gets the package for the [base] object classes.
  * @return     string
  */
 public function getPackage()
 {
     return ($this->getChild()->getPackage() ? $this->getChild()->getPackage() : parent::getPackage()) . ".Om";
 }
 /**
  * Gets the package for the [base] object classes.
  * @return     string
  */
 public function getPackage()
 {
     return $this->getChild()->getPackage() ? $this->getChild()->getPackage() : parent::getPackage();
 }