Example #1
0
 protected function addSave(&$script)
 {
     parent::addSave($script);
     $script .= "\t\n\tpublic function wasObjectSaved()\n\t{\n\t\treturn \$this->objectSaved;\n\t}\n";
 }
Example #2
0
    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;
    }