/** * Change default propel behaviour * * Adds setter method for boolean columns. * * @see \Propel\Generator\Builder\Om\ObjectBuilder::addColumnMutators() * * @param string &$script The script will be modified in this method. * @param \Propel\Generator\Model\Column $col The current column. * * @return void */ protected function addBooleanMutator(&$script, Column $col) { $clo = $col->getLowercasedName(); $this->addBooleanMutatorComment($script, $col); $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); $allowNullValues = $col->getAttribute('required', 'true') === 'true' ? 'false' : 'true'; $script .= "\n if (\$v !== null) {\n if (is_string(\$v)) {\n \$v = in_array(strtolower(\$v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;\n } else {\n \$v = (bool) \$v;\n }\n }\n\n \$allowNullValues = {$allowNullValues};\n\n if (\$v === null && !\$allowNullValues) {\n return \$this;\n }\n\n if (\$this->{$clo} !== \$v) {\n \$this->{$clo} = \$v;\n \$this->modifiedColumns[" . $this->getColumnConstant($col) . '] = true; } '; $this->addMutatorClose($script, $col); }
/** * Adds setter method for "normal" columns. * @param string &$script The script will be modified in this method. * @param Column $col The current column. * @see parent::addColumnMutators() */ protected function addDefaultMutator(&$script, Column $col) { $clo = $col->getLowercasedName(); $this->addMutatorOpen($script, $col); // Perform type-casting to ensure that we can use type-sensitive // checking in mutators. if ($col->isPhpPrimitiveType()) { $script .= "\n if (\$v !== null) {\n \$v = (" . $col->getPhpType() . ") \$v;\n }\n"; } $script .= "\n if (\$this->{$clo} !== \$v) {\n \$this->{$clo} = \$v;\n \$this->modifiedColumns[" . $this->getColumnConstant($col) . "] = true;\n }\n"; $this->addMutatorClose($script, $col); }