/** * Get the wraps for getter/setter, if the scope column has not the default name * * @return string */ protected function addScopeAccessors(&$script) { $script .= "\n/**\n * Wrap the getter for scope value\n *\n * @param boolean \$returnNulls If true and all scope values are null, this will return null instead of a array full with nulls\n *\n * @return mixed A array or a native type\n */\npublic function getScopeValue(\$returnNulls = true)\n{\n"; if ($this->behavior->hasMultipleScopes()) { $script .= "\n \$result = array();\n \$onlyNulls = true;\n"; foreach ($this->behavior->getScopes() as $scopeField) { $script .= "\n \$onlyNulls &= null === (\$result[] = \$this->{$this->behavior->getColumnGetter($scopeField)}());\n"; } $script .= "\n\n return \$onlyNulls && \$returnNulls ? null : \$result;\n"; } else { if ($this->behavior->getColumnForParameter('scope_column')->isEnumType()) { $columnConstant = strtoupper(preg_replace('/[^a-zA-Z0-9_\\x7f-\\xff]/', '_', $this->getColumnAttribute('scope_column'))); $script .= "\n return array_search(\$this->{$this->getColumnGetter('scope_column')}(), {$this->tableMapClassName}::getValueSet({$this->tableMapClassName}::COL_{$columnConstant}));\n "; } else { if ($this->behavior->getColumnForParameter('scope_column')->isSetType()) { $columnConstant = strtoupper(preg_replace('/[^a-zA-Z0-9_\\x7f-\\xff]/', '_', $this->getColumnAttribute('scope_column'))); $script .= "\n try {\n return SetColumnConverter::convertToInt(\$this->{$this->getColumnGetter('scope_column')}(), {$this->tableMapClassName}::getValueSet({$this->tableMapClassName}::COL_{$columnConstant}));\n } catch (SetColumnConverterException \$e) {\n throw new PropelException(sprintf('Value \"%s\" is not accepted in this set column', \$e->getValue()), \$e->getCode(), \$e);\n }\n "; } else { $script .= "\n\n return \$this->{$this->getColumnGetter('scope_column')}();\n"; } } } $script .= "\n}\n\n/**\n * Wrap the setter for scope value\n *\n * @param mixed A array or a native type\n * @return \$this|{$this->objectClassName}\n */\npublic function setScopeValue(\$v)\n{\n"; if ($this->behavior->hasMultipleScopes()) { foreach ($this->behavior->getScopes() as $idx => $scopeField) { $script .= "\n \$this->{$this->behavior->getColumnSetter($scopeField)}(\$v === null ? null : \$v[{$idx}]);\n"; } } else { $script .= "\n\n return \$this->{$this->getColumnSetter('scope_column')}(\$v);\n"; } $script .= "\n}\n"; }
/** * Get the wraps for getter/setter, if the scope column has not the default name * * @return string */ protected function addScopeAccessors(&$script) { $script .= "\n/**\n * Wrap the getter for scope value\n *\n * @param boolean \$returnNulls If true and all scope values are null, this will return null instead of a array full with nulls\n *\n * @return mixed A array or a native type\n */\npublic function getScopeValue(\$returnNulls = true)\n{\n"; if ($this->behavior->hasMultipleScopes()) { $script .= "\n \$result = array();\n \$onlyNulls = true;\n"; foreach ($this->behavior->getScopes() as $scopeField) { $script .= "\n \$onlyNulls &= null === (\$result[] = \$this->{$this->behavior->getColumnGetter($scopeField)}());\n"; } $script .= "\n\n return \$onlyNulls && \$returnNulls ? null : \$result;\n"; } else { $script .= "\n\n return \$this->{$this->getColumnGetter('scope_column')}();\n"; } $script .= "\n}\n\n/**\n * Wrap the setter for scope value\n *\n * @param mixed A array or a native type\n * @return \$this|{$this->objectClassName}\n */\npublic function setScopeValue(\$v)\n{\n"; if ($this->behavior->hasMultipleScopes()) { foreach ($this->behavior->getScopes() as $idx => $scopeField) { $script .= "\n \$this->{$this->behavior->getColumnSetter($scopeField)}(\$v === null ? null : \$v[{$idx}]);\n"; } } else { $script .= "\n\n return \$this->{$this->getColumnSetter('scope_column')}(\$v);\n"; } $script .= "\n}\n"; }