Example #1
0
    protected function addClassClose(&$script)
    {
        parent::addClassClose($script);
        $behavior_file_name = 'Base' . $this->getTable()->getPhpName() . 'Behaviors';
        $behavior_file_path = ClassTools::getFilePath($this->getStubObjectBuilder()->getPackage() . '.om', $behavior_file_name);
        $absolute_behavior_file_path = sfConfig::get('sf_root_dir') . '/' . $behavior_file_path;
        if (file_exists($absolute_behavior_file_path)) {
            unlink($absolute_behavior_file_path);
        }
        $behaviors = $this->getTable()->getAttribute('behaviors');
        if ($behaviors) {
            file_put_contents($absolute_behavior_file_path, sprintf("<?php\nsfPropelBehavior::add('%s', %s);\n", $this->getTable()->getPhpName(), var_export(unserialize($behaviors), true)));
            $behavior_include_script = <<<EOF


if (sfProjectConfiguration::getActive() instanceof sfApplicationConfiguration)
{
  include_once '%s';
}

EOF;
            $script .= sprintf($behavior_include_script, $behavior_file_path);
        }
    }
Example #2
0
 /**
  * Closes class.
  * Adds closing brace at end of class and the static map builder registration code.
  * @param      string &$script The script will be modified in this method.
  * @see        addStaticMapBuilderRegistration()
  */
 public function addClassClose(&$script)
 {
     // create retrieveBy* functions
     $methods_created = array();
     foreach ($this->getTable()->getUnices() as $index) {
         // get Column
         if (sizeof($index->getColumns()) != 1) {
             continue;
         }
         $column_name = $index->getColumns();
         $column_name = $column_name[0];
         $column = $this->getTable()->getColumn($column_name);
         if (!$column) {
             continue;
         }
         // method already created?
         if (in_array($column, $methods_created)) {
             continue;
         }
         $methods_created[] = $column;
         // create retrieveBy method
         $table_phpname = $this->getTable()->getPhpName();
         $phpname = $column->getPhpName();
         $peerclass = $this->getPeerClassName();
         $colconst = $this->getColumnConstant($column);
         $script .= "\n\t/**\n\t * Retrieve a single object by {$phpname}\n\t *\n\t * @param      mixed \${$phpname} the {$phpname}\n\t * @param      PropelPDO \$con the connection to use\n\t * @return     {$table_phpname}\n\t */\n\tpublic static function retrieveBy{$phpname}(\${$phpname}, PropelPDO \$con = null)\n\t{\n\t\tif(\$con === null) {\n\t\t\t\$con = Propel::getConnection({$peerclass}::DATABASE_NAME);\n\t\t}\n\t\t\n\t\t\$criteria = new Criteria({$peerclass}::DATABASE_NAME);\n\t\t\$criteria->add({$colconst}, \${$phpname});\n\t\t\n\t\t\$v = {$peerclass}::doSelect(\$criteria, \$con);\n\t\t\n\t\treturn !empty(\$v) ? \$v[0] : null;\n\t}\n";
     }
     // create findBy* functions
     $methods_created = array();
     $columns = array();
     foreach ($this->getTable()->getIndices() as $index) {
         if (sizeof($index->getColumns()) != 1) {
             continue;
         }
         $column_name = $index->getColumns();
         $column_name = $column_name[0];
         $column = $this->getTable()->getColumn($column_name);
         if (!$column) {
             continue;
         }
         $columns[] = $column;
     }
     foreach ($this->getTable()->getForeignKeys() as $fk) {
         if (sizeof($fk->getLocalColumns()) != 1) {
             continue;
         }
         $column_name = $fk->getLocalColumns();
         $column_name = $column_name[0];
         $column = $this->getTable()->getColumn($column_name);
         if (!$column) {
             continue;
         }
         $columns[] = $column;
     }
     foreach ($columns as $column) {
         // method already created
         if (in_array($column, $methods_created)) {
             continue;
         }
         $methods_created[] = $column;
         // create findBy method
         $table_phpname = $this->getTable()->getPhpName();
         $phpname = $column->getPhpName();
         $peerclass = $this->getPeerClassName();
         $colconst = $this->getColumnConstant($column);
         $script .= "\n\t/**\n\t * Retrieve multiple objects by {$phpname}\n\t *\n\t * @param      mixed \${$phpname} the {$phpname}\n\t * @param      PropelPDO \$con the connection to use\n\t * @param      Criteria \$criteria additional criteria to use\n\t * @return     array\n\t */\n\tpublic static function findBy{$phpname}(\${$phpname}, PropelPDO \$con = null, Criteria \$criteria = null)\n\t{\n\t\tif(\$con === null) {\n\t\t\t\$con = Propel::getConnection({$peerclass}::DATABASE_NAME);\n\t\t}\n\t\t\n\t\tif(\$criteria === null) {\n\t\t\t\$criteria = new Criteria;\n\t\t}\n\t\t\n\t\t\$criteria->add({$colconst}, \${$phpname});\n\t\t\n\t\treturn {$peerclass}::doSelect(\$criteria, \$con);\n\t}\n";
     }
     // create find()
     $this->addScript($script, 'FWPropelPeerBuilder/find.php');
     parent::addClassClose($script);
 }