protected function addSave(&$script)
    {
        $tmp = '';
        parent::addSave($tmp);
        // add support for created_(at|on) and updated_(at|on) columns
        $date_script = '';
        $updated = false;
        $created = false;
        foreach ($this->getTable()->getColumns() as $col) {
            $clo = strtolower($col->getName());
            if (!$updated && in_array($clo, array('updated_at', 'updated_on'))) {
                $updated = true;
                $date_script .= "\n    if (\$this->isModified() && !\$this->isColumnModified(" . $this->getColumnConstant($col) . "))\n    {\n      \$this->set" . $col->getPhpName() . "(time());\n    }\n";
            } else {
                if (!$created && in_array($clo, array('created_at', 'created_on'))) {
                    $created = true;
                    $date_script .= "\n    if (\$this->isNew() && !\$this->isColumnModified(" . $this->getColumnConstant($col) . "))\n    {\n      \$this->set" . $col->getPhpName() . "(time());\n    }\n";
                }
            }
        }
        $tmp = preg_replace('/{/', '{' . $date_script, $tmp, 1);
        if (DataModelBuilder::getBuildProperty('builderAddBehaviors')) {
            // add sfMixer call
            $pre_mixer_script = "\n\n    foreach (sfMixer::getCallables('{$this->getClassname()}:save:pre') as \$callable)\n    {\n      \$affectedRows = call_user_func(\$callable, \$this, \$con);\n      if (is_int(\$affectedRows))\n      {\n        return \$affectedRows;\n      }\n    }\n\n";
            $post_mixer_script = <<<EOF

    foreach (sfMixer::getCallables('{$this->getClassname()}:save:post') as \$callable)
    {
      call_user_func(\$callable, \$this, \$con, \$affectedRows);
    }

EOF;
            $tmp = preg_replace('/{/', '{' . $pre_mixer_script, $tmp, 1);
            $tmp = preg_replace('/(\\$con\\->commit\\(\\);)/', '$1' . $post_mixer_script, $tmp);
        }
        // update current script
        $script .= $tmp;
    }
Пример #2
0
    protected function addClassClose(&$script)
    {
        parent::addClassClose($script);
        $behaviors = $this->getTable()->getAttribute('behaviors');
        if ($behaviors) {
            $behavior_file_name = 'Base' . $this->getTable()->getPhpName() . 'Behaviors';
            $behavior_file_path = $this->getFilePath($this->getStubObjectBuilder()->getPackage() . '.om.' . $behavior_file_name);
            $behavior_include_script = <<<EOF


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

EOF;
            $script .= sprintf($behavior_include_script, $behavior_file_path);
        }
    }