repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addLazyLoaderBody
protected function addLazyLoaderBody(&$script, Column $col) { $platform = $this->getPlatform(); $clo = strtolower($col->getName()); // pdo_sqlsrv driver requires the use of PDOStatement::bindColumn() or a hex string will be returned if ($col->getType() === PropelTypes::BLOB && $platform instanceof SqlsrvPlatform) { $script .= " \$c = \$this->buildPkeyCriteria(); \$c->addSelectColumn(" . $this->getColumnConstant($col) . "); try { \$row = array(0 => null); \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con); \$stmt->bindColumn(1, \$row[0], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); \$stmt->fetch(PDO::FETCH_BOUND); \$stmt->closeCursor();"; } else { $script .= " \$c = \$this->buildPkeyCriteria(); \$c->addSelectColumn(" . $this->getColumnConstant($col) . "); try { \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con); \$row = \$stmt->fetch(PDO::FETCH_NUM); \$stmt->closeCursor();"; } if ($col->getType() === PropelTypes::CLOB && $platform instanceof OraclePlatform) { // PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string... $script .= " \$this->$clo = stream_get_contents(\$row[0]);"; } elseif ($col->isLobType() && !$platform->hasStreamBlobImpl()) { $script .= " if (\$row[0] !== null) { \$this->$clo = fopen('php://memory', 'r+'); fwrite(\$this->$clo, \$row[0]); rewind(\$this->$clo); } else { \$this->$clo = null; }"; } elseif ($col->isPhpPrimitiveType()) { $script .= " \$this->$clo = (\$row[0] !== null) ? (" . $col->getPhpType() . ") \$row[0] : null;"; } elseif ($col->isPhpObjectType()) { $script .= " \$this->$clo = (\$row[0] !== null) ? new " . $col->getPhpType() . "(\$row[0]) : null;"; } else { $script .= " \$this->$clo = \$row[0];"; } $script .= " \$this->" . $clo . "_isLoaded = true; } catch (Exception \$e) { throw new PropelException(\"Error loading value for [$clo] column on demand.\", \$e); }"; }
php
protected function addLazyLoaderBody(&$script, Column $col) { $platform = $this->getPlatform(); $clo = strtolower($col->getName()); // pdo_sqlsrv driver requires the use of PDOStatement::bindColumn() or a hex string will be returned if ($col->getType() === PropelTypes::BLOB && $platform instanceof SqlsrvPlatform) { $script .= " \$c = \$this->buildPkeyCriteria(); \$c->addSelectColumn(" . $this->getColumnConstant($col) . "); try { \$row = array(0 => null); \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con); \$stmt->bindColumn(1, \$row[0], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); \$stmt->fetch(PDO::FETCH_BOUND); \$stmt->closeCursor();"; } else { $script .= " \$c = \$this->buildPkeyCriteria(); \$c->addSelectColumn(" . $this->getColumnConstant($col) . "); try { \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$c, \$con); \$row = \$stmt->fetch(PDO::FETCH_NUM); \$stmt->closeCursor();"; } if ($col->getType() === PropelTypes::CLOB && $platform instanceof OraclePlatform) { // PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string... $script .= " \$this->$clo = stream_get_contents(\$row[0]);"; } elseif ($col->isLobType() && !$platform->hasStreamBlobImpl()) { $script .= " if (\$row[0] !== null) { \$this->$clo = fopen('php://memory', 'r+'); fwrite(\$this->$clo, \$row[0]); rewind(\$this->$clo); } else { \$this->$clo = null; }"; } elseif ($col->isPhpPrimitiveType()) { $script .= " \$this->$clo = (\$row[0] !== null) ? (" . $col->getPhpType() . ") \$row[0] : null;"; } elseif ($col->isPhpObjectType()) { $script .= " \$this->$clo = (\$row[0] !== null) ? new " . $col->getPhpType() . "(\$row[0]) : null;"; } else { $script .= " \$this->$clo = \$row[0];"; } $script .= " \$this->" . $clo . "_isLoaded = true; } catch (Exception \$e) { throw new PropelException(\"Error loading value for [$clo] column on demand.\", \$e); }"; }
[ "protected", "function", "addLazyLoaderBody", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "platform", "=", "$", "this", "->", "getPlatform", "(", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "// pdo_sqlsrv driver requires the use of PDOStatement::bindColumn() or a hex string will be returned", "if", "(", "$", "col", "->", "getType", "(", ")", "===", "PropelTypes", "::", "BLOB", "&&", "$", "platform", "instanceof", "SqlsrvPlatform", ")", "{", "$", "script", ".=", "\"\n \\$c = \\$this->buildPkeyCriteria();\n \\$c->addSelectColumn(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\");\n try {\n \\$row = array(0 => null);\n \\$stmt = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::doSelectStmt(\\$c, \\$con);\n \\$stmt->bindColumn(1, \\$row[0], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);\n \\$stmt->fetch(PDO::FETCH_BOUND);\n \\$stmt->closeCursor();\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$c = \\$this->buildPkeyCriteria();\n \\$c->addSelectColumn(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\");\n try {\n \\$stmt = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::doSelectStmt(\\$c, \\$con);\n \\$row = \\$stmt->fetch(PDO::FETCH_NUM);\n \\$stmt->closeCursor();\"", ";", "}", "if", "(", "$", "col", "->", "getType", "(", ")", "===", "PropelTypes", "::", "CLOB", "&&", "$", "platform", "instanceof", "OraclePlatform", ")", "{", "// PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string...", "$", "script", ".=", "\"\n \\$this->$clo = stream_get_contents(\\$row[0]);\"", ";", "}", "elseif", "(", "$", "col", "->", "isLobType", "(", ")", "&&", "!", "$", "platform", "->", "hasStreamBlobImpl", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (\\$row[0] !== null) {\n \\$this->$clo = fopen('php://memory', 'r+');\n fwrite(\\$this->$clo, \\$row[0]);\n rewind(\\$this->$clo);\n } else {\n \\$this->$clo = null;\n }\"", ";", "}", "elseif", "(", "$", "col", "->", "isPhpPrimitiveType", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->$clo = (\\$row[0] !== null) ? (\"", ".", "$", "col", "->", "getPhpType", "(", ")", ".", "\") \\$row[0] : null;\"", ";", "}", "elseif", "(", "$", "col", "->", "isPhpObjectType", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->$clo = (\\$row[0] !== null) ? new \"", ".", "$", "col", "->", "getPhpType", "(", ")", ".", "\"(\\$row[0]) : null;\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$this->$clo = \\$row[0];\"", ";", "}", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "clo", ".", "\"_isLoaded = true;\n } catch (Exception \\$e) {\n throw new PropelException(\\\"Error loading value for [$clo] column on demand.\\\", \\$e);\n }\"", ";", "}" ]
Adds the function body for the lazy loader method @param string &$script The script will be modified in this method. @param Column $col The current column. @see addLazyLoader()
[ "Adds", "the", "function", "body", "for", "the", "lazy", "loader", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1391-L1446
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addMutatorOpen
protected function addMutatorOpen(&$script, Column $col) { $this->addMutatorComment($script, $col); $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); }
php
protected function addMutatorOpen(&$script, Column $col) { $this->addMutatorComment($script, $col); $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); }
[ "protected", "function", "addMutatorOpen", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "this", "->", "addMutatorComment", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorOpenOpen", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorOpenBody", "(", "$", "script", ",", "$", "col", ")", ";", "}" ]
Adds the open of the mutator (setter) method for a column. @param string &$script The script will be modified in this method. @param Column $col The current column.
[ "Adds", "the", "open", "of", "the", "mutator", "(", "setter", ")", "method", "for", "a", "column", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1474-L1479
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addMutatorComment
public function addMutatorComment(&$script, Column $col) { $clo = strtolower($col->getName()); $script .= " /** * Set the value of [$clo] column. * " . $col->getDescription() . " * @param " . $col->getPhpType() . " \$v new value * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */"; }
php
public function addMutatorComment(&$script, Column $col) { $clo = strtolower($col->getName()); $script .= " /** * Set the value of [$clo] column. * " . $col->getDescription() . " * @param " . $col->getPhpType() . " \$v new value * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */"; }
[ "public", "function", "addMutatorComment", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n /**\n * Set the value of [$clo] column.\n * \"", ".", "$", "col", "->", "getDescription", "(", ")", ".", "\"\n * @param \"", ".", "$", "col", "->", "getPhpType", "(", ")", ".", "\" \\$v new value\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n */\"", ";", "}" ]
Adds the comment for a mutator @param string &$script The script will be modified in this method. @param Column $col The current column. @see addMutatorOpen()
[ "Adds", "the", "comment", "for", "a", "mutator" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1489-L1499
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addMutatorOpenOpen
public function addMutatorOpenOpen(&$script, Column $col) { $cfc = $col->getPhpName(); $visibility = $col->getMutatorVisibility(); $script .= " " . $visibility . " function set$cfc(\$v) {"; }
php
public function addMutatorOpenOpen(&$script, Column $col) { $cfc = $col->getPhpName(); $visibility = $col->getMutatorVisibility(); $script .= " " . $visibility . " function set$cfc(\$v) {"; }
[ "public", "function", "addMutatorOpenOpen", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "cfc", "=", "$", "col", "->", "getPhpName", "(", ")", ";", "$", "visibility", "=", "$", "col", "->", "getMutatorVisibility", "(", ")", ";", "$", "script", ".=", "\"\n \"", ".", "$", "visibility", ".", "\" function set$cfc(\\$v)\n {\"", ";", "}" ]
Adds the mutator function declaration @param string &$script The script will be modified in this method. @param Column $col The current column. @see addMutatorOpen()
[ "Adds", "the", "mutator", "function", "declaration" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1509-L1517
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addMutatorOpenBody
protected function addMutatorOpenBody(&$script, Column $col) { $clo = strtolower($col->getName()); $cfc = $col->getPhpName(); if ($col->isLazyLoad()) { $script .= " // Allow unsetting the lazy loaded column even when its not loaded. if (!\$this->" . $clo . "_isLoaded && \$v === null) { \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } // explicitly set the is-loaded flag to true for this lazy load col; // it doesn't matter if the value is actually set or not (logic below) as // any attempt to set the value means that no db lookup should be performed // when the get$cfc() method is called. \$this->" . $clo . "_isLoaded = true; "; } }
php
protected function addMutatorOpenBody(&$script, Column $col) { $clo = strtolower($col->getName()); $cfc = $col->getPhpName(); if ($col->isLazyLoad()) { $script .= " // Allow unsetting the lazy loaded column even when its not loaded. if (!\$this->" . $clo . "_isLoaded && \$v === null) { \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } // explicitly set the is-loaded flag to true for this lazy load col; // it doesn't matter if the value is actually set or not (logic below) as // any attempt to set the value means that no db lookup should be performed // when the get$cfc() method is called. \$this->" . $clo . "_isLoaded = true; "; } }
[ "protected", "function", "addMutatorOpenBody", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "cfc", "=", "$", "col", "->", "getPhpName", "(", ")", ";", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "script", ".=", "\"\n // Allow unsetting the lazy loaded column even when its not loaded.\n if (!\\$this->\"", ".", "$", "clo", ".", "\"_isLoaded && \\$v === null) {\n \\$this->modifiedColumns[] = \"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\";\n }\n\n // explicitly set the is-loaded flag to true for this lazy load col;\n // it doesn't matter if the value is actually set or not (logic below) as\n // any attempt to set the value means that no db lookup should be performed\n // when the get$cfc() method is called.\n \\$this->\"", ".", "$", "clo", ".", "\"_isLoaded = true;\n\"", ";", "}", "}" ]
Adds the mutator open body part @param string &$script The script will be modified in this method. @param Column $col The current column. @see addMutatorOpen()
[ "Adds", "the", "mutator", "open", "body", "part" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1527-L1545
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addMutatorClose
protected function addMutatorClose(&$script, Column $col) { $this->addMutatorCloseBody($script, $col); $this->addMutatorCloseClose($script, $col); }
php
protected function addMutatorClose(&$script, Column $col) { $this->addMutatorCloseBody($script, $col); $this->addMutatorCloseClose($script, $col); }
[ "protected", "function", "addMutatorClose", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "this", "->", "addMutatorCloseBody", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorCloseClose", "(", "$", "script", ",", "$", "col", ")", ";", "}" ]
Adds the close of the mutator (setter) method for a column. @param string &$script The script will be modified in this method. @param Column $col The current column.
[ "Adds", "the", "close", "of", "the", "mutator", "(", "setter", ")", "method", "for", "a", "column", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1553-L1557
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addLobMutator
protected function addLobMutator(&$script, Column $col) { $this->addMutatorOpen($script, $col); $clo = strtolower($col->getName()); $script .= " // Because BLOB columns are streams in PDO we have to assume that they are // always modified when a new value is passed in. For example, the contents // of the stream itself may have changed externally. if (!is_resource(\$v) && \$v !== null) { \$this->$clo = fopen('php://memory', 'r+'); fwrite(\$this->$clo, \$v); rewind(\$this->$clo); } else { // it's already a stream \$this->$clo = \$v; } \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; "; $this->addMutatorClose($script, $col); }
php
protected function addLobMutator(&$script, Column $col) { $this->addMutatorOpen($script, $col); $clo = strtolower($col->getName()); $script .= " // Because BLOB columns are streams in PDO we have to assume that they are // always modified when a new value is passed in. For example, the contents // of the stream itself may have changed externally. if (!is_resource(\$v) && \$v !== null) { \$this->$clo = fopen('php://memory', 'r+'); fwrite(\$this->$clo, \$v); rewind(\$this->$clo); } else { // it's already a stream \$this->$clo = \$v; } \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; "; $this->addMutatorClose($script, $col); }
[ "protected", "function", "addLobMutator", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "this", "->", "addMutatorOpen", "(", "$", "script", ",", "$", "col", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n // Because BLOB columns are streams in PDO we have to assume that they are\n // always modified when a new value is passed in. For example, the contents\n // of the stream itself may have changed externally.\n if (!is_resource(\\$v) && \\$v !== null) {\n \\$this->$clo = fopen('php://memory', 'r+');\n fwrite(\\$this->$clo, \\$v);\n rewind(\\$this->$clo);\n } else { // it's already a stream\n \\$this->$clo = \\$v;\n }\n \\$this->modifiedColumns[] = \"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\";\n\"", ";", "$", "this", "->", "addMutatorClose", "(", "$", "script", ",", "$", "col", ")", ";", "}" ]
Adds a setter for BLOB columns. @param string &$script The script will be modified in this method. @param Column $col The current column. @see parent::addColumnMutators()
[ "Adds", "a", "setter", "for", "BLOB", "columns", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1653-L1671
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addTemporalMutator
protected function addTemporalMutator(&$script, Column $col) { $cfc = $col->getPhpName(); $clo = strtolower($col->getName()); $visibility = $col->getMutatorVisibility(); $dateTimeClass = $this->getBuildProperty('dateTimeClass'); if (!$dateTimeClass) { $dateTimeClass = 'DateTime'; } $this->declareClasses($dateTimeClass, 'DateTimeZone', 'PropelDateTime'); $this->addTemporalMutatorComment($script, $col); $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); $fmt = var_export($this->getTemporalFormatter($col), true); $script .= " \$dt = PropelDateTime::newInstance(\$v, null, '$dateTimeClass'); if (\$this->$clo !== null || \$dt !== null) { \$currentDateAsString = (\$this->$clo !== null && \$tmpDt = new $dateTimeClass(\$this->$clo)) ? \$tmpDt->format($fmt) : null; \$newDateAsString = \$dt ? \$dt->format($fmt) : null;"; if (($def = $col->getDefaultValue()) !== null && !$def->isExpression()) { $defaultValue = $this->getDefaultValueString($col); $script .= " if ( (\$currentDateAsString !== \$newDateAsString) // normalized values don't match || (\$dt->format($fmt) === $defaultValue) // or the entered value matches the default ) {"; } else { $script .= " if (\$currentDateAsString !== \$newDateAsString) {"; } $script .= " \$this->$clo = \$newDateAsString; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } } // if either are not null "; $this->addMutatorClose($script, $col); }
php
protected function addTemporalMutator(&$script, Column $col) { $cfc = $col->getPhpName(); $clo = strtolower($col->getName()); $visibility = $col->getMutatorVisibility(); $dateTimeClass = $this->getBuildProperty('dateTimeClass'); if (!$dateTimeClass) { $dateTimeClass = 'DateTime'; } $this->declareClasses($dateTimeClass, 'DateTimeZone', 'PropelDateTime'); $this->addTemporalMutatorComment($script, $col); $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); $fmt = var_export($this->getTemporalFormatter($col), true); $script .= " \$dt = PropelDateTime::newInstance(\$v, null, '$dateTimeClass'); if (\$this->$clo !== null || \$dt !== null) { \$currentDateAsString = (\$this->$clo !== null && \$tmpDt = new $dateTimeClass(\$this->$clo)) ? \$tmpDt->format($fmt) : null; \$newDateAsString = \$dt ? \$dt->format($fmt) : null;"; if (($def = $col->getDefaultValue()) !== null && !$def->isExpression()) { $defaultValue = $this->getDefaultValueString($col); $script .= " if ( (\$currentDateAsString !== \$newDateAsString) // normalized values don't match || (\$dt->format($fmt) === $defaultValue) // or the entered value matches the default ) {"; } else { $script .= " if (\$currentDateAsString !== \$newDateAsString) {"; } $script .= " \$this->$clo = \$newDateAsString; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } } // if either are not null "; $this->addMutatorClose($script, $col); }
[ "protected", "function", "addTemporalMutator", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "cfc", "=", "$", "col", "->", "getPhpName", "(", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "visibility", "=", "$", "col", "->", "getMutatorVisibility", "(", ")", ";", "$", "dateTimeClass", "=", "$", "this", "->", "getBuildProperty", "(", "'dateTimeClass'", ")", ";", "if", "(", "!", "$", "dateTimeClass", ")", "{", "$", "dateTimeClass", "=", "'DateTime'", ";", "}", "$", "this", "->", "declareClasses", "(", "$", "dateTimeClass", ",", "'DateTimeZone'", ",", "'PropelDateTime'", ")", ";", "$", "this", "->", "addTemporalMutatorComment", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorOpenOpen", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorOpenBody", "(", "$", "script", ",", "$", "col", ")", ";", "$", "fmt", "=", "var_export", "(", "$", "this", "->", "getTemporalFormatter", "(", "$", "col", ")", ",", "true", ")", ";", "$", "script", ".=", "\"\n \\$dt = PropelDateTime::newInstance(\\$v, null, '$dateTimeClass');\n if (\\$this->$clo !== null || \\$dt !== null) {\n \\$currentDateAsString = (\\$this->$clo !== null && \\$tmpDt = new $dateTimeClass(\\$this->$clo)) ? \\$tmpDt->format($fmt) : null;\n \\$newDateAsString = \\$dt ? \\$dt->format($fmt) : null;\"", ";", "if", "(", "(", "$", "def", "=", "$", "col", "->", "getDefaultValue", "(", ")", ")", "!==", "null", "&&", "!", "$", "def", "->", "isExpression", "(", ")", ")", "{", "$", "defaultValue", "=", "$", "this", "->", "getDefaultValueString", "(", "$", "col", ")", ";", "$", "script", ".=", "\"\n if ( (\\$currentDateAsString !== \\$newDateAsString) // normalized values don't match\n || (\\$dt->format($fmt) === $defaultValue) // or the entered value matches the default\n ) {\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n if (\\$currentDateAsString !== \\$newDateAsString) {\"", ";", "}", "$", "script", ".=", "\"\n \\$this->$clo = \\$newDateAsString;\n \\$this->modifiedColumns[] = \"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\";\n }\n } // if either are not null\n\"", ";", "$", "this", "->", "addMutatorClose", "(", "$", "script", ",", "$", "col", ")", ";", "}" ]
Adds a setter method for date/time/timestamp columns. @param string &$script The script will be modified in this method. @param Column $col The current column. @see parent::addColumnMutators()
[ "Adds", "a", "setter", "method", "for", "date", "/", "time", "/", "timestamp", "columns", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1681-L1723
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addObjectMutator
protected function addObjectMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $cloUnserialized = $clo . '_unserialized'; $this->addMutatorOpen($script, $col); $script .= " if (\$this->$cloUnserialized !== \$v) { \$this->$cloUnserialized = \$v; \$this->$clo = serialize(\$v); \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
php
protected function addObjectMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $cloUnserialized = $clo . '_unserialized'; $this->addMutatorOpen($script, $col); $script .= " if (\$this->$cloUnserialized !== \$v) { \$this->$cloUnserialized = \$v; \$this->$clo = serialize(\$v); \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
[ "protected", "function", "addObjectMutator", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "cloUnserialized", "=", "$", "clo", ".", "'_unserialized'", ";", "$", "this", "->", "addMutatorOpen", "(", "$", "script", ",", "$", "col", ")", ";", "$", "script", ".=", "\"\n if (\\$this->$cloUnserialized !== \\$v) {\n \\$this->$cloUnserialized = \\$v;\n \\$this->$clo = serialize(\\$v);\n \\$this->modifiedColumns[] = \"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\";\n }\n\"", ";", "$", "this", "->", "addMutatorClose", "(", "$", "script", ",", "$", "col", ")", ";", "}" ]
Adds a setter for Object columns. @param string &$script The script will be modified in this method. @param Column $col The current column. @see parent::addColumnMutators()
[ "Adds", "a", "setter", "for", "Object", "columns", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1748-L1762
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addAddArrayElement
protected function addAddArrayElement(&$script, Column $col) { $clo = strtolower($col->getName()); $cfc = $col->getPhpName(); $visibility = $col->getAccessorVisibility(); $singularPhpName = rtrim($cfc, 's'); $script .= " /** * Adds a value to the [$clo] array column value. * @param mixed \$value * " . $col->getDescription(); if ($col->isLazyLoad()) { $script .= " * @param PropelPDO \$con An optional PropelPDO connection to use for fetching this lazy-loaded column."; } $script .= " * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ $visibility function add$singularPhpName(\$value"; if ($col->isLazyLoad()) { $script .= ", PropelPDO \$con = null"; } $script .= ") { \$currentArray = \$this->get$cfc("; if ($col->isLazyLoad()) { $script .= "\$con"; } $script .= "); \$currentArray []= \$value; \$this->set$cfc(\$currentArray); return \$this; } // add$singularPhpName() "; }
php
protected function addAddArrayElement(&$script, Column $col) { $clo = strtolower($col->getName()); $cfc = $col->getPhpName(); $visibility = $col->getAccessorVisibility(); $singularPhpName = rtrim($cfc, 's'); $script .= " /** * Adds a value to the [$clo] array column value. * @param mixed \$value * " . $col->getDescription(); if ($col->isLazyLoad()) { $script .= " * @param PropelPDO \$con An optional PropelPDO connection to use for fetching this lazy-loaded column."; } $script .= " * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ $visibility function add$singularPhpName(\$value"; if ($col->isLazyLoad()) { $script .= ", PropelPDO \$con = null"; } $script .= ") { \$currentArray = \$this->get$cfc("; if ($col->isLazyLoad()) { $script .= "\$con"; } $script .= "); \$currentArray []= \$value; \$this->set$cfc(\$currentArray); return \$this; } // add$singularPhpName() "; }
[ "protected", "function", "addAddArrayElement", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "cfc", "=", "$", "col", "->", "getPhpName", "(", ")", ";", "$", "visibility", "=", "$", "col", "->", "getAccessorVisibility", "(", ")", ";", "$", "singularPhpName", "=", "rtrim", "(", "$", "cfc", ",", "'s'", ")", ";", "$", "script", ".=", "\"\n /**\n * Adds a value to the [$clo] array column value.\n * @param mixed \\$value\n * \"", ".", "$", "col", "->", "getDescription", "(", ")", ";", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "script", ".=", "\"\n * @param PropelPDO \\$con An optional PropelPDO connection to use for fetching this lazy-loaded column.\"", ";", "}", "$", "script", ".=", "\"\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n */\n $visibility function add$singularPhpName(\\$value\"", ";", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "script", ".=", "\", PropelPDO \\$con = null\"", ";", "}", "$", "script", ".=", "\")\n {\n \\$currentArray = \\$this->get$cfc(\"", ";", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "script", ".=", "\"\\$con\"", ";", "}", "$", "script", ".=", "\");\n \\$currentArray []= \\$value;\n \\$this->set$cfc(\\$currentArray);\n\n return \\$this;\n } // add$singularPhpName()\n\"", ";", "}" ]
Adds a push method for an array column. @param string &$script The script will be modified in this method. @param Column $col The current column.
[ "Adds", "a", "push", "method", "for", "an", "array", "column", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1794-L1829
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addEnumMutator
protected function addEnumMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $script .= " /** * Set the value of [$clo] column. * " . $col->getDescription() . " * @param " . $col->getPhpType() . " \$v new value * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException - if the value is not accepted by this enum. */"; $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); $script .= " if (\$v !== null) { \$valueSet = " . $this->getPeerClassname() . "::getValueSet(" . $this->getColumnConstant($col) . "); if (!in_array(\$v, \$valueSet)) { throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \$v)); } \$v = array_search(\$v, \$valueSet); } if (\$this->$clo !== \$v) { \$this->$clo = \$v; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
php
protected function addEnumMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $script .= " /** * Set the value of [$clo] column. * " . $col->getDescription() . " * @param " . $col->getPhpType() . " \$v new value * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException - if the value is not accepted by this enum. */"; $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); $script .= " if (\$v !== null) { \$valueSet = " . $this->getPeerClassname() . "::getValueSet(" . $this->getColumnConstant($col) . "); if (!in_array(\$v, \$valueSet)) { throw new PropelException(sprintf('Value \"%s\" is not accepted in this enumerated column', \$v)); } \$v = array_search(\$v, \$valueSet); } if (\$this->$clo !== \$v) { \$this->$clo = \$v; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
[ "protected", "function", "addEnumMutator", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n /**\n * Set the value of [$clo] column.\n * \"", ".", "$", "col", "->", "getDescription", "(", ")", ".", "\"\n * @param \"", ".", "$", "col", "->", "getPhpType", "(", ")", ".", "\" \\$v new value\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n * @throws PropelException - if the value is not accepted by this enum.\n */\"", ";", "$", "this", "->", "addMutatorOpenOpen", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorOpenBody", "(", "$", "script", ",", "$", "col", ")", ";", "$", "script", ".=", "\"\n if (\\$v !== null) {\n \\$valueSet = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::getValueSet(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\");\n if (!in_array(\\$v, \\$valueSet)) {\n throw new PropelException(sprintf('Value \\\"%s\\\" is not accepted in this enumerated column', \\$v));\n }\n \\$v = array_search(\\$v, \\$valueSet);\n }\n\n if (\\$this->$clo !== \\$v) {\n \\$this->$clo = \\$v;\n \\$this->modifiedColumns[] = \"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\";\n }\n\"", ";", "$", "this", "->", "addMutatorClose", "(", "$", "script", ",", "$", "col", ")", ";", "}" ]
Adds a setter for Enum columns. @param string &$script The script will be modified in this method. @param Column $col The current column. @see parent::addColumnMutators()
[ "Adds", "a", "setter", "for", "Enum", "columns", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1887-L1917
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addBooleanMutator
protected function addBooleanMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $this->addBooleanMutatorComment($script, $col); $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); $script .= " if (\$v !== null) { if (is_string(\$v)) { \$v = in_array(strtolower(\$v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; } else { \$v = (boolean) \$v; } } "; $script .= " if (\$this->$clo !== \$v) { \$this->$clo = \$v; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
php
protected function addBooleanMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $this->addBooleanMutatorComment($script, $col); $this->addMutatorOpenOpen($script, $col); $this->addMutatorOpenBody($script, $col); $script .= " if (\$v !== null) { if (is_string(\$v)) { \$v = in_array(strtolower(\$v), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; } else { \$v = (boolean) \$v; } } "; $script .= " if (\$this->$clo !== \$v) { \$this->$clo = \$v; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
[ "protected", "function", "addBooleanMutator", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "addBooleanMutatorComment", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorOpenOpen", "(", "$", "script", ",", "$", "col", ")", ";", "$", "this", "->", "addMutatorOpenBody", "(", "$", "script", ",", "$", "col", ")", ";", "$", "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 = (boolean) \\$v;\n }\n }\n\"", ";", "$", "script", ".=", "\"\n if (\\$this->$clo !== \\$v) {\n \\$this->$clo = \\$v;\n \\$this->modifiedColumns[] = \"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\";\n }\n\"", ";", "$", "this", "->", "addMutatorClose", "(", "$", "script", ",", "$", "col", ")", ";", "}" ]
Adds setter method for boolean columns. @param string &$script The script will be modified in this method. @param Column $col The current column. @see parent::addColumnMutators()
[ "Adds", "setter", "method", "for", "boolean", "columns", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1927-L1952
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addDefaultMutator
protected function addDefaultMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $this->addMutatorOpen($script, $col); // Perform type-casting to ensure that we can use type-sensitive // checking in mutators. if ($col->isPhpPrimitiveType()) { if ($col->isTextType()) { $script .= " if (\$v !== null) {"; } else { $script .= " if (\$v !== null && is_numeric(\$v)) {"; } $script .= " \$v = (" . $col->getPhpType() . ") \$v; } "; } $script .= " if (\$this->$clo !== \$v) { \$this->$clo = \$v; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
php
protected function addDefaultMutator(&$script, Column $col) { $clo = strtolower($col->getName()); $this->addMutatorOpen($script, $col); // Perform type-casting to ensure that we can use type-sensitive // checking in mutators. if ($col->isPhpPrimitiveType()) { if ($col->isTextType()) { $script .= " if (\$v !== null) {"; } else { $script .= " if (\$v !== null && is_numeric(\$v)) {"; } $script .= " \$v = (" . $col->getPhpType() . ") \$v; } "; } $script .= " if (\$this->$clo !== \$v) { \$this->$clo = \$v; \$this->modifiedColumns[] = " . $this->getColumnConstant($col) . "; } "; $this->addMutatorClose($script, $col); }
[ "protected", "function", "addDefaultMutator", "(", "&", "$", "script", ",", "Column", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "addMutatorOpen", "(", "$", "script", ",", "$", "col", ")", ";", "// Perform type-casting to ensure that we can use type-sensitive", "// checking in mutators.", "if", "(", "$", "col", "->", "isPhpPrimitiveType", "(", ")", ")", "{", "if", "(", "$", "col", "->", "isTextType", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (\\$v !== null) {\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n if (\\$v !== null && is_numeric(\\$v)) {\"", ";", "}", "$", "script", ".=", "\"\n \\$v = (\"", ".", "$", "col", "->", "getPhpType", "(", ")", ".", "\") \\$v;\n }\n\"", ";", "}", "$", "script", ".=", "\"\n if (\\$this->$clo !== \\$v) {\n \\$this->$clo = \\$v;\n \\$this->modifiedColumns[] = \"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\";\n }\n\"", ";", "$", "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()
[ "Adds", "setter", "method", "for", "normal", "columns", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L1980-L2010
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addHydrateBody
protected function addHydrateBody(&$script) { $table = $this->getTable(); $platform = $this->getPlatform(); $script .= " try { "; $n = 0; foreach ($table->getColumns() as $col) { if (!$col->isLazyLoad()) { $clo = strtolower($col->getName()); if ($col->getType() === PropelTypes::CLOB_EMU && $this->getPlatform() instanceof OraclePlatform) { // PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string... $script .= " \$this->$clo = stream_get_contents(\$row[\$startcol + $n]);"; } elseif ($col->isLobType() && !$platform->hasStreamBlobImpl()) { $script .= " if (\$row[\$startcol + $n] !== null) { \$this->$clo = fopen('php://memory', 'r+'); fwrite(\$this->$clo, \$row[\$startcol + $n]); rewind(\$this->$clo); } else { \$this->$clo = null; }"; } elseif ($col->isPhpPrimitiveType()) { $script .= " \$this->$clo = (\$row[\$startcol + $n] !== null) ? (" . $col->getPhpType() . ") \$row[\$startcol + $n] : null;"; } elseif ($col->getType() === PropelTypes::OBJECT) { $script .= " \$this->$clo = \$row[\$startcol + $n];"; } elseif ($col->getType() === PropelTypes::PHP_ARRAY) { $cloUnserialized = $clo . '_unserialized'; $script .= " \$this->$clo = \$row[\$startcol + $n]; \$this->$cloUnserialized = null;"; } elseif ($col->isPhpObjectType()) { $script .= " \$this->$clo = (\$row[\$startcol + $n] !== null) ? new " . $col->getPhpType() . "(\$row[\$startcol + $n]) : null;"; } else { $script .= " \$this->$clo = \$row[\$startcol + $n];"; } $n++; } // if col->isLazyLoad() } /* foreach */ if ($this->getBuildProperty("addSaveMethod")) { $script .= " \$this->resetModified(); "; } $script .= " \$this->setNew(false); if (\$rehydrate) { \$this->ensureConsistency(); } \$this->postHydrate(\$row, \$startcol, \$rehydrate);"; $this->applyBehaviorModifier('postHydrate', $script, " "); $script .= " return \$startcol + $n; // $n = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS. } catch (Exception \$e) { throw new PropelException(\"Error populating " . $this->getStubObjectBuilder()->getClassname() . " object\", \$e); }"; }
php
protected function addHydrateBody(&$script) { $table = $this->getTable(); $platform = $this->getPlatform(); $script .= " try { "; $n = 0; foreach ($table->getColumns() as $col) { if (!$col->isLazyLoad()) { $clo = strtolower($col->getName()); if ($col->getType() === PropelTypes::CLOB_EMU && $this->getPlatform() instanceof OraclePlatform) { // PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string... $script .= " \$this->$clo = stream_get_contents(\$row[\$startcol + $n]);"; } elseif ($col->isLobType() && !$platform->hasStreamBlobImpl()) { $script .= " if (\$row[\$startcol + $n] !== null) { \$this->$clo = fopen('php://memory', 'r+'); fwrite(\$this->$clo, \$row[\$startcol + $n]); rewind(\$this->$clo); } else { \$this->$clo = null; }"; } elseif ($col->isPhpPrimitiveType()) { $script .= " \$this->$clo = (\$row[\$startcol + $n] !== null) ? (" . $col->getPhpType() . ") \$row[\$startcol + $n] : null;"; } elseif ($col->getType() === PropelTypes::OBJECT) { $script .= " \$this->$clo = \$row[\$startcol + $n];"; } elseif ($col->getType() === PropelTypes::PHP_ARRAY) { $cloUnserialized = $clo . '_unserialized'; $script .= " \$this->$clo = \$row[\$startcol + $n]; \$this->$cloUnserialized = null;"; } elseif ($col->isPhpObjectType()) { $script .= " \$this->$clo = (\$row[\$startcol + $n] !== null) ? new " . $col->getPhpType() . "(\$row[\$startcol + $n]) : null;"; } else { $script .= " \$this->$clo = \$row[\$startcol + $n];"; } $n++; } // if col->isLazyLoad() } /* foreach */ if ($this->getBuildProperty("addSaveMethod")) { $script .= " \$this->resetModified(); "; } $script .= " \$this->setNew(false); if (\$rehydrate) { \$this->ensureConsistency(); } \$this->postHydrate(\$row, \$startcol, \$rehydrate);"; $this->applyBehaviorModifier('postHydrate', $script, " "); $script .= " return \$startcol + $n; // $n = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS. } catch (Exception \$e) { throw new PropelException(\"Error populating " . $this->getStubObjectBuilder()->getClassname() . " object\", \$e); }"; }
[ "protected", "function", "addHydrateBody", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "platform", "=", "$", "this", "->", "getPlatform", "(", ")", ";", "$", "script", ".=", "\"\n try {\n\"", ";", "$", "n", "=", "0", ";", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "if", "(", "!", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "col", "->", "getType", "(", ")", "===", "PropelTypes", "::", "CLOB_EMU", "&&", "$", "this", "->", "getPlatform", "(", ")", "instanceof", "OraclePlatform", ")", "{", "// PDO_OCI returns a stream for CLOB objects, while other PDO adapters return a string...", "$", "script", ".=", "\"\n \\$this->$clo = stream_get_contents(\\$row[\\$startcol + $n]);\"", ";", "}", "elseif", "(", "$", "col", "->", "isLobType", "(", ")", "&&", "!", "$", "platform", "->", "hasStreamBlobImpl", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (\\$row[\\$startcol + $n] !== null) {\n \\$this->$clo = fopen('php://memory', 'r+');\n fwrite(\\$this->$clo, \\$row[\\$startcol + $n]);\n rewind(\\$this->$clo);\n } else {\n \\$this->$clo = null;\n }\"", ";", "}", "elseif", "(", "$", "col", "->", "isPhpPrimitiveType", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->$clo = (\\$row[\\$startcol + $n] !== null) ? (\"", ".", "$", "col", "->", "getPhpType", "(", ")", ".", "\") \\$row[\\$startcol + $n] : null;\"", ";", "}", "elseif", "(", "$", "col", "->", "getType", "(", ")", "===", "PropelTypes", "::", "OBJECT", ")", "{", "$", "script", ".=", "\"\n \\$this->$clo = \\$row[\\$startcol + $n];\"", ";", "}", "elseif", "(", "$", "col", "->", "getType", "(", ")", "===", "PropelTypes", "::", "PHP_ARRAY", ")", "{", "$", "cloUnserialized", "=", "$", "clo", ".", "'_unserialized'", ";", "$", "script", ".=", "\"\n \\$this->$clo = \\$row[\\$startcol + $n];\n \\$this->$cloUnserialized = null;\"", ";", "}", "elseif", "(", "$", "col", "->", "isPhpObjectType", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->$clo = (\\$row[\\$startcol + $n] !== null) ? new \"", ".", "$", "col", "->", "getPhpType", "(", ")", ".", "\"(\\$row[\\$startcol + $n]) : null;\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$this->$clo = \\$row[\\$startcol + $n];\"", ";", "}", "$", "n", "++", ";", "}", "// if col->isLazyLoad()", "}", "/* foreach */", "if", "(", "$", "this", "->", "getBuildProperty", "(", "\"addSaveMethod\"", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->resetModified();\n\"", ";", "}", "$", "script", ".=", "\"\n \\$this->setNew(false);\n\n if (\\$rehydrate) {\n \\$this->ensureConsistency();\n }\n \\$this->postHydrate(\\$row, \\$startcol, \\$rehydrate);\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'postHydrate'", ",", "$", "script", ",", "\" \"", ")", ";", "$", "script", ".=", "\"\n\n return \\$startcol + $n; // $n = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::NUM_HYDRATE_COLUMNS.\n\n } catch (Exception \\$e) {\n throw new PropelException(\\\"Error populating \"", ".", "$", "this", "->", "getStubObjectBuilder", "(", ")", "->", "getClassname", "(", ")", ".", "\" object\\\", \\$e);\n }\"", ";", "}" ]
Adds the function body for the hydrate method @param string &$script The script will be modified in this method. @see addHydrate()
[ "Adds", "the", "function", "body", "for", "the", "hydrate", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L2167-L2236
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addBuildPkeyCriteria
protected function addBuildPkeyCriteria(&$script) { $this->addBuildPkeyCriteriaComment($script); $this->addBuildPkeyCriteriaOpen($script); $this->addBuildPkeyCriteriaBody($script); $this->addBuildPkeyCriteriaClose($script); }
php
protected function addBuildPkeyCriteria(&$script) { $this->addBuildPkeyCriteriaComment($script); $this->addBuildPkeyCriteriaOpen($script); $this->addBuildPkeyCriteriaBody($script); $this->addBuildPkeyCriteriaClose($script); }
[ "protected", "function", "addBuildPkeyCriteria", "(", "&", "$", "script", ")", "{", "$", "this", "->", "addBuildPkeyCriteriaComment", "(", "$", "script", ")", ";", "$", "this", "->", "addBuildPkeyCriteriaOpen", "(", "$", "script", ")", ";", "$", "this", "->", "addBuildPkeyCriteriaBody", "(", "$", "script", ")", ";", "$", "this", "->", "addBuildPkeyCriteriaClose", "(", "$", "script", ")", ";", "}" ]
Adds the buildPkeyCriteria method @param string &$script The script will be modified in this method.
[ "Adds", "the", "buildPkeyCriteria", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L2257-L2263
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addBuildPkeyCriteriaBody
protected function addBuildPkeyCriteriaBody(&$script) { $script .= " \$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);"; foreach ($this->getTable()->getPrimaryKey() as $col) { $clo = strtolower($col->getName()); $script .= " \$criteria->add(" . $this->getColumnConstant($col) . ", \$this->$clo);"; } }
php
protected function addBuildPkeyCriteriaBody(&$script) { $script .= " \$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);"; foreach ($this->getTable()->getPrimaryKey() as $col) { $clo = strtolower($col->getName()); $script .= " \$criteria->add(" . $this->getColumnConstant($col) . ", \$this->$clo);"; } }
[ "protected", "function", "addBuildPkeyCriteriaBody", "(", "&", "$", "script", ")", "{", "$", "script", ".=", "\"\n \\$criteria = new Criteria(\"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME);\"", ";", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getPrimaryKey", "(", ")", "as", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n \\$criteria->add(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\", \\$this->$clo);\"", ";", "}", "}" ]
Adds the function body for the buildPkeyCriteria method @param string &$script The script will be modified in this method. @see addBuildPkeyCriteria()
[ "Adds", "the", "function", "body", "for", "the", "buildPkeyCriteria", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L2306-L2315
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addBuildCriteriaBody
protected function addBuildCriteriaBody(&$script) { $script .= " \$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME); "; foreach ($this->getTable()->getColumns() as $col) { $clo = strtolower($col->getName()); $script .= " if (\$this->isColumnModified(" . $this->getColumnConstant($col) . ")) \$criteria->add(" . $this->getColumnConstant($col) . ", \$this->$clo);"; } }
php
protected function addBuildCriteriaBody(&$script) { $script .= " \$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME); "; foreach ($this->getTable()->getColumns() as $col) { $clo = strtolower($col->getName()); $script .= " if (\$this->isColumnModified(" . $this->getColumnConstant($col) . ")) \$criteria->add(" . $this->getColumnConstant($col) . ", \$this->$clo);"; } }
[ "protected", "function", "addBuildCriteriaBody", "(", "&", "$", "script", ")", "{", "$", "script", ".=", "\"\n \\$criteria = new Criteria(\"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME);\n\"", ";", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n if (\\$this->isColumnModified(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\")) \\$criteria->add(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\", \\$this->$clo);\"", ";", "}", "}" ]
Adds the function body of the buildCriteria method @param string &$script The script will be modified in this method. @see addBuildCriteria()
[ "Adds", "the", "function", "body", "of", "the", "buildCriteria", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L2384-L2394
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addToArray
protected function addToArray(&$script) { $fks = $this->getTable()->getForeignKeys(); $referrers = $this->getTable()->getReferrers(); $hasFks = count($fks) > 0 || count($referrers) > 0; $objectClassName = $this->getObjectClassname(); $pkGetter = $this->getTable()->hasCompositePrimaryKey() ? 'serialize($this->getPrimaryKey())' : '$this->getPrimaryKey()'; $defaultKeyType = $this->getDefaultKeyType(); $script .= " /** * Exports the object as an array. * * You can specify the key type of the array by passing one of the class * type constants. * * @param string \$keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * Defaults to BasePeer::$defaultKeyType. * @param boolean \$includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true. * @param array \$alreadyDumpedObjects List of objects to skip to avoid recursion"; if ($hasFks) { $script .= " * @param boolean \$includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE."; } $script .= " * * @return array an associative array containing the field names (as keys) and field values */ public function toArray(\$keyType = BasePeer::$defaultKeyType, \$includeLazyLoadColumns = true, \$alreadyDumpedObjects = array()" . ($hasFks ? ", \$includeForeignObjects = false" : '') . ") { if (isset(\$alreadyDumpedObjects['$objectClassName'][$pkGetter])) { return '*RECURSION*'; } \$alreadyDumpedObjects['$objectClassName'][$pkGetter] = true; \$keys = " . $this->getPeerClassname() . "::getFieldNames(\$keyType); \$result = array("; foreach ($this->getTable()->getColumns() as $num => $col) { if ($col->isLazyLoad()) { $script .= " \$keys[$num] => (\$includeLazyLoadColumns) ? \$this->get" . $col->getPhpName() . "() : null,"; } else { $script .= " \$keys[$num] => \$this->get" . $col->getPhpName() . "(),"; } } $script .= " );"; $script .= " \$virtualColumns = \$this->virtualColumns; foreach (\$virtualColumns as \$key => \$virtualColumn) { \$result[\$key] = \$virtualColumn; } "; if ($hasFks) { $script .= " if (\$includeForeignObjects) {"; foreach ($fks as $fk) { $script .= " if (null !== \$this->" . $this->getFKVarName($fk) . ") { \$result['" . $this->getFKPhpNameAffix($fk, $plural = false) . "'] = \$this->" . $this->getFKVarName($fk) . "->toArray(\$keyType, \$includeLazyLoadColumns, \$alreadyDumpedObjects, true); }"; } foreach ($referrers as $fk) { if ($fk->isLocalPrimaryKey()) { $script .= " if (null !== \$this->" . $this->getPKRefFKVarName($fk) . ") { \$result['" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "'] = \$this->" . $this->getPKRefFKVarName($fk) . "->toArray(\$keyType, \$includeLazyLoadColumns, \$alreadyDumpedObjects, true); }"; } else { $script .= " if (null !== \$this->" . $this->getRefFKCollVarName($fk) . ") { \$result['" . $this->getRefFKPhpNameAffix($fk, $plural = true) . "'] = \$this->" . $this->getRefFKCollVarName($fk) . "->toArray(null, true, \$keyType, \$includeLazyLoadColumns, \$alreadyDumpedObjects); }"; } } $script .= " }"; } $script .= " return \$result; } "; }
php
protected function addToArray(&$script) { $fks = $this->getTable()->getForeignKeys(); $referrers = $this->getTable()->getReferrers(); $hasFks = count($fks) > 0 || count($referrers) > 0; $objectClassName = $this->getObjectClassname(); $pkGetter = $this->getTable()->hasCompositePrimaryKey() ? 'serialize($this->getPrimaryKey())' : '$this->getPrimaryKey()'; $defaultKeyType = $this->getDefaultKeyType(); $script .= " /** * Exports the object as an array. * * You can specify the key type of the array by passing one of the class * type constants. * * @param string \$keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * Defaults to BasePeer::$defaultKeyType. * @param boolean \$includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true. * @param array \$alreadyDumpedObjects List of objects to skip to avoid recursion"; if ($hasFks) { $script .= " * @param boolean \$includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE."; } $script .= " * * @return array an associative array containing the field names (as keys) and field values */ public function toArray(\$keyType = BasePeer::$defaultKeyType, \$includeLazyLoadColumns = true, \$alreadyDumpedObjects = array()" . ($hasFks ? ", \$includeForeignObjects = false" : '') . ") { if (isset(\$alreadyDumpedObjects['$objectClassName'][$pkGetter])) { return '*RECURSION*'; } \$alreadyDumpedObjects['$objectClassName'][$pkGetter] = true; \$keys = " . $this->getPeerClassname() . "::getFieldNames(\$keyType); \$result = array("; foreach ($this->getTable()->getColumns() as $num => $col) { if ($col->isLazyLoad()) { $script .= " \$keys[$num] => (\$includeLazyLoadColumns) ? \$this->get" . $col->getPhpName() . "() : null,"; } else { $script .= " \$keys[$num] => \$this->get" . $col->getPhpName() . "(),"; } } $script .= " );"; $script .= " \$virtualColumns = \$this->virtualColumns; foreach (\$virtualColumns as \$key => \$virtualColumn) { \$result[\$key] = \$virtualColumn; } "; if ($hasFks) { $script .= " if (\$includeForeignObjects) {"; foreach ($fks as $fk) { $script .= " if (null !== \$this->" . $this->getFKVarName($fk) . ") { \$result['" . $this->getFKPhpNameAffix($fk, $plural = false) . "'] = \$this->" . $this->getFKVarName($fk) . "->toArray(\$keyType, \$includeLazyLoadColumns, \$alreadyDumpedObjects, true); }"; } foreach ($referrers as $fk) { if ($fk->isLocalPrimaryKey()) { $script .= " if (null !== \$this->" . $this->getPKRefFKVarName($fk) . ") { \$result['" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "'] = \$this->" . $this->getPKRefFKVarName($fk) . "->toArray(\$keyType, \$includeLazyLoadColumns, \$alreadyDumpedObjects, true); }"; } else { $script .= " if (null !== \$this->" . $this->getRefFKCollVarName($fk) . ") { \$result['" . $this->getRefFKPhpNameAffix($fk, $plural = true) . "'] = \$this->" . $this->getRefFKCollVarName($fk) . "->toArray(null, true, \$keyType, \$includeLazyLoadColumns, \$alreadyDumpedObjects); }"; } } $script .= " }"; } $script .= " return \$result; } "; }
[ "protected", "function", "addToArray", "(", "&", "$", "script", ")", "{", "$", "fks", "=", "$", "this", "->", "getTable", "(", ")", "->", "getForeignKeys", "(", ")", ";", "$", "referrers", "=", "$", "this", "->", "getTable", "(", ")", "->", "getReferrers", "(", ")", ";", "$", "hasFks", "=", "count", "(", "$", "fks", ")", ">", "0", "||", "count", "(", "$", "referrers", ")", ">", "0", ";", "$", "objectClassName", "=", "$", "this", "->", "getObjectClassname", "(", ")", ";", "$", "pkGetter", "=", "$", "this", "->", "getTable", "(", ")", "->", "hasCompositePrimaryKey", "(", ")", "?", "'serialize($this->getPrimaryKey())'", ":", "'$this->getPrimaryKey()'", ";", "$", "defaultKeyType", "=", "$", "this", "->", "getDefaultKeyType", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Exports the object as an array.\n *\n * You can specify the key type of the array by passing one of the class\n * type constants.\n *\n * @param string \\$keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,\n * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.\n * Defaults to BasePeer::$defaultKeyType.\n * @param boolean \\$includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.\n * @param array \\$alreadyDumpedObjects List of objects to skip to avoid recursion\"", ";", "if", "(", "$", "hasFks", ")", "{", "$", "script", ".=", "\"\n * @param boolean \\$includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.\"", ";", "}", "$", "script", ".=", "\"\n *\n * @return array an associative array containing the field names (as keys) and field values\n */\n public function toArray(\\$keyType = BasePeer::$defaultKeyType, \\$includeLazyLoadColumns = true, \\$alreadyDumpedObjects = array()\"", ".", "(", "$", "hasFks", "?", "\", \\$includeForeignObjects = false\"", ":", "''", ")", ".", "\")\n {\n if (isset(\\$alreadyDumpedObjects['$objectClassName'][$pkGetter])) {\n return '*RECURSION*';\n }\n \\$alreadyDumpedObjects['$objectClassName'][$pkGetter] = true;\n \\$keys = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::getFieldNames(\\$keyType);\n \\$result = array(\"", ";", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "num", "=>", "$", "col", ")", "{", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$keys[$num] => (\\$includeLazyLoadColumns) ? \\$this->get\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"() : null,\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$keys[$num] => \\$this->get\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"(),\"", ";", "}", "}", "$", "script", ".=", "\"\n );\"", ";", "$", "script", ".=", "\"\n \\$virtualColumns = \\$this->virtualColumns;\n foreach (\\$virtualColumns as \\$key => \\$virtualColumn) {\n \\$result[\\$key] = \\$virtualColumn;\n }\n \"", ";", "if", "(", "$", "hasFks", ")", "{", "$", "script", ".=", "\"\n if (\\$includeForeignObjects) {\"", ";", "foreach", "(", "$", "fks", "as", "$", "fk", ")", "{", "$", "script", ".=", "\"\n if (null !== \\$this->\"", ".", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ".", "\") {\n \\$result['\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ".", "\"'] = \\$this->\"", ".", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ".", "\"->toArray(\\$keyType, \\$includeLazyLoadColumns, \\$alreadyDumpedObjects, true);\n }\"", ";", "}", "foreach", "(", "$", "referrers", "as", "$", "fk", ")", "{", "if", "(", "$", "fk", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (null !== \\$this->\"", ".", "$", "this", "->", "getPKRefFKVarName", "(", "$", "fk", ")", ".", "\") {\n \\$result['\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ".", "\"'] = \\$this->\"", ".", "$", "this", "->", "getPKRefFKVarName", "(", "$", "fk", ")", ".", "\"->toArray(\\$keyType, \\$includeLazyLoadColumns, \\$alreadyDumpedObjects, true);\n }\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n if (null !== \\$this->\"", ".", "$", "this", "->", "getRefFKCollVarName", "(", "$", "fk", ")", ".", "\") {\n \\$result['\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "true", ")", ".", "\"'] = \\$this->\"", ".", "$", "this", "->", "getRefFKCollVarName", "(", "$", "fk", ")", ".", "\"->toArray(null, true, \\$keyType, \\$includeLazyLoadColumns, \\$alreadyDumpedObjects);\n }\"", ";", "}", "}", "$", "script", ".=", "\"\n }\"", ";", "}", "$", "script", ".=", "\"\n\n return \\$result;\n }\n\"", ";", "}" ]
Adds the toArray method @param string &$script The script will be modified in this method.
[ "Adds", "the", "toArray", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L2417-L2500
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addFromArray
protected function addFromArray(&$script) { $defaultKeyType = $this->getDefaultKeyType(); $table = $this->getTable(); $script .= " /** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. \$_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's BasePeer::$defaultKeyType * * @param array \$arr An array to populate the object from. * @param string \$keyType The type of keys the array uses. * @return void */ public function fromArray(\$arr, \$keyType = BasePeer::$defaultKeyType) { \$keys = " . $this->getPeerClassname() . "::getFieldNames(\$keyType); "; foreach ($table->getColumns() as $num => $col) { $cfc = $col->getPhpName(); //TODO: remove. not used $cptype = $col->getPhpType(); $script .= " if (array_key_exists(\$keys[$num], \$arr)) \$this->set$cfc(\$arr[\$keys[$num]]);"; } /* foreach */ $script .= " } "; }
php
protected function addFromArray(&$script) { $defaultKeyType = $this->getDefaultKeyType(); $table = $this->getTable(); $script .= " /** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. \$_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's BasePeer::$defaultKeyType * * @param array \$arr An array to populate the object from. * @param string \$keyType The type of keys the array uses. * @return void */ public function fromArray(\$arr, \$keyType = BasePeer::$defaultKeyType) { \$keys = " . $this->getPeerClassname() . "::getFieldNames(\$keyType); "; foreach ($table->getColumns() as $num => $col) { $cfc = $col->getPhpName(); //TODO: remove. not used $cptype = $col->getPhpType(); $script .= " if (array_key_exists(\$keys[$num], \$arr)) \$this->set$cfc(\$arr[\$keys[$num]]);"; } /* foreach */ $script .= " } "; }
[ "protected", "function", "addFromArray", "(", "&", "$", "script", ")", "{", "$", "defaultKeyType", "=", "$", "this", "->", "getDefaultKeyType", "(", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Populates the object using an array.\n *\n * This is particularly useful when populating an object from one of the\n * request arrays (e.g. \\$_POST). This method goes through the column\n * names, checking to see whether a matching key exists in populated\n * array. If so the setByName() method is called for that column.\n *\n * You can specify the key type of the array by additionally passing one\n * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,\n * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.\n * The default key type is the column's BasePeer::$defaultKeyType\n *\n * @param array \\$arr An array to populate the object from.\n * @param string \\$keyType The type of keys the array uses.\n * @return void\n */\n public function fromArray(\\$arr, \\$keyType = BasePeer::$defaultKeyType)\n {\n \\$keys = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::getFieldNames(\\$keyType);\n\"", ";", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "num", "=>", "$", "col", ")", "{", "$", "cfc", "=", "$", "col", "->", "getPhpName", "(", ")", ";", "//TODO: remove. not used", "$", "cptype", "=", "$", "col", "->", "getPhpType", "(", ")", ";", "$", "script", ".=", "\"\n if (array_key_exists(\\$keys[$num], \\$arr)) \\$this->set$cfc(\\$arr[\\$keys[$num]]);\"", ";", "}", "/* foreach */", "$", "script", ".=", "\"\n }\n\"", ";", "}" ]
addSetByPosition()
[ "addSetByPosition", "()" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L2744-L2780
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addReload
protected function addReload(&$script) { $table = $this->getTable(); $script .= " /** * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. * * This will only work if the object has been saved and has a valid primary key set. * * @param boolean \$deep (optional) Whether to also de-associated any related objects. * @param PropelPDO \$con (optional) The PropelPDO connection to use. * @return void * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db */ public function reload(\$deep = false, PropelPDO \$con = null) { if (\$this->isDeleted()) { throw new PropelException(\"Cannot reload a deleted object.\"); } if (\$this->isNew()) { throw new PropelException(\"Cannot reload an unsaved object.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$this->buildPkeyCriteria(), \$con); \$row = \$stmt->fetch(PDO::FETCH_NUM); \$stmt->closeCursor(); if (!\$row) { throw new PropelException('Cannot find matching row in the database to reload object values.'); } \$this->hydrate(\$row, 0, true); // rehydrate "; // support for lazy load columns foreach ($table->getColumns() as $col) { if ($col->isLazyLoad()) { $clo = strtolower($col->getName()); $script .= " // Reset the $clo lazy-load column \$this->" . $clo . " = null; \$this->" . $clo . "_isLoaded = false; "; } } $script .= " if (\$deep) { // also de-associate any related objects? "; foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " \$this->" . $varName . " = null;"; } foreach ($table->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $script .= " \$this->" . $this->getPKRefFKVarName($refFK) . " = null; "; } else { $script .= " \$this->" . $this->getRefFKCollVarName($refFK) . " = null; "; } } foreach ($table->getCrossFks() as $fkList) { list($refFK, $crossFK) = $fkList; $script .= " \$this->" . $this->getCrossFKVarName($crossFK) . " = null;"; } $script .= " } // if (deep) } "; }
php
protected function addReload(&$script) { $table = $this->getTable(); $script .= " /** * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. * * This will only work if the object has been saved and has a valid primary key set. * * @param boolean \$deep (optional) Whether to also de-associated any related objects. * @param PropelPDO \$con (optional) The PropelPDO connection to use. * @return void * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db */ public function reload(\$deep = false, PropelPDO \$con = null) { if (\$this->isDeleted()) { throw new PropelException(\"Cannot reload a deleted object.\"); } if (\$this->isNew()) { throw new PropelException(\"Cannot reload an unsaved object.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$this->buildPkeyCriteria(), \$con); \$row = \$stmt->fetch(PDO::FETCH_NUM); \$stmt->closeCursor(); if (!\$row) { throw new PropelException('Cannot find matching row in the database to reload object values.'); } \$this->hydrate(\$row, 0, true); // rehydrate "; // support for lazy load columns foreach ($table->getColumns() as $col) { if ($col->isLazyLoad()) { $clo = strtolower($col->getName()); $script .= " // Reset the $clo lazy-load column \$this->" . $clo . " = null; \$this->" . $clo . "_isLoaded = false; "; } } $script .= " if (\$deep) { // also de-associate any related objects? "; foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " \$this->" . $varName . " = null;"; } foreach ($table->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $script .= " \$this->" . $this->getPKRefFKVarName($refFK) . " = null; "; } else { $script .= " \$this->" . $this->getRefFKCollVarName($refFK) . " = null; "; } } foreach ($table->getCrossFks() as $fkList) { list($refFK, $crossFK) = $fkList; $script .= " \$this->" . $this->getCrossFKVarName($crossFK) . " = null;"; } $script .= " } // if (deep) } "; }
[ "protected", "function", "addReload", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.\n *\n * This will only work if the object has been saved and has a valid primary key set.\n *\n * @param boolean \\$deep (optional) Whether to also de-associated any related objects.\n * @param PropelPDO \\$con (optional) The PropelPDO connection to use.\n * @return void\n * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db\n */\n public function reload(\\$deep = false, PropelPDO \\$con = null)\n {\n if (\\$this->isDeleted()) {\n throw new PropelException(\\\"Cannot reload a deleted object.\\\");\n }\n\n if (\\$this->isNew()) {\n throw new PropelException(\\\"Cannot reload an unsaved object.\\\");\n }\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n\n // We don't need to alter the object instance pool; we're just modifying this instance\n // already in the pool.\n\n \\$stmt = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::doSelectStmt(\\$this->buildPkeyCriteria(), \\$con);\n \\$row = \\$stmt->fetch(PDO::FETCH_NUM);\n \\$stmt->closeCursor();\n if (!\\$row) {\n throw new PropelException('Cannot find matching row in the database to reload object values.');\n }\n \\$this->hydrate(\\$row, 0, true); // rehydrate\n\"", ";", "// support for lazy load columns", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n // Reset the $clo lazy-load column\n \\$this->\"", ".", "$", "clo", ".", "\" = null;\n \\$this->\"", ".", "$", "clo", ".", "\"_isLoaded = false;\n\"", ";", "}", "}", "$", "script", ".=", "\"\n if (\\$deep) { // also de-associate any related objects?\n\"", ";", "foreach", "(", "$", "table", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "varName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "varName", ".", "\" = null;\"", ";", "}", "foreach", "(", "$", "table", "->", "getReferrers", "(", ")", "as", "$", "refFK", ")", "{", "if", "(", "$", "refFK", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ".", "\" = null;\n\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ".", "\" = null;\n\"", ";", "}", "}", "foreach", "(", "$", "table", "->", "getCrossFks", "(", ")", "as", "$", "fkList", ")", "{", "list", "(", "$", "refFK", ",", "$", "crossFK", ")", "=", "$", "fkList", ";", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "this", "->", "getCrossFKVarName", "(", "$", "crossFK", ")", ".", "\" = null;\"", ";", "}", "$", "script", ".=", "\"\n } // if (deep)\n }\n\"", ";", "}" ]
Adds a reload() method to re-fetch the data for this object from the database. @param string &$script The script will be modified in this method.
[ "Adds", "a", "reload", "()", "method", "to", "re", "-", "fetch", "the", "data", "for", "this", "object", "from", "the", "database", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L2908-L2992
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addValidationMethods
protected function addValidationMethods(&$script) { $this->addValidationFailuresAttribute($script); $this->addGetValidationFailures($script); $this->addValidate($script); $this->addDoValidate($script); }
php
protected function addValidationMethods(&$script) { $this->addValidationFailuresAttribute($script); $this->addGetValidationFailures($script); $this->addValidate($script); $this->addDoValidate($script); }
[ "protected", "function", "addValidationMethods", "(", "&", "$", "script", ")", "{", "$", "this", "->", "addValidationFailuresAttribute", "(", "$", "script", ")", ";", "$", "this", "->", "addGetValidationFailures", "(", "$", "script", ")", ";", "$", "this", "->", "addValidate", "(", "$", "script", ")", ";", "$", "this", "->", "addDoValidate", "(", "$", "script", ")", ";", "}" ]
Adds the methods related to the validation of the object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "methods", "related", "to", "the", "validation", "of", "the", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3014-L3020
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addSetPrimaryKey_SinglePK
protected function addSetPrimaryKey_SinglePK(&$script) { $pkeys = $this->getTable()->getPrimaryKey(); $col = $pkeys[0]; $clo = strtolower($col->getName()); $ctype = $col->getPhpType(); $script .= " /** * Generic method to set the primary key ($clo column). * * @param $ctype \$key Primary key. * @return void */ public function setPrimaryKey(\$key) { \$this->set" . $col->getPhpName() . "(\$key); } "; }
php
protected function addSetPrimaryKey_SinglePK(&$script) { $pkeys = $this->getTable()->getPrimaryKey(); $col = $pkeys[0]; $clo = strtolower($col->getName()); $ctype = $col->getPhpType(); $script .= " /** * Generic method to set the primary key ($clo column). * * @param $ctype \$key Primary key. * @return void */ public function setPrimaryKey(\$key) { \$this->set" . $col->getPhpName() . "(\$key); } "; }
[ "protected", "function", "addSetPrimaryKey_SinglePK", "(", "&", "$", "script", ")", "{", "$", "pkeys", "=", "$", "this", "->", "getTable", "(", ")", "->", "getPrimaryKey", "(", ")", ";", "$", "col", "=", "$", "pkeys", "[", "0", "]", ";", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "ctype", "=", "$", "col", "->", "getPhpType", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Generic method to set the primary key ($clo column).\n *\n * @param $ctype \\$key Primary key.\n * @return void\n */\n public function setPrimaryKey(\\$key)\n {\n \\$this->set\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"(\\$key);\n }\n\"", ";", "}" ]
Adds the setPrimaryKey() method for tables that contain a single-column primary key. @param string &$script The script will be modified in this method.
[ "Adds", "the", "setPrimaryKey", "()", "method", "for", "tables", "that", "contain", "a", "single", "-", "column", "primary", "key", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3179-L3199
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addFKMutator
protected function addFKMutator(&$script, ForeignKey $fk) { $table = $this->getTable(); $tblFK = $this->getForeignTable($fk); $joinTableObjectBuilder = $this->getNewObjectBuilder($tblFK); $className = $joinTableObjectBuilder->getObjectClassname(); $varName = $this->getFKVarName($fk); $script .= " /** * Declares an association between this object and a $className object. * * @param $className \$v * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException */ public function set" . $this->getFKPhpNameAffix($fk, $plural = false) . "($className \$v = null) {"; foreach ($fk->getLocalColumns() as $columnName) { $column = $table->getColumn($columnName); $lfmap = $fk->getLocalForeignMapping(); $colFKName = $lfmap[$columnName]; $colFK = $tblFK->getColumn($colFKName); $script .= " if (\$v === null) { \$this->set" . $column->getPhpName() . "(" . $this->getDefaultValueString($column) . "); } else { \$this->set" . $column->getPhpName() . "(\$v->get" . $colFK->getPhpName() . "()); } "; } /* foreach local col */ $script .= " \$this->$varName = \$v; "; // Now add bi-directional relationship binding, taking into account whether this is // a one-to-one relationship. if ($fk->isLocalPrimaryKey()) { $script .= " // Add binding for other direction of this 1:1 relationship. if (\$v !== null) { \$v->set" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "(\$this); } "; } else { $script .= " // Add binding for other direction of this n:n relationship. // If this object has already been added to the $className object, it will not be re-added. if (\$v !== null) { \$v->add" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "(\$this); } "; } $script .= " return \$this; } "; }
php
protected function addFKMutator(&$script, ForeignKey $fk) { $table = $this->getTable(); $tblFK = $this->getForeignTable($fk); $joinTableObjectBuilder = $this->getNewObjectBuilder($tblFK); $className = $joinTableObjectBuilder->getObjectClassname(); $varName = $this->getFKVarName($fk); $script .= " /** * Declares an association between this object and a $className object. * * @param $className \$v * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException */ public function set" . $this->getFKPhpNameAffix($fk, $plural = false) . "($className \$v = null) {"; foreach ($fk->getLocalColumns() as $columnName) { $column = $table->getColumn($columnName); $lfmap = $fk->getLocalForeignMapping(); $colFKName = $lfmap[$columnName]; $colFK = $tblFK->getColumn($colFKName); $script .= " if (\$v === null) { \$this->set" . $column->getPhpName() . "(" . $this->getDefaultValueString($column) . "); } else { \$this->set" . $column->getPhpName() . "(\$v->get" . $colFK->getPhpName() . "()); } "; } /* foreach local col */ $script .= " \$this->$varName = \$v; "; // Now add bi-directional relationship binding, taking into account whether this is // a one-to-one relationship. if ($fk->isLocalPrimaryKey()) { $script .= " // Add binding for other direction of this 1:1 relationship. if (\$v !== null) { \$v->set" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "(\$this); } "; } else { $script .= " // Add binding for other direction of this n:n relationship. // If this object has already been added to the $className object, it will not be re-added. if (\$v !== null) { \$v->add" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "(\$this); } "; } $script .= " return \$this; } "; }
[ "protected", "function", "addFKMutator", "(", "&", "$", "script", ",", "ForeignKey", "$", "fk", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tblFK", "=", "$", "this", "->", "getForeignTable", "(", "$", "fk", ")", ";", "$", "joinTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "tblFK", ")", ";", "$", "className", "=", "$", "joinTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "varName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n /**\n * Declares an association between this object and a $className object.\n *\n * @param $className \\$v\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n * @throws PropelException\n */\n public function set\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ".", "\"($className \\$v = null)\n {\"", ";", "foreach", "(", "$", "fk", "->", "getLocalColumns", "(", ")", "as", "$", "columnName", ")", "{", "$", "column", "=", "$", "table", "->", "getColumn", "(", "$", "columnName", ")", ";", "$", "lfmap", "=", "$", "fk", "->", "getLocalForeignMapping", "(", ")", ";", "$", "colFKName", "=", "$", "lfmap", "[", "$", "columnName", "]", ";", "$", "colFK", "=", "$", "tblFK", "->", "getColumn", "(", "$", "colFKName", ")", ";", "$", "script", ".=", "\"\n if (\\$v === null) {\n \\$this->set\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"(\"", ".", "$", "this", "->", "getDefaultValueString", "(", "$", "column", ")", ".", "\");\n } else {\n \\$this->set\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"(\\$v->get\"", ".", "$", "colFK", "->", "getPhpName", "(", ")", ".", "\"());\n }\n\"", ";", "}", "/* foreach local col */", "$", "script", ".=", "\"\n \\$this->$varName = \\$v;\n\"", ";", "// Now add bi-directional relationship binding, taking into account whether this is", "// a one-to-one relationship.", "if", "(", "$", "fk", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "script", ".=", "\"\n // Add binding for other direction of this 1:1 relationship.\n if (\\$v !== null) {\n \\$v->set\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ".", "\"(\\$this);\n }\n\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n // Add binding for other direction of this n:n relationship.\n // If this object has already been added to the $className object, it will not be re-added.\n if (\\$v !== null) {\n \\$v->add\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ".", "\"(\\$this);\n }\n\"", ";", "}", "$", "script", ".=", "\"\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds the mutator (setter) method for setting an fkey related object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "mutator", "(", "setter", ")", "method", "for", "setting", "an", "fkey", "related", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3379-L3442
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addFKByKeyMutator
protected function addFKByKeyMutator(&$script, ForeignKey $fk) { $table = $this->getTable(); #$className = $this->getForeignTable($fk)->getPhpName(); $methodAffix = $this->getFKPhpNameAffix($fk); #$varName = $this->getFKVarName($fk); $script .= " /** * Provides convenient way to set a relationship based on a * key. e.g. * <code>\$bar->setFooKey(\$foo->getPrimaryKey())</code> *"; if (count($fk->getLocalColumns()) > 1) { $script .= " * Note: It is important that the xml schema used to create this class * maintains consistency in the order of related columns between * " . $table->getName() . " and " . $tblFK->getName() . ". * If for some reason this is impossible, this method should be * overridden in <code>" . $table->getPhpName() . "</code>."; } $script .= " * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException */ public function set" . $methodAffix . "Key(\$key) { "; if (count($fk->getLocalColumns()) > 1) { $i = 0; foreach ($fk->getLocalColumns() as $colName) { $col = $table->getColumn($colName); $fktype = $col->getPhpType(); $script .= " \$this->set" . $col->getPhpName() . "( ($fktype) \$key[$i] ); "; $i++; } /* foreach */ } else { $lcols = $fk->getLocalColumns(); $colName = $lcols[0]; $col = $table->getColumn($colName); $fktype = $col->getPhpType(); $script .= " \$this->set" . $col->getPhpName() . "( ($fktype) \$key); "; } $script .= " return \$this; } "; }
php
protected function addFKByKeyMutator(&$script, ForeignKey $fk) { $table = $this->getTable(); #$className = $this->getForeignTable($fk)->getPhpName(); $methodAffix = $this->getFKPhpNameAffix($fk); #$varName = $this->getFKVarName($fk); $script .= " /** * Provides convenient way to set a relationship based on a * key. e.g. * <code>\$bar->setFooKey(\$foo->getPrimaryKey())</code> *"; if (count($fk->getLocalColumns()) > 1) { $script .= " * Note: It is important that the xml schema used to create this class * maintains consistency in the order of related columns between * " . $table->getName() . " and " . $tblFK->getName() . ". * If for some reason this is impossible, this method should be * overridden in <code>" . $table->getPhpName() . "</code>."; } $script .= " * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException */ public function set" . $methodAffix . "Key(\$key) { "; if (count($fk->getLocalColumns()) > 1) { $i = 0; foreach ($fk->getLocalColumns() as $colName) { $col = $table->getColumn($colName); $fktype = $col->getPhpType(); $script .= " \$this->set" . $col->getPhpName() . "( ($fktype) \$key[$i] ); "; $i++; } /* foreach */ } else { $lcols = $fk->getLocalColumns(); $colName = $lcols[0]; $col = $table->getColumn($colName); $fktype = $col->getPhpType(); $script .= " \$this->set" . $col->getPhpName() . "( ($fktype) \$key); "; } $script .= " return \$this; } "; }
[ "protected", "function", "addFKByKeyMutator", "(", "&", "$", "script", ",", "ForeignKey", "$", "fk", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "#$className = $this->getForeignTable($fk)->getPhpName();", "$", "methodAffix", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ")", ";", "#$varName = $this->getFKVarName($fk);", "$", "script", ".=", "\"\n /**\n * Provides convenient way to set a relationship based on a\n * key. e.g.\n * <code>\\$bar->setFooKey(\\$foo->getPrimaryKey())</code>\n *\"", ";", "if", "(", "count", "(", "$", "fk", "->", "getLocalColumns", "(", ")", ")", ">", "1", ")", "{", "$", "script", ".=", "\"\n * Note: It is important that the xml schema used to create this class\n * maintains consistency in the order of related columns between\n * \"", ".", "$", "table", "->", "getName", "(", ")", ".", "\" and \"", ".", "$", "tblFK", "->", "getName", "(", ")", ".", "\".\n * If for some reason this is impossible, this method should be\n * overridden in <code>\"", ".", "$", "table", "->", "getPhpName", "(", ")", ".", "\"</code>.\"", ";", "}", "$", "script", ".=", "\"\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n * @throws PropelException\n */\n public function set\"", ".", "$", "methodAffix", ".", "\"Key(\\$key)\n {\n\"", ";", "if", "(", "count", "(", "$", "fk", "->", "getLocalColumns", "(", ")", ")", ">", "1", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "fk", "->", "getLocalColumns", "(", ")", "as", "$", "colName", ")", "{", "$", "col", "=", "$", "table", "->", "getColumn", "(", "$", "colName", ")", ";", "$", "fktype", "=", "$", "col", "->", "getPhpType", "(", ")", ";", "$", "script", ".=", "\"\n \\$this->set\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"( ($fktype) \\$key[$i] );\n\"", ";", "$", "i", "++", ";", "}", "/* foreach */", "}", "else", "{", "$", "lcols", "=", "$", "fk", "->", "getLocalColumns", "(", ")", ";", "$", "colName", "=", "$", "lcols", "[", "0", "]", ";", "$", "col", "=", "$", "table", "->", "getColumn", "(", "$", "colName", ")", ";", "$", "fktype", "=", "$", "col", "->", "getPhpType", "(", ")", ";", "$", "script", ".=", "\"\n \\$this->set\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"( ($fktype) \\$key);\n\"", ";", "}", "$", "script", ".=", "\"\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds a convenience method for setting a related object by specifying the primary key. This can be used in conjunction with the getPrimaryKey() for systems where nothing is known about the actual objects being related. @param string &$script The script will be modified in this method.
[ "Adds", "a", "convenience", "method", "for", "setting", "a", "related", "object", "by", "specifying", "the", "primary", "key", ".", "This", "can", "be", "used", "in", "conjunction", "with", "the", "getPrimaryKey", "()", "for", "systems", "where", "nothing", "is", "known", "about", "the", "actual", "objects", "being", "related", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3547-L3600
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addRefFKGetJoinMethods
protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $join_behavior = $this->getGeneratorConfig()->getBuildProperty('useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN'; $peerClassname = $this->getStubPeerBuilder()->getClassname(); $fkQueryClassname = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname(); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $fkPeerBuilder = $this->getNewPeerBuilder($tblFK); $className = $fkPeerBuilder->getObjectClassname(); $lastTable = ""; foreach ($tblFK->getForeignKeys() as $fk2) { $tblFK2 = $this->getForeignTable($fk2); $doJoinGet = !$tblFK2->isForReferenceOnly(); // it doesn't make sense to join in rows from the current table, since we are fetching // objects related to *this* table (i.e. the joined rows will all be the same row as current object) if ($this->getTable()->getPhpName() == $tblFK2->getPhpName()) { $doJoinGet = false; } $relCol2 = $this->getFKPhpNameAffix($fk2, $plural = false); if ($this->getRelatedBySuffix($refFK) != "" && ($this->getRelatedBySuffix($refFK) == $this->getRelatedBySuffix($fk2))) { $doJoinGet = false; } if ($doJoinGet) { $script .= " /** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this " . $table->getPhpName() . " is new, it will return * an empty collection; or if this " . $table->getPhpName() . " has previously * been saved, it will retrieve related $relCol from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in " . $table->getPhpName() . ". * * @param Criteria \$criteria optional Criteria object to narrow the query * @param PropelPDO \$con optional connection object * @param string \$join_behavior optional join type to use (defaults to $join_behavior) * @return PropelObjectCollection|{$className}[] List of $className objects */ public function get" . $relCol . "Join" . $relCol2 . "(\$criteria = null, \$con = null, \$join_behavior = $join_behavior) {"; $script .= " \$query = $fkQueryClassname::create(null, \$criteria); \$query->joinWith('" . $this->getFKPhpNameAffix($fk2, $plural = false) . "', \$join_behavior); return \$this->get" . $relCol . "(\$query, \$con); } "; } /* end if ($doJoinGet) */ } /* end foreach ($tblFK->getForeignKeys() as $fk2) { */ }
php
protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $join_behavior = $this->getGeneratorConfig()->getBuildProperty('useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN'; $peerClassname = $this->getStubPeerBuilder()->getClassname(); $fkQueryClassname = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname(); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $fkPeerBuilder = $this->getNewPeerBuilder($tblFK); $className = $fkPeerBuilder->getObjectClassname(); $lastTable = ""; foreach ($tblFK->getForeignKeys() as $fk2) { $tblFK2 = $this->getForeignTable($fk2); $doJoinGet = !$tblFK2->isForReferenceOnly(); // it doesn't make sense to join in rows from the current table, since we are fetching // objects related to *this* table (i.e. the joined rows will all be the same row as current object) if ($this->getTable()->getPhpName() == $tblFK2->getPhpName()) { $doJoinGet = false; } $relCol2 = $this->getFKPhpNameAffix($fk2, $plural = false); if ($this->getRelatedBySuffix($refFK) != "" && ($this->getRelatedBySuffix($refFK) == $this->getRelatedBySuffix($fk2))) { $doJoinGet = false; } if ($doJoinGet) { $script .= " /** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this " . $table->getPhpName() . " is new, it will return * an empty collection; or if this " . $table->getPhpName() . " has previously * been saved, it will retrieve related $relCol from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in " . $table->getPhpName() . ". * * @param Criteria \$criteria optional Criteria object to narrow the query * @param PropelPDO \$con optional connection object * @param string \$join_behavior optional join type to use (defaults to $join_behavior) * @return PropelObjectCollection|{$className}[] List of $className objects */ public function get" . $relCol . "Join" . $relCol2 . "(\$criteria = null, \$con = null, \$join_behavior = $join_behavior) {"; $script .= " \$query = $fkQueryClassname::create(null, \$criteria); \$query->joinWith('" . $this->getFKPhpNameAffix($fk2, $plural = false) . "', \$join_behavior); return \$this->get" . $relCol . "(\$query, \$con); } "; } /* end if ($doJoinGet) */ } /* end foreach ($tblFK->getForeignKeys() as $fk2) { */ }
[ "protected", "function", "addRefFKGetJoinMethods", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "join_behavior", "=", "$", "this", "->", "getGeneratorConfig", "(", ")", "->", "getBuildProperty", "(", "'useLeftJoinsInDoJoinMethods'", ")", "?", "'Criteria::LEFT_JOIN'", ":", "'Criteria::INNER_JOIN'", ";", "$", "peerClassname", "=", "$", "this", "->", "getStubPeerBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "fkQueryClassname", "=", "$", "this", "->", "getNewStubQueryBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", "->", "getClassname", "(", ")", ";", "$", "relCol", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "fkPeerBuilder", "=", "$", "this", "->", "getNewPeerBuilder", "(", "$", "tblFK", ")", ";", "$", "className", "=", "$", "fkPeerBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "lastTable", "=", "\"\"", ";", "foreach", "(", "$", "tblFK", "->", "getForeignKeys", "(", ")", "as", "$", "fk2", ")", "{", "$", "tblFK2", "=", "$", "this", "->", "getForeignTable", "(", "$", "fk2", ")", ";", "$", "doJoinGet", "=", "!", "$", "tblFK2", "->", "isForReferenceOnly", "(", ")", ";", "// it doesn't make sense to join in rows from the current table, since we are fetching", "// objects related to *this* table (i.e. the joined rows will all be the same row as current object)", "if", "(", "$", "this", "->", "getTable", "(", ")", "->", "getPhpName", "(", ")", "==", "$", "tblFK2", "->", "getPhpName", "(", ")", ")", "{", "$", "doJoinGet", "=", "false", ";", "}", "$", "relCol2", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk2", ",", "$", "plural", "=", "false", ")", ";", "if", "(", "$", "this", "->", "getRelatedBySuffix", "(", "$", "refFK", ")", "!=", "\"\"", "&&", "(", "$", "this", "->", "getRelatedBySuffix", "(", "$", "refFK", ")", "==", "$", "this", "->", "getRelatedBySuffix", "(", "$", "fk2", ")", ")", ")", "{", "$", "doJoinGet", "=", "false", ";", "}", "if", "(", "$", "doJoinGet", ")", "{", "$", "script", ".=", "\"\n\n /**\n * If this collection has already been initialized with\n * an identical criteria, it returns the collection.\n * Otherwise if this \"", ".", "$", "table", "->", "getPhpName", "(", ")", ".", "\" is new, it will return\n * an empty collection; or if this \"", ".", "$", "table", "->", "getPhpName", "(", ")", ".", "\" has previously\n * been saved, it will retrieve related $relCol from storage.\n *\n * This method is protected by default in order to keep the public\n * api reasonable. You can provide public methods for those you\n * actually need in \"", ".", "$", "table", "->", "getPhpName", "(", ")", ".", "\".\n *\n * @param Criteria \\$criteria optional Criteria object to narrow the query\n * @param PropelPDO \\$con optional connection object\n * @param string \\$join_behavior optional join type to use (defaults to $join_behavior)\n * @return PropelObjectCollection|{$className}[] List of $className objects\n */\n public function get\"", ".", "$", "relCol", ".", "\"Join\"", ".", "$", "relCol2", ".", "\"(\\$criteria = null, \\$con = null, \\$join_behavior = $join_behavior)\n {\"", ";", "$", "script", ".=", "\"\n \\$query = $fkQueryClassname::create(null, \\$criteria);\n \\$query->joinWith('\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk2", ",", "$", "plural", "=", "false", ")", ".", "\"', \\$join_behavior);\n\n return \\$this->get\"", ".", "$", "relCol", ".", "\"(\\$query, \\$con);\n }\n\"", ";", "}", "/* end if ($doJoinGet) */", "}", "/* end foreach ($tblFK->getForeignKeys() as $fk2) { */", "}" ]
Adds the method that fetches fkey-related (referencing) objects but also joins in data from another table. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "fetches", "fkey", "-", "related", "(", "referencing", ")", "objects", "but", "also", "joins", "in", "data", "from", "another", "table", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3607-L3669
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addRefFKAttributes
protected function addRefFKAttributes(&$script, ForeignKey $refFK) { $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); if ($refFK->isLocalPrimaryKey()) { $script .= " /** * @var $className one-to-one related $className object */ protected $" . $this->getPKRefFKVarName($refFK) . "; "; } else { $script .= " /** * @var PropelObjectCollection|{$className}[] Collection to store aggregation of $className objects. */ protected $" . $this->getRefFKCollVarName($refFK) . "; protected $" . $this->getRefFKCollVarName($refFK) . "Partial; "; } }
php
protected function addRefFKAttributes(&$script, ForeignKey $refFK) { $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); if ($refFK->isLocalPrimaryKey()) { $script .= " /** * @var $className one-to-one related $className object */ protected $" . $this->getPKRefFKVarName($refFK) . "; "; } else { $script .= " /** * @var PropelObjectCollection|{$className}[] Collection to store aggregation of $className objects. */ protected $" . $this->getRefFKCollVarName($refFK) . "; protected $" . $this->getRefFKCollVarName($refFK) . "Partial; "; } }
[ "protected", "function", "addRefFKAttributes", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "if", "(", "$", "refFK", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "script", ".=", "\"\n /**\n * @var $className one-to-one related $className object\n */\n protected $\"", ".", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ".", "\";\n\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n /**\n * @var PropelObjectCollection|{$className}[] Collection to store aggregation of $className objects.\n */\n protected $\"", ".", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ".", "\";\n protected $\"", ".", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ".", "\"Partial;\n\"", ";", "}", "}" ]
Adds the attributes used to store objects that have referrer fkey relationships to this object. <code>protected collVarName;</code> <code>private lastVarNameCriteria = null;</code> @param string &$script The script will be modified in this method.
[ "Adds", "the", "attributes", "used", "to", "store", "objects", "that", "have", "referrer", "fkey", "relationships", "to", "this", "object", ".", "<code", ">", "protected", "collVarName", ";", "<", "/", "code", ">", "<code", ">", "private", "lastVarNameCriteria", "=", "null", ";", "<", "/", "code", ">" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3684-L3705
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addRefFKInit
protected function addRefFKInit(&$script, ForeignKey $refFK) { $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $script .= " /** * Initializes the $collName collection. * * By default this just sets the $collName collection to an empty array (like clear$collName()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @param boolean \$overrideExisting If set to true, the method call initializes * the collection even if it is not empty * * @return void */ public function init$relCol(\$overrideExisting = true) { if (null !== \$this->$collName && !\$overrideExisting) { return; } \$this->$collName = new PropelObjectCollection(); \$this->{$collName}->setModel('" . $this->getNewStubObjectBuilder($refFK->getTable())->getClassname() . "'); } "; }
php
protected function addRefFKInit(&$script, ForeignKey $refFK) { $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $script .= " /** * Initializes the $collName collection. * * By default this just sets the $collName collection to an empty array (like clear$collName()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @param boolean \$overrideExisting If set to true, the method call initializes * the collection even if it is not empty * * @return void */ public function init$relCol(\$overrideExisting = true) { if (null !== \$this->$collName && !\$overrideExisting) { return; } \$this->$collName = new PropelObjectCollection(); \$this->{$collName}->setModel('" . $this->getNewStubObjectBuilder($refFK->getTable())->getClassname() . "'); } "; }
[ "protected", "function", "addRefFKInit", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "relCol", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n /**\n * Initializes the $collName collection.\n *\n * By default this just sets the $collName collection to an empty array (like clear$collName());\n * however, you may wish to override this method in your stub class to provide setting appropriate\n * to your application -- for example, setting the initial array to the values stored in database.\n *\n * @param boolean \\$overrideExisting If set to true, the method call initializes\n * the collection even if it is not empty\n *\n * @return void\n */\n public function init$relCol(\\$overrideExisting = true)\n {\n if (null !== \\$this->$collName && !\\$overrideExisting) {\n return;\n }\n \\$this->$collName = new PropelObjectCollection();\n \\$this->{$collName}->setModel('\"", ".", "$", "this", "->", "getNewStubObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", "->", "getClassname", "(", ")", ".", "\"');\n }\n\"", ";", "}" ]
Adds the method that initializes the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "initializes", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3826-L3853
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addRefFKAdd
protected function addRefFKAdd(&$script, ForeignKey $refFK) { $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); if ($tblFK->getChildrenColumn()) { $className = 'Base' . $className; $namespace = $joinedTableObjectBuilder->getNamespace(); $this->declareClass($namespace . '\\' . $className); } $collName = $this->getRefFKCollVarName($refFK); $scheduledForDeletion = lcfirst($this->getRefFKPhpNameAffix($refFK, $plural = true)) . "ScheduledForDeletion"; $script .= " /** * Method called to associate a $className object to this object * through the $className foreign key attribute. * * @param $className \$l $className * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ public function add" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "($className \$l) { if (\$this->$collName === null) { \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(); \$this->{$collName}Partial = true; } if (!in_array(\$l, \$this->{$collName}->getArrayCopy(), true)) { // only add it if the **same** object is not already associated \$this->doAdd" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(\$l); if (\$this->{$scheduledForDeletion} and \$this->{$scheduledForDeletion}->contains(\$l)) { \$this->{$scheduledForDeletion}->remove(\$this->{$scheduledForDeletion}->search(\$l)); } } return \$this; } "; }
php
protected function addRefFKAdd(&$script, ForeignKey $refFK) { $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); if ($tblFK->getChildrenColumn()) { $className = 'Base' . $className; $namespace = $joinedTableObjectBuilder->getNamespace(); $this->declareClass($namespace . '\\' . $className); } $collName = $this->getRefFKCollVarName($refFK); $scheduledForDeletion = lcfirst($this->getRefFKPhpNameAffix($refFK, $plural = true)) . "ScheduledForDeletion"; $script .= " /** * Method called to associate a $className object to this object * through the $className foreign key attribute. * * @param $className \$l $className * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ public function add" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "($className \$l) { if (\$this->$collName === null) { \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(); \$this->{$collName}Partial = true; } if (!in_array(\$l, \$this->{$collName}->getArrayCopy(), true)) { // only add it if the **same** object is not already associated \$this->doAdd" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(\$l); if (\$this->{$scheduledForDeletion} and \$this->{$scheduledForDeletion}->contains(\$l)) { \$this->{$scheduledForDeletion}->remove(\$this->{$scheduledForDeletion}->search(\$l)); } } return \$this; } "; }
[ "protected", "function", "addRefFKAdd", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "if", "(", "$", "tblFK", "->", "getChildrenColumn", "(", ")", ")", "{", "$", "className", "=", "'Base'", ".", "$", "className", ";", "$", "namespace", "=", "$", "joinedTableObjectBuilder", "->", "getNamespace", "(", ")", ";", "$", "this", "->", "declareClass", "(", "$", "namespace", ".", "'\\\\'", ".", "$", "className", ")", ";", "}", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "scheduledForDeletion", "=", "lcfirst", "(", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ")", ".", "\"ScheduledForDeletion\"", ";", "$", "script", ".=", "\"\n /**\n * Method called to associate a $className object to this object\n * through the $className foreign key attribute.\n *\n * @param $className \\$l $className\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n */\n public function add\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"($className \\$l)\n {\n if (\\$this->$collName === null) {\n \\$this->init\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ".", "\"();\n \\$this->{$collName}Partial = true;\n }\n\n if (!in_array(\\$l, \\$this->{$collName}->getArrayCopy(), true)) { // only add it if the **same** object is not already associated\n \\$this->doAdd\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"(\\$l);\n\n if (\\$this->{$scheduledForDeletion} and \\$this->{$scheduledForDeletion}->contains(\\$l)) {\n \\$this->{$scheduledForDeletion}->remove(\\$this->{$scheduledForDeletion}->search(\\$l));\n }\n }\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds the method that adds an object into the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "adds", "an", "object", "into", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3860-L3903
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addRefFKCount
protected function addRefFKCount(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $peerClassname = $this->getStubPeerBuilder()->getClassname(); $fkQueryClassname = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname(); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $script .= " /** * Returns the number of related $className objects. * * @param Criteria \$criteria * @param boolean \$distinct * @param PropelPDO \$con * @return int Count of related $className objects. * @throws PropelException */ public function count$relCol(Criteria \$criteria = null, \$distinct = false, PropelPDO \$con = null) { \$partial = \$this->{$collName}Partial && !\$this->isNew(); if (null === \$this->$collName || null !== \$criteria || \$partial) { if (\$this->isNew() && null === \$this->$collName) { return 0; } if (\$partial && !\$criteria) { return count(\$this->get$relCol()); } \$query = $fkQueryClassname::create(null, \$criteria); if (\$distinct) { \$query->distinct(); } return \$query ->filterBy" . $this->getFKPhpNameAffix($refFK) . "(\$this) ->count(\$con); } return count(\$this->$collName); } "; }
php
protected function addRefFKCount(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $peerClassname = $this->getStubPeerBuilder()->getClassname(); $fkQueryClassname = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname(); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $script .= " /** * Returns the number of related $className objects. * * @param Criteria \$criteria * @param boolean \$distinct * @param PropelPDO \$con * @return int Count of related $className objects. * @throws PropelException */ public function count$relCol(Criteria \$criteria = null, \$distinct = false, PropelPDO \$con = null) { \$partial = \$this->{$collName}Partial && !\$this->isNew(); if (null === \$this->$collName || null !== \$criteria || \$partial) { if (\$this->isNew() && null === \$this->$collName) { return 0; } if (\$partial && !\$criteria) { return count(\$this->get$relCol()); } \$query = $fkQueryClassname::create(null, \$criteria); if (\$distinct) { \$query->distinct(); } return \$query ->filterBy" . $this->getFKPhpNameAffix($refFK) . "(\$this) ->count(\$con); } return count(\$this->$collName); } "; }
[ "protected", "function", "addRefFKCount", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "peerClassname", "=", "$", "this", "->", "getStubPeerBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "fkQueryClassname", "=", "$", "this", "->", "getNewStubQueryBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", "->", "getClassname", "(", ")", ";", "$", "relCol", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Returns the number of related $className objects.\n *\n * @param Criteria \\$criteria\n * @param boolean \\$distinct\n * @param PropelPDO \\$con\n * @return int Count of related $className objects.\n * @throws PropelException\n */\n public function count$relCol(Criteria \\$criteria = null, \\$distinct = false, PropelPDO \\$con = null)\n {\n \\$partial = \\$this->{$collName}Partial && !\\$this->isNew();\n if (null === \\$this->$collName || null !== \\$criteria || \\$partial) {\n if (\\$this->isNew() && null === \\$this->$collName) {\n return 0;\n }\n\n if (\\$partial && !\\$criteria) {\n return count(\\$this->get$relCol());\n }\n \\$query = $fkQueryClassname::create(null, \\$criteria);\n if (\\$distinct) {\n \\$query->distinct();\n }\n\n return \\$query\n ->filterBy\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "refFK", ")", ".", "\"(\\$this)\n ->count(\\$con);\n }\n\n return count(\\$this->$collName);\n }\n\"", ";", "}" ]
Adds the method that returns the size of the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "returns", "the", "size", "of", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L3910-L3958
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addPKRefFKGet
protected function addPKRefFKGet(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $queryClassname = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname(); $varName = $this->getPKRefFKVarName($refFK); $script .= " /** * Gets a single $className object, which is related to this object by a one-to-one relationship. * * @param PropelPDO \$con optional connection object * @return $className * @throws PropelException */ public function get" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(PropelPDO \$con = null) { "; $script .= " if (\$this->$varName === null && !\$this->isNew()) { \$this->$varName = $queryClassname::create()->findPk(\$this->getPrimaryKey(), \$con); } return \$this->$varName; } "; }
php
protected function addPKRefFKGet(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $queryClassname = $this->getNewStubQueryBuilder($refFK->getTable())->getClassname(); $varName = $this->getPKRefFKVarName($refFK); $script .= " /** * Gets a single $className object, which is related to this object by a one-to-one relationship. * * @param PropelPDO \$con optional connection object * @return $className * @throws PropelException */ public function get" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(PropelPDO \$con = null) { "; $script .= " if (\$this->$varName === null && !\$this->isNew()) { \$this->$varName = $queryClassname::create()->findPk(\$this->getPrimaryKey(), \$con); } return \$this->$varName; } "; }
[ "protected", "function", "addPKRefFKGet", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "queryClassname", "=", "$", "this", "->", "getNewStubQueryBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", "->", "getClassname", "(", ")", ";", "$", "varName", "=", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n /**\n * Gets a single $className object, which is related to this object by a one-to-one relationship.\n *\n * @param PropelPDO \\$con optional connection object\n * @return $className\n * @throws PropelException\n */\n public function get\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"(PropelPDO \\$con = null)\n {\n\"", ";", "$", "script", ".=", "\"\n if (\\$this->$varName === null && !\\$this->isNew()) {\n \\$this->$varName = $queryClassname::create()->findPk(\\$this->getPrimaryKey(), \\$con);\n }\n\n return \\$this->$varName;\n }\n\"", ";", "}" ]
Adds the method that gets a one-to-one related referrer fkey. This is for one-to-one relationship special case. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "gets", "a", "one", "-", "to", "-", "one", "related", "referrer", "fkey", ".", "This", "is", "for", "one", "-", "to", "-", "one", "relationship", "special", "case", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4180-L4211
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addPKRefFKSet
protected function addPKRefFKSet(&$script, ForeignKey $refFK) { $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $varName = $this->getPKRefFKVarName($refFK); $script .= " /** * Sets a single $className object as related to this object by a one-to-one relationship. * * @param $className \$v $className * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException */ public function set" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "($className \$v = null) { \$this->$varName = \$v; // Make sure that that the passed-in $className isn't already associated with this object if (\$v !== null && \$v->get" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(null, false) === null) { \$v->set" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(\$this); } return \$this; } "; }
php
protected function addPKRefFKSet(&$script, ForeignKey $refFK) { $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $varName = $this->getPKRefFKVarName($refFK); $script .= " /** * Sets a single $className object as related to this object by a one-to-one relationship. * * @param $className \$v $className * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @throws PropelException */ public function set" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "($className \$v = null) { \$this->$varName = \$v; // Make sure that that the passed-in $className isn't already associated with this object if (\$v !== null && \$v->get" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(null, false) === null) { \$v->set" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(\$this); } return \$this; } "; }
[ "protected", "function", "addPKRefFKSet", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "varName", "=", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n /**\n * Sets a single $className object as related to this object by a one-to-one relationship.\n *\n * @param $className \\$v $className\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n * @throws PropelException\n */\n public function set\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"($className \\$v = null)\n {\n \\$this->$varName = \\$v;\n\n // Make sure that that the passed-in $className isn't already associated with this object\n if (\\$v !== null && \\$v->get\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"(null, false) === null) {\n \\$v->set\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"(\\$this);\n }\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds the method that sets a one-to-one related referrer fkey. This is for one-to-one relationships special case. @param string &$script The script will be modified in this method. @param ForeignKey $refFK The referencing foreign key.
[ "Adds", "the", "method", "that", "sets", "a", "one", "-", "to", "-", "one", "related", "referrer", "fkey", ".", "This", "is", "for", "one", "-", "to", "-", "one", "relationships", "special", "case", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4220-L4249
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addCrossFKAttributes
protected function addCrossFKAttributes(&$script, ForeignKey $crossFK) { $joinedTableObjectBuilder = $this->getNewObjectBuilder($crossFK->getForeignTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $relatedName = $this->getFKPhpNameAffix($crossFK, $plural = true); $script .= " /** * @var PropelObjectCollection|{$className}[] Collection to store aggregation of $className objects. */ protected $" . $this->getCrossFKVarName($crossFK) . "; "; }
php
protected function addCrossFKAttributes(&$script, ForeignKey $crossFK) { $joinedTableObjectBuilder = $this->getNewObjectBuilder($crossFK->getForeignTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $relatedName = $this->getFKPhpNameAffix($crossFK, $plural = true); $script .= " /** * @var PropelObjectCollection|{$className}[] Collection to store aggregation of $className objects. */ protected $" . $this->getCrossFKVarName($crossFK) . "; "; }
[ "protected", "function", "addCrossFKAttributes", "(", "&", "$", "script", ",", "ForeignKey", "$", "crossFK", ")", "{", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "crossFK", "->", "getForeignTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "relatedName", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "crossFK", ",", "$", "plural", "=", "true", ")", ";", "$", "script", ".=", "\"\n /**\n * @var PropelObjectCollection|{$className}[] Collection to store aggregation of $className objects.\n */\n protected $\"", ".", "$", "this", "->", "getCrossFKVarName", "(", "$", "crossFK", ")", ".", "\";\n\"", ";", "}" ]
addPKRefFKSet
[ "addPKRefFKSet" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4251-L4262
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addCrossFKClear
protected function addCrossFKClear(&$script, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = $this->getCrossFKVarName($crossFK); $script .= " /** * Clears out the $collName collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @see add$relCol() */ public function clear$relCol() { \$this->$collName = null; // important to set this to null since that means it is uninitialized \$this->{$collName}Partial = null; return \$this; } "; }
php
protected function addCrossFKClear(&$script, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = $this->getCrossFKVarName($crossFK); $script .= " /** * Clears out the $collName collection * * This does not modify the database; however, it will remove any associated objects, causing * them to be refetched by subsequent calls to accessor method. * * @return " . $this->getObjectClassname() . " The current object (for fluent API support) * @see add$relCol() */ public function clear$relCol() { \$this->$collName = null; // important to set this to null since that means it is uninitialized \$this->{$collName}Partial = null; return \$this; } "; }
[ "protected", "function", "addCrossFKClear", "(", "&", "$", "script", ",", "ForeignKey", "$", "crossFK", ")", "{", "$", "relCol", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "crossFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getCrossFKVarName", "(", "$", "crossFK", ")", ";", "$", "script", ".=", "\"\n /**\n * Clears out the $collName collection\n *\n * This does not modify the database; however, it will remove any associated objects, causing\n * them to be refetched by subsequent calls to accessor method.\n *\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n * @see add$relCol()\n */\n public function clear$relCol()\n {\n \\$this->$collName = null; // important to set this to null since that means it is uninitialized\n \\$this->{$collName}Partial = null;\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds the method that clears the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "clears", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4384-L4407
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addCrossFKInit
protected function addCrossFKInit(&$script, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = $this->getCrossFKVarName($crossFK); $relatedObjectClassName = $this->getNewStubObjectBuilder($crossFK->getForeignTable())->getClassname(); $script .= " /** * Initializes the $collName collection. * * By default this just sets the $collName collection to an empty collection (like clear$relCol()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @return void */ public function init$relCol() { \$this->$collName = new PropelObjectCollection(); \$this->{$collName}->setModel('$relatedObjectClassName'); } "; }
php
protected function addCrossFKInit(&$script, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = $this->getCrossFKVarName($crossFK); $relatedObjectClassName = $this->getNewStubObjectBuilder($crossFK->getForeignTable())->getClassname(); $script .= " /** * Initializes the $collName collection. * * By default this just sets the $collName collection to an empty collection (like clear$relCol()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @return void */ public function init$relCol() { \$this->$collName = new PropelObjectCollection(); \$this->{$collName}->setModel('$relatedObjectClassName'); } "; }
[ "protected", "function", "addCrossFKInit", "(", "&", "$", "script", ",", "ForeignKey", "$", "crossFK", ")", "{", "$", "relCol", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "crossFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getCrossFKVarName", "(", "$", "crossFK", ")", ";", "$", "relatedObjectClassName", "=", "$", "this", "->", "getNewStubObjectBuilder", "(", "$", "crossFK", "->", "getForeignTable", "(", ")", ")", "->", "getClassname", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Initializes the $collName collection.\n *\n * By default this just sets the $collName collection to an empty collection (like clear$relCol());\n * however, you may wish to override this method in your stub class to provide setting appropriate\n * to your application -- for example, setting the initial array to the values stored in database.\n *\n * @return void\n */\n public function init$relCol()\n {\n \\$this->$collName = new PropelObjectCollection();\n \\$this->{$collName}->setModel('$relatedObjectClassName');\n }\n\"", ";", "}" ]
Adds the method that initializes the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "initializes", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4414-L4436
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addCrossFKAdd
protected function addCrossFKAdd(&$script, ForeignKey $refFK, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = $this->getCrossFKVarName($crossFK); $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $crossObjectName = '$' . $crossFK->getForeignTable()->getStudlyPhpName(); $crossObjectClassName = $this->getNewObjectBuilder($crossFK->getForeignTable())->getObjectClassname(); $relatedObjectClassName = $this->getFKPhpNameAffix($crossFK, $plural = false); $scheduledForDeletion = lcfirst($relCol) . "ScheduledForDeletion"; $script .= " /** * Associate a " . $crossObjectClassName . " object to this object * through the " . $tblFK->getName() . " cross reference table. * * @param " . $crossObjectClassName . " " . $crossObjectName . " The $className object to relate * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ public function add{$relatedObjectClassName}($crossObjectClassName $crossObjectName) { if (\$this->" . $collName . " === null) { \$this->init" . $relCol . "(); } if (!\$this->" . $collName . "->contains(" . $crossObjectName . ")) { // only add it if the **same** object is not already associated \$this->doAdd{$relatedObjectClassName}($crossObjectName); \$this->" . $collName . "[] = " . $crossObjectName . "; if (\$this->" . $scheduledForDeletion . " and \$this->" . $scheduledForDeletion . "->contains(" . $crossObjectName . ")) { \$this->" . $scheduledForDeletion . "->remove(\$this->" . $scheduledForDeletion . "->search(" . $crossObjectName . ")); } } return \$this; } "; }
php
protected function addCrossFKAdd(&$script, ForeignKey $refFK, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = $this->getCrossFKVarName($crossFK); $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $crossObjectName = '$' . $crossFK->getForeignTable()->getStudlyPhpName(); $crossObjectClassName = $this->getNewObjectBuilder($crossFK->getForeignTable())->getObjectClassname(); $relatedObjectClassName = $this->getFKPhpNameAffix($crossFK, $plural = false); $scheduledForDeletion = lcfirst($relCol) . "ScheduledForDeletion"; $script .= " /** * Associate a " . $crossObjectClassName . " object to this object * through the " . $tblFK->getName() . " cross reference table. * * @param " . $crossObjectClassName . " " . $crossObjectName . " The $className object to relate * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ public function add{$relatedObjectClassName}($crossObjectClassName $crossObjectName) { if (\$this->" . $collName . " === null) { \$this->init" . $relCol . "(); } if (!\$this->" . $collName . "->contains(" . $crossObjectName . ")) { // only add it if the **same** object is not already associated \$this->doAdd{$relatedObjectClassName}($crossObjectName); \$this->" . $collName . "[] = " . $crossObjectName . "; if (\$this->" . $scheduledForDeletion . " and \$this->" . $scheduledForDeletion . "->contains(" . $crossObjectName . ")) { \$this->" . $scheduledForDeletion . "->remove(\$this->" . $scheduledForDeletion . "->search(" . $crossObjectName . ")); } } return \$this; } "; }
[ "protected", "function", "addCrossFKAdd", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ",", "ForeignKey", "$", "crossFK", ")", "{", "$", "relCol", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "crossFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getCrossFKVarName", "(", "$", "crossFK", ")", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "crossObjectName", "=", "'$'", ".", "$", "crossFK", "->", "getForeignTable", "(", ")", "->", "getStudlyPhpName", "(", ")", ";", "$", "crossObjectClassName", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "crossFK", "->", "getForeignTable", "(", ")", ")", "->", "getObjectClassname", "(", ")", ";", "$", "relatedObjectClassName", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "crossFK", ",", "$", "plural", "=", "false", ")", ";", "$", "scheduledForDeletion", "=", "lcfirst", "(", "$", "relCol", ")", ".", "\"ScheduledForDeletion\"", ";", "$", "script", ".=", "\"\n /**\n * Associate a \"", ".", "$", "crossObjectClassName", ".", "\" object to this object\n * through the \"", ".", "$", "tblFK", "->", "getName", "(", ")", ".", "\" cross reference table.\n *\n * @param \"", ".", "$", "crossObjectClassName", ".", "\" \"", ".", "$", "crossObjectName", ".", "\" The $className object to relate\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n */\n public function add{$relatedObjectClassName}($crossObjectClassName $crossObjectName)\n {\n if (\\$this->\"", ".", "$", "collName", ".", "\" === null) {\n \\$this->init\"", ".", "$", "relCol", ".", "\"();\n }\n\n if (!\\$this->\"", ".", "$", "collName", ".", "\"->contains(\"", ".", "$", "crossObjectName", ".", "\")) { // only add it if the **same** object is not already associated\n \\$this->doAdd{$relatedObjectClassName}($crossObjectName);\n \\$this->\"", ".", "$", "collName", ".", "\"[] = \"", ".", "$", "crossObjectName", ".", "\";\n\n if (\\$this->\"", ".", "$", "scheduledForDeletion", ".", "\" and \\$this->\"", ".", "$", "scheduledForDeletion", ".", "\"->contains(\"", ".", "$", "crossObjectName", ".", "\")) {\n \\$this->\"", ".", "$", "scheduledForDeletion", ".", "\"->remove(\\$this->\"", ".", "$", "scheduledForDeletion", ".", "\"->search(\"", ".", "$", "crossObjectName", ".", "\"));\n }\n }\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds the method that adds an object into the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "adds", "an", "object", "into", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4572-L4615
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addCrossFKRemove
protected function addCrossFKRemove(&$script, ForeignKey $refFK, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = 'coll' . $relCol; $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $lowerRelCol = $relCol; $lowerRelCol[0] = strtolower($lowerRelCol[0]); $M2MScheduledForDeletion = $lowerRelCol . "ScheduledForDeletion"; $crossObjectName = '$' . $crossFK->getForeignTable()->getStudlyPhpName(); $crossObjectClassName = $this->getNewObjectBuilder($crossFK->getForeignTable())->getObjectClassname(); $relatedObjectClassName = $this->getFKPhpNameAffix($crossFK, $plural = false); $script .= " /** * Remove a {$crossObjectClassName} object to this object * through the {$tblFK->getName()} cross reference table. * * @param {$crossObjectClassName} {$crossObjectName} The $className object to relate * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ public function remove{$relatedObjectClassName}($crossObjectClassName $crossObjectName) { if (\$this->get{$relCol}()->contains({$crossObjectName})) { \$this->{$collName}->remove(\$this->{$collName}->search({$crossObjectName})); if (null === \$this->{$M2MScheduledForDeletion}) { \$this->{$M2MScheduledForDeletion} = clone \$this->{$collName}; \$this->{$M2MScheduledForDeletion}->clear(); } \$this->{$M2MScheduledForDeletion}[]= {$crossObjectName}; } return \$this; } "; }
php
protected function addCrossFKRemove(&$script, ForeignKey $refFK, ForeignKey $crossFK) { $relCol = $this->getFKPhpNameAffix($crossFK, $plural = true); $collName = 'coll' . $relCol; $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $lowerRelCol = $relCol; $lowerRelCol[0] = strtolower($lowerRelCol[0]); $M2MScheduledForDeletion = $lowerRelCol . "ScheduledForDeletion"; $crossObjectName = '$' . $crossFK->getForeignTable()->getStudlyPhpName(); $crossObjectClassName = $this->getNewObjectBuilder($crossFK->getForeignTable())->getObjectClassname(); $relatedObjectClassName = $this->getFKPhpNameAffix($crossFK, $plural = false); $script .= " /** * Remove a {$crossObjectClassName} object to this object * through the {$tblFK->getName()} cross reference table. * * @param {$crossObjectClassName} {$crossObjectName} The $className object to relate * @return " . $this->getObjectClassname() . " The current object (for fluent API support) */ public function remove{$relatedObjectClassName}($crossObjectClassName $crossObjectName) { if (\$this->get{$relCol}()->contains({$crossObjectName})) { \$this->{$collName}->remove(\$this->{$collName}->search({$crossObjectName})); if (null === \$this->{$M2MScheduledForDeletion}) { \$this->{$M2MScheduledForDeletion} = clone \$this->{$collName}; \$this->{$M2MScheduledForDeletion}->clear(); } \$this->{$M2MScheduledForDeletion}[]= {$crossObjectName}; } return \$this; } "; }
[ "protected", "function", "addCrossFKRemove", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ",", "ForeignKey", "$", "crossFK", ")", "{", "$", "relCol", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "crossFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "'coll'", ".", "$", "relCol", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "lowerRelCol", "=", "$", "relCol", ";", "$", "lowerRelCol", "[", "0", "]", "=", "strtolower", "(", "$", "lowerRelCol", "[", "0", "]", ")", ";", "$", "M2MScheduledForDeletion", "=", "$", "lowerRelCol", ".", "\"ScheduledForDeletion\"", ";", "$", "crossObjectName", "=", "'$'", ".", "$", "crossFK", "->", "getForeignTable", "(", ")", "->", "getStudlyPhpName", "(", ")", ";", "$", "crossObjectClassName", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "crossFK", "->", "getForeignTable", "(", ")", ")", "->", "getObjectClassname", "(", ")", ";", "$", "relatedObjectClassName", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "crossFK", ",", "$", "plural", "=", "false", ")", ";", "$", "script", ".=", "\"\n /**\n * Remove a {$crossObjectClassName} object to this object\n * through the {$tblFK->getName()} cross reference table.\n *\n * @param {$crossObjectClassName} {$crossObjectName} The $className object to relate\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" The current object (for fluent API support)\n */\n public function remove{$relatedObjectClassName}($crossObjectClassName $crossObjectName)\n {\n if (\\$this->get{$relCol}()->contains({$crossObjectName})) {\n \\$this->{$collName}->remove(\\$this->{$collName}->search({$crossObjectName}));\n if (null === \\$this->{$M2MScheduledForDeletion}) {\n \\$this->{$M2MScheduledForDeletion} = clone \\$this->{$collName};\n \\$this->{$M2MScheduledForDeletion}->clear();\n }\n \\$this->{$M2MScheduledForDeletion}[]= {$crossObjectName};\n }\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds the method that remove an object from the referrer fkey collection. @param string $script The script will be modified in this method.
[ "Adds", "the", "method", "that", "remove", "an", "object", "from", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4662-L4704
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addDoInsertBodyRaw
protected function addDoInsertBodyRaw() { $this->declareClasses('Propel', 'PDO'); $table = $this->getTable(); $peerClassname = $this->getPeerClassname(); $platform = $this->getPlatform(); $primaryKeyMethodInfo = ''; if ($table->getIdMethodParameters()) { $params = $table->getIdMethodParameters(); $imp = $params[0]; $primaryKeyMethodInfo = $imp->getValue(); } elseif ($table->getIdMethod() == IDMethod::NATIVE && ($platform->getNativeIdMethod() == PropelPlatformInterface::SEQUENCE || $platform->getNativeIdMethod() == PropelPlatformInterface::SERIAL)) { $primaryKeyMethodInfo = $platform->getSequenceName($table); } $query = 'INSERT INTO ' . $platform->quoteIdentifier($table->getName()) . ' (%s) VALUES (%s)'; $script = " \$modifiedColumns = array(); \$index = 0; "; foreach ($table->getPrimaryKey() as $column) { if (!$column->isAutoIncrement()) { continue; } $constantName = $this->getColumnConstant($column); if ($platform->supportsInsertNullPk()) { $script .= " \$this->modifiedColumns[] = $constantName;"; } $columnProperty = strtolower($column->getName()); if (!$table->isAllowPkInsert()) { $script .= " if (null !== \$this->{$columnProperty}) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . $constantName . ')'); }"; } elseif (!$platform->supportsInsertNullPk()) { $script .= " // add primary key column only if it is not null since this database does not accept that if (null !== \$this->{$columnProperty}) { \$this->modifiedColumns[] = $constantName; }"; } } // if non auto-increment but using sequence, get the id first if (!$platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() == "native") { $column = $table->getFirstPrimaryKeyColumn(); $columnProperty = strtolower($column->getName()); $script .= " if (null === \$this->{$columnProperty}) { try {"; $script .= $platform->getIdentifierPhp('$this->' . $columnProperty, '$con', $primaryKeyMethodInfo, ' '); $script .= " } catch (Exception \$e) { throw new PropelException('Unable to get sequence id.', \$e); } } "; } $script .= " // check the columns in natural order for more readable SQL queries"; foreach ($table->getColumns() as $column) { $constantName = $this->getColumnConstant($column); $identifier = var_export($platform->quoteIdentifier($column->getName()), true); $script .= " if (\$this->isColumnModified($constantName)) { \$modifiedColumns[':p' . \$index++] = $identifier; }"; } $script .= " \$sql = sprintf( '$query', implode(', ', \$modifiedColumns), implode(', ', array_keys(\$modifiedColumns)) ); try { \$stmt = \$con->prepare(\$sql); foreach (\$modifiedColumns as \$identifier => \$columnName) { switch (\$columnName) {"; foreach ($table->getColumns() as $column) { $columnNameCase = var_export($platform->quoteIdentifier($column->getName()), true); $script .= " case $columnNameCase:"; $script .= $platform->getColumnBindingPHP($column, "\$identifier", '$this->' . strtolower($column->getName()), ' '); $script .= " break;"; } $script .= " } } \$stmt->execute(); } catch (Exception \$e) { Propel::log(\$e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', \$sql), \$e); } "; // if auto-increment, get the id after if ($platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() == "native") { $column = $table->getFirstPrimaryKeyColumn(); $columnProperty = strtolower($column->getName()); $script .= " try {"; $script .= $platform->getIdentifierPhp('$pk', '$con', $primaryKeyMethodInfo); $script .= " } catch (Exception \$e) { throw new PropelException('Unable to get autoincrement id.', \$e); }"; if ($table->isAllowPkInsert()) { $script .= " if (\$pk !== null) { \$this->set" . $column->getPhpName() . "(\$pk); }"; } else { $script .= " \$this->set" . $column->getPhpName() . "(\$pk);"; } $script .= " "; } return $script; }
php
protected function addDoInsertBodyRaw() { $this->declareClasses('Propel', 'PDO'); $table = $this->getTable(); $peerClassname = $this->getPeerClassname(); $platform = $this->getPlatform(); $primaryKeyMethodInfo = ''; if ($table->getIdMethodParameters()) { $params = $table->getIdMethodParameters(); $imp = $params[0]; $primaryKeyMethodInfo = $imp->getValue(); } elseif ($table->getIdMethod() == IDMethod::NATIVE && ($platform->getNativeIdMethod() == PropelPlatformInterface::SEQUENCE || $platform->getNativeIdMethod() == PropelPlatformInterface::SERIAL)) { $primaryKeyMethodInfo = $platform->getSequenceName($table); } $query = 'INSERT INTO ' . $platform->quoteIdentifier($table->getName()) . ' (%s) VALUES (%s)'; $script = " \$modifiedColumns = array(); \$index = 0; "; foreach ($table->getPrimaryKey() as $column) { if (!$column->isAutoIncrement()) { continue; } $constantName = $this->getColumnConstant($column); if ($platform->supportsInsertNullPk()) { $script .= " \$this->modifiedColumns[] = $constantName;"; } $columnProperty = strtolower($column->getName()); if (!$table->isAllowPkInsert()) { $script .= " if (null !== \$this->{$columnProperty}) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . $constantName . ')'); }"; } elseif (!$platform->supportsInsertNullPk()) { $script .= " // add primary key column only if it is not null since this database does not accept that if (null !== \$this->{$columnProperty}) { \$this->modifiedColumns[] = $constantName; }"; } } // if non auto-increment but using sequence, get the id first if (!$platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() == "native") { $column = $table->getFirstPrimaryKeyColumn(); $columnProperty = strtolower($column->getName()); $script .= " if (null === \$this->{$columnProperty}) { try {"; $script .= $platform->getIdentifierPhp('$this->' . $columnProperty, '$con', $primaryKeyMethodInfo, ' '); $script .= " } catch (Exception \$e) { throw new PropelException('Unable to get sequence id.', \$e); } } "; } $script .= " // check the columns in natural order for more readable SQL queries"; foreach ($table->getColumns() as $column) { $constantName = $this->getColumnConstant($column); $identifier = var_export($platform->quoteIdentifier($column->getName()), true); $script .= " if (\$this->isColumnModified($constantName)) { \$modifiedColumns[':p' . \$index++] = $identifier; }"; } $script .= " \$sql = sprintf( '$query', implode(', ', \$modifiedColumns), implode(', ', array_keys(\$modifiedColumns)) ); try { \$stmt = \$con->prepare(\$sql); foreach (\$modifiedColumns as \$identifier => \$columnName) { switch (\$columnName) {"; foreach ($table->getColumns() as $column) { $columnNameCase = var_export($platform->quoteIdentifier($column->getName()), true); $script .= " case $columnNameCase:"; $script .= $platform->getColumnBindingPHP($column, "\$identifier", '$this->' . strtolower($column->getName()), ' '); $script .= " break;"; } $script .= " } } \$stmt->execute(); } catch (Exception \$e) { Propel::log(\$e->getMessage(), Propel::LOG_ERR); throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', \$sql), \$e); } "; // if auto-increment, get the id after if ($platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() == "native") { $column = $table->getFirstPrimaryKeyColumn(); $columnProperty = strtolower($column->getName()); $script .= " try {"; $script .= $platform->getIdentifierPhp('$pk', '$con', $primaryKeyMethodInfo); $script .= " } catch (Exception \$e) { throw new PropelException('Unable to get autoincrement id.', \$e); }"; if ($table->isAllowPkInsert()) { $script .= " if (\$pk !== null) { \$this->set" . $column->getPhpName() . "(\$pk); }"; } else { $script .= " \$this->set" . $column->getPhpName() . "(\$pk);"; } $script .= " "; } return $script; }
[ "protected", "function", "addDoInsertBodyRaw", "(", ")", "{", "$", "this", "->", "declareClasses", "(", "'Propel'", ",", "'PDO'", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "peerClassname", "=", "$", "this", "->", "getPeerClassname", "(", ")", ";", "$", "platform", "=", "$", "this", "->", "getPlatform", "(", ")", ";", "$", "primaryKeyMethodInfo", "=", "''", ";", "if", "(", "$", "table", "->", "getIdMethodParameters", "(", ")", ")", "{", "$", "params", "=", "$", "table", "->", "getIdMethodParameters", "(", ")", ";", "$", "imp", "=", "$", "params", "[", "0", "]", ";", "$", "primaryKeyMethodInfo", "=", "$", "imp", "->", "getValue", "(", ")", ";", "}", "elseif", "(", "$", "table", "->", "getIdMethod", "(", ")", "==", "IDMethod", "::", "NATIVE", "&&", "(", "$", "platform", "->", "getNativeIdMethod", "(", ")", "==", "PropelPlatformInterface", "::", "SEQUENCE", "||", "$", "platform", "->", "getNativeIdMethod", "(", ")", "==", "PropelPlatformInterface", "::", "SERIAL", ")", ")", "{", "$", "primaryKeyMethodInfo", "=", "$", "platform", "->", "getSequenceName", "(", "$", "table", ")", ";", "}", "$", "query", "=", "'INSERT INTO '", ".", "$", "platform", "->", "quoteIdentifier", "(", "$", "table", "->", "getName", "(", ")", ")", ".", "' (%s) VALUES (%s)'", ";", "$", "script", "=", "\"\n \\$modifiedColumns = array();\n \\$index = 0;\n\"", ";", "foreach", "(", "$", "table", "->", "getPrimaryKey", "(", ")", "as", "$", "column", ")", "{", "if", "(", "!", "$", "column", "->", "isAutoIncrement", "(", ")", ")", "{", "continue", ";", "}", "$", "constantName", "=", "$", "this", "->", "getColumnConstant", "(", "$", "column", ")", ";", "if", "(", "$", "platform", "->", "supportsInsertNullPk", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->modifiedColumns[] = $constantName;\"", ";", "}", "$", "columnProperty", "=", "strtolower", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "if", "(", "!", "$", "table", "->", "isAllowPkInsert", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (null !== \\$this->{$columnProperty}) {\n throw new PropelException('Cannot insert a value for auto-increment primary key (' . $constantName . ')');\n }\"", ";", "}", "elseif", "(", "!", "$", "platform", "->", "supportsInsertNullPk", "(", ")", ")", "{", "$", "script", ".=", "\"\n // add primary key column only if it is not null since this database does not accept that\n if (null !== \\$this->{$columnProperty}) {\n \\$this->modifiedColumns[] = $constantName;\n }\"", ";", "}", "}", "// if non auto-increment but using sequence, get the id first", "if", "(", "!", "$", "platform", "->", "isNativeIdMethodAutoIncrement", "(", ")", "&&", "$", "table", "->", "getIdMethod", "(", ")", "==", "\"native\"", ")", "{", "$", "column", "=", "$", "table", "->", "getFirstPrimaryKeyColumn", "(", ")", ";", "$", "columnProperty", "=", "strtolower", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n if (null === \\$this->{$columnProperty}) {\n try {\"", ";", "$", "script", ".=", "$", "platform", "->", "getIdentifierPhp", "(", "'$this->'", ".", "$", "columnProperty", ",", "'$con'", ",", "$", "primaryKeyMethodInfo", ",", "'\t\t\t\t'", ")", ";", "$", "script", ".=", "\"\n } catch (Exception \\$e) {\n throw new PropelException('Unable to get sequence id.', \\$e);\n }\n }\n\"", ";", "}", "$", "script", ".=", "\"\n\n // check the columns in natural order for more readable SQL queries\"", ";", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "constantName", "=", "$", "this", "->", "getColumnConstant", "(", "$", "column", ")", ";", "$", "identifier", "=", "var_export", "(", "$", "platform", "->", "quoteIdentifier", "(", "$", "column", "->", "getName", "(", ")", ")", ",", "true", ")", ";", "$", "script", ".=", "\"\n if (\\$this->isColumnModified($constantName)) {\n \\$modifiedColumns[':p' . \\$index++] = $identifier;\n }\"", ";", "}", "$", "script", ".=", "\"\n\n \\$sql = sprintf(\n '$query',\n implode(', ', \\$modifiedColumns),\n implode(', ', array_keys(\\$modifiedColumns))\n );\n\n try {\n \\$stmt = \\$con->prepare(\\$sql);\n foreach (\\$modifiedColumns as \\$identifier => \\$columnName) {\n switch (\\$columnName) {\"", ";", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "columnNameCase", "=", "var_export", "(", "$", "platform", "->", "quoteIdentifier", "(", "$", "column", "->", "getName", "(", ")", ")", ",", "true", ")", ";", "$", "script", ".=", "\"\n case $columnNameCase:\"", ";", "$", "script", ".=", "$", "platform", "->", "getColumnBindingPHP", "(", "$", "column", ",", "\"\\$identifier\"", ",", "'$this->'", ".", "strtolower", "(", "$", "column", "->", "getName", "(", ")", ")", ",", "'\t\t\t\t\t\t'", ")", ";", "$", "script", ".=", "\"\n break;\"", ";", "}", "$", "script", ".=", "\"\n }\n }\n \\$stmt->execute();\n } catch (Exception \\$e) {\n Propel::log(\\$e->getMessage(), Propel::LOG_ERR);\n throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', \\$sql), \\$e);\n }\n\"", ";", "// if auto-increment, get the id after", "if", "(", "$", "platform", "->", "isNativeIdMethodAutoIncrement", "(", ")", "&&", "$", "table", "->", "getIdMethod", "(", ")", "==", "\"native\"", ")", "{", "$", "column", "=", "$", "table", "->", "getFirstPrimaryKeyColumn", "(", ")", ";", "$", "columnProperty", "=", "strtolower", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n try {\"", ";", "$", "script", ".=", "$", "platform", "->", "getIdentifierPhp", "(", "'$pk'", ",", "'$con'", ",", "$", "primaryKeyMethodInfo", ")", ";", "$", "script", ".=", "\"\n } catch (Exception \\$e) {\n throw new PropelException('Unable to get autoincrement id.', \\$e);\n }\"", ";", "if", "(", "$", "table", "->", "isAllowPkInsert", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (\\$pk !== null) {\n \\$this->set\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"(\\$pk);\n }\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$this->set\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"(\\$pk);\"", ";", "}", "$", "script", ".=", "\"\n\"", ";", "}", "return", "$", "script", ";", "}" ]
Boosts ActiveRecord::doInsert() by doing more calculations at buildtime.
[ "Boosts", "ActiveRecord", "::", "doInsert", "()", "by", "doing", "more", "calculations", "at", "buildtime", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L4970-L5097
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addSaveBody
protected function addSaveBody(&$script) { $table = $this->getTable(); $reloadOnUpdate = $table->isReloadOnUpdate(); $reloadOnInsert = $table->isReloadOnInsert(); $script .= " if (\$this->isDeleted()) { throw new PropelException(\"You cannot save an object that has been deleted.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE); } \$con->beginTransaction(); \$isInsert = \$this->isNew(); try {"; if ($this->getGeneratorConfig()->getBuildProperty('addHooks')) { // save with runtime hooks $script .= " \$ret = \$this->preSave(\$con);"; $this->applyBehaviorModifier('preSave', $script, " "); $script .= " if (\$isInsert) { \$ret = \$ret && \$this->preInsert(\$con);"; $this->applyBehaviorModifier('preInsert', $script, " "); $script .= " } else { \$ret = \$ret && \$this->preUpdate(\$con);"; $this->applyBehaviorModifier('preUpdate', $script, " "); $script .= " } if (\$ret) { \$affectedRows = \$this->doSave(\$con" . ($reloadOnUpdate || $reloadOnInsert ? ", \$skipReload" : "") . "); if (\$isInsert) { \$this->postInsert(\$con);"; $this->applyBehaviorModifier('postInsert', $script, " "); $script .= " } else { \$this->postUpdate(\$con);"; $this->applyBehaviorModifier('postUpdate', $script, " "); $script .= " } \$this->postSave(\$con);"; $this->applyBehaviorModifier('postSave', $script, " "); $script .= " " . $this->getPeerClassname() . "::addInstanceToPool(\$this); } else { \$affectedRows = 0; } \$con->commit(); return \$affectedRows;"; } else { // save without runtime hooks $this->applyBehaviorModifier('preSave', $script, " "); if ($this->hasBehaviorModifier('preUpdate')) { $script .= " if (!\$isInsert) {"; $this->applyBehaviorModifier('preUpdate', $script, " "); $script .= " }"; } if ($this->hasBehaviorModifier('preInsert')) { $script .= " if (\$isInsert) {"; $this->applyBehaviorModifier('preInsert', $script, " "); $script .= " }"; } $script .= " \$affectedRows = \$this->doSave(\$con" . ($reloadOnUpdate || $reloadOnInsert ? ", \$skipReload" : "") . ");"; $this->applyBehaviorModifier('postSave', $script, " "); if ($this->hasBehaviorModifier('postUpdate')) { $script .= " if (!\$isInsert) {"; $this->applyBehaviorModifier('postUpdate', $script, " "); $script .= " }"; } if ($this->hasBehaviorModifier('postInsert')) { $script .= " if (\$isInsert) {"; $this->applyBehaviorModifier('postInsert', $script, " "); $script .= " }"; } $script .= " \$con->commit(); " . $this->getPeerClassname() . "::addInstanceToPool(\$this); return \$affectedRows;"; } $script .= " } catch (Exception \$e) { \$con->rollBack(); throw \$e; }"; }
php
protected function addSaveBody(&$script) { $table = $this->getTable(); $reloadOnUpdate = $table->isReloadOnUpdate(); $reloadOnInsert = $table->isReloadOnInsert(); $script .= " if (\$this->isDeleted()) { throw new PropelException(\"You cannot save an object that has been deleted.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE); } \$con->beginTransaction(); \$isInsert = \$this->isNew(); try {"; if ($this->getGeneratorConfig()->getBuildProperty('addHooks')) { // save with runtime hooks $script .= " \$ret = \$this->preSave(\$con);"; $this->applyBehaviorModifier('preSave', $script, " "); $script .= " if (\$isInsert) { \$ret = \$ret && \$this->preInsert(\$con);"; $this->applyBehaviorModifier('preInsert', $script, " "); $script .= " } else { \$ret = \$ret && \$this->preUpdate(\$con);"; $this->applyBehaviorModifier('preUpdate', $script, " "); $script .= " } if (\$ret) { \$affectedRows = \$this->doSave(\$con" . ($reloadOnUpdate || $reloadOnInsert ? ", \$skipReload" : "") . "); if (\$isInsert) { \$this->postInsert(\$con);"; $this->applyBehaviorModifier('postInsert', $script, " "); $script .= " } else { \$this->postUpdate(\$con);"; $this->applyBehaviorModifier('postUpdate', $script, " "); $script .= " } \$this->postSave(\$con);"; $this->applyBehaviorModifier('postSave', $script, " "); $script .= " " . $this->getPeerClassname() . "::addInstanceToPool(\$this); } else { \$affectedRows = 0; } \$con->commit(); return \$affectedRows;"; } else { // save without runtime hooks $this->applyBehaviorModifier('preSave', $script, " "); if ($this->hasBehaviorModifier('preUpdate')) { $script .= " if (!\$isInsert) {"; $this->applyBehaviorModifier('preUpdate', $script, " "); $script .= " }"; } if ($this->hasBehaviorModifier('preInsert')) { $script .= " if (\$isInsert) {"; $this->applyBehaviorModifier('preInsert', $script, " "); $script .= " }"; } $script .= " \$affectedRows = \$this->doSave(\$con" . ($reloadOnUpdate || $reloadOnInsert ? ", \$skipReload" : "") . ");"; $this->applyBehaviorModifier('postSave', $script, " "); if ($this->hasBehaviorModifier('postUpdate')) { $script .= " if (!\$isInsert) {"; $this->applyBehaviorModifier('postUpdate', $script, " "); $script .= " }"; } if ($this->hasBehaviorModifier('postInsert')) { $script .= " if (\$isInsert) {"; $this->applyBehaviorModifier('postInsert', $script, " "); $script .= " }"; } $script .= " \$con->commit(); " . $this->getPeerClassname() . "::addInstanceToPool(\$this); return \$affectedRows;"; } $script .= " } catch (Exception \$e) { \$con->rollBack(); throw \$e; }"; }
[ "protected", "function", "addSaveBody", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "reloadOnUpdate", "=", "$", "table", "->", "isReloadOnUpdate", "(", ")", ";", "$", "reloadOnInsert", "=", "$", "table", "->", "isReloadOnInsert", "(", ")", ";", "$", "script", ".=", "\"\n if (\\$this->isDeleted()) {\n throw new PropelException(\\\"You cannot save an object that has been deleted.\\\");\n }\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME, Propel::CONNECTION_WRITE);\n }\n\n \\$con->beginTransaction();\n \\$isInsert = \\$this->isNew();\n try {\"", ";", "if", "(", "$", "this", "->", "getGeneratorConfig", "(", ")", "->", "getBuildProperty", "(", "'addHooks'", ")", ")", "{", "// save with runtime hooks", "$", "script", ".=", "\"\n \\$ret = \\$this->preSave(\\$con);\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'preSave'", ",", "$", "script", ",", "\"\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n if (\\$isInsert) {\n \\$ret = \\$ret && \\$this->preInsert(\\$con);\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'preInsert'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n } else {\n \\$ret = \\$ret && \\$this->preUpdate(\\$con);\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'preUpdate'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n }\n if (\\$ret) {\n \\$affectedRows = \\$this->doSave(\\$con\"", ".", "(", "$", "reloadOnUpdate", "||", "$", "reloadOnInsert", "?", "\", \\$skipReload\"", ":", "\"\"", ")", ".", "\");\n if (\\$isInsert) {\n \\$this->postInsert(\\$con);\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'postInsert'", ",", "$", "script", ",", "\"\t\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n } else {\n \\$this->postUpdate(\\$con);\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'postUpdate'", ",", "$", "script", ",", "\"\t\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n }\n \\$this->postSave(\\$con);\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'postSave'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::addInstanceToPool(\\$this);\n } else {\n \\$affectedRows = 0;\n }\n \\$con->commit();\n\n return \\$affectedRows;\"", ";", "}", "else", "{", "// save without runtime hooks", "$", "this", "->", "applyBehaviorModifier", "(", "'preSave'", ",", "$", "script", ",", "\"\t\t\t\"", ")", ";", "if", "(", "$", "this", "->", "hasBehaviorModifier", "(", "'preUpdate'", ")", ")", "{", "$", "script", ".=", "\"\n if (!\\$isInsert) {\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'preUpdate'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n }\"", ";", "}", "if", "(", "$", "this", "->", "hasBehaviorModifier", "(", "'preInsert'", ")", ")", "{", "$", "script", ".=", "\"\n if (\\$isInsert) {\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'preInsert'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n }\"", ";", "}", "$", "script", ".=", "\"\n \\$affectedRows = \\$this->doSave(\\$con\"", ".", "(", "$", "reloadOnUpdate", "||", "$", "reloadOnInsert", "?", "\", \\$skipReload\"", ":", "\"\"", ")", ".", "\");\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'postSave'", ",", "$", "script", ",", "\"\t\t\t\"", ")", ";", "if", "(", "$", "this", "->", "hasBehaviorModifier", "(", "'postUpdate'", ")", ")", "{", "$", "script", ".=", "\"\n if (!\\$isInsert) {\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'postUpdate'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n }\"", ";", "}", "if", "(", "$", "this", "->", "hasBehaviorModifier", "(", "'postInsert'", ")", ")", "{", "$", "script", ".=", "\"\n if (\\$isInsert) {\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'postInsert'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n }\"", ";", "}", "$", "script", ".=", "\"\n \\$con->commit();\n \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::addInstanceToPool(\\$this);\n\n return \\$affectedRows;\"", ";", "}", "$", "script", ".=", "\"\n } catch (Exception \\$e) {\n \\$con->rollBack();\n throw \\$e;\n }\"", ";", "}" ]
Adds the function body for the save method @param string &$script The script will be modified in this method. @see addSave()
[ "Adds", "the", "function", "body", "for", "the", "save", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L5229-L5330
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addDoValidate
protected function addDoValidate(&$script) { $table = $this->getTable(); $script .= " /** * This function performs the validation work for complex object models. * * In addition to checking the current object, all related objects will * also be validated. If all pass then <code>true</code> is returned; otherwise * an aggregated array of ValidationFailed objects will be returned. * * @param array \$columns Array of column names to validate. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objects otherwise. */ protected function doValidate(\$columns = null) { if (!\$this->alreadyInValidation) { \$this->alreadyInValidation = true; \$retval = null; \$failureMap = array(); "; if (count($table->getForeignKeys()) != 0) { $script .= " // We call the validate method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. "; foreach ($table->getForeignKeys() as $fk) { $aVarName = $this->getFKVarName($fk); $script .= " if (\$this->" . $aVarName . " !== null) { if (!\$this->" . $aVarName . "->validate(\$columns)) { \$failureMap = array_merge(\$failureMap, \$this->" . $aVarName . "->getValidationFailures()); } } "; } /* for () */ } /* if count(fkeys) */ $script .= " if ((\$retval = " . $this->getPeerClassname() . "::doValidate(\$this, \$columns)) !== true) { \$failureMap = array_merge(\$failureMap, \$retval); } "; foreach ($table->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $varName = $this->getPKRefFKVarName($refFK); $script .= " if (\$this->$varName !== null) { if (!\$this->" . $varName . "->validate(\$columns)) { \$failureMap = array_merge(\$failureMap, \$this->" . $varName . "->getValidationFailures()); } } "; } else { $collName = $this->getRefFKCollVarName($refFK); $script .= " if (\$this->$collName !== null) { foreach (\$this->$collName as \$referrerFK) { if (!\$referrerFK->validate(\$columns)) { \$failureMap = array_merge(\$failureMap, \$referrerFK->getValidationFailures()); } } } "; } } /* foreach getReferrers() */ $script .= " \$this->alreadyInValidation = false; } return (!empty(\$failureMap) ? \$failureMap : true); } "; }
php
protected function addDoValidate(&$script) { $table = $this->getTable(); $script .= " /** * This function performs the validation work for complex object models. * * In addition to checking the current object, all related objects will * also be validated. If all pass then <code>true</code> is returned; otherwise * an aggregated array of ValidationFailed objects will be returned. * * @param array \$columns Array of column names to validate. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objects otherwise. */ protected function doValidate(\$columns = null) { if (!\$this->alreadyInValidation) { \$this->alreadyInValidation = true; \$retval = null; \$failureMap = array(); "; if (count($table->getForeignKeys()) != 0) { $script .= " // We call the validate method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. "; foreach ($table->getForeignKeys() as $fk) { $aVarName = $this->getFKVarName($fk); $script .= " if (\$this->" . $aVarName . " !== null) { if (!\$this->" . $aVarName . "->validate(\$columns)) { \$failureMap = array_merge(\$failureMap, \$this->" . $aVarName . "->getValidationFailures()); } } "; } /* for () */ } /* if count(fkeys) */ $script .= " if ((\$retval = " . $this->getPeerClassname() . "::doValidate(\$this, \$columns)) !== true) { \$failureMap = array_merge(\$failureMap, \$retval); } "; foreach ($table->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $varName = $this->getPKRefFKVarName($refFK); $script .= " if (\$this->$varName !== null) { if (!\$this->" . $varName . "->validate(\$columns)) { \$failureMap = array_merge(\$failureMap, \$this->" . $varName . "->getValidationFailures()); } } "; } else { $collName = $this->getRefFKCollVarName($refFK); $script .= " if (\$this->$collName !== null) { foreach (\$this->$collName as \$referrerFK) { if (!\$referrerFK->validate(\$columns)) { \$failureMap = array_merge(\$failureMap, \$referrerFK->getValidationFailures()); } } } "; } } /* foreach getReferrers() */ $script .= " \$this->alreadyInValidation = false; } return (!empty(\$failureMap) ? \$failureMap : true); } "; }
[ "protected", "function", "addDoValidate", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * This function performs the validation work for complex object models.\n *\n * In addition to checking the current object, all related objects will\n * also be validated. If all pass then <code>true</code> is returned; otherwise\n * an aggregated array of ValidationFailed objects will be returned.\n *\n * @param array \\$columns Array of column names to validate.\n * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objects otherwise.\n */\n protected function doValidate(\\$columns = null)\n {\n if (!\\$this->alreadyInValidation) {\n \\$this->alreadyInValidation = true;\n \\$retval = null;\n\n \\$failureMap = array();\n\"", ";", "if", "(", "count", "(", "$", "table", "->", "getForeignKeys", "(", ")", ")", "!=", "0", ")", "{", "$", "script", ".=", "\"\n\n // We call the validate method on the following object(s) if they\n // were passed to this object by their corresponding set\n // method. This object relates to these object(s) by a\n // foreign key reference.\n\"", ";", "foreach", "(", "$", "table", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "aVarName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n if (\\$this->\"", ".", "$", "aVarName", ".", "\" !== null) {\n if (!\\$this->\"", ".", "$", "aVarName", ".", "\"->validate(\\$columns)) {\n \\$failureMap = array_merge(\\$failureMap, \\$this->\"", ".", "$", "aVarName", ".", "\"->getValidationFailures());\n }\n }\n\"", ";", "}", "/* for () */", "}", "/* if count(fkeys) */", "$", "script", ".=", "\"\n\n if ((\\$retval = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::doValidate(\\$this, \\$columns)) !== true) {\n \\$failureMap = array_merge(\\$failureMap, \\$retval);\n }\n\n\"", ";", "foreach", "(", "$", "table", "->", "getReferrers", "(", ")", "as", "$", "refFK", ")", "{", "if", "(", "$", "refFK", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "varName", "=", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n if (\\$this->$varName !== null) {\n if (!\\$this->\"", ".", "$", "varName", ".", "\"->validate(\\$columns)) {\n \\$failureMap = array_merge(\\$failureMap, \\$this->\"", ".", "$", "varName", ".", "\"->getValidationFailures());\n }\n }\n\"", ";", "}", "else", "{", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n if (\\$this->$collName !== null) {\n foreach (\\$this->$collName as \\$referrerFK) {\n if (!\\$referrerFK->validate(\\$columns)) {\n \\$failureMap = array_merge(\\$failureMap, \\$referrerFK->getValidationFailures());\n }\n }\n }\n\"", ";", "}", "}", "/* foreach getReferrers() */", "$", "script", ".=", "\"\n\n \\$this->alreadyInValidation = false;\n }\n\n return (!empty(\\$failureMap) ? \\$failureMap : true);\n }\n\"", ";", "}" ]
Adds the workhouse doValidate() method. @param string &$script The script will be modified in this method.
[ "Adds", "the", "workhouse", "doValidate", "()", "method", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L5419-L5502
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addEnsureConsistency
protected function addEnsureConsistency(&$script) { $table = $this->getTable(); $script .= " /** * Checks and repairs the internal consistency of the object. * * This method is executed after an already-instantiated object is re-hydrated * from the database. It exists to check any foreign keys to make sure that * the objects related to the current object are correct based on foreign key. * * You can override this method in the stub class, but you should always invoke * the base method from the overridden method (i.e. parent::ensureConsistency()), * in case your model changes. * * @throws PropelException */ public function ensureConsistency() { "; foreach ($table->getColumns() as $col) { $clo = strtolower($col->getName()); if ($col->isForeignKey()) { foreach ($col->getForeignKeys() as $fk) { $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName()); $colFK = $tblFK->getColumn($fk->getMappedForeignColumn($col->getName())); $varName = $this->getFKVarName($fk); $script .= " if (\$this->" . $varName . " !== null && \$this->$clo !== \$this->" . $varName . "->get" . $colFK->getPhpName() . "()) { \$this->$varName = null; }"; } // foreach } /* if col is foreign key */ } // foreach $script .= " } // ensureConsistency "; }
php
protected function addEnsureConsistency(&$script) { $table = $this->getTable(); $script .= " /** * Checks and repairs the internal consistency of the object. * * This method is executed after an already-instantiated object is re-hydrated * from the database. It exists to check any foreign keys to make sure that * the objects related to the current object are correct based on foreign key. * * You can override this method in the stub class, but you should always invoke * the base method from the overridden method (i.e. parent::ensureConsistency()), * in case your model changes. * * @throws PropelException */ public function ensureConsistency() { "; foreach ($table->getColumns() as $col) { $clo = strtolower($col->getName()); if ($col->isForeignKey()) { foreach ($col->getForeignKeys() as $fk) { $tblFK = $table->getDatabase()->getTable($fk->getForeignTableName()); $colFK = $tblFK->getColumn($fk->getMappedForeignColumn($col->getName())); $varName = $this->getFKVarName($fk); $script .= " if (\$this->" . $varName . " !== null && \$this->$clo !== \$this->" . $varName . "->get" . $colFK->getPhpName() . "()) { \$this->$varName = null; }"; } // foreach } /* if col is foreign key */ } // foreach $script .= " } // ensureConsistency "; }
[ "protected", "function", "addEnsureConsistency", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Checks and repairs the internal consistency of the object.\n *\n * This method is executed after an already-instantiated object is re-hydrated\n * from the database. It exists to check any foreign keys to make sure that\n * the objects related to the current object are correct based on foreign key.\n *\n * You can override this method in the stub class, but you should always invoke\n * the base method from the overridden method (i.e. parent::ensureConsistency()),\n * in case your model changes.\n *\n * @throws PropelException\n */\n public function ensureConsistency()\n {\n\"", ";", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "col", "->", "isForeignKey", "(", ")", ")", "{", "foreach", "(", "$", "col", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "tblFK", "=", "$", "table", "->", "getDatabase", "(", ")", "->", "getTable", "(", "$", "fk", "->", "getForeignTableName", "(", ")", ")", ";", "$", "colFK", "=", "$", "tblFK", "->", "getColumn", "(", "$", "fk", "->", "getMappedForeignColumn", "(", "$", "col", "->", "getName", "(", ")", ")", ")", ";", "$", "varName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n if (\\$this->\"", ".", "$", "varName", ".", "\" !== null && \\$this->$clo !== \\$this->\"", ".", "$", "varName", ".", "\"->get\"", ".", "$", "colFK", "->", "getPhpName", "(", ")", ".", "\"()) {\n \\$this->$varName = null;\n }\"", ";", "}", "// foreach", "}", "/* if col is foreign key */", "}", "// foreach", "$", "script", ".=", "\"\n } // ensureConsistency\n\"", ";", "}" ]
Adds the ensureConsistency() method to ensure that internal state is correct. @param string &$script The script will be modified in this method.
[ "Adds", "the", "ensureConsistency", "()", "method", "to", "ensure", "that", "internal", "state", "is", "correct", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L5509-L5552
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addCopy
protected function addCopy(&$script) { $this->addCopyInto($script); $table = $this->getTable(); $script .= " /** * Makes a copy of this object that will be inserted as a new row in table when saved. * It creates a new object filling in the simple attributes, but skipping any primary * keys that are defined for the table. * * If desired, this method can also make copies of all associated (fkey referrers) * objects. * * @param boolean \$deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @return " . $this->getObjectClassname() . " Clone of current object. * @throws PropelException */ public function copy(\$deepCopy = false) { // we use get_class(), because this might be a subclass \$clazz = get_class(\$this); " . $this->buildObjectInstanceCreationCode('$copyObj', '$clazz') . " \$this->copyInto(\$copyObj, \$deepCopy); return \$copyObj; } "; }
php
protected function addCopy(&$script) { $this->addCopyInto($script); $table = $this->getTable(); $script .= " /** * Makes a copy of this object that will be inserted as a new row in table when saved. * It creates a new object filling in the simple attributes, but skipping any primary * keys that are defined for the table. * * If desired, this method can also make copies of all associated (fkey referrers) * objects. * * @param boolean \$deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @return " . $this->getObjectClassname() . " Clone of current object. * @throws PropelException */ public function copy(\$deepCopy = false) { // we use get_class(), because this might be a subclass \$clazz = get_class(\$this); " . $this->buildObjectInstanceCreationCode('$copyObj', '$clazz') . " \$this->copyInto(\$copyObj, \$deepCopy); return \$copyObj; } "; }
[ "protected", "function", "addCopy", "(", "&", "$", "script", ")", "{", "$", "this", "->", "addCopyInto", "(", "$", "script", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Makes a copy of this object that will be inserted as a new row in table when saved.\n * It creates a new object filling in the simple attributes, but skipping any primary\n * keys that are defined for the table.\n *\n * If desired, this method can also make copies of all associated (fkey referrers)\n * objects.\n *\n * @param boolean \\$deepCopy Whether to also copy all rows that refer (by fkey) to the current row.\n * @return \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" Clone of current object.\n * @throws PropelException\n */\n public function copy(\\$deepCopy = false)\n {\n // we use get_class(), because this might be a subclass\n \\$clazz = get_class(\\$this);\n \"", ".", "$", "this", "->", "buildObjectInstanceCreationCode", "(", "'$copyObj'", ",", "'$clazz'", ")", ".", "\"\n \\$this->copyInto(\\$copyObj, \\$deepCopy);\n\n return \\$copyObj;\n }\n\"", ";", "}" ]
Adds the copy() method, which (in complex OM) includes the $deepCopy param for making copies of related objects. @param string &$script The script will be modified in this method.
[ "Adds", "the", "copy", "()", "method", "which", "(", "in", "complex", "OM", ")", "includes", "the", "$deepCopy", "param", "for", "making", "copies", "of", "related", "objects", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L5559-L5588
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addCopyInto
protected function addCopyInto(&$script) { $table = $this->getTable(); $script .= " /** * Sets contents of passed object to values from current object. * * If desired, this method can also make copies of all associated (fkey referrers) * objects. * * @param object \$copyObj An object of " . $this->getObjectClassname() . " (or compatible) type. * @param boolean \$deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @param boolean \$makeNew Whether to reset autoincrement PKs and make the object new. * @throws PropelException */ public function copyInto(\$copyObj, \$deepCopy = false, \$makeNew = true) {"; $autoIncCols = array(); if ($table->hasCompositePrimaryKey()) { foreach ($table->getColumns() as $col) { /* @var $col Column */ if ($col->isAutoIncrement()) { $autoIncCols[] = $col; } } } else { $autoIncCols = $table->getPrimaryKey(); } foreach ($table->getColumns() as $col) { if (!in_array($col, $autoIncCols, true)) { $script .= " \$copyObj->set" . $col->getPhpName() . "(\$this->get" . $col->getPhpName() . "());"; } } // foreach // Avoid useless code by checking to see if there are any referrers // to this table: if (count($table->getReferrers()) > 0 || count($table->getForeignKeys()) > 0) { $script .= " if (\$deepCopy && !\$this->startCopy) { // important: temporarily setNew(false) because this affects the behavior of // the getter/setter methods for fkey referrer objects. \$copyObj->setNew(false); // store object hash to prevent cycle \$this->startCopy = true; "; foreach ($table->getReferrers() as $fk) { //HL: commenting out self-referential check below // it seems to work as expected and is probably desirable to have those referrers from same table deep-copied. //if ( $fk->getTable()->getName() != $table->getName() ) { if ($fk->isLocalPrimaryKey()) { $afx = $this->getRefFKPhpNameAffix($fk, $plural = false); $script .= " \$relObj = \$this->get$afx(); if (\$relObj) { \$copyObj->set$afx(\$relObj->copy(\$deepCopy)); } "; } else { $script .= " foreach (\$this->get" . $this->getRefFKPhpNameAffix($fk, true) . "() as \$relObj) { if (\$relObj !== \$this) { // ensure that we don't try to copy a reference to ourselves \$copyObj->add" . $this->getRefFKPhpNameAffix($fk) . "(\$relObj->copy(\$deepCopy)); } } "; } // HL: commenting out close of self-referential check // } /* if tblFK != table */ } /* foreach */ // do deep copy for one to one relation foreach ($table->getForeignKeys() as $fk) { if ($fk->isLocalPrimaryKey()) { $afx = $this->getFKPhpNameAffix($fk, $plural = false); $script .= " \$relObj = \$this->get$afx(); if (\$relObj) { \$copyObj->set$afx(\$relObj->copy(\$deepCopy)); } "; } } $script .= " //unflag object copy \$this->startCopy = false; } // if (\$deepCopy) "; } /* if (count referrers > 0 ) */ $script .= " if (\$makeNew) { \$copyObj->setNew(true);"; // Note: we're no longer resetting non-autoincrement primary keys to default values // due to: http://propel.phpdb.org/trac/ticket/618 foreach ($autoIncCols as $col) { $coldefval = $col->getPhpDefaultValue(); $coldefval = var_export($coldefval, true); $script .= " \$copyObj->set" . $col->getPhpName() . "($coldefval); // this is a auto-increment column, so set to default value"; } // foreach $script .= " } } "; }
php
protected function addCopyInto(&$script) { $table = $this->getTable(); $script .= " /** * Sets contents of passed object to values from current object. * * If desired, this method can also make copies of all associated (fkey referrers) * objects. * * @param object \$copyObj An object of " . $this->getObjectClassname() . " (or compatible) type. * @param boolean \$deepCopy Whether to also copy all rows that refer (by fkey) to the current row. * @param boolean \$makeNew Whether to reset autoincrement PKs and make the object new. * @throws PropelException */ public function copyInto(\$copyObj, \$deepCopy = false, \$makeNew = true) {"; $autoIncCols = array(); if ($table->hasCompositePrimaryKey()) { foreach ($table->getColumns() as $col) { /* @var $col Column */ if ($col->isAutoIncrement()) { $autoIncCols[] = $col; } } } else { $autoIncCols = $table->getPrimaryKey(); } foreach ($table->getColumns() as $col) { if (!in_array($col, $autoIncCols, true)) { $script .= " \$copyObj->set" . $col->getPhpName() . "(\$this->get" . $col->getPhpName() . "());"; } } // foreach // Avoid useless code by checking to see if there are any referrers // to this table: if (count($table->getReferrers()) > 0 || count($table->getForeignKeys()) > 0) { $script .= " if (\$deepCopy && !\$this->startCopy) { // important: temporarily setNew(false) because this affects the behavior of // the getter/setter methods for fkey referrer objects. \$copyObj->setNew(false); // store object hash to prevent cycle \$this->startCopy = true; "; foreach ($table->getReferrers() as $fk) { //HL: commenting out self-referential check below // it seems to work as expected and is probably desirable to have those referrers from same table deep-copied. //if ( $fk->getTable()->getName() != $table->getName() ) { if ($fk->isLocalPrimaryKey()) { $afx = $this->getRefFKPhpNameAffix($fk, $plural = false); $script .= " \$relObj = \$this->get$afx(); if (\$relObj) { \$copyObj->set$afx(\$relObj->copy(\$deepCopy)); } "; } else { $script .= " foreach (\$this->get" . $this->getRefFKPhpNameAffix($fk, true) . "() as \$relObj) { if (\$relObj !== \$this) { // ensure that we don't try to copy a reference to ourselves \$copyObj->add" . $this->getRefFKPhpNameAffix($fk) . "(\$relObj->copy(\$deepCopy)); } } "; } // HL: commenting out close of self-referential check // } /* if tblFK != table */ } /* foreach */ // do deep copy for one to one relation foreach ($table->getForeignKeys() as $fk) { if ($fk->isLocalPrimaryKey()) { $afx = $this->getFKPhpNameAffix($fk, $plural = false); $script .= " \$relObj = \$this->get$afx(); if (\$relObj) { \$copyObj->set$afx(\$relObj->copy(\$deepCopy)); } "; } } $script .= " //unflag object copy \$this->startCopy = false; } // if (\$deepCopy) "; } /* if (count referrers > 0 ) */ $script .= " if (\$makeNew) { \$copyObj->setNew(true);"; // Note: we're no longer resetting non-autoincrement primary keys to default values // due to: http://propel.phpdb.org/trac/ticket/618 foreach ($autoIncCols as $col) { $coldefval = $col->getPhpDefaultValue(); $coldefval = var_export($coldefval, true); $script .= " \$copyObj->set" . $col->getPhpName() . "($coldefval); // this is a auto-increment column, so set to default value"; } // foreach $script .= " } } "; }
[ "protected", "function", "addCopyInto", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Sets contents of passed object to values from current object.\n *\n * If desired, this method can also make copies of all associated (fkey referrers)\n * objects.\n *\n * @param object \\$copyObj An object of \"", ".", "$", "this", "->", "getObjectClassname", "(", ")", ".", "\" (or compatible) type.\n * @param boolean \\$deepCopy Whether to also copy all rows that refer (by fkey) to the current row.\n * @param boolean \\$makeNew Whether to reset autoincrement PKs and make the object new.\n * @throws PropelException\n */\n public function copyInto(\\$copyObj, \\$deepCopy = false, \\$makeNew = true)\n {\"", ";", "$", "autoIncCols", "=", "array", "(", ")", ";", "if", "(", "$", "table", "->", "hasCompositePrimaryKey", "(", ")", ")", "{", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "/* @var $col Column */", "if", "(", "$", "col", "->", "isAutoIncrement", "(", ")", ")", "{", "$", "autoIncCols", "[", "]", "=", "$", "col", ";", "}", "}", "}", "else", "{", "$", "autoIncCols", "=", "$", "table", "->", "getPrimaryKey", "(", ")", ";", "}", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "if", "(", "!", "in_array", "(", "$", "col", ",", "$", "autoIncCols", ",", "true", ")", ")", "{", "$", "script", ".=", "\"\n \\$copyObj->set\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"(\\$this->get\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"());\"", ";", "}", "}", "// foreach", "// Avoid useless code by checking to see if there are any referrers", "// to this table:", "if", "(", "count", "(", "$", "table", "->", "getReferrers", "(", ")", ")", ">", "0", "||", "count", "(", "$", "table", "->", "getForeignKeys", "(", ")", ")", ">", "0", ")", "{", "$", "script", ".=", "\"\n\n if (\\$deepCopy && !\\$this->startCopy) {\n // important: temporarily setNew(false) because this affects the behavior of\n // the getter/setter methods for fkey referrer objects.\n \\$copyObj->setNew(false);\n // store object hash to prevent cycle\n \\$this->startCopy = true;\n\"", ";", "foreach", "(", "$", "table", "->", "getReferrers", "(", ")", "as", "$", "fk", ")", "{", "//HL: commenting out self-referential check below", "//\t\tit seems to work as expected and is probably desirable to have those referrers from same table deep-copied.", "//if ( $fk->getTable()->getName() != $table->getName() ) {", "if", "(", "$", "fk", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "afx", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ";", "$", "script", ".=", "\"\n \\$relObj = \\$this->get$afx();\n if (\\$relObj) {\n \\$copyObj->set$afx(\\$relObj->copy(\\$deepCopy));\n }\n\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n foreach (\\$this->get\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "true", ")", ".", "\"() as \\$relObj) {\n if (\\$relObj !== \\$this) { // ensure that we don't try to copy a reference to ourselves\n \\$copyObj->add\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ")", ".", "\"(\\$relObj->copy(\\$deepCopy));\n }\n }\n\"", ";", "}", "// HL: commenting out close of self-referential check", "// } /* if tblFK != table */", "}", "/* foreach */", "// do deep copy for one to one relation", "foreach", "(", "$", "table", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "if", "(", "$", "fk", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "afx", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ";", "$", "script", ".=", "\"\n \\$relObj = \\$this->get$afx();\n if (\\$relObj) {\n \\$copyObj->set$afx(\\$relObj->copy(\\$deepCopy));\n }\n\"", ";", "}", "}", "$", "script", ".=", "\"\n //unflag object copy\n \\$this->startCopy = false;\n } // if (\\$deepCopy)\n\"", ";", "}", "/* if (count referrers > 0 ) */", "$", "script", ".=", "\"\n if (\\$makeNew) {\n \\$copyObj->setNew(true);\"", ";", "// Note: we're no longer resetting non-autoincrement primary keys to default values", "// due to: http://propel.phpdb.org/trac/ticket/618", "foreach", "(", "$", "autoIncCols", "as", "$", "col", ")", "{", "$", "coldefval", "=", "$", "col", "->", "getPhpDefaultValue", "(", ")", ";", "$", "coldefval", "=", "var_export", "(", "$", "coldefval", ",", "true", ")", ";", "$", "script", ".=", "\"\n \\$copyObj->set\"", ".", "$", "col", "->", "getPhpName", "(", ")", ".", "\"($coldefval); // this is a auto-increment column, so set to default value\"", ";", "}", "// foreach", "$", "script", ".=", "\"\n }\n }\n\"", ";", "}" ]
Adds the copyInto() method, which takes an object and sets contents to match current object. In complex OM this method includes the $deepCopy param for making copies of related objects. @param string &$script The script will be modified in this method.
[ "Adds", "the", "copyInto", "()", "method", "which", "takes", "an", "object", "and", "sets", "contents", "to", "match", "current", "object", ".", "In", "complex", "OM", "this", "method", "includes", "the", "$deepCopy", "param", "for", "making", "copies", "of", "related", "objects", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L5596-L5708
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addClear
protected function addClear(&$script) { $table = $this->getTable(); $script .= " /** * Clears the current object and sets all attributes to their default values */ public function clear() {"; foreach ($table->getColumns() as $col) { $clo = strtolower($col->getName()); $script .= " \$this->" . $clo . " = null;"; if ($col->isLazyLoad()) { $script .= " \$this->" . $clo . "_isLoaded = false;"; } if ($col->getType() == PropelTypes::OBJECT || $col->getType() == PropelTypes::PHP_ARRAY) { $cloUnserialized = $clo . '_unserialized'; $script .= " \$this->$cloUnserialized = null;"; } } $script .= " \$this->alreadyInSave = false; \$this->alreadyInValidation = false; \$this->alreadyInClearAllReferencesDeep = false; \$this->clearAllReferences();"; if ($this->hasDefaultValues()) { $script .= " \$this->applyDefaultValues();"; } $script .= " \$this->resetModified(); \$this->setNew(true); \$this->setDeleted(false); } "; }
php
protected function addClear(&$script) { $table = $this->getTable(); $script .= " /** * Clears the current object and sets all attributes to their default values */ public function clear() {"; foreach ($table->getColumns() as $col) { $clo = strtolower($col->getName()); $script .= " \$this->" . $clo . " = null;"; if ($col->isLazyLoad()) { $script .= " \$this->" . $clo . "_isLoaded = false;"; } if ($col->getType() == PropelTypes::OBJECT || $col->getType() == PropelTypes::PHP_ARRAY) { $cloUnserialized = $clo . '_unserialized'; $script .= " \$this->$cloUnserialized = null;"; } } $script .= " \$this->alreadyInSave = false; \$this->alreadyInValidation = false; \$this->alreadyInClearAllReferencesDeep = false; \$this->clearAllReferences();"; if ($this->hasDefaultValues()) { $script .= " \$this->applyDefaultValues();"; } $script .= " \$this->resetModified(); \$this->setNew(true); \$this->setDeleted(false); } "; }
[ "protected", "function", "addClear", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Clears the current object and sets all attributes to their default values\n */\n public function clear()\n {\"", ";", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "clo", ".", "\" = null;\"", ";", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "clo", ".", "\"_isLoaded = false;\"", ";", "}", "if", "(", "$", "col", "->", "getType", "(", ")", "==", "PropelTypes", "::", "OBJECT", "||", "$", "col", "->", "getType", "(", ")", "==", "PropelTypes", "::", "PHP_ARRAY", ")", "{", "$", "cloUnserialized", "=", "$", "clo", ".", "'_unserialized'", ";", "$", "script", ".=", "\"\n \\$this->$cloUnserialized = null;\"", ";", "}", "}", "$", "script", ".=", "\"\n \\$this->alreadyInSave = false;\n \\$this->alreadyInValidation = false;\n \\$this->alreadyInClearAllReferencesDeep = false;\n \\$this->clearAllReferences();\"", ";", "if", "(", "$", "this", "->", "hasDefaultValues", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->applyDefaultValues();\"", ";", "}", "$", "script", ".=", "\"\n \\$this->resetModified();\n \\$this->setNew(true);\n \\$this->setDeleted(false);\n }\n\"", ";", "}" ]
Adds clear method @param string &$script The script will be modified in this method.
[ "Adds", "clear", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L5715-L5757
propelorm/Propel
generator/lib/builder/om/PHP5ObjectBuilder.php
PHP5ObjectBuilder.addClearAllReferences
protected function addClearAllReferences(&$script) { $table = $this->getTable(); $script .= " /** * Resets all references to other model objects or collections of model objects. * * This method is a user-space workaround for PHP's inability to garbage collect * objects with circular references (even in PHP 5.3). This is currently necessary * when using Propel in certain daemon or large-volume/high-memory operations. * * @param boolean \$deep Whether to also clear the references on all referrer objects. */ public function clearAllReferences(\$deep = false) { if (\$deep && !\$this->alreadyInClearAllReferencesDeep) { \$this->alreadyInClearAllReferencesDeep = true;"; $vars = array(); foreach ($this->getTable()->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $varName = $this->getPKRefFKVarName($refFK); $script .= " if (\$this->$varName) { \$this->{$varName}->clearAllReferences(\$deep); }"; } else { $varName = $this->getRefFKCollVarName($refFK); $script .= " if (\$this->$varName) { foreach (\$this->$varName as \$o) { \$o->clearAllReferences(\$deep); } }"; } $vars[] = $varName; } foreach ($this->getTable()->getCrossFks() as $fkList) { list($refFK, $crossFK) = $fkList; $varName = $this->getCrossFKVarName($crossFK); $script .= " if (\$this->$varName) { foreach (\$this->$varName as \$o) { \$o->clearAllReferences(\$deep); } }"; $vars[] = $varName; } foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " if (\$this->$varName instanceof Persistent) { \$this->{$varName}->clearAllReferences(\$deep); }"; } $script .= " \$this->alreadyInClearAllReferencesDeep = false; } // if (\$deep) "; $this->applyBehaviorModifier('objectClearReferences', $script, " "); foreach ($vars as $varName) { $script .= " if (\$this->$varName instanceof PropelCollection) { \$this->{$varName}->clearIterator(); } \$this->$varName = null;"; } foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " \$this->$varName = null;"; } $script .= " } "; }
php
protected function addClearAllReferences(&$script) { $table = $this->getTable(); $script .= " /** * Resets all references to other model objects or collections of model objects. * * This method is a user-space workaround for PHP's inability to garbage collect * objects with circular references (even in PHP 5.3). This is currently necessary * when using Propel in certain daemon or large-volume/high-memory operations. * * @param boolean \$deep Whether to also clear the references on all referrer objects. */ public function clearAllReferences(\$deep = false) { if (\$deep && !\$this->alreadyInClearAllReferencesDeep) { \$this->alreadyInClearAllReferencesDeep = true;"; $vars = array(); foreach ($this->getTable()->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $varName = $this->getPKRefFKVarName($refFK); $script .= " if (\$this->$varName) { \$this->{$varName}->clearAllReferences(\$deep); }"; } else { $varName = $this->getRefFKCollVarName($refFK); $script .= " if (\$this->$varName) { foreach (\$this->$varName as \$o) { \$o->clearAllReferences(\$deep); } }"; } $vars[] = $varName; } foreach ($this->getTable()->getCrossFks() as $fkList) { list($refFK, $crossFK) = $fkList; $varName = $this->getCrossFKVarName($crossFK); $script .= " if (\$this->$varName) { foreach (\$this->$varName as \$o) { \$o->clearAllReferences(\$deep); } }"; $vars[] = $varName; } foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " if (\$this->$varName instanceof Persistent) { \$this->{$varName}->clearAllReferences(\$deep); }"; } $script .= " \$this->alreadyInClearAllReferencesDeep = false; } // if (\$deep) "; $this->applyBehaviorModifier('objectClearReferences', $script, " "); foreach ($vars as $varName) { $script .= " if (\$this->$varName instanceof PropelCollection) { \$this->{$varName}->clearIterator(); } \$this->$varName = null;"; } foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " \$this->$varName = null;"; } $script .= " } "; }
[ "protected", "function", "addClearAllReferences", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Resets all references to other model objects or collections of model objects.\n *\n * This method is a user-space workaround for PHP's inability to garbage collect\n * objects with circular references (even in PHP 5.3). This is currently necessary\n * when using Propel in certain daemon or large-volume/high-memory operations.\n *\n * @param boolean \\$deep Whether to also clear the references on all referrer objects.\n */\n public function clearAllReferences(\\$deep = false)\n {\n if (\\$deep && !\\$this->alreadyInClearAllReferencesDeep) {\n \\$this->alreadyInClearAllReferencesDeep = true;\"", ";", "$", "vars", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getReferrers", "(", ")", "as", "$", "refFK", ")", "{", "if", "(", "$", "refFK", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "varName", "=", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n if (\\$this->$varName) {\n \\$this->{$varName}->clearAllReferences(\\$deep);\n }\"", ";", "}", "else", "{", "$", "varName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n if (\\$this->$varName) {\n foreach (\\$this->$varName as \\$o) {\n \\$o->clearAllReferences(\\$deep);\n }\n }\"", ";", "}", "$", "vars", "[", "]", "=", "$", "varName", ";", "}", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getCrossFks", "(", ")", "as", "$", "fkList", ")", "{", "list", "(", "$", "refFK", ",", "$", "crossFK", ")", "=", "$", "fkList", ";", "$", "varName", "=", "$", "this", "->", "getCrossFKVarName", "(", "$", "crossFK", ")", ";", "$", "script", ".=", "\"\n if (\\$this->$varName) {\n foreach (\\$this->$varName as \\$o) {\n \\$o->clearAllReferences(\\$deep);\n }\n }\"", ";", "$", "vars", "[", "]", "=", "$", "varName", ";", "}", "foreach", "(", "$", "table", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "varName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n if (\\$this->$varName instanceof Persistent) {\n \\$this->{$varName}->clearAllReferences(\\$deep);\n }\"", ";", "}", "$", "script", ".=", "\"\n\n \\$this->alreadyInClearAllReferencesDeep = false;\n } // if (\\$deep)\n\"", ";", "$", "this", "->", "applyBehaviorModifier", "(", "'objectClearReferences'", ",", "$", "script", ",", "\"\t\t\"", ")", ";", "foreach", "(", "$", "vars", "as", "$", "varName", ")", "{", "$", "script", ".=", "\"\n if (\\$this->$varName instanceof PropelCollection) {\n \\$this->{$varName}->clearIterator();\n }\n \\$this->$varName = null;\"", ";", "}", "foreach", "(", "$", "table", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "varName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n \\$this->$varName = null;\"", ";", "}", "$", "script", ".=", "\"\n }\n\"", ";", "}" ]
Adds clearAllReferencers() method which resets all the collections of referencing fk objects. @param string &$script The script will be modified in this method.
[ "Adds", "clearAllReferencers", "()", "method", "which", "resets", "all", "the", "collections", "of", "referencing", "fk", "objects", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectBuilder.php#L5766-L5846
propelorm/Propel
generator/lib/reverse/mysql/MysqlSchemaParser.php
MysqlSchemaParser.getColumnFromRow
public function getColumnFromRow($row, Table $table) { $name = $row['Field']; $is_nullable = ($row['Null'] == 'YES'); $autoincrement = (strpos($row['Extra'], 'auto_increment') !== false); $size = null; $precision = null; $scale = null; $sqlType = false; $desc = $row['Comment']; $regexp = '/^ (\w+) # column type [1] [\(] # ( ?([\d,]*) # size or size, precision [2] [\)] # ) ?\s* # whitespace (\w*) # extra description (UNSIGNED, CHARACTER SET, ...) [3] $/x'; if (preg_match($regexp, $row['Type'], $matches)) { $nativeType = $matches[1]; if ($matches[2]) { if (($cpos = strpos($matches[2], ',')) !== false) { $size = (int) substr($matches[2], 0, $cpos); $precision = $size; $scale = (int) substr($matches[2], $cpos + 1); } else { $size = (int) $matches[2]; } } if ($matches[3]) { $sqlType = $row['Type']; } foreach (self::$defaultTypeSizes as $type => $defaultSize) { if ($nativeType == $type && $size == $defaultSize && $scale === null) { $size = null; continue; } } } elseif (preg_match('/^(\w+)\(/', $row['Type'], $matches)) { $nativeType = $matches[1]; if ($nativeType == 'enum') { $sqlType = $row['Type']; } } else { $nativeType = $row['Type']; } //BLOBs can't have any default values in MySQL $default = preg_match('~blob|text~', $nativeType) ? null : $row['Default']; $propelType = $this->getMappedPropelType($nativeType); if (!$propelType) { $propelType = Column::DEFAULT_TYPE; $sqlType = $row['Type']; $this->warn("Column [" . $table->getName() . "." . $name . "] has a column type (" . $nativeType . ") that Propel does not support."); } // Special case for TINYINT(1) which is a BOOLEAN if (PropelTypes::TINYINT === $propelType && 1 === $size) { $propelType = PropelTypes::BOOLEAN; } $column = new Column($name); $column->setTable($table); $column->setDomainForType($propelType); if ($sqlType) { $column->getDomain()->replaceSqlType($sqlType); } $column->getDomain()->replaceSize($size); $column->getDomain()->replaceScale($scale); if ($default !== null) { if ($propelType == PropelTypes::BOOLEAN) { if ($default == '1') { $default = 'true'; } if ($default == '0') { $default = 'false'; } } if (in_array($default, array('CURRENT_TIMESTAMP'))) { $type = ColumnDefaultValue::TYPE_EXPR; } else { $type = ColumnDefaultValue::TYPE_VALUE; } $column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, $type)); } $column->setAutoIncrement($autoincrement); $column->setNotNull(!$is_nullable); if ($this->addVendorInfo) { $vi = $this->getNewVendorInfoObject($row); $column->addVendorInfo($vi); } if ($desc){ if(!$this->isUtf8($desc)) $desc = utf8_encode($desc); $column->setDescription($desc); } return $column; }
php
public function getColumnFromRow($row, Table $table) { $name = $row['Field']; $is_nullable = ($row['Null'] == 'YES'); $autoincrement = (strpos($row['Extra'], 'auto_increment') !== false); $size = null; $precision = null; $scale = null; $sqlType = false; $desc = $row['Comment']; $regexp = '/^ (\w+) # column type [1] [\(] # ( ?([\d,]*) # size or size, precision [2] [\)] # ) ?\s* # whitespace (\w*) # extra description (UNSIGNED, CHARACTER SET, ...) [3] $/x'; if (preg_match($regexp, $row['Type'], $matches)) { $nativeType = $matches[1]; if ($matches[2]) { if (($cpos = strpos($matches[2], ',')) !== false) { $size = (int) substr($matches[2], 0, $cpos); $precision = $size; $scale = (int) substr($matches[2], $cpos + 1); } else { $size = (int) $matches[2]; } } if ($matches[3]) { $sqlType = $row['Type']; } foreach (self::$defaultTypeSizes as $type => $defaultSize) { if ($nativeType == $type && $size == $defaultSize && $scale === null) { $size = null; continue; } } } elseif (preg_match('/^(\w+)\(/', $row['Type'], $matches)) { $nativeType = $matches[1]; if ($nativeType == 'enum') { $sqlType = $row['Type']; } } else { $nativeType = $row['Type']; } //BLOBs can't have any default values in MySQL $default = preg_match('~blob|text~', $nativeType) ? null : $row['Default']; $propelType = $this->getMappedPropelType($nativeType); if (!$propelType) { $propelType = Column::DEFAULT_TYPE; $sqlType = $row['Type']; $this->warn("Column [" . $table->getName() . "." . $name . "] has a column type (" . $nativeType . ") that Propel does not support."); } // Special case for TINYINT(1) which is a BOOLEAN if (PropelTypes::TINYINT === $propelType && 1 === $size) { $propelType = PropelTypes::BOOLEAN; } $column = new Column($name); $column->setTable($table); $column->setDomainForType($propelType); if ($sqlType) { $column->getDomain()->replaceSqlType($sqlType); } $column->getDomain()->replaceSize($size); $column->getDomain()->replaceScale($scale); if ($default !== null) { if ($propelType == PropelTypes::BOOLEAN) { if ($default == '1') { $default = 'true'; } if ($default == '0') { $default = 'false'; } } if (in_array($default, array('CURRENT_TIMESTAMP'))) { $type = ColumnDefaultValue::TYPE_EXPR; } else { $type = ColumnDefaultValue::TYPE_VALUE; } $column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, $type)); } $column->setAutoIncrement($autoincrement); $column->setNotNull(!$is_nullable); if ($this->addVendorInfo) { $vi = $this->getNewVendorInfoObject($row); $column->addVendorInfo($vi); } if ($desc){ if(!$this->isUtf8($desc)) $desc = utf8_encode($desc); $column->setDescription($desc); } return $column; }
[ "public", "function", "getColumnFromRow", "(", "$", "row", ",", "Table", "$", "table", ")", "{", "$", "name", "=", "$", "row", "[", "'Field'", "]", ";", "$", "is_nullable", "=", "(", "$", "row", "[", "'Null'", "]", "==", "'YES'", ")", ";", "$", "autoincrement", "=", "(", "strpos", "(", "$", "row", "[", "'Extra'", "]", ",", "'auto_increment'", ")", "!==", "false", ")", ";", "$", "size", "=", "null", ";", "$", "precision", "=", "null", ";", "$", "scale", "=", "null", ";", "$", "sqlType", "=", "false", ";", "$", "desc", "=", "$", "row", "[", "'Comment'", "]", ";", "$", "regexp", "=", "'/^\n (\\w+) # column type [1]\n [\\(] # (\n ?([\\d,]*) # size or size, precision [2]\n [\\)] # )\n ?\\s* # whitespace\n (\\w*) # extra description (UNSIGNED, CHARACTER SET, ...) [3]\n $/x'", ";", "if", "(", "preg_match", "(", "$", "regexp", ",", "$", "row", "[", "'Type'", "]", ",", "$", "matches", ")", ")", "{", "$", "nativeType", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "$", "matches", "[", "2", "]", ")", "{", "if", "(", "(", "$", "cpos", "=", "strpos", "(", "$", "matches", "[", "2", "]", ",", "','", ")", ")", "!==", "false", ")", "{", "$", "size", "=", "(", "int", ")", "substr", "(", "$", "matches", "[", "2", "]", ",", "0", ",", "$", "cpos", ")", ";", "$", "precision", "=", "$", "size", ";", "$", "scale", "=", "(", "int", ")", "substr", "(", "$", "matches", "[", "2", "]", ",", "$", "cpos", "+", "1", ")", ";", "}", "else", "{", "$", "size", "=", "(", "int", ")", "$", "matches", "[", "2", "]", ";", "}", "}", "if", "(", "$", "matches", "[", "3", "]", ")", "{", "$", "sqlType", "=", "$", "row", "[", "'Type'", "]", ";", "}", "foreach", "(", "self", "::", "$", "defaultTypeSizes", "as", "$", "type", "=>", "$", "defaultSize", ")", "{", "if", "(", "$", "nativeType", "==", "$", "type", "&&", "$", "size", "==", "$", "defaultSize", "&&", "$", "scale", "===", "null", ")", "{", "$", "size", "=", "null", ";", "continue", ";", "}", "}", "}", "elseif", "(", "preg_match", "(", "'/^(\\w+)\\(/'", ",", "$", "row", "[", "'Type'", "]", ",", "$", "matches", ")", ")", "{", "$", "nativeType", "=", "$", "matches", "[", "1", "]", ";", "if", "(", "$", "nativeType", "==", "'enum'", ")", "{", "$", "sqlType", "=", "$", "row", "[", "'Type'", "]", ";", "}", "}", "else", "{", "$", "nativeType", "=", "$", "row", "[", "'Type'", "]", ";", "}", "//BLOBs can't have any default values in MySQL", "$", "default", "=", "preg_match", "(", "'~blob|text~'", ",", "$", "nativeType", ")", "?", "null", ":", "$", "row", "[", "'Default'", "]", ";", "$", "propelType", "=", "$", "this", "->", "getMappedPropelType", "(", "$", "nativeType", ")", ";", "if", "(", "!", "$", "propelType", ")", "{", "$", "propelType", "=", "Column", "::", "DEFAULT_TYPE", ";", "$", "sqlType", "=", "$", "row", "[", "'Type'", "]", ";", "$", "this", "->", "warn", "(", "\"Column [\"", ".", "$", "table", "->", "getName", "(", ")", ".", "\".\"", ".", "$", "name", ".", "\"] has a column type (\"", ".", "$", "nativeType", ".", "\") that Propel does not support.\"", ")", ";", "}", "// Special case for TINYINT(1) which is a BOOLEAN", "if", "(", "PropelTypes", "::", "TINYINT", "===", "$", "propelType", "&&", "1", "===", "$", "size", ")", "{", "$", "propelType", "=", "PropelTypes", "::", "BOOLEAN", ";", "}", "$", "column", "=", "new", "Column", "(", "$", "name", ")", ";", "$", "column", "->", "setTable", "(", "$", "table", ")", ";", "$", "column", "->", "setDomainForType", "(", "$", "propelType", ")", ";", "if", "(", "$", "sqlType", ")", "{", "$", "column", "->", "getDomain", "(", ")", "->", "replaceSqlType", "(", "$", "sqlType", ")", ";", "}", "$", "column", "->", "getDomain", "(", ")", "->", "replaceSize", "(", "$", "size", ")", ";", "$", "column", "->", "getDomain", "(", ")", "->", "replaceScale", "(", "$", "scale", ")", ";", "if", "(", "$", "default", "!==", "null", ")", "{", "if", "(", "$", "propelType", "==", "PropelTypes", "::", "BOOLEAN", ")", "{", "if", "(", "$", "default", "==", "'1'", ")", "{", "$", "default", "=", "'true'", ";", "}", "if", "(", "$", "default", "==", "'0'", ")", "{", "$", "default", "=", "'false'", ";", "}", "}", "if", "(", "in_array", "(", "$", "default", ",", "array", "(", "'CURRENT_TIMESTAMP'", ")", ")", ")", "{", "$", "type", "=", "ColumnDefaultValue", "::", "TYPE_EXPR", ";", "}", "else", "{", "$", "type", "=", "ColumnDefaultValue", "::", "TYPE_VALUE", ";", "}", "$", "column", "->", "getDomain", "(", ")", "->", "setDefaultValue", "(", "new", "ColumnDefaultValue", "(", "$", "default", ",", "$", "type", ")", ")", ";", "}", "$", "column", "->", "setAutoIncrement", "(", "$", "autoincrement", ")", ";", "$", "column", "->", "setNotNull", "(", "!", "$", "is_nullable", ")", ";", "if", "(", "$", "this", "->", "addVendorInfo", ")", "{", "$", "vi", "=", "$", "this", "->", "getNewVendorInfoObject", "(", "$", "row", ")", ";", "$", "column", "->", "addVendorInfo", "(", "$", "vi", ")", ";", "}", "if", "(", "$", "desc", ")", "{", "if", "(", "!", "$", "this", "->", "isUtf8", "(", "$", "desc", ")", ")", "$", "desc", "=", "utf8_encode", "(", "$", "desc", ")", ";", "$", "column", "->", "setDescription", "(", "$", "desc", ")", ";", "}", "return", "$", "column", ";", "}" ]
Factory method creating a Column object based on a row from the 'show columns from ' MySQL query result. @param array $row An associative array with the following keys: Field, Type, Null, Key, Default, Extra. @return Column
[ "Factory", "method", "creating", "a", "Column", "object", "based", "on", "a", "row", "from", "the", "show", "columns", "from", "MySQL", "query", "result", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/reverse/mysql/MysqlSchemaParser.php#L173-L275
propelorm/Propel
generator/lib/reverse/mysql/MysqlSchemaParser.php
MysqlSchemaParser.addPrimaryKey
protected function addPrimaryKey(Table $table) { $stmt = $this->dbh->query("SHOW KEYS FROM `" . $table->getName() . "`"); // Loop through the returned results, grouping the same key_name together // adding each column for that key. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Skip any non-primary keys. if ($row['Key_name'] !== 'PRIMARY') { continue; } $name = $row["Column_name"]; $table->getColumn($name)->setPrimaryKey(true); } }
php
protected function addPrimaryKey(Table $table) { $stmt = $this->dbh->query("SHOW KEYS FROM `" . $table->getName() . "`"); // Loop through the returned results, grouping the same key_name together // adding each column for that key. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Skip any non-primary keys. if ($row['Key_name'] !== 'PRIMARY') { continue; } $name = $row["Column_name"]; $table->getColumn($name)->setPrimaryKey(true); } }
[ "protected", "function", "addPrimaryKey", "(", "Table", "$", "table", ")", "{", "$", "stmt", "=", "$", "this", "->", "dbh", "->", "query", "(", "\"SHOW KEYS FROM `\"", ".", "$", "table", "->", "getName", "(", ")", ".", "\"`\"", ")", ";", "// Loop through the returned results, grouping the same key_name together", "// adding each column for that key.", "while", "(", "$", "row", "=", "$", "stmt", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ")", "{", "// Skip any non-primary keys.", "if", "(", "$", "row", "[", "'Key_name'", "]", "!==", "'PRIMARY'", ")", "{", "continue", ";", "}", "$", "name", "=", "$", "row", "[", "\"Column_name\"", "]", ";", "$", "table", "->", "getColumn", "(", "$", "name", ")", "->", "setPrimaryKey", "(", "true", ")", ";", "}", "}" ]
Loads the primary key for this table.
[ "Loads", "the", "primary", "key", "for", "this", "table", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/reverse/mysql/MysqlSchemaParser.php#L416-L430
propelorm/Propel
generator/lib/config/QuickGeneratorConfig.php
QuickGeneratorConfig.parsePseudoIniFile
protected function parsePseudoIniFile($filepath) { $properties = array(); if (($lines = @file($filepath)) === false) { throw new Exception("Unable to parse contents of $filepath"); } foreach ($lines as $line) { $line = trim($line); if ($line == "" || $line{0} == '#' || $line{0} == ';') { continue; } $pos = strpos($line, '='); $property = trim(substr($line, 0, $pos)); $value = trim(substr($line, $pos + 1)); if ($value === "true") { $value = true; } elseif ($value === "false") { $value = false; } $properties[$property] = $value; } return $properties; }
php
protected function parsePseudoIniFile($filepath) { $properties = array(); if (($lines = @file($filepath)) === false) { throw new Exception("Unable to parse contents of $filepath"); } foreach ($lines as $line) { $line = trim($line); if ($line == "" || $line{0} == '#' || $line{0} == ';') { continue; } $pos = strpos($line, '='); $property = trim(substr($line, 0, $pos)); $value = trim(substr($line, $pos + 1)); if ($value === "true") { $value = true; } elseif ($value === "false") { $value = false; } $properties[$property] = $value; } return $properties; }
[ "protected", "function", "parsePseudoIniFile", "(", "$", "filepath", ")", "{", "$", "properties", "=", "array", "(", ")", ";", "if", "(", "(", "$", "lines", "=", "@", "file", "(", "$", "filepath", ")", ")", "===", "false", ")", "{", "throw", "new", "Exception", "(", "\"Unable to parse contents of $filepath\"", ")", ";", "}", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "$", "line", ")", ";", "if", "(", "$", "line", "==", "\"\"", "||", "$", "line", "{", "0", "}", "==", "'#'", "||", "$", "line", "{", "0", "}", "==", "';'", ")", "{", "continue", ";", "}", "$", "pos", "=", "strpos", "(", "$", "line", ",", "'='", ")", ";", "$", "property", "=", "trim", "(", "substr", "(", "$", "line", ",", "0", ",", "$", "pos", ")", ")", ";", "$", "value", "=", "trim", "(", "substr", "(", "$", "line", ",", "$", "pos", "+", "1", ")", ")", ";", "if", "(", "$", "value", "===", "\"true\"", ")", "{", "$", "value", "=", "true", ";", "}", "elseif", "(", "$", "value", "===", "\"false\"", ")", "{", "$", "value", "=", "false", ";", "}", "$", "properties", "[", "$", "property", "]", "=", "$", "value", ";", "}", "return", "$", "properties", ";", "}" ]
Why would Phing use ini while it so fun to invent a new format? (sic) parse_ini_file() doesn't work for Phing property files
[ "Why", "would", "Phing", "use", "ini", "while", "it", "so", "fun", "to", "invent", "a", "new", "format?", "(", "sic", ")", "parse_ini_file", "()", "doesn", "t", "work", "for", "Phing", "property", "files" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/config/QuickGeneratorConfig.php#L57-L80
propelorm/Propel
generator/lib/config/QuickGeneratorConfig.php
QuickGeneratorConfig.getConfiguredBuilder
public function getConfiguredBuilder(Table $table, $type) { $class = $this->builders[$type]; require_once dirname(__FILE__) . '/../builder/om/' . $class . '.php'; $builder = new $class($table); $builder->setGeneratorConfig($this); return $builder; }
php
public function getConfiguredBuilder(Table $table, $type) { $class = $this->builders[$type]; require_once dirname(__FILE__) . '/../builder/om/' . $class . '.php'; $builder = new $class($table); $builder->setGeneratorConfig($this); return $builder; }
[ "public", "function", "getConfiguredBuilder", "(", "Table", "$", "table", ",", "$", "type", ")", "{", "$", "class", "=", "$", "this", "->", "builders", "[", "$", "type", "]", ";", "require_once", "dirname", "(", "__FILE__", ")", ".", "'/../builder/om/'", ".", "$", "class", ".", "'.php'", ";", "$", "builder", "=", "new", "$", "class", "(", "$", "table", ")", ";", "$", "builder", "->", "setGeneratorConfig", "(", "$", "this", ")", ";", "return", "$", "builder", ";", "}" ]
Gets a configured data model builder class for specified table and based on type. @param Table $table @param string $type The type of builder ('ddl', 'sql', etc.) @return DataModelBuilder
[ "Gets", "a", "configured", "data", "model", "builder", "class", "for", "specified", "table", "and", "based", "on", "type", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/config/QuickGeneratorConfig.php#L90-L98
propelorm/Propel
generator/lib/config/QuickGeneratorConfig.php
QuickGeneratorConfig.getConfiguredPlatform
public function getConfiguredPlatform(PDO $con = null, $database = null) { if (null === $this->configuredPlatform) { return new SqlitePlatform($con); } $this->configuredPlatform->setConnection($con); return $this->configuredPlatform; }
php
public function getConfiguredPlatform(PDO $con = null, $database = null) { if (null === $this->configuredPlatform) { return new SqlitePlatform($con); } $this->configuredPlatform->setConnection($con); return $this->configuredPlatform; }
[ "public", "function", "getConfiguredPlatform", "(", "PDO", "$", "con", "=", "null", ",", "$", "database", "=", "null", ")", "{", "if", "(", "null", "===", "$", "this", "->", "configuredPlatform", ")", "{", "return", "new", "SqlitePlatform", "(", "$", "con", ")", ";", "}", "$", "this", "->", "configuredPlatform", "->", "setConnection", "(", "$", "con", ")", ";", "return", "$", "this", "->", "configuredPlatform", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/config/QuickGeneratorConfig.php#L164-L173
propelorm/Propel
generator/lib/model/diff/PropelDatabaseComparator.php
PropelDatabaseComparator.computeDiff
public static function computeDiff(Database $fromDatabase, Database $toDatabase, $caseInsensitive = false) { $dc = new self(); $dc->setFromDatabase($fromDatabase); $dc->setToDatabase($toDatabase); $differences = 0; $differences += $dc->compareTables($caseInsensitive); return ($differences > 0) ? $dc->getDatabaseDiff() : false; }
php
public static function computeDiff(Database $fromDatabase, Database $toDatabase, $caseInsensitive = false) { $dc = new self(); $dc->setFromDatabase($fromDatabase); $dc->setToDatabase($toDatabase); $differences = 0; $differences += $dc->compareTables($caseInsensitive); return ($differences > 0) ? $dc->getDatabaseDiff() : false; }
[ "public", "static", "function", "computeDiff", "(", "Database", "$", "fromDatabase", ",", "Database", "$", "toDatabase", ",", "$", "caseInsensitive", "=", "false", ")", "{", "$", "dc", "=", "new", "self", "(", ")", ";", "$", "dc", "->", "setFromDatabase", "(", "$", "fromDatabase", ")", ";", "$", "dc", "->", "setToDatabase", "(", "$", "toDatabase", ")", ";", "$", "differences", "=", "0", ";", "$", "differences", "+=", "$", "dc", "->", "compareTables", "(", "$", "caseInsensitive", ")", ";", "return", "(", "$", "differences", ">", "0", ")", "?", "$", "dc", "->", "getDatabaseDiff", "(", ")", ":", "false", ";", "}" ]
Compute and return the difference between two database objects @param Database $fromDatabase @param Database $toDatabase @param boolean $caseInsensitive Whether the comparison is case insensitive. False by default. @return PropelDatabaseDiff|boolean return false if the two databases are similar
[ "Compute", "and", "return", "the", "difference", "between", "two", "database", "objects" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/diff/PropelDatabaseComparator.php#L88-L97
propelorm/Propel
generator/lib/util/PropelQuickBuilder.php
PropelQuickBuilder.getPlatform
public function getPlatform() { if (null === $this->platform) { require_once dirname(__FILE__) . '/../platform/SqlitePlatform.php'; $this->platform = new SqlitePlatform(); } return $this->platform; }
php
public function getPlatform() { if (null === $this->platform) { require_once dirname(__FILE__) . '/../platform/SqlitePlatform.php'; $this->platform = new SqlitePlatform(); } return $this->platform; }
[ "public", "function", "getPlatform", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "platform", ")", "{", "require_once", "dirname", "(", "__FILE__", ")", ".", "'/../platform/SqlitePlatform.php'", ";", "$", "this", "->", "platform", "=", "new", "SqlitePlatform", "(", ")", ";", "}", "return", "$", "this", "->", "platform", ";", "}" ]
Getter for the platform property @return PropelPlatformInterface
[ "Getter", "for", "the", "platform", "property" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/util/PropelQuickBuilder.php#L45-L53
propelorm/Propel
generator/lib/util/PropelQuickBuilder.php
PropelQuickBuilder.getConfig
public function getConfig() { if (null === $this->config) { require_once dirname(__FILE__) . '/../config/QuickGeneratorConfig.php'; $this->config = new QuickGeneratorConfig($this->getPlatform()); } return $this->config; }
php
public function getConfig() { if (null === $this->config) { require_once dirname(__FILE__) . '/../config/QuickGeneratorConfig.php'; $this->config = new QuickGeneratorConfig($this->getPlatform()); } return $this->config; }
[ "public", "function", "getConfig", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "config", ")", "{", "require_once", "dirname", "(", "__FILE__", ")", ".", "'/../config/QuickGeneratorConfig.php'", ";", "$", "this", "->", "config", "=", "new", "QuickGeneratorConfig", "(", "$", "this", "->", "getPlatform", "(", ")", ")", ";", "}", "return", "$", "this", "->", "config", ";", "}" ]
Getter for the config property @return GeneratorConfigInterface
[ "Getter", "for", "the", "config", "property" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/util/PropelQuickBuilder.php#L70-L78
propelorm/Propel
generator/lib/model/Behavior.php
Behavior.addParameter
public function addParameter($attribute) { $attribute = array_change_key_case($attribute, CASE_LOWER); $this->parameters[$attribute['name']] = $attribute['value']; }
php
public function addParameter($attribute) { $attribute = array_change_key_case($attribute, CASE_LOWER); $this->parameters[$attribute['name']] = $attribute['value']; }
[ "public", "function", "addParameter", "(", "$", "attribute", ")", "{", "$", "attribute", "=", "array_change_key_case", "(", "$", "attribute", ",", "CASE_LOWER", ")", ";", "$", "this", "->", "parameters", "[", "$", "attribute", "[", "'name'", "]", "]", "=", "$", "attribute", "[", "'value'", "]", ";", "}" ]
Add a parameter Expects an associative array looking like array('name' => 'foo', 'value' => bar) @param array $attribute
[ "Add", "a", "parameter", "Expects", "an", "associative", "array", "looking", "like", "array", "(", "name", "=", ">", "foo", "value", "=", ">", "bar", ")" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/Behavior.php#L99-L103
propelorm/Propel
generator/lib/model/Behavior.php
Behavior.getDirname
protected function getDirname() { if (null === $this->dirname) { $r = new ReflectionObject($this); $this->dirname = dirname($r->getFileName()); } return $this->dirname; }
php
protected function getDirname() { if (null === $this->dirname) { $r = new ReflectionObject($this); $this->dirname = dirname($r->getFileName()); } return $this->dirname; }
[ "protected", "function", "getDirname", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "dirname", ")", "{", "$", "r", "=", "new", "ReflectionObject", "(", "$", "this", ")", ";", "$", "this", "->", "dirname", "=", "dirname", "(", "$", "r", "->", "getFileName", "(", ")", ")", ";", "}", "return", "$", "this", "->", "dirname", ";", "}" ]
Returns the current dirname of this behavior (also works for descendants) @return string The absolute directory name
[ "Returns", "the", "current", "dirname", "of", "this", "behavior", "(", "also", "works", "for", "descendants", ")" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/Behavior.php#L229-L237
propelorm/Propel
generator/lib/util/PropelSqlManager.php
PropelSqlManager.buildSql
public function buildSql() { $sqlDbMapContent = "# Sqlfile -> Database map\n"; foreach ($this->getDatabases() as $datasource => $database) { $platform = $database->getPlatform(); $filename = $database->getName() . '.sql'; if ($this->getGeneratorConfig()->getBuildProperty('disableIdentifierQuoting')) { $platform->setIdentifierQuoting(false); } $ddl = $platform->getAddTablesDDL($database); $file = $this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $filename; if (file_exists($file) && $ddl == file_get_contents($file)) { // Unchanged } else { file_put_contents($file, $ddl); } $sqlDbMapContent .= sprintf("%s=%s\n", $filename, $datasource); } file_put_contents($this->getSqlDbMapFilename(), $sqlDbMapContent); }
php
public function buildSql() { $sqlDbMapContent = "# Sqlfile -> Database map\n"; foreach ($this->getDatabases() as $datasource => $database) { $platform = $database->getPlatform(); $filename = $database->getName() . '.sql'; if ($this->getGeneratorConfig()->getBuildProperty('disableIdentifierQuoting')) { $platform->setIdentifierQuoting(false); } $ddl = $platform->getAddTablesDDL($database); $file = $this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $filename; if (file_exists($file) && $ddl == file_get_contents($file)) { // Unchanged } else { file_put_contents($file, $ddl); } $sqlDbMapContent .= sprintf("%s=%s\n", $filename, $datasource); } file_put_contents($this->getSqlDbMapFilename(), $sqlDbMapContent); }
[ "public", "function", "buildSql", "(", ")", "{", "$", "sqlDbMapContent", "=", "\"# Sqlfile -> Database map\\n\"", ";", "foreach", "(", "$", "this", "->", "getDatabases", "(", ")", "as", "$", "datasource", "=>", "$", "database", ")", "{", "$", "platform", "=", "$", "database", "->", "getPlatform", "(", ")", ";", "$", "filename", "=", "$", "database", "->", "getName", "(", ")", ".", "'.sql'", ";", "if", "(", "$", "this", "->", "getGeneratorConfig", "(", ")", "->", "getBuildProperty", "(", "'disableIdentifierQuoting'", ")", ")", "{", "$", "platform", "->", "setIdentifierQuoting", "(", "false", ")", ";", "}", "$", "ddl", "=", "$", "platform", "->", "getAddTablesDDL", "(", "$", "database", ")", ";", "$", "file", "=", "$", "this", "->", "getWorkingDirectory", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "filename", ";", "if", "(", "file_exists", "(", "$", "file", ")", "&&", "$", "ddl", "==", "file_get_contents", "(", "$", "file", ")", ")", "{", "// Unchanged", "}", "else", "{", "file_put_contents", "(", "$", "file", ",", "$", "ddl", ")", ";", "}", "$", "sqlDbMapContent", ".=", "sprintf", "(", "\"%s=%s\\n\"", ",", "$", "filename", ",", "$", "datasource", ")", ";", "}", "file_put_contents", "(", "$", "this", "->", "getSqlDbMapFilename", "(", ")", ",", "$", "sqlDbMapContent", ")", ";", "}" ]
Build SQL files.
[ "Build", "SQL", "files", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/util/PropelSqlManager.php#L165-L189
propelorm/Propel
generator/lib/util/PropelSqlManager.php
PropelSqlManager.insertSql
public function insertSql($datasource = null) { $statementsToInsert = array(); foreach ($this->getProperties($this->getSqlDbMapFilename()) as $sqlFile => $database) { if (null !== $datasource && $database !== $datasource) { // skip continue; } if (!isset($statementsToInsert[$database])) { $statementsToInsert[$database] = array(); } if (null === $database || (null !== $database && $database === $datasource)) { $filename = $this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $sqlFile; if (file_exists($filename)) { foreach (PropelSQLParser::parseFile($filename) as $sql) { $statementsToInsert[$database][] = $sql; } } } } foreach ($statementsToInsert as $database => $sqls) { if (!$this->hasConnection($database)) { continue; } $pdo = $this->getPdoConnection($database); $pdo->beginTransaction(); try { foreach ($sqls as $sql) { $stmt = $pdo->prepare($sql); $stmt->execute(); } $pdo->commit(); } catch (PDOException $e) { $pdo->rollback(); throw $e; } } return true; }
php
public function insertSql($datasource = null) { $statementsToInsert = array(); foreach ($this->getProperties($this->getSqlDbMapFilename()) as $sqlFile => $database) { if (null !== $datasource && $database !== $datasource) { // skip continue; } if (!isset($statementsToInsert[$database])) { $statementsToInsert[$database] = array(); } if (null === $database || (null !== $database && $database === $datasource)) { $filename = $this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $sqlFile; if (file_exists($filename)) { foreach (PropelSQLParser::parseFile($filename) as $sql) { $statementsToInsert[$database][] = $sql; } } } } foreach ($statementsToInsert as $database => $sqls) { if (!$this->hasConnection($database)) { continue; } $pdo = $this->getPdoConnection($database); $pdo->beginTransaction(); try { foreach ($sqls as $sql) { $stmt = $pdo->prepare($sql); $stmt->execute(); } $pdo->commit(); } catch (PDOException $e) { $pdo->rollback(); throw $e; } } return true; }
[ "public", "function", "insertSql", "(", "$", "datasource", "=", "null", ")", "{", "$", "statementsToInsert", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getProperties", "(", "$", "this", "->", "getSqlDbMapFilename", "(", ")", ")", "as", "$", "sqlFile", "=>", "$", "database", ")", "{", "if", "(", "null", "!==", "$", "datasource", "&&", "$", "database", "!==", "$", "datasource", ")", "{", "// skip", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "statementsToInsert", "[", "$", "database", "]", ")", ")", "{", "$", "statementsToInsert", "[", "$", "database", "]", "=", "array", "(", ")", ";", "}", "if", "(", "null", "===", "$", "database", "||", "(", "null", "!==", "$", "database", "&&", "$", "database", "===", "$", "datasource", ")", ")", "{", "$", "filename", "=", "$", "this", "->", "getWorkingDirectory", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "sqlFile", ";", "if", "(", "file_exists", "(", "$", "filename", ")", ")", "{", "foreach", "(", "PropelSQLParser", "::", "parseFile", "(", "$", "filename", ")", "as", "$", "sql", ")", "{", "$", "statementsToInsert", "[", "$", "database", "]", "[", "]", "=", "$", "sql", ";", "}", "}", "}", "}", "foreach", "(", "$", "statementsToInsert", "as", "$", "database", "=>", "$", "sqls", ")", "{", "if", "(", "!", "$", "this", "->", "hasConnection", "(", "$", "database", ")", ")", "{", "continue", ";", "}", "$", "pdo", "=", "$", "this", "->", "getPdoConnection", "(", "$", "database", ")", ";", "$", "pdo", "->", "beginTransaction", "(", ")", ";", "try", "{", "foreach", "(", "$", "sqls", "as", "$", "sql", ")", "{", "$", "stmt", "=", "$", "pdo", "->", "prepare", "(", "$", "sql", ")", ";", "$", "stmt", "->", "execute", "(", ")", ";", "}", "$", "pdo", "->", "commit", "(", ")", ";", "}", "catch", "(", "PDOException", "$", "e", ")", "{", "$", "pdo", "->", "rollback", "(", ")", ";", "throw", "$", "e", ";", "}", "}", "return", "true", ";", "}" ]
@param string $datasource A datasource name. @return bool @throws PDOException
[ "@param", "string", "$datasource", "A", "datasource", "name", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/util/PropelSqlManager.php#L198-L243
propelorm/Propel
generator/lib/util/PropelSqlManager.php
PropelSqlManager.getPdoConnection
protected function getPdoConnection($datasource) { $buildConnection = $this->getConnection($datasource); $dsn = str_replace("@DB@", $datasource, $buildConnection['dsn']); // Set user + password to null if they are empty strings or missing $username = isset($buildConnection['user']) && $buildConnection['user'] ? $buildConnection['user'] : null; $password = isset($buildConnection['password']) && $buildConnection['password'] ? $buildConnection['password'] : null; $pdo = new PDO($dsn, $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $pdo; }
php
protected function getPdoConnection($datasource) { $buildConnection = $this->getConnection($datasource); $dsn = str_replace("@DB@", $datasource, $buildConnection['dsn']); // Set user + password to null if they are empty strings or missing $username = isset($buildConnection['user']) && $buildConnection['user'] ? $buildConnection['user'] : null; $password = isset($buildConnection['password']) && $buildConnection['password'] ? $buildConnection['password'] : null; $pdo = new PDO($dsn, $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $pdo; }
[ "protected", "function", "getPdoConnection", "(", "$", "datasource", ")", "{", "$", "buildConnection", "=", "$", "this", "->", "getConnection", "(", "$", "datasource", ")", ";", "$", "dsn", "=", "str_replace", "(", "\"@DB@\"", ",", "$", "datasource", ",", "$", "buildConnection", "[", "'dsn'", "]", ")", ";", "// Set user + password to null if they are empty strings or missing", "$", "username", "=", "isset", "(", "$", "buildConnection", "[", "'user'", "]", ")", "&&", "$", "buildConnection", "[", "'user'", "]", "?", "$", "buildConnection", "[", "'user'", "]", ":", "null", ";", "$", "password", "=", "isset", "(", "$", "buildConnection", "[", "'password'", "]", ")", "&&", "$", "buildConnection", "[", "'password'", "]", "?", "$", "buildConnection", "[", "'password'", "]", ":", "null", ";", "$", "pdo", "=", "new", "PDO", "(", "$", "dsn", ",", "$", "username", ",", "$", "password", ")", ";", "$", "pdo", "->", "setAttribute", "(", "PDO", "::", "ATTR_ERRMODE", ",", "PDO", "::", "ERRMODE_EXCEPTION", ")", ";", "return", "$", "pdo", ";", "}" ]
Gets a PDO connection for a given datasource. @return PDO
[ "Gets", "a", "PDO", "connection", "for", "a", "given", "datasource", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/util/PropelSqlManager.php#L250-L263
propelorm/Propel
generator/lib/util/PropelSqlManager.php
PropelSqlManager.getProperties
protected function getProperties($file) { $properties = array(); if (false === $lines = @file($file)) { throw new Exception(sprintf('Unable to parse contents of "%s".', $file)); } foreach ($lines as $line) { $line = trim($line); if ('' == $line || in_array($line[0], array('#', ';'))) { continue; } $pos = strpos($line, '='); $properties[trim(substr($line, 0, $pos))] = trim(substr($line, $pos + 1)); } return $properties; }
php
protected function getProperties($file) { $properties = array(); if (false === $lines = @file($file)) { throw new Exception(sprintf('Unable to parse contents of "%s".', $file)); } foreach ($lines as $line) { $line = trim($line); if ('' == $line || in_array($line[0], array('#', ';'))) { continue; } $pos = strpos($line, '='); $properties[trim(substr($line, 0, $pos))] = trim(substr($line, $pos + 1)); } return $properties; }
[ "protected", "function", "getProperties", "(", "$", "file", ")", "{", "$", "properties", "=", "array", "(", ")", ";", "if", "(", "false", "===", "$", "lines", "=", "@", "file", "(", "$", "file", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Unable to parse contents of \"%s\".'", ",", "$", "file", ")", ")", ";", "}", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "line", "=", "trim", "(", "$", "line", ")", ";", "if", "(", "''", "==", "$", "line", "||", "in_array", "(", "$", "line", "[", "0", "]", ",", "array", "(", "'#'", ",", "';'", ")", ")", ")", "{", "continue", ";", "}", "$", "pos", "=", "strpos", "(", "$", "line", ",", "'='", ")", ";", "$", "properties", "[", "trim", "(", "substr", "(", "$", "line", ",", "0", ",", "$", "pos", ")", ")", "]", "=", "trim", "(", "substr", "(", "$", "line", ",", "$", "pos", "+", "1", ")", ")", ";", "}", "return", "$", "properties", ";", "}" ]
Returns an array of properties as key/value pairs from an input file. @param string $file A file properties. @return array An array of properties as key/value pairs. @throws Exception
[ "Returns", "an", "array", "of", "properties", "as", "key", "/", "value", "pairs", "from", "an", "input", "file", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/util/PropelSqlManager.php#L273-L293
propelorm/Propel
generator/lib/model/Validator.php
Validator.setupObject
protected function setupObject() { $this->column = $this->getTable()->getColumn($this->getAttribute("column")); $this->translate = $this->getAttribute("translate", $this->getTable()->getDatabase()->getDefaultTranslateMethod());; }
php
protected function setupObject() { $this->column = $this->getTable()->getColumn($this->getAttribute("column")); $this->translate = $this->getAttribute("translate", $this->getTable()->getDatabase()->getDefaultTranslateMethod());; }
[ "protected", "function", "setupObject", "(", ")", "{", "$", "this", "->", "column", "=", "$", "this", "->", "getTable", "(", ")", "->", "getColumn", "(", "$", "this", "->", "getAttribute", "(", "\"column\"", ")", ")", ";", "$", "this", "->", "translate", "=", "$", "this", "->", "getAttribute", "(", "\"translate\"", ",", "$", "this", "->", "getTable", "(", ")", "->", "getDatabase", "(", ")", "->", "getDefaultTranslateMethod", "(", ")", ")", ";", ";", "}" ]
Sets up the Validator object based on the attributes that were passed to loadFromXML(). @see parent::loadFromXML()
[ "Sets", "up", "the", "Validator", "object", "based", "on", "the", "attributes", "that", "were", "passed", "to", "loadFromXML", "()", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/Validator.php#L62-L66
propelorm/Propel
generator/lib/model/Validator.php
Validator.addRule
public function addRule($data) { if ($data instanceof Rule) { $rule = $data; // alias $rule->setValidator($this); $this->ruleList[] = $rule; return $rule; } else { $rule = new Rule(); $rule->setValidator($this); $rule->loadFromXML($data); return $this->addRule($rule); // call self w/ different param } }
php
public function addRule($data) { if ($data instanceof Rule) { $rule = $data; // alias $rule->setValidator($this); $this->ruleList[] = $rule; return $rule; } else { $rule = new Rule(); $rule->setValidator($this); $rule->loadFromXML($data); return $this->addRule($rule); // call self w/ different param } }
[ "public", "function", "addRule", "(", "$", "data", ")", "{", "if", "(", "$", "data", "instanceof", "Rule", ")", "{", "$", "rule", "=", "$", "data", ";", "// alias", "$", "rule", "->", "setValidator", "(", "$", "this", ")", ";", "$", "this", "->", "ruleList", "[", "]", "=", "$", "rule", ";", "return", "$", "rule", ";", "}", "else", "{", "$", "rule", "=", "new", "Rule", "(", ")", ";", "$", "rule", "->", "setValidator", "(", "$", "this", ")", ";", "$", "rule", "->", "loadFromXML", "(", "$", "data", ")", ";", "return", "$", "this", "->", "addRule", "(", "$", "rule", ")", ";", "// call self w/ different param", "}", "}" ]
Add a Rule to this validator. Supports two signatures: - addRule(Rule $rule) - addRule(array $attribs) @param mixed $data Rule object or XML attribs (array) from <rule/> element. @return Rule The added Rule.
[ "Add", "a", "Rule", "to", "this", "validator", ".", "Supports", "two", "signatures", ":", "-", "addRule", "(", "Rule", "$rule", ")", "-", "addRule", "(", "array", "$attribs", ")" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/Validator.php#L78-L93
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addBuildPkeyCriteriaBody
protected function addBuildPkeyCriteriaBody(&$script) { $script .= " \$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);"; foreach ($this->getTable()->getColumns() as $col) { $clo = strtolower($col->getName()); if ($col->isPrimaryKey()) { $script .= " \$criteria->add(" . $this->getColumnConstant($col) . ", \$this->$clo);"; } } }
php
protected function addBuildPkeyCriteriaBody(&$script) { $script .= " \$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);"; foreach ($this->getTable()->getColumns() as $col) { $clo = strtolower($col->getName()); if ($col->isPrimaryKey()) { $script .= " \$criteria->add(" . $this->getColumnConstant($col) . ", \$this->$clo);"; } } }
[ "protected", "function", "addBuildPkeyCriteriaBody", "(", "&", "$", "script", ")", "{", "$", "script", ".=", "\"\n \\$criteria = new Criteria(\"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME);\"", ";", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "col", "->", "isPrimaryKey", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$criteria->add(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ".", "\", \\$this->$clo);\"", ";", "}", "}", "}" ]
Adds the function body for the buildPkeyCriteria method @param string &$script The script will be modified in this method. @see addBuildPkeyCriteria()
[ "Adds", "the", "function", "body", "for", "the", "buildPkeyCriteria", "method" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L215-L226
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addDeleteBody
protected function addDeleteBody(&$script) { $script .= " if (\$this->isDeleted()) { throw new PropelException(\"This object has already been deleted.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE); } \$con->beginTransaction(); try {"; if ($this->getGeneratorConfig()->getBuildProperty('addHooks')) { $script .= " \$ret = \$this->preDelete(\$con);"; // apply behaviors $this->applyBehaviorModifier('preDelete', $script, " "); $script .= " if (\$ret) { " . $this->getPeerClassname() . "::doDelete(\$this, \$con); \$this->postDelete(\$con);"; // apply behaviors $this->applyBehaviorModifier('postDelete', $script, " "); $script .= " \$con->commit(); \$this->setDeleted(true); } else { \$con->commit(); }"; } else { // apply behaviors $this->applyBehaviorModifier('preDelete', $script, " "); $script .= " " . $this->getPeerClassname() . "::doDelete(\$this, \$con);"; // apply behaviors $this->applyBehaviorModifier('postDelete', $script, " "); $script .= " \$con->commit(); \$this->setDeleted(true);"; } $script .= " } catch (Exception \$e) { \$con->rollBack(); throw \$e; }"; }
php
protected function addDeleteBody(&$script) { $script .= " if (\$this->isDeleted()) { throw new PropelException(\"This object has already been deleted.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE); } \$con->beginTransaction(); try {"; if ($this->getGeneratorConfig()->getBuildProperty('addHooks')) { $script .= " \$ret = \$this->preDelete(\$con);"; // apply behaviors $this->applyBehaviorModifier('preDelete', $script, " "); $script .= " if (\$ret) { " . $this->getPeerClassname() . "::doDelete(\$this, \$con); \$this->postDelete(\$con);"; // apply behaviors $this->applyBehaviorModifier('postDelete', $script, " "); $script .= " \$con->commit(); \$this->setDeleted(true); } else { \$con->commit(); }"; } else { // apply behaviors $this->applyBehaviorModifier('preDelete', $script, " "); $script .= " " . $this->getPeerClassname() . "::doDelete(\$this, \$con);"; // apply behaviors $this->applyBehaviorModifier('postDelete', $script, " "); $script .= " \$con->commit(); \$this->setDeleted(true);"; } $script .= " } catch (Exception \$e) { \$con->rollBack(); throw \$e; }"; }
[ "protected", "function", "addDeleteBody", "(", "&", "$", "script", ")", "{", "$", "script", ".=", "\"\n if (\\$this->isDeleted()) {\n throw new PropelException(\\\"This object has already been deleted.\\\");\n }\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME, Propel::CONNECTION_WRITE);\n }\n\n \\$con->beginTransaction();\n try {\"", ";", "if", "(", "$", "this", "->", "getGeneratorConfig", "(", ")", "->", "getBuildProperty", "(", "'addHooks'", ")", ")", "{", "$", "script", ".=", "\"\n \\$ret = \\$this->preDelete(\\$con);\"", ";", "// apply behaviors", "$", "this", "->", "applyBehaviorModifier", "(", "'preDelete'", ",", "$", "script", ",", "\"\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n if (\\$ret) {\n \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::doDelete(\\$this, \\$con);\n \\$this->postDelete(\\$con);\"", ";", "// apply behaviors", "$", "this", "->", "applyBehaviorModifier", "(", "'postDelete'", ",", "$", "script", ",", "\"\t\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n \\$con->commit();\n \\$this->setDeleted(true);\n } else {\n \\$con->commit();\n }\"", ";", "}", "else", "{", "// apply behaviors", "$", "this", "->", "applyBehaviorModifier", "(", "'preDelete'", ",", "$", "script", ",", "\"\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::doDelete(\\$this, \\$con);\"", ";", "// apply behaviors", "$", "this", "->", "applyBehaviorModifier", "(", "'postDelete'", ",", "$", "script", ",", "\"\t\t\t\"", ")", ";", "$", "script", ".=", "\"\n \\$con->commit();\n \\$this->setDeleted(true);\"", ";", "}", "$", "script", ".=", "\"\n } catch (Exception \\$e) {\n \\$con->rollBack();\n throw \\$e;\n }\"", ";", "}" ]
Adds the function body for the delete function @param string &$script The script will be modified in this method. @see addDelete()
[ "Adds", "the", "function", "body", "for", "the", "delete", "function" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L330-L377
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addReload
protected function addReload(&$script) { $table = $this->getTable(); $script .= " /** * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. * * This will only work if the object has been saved and has a valid primary key set. * * @param boolean \$deep (optional) Whether to also de-associated any related objects. * @param PropelPDO \$con (optional) The PropelPDO connection to use. * @return void * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db */ public function reload(\$deep = false, PropelPDO \$con = null) { if (\$this->isDeleted()) { throw new PropelException(\"Cannot reload a deleted object.\"); } if (\$this->isNew()) { throw new PropelException(\"Cannot reload an unsaved object.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$this->buildPkeyCriteria(), \$con); \$row = \$stmt->fetch(PDO::FETCH_NUM); \$stmt->closeCursor(); if (!\$row) { throw new PropelException('Cannot find matching row in the database to reload object values.'); } \$this->hydrate(\$row, 0, true); // rehydrate "; // support for lazy load columns foreach ($table->getColumns() as $col) { if ($col->isLazyLoad()) { $clo = strtolower($col->getName()); $script .= " // Reset the $clo lazy-load column \$this->" . $clo . " = null; \$this->" . $clo . "_isLoaded = false; "; } } $script .= " if (\$deep) { // also de-associate any related objects? "; foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " \$this->" . $varName . " = null;"; } foreach ($table->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $script .= " \$this->" . $this->getPKRefFKVarName($refFK) . " = null; "; } else { $script .= " \$this->" . $this->getRefFKCollVarName($refFK) . " = null; \$this->" . $this->getRefFKLastCriteriaVarName($refFK) . " = null; "; } } $script .= " } // if (deep) } "; }
php
protected function addReload(&$script) { $table = $this->getTable(); $script .= " /** * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. * * This will only work if the object has been saved and has a valid primary key set. * * @param boolean \$deep (optional) Whether to also de-associated any related objects. * @param PropelPDO \$con (optional) The PropelPDO connection to use. * @return void * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db */ public function reload(\$deep = false, PropelPDO \$con = null) { if (\$this->isDeleted()) { throw new PropelException(\"Cannot reload a deleted object.\"); } if (\$this->isNew()) { throw new PropelException(\"Cannot reload an unsaved object.\"); } if (\$con === null) { \$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ); } // We don't need to alter the object instance pool; we're just modifying this instance // already in the pool. \$stmt = " . $this->getPeerClassname() . "::doSelectStmt(\$this->buildPkeyCriteria(), \$con); \$row = \$stmt->fetch(PDO::FETCH_NUM); \$stmt->closeCursor(); if (!\$row) { throw new PropelException('Cannot find matching row in the database to reload object values.'); } \$this->hydrate(\$row, 0, true); // rehydrate "; // support for lazy load columns foreach ($table->getColumns() as $col) { if ($col->isLazyLoad()) { $clo = strtolower($col->getName()); $script .= " // Reset the $clo lazy-load column \$this->" . $clo . " = null; \$this->" . $clo . "_isLoaded = false; "; } } $script .= " if (\$deep) { // also de-associate any related objects? "; foreach ($table->getForeignKeys() as $fk) { $varName = $this->getFKVarName($fk); $script .= " \$this->" . $varName . " = null;"; } foreach ($table->getReferrers() as $refFK) { if ($refFK->isLocalPrimaryKey()) { $script .= " \$this->" . $this->getPKRefFKVarName($refFK) . " = null; "; } else { $script .= " \$this->" . $this->getRefFKCollVarName($refFK) . " = null; \$this->" . $this->getRefFKLastCriteriaVarName($refFK) . " = null; "; } } $script .= " } // if (deep) } "; }
[ "protected", "function", "addReload", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Reloads this object from datastore based on primary key and (optionally) resets all associated objects.\n *\n * This will only work if the object has been saved and has a valid primary key set.\n *\n * @param boolean \\$deep (optional) Whether to also de-associated any related objects.\n * @param PropelPDO \\$con (optional) The PropelPDO connection to use.\n * @return void\n * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db\n */\n public function reload(\\$deep = false, PropelPDO \\$con = null)\n {\n if (\\$this->isDeleted()) {\n throw new PropelException(\\\"Cannot reload a deleted object.\\\");\n }\n\n if (\\$this->isNew()) {\n throw new PropelException(\\\"Cannot reload an unsaved object.\\\");\n }\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n\n // We don't need to alter the object instance pool; we're just modifying this instance\n // already in the pool.\n\n \\$stmt = \"", ".", "$", "this", "->", "getPeerClassname", "(", ")", ".", "\"::doSelectStmt(\\$this->buildPkeyCriteria(), \\$con);\n \\$row = \\$stmt->fetch(PDO::FETCH_NUM);\n \\$stmt->closeCursor();\n if (!\\$row) {\n throw new PropelException('Cannot find matching row in the database to reload object values.');\n }\n \\$this->hydrate(\\$row, 0, true); // rehydrate\n\"", ";", "// support for lazy load columns", "foreach", "(", "$", "table", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "if", "(", "$", "col", "->", "isLazyLoad", "(", ")", ")", "{", "$", "clo", "=", "strtolower", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n // Reset the $clo lazy-load column\n \\$this->\"", ".", "$", "clo", ".", "\" = null;\n \\$this->\"", ".", "$", "clo", ".", "\"_isLoaded = false;\n\"", ";", "}", "}", "$", "script", ".=", "\"\n if (\\$deep) { // also de-associate any related objects?\n\"", ";", "foreach", "(", "$", "table", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "varName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "varName", ".", "\" = null;\"", ";", "}", "foreach", "(", "$", "table", "->", "getReferrers", "(", ")", "as", "$", "refFK", ")", "{", "if", "(", "$", "refFK", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ".", "\" = null;\n\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$this->\"", ".", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ".", "\" = null;\n \\$this->\"", ".", "$", "this", "->", "getRefFKLastCriteriaVarName", "(", "$", "refFK", ")", ".", "\" = null;\n\"", ";", "}", "}", "$", "script", ".=", "\"\n } // if (deep)\n }\n\"", ";", "}" ]
Adds a reload() method to re-fetch the data for this object from the database. @param string &$script The script will be modified in this method.
[ "Adds", "a", "reload", "()", "method", "to", "re", "-", "fetch", "the", "data", "for", "this", "object", "from", "the", "database", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L384-L463
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addFKAccessor
protected function addFKAccessor(&$script, ForeignKey $fk) { $table = $this->getTable(); $varName = $this->getFKVarName($fk); $fkPeerBuilder = $this->getNewPeerBuilder($this->getForeignTable($fk)); $fkObjectBuilder = $this->getNewObjectBuilder($this->getForeignTable($fk))->getStubObjectBuilder(); $className = $fkObjectBuilder->getClassname(); // get the Classname that has maybe a prefix $and = ""; $conditional = ""; $localColumns = array(); // foreign key local attributes names $argmap = array(); // foreign -> local mapping // If the related columns are a primary key on the foreign table // then use retrieveByPk() instead of doSelect() to take advantage // of instance pooling $useRetrieveByPk = $fk->isForeignPrimaryKey(); foreach ($fk->getLocalColumns() as $columnName) { $lfmap = $fk->getLocalForeignMapping(); $localColumn = $table->getColumn($columnName); $foreignColumn = $fk->getForeignTable()->getColumn($lfmap[$columnName]); $column = $table->getColumn($columnName); $cptype = $column->getPhpType(); $clo = strtolower($column->getName()); $localColumns[$foreignColumn->getPosition()] = '$this->' . $clo; if ($cptype == "integer" || $cptype == "float" || $cptype == "double") { $conditional .= $and . "\$this->" . $clo . " != 0"; } elseif ($cptype == "string") { $conditional .= $and . "(\$this->" . $clo . " !== \"\" && \$this->" . $clo . " !== null)"; } else { $conditional .= $and . "\$this->" . $clo . " !== null"; } $argmap[] = array('foreign' => $foreignColumn, 'local' => $localColumn); $and = " && "; } ksort($localColumns); // restoring the order of the foreign PK $localColumns = count($localColumns) > 1 ? ('array(' . implode(', ', $localColumns) . ')') : reset($localColumns); // If the related column is a primary kay and if it's a simple association, // The use retrieveByPk() instead of doSelect() to take advantage of instance pooling $useRetrieveByPk = count($argmap) == 1 && $argmap[0]['foreign']->isPrimaryKey(); $script .= " /** * Get the associated $className object * * @param PropelPDO Optional Connection object. * @return $className The associated $className object. * @throws PropelException */ public function get" . $this->getFKPhpNameAffix($fk, $plural = false) . "(PropelPDO \$con = null) {"; $script .= " if (\$this->$varName === null && ($conditional)) {"; if ($useRetrieveByPk) { $script .= " \$this->$varName = " . $fkPeerBuilder->getPeerClassname() . "::retrieveByPk($localColumns, \$con);"; } else { $script .= " \$c = new Criteria(" . $fkPeerBuilder->getPeerClassname() . "::DATABASE_NAME);"; foreach ($argmap as $el) { $fcol = $el['foreign']; $lcol = $el['local']; $clo = strtolower($lcol->getName()); $script .= " \$c->add(" . $fkPeerBuilder->getColumnConstant($fcol) . ", \$this->" . $clo . ");"; } $script .= " \$this->$varName = " . $fkPeerBuilder->getPeerClassname() . "::doSelectOne(\$c, \$con);"; } if ($fk->isLocalPrimaryKey()) { $script .= " // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association. \$this->{$varName}->set" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "(\$this);"; } else { $script .= " /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. \$this->{$varName}->add" . $this->getRefFKPhpNameAffix($fk, $plural = true) . "(\$this); */"; } $script .= " } return \$this->$varName; } "; }
php
protected function addFKAccessor(&$script, ForeignKey $fk) { $table = $this->getTable(); $varName = $this->getFKVarName($fk); $fkPeerBuilder = $this->getNewPeerBuilder($this->getForeignTable($fk)); $fkObjectBuilder = $this->getNewObjectBuilder($this->getForeignTable($fk))->getStubObjectBuilder(); $className = $fkObjectBuilder->getClassname(); // get the Classname that has maybe a prefix $and = ""; $conditional = ""; $localColumns = array(); // foreign key local attributes names $argmap = array(); // foreign -> local mapping // If the related columns are a primary key on the foreign table // then use retrieveByPk() instead of doSelect() to take advantage // of instance pooling $useRetrieveByPk = $fk->isForeignPrimaryKey(); foreach ($fk->getLocalColumns() as $columnName) { $lfmap = $fk->getLocalForeignMapping(); $localColumn = $table->getColumn($columnName); $foreignColumn = $fk->getForeignTable()->getColumn($lfmap[$columnName]); $column = $table->getColumn($columnName); $cptype = $column->getPhpType(); $clo = strtolower($column->getName()); $localColumns[$foreignColumn->getPosition()] = '$this->' . $clo; if ($cptype == "integer" || $cptype == "float" || $cptype == "double") { $conditional .= $and . "\$this->" . $clo . " != 0"; } elseif ($cptype == "string") { $conditional .= $and . "(\$this->" . $clo . " !== \"\" && \$this->" . $clo . " !== null)"; } else { $conditional .= $and . "\$this->" . $clo . " !== null"; } $argmap[] = array('foreign' => $foreignColumn, 'local' => $localColumn); $and = " && "; } ksort($localColumns); // restoring the order of the foreign PK $localColumns = count($localColumns) > 1 ? ('array(' . implode(', ', $localColumns) . ')') : reset($localColumns); // If the related column is a primary kay and if it's a simple association, // The use retrieveByPk() instead of doSelect() to take advantage of instance pooling $useRetrieveByPk = count($argmap) == 1 && $argmap[0]['foreign']->isPrimaryKey(); $script .= " /** * Get the associated $className object * * @param PropelPDO Optional Connection object. * @return $className The associated $className object. * @throws PropelException */ public function get" . $this->getFKPhpNameAffix($fk, $plural = false) . "(PropelPDO \$con = null) {"; $script .= " if (\$this->$varName === null && ($conditional)) {"; if ($useRetrieveByPk) { $script .= " \$this->$varName = " . $fkPeerBuilder->getPeerClassname() . "::retrieveByPk($localColumns, \$con);"; } else { $script .= " \$c = new Criteria(" . $fkPeerBuilder->getPeerClassname() . "::DATABASE_NAME);"; foreach ($argmap as $el) { $fcol = $el['foreign']; $lcol = $el['local']; $clo = strtolower($lcol->getName()); $script .= " \$c->add(" . $fkPeerBuilder->getColumnConstant($fcol) . ", \$this->" . $clo . ");"; } $script .= " \$this->$varName = " . $fkPeerBuilder->getPeerClassname() . "::doSelectOne(\$c, \$con);"; } if ($fk->isLocalPrimaryKey()) { $script .= " // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association. \$this->{$varName}->set" . $this->getRefFKPhpNameAffix($fk, $plural = false) . "(\$this);"; } else { $script .= " /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. \$this->{$varName}->add" . $this->getRefFKPhpNameAffix($fk, $plural = true) . "(\$this); */"; } $script .= " } return \$this->$varName; } "; }
[ "protected", "function", "addFKAccessor", "(", "&", "$", "script", ",", "ForeignKey", "$", "fk", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "varName", "=", "$", "this", "->", "getFKVarName", "(", "$", "fk", ")", ";", "$", "fkPeerBuilder", "=", "$", "this", "->", "getNewPeerBuilder", "(", "$", "this", "->", "getForeignTable", "(", "$", "fk", ")", ")", ";", "$", "fkObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "this", "->", "getForeignTable", "(", "$", "fk", ")", ")", "->", "getStubObjectBuilder", "(", ")", ";", "$", "className", "=", "$", "fkObjectBuilder", "->", "getClassname", "(", ")", ";", "// get the Classname that has maybe a prefix", "$", "and", "=", "\"\"", ";", "$", "conditional", "=", "\"\"", ";", "$", "localColumns", "=", "array", "(", ")", ";", "// foreign key local attributes names", "$", "argmap", "=", "array", "(", ")", ";", "// foreign -> local mapping", "// If the related columns are a primary key on the foreign table", "// then use retrieveByPk() instead of doSelect() to take advantage", "// of instance pooling", "$", "useRetrieveByPk", "=", "$", "fk", "->", "isForeignPrimaryKey", "(", ")", ";", "foreach", "(", "$", "fk", "->", "getLocalColumns", "(", ")", "as", "$", "columnName", ")", "{", "$", "lfmap", "=", "$", "fk", "->", "getLocalForeignMapping", "(", ")", ";", "$", "localColumn", "=", "$", "table", "->", "getColumn", "(", "$", "columnName", ")", ";", "$", "foreignColumn", "=", "$", "fk", "->", "getForeignTable", "(", ")", "->", "getColumn", "(", "$", "lfmap", "[", "$", "columnName", "]", ")", ";", "$", "column", "=", "$", "table", "->", "getColumn", "(", "$", "columnName", ")", ";", "$", "cptype", "=", "$", "column", "->", "getPhpType", "(", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "$", "localColumns", "[", "$", "foreignColumn", "->", "getPosition", "(", ")", "]", "=", "'$this->'", ".", "$", "clo", ";", "if", "(", "$", "cptype", "==", "\"integer\"", "||", "$", "cptype", "==", "\"float\"", "||", "$", "cptype", "==", "\"double\"", ")", "{", "$", "conditional", ".=", "$", "and", ".", "\"\\$this->\"", ".", "$", "clo", ".", "\" != 0\"", ";", "}", "elseif", "(", "$", "cptype", "==", "\"string\"", ")", "{", "$", "conditional", ".=", "$", "and", ".", "\"(\\$this->\"", ".", "$", "clo", ".", "\" !== \\\"\\\" && \\$this->\"", ".", "$", "clo", ".", "\" !== null)\"", ";", "}", "else", "{", "$", "conditional", ".=", "$", "and", ".", "\"\\$this->\"", ".", "$", "clo", ".", "\" !== null\"", ";", "}", "$", "argmap", "[", "]", "=", "array", "(", "'foreign'", "=>", "$", "foreignColumn", ",", "'local'", "=>", "$", "localColumn", ")", ";", "$", "and", "=", "\" && \"", ";", "}", "ksort", "(", "$", "localColumns", ")", ";", "// restoring the order of the foreign PK", "$", "localColumns", "=", "count", "(", "$", "localColumns", ")", ">", "1", "?", "(", "'array('", ".", "implode", "(", "', '", ",", "$", "localColumns", ")", ".", "')'", ")", ":", "reset", "(", "$", "localColumns", ")", ";", "// If the related column is a primary kay and if it's a simple association,", "// The use retrieveByPk() instead of doSelect() to take advantage of instance pooling", "$", "useRetrieveByPk", "=", "count", "(", "$", "argmap", ")", "==", "1", "&&", "$", "argmap", "[", "0", "]", "[", "'foreign'", "]", "->", "isPrimaryKey", "(", ")", ";", "$", "script", ".=", "\"\n\n /**\n * Get the associated $className object\n *\n * @param PropelPDO Optional Connection object.\n * @return $className The associated $className object.\n * @throws PropelException\n */\n public function get\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ".", "\"(PropelPDO \\$con = null)\n {\"", ";", "$", "script", ".=", "\"\n if (\\$this->$varName === null && ($conditional)) {\"", ";", "if", "(", "$", "useRetrieveByPk", ")", "{", "$", "script", ".=", "\"\n \\$this->$varName = \"", ".", "$", "fkPeerBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::retrieveByPk($localColumns, \\$con);\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n \\$c = new Criteria(\"", ".", "$", "fkPeerBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::DATABASE_NAME);\"", ";", "foreach", "(", "$", "argmap", "as", "$", "el", ")", "{", "$", "fcol", "=", "$", "el", "[", "'foreign'", "]", ";", "$", "lcol", "=", "$", "el", "[", "'local'", "]", ";", "$", "clo", "=", "strtolower", "(", "$", "lcol", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n \\$c->add(\"", ".", "$", "fkPeerBuilder", "->", "getColumnConstant", "(", "$", "fcol", ")", ".", "\", \\$this->\"", ".", "$", "clo", ".", "\");\"", ";", "}", "$", "script", ".=", "\"\n \\$this->$varName = \"", ".", "$", "fkPeerBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::doSelectOne(\\$c, \\$con);\"", ";", "}", "if", "(", "$", "fk", "->", "isLocalPrimaryKey", "(", ")", ")", "{", "$", "script", ".=", "\"\n // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association.\n \\$this->{$varName}->set\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "false", ")", ".", "\"(\\$this);\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n /* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n \\$this->{$varName}->add\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ",", "$", "plural", "=", "true", ")", ".", "\"(\\$this);\n */\"", ";", "}", "$", "script", ".=", "\"\n }\n\n return \\$this->$varName;\n }\n\"", ";", "}" ]
Adds the accessor (getter) method for getting an fkey related object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "accessor", "(", "getter", ")", "method", "for", "getting", "an", "fkey", "related", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L483-L584
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addRefFKGetJoinMethods
protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $join_behavior = $this->getGeneratorConfig()->getBuildProperty('useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN'; $peerClassname = $this->getStubPeerBuilder()->getClassname(); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK); $fkPeerBuilder = $this->getNewPeerBuilder($tblFK); $lastTable = ""; foreach ($tblFK->getForeignKeys() as $fk2) { $tblFK2 = $this->getForeignTable($fk2); $doJoinGet = !$tblFK2->isForReferenceOnly(); // it doesn't make sense to join in rows from the current table, since we are fetching // objects related to *this* table (i.e. the joined rows will all be the same row as current object) if ($this->getTable()->getPhpName() == $tblFK2->getPhpName()) { $doJoinGet = false; } $relCol2 = $this->getFKPhpNameAffix($fk2, $plural = false); if ($this->getRelatedBySuffix($refFK) != "" && ($this->getRelatedBySuffix($refFK) == $this->getRelatedBySuffix($fk2))) { $doJoinGet = false; } if ($doJoinGet) { $script .= " /** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this " . $table->getPhpName() . " is new, it will return * an empty collection; or if this " . $table->getPhpName() . " has previously * been saved, it will retrieve related $relCol from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in " . $table->getPhpName() . ". */ public function get" . $relCol . "Join" . $relCol2 . "(\$criteria = null, \$con = null, \$join_behavior = $join_behavior) {"; $script .= " if (\$criteria === null) { \$criteria = new Criteria($peerClassname::DATABASE_NAME); } elseif (\$criteria instanceof Criteria) { \$criteria = clone \$criteria; } if (\$this->$collName === null) { if (\$this->isNew()) { \$this->$collName = array(); } else { "; foreach ($refFK->getForeignColumns() as $columnName) { $column = $table->getColumn($columnName); $flMap = $refFK->getForeignLocalMapping(); $colFKName = $flMap[$columnName]; $colFK = $tblFK->getColumn($colFKName); if ($colFK === null) { throw new EngineException("Column $colFKName not found in " . $tblFK->getName()); } $clo = strtolower($column->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } // end foreach ($fk->getForeignColumns() $script .= " \$this->$collName = " . $fkPeerBuilder->getPeerClassname() . "::doSelectJoin$relCol2(\$criteria, \$con, \$join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. "; foreach ($refFK->getForeignColumns() as $columnName) { $column = $table->getColumn($columnName); $flMap = $refFK->getForeignLocalMapping(); $colFKName = $flMap[$columnName]; $colFK = $tblFK->getColumn($colFKName); $clo = strtolower($column->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } /* end foreach ($fk->getForeignColumns() */ $script .= " if (!isset(\$this->$lastCriteriaName) || !\$this->" . $lastCriteriaName . "->equals(\$criteria)) { \$this->$collName = " . $fkPeerBuilder->getPeerClassname() . "::doSelectJoin$relCol2(\$criteria, \$con, \$join_behavior); } } \$this->$lastCriteriaName = \$criteria; return \$this->$collName; } "; } /* end if ($doJoinGet) */ } /* end foreach ($tblFK->getForeignKeys() as $fk2) { */ }
php
protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $join_behavior = $this->getGeneratorConfig()->getBuildProperty('useLeftJoinsInDoJoinMethods') ? 'Criteria::LEFT_JOIN' : 'Criteria::INNER_JOIN'; $peerClassname = $this->getStubPeerBuilder()->getClassname(); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK); $fkPeerBuilder = $this->getNewPeerBuilder($tblFK); $lastTable = ""; foreach ($tblFK->getForeignKeys() as $fk2) { $tblFK2 = $this->getForeignTable($fk2); $doJoinGet = !$tblFK2->isForReferenceOnly(); // it doesn't make sense to join in rows from the current table, since we are fetching // objects related to *this* table (i.e. the joined rows will all be the same row as current object) if ($this->getTable()->getPhpName() == $tblFK2->getPhpName()) { $doJoinGet = false; } $relCol2 = $this->getFKPhpNameAffix($fk2, $plural = false); if ($this->getRelatedBySuffix($refFK) != "" && ($this->getRelatedBySuffix($refFK) == $this->getRelatedBySuffix($fk2))) { $doJoinGet = false; } if ($doJoinGet) { $script .= " /** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this " . $table->getPhpName() . " is new, it will return * an empty collection; or if this " . $table->getPhpName() . " has previously * been saved, it will retrieve related $relCol from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in " . $table->getPhpName() . ". */ public function get" . $relCol . "Join" . $relCol2 . "(\$criteria = null, \$con = null, \$join_behavior = $join_behavior) {"; $script .= " if (\$criteria === null) { \$criteria = new Criteria($peerClassname::DATABASE_NAME); } elseif (\$criteria instanceof Criteria) { \$criteria = clone \$criteria; } if (\$this->$collName === null) { if (\$this->isNew()) { \$this->$collName = array(); } else { "; foreach ($refFK->getForeignColumns() as $columnName) { $column = $table->getColumn($columnName); $flMap = $refFK->getForeignLocalMapping(); $colFKName = $flMap[$columnName]; $colFK = $tblFK->getColumn($colFKName); if ($colFK === null) { throw new EngineException("Column $colFKName not found in " . $tblFK->getName()); } $clo = strtolower($column->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } // end foreach ($fk->getForeignColumns() $script .= " \$this->$collName = " . $fkPeerBuilder->getPeerClassname() . "::doSelectJoin$relCol2(\$criteria, \$con, \$join_behavior); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. "; foreach ($refFK->getForeignColumns() as $columnName) { $column = $table->getColumn($columnName); $flMap = $refFK->getForeignLocalMapping(); $colFKName = $flMap[$columnName]; $colFK = $tblFK->getColumn($colFKName); $clo = strtolower($column->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } /* end foreach ($fk->getForeignColumns() */ $script .= " if (!isset(\$this->$lastCriteriaName) || !\$this->" . $lastCriteriaName . "->equals(\$criteria)) { \$this->$collName = " . $fkPeerBuilder->getPeerClassname() . "::doSelectJoin$relCol2(\$criteria, \$con, \$join_behavior); } } \$this->$lastCriteriaName = \$criteria; return \$this->$collName; } "; } /* end if ($doJoinGet) */ } /* end foreach ($tblFK->getForeignKeys() as $fk2) { */ }
[ "protected", "function", "addRefFKGetJoinMethods", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "join_behavior", "=", "$", "this", "->", "getGeneratorConfig", "(", ")", "->", "getBuildProperty", "(", "'useLeftJoinsInDoJoinMethods'", ")", "?", "'Criteria::LEFT_JOIN'", ":", "'Criteria::INNER_JOIN'", ";", "$", "peerClassname", "=", "$", "this", "->", "getStubPeerBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "relCol", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "lastCriteriaName", "=", "$", "this", "->", "getRefFKLastCriteriaVarName", "(", "$", "refFK", ")", ";", "$", "fkPeerBuilder", "=", "$", "this", "->", "getNewPeerBuilder", "(", "$", "tblFK", ")", ";", "$", "lastTable", "=", "\"\"", ";", "foreach", "(", "$", "tblFK", "->", "getForeignKeys", "(", ")", "as", "$", "fk2", ")", "{", "$", "tblFK2", "=", "$", "this", "->", "getForeignTable", "(", "$", "fk2", ")", ";", "$", "doJoinGet", "=", "!", "$", "tblFK2", "->", "isForReferenceOnly", "(", ")", ";", "// it doesn't make sense to join in rows from the current table, since we are fetching", "// objects related to *this* table (i.e. the joined rows will all be the same row as current object)", "if", "(", "$", "this", "->", "getTable", "(", ")", "->", "getPhpName", "(", ")", "==", "$", "tblFK2", "->", "getPhpName", "(", ")", ")", "{", "$", "doJoinGet", "=", "false", ";", "}", "$", "relCol2", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk2", ",", "$", "plural", "=", "false", ")", ";", "if", "(", "$", "this", "->", "getRelatedBySuffix", "(", "$", "refFK", ")", "!=", "\"\"", "&&", "(", "$", "this", "->", "getRelatedBySuffix", "(", "$", "refFK", ")", "==", "$", "this", "->", "getRelatedBySuffix", "(", "$", "fk2", ")", ")", ")", "{", "$", "doJoinGet", "=", "false", ";", "}", "if", "(", "$", "doJoinGet", ")", "{", "$", "script", ".=", "\"\n\n /**\n * If this collection has already been initialized with\n * an identical criteria, it returns the collection.\n * Otherwise if this \"", ".", "$", "table", "->", "getPhpName", "(", ")", ".", "\" is new, it will return\n * an empty collection; or if this \"", ".", "$", "table", "->", "getPhpName", "(", ")", ".", "\" has previously\n * been saved, it will retrieve related $relCol from storage.\n *\n * This method is protected by default in order to keep the public\n * api reasonable. You can provide public methods for those you\n * actually need in \"", ".", "$", "table", "->", "getPhpName", "(", ")", ".", "\".\n */\n public function get\"", ".", "$", "relCol", ".", "\"Join\"", ".", "$", "relCol2", ".", "\"(\\$criteria = null, \\$con = null, \\$join_behavior = $join_behavior)\n {\"", ";", "$", "script", ".=", "\"\n if (\\$criteria === null) {\n \\$criteria = new Criteria($peerClassname::DATABASE_NAME);\n } elseif (\\$criteria instanceof Criteria) {\n \\$criteria = clone \\$criteria;\n }\n\n if (\\$this->$collName === null) {\n if (\\$this->isNew()) {\n \\$this->$collName = array();\n } else {\n\"", ";", "foreach", "(", "$", "refFK", "->", "getForeignColumns", "(", ")", "as", "$", "columnName", ")", "{", "$", "column", "=", "$", "table", "->", "getColumn", "(", "$", "columnName", ")", ";", "$", "flMap", "=", "$", "refFK", "->", "getForeignLocalMapping", "(", ")", ";", "$", "colFKName", "=", "$", "flMap", "[", "$", "columnName", "]", ";", "$", "colFK", "=", "$", "tblFK", "->", "getColumn", "(", "$", "colFKName", ")", ";", "if", "(", "$", "colFK", "===", "null", ")", "{", "throw", "new", "EngineException", "(", "\"Column $colFKName not found in \"", ".", "$", "tblFK", "->", "getName", "(", ")", ")", ";", "}", "$", "clo", "=", "strtolower", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n \\$criteria->add(\"", ".", "$", "fkPeerBuilder", "->", "getColumnConstant", "(", "$", "colFK", ")", ".", "\", \\$this->$clo);\n\"", ";", "}", "// end foreach ($fk->getForeignColumns()", "$", "script", ".=", "\"\n \\$this->$collName = \"", ".", "$", "fkPeerBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::doSelectJoin$relCol2(\\$criteria, \\$con, \\$join_behavior);\n }\n } else {\n // the following code is to determine if a new query is\n // called for. If the criteria is the same as the last\n // one, just return the collection.\n\"", ";", "foreach", "(", "$", "refFK", "->", "getForeignColumns", "(", ")", "as", "$", "columnName", ")", "{", "$", "column", "=", "$", "table", "->", "getColumn", "(", "$", "columnName", ")", ";", "$", "flMap", "=", "$", "refFK", "->", "getForeignLocalMapping", "(", ")", ";", "$", "colFKName", "=", "$", "flMap", "[", "$", "columnName", "]", ";", "$", "colFK", "=", "$", "tblFK", "->", "getColumn", "(", "$", "colFKName", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "column", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n \\$criteria->add(\"", ".", "$", "fkPeerBuilder", "->", "getColumnConstant", "(", "$", "colFK", ")", ".", "\", \\$this->$clo);\n\"", ";", "}", "/* end foreach ($fk->getForeignColumns() */", "$", "script", ".=", "\"\n if (!isset(\\$this->$lastCriteriaName) || !\\$this->\"", ".", "$", "lastCriteriaName", ".", "\"->equals(\\$criteria)) {\n \\$this->$collName = \"", ".", "$", "fkPeerBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::doSelectJoin$relCol2(\\$criteria, \\$con, \\$join_behavior);\n }\n }\n \\$this->$lastCriteriaName = \\$criteria;\n\n return \\$this->$collName;\n }\n\"", ";", "}", "/* end if ($doJoinGet) */", "}", "/* end foreach ($tblFK->getForeignKeys() as $fk2) { */", "}" ]
Adds the method that fetches fkey-related (referencing) objects but also joins in data from another table. @param string &$script The script will be modified in this method. @throws EngineException
[ "Adds", "the", "method", "that", "fetches", "fkey", "-", "related", "(", "referencing", ")", "objects", "but", "also", "joins", "in", "data", "from", "another", "table", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L594-L698
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addRefFKInit
protected function addRefFKInit(&$script, ForeignKey $refFK) { $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $script .= " /** * Initializes the $collName collection (array) . * * By default this just sets the $collName collection to an empty array (like clear$collName()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @return void */ public function init$relCol() { \$this->$collName = array(); } "; }
php
protected function addRefFKInit(&$script, ForeignKey $refFK) { $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $script .= " /** * Initializes the $collName collection (array) . * * By default this just sets the $collName collection to an empty array (like clear$collName()); * however, you may wish to override this method in your stub class to provide setting appropriate * to your application -- for example, setting the initial array to the values stored in database. * * @return void */ public function init$relCol() { \$this->$collName = array(); } "; }
[ "protected", "function", "addRefFKInit", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "relCol", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n /**\n * Initializes the $collName collection (array) .\n *\n * By default this just sets the $collName collection to an empty array (like clear$collName());\n * however, you may wish to override this method in your stub class to provide setting appropriate\n * to your application -- for example, setting the initial array to the values stored in database.\n *\n * @return void\n */\n public function init$relCol()\n {\n \\$this->$collName = array();\n }\n\"", ";", "}" ]
Adds the method that initializes the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "initializes", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L705-L725
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addRefFKAdd
protected function addRefFKAdd(&$script, ForeignKey $refFK) { $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $collName = $this->getRefFKCollVarName($refFK); $script .= " /** * Method called to associate a $className object to this object * through the $className foreign key attribute. * * @param $className \$l $className * @return void * @throws PropelException */ public function add" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "($className \$l) { if (\$this->$collName === null) { \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(); } if (!in_array(\$l, \$this->$collName, true)) { // only add it if the **same** object is not already associated array_push(\$this->$collName, \$l); \$l->set" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(\$this); } } "; }
php
protected function addRefFKAdd(&$script, ForeignKey $refFK) { $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $collName = $this->getRefFKCollVarName($refFK); $script .= " /** * Method called to associate a $className object to this object * through the $className foreign key attribute. * * @param $className \$l $className * @return void * @throws PropelException */ public function add" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "($className \$l) { if (\$this->$collName === null) { \$this->init" . $this->getRefFKPhpNameAffix($refFK, $plural = true) . "(); } if (!in_array(\$l, \$this->$collName, true)) { // only add it if the **same** object is not already associated array_push(\$this->$collName, \$l); \$l->set" . $this->getFKPhpNameAffix($refFK, $plural = false) . "(\$this); } } "; }
[ "protected", "function", "addRefFKAdd", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n /**\n * Method called to associate a $className object to this object\n * through the $className foreign key attribute.\n *\n * @param $className \\$l $className\n * @return void\n * @throws PropelException\n */\n public function add\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"($className \\$l)\n {\n if (\\$this->$collName === null) {\n \\$this->init\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ".", "\"();\n }\n if (!in_array(\\$l, \\$this->$collName, true)) { // only add it if the **same** object is not already associated\n array_push(\\$this->$collName, \\$l);\n \\$l->set\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"(\\$this);\n }\n }\n\"", ";", "}" ]
Adds the method that adds an object into the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "adds", "an", "object", "into", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L732-L761
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addRefFKCount
protected function addRefFKCount(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $peerClassname = $this->getStubPeerBuilder()->getClassname(); $fkPeerBuilder = $this->getNewPeerBuilder($refFK->getTable()); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK); $className = $fkPeerBuilder->getObjectClassname(); $script .= " /** * Returns the number of related $className objects. * * @param Criteria \$criteria * @param boolean \$distinct * @param PropelPDO \$con * @return int Count of related $className objects. * @throws PropelException */ public function count$relCol(Criteria \$criteria = null, \$distinct = false, PropelPDO \$con = null) {"; $script .= " if (\$criteria === null) { \$criteria = new Criteria($peerClassname::DATABASE_NAME); } else { \$criteria = clone \$criteria; } if (\$distinct) { \$criteria->setDistinct(); } \$count = null; if (\$this->$collName === null) { if (\$this->isNew()) { \$count = 0; } else { "; foreach ($refFK->getLocalColumns() as $colFKName) { // $colFKName is local to the referring table (i.e. foreign to this table) $lfmap = $refFK->getLocalForeignMapping(); $localColumn = $this->getTable()->getColumn($lfmap[$colFKName]); $colFK = $refFK->getTable()->getColumn($colFKName); $clo = strtolower($localColumn->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } // end foreach ($fk->getForeignColumns() $script .= " \$count = " . $fkPeerBuilder->getPeerClassname() . "::doCount(\$criteria, false, \$con); } } else { // criteria has no effect for a new object if (!\$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. "; foreach ($refFK->getLocalColumns() as $colFKName) { // $colFKName is local to the referring table (i.e. foreign to this table) $lfmap = $refFK->getLocalForeignMapping(); $localColumn = $this->getTable()->getColumn($lfmap[$colFKName]); $colFK = $refFK->getTable()->getColumn($colFKName); $clo = strtolower($localColumn->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } // foreach ($fk->getForeignColumns() $script .= " if (!isset(\$this->$lastCriteriaName) || !\$this->" . $lastCriteriaName . "->equals(\$criteria)) { \$count = " . $fkPeerBuilder->getPeerClassname() . "::doCount(\$criteria, false, \$con); } else { \$count = count(\$this->$collName); } } else { \$count = count(\$this->$collName); } } return \$count; } "; }
php
protected function addRefFKCount(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $peerClassname = $this->getStubPeerBuilder()->getClassname(); $fkPeerBuilder = $this->getNewPeerBuilder($refFK->getTable()); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true); $collName = $this->getRefFKCollVarName($refFK); $lastCriteriaName = $this->getRefFKLastCriteriaVarName($refFK); $className = $fkPeerBuilder->getObjectClassname(); $script .= " /** * Returns the number of related $className objects. * * @param Criteria \$criteria * @param boolean \$distinct * @param PropelPDO \$con * @return int Count of related $className objects. * @throws PropelException */ public function count$relCol(Criteria \$criteria = null, \$distinct = false, PropelPDO \$con = null) {"; $script .= " if (\$criteria === null) { \$criteria = new Criteria($peerClassname::DATABASE_NAME); } else { \$criteria = clone \$criteria; } if (\$distinct) { \$criteria->setDistinct(); } \$count = null; if (\$this->$collName === null) { if (\$this->isNew()) { \$count = 0; } else { "; foreach ($refFK->getLocalColumns() as $colFKName) { // $colFKName is local to the referring table (i.e. foreign to this table) $lfmap = $refFK->getLocalForeignMapping(); $localColumn = $this->getTable()->getColumn($lfmap[$colFKName]); $colFK = $refFK->getTable()->getColumn($colFKName); $clo = strtolower($localColumn->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } // end foreach ($fk->getForeignColumns() $script .= " \$count = " . $fkPeerBuilder->getPeerClassname() . "::doCount(\$criteria, false, \$con); } } else { // criteria has no effect for a new object if (!\$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. "; foreach ($refFK->getLocalColumns() as $colFKName) { // $colFKName is local to the referring table (i.e. foreign to this table) $lfmap = $refFK->getLocalForeignMapping(); $localColumn = $this->getTable()->getColumn($lfmap[$colFKName]); $colFK = $refFK->getTable()->getColumn($colFKName); $clo = strtolower($localColumn->getName()); $script .= " \$criteria->add(" . $fkPeerBuilder->getColumnConstant($colFK) . ", \$this->$clo); "; } // foreach ($fk->getForeignColumns() $script .= " if (!isset(\$this->$lastCriteriaName) || !\$this->" . $lastCriteriaName . "->equals(\$criteria)) { \$count = " . $fkPeerBuilder->getPeerClassname() . "::doCount(\$criteria, false, \$con); } else { \$count = count(\$this->$collName); } } else { \$count = count(\$this->$collName); } } return \$count; } "; }
[ "protected", "function", "addRefFKCount", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "peerClassname", "=", "$", "this", "->", "getStubPeerBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "fkPeerBuilder", "=", "$", "this", "->", "getNewPeerBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "relCol", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "true", ")", ";", "$", "collName", "=", "$", "this", "->", "getRefFKCollVarName", "(", "$", "refFK", ")", ";", "$", "lastCriteriaName", "=", "$", "this", "->", "getRefFKLastCriteriaVarName", "(", "$", "refFK", ")", ";", "$", "className", "=", "$", "fkPeerBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Returns the number of related $className objects.\n *\n * @param Criteria \\$criteria\n * @param boolean \\$distinct\n * @param PropelPDO \\$con\n * @return int Count of related $className objects.\n * @throws PropelException\n */\n public function count$relCol(Criteria \\$criteria = null, \\$distinct = false, PropelPDO \\$con = null)\n {\"", ";", "$", "script", ".=", "\"\n if (\\$criteria === null) {\n \\$criteria = new Criteria($peerClassname::DATABASE_NAME);\n } else {\n \\$criteria = clone \\$criteria;\n }\n\n if (\\$distinct) {\n \\$criteria->setDistinct();\n }\n\n \\$count = null;\n\n if (\\$this->$collName === null) {\n if (\\$this->isNew()) {\n \\$count = 0;\n } else {\n\"", ";", "foreach", "(", "$", "refFK", "->", "getLocalColumns", "(", ")", "as", "$", "colFKName", ")", "{", "// $colFKName is local to the referring table (i.e. foreign to this table)", "$", "lfmap", "=", "$", "refFK", "->", "getLocalForeignMapping", "(", ")", ";", "$", "localColumn", "=", "$", "this", "->", "getTable", "(", ")", "->", "getColumn", "(", "$", "lfmap", "[", "$", "colFKName", "]", ")", ";", "$", "colFK", "=", "$", "refFK", "->", "getTable", "(", ")", "->", "getColumn", "(", "$", "colFKName", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "localColumn", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n \\$criteria->add(\"", ".", "$", "fkPeerBuilder", "->", "getColumnConstant", "(", "$", "colFK", ")", ".", "\", \\$this->$clo);\n\"", ";", "}", "// end foreach ($fk->getForeignColumns()", "$", "script", ".=", "\"\n \\$count = \"", ".", "$", "fkPeerBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::doCount(\\$criteria, false, \\$con);\n }\n } else {\n // criteria has no effect for a new object\n if (!\\$this->isNew()) {\n // the following code is to determine if a new query is\n // called for. If the criteria is the same as the last\n // one, just return count of the collection.\n\"", ";", "foreach", "(", "$", "refFK", "->", "getLocalColumns", "(", ")", "as", "$", "colFKName", ")", "{", "// $colFKName is local to the referring table (i.e. foreign to this table)", "$", "lfmap", "=", "$", "refFK", "->", "getLocalForeignMapping", "(", ")", ";", "$", "localColumn", "=", "$", "this", "->", "getTable", "(", ")", "->", "getColumn", "(", "$", "lfmap", "[", "$", "colFKName", "]", ")", ";", "$", "colFK", "=", "$", "refFK", "->", "getTable", "(", ")", "->", "getColumn", "(", "$", "colFKName", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "localColumn", "->", "getName", "(", ")", ")", ";", "$", "script", ".=", "\"\n\n \\$criteria->add(\"", ".", "$", "fkPeerBuilder", "->", "getColumnConstant", "(", "$", "colFK", ")", ".", "\", \\$this->$clo);\n\"", ";", "}", "// foreach ($fk->getForeignColumns()", "$", "script", ".=", "\"\n if (!isset(\\$this->$lastCriteriaName) || !\\$this->\"", ".", "$", "lastCriteriaName", ".", "\"->equals(\\$criteria)) {\n \\$count = \"", ".", "$", "fkPeerBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::doCount(\\$criteria, false, \\$con);\n } else {\n \\$count = count(\\$this->$collName);\n }\n } else {\n \\$count = count(\\$this->$collName);\n }\n }\n\n return \\$count;\n }\n\"", ";", "}" ]
Adds the method that returns the size of the referrer fkey collection. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "returns", "the", "size", "of", "the", "referrer", "fkey", "collection", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L768-L860
propelorm/Propel
generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php
PHP5ObjectNoCollectionBuilder.addPKRefFKGet
protected function addPKRefFKGet(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $joinedTablePeerBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $varName = $this->getPKRefFKVarName($refFK); $script .= " /** * Gets a single $className object, which is related to this object by a one-to-one relationship. * * @param PropelPDO \$con * @return $className * @throws PropelException */ public function get" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(PropelPDO \$con = null) { "; $script .= " if (\$this->$varName === null && !\$this->isNew()) {"; $lfmap = $refFK->getLocalForeignMapping(); // remember: this object represents the foreign table, // so we need foreign columns of the reffk to know the local columns // that we need to set :) $localcols = $refFK->getForeignColumns(); // we know that at least every column in the primary key of the foreign table // is represented in this foreign key $params = array(); foreach ($tblFK->getPrimaryKey() as $col) { $localColumn = $table->getColumn($lfmap[$col->getName()]); $clo = strtolower($localColumn->getName()); $params[] = "\$this->$clo"; } $script .= " \$this->$varName = " . $joinedTableObjectBuilder->getPeerClassname() . "::retrieveByPK(" . implode(", ", $params) . ", \$con); } return \$this->$varName; } "; }
php
protected function addPKRefFKGet(&$script, ForeignKey $refFK) { $table = $this->getTable(); $tblFK = $refFK->getTable(); $joinedTableObjectBuilder = $this->getNewObjectBuilder($refFK->getTable()); $joinedTablePeerBuilder = $this->getNewObjectBuilder($refFK->getTable()); $className = $joinedTableObjectBuilder->getObjectClassname(); $varName = $this->getPKRefFKVarName($refFK); $script .= " /** * Gets a single $className object, which is related to this object by a one-to-one relationship. * * @param PropelPDO \$con * @return $className * @throws PropelException */ public function get" . $this->getRefFKPhpNameAffix($refFK, $plural = false) . "(PropelPDO \$con = null) { "; $script .= " if (\$this->$varName === null && !\$this->isNew()) {"; $lfmap = $refFK->getLocalForeignMapping(); // remember: this object represents the foreign table, // so we need foreign columns of the reffk to know the local columns // that we need to set :) $localcols = $refFK->getForeignColumns(); // we know that at least every column in the primary key of the foreign table // is represented in this foreign key $params = array(); foreach ($tblFK->getPrimaryKey() as $col) { $localColumn = $table->getColumn($lfmap[$col->getName()]); $clo = strtolower($localColumn->getName()); $params[] = "\$this->$clo"; } $script .= " \$this->$varName = " . $joinedTableObjectBuilder->getPeerClassname() . "::retrieveByPK(" . implode(", ", $params) . ", \$con); } return \$this->$varName; } "; }
[ "protected", "function", "addPKRefFKGet", "(", "&", "$", "script", ",", "ForeignKey", "$", "refFK", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tblFK", "=", "$", "refFK", "->", "getTable", "(", ")", ";", "$", "joinedTableObjectBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "joinedTablePeerBuilder", "=", "$", "this", "->", "getNewObjectBuilder", "(", "$", "refFK", "->", "getTable", "(", ")", ")", ";", "$", "className", "=", "$", "joinedTableObjectBuilder", "->", "getObjectClassname", "(", ")", ";", "$", "varName", "=", "$", "this", "->", "getPKRefFKVarName", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n /**\n * Gets a single $className object, which is related to this object by a one-to-one relationship.\n *\n * @param PropelPDO \\$con\n * @return $className\n * @throws PropelException\n */\n public function get\"", ".", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ",", "$", "plural", "=", "false", ")", ".", "\"(PropelPDO \\$con = null)\n {\n\"", ";", "$", "script", ".=", "\"\n if (\\$this->$varName === null && !\\$this->isNew()) {\"", ";", "$", "lfmap", "=", "$", "refFK", "->", "getLocalForeignMapping", "(", ")", ";", "// remember: this object represents the foreign table,", "// so we need foreign columns of the reffk to know the local columns", "// that we need to set :)", "$", "localcols", "=", "$", "refFK", "->", "getForeignColumns", "(", ")", ";", "// we know that at least every column in the primary key of the foreign table", "// is represented in this foreign key", "$", "params", "=", "array", "(", ")", ";", "foreach", "(", "$", "tblFK", "->", "getPrimaryKey", "(", ")", "as", "$", "col", ")", "{", "$", "localColumn", "=", "$", "table", "->", "getColumn", "(", "$", "lfmap", "[", "$", "col", "->", "getName", "(", ")", "]", ")", ";", "$", "clo", "=", "strtolower", "(", "$", "localColumn", "->", "getName", "(", ")", ")", ";", "$", "params", "[", "]", "=", "\"\\$this->$clo\"", ";", "}", "$", "script", ".=", "\"\n \\$this->$varName = \"", ".", "$", "joinedTableObjectBuilder", "->", "getPeerClassname", "(", ")", ".", "\"::retrieveByPK(\"", ".", "implode", "(", "\", \"", ",", "$", "params", ")", ".", "\", \\$con);\n }\n\n return \\$this->$varName;\n }\n\"", ";", "}" ]
Adds the method that gets a one-to-one related referrer fkey. This is for one-to-one relationship special case. @param string &$script The script will be modified in this method.
[ "Adds", "the", "method", "that", "gets", "a", "one", "-", "to", "-", "one", "related", "referrer", "fkey", ".", "This", "is", "for", "one", "-", "to", "-", "one", "relationship", "special", "case", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ObjectNoCollectionBuilder.php#L965-L1015
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.init
public function init(Criteria $criteria) { // init $this->db try { $db = Propel::getDB($criteria->getDbName()); $this->setDB($db); } catch (Exception $e) { // we are only doing this to allow easier debugging, so // no need to throw up the exception, just make note of it. Propel::log("Could not get a DBAdapter, sql may be wrong", Propel::LOG_ERR); } // init $this->realtable $realtable = $criteria->getTableForAlias($this->table); $this->realtable = $realtable ? $realtable : $this->table; }
php
public function init(Criteria $criteria) { // init $this->db try { $db = Propel::getDB($criteria->getDbName()); $this->setDB($db); } catch (Exception $e) { // we are only doing this to allow easier debugging, so // no need to throw up the exception, just make note of it. Propel::log("Could not get a DBAdapter, sql may be wrong", Propel::LOG_ERR); } // init $this->realtable $realtable = $criteria->getTableForAlias($this->table); $this->realtable = $realtable ? $realtable : $this->table; }
[ "public", "function", "init", "(", "Criteria", "$", "criteria", ")", "{", "// init $this->db", "try", "{", "$", "db", "=", "Propel", "::", "getDB", "(", "$", "criteria", "->", "getDbName", "(", ")", ")", ";", "$", "this", "->", "setDB", "(", "$", "db", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// we are only doing this to allow easier debugging, so", "// no need to throw up the exception, just make note of it.", "Propel", "::", "log", "(", "\"Could not get a DBAdapter, sql may be wrong\"", ",", "Propel", "::", "LOG_ERR", ")", ";", "}", "// init $this->realtable", "$", "realtable", "=", "$", "criteria", "->", "getTableForAlias", "(", "$", "this", "->", "table", ")", ";", "$", "this", "->", "realtable", "=", "$", "realtable", "?", "$", "realtable", ":", "$", "this", "->", "table", ";", "}" ]
Init some properties with the help of outer class @param Criteria $criteria The outer class
[ "Init", "some", "properties", "with", "the", "help", "of", "outer", "class" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L102-L117
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.setDB
public function setDB(DBAdapter $v) { $this->db = $v; foreach ($this->clauses as $clause) { $clause->setDB($v); } }
php
public function setDB(DBAdapter $v) { $this->db = $v; foreach ($this->clauses as $clause) { $clause->setDB($v); } }
[ "public", "function", "setDB", "(", "DBAdapter", "$", "v", ")", "{", "$", "this", "->", "db", "=", "$", "v", ";", "foreach", "(", "$", "this", "->", "clauses", "as", "$", "clause", ")", "{", "$", "clause", "->", "setDB", "(", "$", "v", ")", ";", "}", "}" ]
Set the value of db. The DBAdapter might be used to get db specific variations of sql. @param DBAdapter $v Value to assign to db. @return void
[ "Set", "the", "value", "of", "db", ".", "The", "DBAdapter", "might", "be", "used", "to", "get", "db", "specific", "variations", "of", "sql", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L191-L197
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.addAnd
public function addAnd(Criterion $criterion) { $this->clauses[] = $criterion; $this->conjunctions[] = self::UND; return $this; }
php
public function addAnd(Criterion $criterion) { $this->clauses[] = $criterion; $this->conjunctions[] = self::UND; return $this; }
[ "public", "function", "addAnd", "(", "Criterion", "$", "criterion", ")", "{", "$", "this", "->", "clauses", "[", "]", "=", "$", "criterion", ";", "$", "this", "->", "conjunctions", "[", "]", "=", "self", "::", "UND", ";", "return", "$", "this", ";", "}" ]
Append an AND Criterion onto this Criterion's list.
[ "Append", "an", "AND", "Criterion", "onto", "this", "Criterion", "s", "list", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L246-L252
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.addOr
public function addOr(Criterion $criterion) { $this->clauses[] = $criterion; $this->conjunctions[] = self::ODER; return $this; }
php
public function addOr(Criterion $criterion) { $this->clauses[] = $criterion; $this->conjunctions[] = self::ODER; return $this; }
[ "public", "function", "addOr", "(", "Criterion", "$", "criterion", ")", "{", "$", "this", "->", "clauses", "[", "]", "=", "$", "criterion", ";", "$", "this", "->", "conjunctions", "[", "]", "=", "self", "::", "ODER", ";", "return", "$", "this", ";", "}" ]
Append an OR Criterion onto this Criterion's list. @param Criterion $criterion @return Criterion
[ "Append", "an", "OR", "Criterion", "onto", "this", "Criterion", "s", "list", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L261-L267
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.appendPsTo
public function appendPsTo(&$sb, array &$params) { $sb .= str_repeat('(', count($this->clauses)); $this->dispatchPsHandling($sb, $params); foreach ($this->clauses as $key => $clause) { $sb .= $this->conjunctions[$key]; $clause->appendPsTo($sb, $params); $sb .= ')'; } }
php
public function appendPsTo(&$sb, array &$params) { $sb .= str_repeat('(', count($this->clauses)); $this->dispatchPsHandling($sb, $params); foreach ($this->clauses as $key => $clause) { $sb .= $this->conjunctions[$key]; $clause->appendPsTo($sb, $params); $sb .= ')'; } }
[ "public", "function", "appendPsTo", "(", "&", "$", "sb", ",", "array", "&", "$", "params", ")", "{", "$", "sb", ".=", "str_repeat", "(", "'('", ",", "count", "(", "$", "this", "->", "clauses", ")", ")", ";", "$", "this", "->", "dispatchPsHandling", "(", "$", "sb", ",", "$", "params", ")", ";", "foreach", "(", "$", "this", "->", "clauses", "as", "$", "key", "=>", "$", "clause", ")", "{", "$", "sb", ".=", "$", "this", "->", "conjunctions", "[", "$", "key", "]", ";", "$", "clause", "->", "appendPsTo", "(", "$", "sb", ",", "$", "params", ")", ";", "$", "sb", ".=", "')'", ";", "}", "}" ]
Appends a Prepared Statement representation of the Criterion onto the buffer. @param string &$sb The string that will receive the Prepared Statement @param array $params A list to which Prepared Statement parameters will be appended @return void @throws PropelException - if the expression builder cannot figure out how to turn a specified expression into proper SQL.
[ "Appends", "a", "Prepared", "Statement", "representation", "of", "the", "Criterion", "onto", "the", "buffer", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L280-L291
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.dispatchPsHandling
protected function dispatchPsHandling(&$sb, array &$params) { switch ($this->comparison) { case Criteria::CUSTOM: // custom expression with no parameter binding $this->appendCustomToPs($sb, $params); break; case Criteria::RAW: // custom expression with a typed parameter binding $this->appendRawToPs($sb, $params); break; case Criteria::IN: case Criteria::NOT_IN: // table.column IN (?, ?) or table.column NOT IN (?, ?) $this->appendInToPs($sb, $params); break; case Criteria::LIKE: case Criteria::NOT_LIKE: case Criteria::ILIKE: case Criteria::NOT_ILIKE: // table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres) $this->appendLikeToPs($sb, $params); break; default: // table.column = ? or table.column >= ? etc. (traditional expressions, the default) $this->appendBasicToPs($sb, $params); } }
php
protected function dispatchPsHandling(&$sb, array &$params) { switch ($this->comparison) { case Criteria::CUSTOM: // custom expression with no parameter binding $this->appendCustomToPs($sb, $params); break; case Criteria::RAW: // custom expression with a typed parameter binding $this->appendRawToPs($sb, $params); break; case Criteria::IN: case Criteria::NOT_IN: // table.column IN (?, ?) or table.column NOT IN (?, ?) $this->appendInToPs($sb, $params); break; case Criteria::LIKE: case Criteria::NOT_LIKE: case Criteria::ILIKE: case Criteria::NOT_ILIKE: // table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres) $this->appendLikeToPs($sb, $params); break; default: // table.column = ? or table.column >= ? etc. (traditional expressions, the default) $this->appendBasicToPs($sb, $params); } }
[ "protected", "function", "dispatchPsHandling", "(", "&", "$", "sb", ",", "array", "&", "$", "params", ")", "{", "switch", "(", "$", "this", "->", "comparison", ")", "{", "case", "Criteria", "::", "CUSTOM", ":", "// custom expression with no parameter binding", "$", "this", "->", "appendCustomToPs", "(", "$", "sb", ",", "$", "params", ")", ";", "break", ";", "case", "Criteria", "::", "RAW", ":", "// custom expression with a typed parameter binding", "$", "this", "->", "appendRawToPs", "(", "$", "sb", ",", "$", "params", ")", ";", "break", ";", "case", "Criteria", "::", "IN", ":", "case", "Criteria", "::", "NOT_IN", ":", "// table.column IN (?, ?) or table.column NOT IN (?, ?)", "$", "this", "->", "appendInToPs", "(", "$", "sb", ",", "$", "params", ")", ";", "break", ";", "case", "Criteria", "::", "LIKE", ":", "case", "Criteria", "::", "NOT_LIKE", ":", "case", "Criteria", "::", "ILIKE", ":", "case", "Criteria", "::", "NOT_ILIKE", ":", "// table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres)", "$", "this", "->", "appendLikeToPs", "(", "$", "sb", ",", "$", "params", ")", ";", "break", ";", "default", ":", "// table.column = ? or table.column >= ? etc. (traditional expressions, the default)", "$", "this", "->", "appendBasicToPs", "(", "$", "sb", ",", "$", "params", ")", ";", "}", "}" ]
Figure out which Criterion method to use to build the prepared statement and parameters using to the Criterion comparison and call it to append the prepared statement and the parameters of the current clause @param string &$sb The string that will receive the Prepared Statement @param array $params A list to which Prepared Statement parameters will be appended
[ "Figure", "out", "which", "Criterion", "method", "to", "use", "to", "build", "the", "prepared", "statement", "and", "parameters", "using", "to", "the", "Criterion", "comparison", "and", "call", "it", "to", "append", "the", "prepared", "statement", "and", "the", "parameters", "of", "the", "current", "clause" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L301-L328
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.appendInToPs
protected function appendInToPs(&$sb, array &$params) { if ($this->value !== "") { $bindParams = array(); $index = count($params); // to avoid counting the number of parameters for each element in the array foreach ((array) $this->value as $value) { $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value); $index++; // increment this first to correct for wanting bind params to start with :p1 $bindParams[] = ':p' . $index; } if (count($bindParams)) { $field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column; $sb .= $field . $this->comparison . '(' . implode(',', $bindParams) . ')'; } else { $sb .= ($this->comparison === Criteria::IN) ? "1<>1" : "1=1"; } } }
php
protected function appendInToPs(&$sb, array &$params) { if ($this->value !== "") { $bindParams = array(); $index = count($params); // to avoid counting the number of parameters for each element in the array foreach ((array) $this->value as $value) { $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value); $index++; // increment this first to correct for wanting bind params to start with :p1 $bindParams[] = ':p' . $index; } if (count($bindParams)) { $field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column; $sb .= $field . $this->comparison . '(' . implode(',', $bindParams) . ')'; } else { $sb .= ($this->comparison === Criteria::IN) ? "1<>1" : "1=1"; } } }
[ "protected", "function", "appendInToPs", "(", "&", "$", "sb", ",", "array", "&", "$", "params", ")", "{", "if", "(", "$", "this", "->", "value", "!==", "\"\"", ")", "{", "$", "bindParams", "=", "array", "(", ")", ";", "$", "index", "=", "count", "(", "$", "params", ")", ";", "// to avoid counting the number of parameters for each element in the array", "foreach", "(", "(", "array", ")", "$", "this", "->", "value", "as", "$", "value", ")", "{", "$", "params", "[", "]", "=", "array", "(", "'table'", "=>", "$", "this", "->", "realtable", ",", "'column'", "=>", "$", "this", "->", "column", ",", "'value'", "=>", "$", "value", ")", ";", "$", "index", "++", ";", "// increment this first to correct for wanting bind params to start with :p1", "$", "bindParams", "[", "]", "=", "':p'", ".", "$", "index", ";", "}", "if", "(", "count", "(", "$", "bindParams", ")", ")", "{", "$", "field", "=", "(", "$", "this", "->", "table", "===", "null", ")", "?", "$", "this", "->", "column", ":", "$", "this", "->", "table", ".", "'.'", ".", "$", "this", "->", "column", ";", "$", "sb", ".=", "$", "field", ".", "$", "this", "->", "comparison", ".", "'('", ".", "implode", "(", "','", ",", "$", "bindParams", ")", ".", "')'", ";", "}", "else", "{", "$", "sb", ".=", "(", "$", "this", "->", "comparison", "===", "Criteria", "::", "IN", ")", "?", "\"1<>1\"", ":", "\"1=1\"", ";", "}", "}", "}" ]
Appends a Prepared Statement representation of the Criterion onto the buffer For IN expressions, e.g. table.column IN (?, ?) or table.column NOT IN (?, ?) @param string &$sb The string that will receive the Prepared Statement @param array $params A list to which Prepared Statement parameters will be appended
[ "Appends", "a", "Prepared", "Statement", "representation", "of", "the", "Criterion", "onto", "the", "buffer", "For", "IN", "expressions", "e", ".", "g", ".", "table", ".", "column", "IN", "(", "?", "?", ")", "or", "table", ".", "column", "NOT", "IN", "(", "?", "?", ")" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L369-L386
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.appendLikeToPs
protected function appendLikeToPs(&$sb, array &$params) { $field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column; $db = $this->getDb(); // If selection is case insensitive use ILIKE for PostgreSQL or SQL // UPPER() function on column name for other databases. if ($this->ignoreStringCase) { if ($db instanceof DBPostgres) { if ($this->comparison === Criteria::LIKE) { $this->comparison = Criteria::ILIKE; } elseif ($this->comparison === Criteria::NOT_LIKE) { $this->comparison = Criteria::NOT_ILIKE; } } else { $field = $db->ignoreCase($field); } } $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value); $sb .= $field . $this->comparison; // If selection is case insensitive use SQL UPPER() function // on criteria or, if Postgres we are using ILIKE, so not necessary. if ($this->ignoreStringCase && !($db instanceof DBPostgres)) { $sb .= $db->ignoreCase(':p' . count($params)); } else { $sb .= ':p' . count($params); } }
php
protected function appendLikeToPs(&$sb, array &$params) { $field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column; $db = $this->getDb(); // If selection is case insensitive use ILIKE for PostgreSQL or SQL // UPPER() function on column name for other databases. if ($this->ignoreStringCase) { if ($db instanceof DBPostgres) { if ($this->comparison === Criteria::LIKE) { $this->comparison = Criteria::ILIKE; } elseif ($this->comparison === Criteria::NOT_LIKE) { $this->comparison = Criteria::NOT_ILIKE; } } else { $field = $db->ignoreCase($field); } } $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value); $sb .= $field . $this->comparison; // If selection is case insensitive use SQL UPPER() function // on criteria or, if Postgres we are using ILIKE, so not necessary. if ($this->ignoreStringCase && !($db instanceof DBPostgres)) { $sb .= $db->ignoreCase(':p' . count($params)); } else { $sb .= ':p' . count($params); } }
[ "protected", "function", "appendLikeToPs", "(", "&", "$", "sb", ",", "array", "&", "$", "params", ")", "{", "$", "field", "=", "(", "$", "this", "->", "table", "===", "null", ")", "?", "$", "this", "->", "column", ":", "$", "this", "->", "table", ".", "'.'", ".", "$", "this", "->", "column", ";", "$", "db", "=", "$", "this", "->", "getDb", "(", ")", ";", "// If selection is case insensitive use ILIKE for PostgreSQL or SQL", "// UPPER() function on column name for other databases.", "if", "(", "$", "this", "->", "ignoreStringCase", ")", "{", "if", "(", "$", "db", "instanceof", "DBPostgres", ")", "{", "if", "(", "$", "this", "->", "comparison", "===", "Criteria", "::", "LIKE", ")", "{", "$", "this", "->", "comparison", "=", "Criteria", "::", "ILIKE", ";", "}", "elseif", "(", "$", "this", "->", "comparison", "===", "Criteria", "::", "NOT_LIKE", ")", "{", "$", "this", "->", "comparison", "=", "Criteria", "::", "NOT_ILIKE", ";", "}", "}", "else", "{", "$", "field", "=", "$", "db", "->", "ignoreCase", "(", "$", "field", ")", ";", "}", "}", "$", "params", "[", "]", "=", "array", "(", "'table'", "=>", "$", "this", "->", "realtable", ",", "'column'", "=>", "$", "this", "->", "column", ",", "'value'", "=>", "$", "this", "->", "value", ")", ";", "$", "sb", ".=", "$", "field", ".", "$", "this", "->", "comparison", ";", "// If selection is case insensitive use SQL UPPER() function", "// on criteria or, if Postgres we are using ILIKE, so not necessary.", "if", "(", "$", "this", "->", "ignoreStringCase", "&&", "!", "(", "$", "db", "instanceof", "DBPostgres", ")", ")", "{", "$", "sb", ".=", "$", "db", "->", "ignoreCase", "(", "':p'", ".", "count", "(", "$", "params", ")", ")", ";", "}", "else", "{", "$", "sb", ".=", "':p'", ".", "count", "(", "$", "params", ")", ";", "}", "}" ]
Appends a Prepared Statement representation of the Criterion onto the buffer For LIKE expressions, e.g. table.column LIKE ? or table.column NOT LIKE ? (or ILIKE for Postgres) @param string &$sb The string that will receive the Prepared Statement @param array $params A list to which Prepared Statement parameters will be appended
[ "Appends", "a", "Prepared", "Statement", "representation", "of", "the", "Criterion", "onto", "the", "buffer", "For", "LIKE", "expressions", "e", ".", "g", ".", "table", ".", "column", "LIKE", "?", "or", "table", ".", "column", "NOT", "LIKE", "?", "(", "or", "ILIKE", "for", "Postgres", ")" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L395-L424
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.appendBasicToPs
protected function appendBasicToPs(&$sb, array &$params) { $field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column; // NULL VALUES need special treatment because the SQL syntax is different // i.e. table.column IS NULL rather than table.column = null if ($this->value !== null) { // ANSI SQL functions get inserted right into SQL (not escaped, etc.) if ($this->value === Criteria::CURRENT_DATE || $this->value === Criteria::CURRENT_TIME || $this->value === Criteria::CURRENT_TIMESTAMP) { $sb .= $field . $this->comparison . $this->value; } else { $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value); // default case, it is a normal col = value expression; value // will be replaced w/ '?' and will be inserted later using PDO bindValue() if ($this->ignoreStringCase) { $sb .= $this->getDb()->ignoreCase($field) . $this->comparison . $this->getDb()->ignoreCase(':p' . count($params)); } else { $sb .= $field . $this->comparison . ':p' . count($params); } } } else { // value is null, which means it was either not specified or specifically // set to null. if ($this->comparison === Criteria::EQUAL || $this->comparison === Criteria::ISNULL) { $sb .= $field . Criteria::ISNULL; } elseif ($this->comparison === Criteria::NOT_EQUAL || $this->comparison === Criteria::ISNOTNULL) { $sb .= $field . Criteria::ISNOTNULL; } else { // for now throw an exception, because not sure how to interpret this throw new PropelException("Could not build SQL for expression: $field " . $this->comparison . " NULL"); } } }
php
protected function appendBasicToPs(&$sb, array &$params) { $field = ($this->table === null) ? $this->column : $this->table . '.' . $this->column; // NULL VALUES need special treatment because the SQL syntax is different // i.e. table.column IS NULL rather than table.column = null if ($this->value !== null) { // ANSI SQL functions get inserted right into SQL (not escaped, etc.) if ($this->value === Criteria::CURRENT_DATE || $this->value === Criteria::CURRENT_TIME || $this->value === Criteria::CURRENT_TIMESTAMP) { $sb .= $field . $this->comparison . $this->value; } else { $params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value); // default case, it is a normal col = value expression; value // will be replaced w/ '?' and will be inserted later using PDO bindValue() if ($this->ignoreStringCase) { $sb .= $this->getDb()->ignoreCase($field) . $this->comparison . $this->getDb()->ignoreCase(':p' . count($params)); } else { $sb .= $field . $this->comparison . ':p' . count($params); } } } else { // value is null, which means it was either not specified or specifically // set to null. if ($this->comparison === Criteria::EQUAL || $this->comparison === Criteria::ISNULL) { $sb .= $field . Criteria::ISNULL; } elseif ($this->comparison === Criteria::NOT_EQUAL || $this->comparison === Criteria::ISNOTNULL) { $sb .= $field . Criteria::ISNOTNULL; } else { // for now throw an exception, because not sure how to interpret this throw new PropelException("Could not build SQL for expression: $field " . $this->comparison . " NULL"); } } }
[ "protected", "function", "appendBasicToPs", "(", "&", "$", "sb", ",", "array", "&", "$", "params", ")", "{", "$", "field", "=", "(", "$", "this", "->", "table", "===", "null", ")", "?", "$", "this", "->", "column", ":", "$", "this", "->", "table", ".", "'.'", ".", "$", "this", "->", "column", ";", "// NULL VALUES need special treatment because the SQL syntax is different", "// i.e. table.column IS NULL rather than table.column = null", "if", "(", "$", "this", "->", "value", "!==", "null", ")", "{", "// ANSI SQL functions get inserted right into SQL (not escaped, etc.)", "if", "(", "$", "this", "->", "value", "===", "Criteria", "::", "CURRENT_DATE", "||", "$", "this", "->", "value", "===", "Criteria", "::", "CURRENT_TIME", "||", "$", "this", "->", "value", "===", "Criteria", "::", "CURRENT_TIMESTAMP", ")", "{", "$", "sb", ".=", "$", "field", ".", "$", "this", "->", "comparison", ".", "$", "this", "->", "value", ";", "}", "else", "{", "$", "params", "[", "]", "=", "array", "(", "'table'", "=>", "$", "this", "->", "realtable", ",", "'column'", "=>", "$", "this", "->", "column", ",", "'value'", "=>", "$", "this", "->", "value", ")", ";", "// default case, it is a normal col = value expression; value", "// will be replaced w/ '?' and will be inserted later using PDO bindValue()", "if", "(", "$", "this", "->", "ignoreStringCase", ")", "{", "$", "sb", ".=", "$", "this", "->", "getDb", "(", ")", "->", "ignoreCase", "(", "$", "field", ")", ".", "$", "this", "->", "comparison", ".", "$", "this", "->", "getDb", "(", ")", "->", "ignoreCase", "(", "':p'", ".", "count", "(", "$", "params", ")", ")", ";", "}", "else", "{", "$", "sb", ".=", "$", "field", ".", "$", "this", "->", "comparison", ".", "':p'", ".", "count", "(", "$", "params", ")", ";", "}", "}", "}", "else", "{", "// value is null, which means it was either not specified or specifically", "// set to null.", "if", "(", "$", "this", "->", "comparison", "===", "Criteria", "::", "EQUAL", "||", "$", "this", "->", "comparison", "===", "Criteria", "::", "ISNULL", ")", "{", "$", "sb", ".=", "$", "field", ".", "Criteria", "::", "ISNULL", ";", "}", "elseif", "(", "$", "this", "->", "comparison", "===", "Criteria", "::", "NOT_EQUAL", "||", "$", "this", "->", "comparison", "===", "Criteria", "::", "ISNOTNULL", ")", "{", "$", "sb", ".=", "$", "field", ".", "Criteria", "::", "ISNOTNULL", ";", "}", "else", "{", "// for now throw an exception, because not sure how to interpret this", "throw", "new", "PropelException", "(", "\"Could not build SQL for expression: $field \"", ".", "$", "this", "->", "comparison", ".", "\" NULL\"", ")", ";", "}", "}", "}" ]
Appends a Prepared Statement representation of the Criterion onto the buffer For traditional expressions, e.g. table.column = ? or table.column >= ? etc. @param string &$sb The string that will receive the Prepared Statement @param array $params A list to which Prepared Statement parameters will be appended @throws PropelException
[ "Appends", "a", "Prepared", "Statement", "representation", "of", "the", "Criterion", "onto", "the", "buffer", "For", "traditional", "expressions", "e", ".", "g", ".", "table", ".", "column", "=", "?", "or", "table", ".", "column", ">", "=", "?", "etc", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L435-L470
propelorm/Propel
runtime/lib/query/Criterion.php
Criterion.hashCode
public function hashCode() { $h = crc32(serialize($this->value)) ^ crc32($this->comparison); if ($this->table !== null) { $h ^= crc32($this->table); } if ($this->column !== null) { $h ^= crc32($this->column); } foreach ($this->clauses as $clause) { // TODO: I KNOW there is a php incompatibility with the following line // but I don't remember what it is, someone care to look it up and // replace it if it doesn't bother us? // $clause->appendPsTo($sb='',$params=array()); $sb = ''; $params = array(); $clause->appendPsTo($sb, $params); $h ^= crc32(serialize(array($sb, $params))); unset ($sb, $params); } return $h; }
php
public function hashCode() { $h = crc32(serialize($this->value)) ^ crc32($this->comparison); if ($this->table !== null) { $h ^= crc32($this->table); } if ($this->column !== null) { $h ^= crc32($this->column); } foreach ($this->clauses as $clause) { // TODO: I KNOW there is a php incompatibility with the following line // but I don't remember what it is, someone care to look it up and // replace it if it doesn't bother us? // $clause->appendPsTo($sb='',$params=array()); $sb = ''; $params = array(); $clause->appendPsTo($sb, $params); $h ^= crc32(serialize(array($sb, $params))); unset ($sb, $params); } return $h; }
[ "public", "function", "hashCode", "(", ")", "{", "$", "h", "=", "crc32", "(", "serialize", "(", "$", "this", "->", "value", ")", ")", "^", "crc32", "(", "$", "this", "->", "comparison", ")", ";", "if", "(", "$", "this", "->", "table", "!==", "null", ")", "{", "$", "h", "^=", "crc32", "(", "$", "this", "->", "table", ")", ";", "}", "if", "(", "$", "this", "->", "column", "!==", "null", ")", "{", "$", "h", "^=", "crc32", "(", "$", "this", "->", "column", ")", ";", "}", "foreach", "(", "$", "this", "->", "clauses", "as", "$", "clause", ")", "{", "// TODO: I KNOW there is a php incompatibility with the following line", "// but I don't remember what it is, someone care to look it up and", "// replace it if it doesn't bother us?", "// $clause->appendPsTo($sb='',$params=array());", "$", "sb", "=", "''", ";", "$", "params", "=", "array", "(", ")", ";", "$", "clause", "->", "appendPsTo", "(", "$", "sb", ",", "$", "params", ")", ";", "$", "h", "^=", "crc32", "(", "serialize", "(", "array", "(", "$", "sb", ",", "$", "params", ")", ")", ")", ";", "unset", "(", "$", "sb", ",", "$", "params", ")", ";", "}", "return", "$", "h", ";", "}" ]
Returns a hash code value for the object.
[ "Returns", "a", "hash", "code", "value", "for", "the", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/Criterion.php#L520-L545
propelorm/Propel
generator/lib/builder/om/OMBuilder.php
OMBuilder.build
public function build() { $this->validateModel(); $script = ''; if ($this->isAddIncludes()) { $this->addIncludes($script); } $this->addClassOpen($script); $this->addClassBody($script); $this->addClassClose($script); if ($useStatements = $this->getUseStatements($ignoredNamespace = $this->getNamespace())) { $script = $useStatements . $script; } if ($namespaceStatement = $this->getNamespaceStatement()) { $script = $namespaceStatement . $script; } $script = "<?php " . $script; return $this->clean($script); }
php
public function build() { $this->validateModel(); $script = ''; if ($this->isAddIncludes()) { $this->addIncludes($script); } $this->addClassOpen($script); $this->addClassBody($script); $this->addClassClose($script); if ($useStatements = $this->getUseStatements($ignoredNamespace = $this->getNamespace())) { $script = $useStatements . $script; } if ($namespaceStatement = $this->getNamespaceStatement()) { $script = $namespaceStatement . $script; } $script = "<?php " . $script; return $this->clean($script); }
[ "public", "function", "build", "(", ")", "{", "$", "this", "->", "validateModel", "(", ")", ";", "$", "script", "=", "''", ";", "if", "(", "$", "this", "->", "isAddIncludes", "(", ")", ")", "{", "$", "this", "->", "addIncludes", "(", "$", "script", ")", ";", "}", "$", "this", "->", "addClassOpen", "(", "$", "script", ")", ";", "$", "this", "->", "addClassBody", "(", "$", "script", ")", ";", "$", "this", "->", "addClassClose", "(", "$", "script", ")", ";", "if", "(", "$", "useStatements", "=", "$", "this", "->", "getUseStatements", "(", "$", "ignoredNamespace", "=", "$", "this", "->", "getNamespace", "(", ")", ")", ")", "{", "$", "script", "=", "$", "useStatements", ".", "$", "script", ";", "}", "if", "(", "$", "namespaceStatement", "=", "$", "this", "->", "getNamespaceStatement", "(", ")", ")", "{", "$", "script", "=", "$", "namespaceStatement", ".", "$", "script", ";", "}", "$", "script", "=", "\"<?php\n\n\"", ".", "$", "script", ";", "return", "$", "this", "->", "clean", "(", "$", "script", ")", ";", "}" ]
Builds the PHP source for current class and returns it as a string. This is the main entry point and defines a basic structure that classes should follow. In most cases this method will not need to be overridden by subclasses. This method does assume that the output language is PHP code, so it will need to be overridden if this is not the case. @return string The resulting PHP sourcecode.
[ "Builds", "the", "PHP", "source", "for", "current", "class", "and", "returns", "it", "as", "a", "string", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/OMBuilder.php#L43-L70
propelorm/Propel
generator/lib/builder/om/OMBuilder.php
OMBuilder.getClasspath
public function getClasspath() { if ($this->getPackage()) { $path = $this->getPackage() . '.' . $this->getClassname(); } else { $path = $this->getClassname(); } return $path; }
php
public function getClasspath() { if ($this->getPackage()) { $path = $this->getPackage() . '.' . $this->getClassname(); } else { $path = $this->getClassname(); } return $path; }
[ "public", "function", "getClasspath", "(", ")", "{", "if", "(", "$", "this", "->", "getPackage", "(", ")", ")", "{", "$", "path", "=", "$", "this", "->", "getPackage", "(", ")", ".", "'.'", ".", "$", "this", "->", "getClassname", "(", ")", ";", "}", "else", "{", "$", "path", "=", "$", "this", "->", "getClassname", "(", ")", ";", "}", "return", "$", "path", ";", "}" ]
Gets the dot-path representation of current class being built. @return string
[ "Gets", "the", "dot", "-", "path", "representation", "of", "current", "class", "being", "built", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/OMBuilder.php#L134-L143
propelorm/Propel
generator/lib/builder/om/OMBuilder.php
OMBuilder.getPackagePath
public function getPackagePath() { $pkg = $this->getPackage(); if (false !== strpos($pkg, '/')) { return preg_replace('#\.(map|om)$#', '/\1', $pkg); } if ('.' === substr($pkg, 0, 1)) { $pkg = substr($pkg, 1); } return strtr($pkg, '.', '/'); }
php
public function getPackagePath() { $pkg = $this->getPackage(); if (false !== strpos($pkg, '/')) { return preg_replace('#\.(map|om)$#', '/\1', $pkg); } if ('.' === substr($pkg, 0, 1)) { $pkg = substr($pkg, 1); } return strtr($pkg, '.', '/'); }
[ "public", "function", "getPackagePath", "(", ")", "{", "$", "pkg", "=", "$", "this", "->", "getPackage", "(", ")", ";", "if", "(", "false", "!==", "strpos", "(", "$", "pkg", ",", "'/'", ")", ")", "{", "return", "preg_replace", "(", "'#\\.(map|om)$#'", ",", "'/\\1'", ",", "$", "pkg", ")", ";", "}", "if", "(", "'.'", "===", "substr", "(", "$", "pkg", ",", "0", ",", "1", ")", ")", "{", "$", "pkg", "=", "substr", "(", "$", "pkg", ",", "1", ")", ";", "}", "return", "strtr", "(", "$", "pkg", ",", "'.'", ",", "'/'", ")", ";", "}" ]
Returns filesystem path for current package. @return string
[ "Returns", "filesystem", "path", "for", "current", "package", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/OMBuilder.php#L176-L189
propelorm/Propel
generator/lib/builder/om/OMBuilder.php
OMBuilder.getColumnConstant
public function getColumnConstant($col, $classname = null) { if ($col === null) { $e = new Exception("No col specified."); print $e; throw $e; } if ($classname === null) { return $this->getBuildProperty('classPrefix') . $col->getConstantName(); } // was it overridden in schema.xml ? if ($col->getPeerName()) { $const = strtoupper($col->getPeerName()); } else { $const = strtoupper($col->getName()); } return $classname . '::' . $const; }
php
public function getColumnConstant($col, $classname = null) { if ($col === null) { $e = new Exception("No col specified."); print $e; throw $e; } if ($classname === null) { return $this->getBuildProperty('classPrefix') . $col->getConstantName(); } // was it overridden in schema.xml ? if ($col->getPeerName()) { $const = strtoupper($col->getPeerName()); } else { $const = strtoupper($col->getName()); } return $classname . '::' . $const; }
[ "public", "function", "getColumnConstant", "(", "$", "col", ",", "$", "classname", "=", "null", ")", "{", "if", "(", "$", "col", "===", "null", ")", "{", "$", "e", "=", "new", "Exception", "(", "\"No col specified.\"", ")", ";", "print", "$", "e", ";", "throw", "$", "e", ";", "}", "if", "(", "$", "classname", "===", "null", ")", "{", "return", "$", "this", "->", "getBuildProperty", "(", "'classPrefix'", ")", ".", "$", "col", "->", "getConstantName", "(", ")", ";", "}", "// was it overridden in schema.xml ?", "if", "(", "$", "col", "->", "getPeerName", "(", ")", ")", "{", "$", "const", "=", "strtoupper", "(", "$", "col", "->", "getPeerName", "(", ")", ")", ";", "}", "else", "{", "$", "const", "=", "strtoupper", "(", "$", "col", "->", "getName", "(", ")", ")", ";", "}", "return", "$", "classname", ".", "'::'", ".", "$", "const", ";", "}" ]
Get the column constant name (e.g. PeerName::COLUMN_NAME). @param Column $col The column we need a name for. @param string $classname The Peer classname to use. @return string If $classname is provided, then will return $classname::COLUMN_NAME; if not, then the peername is looked up for current table to yield $currTablePeer::COLUMN_NAME. @throws Exception
[ "Get", "the", "column", "constant", "name", "(", "e", ".", "g", ".", "PeerName", "::", "COLUMN_NAME", ")", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/OMBuilder.php#L319-L337
propelorm/Propel
generator/lib/builder/om/OMBuilder.php
OMBuilder.getFKPhpNameAffix
public function getFKPhpNameAffix(ForeignKey $fk, $plural = false) { if ($fk->getPhpName()) { if ($plural) { return $this->getPluralizer()->getPluralForm($fk->getPhpName()); } else { return $fk->getPhpName(); } } else { $className = $fk->getForeignTable()->getPhpName(); if ($plural) { $className = $this->getPluralizer()->getPluralForm($className); } return $className . $this->getRelatedBySuffix($fk); } }
php
public function getFKPhpNameAffix(ForeignKey $fk, $plural = false) { if ($fk->getPhpName()) { if ($plural) { return $this->getPluralizer()->getPluralForm($fk->getPhpName()); } else { return $fk->getPhpName(); } } else { $className = $fk->getForeignTable()->getPhpName(); if ($plural) { $className = $this->getPluralizer()->getPluralForm($className); } return $className . $this->getRelatedBySuffix($fk); } }
[ "public", "function", "getFKPhpNameAffix", "(", "ForeignKey", "$", "fk", ",", "$", "plural", "=", "false", ")", "{", "if", "(", "$", "fk", "->", "getPhpName", "(", ")", ")", "{", "if", "(", "$", "plural", ")", "{", "return", "$", "this", "->", "getPluralizer", "(", ")", "->", "getPluralForm", "(", "$", "fk", "->", "getPhpName", "(", ")", ")", ";", "}", "else", "{", "return", "$", "fk", "->", "getPhpName", "(", ")", ";", "}", "}", "else", "{", "$", "className", "=", "$", "fk", "->", "getForeignTable", "(", ")", "->", "getPhpName", "(", ")", ";", "if", "(", "$", "plural", ")", "{", "$", "className", "=", "$", "this", "->", "getPluralizer", "(", ")", "->", "getPluralForm", "(", "$", "className", ")", ";", "}", "return", "$", "className", ".", "$", "this", "->", "getRelatedBySuffix", "(", "$", "fk", ")", ";", "}", "}" ]
Gets the PHP method name affix to be used for fkeys for the current table (not referrers to this table). The difference between this method and the getRefFKPhpNameAffix() method is that in this method the classname in the affix is the foreign table classname. @param ForeignKey $fk The local FK that we need a name for. @param boolean $plural Whether the php name should be plural (e.g. initRelatedObjs() vs. addRelatedObj() @return string
[ "Gets", "the", "PHP", "method", "name", "affix", "to", "be", "used", "for", "fkeys", "for", "the", "current", "table", "(", "not", "referrers", "to", "this", "table", ")", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/OMBuilder.php#L398-L414
propelorm/Propel
generator/lib/builder/om/OMBuilder.php
OMBuilder.getRelatedBySuffix
protected static function getRelatedBySuffix(ForeignKey $fk) { $relCol = ''; foreach ($fk->getLocalForeignMapping() as $localColumnName => $foreignColumnName) { $localTable = $fk->getTable(); $localColumn = $localTable->getColumn($localColumnName); if (!$localColumn) { throw new Exception("Could not fetch column: $localColumnName in table " . $localTable->getName()); } if (count($localTable->getForeignKeysReferencingTable($fk->getForeignTableName())) > 1 || count($fk->getForeignTable()->getForeignKeysReferencingTable($fk->getTableName())) > 0 || $fk->getForeignTableName() == $fk->getTableName()) { // self referential foreign key, or several foreign keys to the same table, or cross-reference fkey $relCol .= $localColumn->getPhpName(); } } if ($relCol != '') { $relCol = 'RelatedBy' . $relCol; } return $relCol; }
php
protected static function getRelatedBySuffix(ForeignKey $fk) { $relCol = ''; foreach ($fk->getLocalForeignMapping() as $localColumnName => $foreignColumnName) { $localTable = $fk->getTable(); $localColumn = $localTable->getColumn($localColumnName); if (!$localColumn) { throw new Exception("Could not fetch column: $localColumnName in table " . $localTable->getName()); } if (count($localTable->getForeignKeysReferencingTable($fk->getForeignTableName())) > 1 || count($fk->getForeignTable()->getForeignKeysReferencingTable($fk->getTableName())) > 0 || $fk->getForeignTableName() == $fk->getTableName()) { // self referential foreign key, or several foreign keys to the same table, or cross-reference fkey $relCol .= $localColumn->getPhpName(); } } if ($relCol != '') { $relCol = 'RelatedBy' . $relCol; } return $relCol; }
[ "protected", "static", "function", "getRelatedBySuffix", "(", "ForeignKey", "$", "fk", ")", "{", "$", "relCol", "=", "''", ";", "foreach", "(", "$", "fk", "->", "getLocalForeignMapping", "(", ")", "as", "$", "localColumnName", "=>", "$", "foreignColumnName", ")", "{", "$", "localTable", "=", "$", "fk", "->", "getTable", "(", ")", ";", "$", "localColumn", "=", "$", "localTable", "->", "getColumn", "(", "$", "localColumnName", ")", ";", "if", "(", "!", "$", "localColumn", ")", "{", "throw", "new", "Exception", "(", "\"Could not fetch column: $localColumnName in table \"", ".", "$", "localTable", "->", "getName", "(", ")", ")", ";", "}", "if", "(", "count", "(", "$", "localTable", "->", "getForeignKeysReferencingTable", "(", "$", "fk", "->", "getForeignTableName", "(", ")", ")", ")", ">", "1", "||", "count", "(", "$", "fk", "->", "getForeignTable", "(", ")", "->", "getForeignKeysReferencingTable", "(", "$", "fk", "->", "getTableName", "(", ")", ")", ")", ">", "0", "||", "$", "fk", "->", "getForeignTableName", "(", ")", "==", "$", "fk", "->", "getTableName", "(", ")", ")", "{", "// self referential foreign key, or several foreign keys to the same table, or cross-reference fkey", "$", "relCol", ".=", "$", "localColumn", "->", "getPhpName", "(", ")", ";", "}", "}", "if", "(", "$", "relCol", "!=", "''", ")", "{", "$", "relCol", "=", "'RelatedBy'", ".", "$", "relCol", ";", "}", "return", "$", "relCol", ";", "}" ]
Gets the "RelatedBy*" suffix (if needed) that is attached to method and variable names. The related by suffix is based on the local columns of the foreign key. If there is more than one column in a table that points to the same foreign table, then a 'RelatedByLocalColName' suffix will be appended. @return string @throws Exception
[ "Gets", "the", "RelatedBy", "*", "suffix", "(", "if", "needed", ")", "that", "is", "attached", "to", "method", "and", "variable", "names", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/OMBuilder.php#L427-L449
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addClassOpen
protected function addClassOpen(&$script) { $table = $this->getTable(); $tableName = $table->getName(); $tableDesc = $table->getDescription(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $modelClass = $this->getStubObjectBuilder()->getClassname(); $parentClass = $this->getBehaviorContent('parentClass'); $parentClass = null === $parentClass ? 'ModelCriteria' : $parentClass; if ($this->getBuildProperty('addClassLevelComment')) { $script .= " /** * Base class that represents a query for the '$tableName' table. * * $tableDesc *"; if ($this->getBuildProperty('addTimeStamp')) { $now = strftime('%c'); $script .= " * This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on: * * $now *"; } } else { $script .= " /**"; } // magic orderBy() methods, for IDE completion foreach ($this->getTable()->getColumns() as $column) { $script .= " * @method $queryClass orderBy" . $column->getPhpName() . "(\$order = Criteria::ASC) Order by the " . $column->getName() . " column"; } $script .= " *"; // magic groupBy() methods, for IDE completion foreach ($this->getTable()->getColumns() as $column) { $script .= " * @method $queryClass groupBy" . $column->getPhpName() . "() Group by the " . $column->getName() . " column"; } // override the signature of ModelCriteria::left-, right- and innerJoin to specify the class of the returned object, for IDE completion $script .= " * * @method $queryClass leftJoin(\$relation) Adds a LEFT JOIN clause to the query * @method $queryClass rightJoin(\$relation) Adds a RIGHT JOIN clause to the query * @method $queryClass innerJoin(\$relation) Adds a INNER JOIN clause to the query *"; // magic XXXjoinYYY() methods, for IDE completion foreach ($this->getTable()->getForeignKeys() as $fk) { $relationName = $this->getFKPhpNameAffix($fk); $script .= " * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation *"; } foreach ($this->getTable()->getReferrers() as $refFK) { $relationName = $this->getRefFKPhpNameAffix($refFK); $script .= " * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation *"; } // override the signature of ModelCriteria::findOne() to specify the class of the returned object, for IDE completion $script .= " * @method $modelClass findOne(PropelPDO \$con = null) Return the first $modelClass matching the query * @method $modelClass findOneOrCreate(PropelPDO \$con = null) Return the first $modelClass matching the query, or a new $modelClass object populated from the query conditions when no match is found *"; // magic findBy() methods, for IDE completion foreach ($this->getTable()->getColumns() as $column) { // skip "findPk" alias method if (!$this->getTable()->hasCompositePrimaryKey() && $column->isPrimaryKey()) { continue; } $script .= " * @method $modelClass findOneBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return the first $modelClass filtered by the " . $column->getName() . " column"; } $script .= " *"; foreach ($this->getTable()->getColumns() as $column) { $script .= " * @method array findBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return $modelClass objects filtered by the " . $column->getName() . " column"; } if ($this->getBuildProperty('addClassLevelComment')) { $script .= " * * @package propel.generator." . $this->getPackage(); } $script .= " */ abstract class " . $this->getClassname() . " extends " . $parentClass . " {"; }
php
protected function addClassOpen(&$script) { $table = $this->getTable(); $tableName = $table->getName(); $tableDesc = $table->getDescription(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $modelClass = $this->getStubObjectBuilder()->getClassname(); $parentClass = $this->getBehaviorContent('parentClass'); $parentClass = null === $parentClass ? 'ModelCriteria' : $parentClass; if ($this->getBuildProperty('addClassLevelComment')) { $script .= " /** * Base class that represents a query for the '$tableName' table. * * $tableDesc *"; if ($this->getBuildProperty('addTimeStamp')) { $now = strftime('%c'); $script .= " * This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on: * * $now *"; } } else { $script .= " /**"; } // magic orderBy() methods, for IDE completion foreach ($this->getTable()->getColumns() as $column) { $script .= " * @method $queryClass orderBy" . $column->getPhpName() . "(\$order = Criteria::ASC) Order by the " . $column->getName() . " column"; } $script .= " *"; // magic groupBy() methods, for IDE completion foreach ($this->getTable()->getColumns() as $column) { $script .= " * @method $queryClass groupBy" . $column->getPhpName() . "() Group by the " . $column->getName() . " column"; } // override the signature of ModelCriteria::left-, right- and innerJoin to specify the class of the returned object, for IDE completion $script .= " * * @method $queryClass leftJoin(\$relation) Adds a LEFT JOIN clause to the query * @method $queryClass rightJoin(\$relation) Adds a RIGHT JOIN clause to the query * @method $queryClass innerJoin(\$relation) Adds a INNER JOIN clause to the query *"; // magic XXXjoinYYY() methods, for IDE completion foreach ($this->getTable()->getForeignKeys() as $fk) { $relationName = $this->getFKPhpNameAffix($fk); $script .= " * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation *"; } foreach ($this->getTable()->getReferrers() as $refFK) { $relationName = $this->getRefFKPhpNameAffix($refFK); $script .= " * @method $queryClass leftJoin" . $relationName . "(\$relationAlias = null) Adds a LEFT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass rightJoin" . $relationName . "(\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the " . $relationName . " relation * @method $queryClass innerJoin" . $relationName . "(\$relationAlias = null) Adds a INNER JOIN clause to the query using the " . $relationName . " relation *"; } // override the signature of ModelCriteria::findOne() to specify the class of the returned object, for IDE completion $script .= " * @method $modelClass findOne(PropelPDO \$con = null) Return the first $modelClass matching the query * @method $modelClass findOneOrCreate(PropelPDO \$con = null) Return the first $modelClass matching the query, or a new $modelClass object populated from the query conditions when no match is found *"; // magic findBy() methods, for IDE completion foreach ($this->getTable()->getColumns() as $column) { // skip "findPk" alias method if (!$this->getTable()->hasCompositePrimaryKey() && $column->isPrimaryKey()) { continue; } $script .= " * @method $modelClass findOneBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return the first $modelClass filtered by the " . $column->getName() . " column"; } $script .= " *"; foreach ($this->getTable()->getColumns() as $column) { $script .= " * @method array findBy" . $column->getPhpName() . "(" . $column->getPhpType() . " \$" . $column->getName() . ") Return $modelClass objects filtered by the " . $column->getName() . " column"; } if ($this->getBuildProperty('addClassLevelComment')) { $script .= " * * @package propel.generator." . $this->getPackage(); } $script .= " */ abstract class " . $this->getClassname() . " extends " . $parentClass . " {"; }
[ "protected", "function", "addClassOpen", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "tableName", "=", "$", "table", "->", "getName", "(", ")", ";", "$", "tableDesc", "=", "$", "table", "->", "getDescription", "(", ")", ";", "$", "queryClass", "=", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "modelClass", "=", "$", "this", "->", "getStubObjectBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "parentClass", "=", "$", "this", "->", "getBehaviorContent", "(", "'parentClass'", ")", ";", "$", "parentClass", "=", "null", "===", "$", "parentClass", "?", "'ModelCriteria'", ":", "$", "parentClass", ";", "if", "(", "$", "this", "->", "getBuildProperty", "(", "'addClassLevelComment'", ")", ")", "{", "$", "script", ".=", "\"\n/**\n * Base class that represents a query for the '$tableName' table.\n *\n * $tableDesc\n *\"", ";", "if", "(", "$", "this", "->", "getBuildProperty", "(", "'addTimeStamp'", ")", ")", "{", "$", "now", "=", "strftime", "(", "'%c'", ")", ";", "$", "script", ".=", "\"\n * This class was autogenerated by Propel \"", ".", "$", "this", "->", "getBuildProperty", "(", "'version'", ")", ".", "\" on:\n *\n * $now\n *\"", ";", "}", "}", "else", "{", "$", "script", ".=", "\"\n/**\"", ";", "}", "// magic orderBy() methods, for IDE completion", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "script", ".=", "\"\n * @method $queryClass orderBy\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"(\\$order = Criteria::ASC) Order by the \"", ".", "$", "column", "->", "getName", "(", ")", ".", "\" column\"", ";", "}", "$", "script", ".=", "\"\n *\"", ";", "// magic groupBy() methods, for IDE completion", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "script", ".=", "\"\n * @method $queryClass groupBy\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"() Group by the \"", ".", "$", "column", "->", "getName", "(", ")", ".", "\" column\"", ";", "}", "// override the signature of ModelCriteria::left-, right- and innerJoin to specify the class of the returned object, for IDE completion", "$", "script", ".=", "\"\n *\n * @method $queryClass leftJoin(\\$relation) Adds a LEFT JOIN clause to the query\n * @method $queryClass rightJoin(\\$relation) Adds a RIGHT JOIN clause to the query\n * @method $queryClass innerJoin(\\$relation) Adds a INNER JOIN clause to the query\n *\"", ";", "// magic XXXjoinYYY() methods, for IDE completion", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "relationName", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ")", ";", "$", "script", ".=", "\"\n * @method $queryClass leftJoin\"", ".", "$", "relationName", ".", "\"(\\$relationAlias = null) Adds a LEFT JOIN clause to the query using the \"", ".", "$", "relationName", ".", "\" relation\n * @method $queryClass rightJoin\"", ".", "$", "relationName", ".", "\"(\\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the \"", ".", "$", "relationName", ".", "\" relation\n * @method $queryClass innerJoin\"", ".", "$", "relationName", ".", "\"(\\$relationAlias = null) Adds a INNER JOIN clause to the query using the \"", ".", "$", "relationName", ".", "\" relation\n *\"", ";", "}", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getReferrers", "(", ")", "as", "$", "refFK", ")", "{", "$", "relationName", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "refFK", ")", ";", "$", "script", ".=", "\"\n * @method $queryClass leftJoin\"", ".", "$", "relationName", ".", "\"(\\$relationAlias = null) Adds a LEFT JOIN clause to the query using the \"", ".", "$", "relationName", ".", "\" relation\n * @method $queryClass rightJoin\"", ".", "$", "relationName", ".", "\"(\\$relationAlias = null) Adds a RIGHT JOIN clause to the query using the \"", ".", "$", "relationName", ".", "\" relation\n * @method $queryClass innerJoin\"", ".", "$", "relationName", ".", "\"(\\$relationAlias = null) Adds a INNER JOIN clause to the query using the \"", ".", "$", "relationName", ".", "\" relation\n *\"", ";", "}", "// override the signature of ModelCriteria::findOne() to specify the class of the returned object, for IDE completion", "$", "script", ".=", "\"\n * @method $modelClass findOne(PropelPDO \\$con = null) Return the first $modelClass matching the query\n * @method $modelClass findOneOrCreate(PropelPDO \\$con = null) Return the first $modelClass matching the query, or a new $modelClass object populated from the query conditions when no match is found\n *\"", ";", "// magic findBy() methods, for IDE completion", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "// skip \"findPk\" alias method", "if", "(", "!", "$", "this", "->", "getTable", "(", ")", "->", "hasCompositePrimaryKey", "(", ")", "&&", "$", "column", "->", "isPrimaryKey", "(", ")", ")", "{", "continue", ";", "}", "$", "script", ".=", "\"\n * @method $modelClass findOneBy\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"(\"", ".", "$", "column", "->", "getPhpType", "(", ")", ".", "\" \\$\"", ".", "$", "column", "->", "getName", "(", ")", ".", "\") Return the first $modelClass filtered by the \"", ".", "$", "column", "->", "getName", "(", ")", ".", "\" column\"", ";", "}", "$", "script", ".=", "\"\n *\"", ";", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "column", ")", "{", "$", "script", ".=", "\"\n * @method array findBy\"", ".", "$", "column", "->", "getPhpName", "(", ")", ".", "\"(\"", ".", "$", "column", "->", "getPhpType", "(", ")", ".", "\" \\$\"", ".", "$", "column", "->", "getName", "(", ")", ".", "\") Return $modelClass objects filtered by the \"", ".", "$", "column", "->", "getName", "(", ")", ".", "\" column\"", ";", "}", "if", "(", "$", "this", "->", "getBuildProperty", "(", "'addClassLevelComment'", ")", ")", "{", "$", "script", ".=", "\"\n *\n * @package propel.generator.\"", ".", "$", "this", "->", "getPackage", "(", ")", ";", "}", "$", "script", ".=", "\"\n */\nabstract class \"", ".", "$", "this", "->", "getClassname", "(", ")", ".", "\" extends \"", ".", "$", "parentClass", ".", "\"\n{\"", ";", "}" ]
Adds class phpdoc comment and opening of class. @param string &$script The script will be modified in this method.
[ "Adds", "class", "phpdoc", "comment", "and", "opening", "of", "class", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L70-L175
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addClassBody
protected function addClassBody(&$script) { // namespaces $this->declareClasses('ModelCriteria', 'Criteria', 'ModelJoin', 'Exception'); $this->declareClassFromBuilder($this->getStubQueryBuilder()); $this->declareClassFromBuilder($this->getStubPeerBuilder()); // apply behaviors $this->applyBehaviorModifier('queryAttributes', $script, " "); $this->addConstructor($script); $this->addFactory($script); $this->addFindPk($script); $this->addFindOneByPk($script); $this->addFindPkSimple($script); $this->addFindPkComplex($script); $this->addFindPks($script); $this->addFilterByPrimaryKey($script); $this->addFilterByPrimaryKeys($script); foreach ($this->getTable()->getColumns() as $col) { $this->addFilterByCol($script, $col); if ($col->getType() === PropelTypes::PHP_ARRAY && $col->isNamePlural()) { $this->addFilterByArrayCol($script, $col); } } foreach ($this->getTable()->getForeignKeys() as $fk) { $this->addFilterByFK($script, $fk); $this->addJoinFk($script, $fk); $this->addUseFKQuery($script, $fk); } foreach ($this->getTable()->getReferrers() as $refFK) { $this->addFilterByRefFK($script, $refFK); $this->addJoinRefFk($script, $refFK); $this->addUseRefFKQuery($script, $refFK); } foreach ($this->getTable()->getCrossFks() as $fkList) { list($refFK, $crossFK) = $fkList; $this->addFilterByCrossFK($script, $refFK, $crossFK); } $this->addPrune($script); $this->addBasePreSelect($script); $this->addBasePreDelete($script); $this->addBasePostDelete($script); $this->addBasePreUpdate($script); $this->addBasePostUpdate($script); // apply behaviors $this->applyBehaviorModifier('queryMethods', $script, " "); }
php
protected function addClassBody(&$script) { // namespaces $this->declareClasses('ModelCriteria', 'Criteria', 'ModelJoin', 'Exception'); $this->declareClassFromBuilder($this->getStubQueryBuilder()); $this->declareClassFromBuilder($this->getStubPeerBuilder()); // apply behaviors $this->applyBehaviorModifier('queryAttributes', $script, " "); $this->addConstructor($script); $this->addFactory($script); $this->addFindPk($script); $this->addFindOneByPk($script); $this->addFindPkSimple($script); $this->addFindPkComplex($script); $this->addFindPks($script); $this->addFilterByPrimaryKey($script); $this->addFilterByPrimaryKeys($script); foreach ($this->getTable()->getColumns() as $col) { $this->addFilterByCol($script, $col); if ($col->getType() === PropelTypes::PHP_ARRAY && $col->isNamePlural()) { $this->addFilterByArrayCol($script, $col); } } foreach ($this->getTable()->getForeignKeys() as $fk) { $this->addFilterByFK($script, $fk); $this->addJoinFk($script, $fk); $this->addUseFKQuery($script, $fk); } foreach ($this->getTable()->getReferrers() as $refFK) { $this->addFilterByRefFK($script, $refFK); $this->addJoinRefFk($script, $refFK); $this->addUseRefFKQuery($script, $refFK); } foreach ($this->getTable()->getCrossFks() as $fkList) { list($refFK, $crossFK) = $fkList; $this->addFilterByCrossFK($script, $refFK, $crossFK); } $this->addPrune($script); $this->addBasePreSelect($script); $this->addBasePreDelete($script); $this->addBasePostDelete($script); $this->addBasePreUpdate($script); $this->addBasePostUpdate($script); // apply behaviors $this->applyBehaviorModifier('queryMethods', $script, " "); }
[ "protected", "function", "addClassBody", "(", "&", "$", "script", ")", "{", "// namespaces", "$", "this", "->", "declareClasses", "(", "'ModelCriteria'", ",", "'Criteria'", ",", "'ModelJoin'", ",", "'Exception'", ")", ";", "$", "this", "->", "declareClassFromBuilder", "(", "$", "this", "->", "getStubQueryBuilder", "(", ")", ")", ";", "$", "this", "->", "declareClassFromBuilder", "(", "$", "this", "->", "getStubPeerBuilder", "(", ")", ")", ";", "// apply behaviors", "$", "this", "->", "applyBehaviorModifier", "(", "'queryAttributes'", ",", "$", "script", ",", "\"\t\"", ")", ";", "$", "this", "->", "addConstructor", "(", "$", "script", ")", ";", "$", "this", "->", "addFactory", "(", "$", "script", ")", ";", "$", "this", "->", "addFindPk", "(", "$", "script", ")", ";", "$", "this", "->", "addFindOneByPk", "(", "$", "script", ")", ";", "$", "this", "->", "addFindPkSimple", "(", "$", "script", ")", ";", "$", "this", "->", "addFindPkComplex", "(", "$", "script", ")", ";", "$", "this", "->", "addFindPks", "(", "$", "script", ")", ";", "$", "this", "->", "addFilterByPrimaryKey", "(", "$", "script", ")", ";", "$", "this", "->", "addFilterByPrimaryKeys", "(", "$", "script", ")", ";", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getColumns", "(", ")", "as", "$", "col", ")", "{", "$", "this", "->", "addFilterByCol", "(", "$", "script", ",", "$", "col", ")", ";", "if", "(", "$", "col", "->", "getType", "(", ")", "===", "PropelTypes", "::", "PHP_ARRAY", "&&", "$", "col", "->", "isNamePlural", "(", ")", ")", "{", "$", "this", "->", "addFilterByArrayCol", "(", "$", "script", ",", "$", "col", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "this", "->", "addFilterByFK", "(", "$", "script", ",", "$", "fk", ")", ";", "$", "this", "->", "addJoinFk", "(", "$", "script", ",", "$", "fk", ")", ";", "$", "this", "->", "addUseFKQuery", "(", "$", "script", ",", "$", "fk", ")", ";", "}", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getReferrers", "(", ")", "as", "$", "refFK", ")", "{", "$", "this", "->", "addFilterByRefFK", "(", "$", "script", ",", "$", "refFK", ")", ";", "$", "this", "->", "addJoinRefFk", "(", "$", "script", ",", "$", "refFK", ")", ";", "$", "this", "->", "addUseRefFKQuery", "(", "$", "script", ",", "$", "refFK", ")", ";", "}", "foreach", "(", "$", "this", "->", "getTable", "(", ")", "->", "getCrossFks", "(", ")", "as", "$", "fkList", ")", "{", "list", "(", "$", "refFK", ",", "$", "crossFK", ")", "=", "$", "fkList", ";", "$", "this", "->", "addFilterByCrossFK", "(", "$", "script", ",", "$", "refFK", ",", "$", "crossFK", ")", ";", "}", "$", "this", "->", "addPrune", "(", "$", "script", ")", ";", "$", "this", "->", "addBasePreSelect", "(", "$", "script", ")", ";", "$", "this", "->", "addBasePreDelete", "(", "$", "script", ")", ";", "$", "this", "->", "addBasePostDelete", "(", "$", "script", ")", ";", "$", "this", "->", "addBasePreUpdate", "(", "$", "script", ")", ";", "$", "this", "->", "addBasePostUpdate", "(", "$", "script", ")", ";", "// apply behaviors", "$", "this", "->", "applyBehaviorModifier", "(", "'queryMethods'", ",", "$", "script", ",", "\"\t\"", ")", ";", "}" ]
Specifies the methods that are added as part of the stub object class. By default there are no methods for the empty stub classes; override this method if you want to change that behavior. @see ObjectBuilder::addClassBody()
[ "Specifies", "the", "methods", "that", "are", "added", "as", "part", "of", "the", "stub", "object", "class", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L185-L231
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addConstructorBody
protected function addConstructorBody(&$script) { $table = $this->getTable(); $script .= " if (null === \$dbName) { \$dbName = '" . $table->getDatabase()->getName() . "'; } if (null === \$modelName) { \$modelName = '" . addslashes($this->getNewStubObjectBuilder($table)->getFullyQualifiedClassname()) . "'; } parent::__construct(\$dbName, \$modelName, \$modelAlias);"; }
php
protected function addConstructorBody(&$script) { $table = $this->getTable(); $script .= " if (null === \$dbName) { \$dbName = '" . $table->getDatabase()->getName() . "'; } if (null === \$modelName) { \$modelName = '" . addslashes($this->getNewStubObjectBuilder($table)->getFullyQualifiedClassname()) . "'; } parent::__construct(\$dbName, \$modelName, \$modelAlias);"; }
[ "protected", "function", "addConstructorBody", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "script", ".=", "\"\n if (null === \\$dbName) {\n \\$dbName = '\"", ".", "$", "table", "->", "getDatabase", "(", ")", "->", "getName", "(", ")", ".", "\"';\n }\n if (null === \\$modelName) {\n \\$modelName = '\"", ".", "addslashes", "(", "$", "this", "->", "getNewStubObjectBuilder", "(", "$", "table", ")", "->", "getFullyQualifiedClassname", "(", ")", ")", ".", "\"';\n }\n parent::__construct(\\$dbName, \\$modelName, \\$modelAlias);\"", ";", "}" ]
Adds the function body for the constructor @param string &$script The script will be modified in this method.
[ "Adds", "the", "function", "body", "for", "the", "constructor" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L295-L306
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFactoryComment
protected function addFactoryComment(&$script) { $classname = $this->getNewStubQueryBuilder($this->getTable())->getClassname(); $script .= " /** * Returns a new " . $classname . " object. * * @param string \$modelAlias The alias of a model in the query * @param $classname|Criteria \$criteria Optional Criteria to build the query from * * @return " . $classname . " */"; }
php
protected function addFactoryComment(&$script) { $classname = $this->getNewStubQueryBuilder($this->getTable())->getClassname(); $script .= " /** * Returns a new " . $classname . " object. * * @param string \$modelAlias The alias of a model in the query * @param $classname|Criteria \$criteria Optional Criteria to build the query from * * @return " . $classname . " */"; }
[ "protected", "function", "addFactoryComment", "(", "&", "$", "script", ")", "{", "$", "classname", "=", "$", "this", "->", "getNewStubQueryBuilder", "(", "$", "this", "->", "getTable", "(", ")", ")", "->", "getClassname", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Returns a new \"", ".", "$", "classname", ".", "\" object.\n *\n * @param string \\$modelAlias The alias of a model in the query\n * @param $classname|Criteria \\$criteria Optional Criteria to build the query from\n *\n * @return \"", ".", "$", "classname", ".", "\"\n */\"", ";", "}" ]
Adds the comment for the factory @param string &$script The script will be modified in this method.
[ "Adds", "the", "comment", "for", "the", "factory" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L338-L350
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFactoryBody
protected function addFactoryBody(&$script) { $classname = $this->getNewStubQueryBuilder($this->getTable())->getClassname(); $script .= " if (\$criteria instanceof " . $classname . ") { return \$criteria; } \$query = new " . $classname . "(null, null, \$modelAlias); if (\$criteria instanceof Criteria) { \$query->mergeWith(\$criteria); } return \$query;"; }
php
protected function addFactoryBody(&$script) { $classname = $this->getNewStubQueryBuilder($this->getTable())->getClassname(); $script .= " if (\$criteria instanceof " . $classname . ") { return \$criteria; } \$query = new " . $classname . "(null, null, \$modelAlias); if (\$criteria instanceof Criteria) { \$query->mergeWith(\$criteria); } return \$query;"; }
[ "protected", "function", "addFactoryBody", "(", "&", "$", "script", ")", "{", "$", "classname", "=", "$", "this", "->", "getNewStubQueryBuilder", "(", "$", "this", "->", "getTable", "(", ")", ")", "->", "getClassname", "(", ")", ";", "$", "script", ".=", "\"\n if (\\$criteria instanceof \"", ".", "$", "classname", ".", "\") {\n return \\$criteria;\n }\n \\$query = new \"", ".", "$", "classname", ".", "\"(null, null, \\$modelAlias);\n\n if (\\$criteria instanceof Criteria) {\n \\$query->mergeWith(\\$criteria);\n }\n\n return \\$query;\"", ";", "}" ]
Adds the function body for the factory @param string &$script The script will be modified in this method.
[ "Adds", "the", "function", "body", "for", "the", "factory" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L369-L383
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFindPkComplex
protected function addFindPkComplex(&$script) { $table = $this->getTable(); $pks = $table->getPrimaryKey(); $class = $this->getStubObjectBuilder()->getClassname(); $this->declareClasses('PropelPDO'); $script .= " /** * Find object by primary key. * * @param mixed \$key Primary key to use for the query * @param PropelPDO \$con A connection object * * @return " . $class . "|{$class}[]|mixed the result, formatted by the current formatter */ protected function findPkComplex(\$key, \$con) { // As the query uses a PK condition, no limit(1) is necessary. \$criteria = \$this->isKeepQuery() ? clone \$this : \$this; \$stmt = \$criteria ->filterByPrimaryKey(\$key) ->doSelect(\$con); return \$criteria->getFormatter()->init(\$criteria)->formatOne(\$stmt); } "; }
php
protected function addFindPkComplex(&$script) { $table = $this->getTable(); $pks = $table->getPrimaryKey(); $class = $this->getStubObjectBuilder()->getClassname(); $this->declareClasses('PropelPDO'); $script .= " /** * Find object by primary key. * * @param mixed \$key Primary key to use for the query * @param PropelPDO \$con A connection object * * @return " . $class . "|{$class}[]|mixed the result, formatted by the current formatter */ protected function findPkComplex(\$key, \$con) { // As the query uses a PK condition, no limit(1) is necessary. \$criteria = \$this->isKeepQuery() ? clone \$this : \$this; \$stmt = \$criteria ->filterByPrimaryKey(\$key) ->doSelect(\$con); return \$criteria->getFormatter()->init(\$criteria)->formatOne(\$stmt); } "; }
[ "protected", "function", "addFindPkComplex", "(", "&", "$", "script", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "pks", "=", "$", "table", "->", "getPrimaryKey", "(", ")", ";", "$", "class", "=", "$", "this", "->", "getStubObjectBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "this", "->", "declareClasses", "(", "'PropelPDO'", ")", ";", "$", "script", ".=", "\"\n /**\n * Find object by primary key.\n *\n * @param mixed \\$key Primary key to use for the query\n * @param PropelPDO \\$con A connection object\n *\n * @return \"", ".", "$", "class", ".", "\"|{$class}[]|mixed the result, formatted by the current formatter\n */\n protected function findPkComplex(\\$key, \\$con)\n {\n // As the query uses a PK condition, no limit(1) is necessary.\n \\$criteria = \\$this->isKeepQuery() ? clone \\$this : \\$this;\n \\$stmt = \\$criteria\n ->filterByPrimaryKey(\\$key)\n ->doSelect(\\$con);\n\n return \\$criteria->getFormatter()->init(\\$criteria)->formatOne(\\$stmt);\n }\n\"", ";", "}" ]
Adds the findPk method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "findPk", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L584-L610
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFindPks
protected function addFindPks(&$script) { $this->declareClasses('PropelPDO', 'Propel'); $table = $this->getTable(); $pks = $table->getPrimaryKey(); $count = count($pks); $class = $this->getStubObjectBuilder()->getClassname(); $script .= " /** * Find objects by primary key * <code>"; if ($count === 1) { $script .= " * \$objs = \$c->findPks(array(12, 56, 832), \$con);"; } else { $script .= " * \$objs = \$c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), \$con);"; } $script .= " * </code> * @param array \$keys Primary keys to use for the query * @param PropelPDO \$con an optional connection object * * @return PropelObjectCollection|{$class}[]|mixed the list of results, formatted by the current formatter */ public function findPks(\$keys, \$con = null) { if (\$con === null) { \$con = Propel::getConnection(\$this->getDbName(), Propel::CONNECTION_READ); } \$this->basePreSelect(\$con); \$criteria = \$this->isKeepQuery() ? clone \$this : \$this; \$stmt = \$criteria ->filterByPrimaryKeys(\$keys) ->doSelect(\$con); return \$criteria->getFormatter()->init(\$criteria)->format(\$stmt); } "; }
php
protected function addFindPks(&$script) { $this->declareClasses('PropelPDO', 'Propel'); $table = $this->getTable(); $pks = $table->getPrimaryKey(); $count = count($pks); $class = $this->getStubObjectBuilder()->getClassname(); $script .= " /** * Find objects by primary key * <code>"; if ($count === 1) { $script .= " * \$objs = \$c->findPks(array(12, 56, 832), \$con);"; } else { $script .= " * \$objs = \$c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), \$con);"; } $script .= " * </code> * @param array \$keys Primary keys to use for the query * @param PropelPDO \$con an optional connection object * * @return PropelObjectCollection|{$class}[]|mixed the list of results, formatted by the current formatter */ public function findPks(\$keys, \$con = null) { if (\$con === null) { \$con = Propel::getConnection(\$this->getDbName(), Propel::CONNECTION_READ); } \$this->basePreSelect(\$con); \$criteria = \$this->isKeepQuery() ? clone \$this : \$this; \$stmt = \$criteria ->filterByPrimaryKeys(\$keys) ->doSelect(\$con); return \$criteria->getFormatter()->init(\$criteria)->format(\$stmt); } "; }
[ "protected", "function", "addFindPks", "(", "&", "$", "script", ")", "{", "$", "this", "->", "declareClasses", "(", "'PropelPDO'", ",", "'Propel'", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "pks", "=", "$", "table", "->", "getPrimaryKey", "(", ")", ";", "$", "count", "=", "count", "(", "$", "pks", ")", ";", "$", "class", "=", "$", "this", "->", "getStubObjectBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Find objects by primary key\n * <code>\"", ";", "if", "(", "$", "count", "===", "1", ")", "{", "$", "script", ".=", "\"\n * \\$objs = \\$c->findPks(array(12, 56, 832), \\$con);\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n * \\$objs = \\$c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), \\$con);\"", ";", "}", "$", "script", ".=", "\"\n * </code>\n * @param array \\$keys Primary keys to use for the query\n * @param PropelPDO \\$con an optional connection object\n *\n * @return PropelObjectCollection|{$class}[]|mixed the list of results, formatted by the current formatter\n */\n public function findPks(\\$keys, \\$con = null)\n {\n if (\\$con === null) {\n \\$con = Propel::getConnection(\\$this->getDbName(), Propel::CONNECTION_READ);\n }\n \\$this->basePreSelect(\\$con);\n \\$criteria = \\$this->isKeepQuery() ? clone \\$this : \\$this;\n \\$stmt = \\$criteria\n ->filterByPrimaryKeys(\\$keys)\n ->doSelect(\\$con);\n\n return \\$criteria->getFormatter()->init(\\$criteria)->format(\\$stmt);\n }\n\"", ";", "}" ]
Adds the findPks method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "findPks", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L617-L656
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFilterByPrimaryKey
protected function addFilterByPrimaryKey(&$script) { $script .= " /** * Filter the query by primary key * * @param mixed \$key Primary key to use for the query * * @return " . $this->getStubQueryBuilder()->getClassname() . " The current query, for fluid interface */ public function filterByPrimaryKey(\$key) {"; $table = $this->getTable(); $pks = $table->getPrimaryKey(); if (count($pks) === 1) { // simple primary key $col = $pks[0]; $const = $this->getColumnConstant($col); $script .= " return \$this->addUsingAlias($const, \$key, Criteria::EQUAL);"; } else { // composite primary key $i = 0; foreach ($pks as $col) { $const = $this->getColumnConstant($col); $script .= " \$this->addUsingAlias($const, \$key[$i], Criteria::EQUAL);"; $i++; } $script .= " return \$this;"; } $script .= " } "; }
php
protected function addFilterByPrimaryKey(&$script) { $script .= " /** * Filter the query by primary key * * @param mixed \$key Primary key to use for the query * * @return " . $this->getStubQueryBuilder()->getClassname() . " The current query, for fluid interface */ public function filterByPrimaryKey(\$key) {"; $table = $this->getTable(); $pks = $table->getPrimaryKey(); if (count($pks) === 1) { // simple primary key $col = $pks[0]; $const = $this->getColumnConstant($col); $script .= " return \$this->addUsingAlias($const, \$key, Criteria::EQUAL);"; } else { // composite primary key $i = 0; foreach ($pks as $col) { $const = $this->getColumnConstant($col); $script .= " \$this->addUsingAlias($const, \$key[$i], Criteria::EQUAL);"; $i++; } $script .= " return \$this;"; } $script .= " } "; }
[ "protected", "function", "addFilterByPrimaryKey", "(", "&", "$", "script", ")", "{", "$", "script", ".=", "\"\n /**\n * Filter the query by primary key\n *\n * @param mixed \\$key Primary key to use for the query\n *\n * @return \"", ".", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ".", "\" The current query, for fluid interface\n */\n public function filterByPrimaryKey(\\$key)\n {\"", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "pks", "=", "$", "table", "->", "getPrimaryKey", "(", ")", ";", "if", "(", "count", "(", "$", "pks", ")", "===", "1", ")", "{", "// simple primary key", "$", "col", "=", "$", "pks", "[", "0", "]", ";", "$", "const", "=", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ";", "$", "script", ".=", "\"\n\n return \\$this->addUsingAlias($const, \\$key, Criteria::EQUAL);\"", ";", "}", "else", "{", "// composite primary key", "$", "i", "=", "0", ";", "foreach", "(", "$", "pks", "as", "$", "col", ")", "{", "$", "const", "=", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ";", "$", "script", ".=", "\"\n \\$this->addUsingAlias($const, \\$key[$i], Criteria::EQUAL);\"", ";", "$", "i", "++", ";", "}", "$", "script", ".=", "\"\n\n return \\$this;\"", ";", "}", "$", "script", ".=", "\"\n }\n\"", ";", "}" ]
Adds the filterByPrimaryKey method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "filterByPrimaryKey", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L663-L700
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFilterByCol
protected function addFilterByCol(&$script, $col) { $colPhpName = $col->getPhpName(); $colName = $col->getName(); $variableName = $col->getStudlyPhpName(); $qualifiedName = $this->getColumnConstant($col); $script .= " /** * Filter the query on the $colName column *"; if ($col->isNumericType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName(1234); // WHERE $colName = 1234 * \$query->filterBy$colPhpName(array(12, 34)); // WHERE $colName IN (12, 34) * \$query->filterBy$colPhpName(array('min' => 12)); // WHERE $colName >= 12 * \$query->filterBy$colPhpName(array('max' => 12)); // WHERE $colName <= 12 * </code>"; if ($col->isForeignKey()) { foreach ($col->getForeignKeys() as $fk) { $script .= " * * @see filterBy" . $this->getFKPhpNameAffix($fk) . "()"; } } $script .= " * * @param mixed \$$variableName The value to use as filter. * Use scalar values for equality. * Use array values for in_array() equivalent. * Use associative array('min' => \$minValue, 'max' => \$maxValue) for intervals."; } elseif ($col->isTemporalType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName('2011-03-14'); // WHERE $colName = '2011-03-14' * \$query->filterBy$colPhpName('now'); // WHERE $colName = '2011-03-14' * \$query->filterBy$colPhpName(array('max' => 'yesterday')); // WHERE $colName < '2011-03-13' * </code> * * @param mixed \$$variableName The value to use as filter. * Values can be integers (unix timestamps), DateTime objects, or strings. * Empty strings are treated as NULL. * Use scalar values for equality. * Use array values for in_array() equivalent. * Use associative array('min' => \$minValue, 'max' => \$maxValue) for intervals."; } elseif ($col->getType() == PropelTypes::PHP_ARRAY) { $script .= " * @param array \$$variableName The values to use as filter."; } elseif ($col->isTextType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName('fooValue'); // WHERE $colName = 'fooValue' * \$query->filterBy$colPhpName('%fooValue%'); // WHERE $colName LIKE '%fooValue%' * </code> * * @param string \$$variableName The value to use as filter. * Accepts wildcards (* and % trigger a LIKE)"; } elseif ($col->isBooleanType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName(true); // WHERE $colName = true * \$query->filterBy$colPhpName('yes'); // WHERE $colName = true * </code> * * @param boolean|string \$$variableName The value to use as filter. * Non-boolean arguments are converted using the following rules: * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true * * 0, '0', 'false', 'off', and 'no' are converted to boolean false * Check on string values is case insensitive (so 'FaLsE' is seen as 'false')."; } else { $script .= " * @param mixed \$$variableName The value to use as filter"; } $script .= " * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return " . $this->getStubQueryBuilder()->getClassname() . " The current query, for fluid interface"; if ($col->getType() == PropelTypes::ENUM) { $script .= " * @throws PropelException - if the value is not accepted by the enum."; } $script .= " */ public function filterBy$colPhpName(\$$variableName = null, \$comparison = null) {"; if ($col->isNumericType() || $col->isTemporalType()) { $script .= " if (is_array(\$$variableName)) { \$useMinMax = false; if (isset(\${$variableName}['min'])) { \$this->addUsingAlias($qualifiedName, \${$variableName}['min'], Criteria::GREATER_EQUAL); \$useMinMax = true; } if (isset(\${$variableName}['max'])) { \$this->addUsingAlias($qualifiedName, \${$variableName}['max'], Criteria::LESS_EQUAL); \$useMinMax = true; } if (\$useMinMax) { return \$this; } if (null === \$comparison) { \$comparison = Criteria::IN; } }"; } elseif ($col->getType() == PropelTypes::OBJECT) { $script .= " if (is_object(\$$variableName)) { \$$variableName = serialize(\$$variableName); }"; } elseif ($col->getType() == PropelTypes::PHP_ARRAY) { $script .= " \$key = \$this->getAliasedColName($qualifiedName); if (null === \$comparison || \$comparison == Criteria::CONTAINS_ALL) { foreach (\$$variableName as \$value) { \$value = '%| ' . \$value . ' |%'; if (\$this->containsKey(\$key)) { \$this->addAnd(\$key, \$value, Criteria::LIKE); } else { \$this->add(\$key, \$value, Criteria::LIKE); } } return \$this; } elseif (\$comparison == Criteria::CONTAINS_SOME) { foreach (\$$variableName as \$value) { \$value = '%| ' . \$value . ' |%'; if (\$this->containsKey(\$key)) { \$this->addOr(\$key, \$value, Criteria::LIKE); } else { \$this->add(\$key, \$value, Criteria::LIKE); } } return \$this; } elseif (\$comparison == Criteria::CONTAINS_NONE) { foreach (\$$variableName as \$value) { \$value = '%| ' . \$value . ' |%'; if (\$this->containsKey(\$key)) { \$this->addAnd(\$key, \$value, Criteria::NOT_LIKE); } else { \$this->add(\$key, \$value, Criteria::NOT_LIKE); } } \$this->addOr(\$key, null, Criteria::ISNULL); return \$this; }"; } elseif ($col->getType() == PropelTypes::ENUM) { $script .= " if (is_scalar(\$$variableName)) { \$$variableName = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$$variableName); } elseif (is_array(\$$variableName)) { \$convertedValues = array(); foreach (\$$variableName as \$value) { \$convertedValues[] = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$value); } \$$variableName = \$convertedValues; if (null === \$comparison) { \$comparison = Criteria::IN; } }"; } elseif ($col->isTextType()) { $script .= " if (null === \$comparison) { if (is_array(\$$variableName)) { \$comparison = Criteria::IN; } elseif (preg_match('/[\%\*]/', \$$variableName)) { \$$variableName = str_replace('*', '%', \$$variableName); \$comparison = Criteria::LIKE; } }"; } elseif ($col->isBooleanType()) { $script .= " if (is_string(\$$variableName)) { \$$variableName = in_array(strtolower(\$$variableName), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; }"; } $script .= " return \$this->addUsingAlias($qualifiedName, \$$variableName, \$comparison); } "; }
php
protected function addFilterByCol(&$script, $col) { $colPhpName = $col->getPhpName(); $colName = $col->getName(); $variableName = $col->getStudlyPhpName(); $qualifiedName = $this->getColumnConstant($col); $script .= " /** * Filter the query on the $colName column *"; if ($col->isNumericType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName(1234); // WHERE $colName = 1234 * \$query->filterBy$colPhpName(array(12, 34)); // WHERE $colName IN (12, 34) * \$query->filterBy$colPhpName(array('min' => 12)); // WHERE $colName >= 12 * \$query->filterBy$colPhpName(array('max' => 12)); // WHERE $colName <= 12 * </code>"; if ($col->isForeignKey()) { foreach ($col->getForeignKeys() as $fk) { $script .= " * * @see filterBy" . $this->getFKPhpNameAffix($fk) . "()"; } } $script .= " * * @param mixed \$$variableName The value to use as filter. * Use scalar values for equality. * Use array values for in_array() equivalent. * Use associative array('min' => \$minValue, 'max' => \$maxValue) for intervals."; } elseif ($col->isTemporalType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName('2011-03-14'); // WHERE $colName = '2011-03-14' * \$query->filterBy$colPhpName('now'); // WHERE $colName = '2011-03-14' * \$query->filterBy$colPhpName(array('max' => 'yesterday')); // WHERE $colName < '2011-03-13' * </code> * * @param mixed \$$variableName The value to use as filter. * Values can be integers (unix timestamps), DateTime objects, or strings. * Empty strings are treated as NULL. * Use scalar values for equality. * Use array values for in_array() equivalent. * Use associative array('min' => \$minValue, 'max' => \$maxValue) for intervals."; } elseif ($col->getType() == PropelTypes::PHP_ARRAY) { $script .= " * @param array \$$variableName The values to use as filter."; } elseif ($col->isTextType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName('fooValue'); // WHERE $colName = 'fooValue' * \$query->filterBy$colPhpName('%fooValue%'); // WHERE $colName LIKE '%fooValue%' * </code> * * @param string \$$variableName The value to use as filter. * Accepts wildcards (* and % trigger a LIKE)"; } elseif ($col->isBooleanType()) { $script .= " * Example usage: * <code> * \$query->filterBy$colPhpName(true); // WHERE $colName = true * \$query->filterBy$colPhpName('yes'); // WHERE $colName = true * </code> * * @param boolean|string \$$variableName The value to use as filter. * Non-boolean arguments are converted using the following rules: * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true * * 0, '0', 'false', 'off', and 'no' are converted to boolean false * Check on string values is case insensitive (so 'FaLsE' is seen as 'false')."; } else { $script .= " * @param mixed \$$variableName The value to use as filter"; } $script .= " * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return " . $this->getStubQueryBuilder()->getClassname() . " The current query, for fluid interface"; if ($col->getType() == PropelTypes::ENUM) { $script .= " * @throws PropelException - if the value is not accepted by the enum."; } $script .= " */ public function filterBy$colPhpName(\$$variableName = null, \$comparison = null) {"; if ($col->isNumericType() || $col->isTemporalType()) { $script .= " if (is_array(\$$variableName)) { \$useMinMax = false; if (isset(\${$variableName}['min'])) { \$this->addUsingAlias($qualifiedName, \${$variableName}['min'], Criteria::GREATER_EQUAL); \$useMinMax = true; } if (isset(\${$variableName}['max'])) { \$this->addUsingAlias($qualifiedName, \${$variableName}['max'], Criteria::LESS_EQUAL); \$useMinMax = true; } if (\$useMinMax) { return \$this; } if (null === \$comparison) { \$comparison = Criteria::IN; } }"; } elseif ($col->getType() == PropelTypes::OBJECT) { $script .= " if (is_object(\$$variableName)) { \$$variableName = serialize(\$$variableName); }"; } elseif ($col->getType() == PropelTypes::PHP_ARRAY) { $script .= " \$key = \$this->getAliasedColName($qualifiedName); if (null === \$comparison || \$comparison == Criteria::CONTAINS_ALL) { foreach (\$$variableName as \$value) { \$value = '%| ' . \$value . ' |%'; if (\$this->containsKey(\$key)) { \$this->addAnd(\$key, \$value, Criteria::LIKE); } else { \$this->add(\$key, \$value, Criteria::LIKE); } } return \$this; } elseif (\$comparison == Criteria::CONTAINS_SOME) { foreach (\$$variableName as \$value) { \$value = '%| ' . \$value . ' |%'; if (\$this->containsKey(\$key)) { \$this->addOr(\$key, \$value, Criteria::LIKE); } else { \$this->add(\$key, \$value, Criteria::LIKE); } } return \$this; } elseif (\$comparison == Criteria::CONTAINS_NONE) { foreach (\$$variableName as \$value) { \$value = '%| ' . \$value . ' |%'; if (\$this->containsKey(\$key)) { \$this->addAnd(\$key, \$value, Criteria::NOT_LIKE); } else { \$this->add(\$key, \$value, Criteria::NOT_LIKE); } } \$this->addOr(\$key, null, Criteria::ISNULL); return \$this; }"; } elseif ($col->getType() == PropelTypes::ENUM) { $script .= " if (is_scalar(\$$variableName)) { \$$variableName = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$$variableName); } elseif (is_array(\$$variableName)) { \$convertedValues = array(); foreach (\$$variableName as \$value) { \$convertedValues[] = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$value); } \$$variableName = \$convertedValues; if (null === \$comparison) { \$comparison = Criteria::IN; } }"; } elseif ($col->isTextType()) { $script .= " if (null === \$comparison) { if (is_array(\$$variableName)) { \$comparison = Criteria::IN; } elseif (preg_match('/[\%\*]/', \$$variableName)) { \$$variableName = str_replace('*', '%', \$$variableName); \$comparison = Criteria::LIKE; } }"; } elseif ($col->isBooleanType()) { $script .= " if (is_string(\$$variableName)) { \$$variableName = in_array(strtolower(\$$variableName), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true; }"; } $script .= " return \$this->addUsingAlias($qualifiedName, \$$variableName, \$comparison); } "; }
[ "protected", "function", "addFilterByCol", "(", "&", "$", "script", ",", "$", "col", ")", "{", "$", "colPhpName", "=", "$", "col", "->", "getPhpName", "(", ")", ";", "$", "colName", "=", "$", "col", "->", "getName", "(", ")", ";", "$", "variableName", "=", "$", "col", "->", "getStudlyPhpName", "(", ")", ";", "$", "qualifiedName", "=", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ";", "$", "script", ".=", "\"\n /**\n * Filter the query on the $colName column\n *\"", ";", "if", "(", "$", "col", "->", "isNumericType", "(", ")", ")", "{", "$", "script", ".=", "\"\n * Example usage:\n * <code>\n * \\$query->filterBy$colPhpName(1234); // WHERE $colName = 1234\n * \\$query->filterBy$colPhpName(array(12, 34)); // WHERE $colName IN (12, 34)\n * \\$query->filterBy$colPhpName(array('min' => 12)); // WHERE $colName >= 12\n * \\$query->filterBy$colPhpName(array('max' => 12)); // WHERE $colName <= 12\n * </code>\"", ";", "if", "(", "$", "col", "->", "isForeignKey", "(", ")", ")", "{", "foreach", "(", "$", "col", "->", "getForeignKeys", "(", ")", "as", "$", "fk", ")", "{", "$", "script", ".=", "\"\n *\n * @see filterBy\"", ".", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ")", ".", "\"()\"", ";", "}", "}", "$", "script", ".=", "\"\n *\n * @param mixed \\$$variableName The value to use as filter.\n * Use scalar values for equality.\n * Use array values for in_array() equivalent.\n * Use associative array('min' => \\$minValue, 'max' => \\$maxValue) for intervals.\"", ";", "}", "elseif", "(", "$", "col", "->", "isTemporalType", "(", ")", ")", "{", "$", "script", ".=", "\"\n * Example usage:\n * <code>\n * \\$query->filterBy$colPhpName('2011-03-14'); // WHERE $colName = '2011-03-14'\n * \\$query->filterBy$colPhpName('now'); // WHERE $colName = '2011-03-14'\n * \\$query->filterBy$colPhpName(array('max' => 'yesterday')); // WHERE $colName < '2011-03-13'\n * </code>\n *\n * @param mixed \\$$variableName The value to use as filter.\n * Values can be integers (unix timestamps), DateTime objects, or strings.\n * Empty strings are treated as NULL.\n * Use scalar values for equality.\n * Use array values for in_array() equivalent.\n * Use associative array('min' => \\$minValue, 'max' => \\$maxValue) for intervals.\"", ";", "}", "elseif", "(", "$", "col", "->", "getType", "(", ")", "==", "PropelTypes", "::", "PHP_ARRAY", ")", "{", "$", "script", ".=", "\"\n * @param array \\$$variableName The values to use as filter.\"", ";", "}", "elseif", "(", "$", "col", "->", "isTextType", "(", ")", ")", "{", "$", "script", ".=", "\"\n * Example usage:\n * <code>\n * \\$query->filterBy$colPhpName('fooValue'); // WHERE $colName = 'fooValue'\n * \\$query->filterBy$colPhpName('%fooValue%'); // WHERE $colName LIKE '%fooValue%'\n * </code>\n *\n * @param string \\$$variableName The value to use as filter.\n * Accepts wildcards (* and % trigger a LIKE)\"", ";", "}", "elseif", "(", "$", "col", "->", "isBooleanType", "(", ")", ")", "{", "$", "script", ".=", "\"\n * Example usage:\n * <code>\n * \\$query->filterBy$colPhpName(true); // WHERE $colName = true\n * \\$query->filterBy$colPhpName('yes'); // WHERE $colName = true\n * </code>\n *\n * @param boolean|string \\$$variableName The value to use as filter.\n * Non-boolean arguments are converted using the following rules:\n * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true\n * * 0, '0', 'false', 'off', and 'no' are converted to boolean false\n * Check on string values is case insensitive (so 'FaLsE' is seen as 'false').\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n * @param mixed \\$$variableName The value to use as filter\"", ";", "}", "$", "script", ".=", "\"\n * @param string \\$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL\n *\n * @return \"", ".", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ".", "\" The current query, for fluid interface\"", ";", "if", "(", "$", "col", "->", "getType", "(", ")", "==", "PropelTypes", "::", "ENUM", ")", "{", "$", "script", ".=", "\"\n * @throws PropelException - if the value is not accepted by the enum.\"", ";", "}", "$", "script", ".=", "\"\n */\n public function filterBy$colPhpName(\\$$variableName = null, \\$comparison = null)\n {\"", ";", "if", "(", "$", "col", "->", "isNumericType", "(", ")", "||", "$", "col", "->", "isTemporalType", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (is_array(\\$$variableName)) {\n \\$useMinMax = false;\n if (isset(\\${$variableName}['min'])) {\n \\$this->addUsingAlias($qualifiedName, \\${$variableName}['min'], Criteria::GREATER_EQUAL);\n \\$useMinMax = true;\n }\n if (isset(\\${$variableName}['max'])) {\n \\$this->addUsingAlias($qualifiedName, \\${$variableName}['max'], Criteria::LESS_EQUAL);\n \\$useMinMax = true;\n }\n if (\\$useMinMax) {\n return \\$this;\n }\n if (null === \\$comparison) {\n \\$comparison = Criteria::IN;\n }\n }\"", ";", "}", "elseif", "(", "$", "col", "->", "getType", "(", ")", "==", "PropelTypes", "::", "OBJECT", ")", "{", "$", "script", ".=", "\"\n if (is_object(\\$$variableName)) {\n \\$$variableName = serialize(\\$$variableName);\n }\"", ";", "}", "elseif", "(", "$", "col", "->", "getType", "(", ")", "==", "PropelTypes", "::", "PHP_ARRAY", ")", "{", "$", "script", ".=", "\"\n \\$key = \\$this->getAliasedColName($qualifiedName);\n if (null === \\$comparison || \\$comparison == Criteria::CONTAINS_ALL) {\n foreach (\\$$variableName as \\$value) {\n \\$value = '%| ' . \\$value . ' |%';\n if (\\$this->containsKey(\\$key)) {\n \\$this->addAnd(\\$key, \\$value, Criteria::LIKE);\n } else {\n \\$this->add(\\$key, \\$value, Criteria::LIKE);\n }\n }\n\n return \\$this;\n } elseif (\\$comparison == Criteria::CONTAINS_SOME) {\n foreach (\\$$variableName as \\$value) {\n \\$value = '%| ' . \\$value . ' |%';\n if (\\$this->containsKey(\\$key)) {\n \\$this->addOr(\\$key, \\$value, Criteria::LIKE);\n } else {\n \\$this->add(\\$key, \\$value, Criteria::LIKE);\n }\n }\n\n return \\$this;\n } elseif (\\$comparison == Criteria::CONTAINS_NONE) {\n foreach (\\$$variableName as \\$value) {\n \\$value = '%| ' . \\$value . ' |%';\n if (\\$this->containsKey(\\$key)) {\n \\$this->addAnd(\\$key, \\$value, Criteria::NOT_LIKE);\n } else {\n \\$this->add(\\$key, \\$value, Criteria::NOT_LIKE);\n }\n }\n \\$this->addOr(\\$key, null, Criteria::ISNULL);\n\n return \\$this;\n }\"", ";", "}", "elseif", "(", "$", "col", "->", "getType", "(", ")", "==", "PropelTypes", "::", "ENUM", ")", "{", "$", "script", ".=", "\"\n if (is_scalar(\\$$variableName)) {\n \\$$variableName = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \\$$variableName);\n } elseif (is_array(\\$$variableName)) {\n \\$convertedValues = array();\n foreach (\\$$variableName as \\$value) {\n \\$convertedValues[] = {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \\$value);\n }\n \\$$variableName = \\$convertedValues;\n if (null === \\$comparison) {\n \\$comparison = Criteria::IN;\n }\n }\"", ";", "}", "elseif", "(", "$", "col", "->", "isTextType", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (null === \\$comparison) {\n if (is_array(\\$$variableName)) {\n \\$comparison = Criteria::IN;\n } elseif (preg_match('/[\\%\\*]/', \\$$variableName)) {\n \\$$variableName = str_replace('*', '%', \\$$variableName);\n \\$comparison = Criteria::LIKE;\n }\n }\"", ";", "}", "elseif", "(", "$", "col", "->", "isBooleanType", "(", ")", ")", "{", "$", "script", ".=", "\"\n if (is_string(\\$$variableName)) {\n \\$$variableName = in_array(strtolower(\\$$variableName), array('false', 'off', '-', 'no', 'n', '0', '')) ? false : true;\n }\"", ";", "}", "$", "script", ".=", "\"\n\n return \\$this->addUsingAlias($qualifiedName, \\$$variableName, \\$comparison);\n }\n\"", ";", "}" ]
Adds the filterByCol method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "filterByCol", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L763-L951
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFilterByArrayCol
protected function addFilterByArrayCol(&$script, $col) { $colPhpName = $col->getPhpName(); $singularPhpName = rtrim($colPhpName, 's'); $colName = $col->getName(); $variableName = $col->getStudlyPhpName(); $qualifiedName = $this->getColumnConstant($col); $script .= " /** * Filter the query on the $colName column * @param mixed \$$variableName The value to use as filter * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::CONTAINS_ALL * * @return " . $this->getStubQueryBuilder()->getClassname() . " The current query, for fluid interface */ public function filterBy$singularPhpName(\$$variableName = null, \$comparison = null) { if (null === \$comparison || \$comparison == Criteria::CONTAINS_ALL) { if (is_scalar(\$$variableName)) { \$$variableName = '%| ' . \$$variableName . ' |%'; \$comparison = Criteria::LIKE; } } elseif (\$comparison == Criteria::CONTAINS_NONE) { \$$variableName = '%| ' . \$$variableName . ' |%'; \$comparison = Criteria::NOT_LIKE; \$key = \$this->getAliasedColName($qualifiedName); if (\$this->containsKey(\$key)) { \$this->addAnd(\$key, \$$variableName, \$comparison); } else { \$this->addAnd(\$key, \$$variableName, \$comparison); } \$this->addOr(\$key, null, Criteria::ISNULL); return \$this; } return \$this->addUsingAlias($qualifiedName, \$$variableName, \$comparison); } "; }
php
protected function addFilterByArrayCol(&$script, $col) { $colPhpName = $col->getPhpName(); $singularPhpName = rtrim($colPhpName, 's'); $colName = $col->getName(); $variableName = $col->getStudlyPhpName(); $qualifiedName = $this->getColumnConstant($col); $script .= " /** * Filter the query on the $colName column * @param mixed \$$variableName The value to use as filter * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::CONTAINS_ALL * * @return " . $this->getStubQueryBuilder()->getClassname() . " The current query, for fluid interface */ public function filterBy$singularPhpName(\$$variableName = null, \$comparison = null) { if (null === \$comparison || \$comparison == Criteria::CONTAINS_ALL) { if (is_scalar(\$$variableName)) { \$$variableName = '%| ' . \$$variableName . ' |%'; \$comparison = Criteria::LIKE; } } elseif (\$comparison == Criteria::CONTAINS_NONE) { \$$variableName = '%| ' . \$$variableName . ' |%'; \$comparison = Criteria::NOT_LIKE; \$key = \$this->getAliasedColName($qualifiedName); if (\$this->containsKey(\$key)) { \$this->addAnd(\$key, \$$variableName, \$comparison); } else { \$this->addAnd(\$key, \$$variableName, \$comparison); } \$this->addOr(\$key, null, Criteria::ISNULL); return \$this; } return \$this->addUsingAlias($qualifiedName, \$$variableName, \$comparison); } "; }
[ "protected", "function", "addFilterByArrayCol", "(", "&", "$", "script", ",", "$", "col", ")", "{", "$", "colPhpName", "=", "$", "col", "->", "getPhpName", "(", ")", ";", "$", "singularPhpName", "=", "rtrim", "(", "$", "colPhpName", ",", "'s'", ")", ";", "$", "colName", "=", "$", "col", "->", "getName", "(", ")", ";", "$", "variableName", "=", "$", "col", "->", "getStudlyPhpName", "(", ")", ";", "$", "qualifiedName", "=", "$", "this", "->", "getColumnConstant", "(", "$", "col", ")", ";", "$", "script", ".=", "\"\n /**\n * Filter the query on the $colName column\n * @param mixed \\$$variableName The value to use as filter\n * @param string \\$comparison Operator to use for the column comparison, defaults to Criteria::CONTAINS_ALL\n *\n * @return \"", ".", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ".", "\" The current query, for fluid interface\n */\n public function filterBy$singularPhpName(\\$$variableName = null, \\$comparison = null)\n {\n if (null === \\$comparison || \\$comparison == Criteria::CONTAINS_ALL) {\n if (is_scalar(\\$$variableName)) {\n \\$$variableName = '%| ' . \\$$variableName . ' |%';\n \\$comparison = Criteria::LIKE;\n }\n } elseif (\\$comparison == Criteria::CONTAINS_NONE) {\n \\$$variableName = '%| ' . \\$$variableName . ' |%';\n \\$comparison = Criteria::NOT_LIKE;\n \\$key = \\$this->getAliasedColName($qualifiedName);\n if (\\$this->containsKey(\\$key)) {\n \\$this->addAnd(\\$key, \\$$variableName, \\$comparison);\n } else {\n \\$this->addAnd(\\$key, \\$$variableName, \\$comparison);\n }\n \\$this->addOr(\\$key, null, Criteria::ISNULL);\n\n return \\$this;\n }\n\n return \\$this->addUsingAlias($qualifiedName, \\$$variableName, \\$comparison);\n }\n\"", ";", "}" ]
Adds the singular filterByCol method for an Array column. @param string &$script The script will be modified in this method.
[ "Adds", "the", "singular", "filterByCol", "method", "for", "an", "Array", "column", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L958-L997
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFilterByFk
protected function addFilterByFk(&$script, $fk) { $this->declareClasses('PropelObjectCollection', 'PropelCollection', 'PropelException'); $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getForeignTable($fk); $fkStubObjectBuilder = $this->getNewStubObjectBuilder($fkTable); $this->declareClassFromBuilder($fkStubObjectBuilder); $fkPhpName = $fkStubObjectBuilder->getClassname(); $relationName = $this->getFKPhpNameAffix($fk); $objectName = '$' . $fkTable->getStudlyPhpName(); $script .= " /** * Filter the query by a related $fkPhpName object *"; if ($fk->isComposite()) { $script .= " * @param $fkPhpName $objectName The related object to use as filter"; } else { $script .= " * @param $fkPhpName|PropelObjectCollection $objectName The related object(s) to use as filter"; } $script .= " * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return $queryClass The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterBy$relationName($objectName, \$comparison = null) { if ($objectName instanceof $fkPhpName) { return \$this"; foreach ($fk->getLocalForeignMapping() as $localColumn => $foreignColumn) { $localColumnObject = $table->getColumn($localColumn); $foreignColumnObject = $fkTable->getColumn($foreignColumn); $script .= " ->addUsingAlias(" . $this->getColumnConstant($localColumnObject) . ", " . $objectName . "->get" . $foreignColumnObject->getPhpName() . "(), \$comparison)"; } $script .= ";"; if (!$fk->isComposite()) { $localColumnConstant = $this->getColumnConstant($fk->getLocalColumn()); $foreignColumnName = $fk->getForeignColumn()->getPhpName(); $keyColumn = $fk->getForeignTable()->hasCompositePrimaryKey() ? $foreignColumnName : 'PrimaryKey'; $script .= " } elseif ($objectName instanceof PropelObjectCollection) { if (null === \$comparison) { \$comparison = Criteria::IN; } return \$this ->addUsingAlias($localColumnConstant, {$objectName}->toKeyValue('$keyColumn', '$foreignColumnName'), \$comparison);"; } $script .= " } else {"; if ($fk->isComposite()) { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName');"; } else { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');"; } $script .= " } } "; }
php
protected function addFilterByFk(&$script, $fk) { $this->declareClasses('PropelObjectCollection', 'PropelCollection', 'PropelException'); $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getForeignTable($fk); $fkStubObjectBuilder = $this->getNewStubObjectBuilder($fkTable); $this->declareClassFromBuilder($fkStubObjectBuilder); $fkPhpName = $fkStubObjectBuilder->getClassname(); $relationName = $this->getFKPhpNameAffix($fk); $objectName = '$' . $fkTable->getStudlyPhpName(); $script .= " /** * Filter the query by a related $fkPhpName object *"; if ($fk->isComposite()) { $script .= " * @param $fkPhpName $objectName The related object to use as filter"; } else { $script .= " * @param $fkPhpName|PropelObjectCollection $objectName The related object(s) to use as filter"; } $script .= " * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return $queryClass The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterBy$relationName($objectName, \$comparison = null) { if ($objectName instanceof $fkPhpName) { return \$this"; foreach ($fk->getLocalForeignMapping() as $localColumn => $foreignColumn) { $localColumnObject = $table->getColumn($localColumn); $foreignColumnObject = $fkTable->getColumn($foreignColumn); $script .= " ->addUsingAlias(" . $this->getColumnConstant($localColumnObject) . ", " . $objectName . "->get" . $foreignColumnObject->getPhpName() . "(), \$comparison)"; } $script .= ";"; if (!$fk->isComposite()) { $localColumnConstant = $this->getColumnConstant($fk->getLocalColumn()); $foreignColumnName = $fk->getForeignColumn()->getPhpName(); $keyColumn = $fk->getForeignTable()->hasCompositePrimaryKey() ? $foreignColumnName : 'PrimaryKey'; $script .= " } elseif ($objectName instanceof PropelObjectCollection) { if (null === \$comparison) { \$comparison = Criteria::IN; } return \$this ->addUsingAlias($localColumnConstant, {$objectName}->toKeyValue('$keyColumn', '$foreignColumnName'), \$comparison);"; } $script .= " } else {"; if ($fk->isComposite()) { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName');"; } else { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');"; } $script .= " } } "; }
[ "protected", "function", "addFilterByFk", "(", "&", "$", "script", ",", "$", "fk", ")", "{", "$", "this", "->", "declareClasses", "(", "'PropelObjectCollection'", ",", "'PropelCollection'", ",", "'PropelException'", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "queryClass", "=", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "fkTable", "=", "$", "this", "->", "getForeignTable", "(", "$", "fk", ")", ";", "$", "fkStubObjectBuilder", "=", "$", "this", "->", "getNewStubObjectBuilder", "(", "$", "fkTable", ")", ";", "$", "this", "->", "declareClassFromBuilder", "(", "$", "fkStubObjectBuilder", ")", ";", "$", "fkPhpName", "=", "$", "fkStubObjectBuilder", "->", "getClassname", "(", ")", ";", "$", "relationName", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ")", ";", "$", "objectName", "=", "'$'", ".", "$", "fkTable", "->", "getStudlyPhpName", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Filter the query by a related $fkPhpName object\n *\"", ";", "if", "(", "$", "fk", "->", "isComposite", "(", ")", ")", "{", "$", "script", ".=", "\"\n * @param $fkPhpName $objectName The related object to use as filter\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n * @param $fkPhpName|PropelObjectCollection $objectName The related object(s) to use as filter\"", ";", "}", "$", "script", ".=", "\"\n * @param string \\$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL\n *\n * @return $queryClass The current query, for fluid interface\n * @throws PropelException - if the provided filter is invalid.\n */\n public function filterBy$relationName($objectName, \\$comparison = null)\n {\n if ($objectName instanceof $fkPhpName) {\n return \\$this\"", ";", "foreach", "(", "$", "fk", "->", "getLocalForeignMapping", "(", ")", "as", "$", "localColumn", "=>", "$", "foreignColumn", ")", "{", "$", "localColumnObject", "=", "$", "table", "->", "getColumn", "(", "$", "localColumn", ")", ";", "$", "foreignColumnObject", "=", "$", "fkTable", "->", "getColumn", "(", "$", "foreignColumn", ")", ";", "$", "script", ".=", "\"\n ->addUsingAlias(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "localColumnObject", ")", ".", "\", \"", ".", "$", "objectName", ".", "\"->get\"", ".", "$", "foreignColumnObject", "->", "getPhpName", "(", ")", ".", "\"(), \\$comparison)\"", ";", "}", "$", "script", ".=", "\";\"", ";", "if", "(", "!", "$", "fk", "->", "isComposite", "(", ")", ")", "{", "$", "localColumnConstant", "=", "$", "this", "->", "getColumnConstant", "(", "$", "fk", "->", "getLocalColumn", "(", ")", ")", ";", "$", "foreignColumnName", "=", "$", "fk", "->", "getForeignColumn", "(", ")", "->", "getPhpName", "(", ")", ";", "$", "keyColumn", "=", "$", "fk", "->", "getForeignTable", "(", ")", "->", "hasCompositePrimaryKey", "(", ")", "?", "$", "foreignColumnName", ":", "'PrimaryKey'", ";", "$", "script", ".=", "\"\n } elseif ($objectName instanceof PropelObjectCollection) {\n if (null === \\$comparison) {\n \\$comparison = Criteria::IN;\n }\n\n return \\$this\n ->addUsingAlias($localColumnConstant, {$objectName}->toKeyValue('$keyColumn', '$foreignColumnName'), \\$comparison);\"", ";", "}", "$", "script", ".=", "\"\n } else {\"", ";", "if", "(", "$", "fk", "->", "isComposite", "(", ")", ")", "{", "$", "script", ".=", "\"\n throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName');\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');\"", ";", "}", "$", "script", ".=", "\"\n }\n }\n\"", ";", "}" ]
Adds the filterByFk method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "filterByFk", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L1004-L1069
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addFilterByRefFk
protected function addFilterByRefFk(&$script, $fk) { $this->declareClasses('PropelObjectCollection', 'PropelCollection', 'PropelException'); $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getTable()->getDatabase()->getTable($fk->getTableName()); $fkStubObjectBuilder = $this->getNewStubObjectBuilder($fkTable); $this->declareClassFromBuilder($fkStubObjectBuilder); $fkPhpName = $fkStubObjectBuilder->getClassname(); $relationName = $this->getRefFKPhpNameAffix($fk); $objectName = '$' . $fkTable->getStudlyPhpName(); $script .= " /** * Filter the query by a related $fkPhpName object * * @param $fkPhpName|PropelObjectCollection $objectName the related object to use as filter * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return $queryClass The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterBy$relationName($objectName, \$comparison = null) { if ($objectName instanceof $fkPhpName) { return \$this"; foreach ($fk->getForeignLocalMapping() as $localColumn => $foreignColumn) { $localColumnObject = $table->getColumn($localColumn); $foreignColumnObject = $fkTable->getColumn($foreignColumn); $script .= " ->addUsingAlias(" . $this->getColumnConstant($localColumnObject) . ", " . $objectName . "->get" . $foreignColumnObject->getPhpName() . "(), \$comparison)"; } $script .= ";"; if (!$fk->isComposite()) { $script .= " } elseif ($objectName instanceof PropelObjectCollection) { return \$this ->use{$relationName}Query() ->filterByPrimaryKeys({$objectName}->getPrimaryKeys()) ->endUse();"; } $script .= " } else {"; if ($fk->isComposite()) { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName');"; } else { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');"; } $script .= " } } "; }
php
protected function addFilterByRefFk(&$script, $fk) { $this->declareClasses('PropelObjectCollection', 'PropelCollection', 'PropelException'); $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getTable()->getDatabase()->getTable($fk->getTableName()); $fkStubObjectBuilder = $this->getNewStubObjectBuilder($fkTable); $this->declareClassFromBuilder($fkStubObjectBuilder); $fkPhpName = $fkStubObjectBuilder->getClassname(); $relationName = $this->getRefFKPhpNameAffix($fk); $objectName = '$' . $fkTable->getStudlyPhpName(); $script .= " /** * Filter the query by a related $fkPhpName object * * @param $fkPhpName|PropelObjectCollection $objectName the related object to use as filter * @param string \$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return $queryClass The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterBy$relationName($objectName, \$comparison = null) { if ($objectName instanceof $fkPhpName) { return \$this"; foreach ($fk->getForeignLocalMapping() as $localColumn => $foreignColumn) { $localColumnObject = $table->getColumn($localColumn); $foreignColumnObject = $fkTable->getColumn($foreignColumn); $script .= " ->addUsingAlias(" . $this->getColumnConstant($localColumnObject) . ", " . $objectName . "->get" . $foreignColumnObject->getPhpName() . "(), \$comparison)"; } $script .= ";"; if (!$fk->isComposite()) { $script .= " } elseif ($objectName instanceof PropelObjectCollection) { return \$this ->use{$relationName}Query() ->filterByPrimaryKeys({$objectName}->getPrimaryKeys()) ->endUse();"; } $script .= " } else {"; if ($fk->isComposite()) { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName');"; } else { $script .= " throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');"; } $script .= " } } "; }
[ "protected", "function", "addFilterByRefFk", "(", "&", "$", "script", ",", "$", "fk", ")", "{", "$", "this", "->", "declareClasses", "(", "'PropelObjectCollection'", ",", "'PropelCollection'", ",", "'PropelException'", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "queryClass", "=", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "fkTable", "=", "$", "this", "->", "getTable", "(", ")", "->", "getDatabase", "(", ")", "->", "getTable", "(", "$", "fk", "->", "getTableName", "(", ")", ")", ";", "$", "fkStubObjectBuilder", "=", "$", "this", "->", "getNewStubObjectBuilder", "(", "$", "fkTable", ")", ";", "$", "this", "->", "declareClassFromBuilder", "(", "$", "fkStubObjectBuilder", ")", ";", "$", "fkPhpName", "=", "$", "fkStubObjectBuilder", "->", "getClassname", "(", ")", ";", "$", "relationName", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ")", ";", "$", "objectName", "=", "'$'", ".", "$", "fkTable", "->", "getStudlyPhpName", "(", ")", ";", "$", "script", ".=", "\"\n /**\n * Filter the query by a related $fkPhpName object\n *\n * @param $fkPhpName|PropelObjectCollection $objectName the related object to use as filter\n * @param string \\$comparison Operator to use for the column comparison, defaults to Criteria::EQUAL\n *\n * @return $queryClass The current query, for fluid interface\n * @throws PropelException - if the provided filter is invalid.\n */\n public function filterBy$relationName($objectName, \\$comparison = null)\n {\n if ($objectName instanceof $fkPhpName) {\n return \\$this\"", ";", "foreach", "(", "$", "fk", "->", "getForeignLocalMapping", "(", ")", "as", "$", "localColumn", "=>", "$", "foreignColumn", ")", "{", "$", "localColumnObject", "=", "$", "table", "->", "getColumn", "(", "$", "localColumn", ")", ";", "$", "foreignColumnObject", "=", "$", "fkTable", "->", "getColumn", "(", "$", "foreignColumn", ")", ";", "$", "script", ".=", "\"\n ->addUsingAlias(\"", ".", "$", "this", "->", "getColumnConstant", "(", "$", "localColumnObject", ")", ".", "\", \"", ".", "$", "objectName", ".", "\"->get\"", ".", "$", "foreignColumnObject", "->", "getPhpName", "(", ")", ".", "\"(), \\$comparison)\"", ";", "}", "$", "script", ".=", "\";\"", ";", "if", "(", "!", "$", "fk", "->", "isComposite", "(", ")", ")", "{", "$", "script", ".=", "\"\n } elseif ($objectName instanceof PropelObjectCollection) {\n return \\$this\n ->use{$relationName}Query()\n ->filterByPrimaryKeys({$objectName}->getPrimaryKeys())\n ->endUse();\"", ";", "}", "$", "script", ".=", "\"\n } else {\"", ";", "if", "(", "$", "fk", "->", "isComposite", "(", ")", ")", "{", "$", "script", ".=", "\"\n throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName');\"", ";", "}", "else", "{", "$", "script", ".=", "\"\n throw new PropelException('filterBy$relationName() only accepts arguments of type $fkPhpName or PropelCollection');\"", ";", "}", "$", "script", ".=", "\"\n }\n }\n\"", ";", "}" ]
Adds the filterByRefFk method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "filterByRefFk", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L1076-L1129
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addJoinFk
protected function addJoinFk(&$script, $fk) { $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getForeignTable($fk); $relationName = $this->getFKPhpNameAffix($fk); $joinType = $this->getJoinType($fk); $this->addJoinRelated($script, $fkTable, $queryClass, $relationName, $joinType); }
php
protected function addJoinFk(&$script, $fk) { $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getForeignTable($fk); $relationName = $this->getFKPhpNameAffix($fk); $joinType = $this->getJoinType($fk); $this->addJoinRelated($script, $fkTable, $queryClass, $relationName, $joinType); }
[ "protected", "function", "addJoinFk", "(", "&", "$", "script", ",", "$", "fk", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "queryClass", "=", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "fkTable", "=", "$", "this", "->", "getForeignTable", "(", "$", "fk", ")", ";", "$", "relationName", "=", "$", "this", "->", "getFKPhpNameAffix", "(", "$", "fk", ")", ";", "$", "joinType", "=", "$", "this", "->", "getJoinType", "(", "$", "fk", ")", ";", "$", "this", "->", "addJoinRelated", "(", "$", "script", ",", "$", "fkTable", ",", "$", "queryClass", ",", "$", "relationName", ",", "$", "joinType", ")", ";", "}" ]
Adds the joinFk method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "joinFk", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L1136-L1144
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addJoinRefFk
protected function addJoinRefFk(&$script, $fk) { $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getTable()->getDatabase()->getTable($fk->getTableName()); $relationName = $this->getRefFKPhpNameAffix($fk); $joinType = $this->getJoinType($fk); $this->addJoinRelated($script, $fkTable, $queryClass, $relationName, $joinType); }
php
protected function addJoinRefFk(&$script, $fk) { $table = $this->getTable(); $queryClass = $this->getStubQueryBuilder()->getClassname(); $fkTable = $this->getTable()->getDatabase()->getTable($fk->getTableName()); $relationName = $this->getRefFKPhpNameAffix($fk); $joinType = $this->getJoinType($fk); $this->addJoinRelated($script, $fkTable, $queryClass, $relationName, $joinType); }
[ "protected", "function", "addJoinRefFk", "(", "&", "$", "script", ",", "$", "fk", ")", "{", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "queryClass", "=", "$", "this", "->", "getStubQueryBuilder", "(", ")", "->", "getClassname", "(", ")", ";", "$", "fkTable", "=", "$", "this", "->", "getTable", "(", ")", "->", "getDatabase", "(", ")", "->", "getTable", "(", "$", "fk", "->", "getTableName", "(", ")", ")", ";", "$", "relationName", "=", "$", "this", "->", "getRefFKPhpNameAffix", "(", "$", "fk", ")", ";", "$", "joinType", "=", "$", "this", "->", "getJoinType", "(", "$", "fk", ")", ";", "$", "this", "->", "addJoinRelated", "(", "$", "script", ",", "$", "fkTable", ",", "$", "queryClass", ",", "$", "relationName", ",", "$", "joinType", ")", ";", "}" ]
Adds the joinRefFk method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "the", "joinRefFk", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L1151-L1159
propelorm/Propel
generator/lib/builder/om/QueryBuilder.php
QueryBuilder.addJoinRelated
protected function addJoinRelated(&$script, $fkTable, $queryClass, $relationName, $joinType) { $script .= " /** * Adds a JOIN clause to the query using the " . $relationName . " relation * * @param string \$relationAlias optional alias for the relation * @param string \$joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return " . $queryClass . " The current query, for fluid interface */ public function join" . $relationName . "(\$relationAlias = null, \$joinType = " . $joinType . ") { \$tableMap = \$this->getTableMap(); \$relationMap = \$tableMap->getRelation('" . $relationName . "'); // create a ModelJoin object for this join \$join = new ModelJoin(); \$join->setJoinType(\$joinType); \$join->setRelationMap(\$relationMap, \$this->useAliasInSQL ? \$this->getModelAlias() : null, \$relationAlias); if (\$previousJoin = \$this->getPreviousJoin()) { \$join->setPreviousJoin(\$previousJoin); } // add the ModelJoin to the current object if (\$relationAlias) { \$this->addAlias(\$relationAlias, \$relationMap->getRightTable()->getName()); \$this->addJoinObject(\$join, \$relationAlias); } else { \$this->addJoinObject(\$join, '" . $relationName . "'); } return \$this; } "; }
php
protected function addJoinRelated(&$script, $fkTable, $queryClass, $relationName, $joinType) { $script .= " /** * Adds a JOIN clause to the query using the " . $relationName . " relation * * @param string \$relationAlias optional alias for the relation * @param string \$joinType Accepted values are null, 'left join', 'right join', 'inner join' * * @return " . $queryClass . " The current query, for fluid interface */ public function join" . $relationName . "(\$relationAlias = null, \$joinType = " . $joinType . ") { \$tableMap = \$this->getTableMap(); \$relationMap = \$tableMap->getRelation('" . $relationName . "'); // create a ModelJoin object for this join \$join = new ModelJoin(); \$join->setJoinType(\$joinType); \$join->setRelationMap(\$relationMap, \$this->useAliasInSQL ? \$this->getModelAlias() : null, \$relationAlias); if (\$previousJoin = \$this->getPreviousJoin()) { \$join->setPreviousJoin(\$previousJoin); } // add the ModelJoin to the current object if (\$relationAlias) { \$this->addAlias(\$relationAlias, \$relationMap->getRightTable()->getName()); \$this->addJoinObject(\$join, \$relationAlias); } else { \$this->addJoinObject(\$join, '" . $relationName . "'); } return \$this; } "; }
[ "protected", "function", "addJoinRelated", "(", "&", "$", "script", ",", "$", "fkTable", ",", "$", "queryClass", ",", "$", "relationName", ",", "$", "joinType", ")", "{", "$", "script", ".=", "\"\n /**\n * Adds a JOIN clause to the query using the \"", ".", "$", "relationName", ".", "\" relation\n *\n * @param string \\$relationAlias optional alias for the relation\n * @param string \\$joinType Accepted values are null, 'left join', 'right join', 'inner join'\n *\n * @return \"", ".", "$", "queryClass", ".", "\" The current query, for fluid interface\n */\n public function join\"", ".", "$", "relationName", ".", "\"(\\$relationAlias = null, \\$joinType = \"", ".", "$", "joinType", ".", "\")\n {\n \\$tableMap = \\$this->getTableMap();\n \\$relationMap = \\$tableMap->getRelation('\"", ".", "$", "relationName", ".", "\"');\n\n // create a ModelJoin object for this join\n \\$join = new ModelJoin();\n \\$join->setJoinType(\\$joinType);\n \\$join->setRelationMap(\\$relationMap, \\$this->useAliasInSQL ? \\$this->getModelAlias() : null, \\$relationAlias);\n if (\\$previousJoin = \\$this->getPreviousJoin()) {\n \\$join->setPreviousJoin(\\$previousJoin);\n }\n\n // add the ModelJoin to the current object\n if (\\$relationAlias) {\n \\$this->addAlias(\\$relationAlias, \\$relationMap->getRightTable()->getName());\n \\$this->addJoinObject(\\$join, \\$relationAlias);\n } else {\n \\$this->addJoinObject(\\$join, '\"", ".", "$", "relationName", ".", "\"');\n }\n\n return \\$this;\n }\n\"", ";", "}" ]
Adds a joinRelated method for this object. @param string &$script The script will be modified in this method.
[ "Adds", "a", "joinRelated", "method", "for", "this", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/QueryBuilder.php#L1166-L1201