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 | runtime/lib/map/DatabaseMap.php | DatabaseMap.getTable | public function getTable($name)
{
if (!isset($this->tables[$name])) {
throw new PropelException("Cannot fetch TableMap for undefined table: " . $name);
}
return $this->tables[$name];
} | php | public function getTable($name)
{
if (!isset($this->tables[$name])) {
throw new PropelException("Cannot fetch TableMap for undefined table: " . $name);
}
return $this->tables[$name];
} | [
"public",
"function",
"getTable",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"PropelException",
"(",
"\"Cannot fetch TableMap for undefined table: \"",
".",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"tables",
"[",
"$",
"name",
"]",
";",
"}"
] | Get a TableMap for the table by name.
@param string $name Name of the table.
@return TableMap A TableMap
@throws PropelException if the table is undefined | [
"Get",
"a",
"TableMap",
"for",
"the",
"table",
"by",
"name",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/map/DatabaseMap.php#L123-L130 |
propelorm/Propel | generator/lib/reverse/pgsql/PgsqlSchemaParser.php | PgsqlSchemaParser.addColumns | protected function addColumns(Table $table, $oid, $version)
{
// Get the columns, types, etc.
// Based on code from pgAdmin3 (http://www.pgadmin.org/)
$stmt = $this->dbh->prepare("SELECT
att.attname,
att.atttypmod,
att.atthasdef,
att.attnotnull,
def.adsrc,
CASE WHEN att.attndims > 0 THEN 1 ELSE 0 END AS isarray,
CASE
WHEN ty.typname = 'bpchar'
THEN 'char'
WHEN ty.typname = '_bpchar'
THEN '_char'
ELSE
ty.typname
END AS typname,
ty.typtype
FROM pg_attribute att
JOIN pg_type ty ON ty.oid=att.atttypid
LEFT OUTER JOIN pg_attrdef def ON adrelid=att.attrelid AND adnum=att.attnum
WHERE att.attrelid = ? AND att.attnum > 0
AND att.attisdropped IS FALSE
ORDER BY att.attnum");
$stmt->bindValue(1, $oid, PDO::PARAM_INT);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$size = null;
$precision = null;
$scale = null;
// Check to ensure that this column isn't an array data type
if (((int) $row['isarray']) === 1) {
throw new EngineException (sprintf("Array datatypes are not currently supported [%s.%s]", $this->name, $row['attname']));
} // if (((int) $row['isarray']) === 1)
$name = $row['attname'];
// If they type is a domain, Process it
if (strtolower($row['typtype']) == 'd') {
$arrDomain = $this->processDomain($row['typname']);
$type = $arrDomain['type'];
$size = $arrDomain['length'];
$precision = $size;
$scale = $arrDomain['scale'];
$boolHasDefault = (strlen(trim($row['atthasdef'])) > 0) ? $row['atthasdef'] : $arrDomain['hasdefault'];
$default = (strlen(trim($row['adsrc'])) > 0) ? $row['adsrc'] : $arrDomain['default'];
$is_nullable = (strlen(trim($row['attnotnull'])) > 0) ? $row['attnotnull'] : $arrDomain['notnull'];
$is_nullable = (($is_nullable == 't') ? false : true);
} else {
$type = $row['typname'];
$arrLengthPrecision = $this->processLengthScale($row['atttypmod'], $type);
$size = $arrLengthPrecision['length'];
$precision = $size;
$scale = $arrLengthPrecision['scale'];
$boolHasDefault = $row['atthasdef'];
$default = $row['adsrc'];
$is_nullable = (($row['attnotnull'] == 't') ? false : true);
} // else (strtolower ($row['typtype']) == 'd')
$autoincrement = null;
// if column has a default
if (($boolHasDefault == 't') && (strlen(trim($default)) > 0)) {
if (!preg_match('/^nextval\(/', $default)) {
$strDefault = preg_replace('/::[\W\D]*/', '', $default);
$default = str_replace("'", '', $strDefault);
} else {
$autoincrement = true;
$default = null;
}
} else {
$default = null;
}
$propelType = $this->getMappedPropelType($type);
if (!$propelType) {
$propelType = Column::DEFAULT_TYPE;
$this->warn("Column [" . $table->getName() . "." . $name . "] has a column type (" . $type . ") that Propel does not support.");
}
$column = new Column($name);
$column->setTable($table);
$column->setDomainForType($propelType);
// We may want to provide an option to include this:
// $column->getDomain()->replaceSqlType($type);
$column->getDomain()->replaceSize($size);
$column->getDomain()->replaceScale($scale);
if ($default !== null) {
if (in_array($default, array('now()'))) {
$type = ColumnDefaultValue::TYPE_EXPR;
} else {
$type = ColumnDefaultValue::TYPE_VALUE;
}
$column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, $type));
}
$column->setAutoIncrement($autoincrement);
$column->setNotNull(!$is_nullable);
$table->addColumn($column);
}
} | php | protected function addColumns(Table $table, $oid, $version)
{
// Get the columns, types, etc.
// Based on code from pgAdmin3 (http://www.pgadmin.org/)
$stmt = $this->dbh->prepare("SELECT
att.attname,
att.atttypmod,
att.atthasdef,
att.attnotnull,
def.adsrc,
CASE WHEN att.attndims > 0 THEN 1 ELSE 0 END AS isarray,
CASE
WHEN ty.typname = 'bpchar'
THEN 'char'
WHEN ty.typname = '_bpchar'
THEN '_char'
ELSE
ty.typname
END AS typname,
ty.typtype
FROM pg_attribute att
JOIN pg_type ty ON ty.oid=att.atttypid
LEFT OUTER JOIN pg_attrdef def ON adrelid=att.attrelid AND adnum=att.attnum
WHERE att.attrelid = ? AND att.attnum > 0
AND att.attisdropped IS FALSE
ORDER BY att.attnum");
$stmt->bindValue(1, $oid, PDO::PARAM_INT);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$size = null;
$precision = null;
$scale = null;
// Check to ensure that this column isn't an array data type
if (((int) $row['isarray']) === 1) {
throw new EngineException (sprintf("Array datatypes are not currently supported [%s.%s]", $this->name, $row['attname']));
} // if (((int) $row['isarray']) === 1)
$name = $row['attname'];
// If they type is a domain, Process it
if (strtolower($row['typtype']) == 'd') {
$arrDomain = $this->processDomain($row['typname']);
$type = $arrDomain['type'];
$size = $arrDomain['length'];
$precision = $size;
$scale = $arrDomain['scale'];
$boolHasDefault = (strlen(trim($row['atthasdef'])) > 0) ? $row['atthasdef'] : $arrDomain['hasdefault'];
$default = (strlen(trim($row['adsrc'])) > 0) ? $row['adsrc'] : $arrDomain['default'];
$is_nullable = (strlen(trim($row['attnotnull'])) > 0) ? $row['attnotnull'] : $arrDomain['notnull'];
$is_nullable = (($is_nullable == 't') ? false : true);
} else {
$type = $row['typname'];
$arrLengthPrecision = $this->processLengthScale($row['atttypmod'], $type);
$size = $arrLengthPrecision['length'];
$precision = $size;
$scale = $arrLengthPrecision['scale'];
$boolHasDefault = $row['atthasdef'];
$default = $row['adsrc'];
$is_nullable = (($row['attnotnull'] == 't') ? false : true);
} // else (strtolower ($row['typtype']) == 'd')
$autoincrement = null;
// if column has a default
if (($boolHasDefault == 't') && (strlen(trim($default)) > 0)) {
if (!preg_match('/^nextval\(/', $default)) {
$strDefault = preg_replace('/::[\W\D]*/', '', $default);
$default = str_replace("'", '', $strDefault);
} else {
$autoincrement = true;
$default = null;
}
} else {
$default = null;
}
$propelType = $this->getMappedPropelType($type);
if (!$propelType) {
$propelType = Column::DEFAULT_TYPE;
$this->warn("Column [" . $table->getName() . "." . $name . "] has a column type (" . $type . ") that Propel does not support.");
}
$column = new Column($name);
$column->setTable($table);
$column->setDomainForType($propelType);
// We may want to provide an option to include this:
// $column->getDomain()->replaceSqlType($type);
$column->getDomain()->replaceSize($size);
$column->getDomain()->replaceScale($scale);
if ($default !== null) {
if (in_array($default, array('now()'))) {
$type = ColumnDefaultValue::TYPE_EXPR;
} else {
$type = ColumnDefaultValue::TYPE_VALUE;
}
$column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, $type));
}
$column->setAutoIncrement($autoincrement);
$column->setNotNull(!$is_nullable);
$table->addColumn($column);
}
} | [
"protected",
"function",
"addColumns",
"(",
"Table",
"$",
"table",
",",
"$",
"oid",
",",
"$",
"version",
")",
"{",
"// Get the columns, types, etc.",
"// Based on code from pgAdmin3 (http://www.pgadmin.org/)",
"$",
"stmt",
"=",
"$",
"this",
"->",
"dbh",
"->",
"prepare",
"(",
"\"SELECT\n att.attname,\n att.atttypmod,\n att.atthasdef,\n att.attnotnull,\n def.adsrc,\n CASE WHEN att.attndims > 0 THEN 1 ELSE 0 END AS isarray,\n CASE\n WHEN ty.typname = 'bpchar'\n THEN 'char'\n WHEN ty.typname = '_bpchar'\n THEN '_char'\n ELSE\n ty.typname\n END AS typname,\n ty.typtype\n FROM pg_attribute att\n JOIN pg_type ty ON ty.oid=att.atttypid\n LEFT OUTER JOIN pg_attrdef def ON adrelid=att.attrelid AND adnum=att.attnum\n WHERE att.attrelid = ? AND att.attnum > 0\n AND att.attisdropped IS FALSE\n ORDER BY att.attnum\"",
")",
";",
"$",
"stmt",
"->",
"bindValue",
"(",
"1",
",",
"$",
"oid",
",",
"PDO",
"::",
"PARAM_INT",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"$",
"size",
"=",
"null",
";",
"$",
"precision",
"=",
"null",
";",
"$",
"scale",
"=",
"null",
";",
"// Check to ensure that this column isn't an array data type",
"if",
"(",
"(",
"(",
"int",
")",
"$",
"row",
"[",
"'isarray'",
"]",
")",
"===",
"1",
")",
"{",
"throw",
"new",
"EngineException",
"(",
"sprintf",
"(",
"\"Array datatypes are not currently supported [%s.%s]\"",
",",
"$",
"this",
"->",
"name",
",",
"$",
"row",
"[",
"'attname'",
"]",
")",
")",
";",
"}",
"// if (((int) $row['isarray']) === 1)",
"$",
"name",
"=",
"$",
"row",
"[",
"'attname'",
"]",
";",
"// If they type is a domain, Process it",
"if",
"(",
"strtolower",
"(",
"$",
"row",
"[",
"'typtype'",
"]",
")",
"==",
"'d'",
")",
"{",
"$",
"arrDomain",
"=",
"$",
"this",
"->",
"processDomain",
"(",
"$",
"row",
"[",
"'typname'",
"]",
")",
";",
"$",
"type",
"=",
"$",
"arrDomain",
"[",
"'type'",
"]",
";",
"$",
"size",
"=",
"$",
"arrDomain",
"[",
"'length'",
"]",
";",
"$",
"precision",
"=",
"$",
"size",
";",
"$",
"scale",
"=",
"$",
"arrDomain",
"[",
"'scale'",
"]",
";",
"$",
"boolHasDefault",
"=",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"row",
"[",
"'atthasdef'",
"]",
")",
")",
">",
"0",
")",
"?",
"$",
"row",
"[",
"'atthasdef'",
"]",
":",
"$",
"arrDomain",
"[",
"'hasdefault'",
"]",
";",
"$",
"default",
"=",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"row",
"[",
"'adsrc'",
"]",
")",
")",
">",
"0",
")",
"?",
"$",
"row",
"[",
"'adsrc'",
"]",
":",
"$",
"arrDomain",
"[",
"'default'",
"]",
";",
"$",
"is_nullable",
"=",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"row",
"[",
"'attnotnull'",
"]",
")",
")",
">",
"0",
")",
"?",
"$",
"row",
"[",
"'attnotnull'",
"]",
":",
"$",
"arrDomain",
"[",
"'notnull'",
"]",
";",
"$",
"is_nullable",
"=",
"(",
"(",
"$",
"is_nullable",
"==",
"'t'",
")",
"?",
"false",
":",
"true",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"$",
"row",
"[",
"'typname'",
"]",
";",
"$",
"arrLengthPrecision",
"=",
"$",
"this",
"->",
"processLengthScale",
"(",
"$",
"row",
"[",
"'atttypmod'",
"]",
",",
"$",
"type",
")",
";",
"$",
"size",
"=",
"$",
"arrLengthPrecision",
"[",
"'length'",
"]",
";",
"$",
"precision",
"=",
"$",
"size",
";",
"$",
"scale",
"=",
"$",
"arrLengthPrecision",
"[",
"'scale'",
"]",
";",
"$",
"boolHasDefault",
"=",
"$",
"row",
"[",
"'atthasdef'",
"]",
";",
"$",
"default",
"=",
"$",
"row",
"[",
"'adsrc'",
"]",
";",
"$",
"is_nullable",
"=",
"(",
"(",
"$",
"row",
"[",
"'attnotnull'",
"]",
"==",
"'t'",
")",
"?",
"false",
":",
"true",
")",
";",
"}",
"// else (strtolower ($row['typtype']) == 'd')",
"$",
"autoincrement",
"=",
"null",
";",
"// if column has a default",
"if",
"(",
"(",
"$",
"boolHasDefault",
"==",
"'t'",
")",
"&&",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"default",
")",
")",
">",
"0",
")",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^nextval\\(/'",
",",
"$",
"default",
")",
")",
"{",
"$",
"strDefault",
"=",
"preg_replace",
"(",
"'/::[\\W\\D]*/'",
",",
"''",
",",
"$",
"default",
")",
";",
"$",
"default",
"=",
"str_replace",
"(",
"\"'\"",
",",
"''",
",",
"$",
"strDefault",
")",
";",
"}",
"else",
"{",
"$",
"autoincrement",
"=",
"true",
";",
"$",
"default",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"$",
"default",
"=",
"null",
";",
"}",
"$",
"propelType",
"=",
"$",
"this",
"->",
"getMappedPropelType",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"$",
"propelType",
")",
"{",
"$",
"propelType",
"=",
"Column",
"::",
"DEFAULT_TYPE",
";",
"$",
"this",
"->",
"warn",
"(",
"\"Column [\"",
".",
"$",
"table",
"->",
"getName",
"(",
")",
".",
"\".\"",
".",
"$",
"name",
".",
"\"] has a column type (\"",
".",
"$",
"type",
".",
"\") that Propel does not support.\"",
")",
";",
"}",
"$",
"column",
"=",
"new",
"Column",
"(",
"$",
"name",
")",
";",
"$",
"column",
"->",
"setTable",
"(",
"$",
"table",
")",
";",
"$",
"column",
"->",
"setDomainForType",
"(",
"$",
"propelType",
")",
";",
"// We may want to provide an option to include this:",
"// $column->getDomain()->replaceSqlType($type);",
"$",
"column",
"->",
"getDomain",
"(",
")",
"->",
"replaceSize",
"(",
"$",
"size",
")",
";",
"$",
"column",
"->",
"getDomain",
"(",
")",
"->",
"replaceScale",
"(",
"$",
"scale",
")",
";",
"if",
"(",
"$",
"default",
"!==",
"null",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"default",
",",
"array",
"(",
"'now()'",
")",
")",
")",
"{",
"$",
"type",
"=",
"ColumnDefaultValue",
"::",
"TYPE_EXPR",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"ColumnDefaultValue",
"::",
"TYPE_VALUE",
";",
"}",
"$",
"column",
"->",
"getDomain",
"(",
")",
"->",
"setDefaultValue",
"(",
"new",
"ColumnDefaultValue",
"(",
"$",
"default",
",",
"$",
"type",
")",
")",
";",
"}",
"$",
"column",
"->",
"setAutoIncrement",
"(",
"$",
"autoincrement",
")",
";",
"$",
"column",
"->",
"setNotNull",
"(",
"!",
"$",
"is_nullable",
")",
";",
"$",
"table",
"->",
"addColumn",
"(",
"$",
"column",
")",
";",
"}",
"}"
] | Adds Columns to the specified table.
@param Table $table The Table model class to add columns to.
@param int $oid The table OID
@param string $version The database version.
@throws EngineException | [
"Adds",
"Columns",
"to",
"the",
"specified",
"table",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/reverse/pgsql/PgsqlSchemaParser.php#L169-L275 |
propelorm/Propel | generator/lib/reverse/pgsql/PgsqlSchemaParser.php | PgsqlSchemaParser.addPrimaryKey | protected function addPrimaryKey(Table $table, $oid, $version)
{
$stmt = $this->dbh->prepare("SELECT
DISTINCT ON(cls.relname)
cls.relname as idxname,
indkey,
indisunique
FROM pg_index idx
JOIN pg_class cls ON cls.oid=indexrelid
WHERE indrelid = ? AND indisprimary
ORDER BY cls.relname");
$stmt->bindValue(1, $oid);
$stmt->execute();
// Loop through the returned results, grouping the same key_name together
// adding each column for that key.
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$arrColumns = explode(' ', $row['indkey']);
foreach ($arrColumns as $intColNum) {
$stmt2 = $this->dbh->prepare("SELECT a.attname
FROM pg_catalog.pg_class c JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
WHERE c.oid = ? AND a.attnum = ? AND NOT a.attisdropped
ORDER BY a.attnum");
$stmt2->bindValue(1, $oid);
$stmt2->bindValue(2, $intColNum);
$stmt2->execute();
$row2 = $stmt2->fetch(PDO::FETCH_ASSOC);
$table->getColumn($row2['attname'])->setPrimaryKey(true);
} // foreach ($arrColumns as $intColNum)
}
} | php | protected function addPrimaryKey(Table $table, $oid, $version)
{
$stmt = $this->dbh->prepare("SELECT
DISTINCT ON(cls.relname)
cls.relname as idxname,
indkey,
indisunique
FROM pg_index idx
JOIN pg_class cls ON cls.oid=indexrelid
WHERE indrelid = ? AND indisprimary
ORDER BY cls.relname");
$stmt->bindValue(1, $oid);
$stmt->execute();
// Loop through the returned results, grouping the same key_name together
// adding each column for that key.
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$arrColumns = explode(' ', $row['indkey']);
foreach ($arrColumns as $intColNum) {
$stmt2 = $this->dbh->prepare("SELECT a.attname
FROM pg_catalog.pg_class c JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
WHERE c.oid = ? AND a.attnum = ? AND NOT a.attisdropped
ORDER BY a.attnum");
$stmt2->bindValue(1, $oid);
$stmt2->bindValue(2, $intColNum);
$stmt2->execute();
$row2 = $stmt2->fetch(PDO::FETCH_ASSOC);
$table->getColumn($row2['attname'])->setPrimaryKey(true);
} // foreach ($arrColumns as $intColNum)
}
} | [
"protected",
"function",
"addPrimaryKey",
"(",
"Table",
"$",
"table",
",",
"$",
"oid",
",",
"$",
"version",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"dbh",
"->",
"prepare",
"(",
"\"SELECT\n DISTINCT ON(cls.relname)\n cls.relname as idxname,\n indkey,\n indisunique\n FROM pg_index idx\n JOIN pg_class cls ON cls.oid=indexrelid\n WHERE indrelid = ? AND indisprimary\n ORDER BY cls.relname\"",
")",
";",
"$",
"stmt",
"->",
"bindValue",
"(",
"1",
",",
"$",
"oid",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
")",
";",
"// Loop through the returned results, grouping the same key_name together",
"// adding each column for that key.",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
"{",
"$",
"arrColumns",
"=",
"explode",
"(",
"' '",
",",
"$",
"row",
"[",
"'indkey'",
"]",
")",
";",
"foreach",
"(",
"$",
"arrColumns",
"as",
"$",
"intColNum",
")",
"{",
"$",
"stmt2",
"=",
"$",
"this",
"->",
"dbh",
"->",
"prepare",
"(",
"\"SELECT a.attname\n FROM pg_catalog.pg_class c JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid\n WHERE c.oid = ? AND a.attnum = ? AND NOT a.attisdropped\n ORDER BY a.attnum\"",
")",
";",
"$",
"stmt2",
"->",
"bindValue",
"(",
"1",
",",
"$",
"oid",
")",
";",
"$",
"stmt2",
"->",
"bindValue",
"(",
"2",
",",
"$",
"intColNum",
")",
";",
"$",
"stmt2",
"->",
"execute",
"(",
")",
";",
"$",
"row2",
"=",
"$",
"stmt2",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"table",
"->",
"getColumn",
"(",
"$",
"row2",
"[",
"'attname'",
"]",
")",
"->",
"setPrimaryKey",
"(",
"true",
")",
";",
"}",
"// foreach ($arrColumns as $intColNum)",
"}",
"}"
] | 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/pgsql/PgsqlSchemaParser.php#L507-L540 |
propelorm/Propel | generator/lib/builder/om/PHP5ExtensionPeerBuilder.php | PHP5ExtensionPeerBuilder.addIncludes | protected function addIncludes(&$script)
{
switch ($this->getTable()->treeMode()) {
case 'NestedSet':
$requiredClassFilePath = $this->getNestedSetPeerBuilder()->getClassFilePath();
break;
case 'MaterializedPath':
case 'AdjacencyList':
default:
$requiredClassFilePath = $this->getPeerBuilder()->getClassFilePath();
break;
}
$script .= "
require '" . $requiredClassFilePath . "';
";
} | php | protected function addIncludes(&$script)
{
switch ($this->getTable()->treeMode()) {
case 'NestedSet':
$requiredClassFilePath = $this->getNestedSetPeerBuilder()->getClassFilePath();
break;
case 'MaterializedPath':
case 'AdjacencyList':
default:
$requiredClassFilePath = $this->getPeerBuilder()->getClassFilePath();
break;
}
$script .= "
require '" . $requiredClassFilePath . "';
";
} | [
"protected",
"function",
"addIncludes",
"(",
"&",
"$",
"script",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"treeMode",
"(",
")",
")",
"{",
"case",
"'NestedSet'",
":",
"$",
"requiredClassFilePath",
"=",
"$",
"this",
"->",
"getNestedSetPeerBuilder",
"(",
")",
"->",
"getClassFilePath",
"(",
")",
";",
"break",
";",
"case",
"'MaterializedPath'",
":",
"case",
"'AdjacencyList'",
":",
"default",
":",
"$",
"requiredClassFilePath",
"=",
"$",
"this",
"->",
"getPeerBuilder",
"(",
")",
"->",
"getClassFilePath",
"(",
")",
";",
"break",
";",
"}",
"$",
"script",
".=",
"\"\nrequire '\"",
".",
"$",
"requiredClassFilePath",
".",
"\"';\n\"",
";",
"}"
] | Adds the include() statements for files that this class depends on or utilizes.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"include",
"()",
"statements",
"for",
"files",
"that",
"this",
"class",
"depends",
"on",
"or",
"utilizes",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5ExtensionPeerBuilder.php#L40-L57 |
propelorm/Propel | generator/lib/builder/om/PHP5ExtensionPeerBuilder.php | PHP5ExtensionPeerBuilder.addClassOpen | protected function addClassOpen(&$script)
{
$table = $this->getTable();
$this->declareClassFromBuilder($this->getPeerBuilder());
$tableName = $table->getName();
$tableDesc = $table->getDescription();
switch ($table->treeMode()) {
case 'NestedSet':
$baseClassname = $this->getNestedSetPeerBuilder()->getClassname();
break;
case 'MaterializedPath':
case 'AdjacencyList':
default:
$baseClassname = $this->getPeerBuilder()->getClassname();
break;
}
if ($this->getBuildProperty('addClassLevelComment')) {
$script .= "
/**
* Skeleton subclass for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator." . $this->getPackage() . "
*/";
}
$script .= "
class " . $this->getClassname() . " extends $baseClassname
{";
} | php | protected function addClassOpen(&$script)
{
$table = $this->getTable();
$this->declareClassFromBuilder($this->getPeerBuilder());
$tableName = $table->getName();
$tableDesc = $table->getDescription();
switch ($table->treeMode()) {
case 'NestedSet':
$baseClassname = $this->getNestedSetPeerBuilder()->getClassname();
break;
case 'MaterializedPath':
case 'AdjacencyList':
default:
$baseClassname = $this->getPeerBuilder()->getClassname();
break;
}
if ($this->getBuildProperty('addClassLevelComment')) {
$script .= "
/**
* Skeleton subclass for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
*
* @package propel.generator." . $this->getPackage() . "
*/";
}
$script .= "
class " . $this->getClassname() . " extends $baseClassname
{";
} | [
"protected",
"function",
"addClassOpen",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"this",
"->",
"declareClassFromBuilder",
"(",
"$",
"this",
"->",
"getPeerBuilder",
"(",
")",
")",
";",
"$",
"tableName",
"=",
"$",
"table",
"->",
"getName",
"(",
")",
";",
"$",
"tableDesc",
"=",
"$",
"table",
"->",
"getDescription",
"(",
")",
";",
"switch",
"(",
"$",
"table",
"->",
"treeMode",
"(",
")",
")",
"{",
"case",
"'NestedSet'",
":",
"$",
"baseClassname",
"=",
"$",
"this",
"->",
"getNestedSetPeerBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
";",
"break",
";",
"case",
"'MaterializedPath'",
":",
"case",
"'AdjacencyList'",
":",
"default",
":",
"$",
"baseClassname",
"=",
"$",
"this",
"->",
"getPeerBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getBuildProperty",
"(",
"'addClassLevelComment'",
")",
")",
"{",
"$",
"script",
".=",
"\"\n\n/**\n * Skeleton subclass for performing query and update operations on 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 *\"",
";",
"}",
"$",
"script",
".=",
"\"\n * You should add additional methods to this class to meet the\n * application requirements. This class will only be generated as\n * long as it does not already exist in the output directory.\n *\n * @package propel.generator.\"",
".",
"$",
"this",
"->",
"getPackage",
"(",
")",
".",
"\"\n */\"",
";",
"}",
"$",
"script",
".=",
"\"\nclass \"",
".",
"$",
"this",
"->",
"getClassname",
"(",
")",
".",
"\" extends $baseClassname\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/PHP5ExtensionPeerBuilder.php#L64-L111 |
propelorm/Propel | runtime/lib/parser/PropelParser.php | PropelParser.load | public function load($path)
{
if (!file_exists($path)) {
throw new PropelException(sprintf('File "%s" does not exist or is unreadable', $path));
}
ob_start();
include($path);
$contents = ob_get_clean();
return $contents;
} | php | public function load($path)
{
if (!file_exists($path)) {
throw new PropelException(sprintf('File "%s" does not exist or is unreadable', $path));
}
ob_start();
include($path);
$contents = ob_get_clean();
return $contents;
} | [
"public",
"function",
"load",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"PropelException",
"(",
"sprintf",
"(",
"'File \"%s\" does not exist or is unreadable'",
",",
"$",
"path",
")",
")",
";",
"}",
"ob_start",
"(",
")",
";",
"include",
"(",
"$",
"path",
")",
";",
"$",
"contents",
"=",
"ob_get_clean",
"(",
")",
";",
"return",
"$",
"contents",
";",
"}"
] | Loads data from a file. Executes PHP code blocks in the file.
@param string $path Path to the file to load
@return string The file content processed by PHP
@throws PropelException | [
"Loads",
"data",
"from",
"a",
"file",
".",
"Executes",
"PHP",
"code",
"blocks",
"in",
"the",
"file",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/parser/PropelParser.php#L61-L71 |
propelorm/Propel | runtime/lib/parser/PropelParser.php | PropelParser.dump | public function dump($data, $path = null)
{
if ($path !== null) {
return file_put_contents($path, $data);
} else {
echo $data;
}
} | php | public function dump($data, $path = null)
{
if ($path !== null) {
return file_put_contents($path, $data);
} else {
echo $data;
}
} | [
"public",
"function",
"dump",
"(",
"$",
"data",
",",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"!==",
"null",
")",
"{",
"return",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"echo",
"$",
"data",
";",
"}",
"}"
] | Dumps data to a file, or to STDOUT if no filename is given
@param string $data The file content
@param string $path Path of the file to create
@return int|null If path given, the written bytes, null otherwise. | [
"Dumps",
"data",
"to",
"a",
"file",
"or",
"to",
"STDOUT",
"if",
"no",
"filename",
"is",
"given"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/parser/PropelParser.php#L81-L88 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.getPrevious | public function getPrevious()
{
$pos = $this->getPosition();
if ($pos == 0) {
return null;
} else {
$this->getInternalIterator()->seek($pos - 1);
return $this->getCurrent();
}
} | php | public function getPrevious()
{
$pos = $this->getPosition();
if ($pos == 0) {
return null;
} else {
$this->getInternalIterator()->seek($pos - 1);
return $this->getCurrent();
}
} | [
"public",
"function",
"getPrevious",
"(",
")",
"{",
"$",
"pos",
"=",
"$",
"this",
"->",
"getPosition",
"(",
")",
";",
"if",
"(",
"$",
"pos",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getInternalIterator",
"(",
")",
"->",
"seek",
"(",
"$",
"pos",
"-",
"1",
")",
";",
"return",
"$",
"this",
"->",
"getCurrent",
"(",
")",
";",
"}",
"}"
] | Move the internal pointer backward
And get the previous element in the collection
@return mixed | [
"Move",
"the",
"internal",
"pointer",
"backward",
"And",
"get",
"the",
"previous",
"element",
"in",
"the",
"collection"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L107-L117 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.getLast | public function getLast()
{
$count = $this->count();
if ($count == 0) {
return null;
} else {
$this->getInternalIterator()->seek($count - 1);
return $this->getCurrent();
}
} | php | public function getLast()
{
$count = $this->count();
if ($count == 0) {
return null;
} else {
$this->getInternalIterator()->seek($count - 1);
return $this->getCurrent();
}
} | [
"public",
"function",
"getLast",
"(",
")",
"{",
"$",
"count",
"=",
"$",
"this",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"count",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"getInternalIterator",
"(",
")",
"->",
"seek",
"(",
"$",
"count",
"-",
"1",
")",
";",
"return",
"$",
"this",
"->",
"getCurrent",
"(",
")",
";",
"}",
"}"
] | Move the internal pointer to the end of the list
And get the last element in the collection
@return mixed | [
"Move",
"the",
"internal",
"pointer",
"to",
"the",
"end",
"of",
"the",
"list",
"And",
"get",
"the",
"last",
"element",
"in",
"the",
"collection"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L148-L158 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.get | public function get($key)
{
if (!$this->offsetExists($key)) {
throw new PropelException('Unknown key ' . $key);
}
return $this->offsetGet($key);
} | php | public function get($key)
{
if (!$this->offsetExists($key)) {
throw new PropelException('Unknown key ' . $key);
}
return $this->offsetGet($key);
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"PropelException",
"(",
"'Unknown key '",
".",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"key",
")",
";",
"}"
] | Get an element from its key
Alias for ArrayObject::offsetGet()
@param mixed $key
@return mixed The element
@throws PropelException | [
"Get",
"an",
"element",
"from",
"its",
"key",
"Alias",
"for",
"ArrayObject",
"::",
"offsetGet",
"()"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L216-L223 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.pop | public function pop()
{
if ($this->count() == 0) {
return null;
}
$ret = $this->getLast();
$lastKey = $this->getInternalIterator()->key();
$this->offsetUnset((string) $lastKey);
return $ret;
} | php | public function pop()
{
if ($this->count() == 0) {
return null;
}
$ret = $this->getLast();
$lastKey = $this->getInternalIterator()->key();
$this->offsetUnset((string) $lastKey);
return $ret;
} | [
"public",
"function",
"pop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"ret",
"=",
"$",
"this",
"->",
"getLast",
"(",
")",
";",
"$",
"lastKey",
"=",
"$",
"this",
"->",
"getInternalIterator",
"(",
")",
"->",
"key",
"(",
")",
";",
"$",
"this",
"->",
"offsetUnset",
"(",
"(",
"string",
")",
"$",
"lastKey",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Pops an element off the end of the collection
@return mixed The popped element | [
"Pops",
"an",
"element",
"off",
"the",
"end",
"of",
"the",
"collection"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L230-L240 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.remove | public function remove($key)
{
if (!$this->offsetExists($key)) {
throw new PropelException('Unknown key ' . $key);
}
return $this->offsetUnset($key);
} | php | public function remove($key)
{
if (!$this->offsetExists($key)) {
throw new PropelException('Unknown key ' . $key);
}
return $this->offsetUnset($key);
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"PropelException",
"(",
"'Unknown key '",
".",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
"->",
"offsetUnset",
"(",
"$",
"key",
")",
";",
"}"
] | Removes a specified collection element
Alias for ArrayObject::offsetUnset()
@param mixed $key
@return mixed The removed element
@throws PropelException | [
"Removes",
"a",
"specified",
"collection",
"element",
"Alias",
"for",
"ArrayObject",
"::",
"offsetUnset",
"()"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L298-L305 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.diff | public function diff(PropelCollection $collection)
{
$diff = clone $this;
$diff->clear();
foreach ($this as $object) {
if (!$collection->contains($object)) {
$diff[] = $object;
}
}
return $diff;
} | php | public function diff(PropelCollection $collection)
{
$diff = clone $this;
$diff->clear();
foreach ($this as $object) {
if (!$collection->contains($object)) {
$diff[] = $object;
}
}
return $diff;
} | [
"public",
"function",
"diff",
"(",
"PropelCollection",
"$",
"collection",
")",
"{",
"$",
"diff",
"=",
"clone",
"$",
"this",
";",
"$",
"diff",
"->",
"clear",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"collection",
"->",
"contains",
"(",
"$",
"object",
")",
")",
"{",
"$",
"diff",
"[",
"]",
"=",
"$",
"object",
";",
"}",
"}",
"return",
"$",
"diff",
";",
"}"
] | Returns an array of objects present in the collection that
are not presents in the given collection.
@param PropelCollection $collection A Propel collection.
@return PropelCollection An array of Propel objects from the collection that are not presents in the given collection. | [
"Returns",
"an",
"array",
"of",
"objects",
"present",
"in",
"the",
"collection",
"that",
"are",
"not",
"presents",
"in",
"the",
"given",
"collection",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L349-L361 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.getConnection | public function getConnection($type = Propel::CONNECTION_READ)
{
$databaseName = constant($this->getPeerClass() . '::DATABASE_NAME');
return Propel::getConnection($databaseName, $type);
} | php | public function getConnection($type = Propel::CONNECTION_READ)
{
$databaseName = constant($this->getPeerClass() . '::DATABASE_NAME');
return Propel::getConnection($databaseName, $type);
} | [
"public",
"function",
"getConnection",
"(",
"$",
"type",
"=",
"Propel",
"::",
"CONNECTION_READ",
")",
"{",
"$",
"databaseName",
"=",
"constant",
"(",
"$",
"this",
"->",
"getPeerClass",
"(",
")",
".",
"'::DATABASE_NAME'",
")",
";",
"return",
"Propel",
"::",
"getConnection",
"(",
"$",
"databaseName",
",",
"$",
"type",
")",
";",
"}"
] | Get a connection object for the database containing the elements of the collection
@param string $type The connection type (Propel::CONNECTION_READ by default; can be Propel::connection_WRITE)
@return PropelPDO A PropelPDO connection object | [
"Get",
"a",
"connection",
"object",
"for",
"the",
"database",
"containing",
"the",
"elements",
"of",
"the",
"collection"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L490-L495 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.importFrom | public function importFrom($parser, $data)
{
if (!$parser instanceof PropelParser) {
$parser = PropelParser::getParser($parser);
}
return $this->fromArray($parser->listToArray($data), BasePeer::TYPE_PHPNAME);
} | php | public function importFrom($parser, $data)
{
if (!$parser instanceof PropelParser) {
$parser = PropelParser::getParser($parser);
}
return $this->fromArray($parser->listToArray($data), BasePeer::TYPE_PHPNAME);
} | [
"public",
"function",
"importFrom",
"(",
"$",
"parser",
",",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"parser",
"instanceof",
"PropelParser",
")",
"{",
"$",
"parser",
"=",
"PropelParser",
"::",
"getParser",
"(",
"$",
"parser",
")",
";",
"}",
"return",
"$",
"this",
"->",
"fromArray",
"(",
"$",
"parser",
"->",
"listToArray",
"(",
"$",
"data",
")",
",",
"BasePeer",
"::",
"TYPE_PHPNAME",
")",
";",
"}"
] | Populate the current collection from a string, using a given parser format
<code>
$coll = new PropelObjectCollection();
$coll->setModel('Book');
$coll->importFrom('JSON', '{{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}}');
</code>
@param mixed $parser A PropelParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
@param string $data The source data to import from
@return BaseObject The current object, for fluid interface | [
"Populate",
"the",
"current",
"collection",
"from",
"a",
"string",
"using",
"a",
"given",
"parser",
"format",
"<code",
">",
"$coll",
"=",
"new",
"PropelObjectCollection",
"()",
";",
"$coll",
"-",
">",
"setModel",
"(",
"Book",
")",
";",
"$coll",
"-",
">",
"importFrom",
"(",
"JSON",
"{{",
"Id",
":",
"9012",
"Title",
":",
"Don",
"Juan",
"ISBN",
":",
"0140422161",
"Price",
":",
"12",
".",
"99",
"PublisherId",
":",
"1234",
"AuthorId",
":",
"5678",
"}}",
")",
";",
"<",
"/",
"code",
">"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L510-L517 |
propelorm/Propel | runtime/lib/collection/PropelCollection.php | PropelCollection.exportTo | public function exportTo($parser, $usePrefix = true, $includeLazyLoadColumns = true)
{
if (!$parser instanceof PropelParser) {
$parser = PropelParser::getParser($parser);
}
return $parser->listFromArray($this->toArray(null, $usePrefix, BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns));
} | php | public function exportTo($parser, $usePrefix = true, $includeLazyLoadColumns = true)
{
if (!$parser instanceof PropelParser) {
$parser = PropelParser::getParser($parser);
}
return $parser->listFromArray($this->toArray(null, $usePrefix, BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns));
} | [
"public",
"function",
"exportTo",
"(",
"$",
"parser",
",",
"$",
"usePrefix",
"=",
"true",
",",
"$",
"includeLazyLoadColumns",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"parser",
"instanceof",
"PropelParser",
")",
"{",
"$",
"parser",
"=",
"PropelParser",
"::",
"getParser",
"(",
"$",
"parser",
")",
";",
"}",
"return",
"$",
"parser",
"->",
"listFromArray",
"(",
"$",
"this",
"->",
"toArray",
"(",
"null",
",",
"$",
"usePrefix",
",",
"BasePeer",
"::",
"TYPE_PHPNAME",
",",
"$",
"includeLazyLoadColumns",
")",
")",
";",
"}"
] | Export the current collection to a string, using a given parser format
<code>
$books = BookQuery::create()->find();
echo $book->exportTo('JSON');
=> {{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}}');
</code>
A PropelOnDemandCollection cannot be exported. Any attempt will result in a PropelExecption being thrown.
@param mixed $parser A PropelParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV')
@param boolean $usePrefix (optional) If true, the returned element keys will be prefixed with the
model class name ('Article_0', 'Article_1', etc). Defaults to TRUE.
Not supported by PropelArrayCollection, as PropelArrayFormatter has
already created the array used here with integers as keys.
@param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE.
Not supported by PropelArrayCollection, as PropelArrayFormatter has
already included lazy-load columns in the array used here.
@return string The exported data | [
"Export",
"the",
"current",
"collection",
"to",
"a",
"string",
"using",
"a",
"given",
"parser",
"format",
"<code",
">",
"$books",
"=",
"BookQuery",
"::",
"create",
"()",
"-",
">",
"find",
"()",
";",
"echo",
"$book",
"-",
">",
"exportTo",
"(",
"JSON",
")",
";",
"=",
">",
"{{",
"Id",
":",
"9012",
"Title",
":",
"Don",
"Juan",
"ISBN",
":",
"0140422161",
"Price",
":",
"12",
".",
"99",
"PublisherId",
":",
"1234",
"AuthorId",
":",
"5678",
"}}",
")",
";",
"<",
"/",
"code",
">"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/collection/PropelCollection.php#L540-L547 |
propelorm/Propel | generator/lib/builder/om/PHP5NodePeerBuilder.php | PHP5NodePeerBuilder.addClassBody | protected function addClassBody(&$script)
{
$table = $this->getTable();
// FIXME
// - Probably the build needs to be customized for supporting
// tables that are "aliases". -- definitely a fringe usecase, though.
$this->addConstants($script);
$this->addIsCodeBase($script);
$this->addRetrieveMethods($script);
$this->addCreateNewRootNode($script);
$this->addInsertNewRootNode($script);
$this->addMoveNodeSubTree($script);
$this->addDeleteNodeSubTree($script);
$this->addBuildFamilyCriteria($script);
$this->addBuildTree($script);
$this->addPopulateNodes($script);
} | php | protected function addClassBody(&$script)
{
$table = $this->getTable();
// FIXME
// - Probably the build needs to be customized for supporting
// tables that are "aliases". -- definitely a fringe usecase, though.
$this->addConstants($script);
$this->addIsCodeBase($script);
$this->addRetrieveMethods($script);
$this->addCreateNewRootNode($script);
$this->addInsertNewRootNode($script);
$this->addMoveNodeSubTree($script);
$this->addDeleteNodeSubTree($script);
$this->addBuildFamilyCriteria($script);
$this->addBuildTree($script);
$this->addPopulateNodes($script);
} | [
"protected",
"function",
"addClassBody",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"// FIXME",
"// - Probably the build needs to be customized for supporting",
"// tables that are \"aliases\". -- definitely a fringe usecase, though.",
"$",
"this",
"->",
"addConstants",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addIsCodeBase",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveMethods",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addCreateNewRootNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInsertNewRootNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addMoveNodeSubTree",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDeleteNodeSubTree",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addBuildFamilyCriteria",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addBuildTree",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addPopulateNodes",
"(",
"$",
"script",
")",
";",
"}"
] | Specifies the methods that are added as part of the basic OM class.
This can be overridden by subclasses that wish to add more methods.
@see ObjectBuilder::addClassBody() | [
"Specifies",
"the",
"methods",
"that",
"are",
"added",
"as",
"part",
"of",
"the",
"basic",
"OM",
"class",
".",
"This",
"can",
"be",
"overridden",
"by",
"subclasses",
"that",
"wish",
"to",
"add",
"more",
"methods",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5NodePeerBuilder.php#L93-L116 |
propelorm/Propel | generator/lib/builder/om/PHP5NodePeerBuilder.php | PHP5NodePeerBuilder.addRetrieveMethods | protected function addRetrieveMethods(&$script)
{
$this->addRetrieveNodes($script);
$this->addRetrieveNodeByPK($script);
$this->addRetrieveNodeByNP($script);
$this->addRetrieveRootNode($script);
} | php | protected function addRetrieveMethods(&$script)
{
$this->addRetrieveNodes($script);
$this->addRetrieveNodeByPK($script);
$this->addRetrieveNodeByNP($script);
$this->addRetrieveRootNode($script);
} | [
"protected",
"function",
"addRetrieveMethods",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"this",
"->",
"addRetrieveNodes",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveNodeByPK",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveNodeByNP",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveRootNode",
"(",
"$",
"script",
")",
";",
"}"
] | Adds the methods for retrieving nodes. | [
"Adds",
"the",
"methods",
"for",
"retrieving",
"nodes",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5NodePeerBuilder.php#L273-L279 |
propelorm/Propel | generator/lib/behavior/TimestampableBehavior.php | TimestampableBehavior.modifyTable | public function modifyTable()
{
if (!$this->getTable()->containsColumn($this->getParameter('create_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('create_column'),
'type' => 'TIMESTAMP'
));
}
if ($this->withUpdatedAt()) {
if (!$this->getTable()->containsColumn($this->getParameter('update_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('update_column'),
'type' => 'TIMESTAMP'
));
}
}
} | php | public function modifyTable()
{
if (!$this->getTable()->containsColumn($this->getParameter('create_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('create_column'),
'type' => 'TIMESTAMP'
));
}
if ($this->withUpdatedAt()) {
if (!$this->getTable()->containsColumn($this->getParameter('update_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('update_column'),
'type' => 'TIMESTAMP'
));
}
}
} | [
"public",
"function",
"modifyTable",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"containsColumn",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'create_column'",
")",
")",
")",
"{",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"addColumn",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"getParameter",
"(",
"'create_column'",
")",
",",
"'type'",
"=>",
"'TIMESTAMP'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"withUpdatedAt",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"containsColumn",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'update_column'",
")",
")",
")",
"{",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"addColumn",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"getParameter",
"(",
"'update_column'",
")",
",",
"'type'",
"=>",
"'TIMESTAMP'",
")",
")",
";",
"}",
"}",
"}"
] | Add the create_column and update_columns to the current table | [
"Add",
"the",
"create_column",
"and",
"update_columns",
"to",
"the",
"current",
"table"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/behavior/TimestampableBehavior.php#L31-L48 |
propelorm/Propel | generator/lib/behavior/TimestampableBehavior.php | TimestampableBehavior.preUpdate | public function preUpdate(PHP5ObjectBuilder $builder)
{
if ($this->withUpdatedAt()) {
return "if (\$this->isModified() && !\$this->isColumnModified(" . $this->getColumnConstant('update_column', $builder) . ")) {
\$this->" . $this->getColumnSetter('update_column') . "(time());
}";
}
return '';
} | php | public function preUpdate(PHP5ObjectBuilder $builder)
{
if ($this->withUpdatedAt()) {
return "if (\$this->isModified() && !\$this->isColumnModified(" . $this->getColumnConstant('update_column', $builder) . ")) {
\$this->" . $this->getColumnSetter('update_column') . "(time());
}";
}
return '';
} | [
"public",
"function",
"preUpdate",
"(",
"PHP5ObjectBuilder",
"$",
"builder",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"withUpdatedAt",
"(",
")",
")",
"{",
"return",
"\"if (\\$this->isModified() && !\\$this->isColumnModified(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"'update_column'",
",",
"$",
"builder",
")",
".",
"\")) {\n \\$this->\"",
".",
"$",
"this",
"->",
"getColumnSetter",
"(",
"'update_column'",
")",
".",
"\"(time());\n}\"",
";",
"}",
"return",
"''",
";",
"}"
] | Add code in ObjectBuilder::preUpdate
@param PHP5ObjectBuilder $builder
@return string The code to put at the hook | [
"Add",
"code",
"in",
"ObjectBuilder",
"::",
"preUpdate"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/behavior/TimestampableBehavior.php#L82-L91 |
propelorm/Propel | generator/lib/behavior/TimestampableBehavior.php | TimestampableBehavior.preInsert | public function preInsert(PHP5ObjectBuilder $builder)
{
$script = "if (!\$this->isColumnModified(" . $this->getColumnConstant('create_column', $builder) . ")) {
\$this->" . $this->getColumnSetter('create_column') . "(time());
}";
if ($this->withUpdatedAt()) {
$script .= "
if (!\$this->isColumnModified(" . $this->getColumnConstant('update_column', $builder) . ")) {
\$this->" . $this->getColumnSetter('update_column') . "(time());
}";
}
return $script;
} | php | public function preInsert(PHP5ObjectBuilder $builder)
{
$script = "if (!\$this->isColumnModified(" . $this->getColumnConstant('create_column', $builder) . ")) {
\$this->" . $this->getColumnSetter('create_column') . "(time());
}";
if ($this->withUpdatedAt()) {
$script .= "
if (!\$this->isColumnModified(" . $this->getColumnConstant('update_column', $builder) . ")) {
\$this->" . $this->getColumnSetter('update_column') . "(time());
}";
}
return $script;
} | [
"public",
"function",
"preInsert",
"(",
"PHP5ObjectBuilder",
"$",
"builder",
")",
"{",
"$",
"script",
"=",
"\"if (!\\$this->isColumnModified(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"'create_column'",
",",
"$",
"builder",
")",
".",
"\")) {\n \\$this->\"",
".",
"$",
"this",
"->",
"getColumnSetter",
"(",
"'create_column'",
")",
".",
"\"(time());\n}\"",
";",
"if",
"(",
"$",
"this",
"->",
"withUpdatedAt",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\nif (!\\$this->isColumnModified(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"'update_column'",
",",
"$",
"builder",
")",
".",
"\")) {\n \\$this->\"",
".",
"$",
"this",
"->",
"getColumnSetter",
"(",
"'update_column'",
")",
".",
"\"(time());\n}\"",
";",
"}",
"return",
"$",
"script",
";",
"}"
] | Add code in ObjectBuilder::preInsert
@param PHP5ObjectBuilder $builder
@return string The code to put at the hook | [
"Add",
"code",
"in",
"ObjectBuilder",
"::",
"preInsert"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/behavior/TimestampableBehavior.php#L100-L114 |
propelorm/Propel | generator/lib/model/XMLElement.php | XMLElement.booleanValue | protected function booleanValue($val)
{
if (is_numeric($val)) {
return (bool) $val;
} else {
return (in_array(strtolower($val), array('true', 't', 'y', 'yes'), true) ? true : false);
}
} | php | protected function booleanValue($val)
{
if (is_numeric($val)) {
return (bool) $val;
} else {
return (in_array(strtolower($val), array('true', 't', 'y', 'yes'), true) ? true : false);
}
} | [
"protected",
"function",
"booleanValue",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"val",
")",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"val",
";",
"}",
"else",
"{",
"return",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"val",
")",
",",
"array",
"(",
"'true'",
",",
"'t'",
",",
"'y'",
",",
"'yes'",
")",
",",
"true",
")",
"?",
"true",
":",
"false",
")",
";",
"}",
"}"
] | Converts value specified in XML to a boolean value.
This is to support the default value when used w/ a boolean column.
@return bool | [
"Converts",
"value",
"specified",
"in",
"XML",
"to",
"a",
"boolean",
"value",
".",
"This",
"is",
"to",
"support",
"the",
"default",
"value",
"when",
"used",
"w",
"/",
"a",
"boolean",
"column",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/XMLElement.php#L90-L97 |
propelorm/Propel | generator/lib/model/XMLElement.php | XMLElement.addVendorInfo | public function addVendorInfo($data)
{
if ($data instanceof VendorInfo) {
$vi = $data;
$this->vendorInfos[$vi->getType()] = $vi;
return $vi;
} else {
$vi = new VendorInfo();
$vi->loadFromXML($data);
return $this->addVendorInfo($vi); // call self w/ different param
}
} | php | public function addVendorInfo($data)
{
if ($data instanceof VendorInfo) {
$vi = $data;
$this->vendorInfos[$vi->getType()] = $vi;
return $vi;
} else {
$vi = new VendorInfo();
$vi->loadFromXML($data);
return $this->addVendorInfo($vi); // call self w/ different param
}
} | [
"public",
"function",
"addVendorInfo",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"VendorInfo",
")",
"{",
"$",
"vi",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"vendorInfos",
"[",
"$",
"vi",
"->",
"getType",
"(",
")",
"]",
"=",
"$",
"vi",
";",
"return",
"$",
"vi",
";",
"}",
"else",
"{",
"$",
"vi",
"=",
"new",
"VendorInfo",
"(",
")",
";",
"$",
"vi",
"->",
"loadFromXML",
"(",
"$",
"data",
")",
";",
"return",
"$",
"this",
"->",
"addVendorInfo",
"(",
"$",
"vi",
")",
";",
"// call self w/ different param",
"}",
"}"
] | Sets an associated VendorInfo object.
@param mixed $data VendorInfo object or XML attrib data (array)
@return VendorInfo | [
"Sets",
"an",
"associated",
"VendorInfo",
"object",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/XMLElement.php#L134-L147 |
propelorm/Propel | generator/lib/model/XMLElement.php | XMLElement.getVendorInfoForType | public function getVendorInfoForType($type)
{
if (isset($this->vendorInfos[$type])) {
return $this->vendorInfos[$type];
} else {
// return an empty object
return new VendorInfo($type);
}
} | php | public function getVendorInfoForType($type)
{
if (isset($this->vendorInfos[$type])) {
return $this->vendorInfos[$type];
} else {
// return an empty object
return new VendorInfo($type);
}
} | [
"public",
"function",
"getVendorInfoForType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"vendorInfos",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"vendorInfos",
"[",
"$",
"type",
"]",
";",
"}",
"else",
"{",
"// return an empty object",
"return",
"new",
"VendorInfo",
"(",
"$",
"type",
")",
";",
"}",
"}"
] | Gets the any associated VendorInfo object.
@return VendorInfo | [
"Gets",
"the",
"any",
"associated",
"VendorInfo",
"object",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/XMLElement.php#L154-L162 |
propelorm/Propel | generator/lib/model/XMLElement.php | XMLElement.getConfiguredBehavior | public function getConfiguredBehavior($bname)
{
if ($config = $this->getGeneratorConfig()) {
if ($class = $config->getConfiguredBehavior($bname)) {
return $class;
}
}
// fallback: maybe the behavior is loaded or autoloaded
$gen = new PhpNameGenerator();
if (class_exists($class = $gen->generateName(array($bname, PhpNameGenerator::CONV_METHOD_PHPNAME)) . 'Behavior')) {
return $class;
}
throw new InvalidArgumentException(sprintf('Unknown behavior "%s"; make sure you configured the propel.behavior.%s.class setting in your build.properties', $bname, $bname));
} | php | public function getConfiguredBehavior($bname)
{
if ($config = $this->getGeneratorConfig()) {
if ($class = $config->getConfiguredBehavior($bname)) {
return $class;
}
}
// fallback: maybe the behavior is loaded or autoloaded
$gen = new PhpNameGenerator();
if (class_exists($class = $gen->generateName(array($bname, PhpNameGenerator::CONV_METHOD_PHPNAME)) . 'Behavior')) {
return $class;
}
throw new InvalidArgumentException(sprintf('Unknown behavior "%s"; make sure you configured the propel.behavior.%s.class setting in your build.properties', $bname, $bname));
} | [
"public",
"function",
"getConfiguredBehavior",
"(",
"$",
"bname",
")",
"{",
"if",
"(",
"$",
"config",
"=",
"$",
"this",
"->",
"getGeneratorConfig",
"(",
")",
")",
"{",
"if",
"(",
"$",
"class",
"=",
"$",
"config",
"->",
"getConfiguredBehavior",
"(",
"$",
"bname",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"}",
"// fallback: maybe the behavior is loaded or autoloaded",
"$",
"gen",
"=",
"new",
"PhpNameGenerator",
"(",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
"=",
"$",
"gen",
"->",
"generateName",
"(",
"array",
"(",
"$",
"bname",
",",
"PhpNameGenerator",
"::",
"CONV_METHOD_PHPNAME",
")",
")",
".",
"'Behavior'",
")",
")",
"{",
"return",
"$",
"class",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unknown behavior \"%s\"; make sure you configured the propel.behavior.%s.class setting in your build.properties'",
",",
"$",
"bname",
",",
"$",
"bname",
")",
")",
";",
"}"
] | Find the best class name for a given behavior
Looks in build.properties for path like propel.behavior.[bname].class
If not found, tries to autoload [Bname]Behavior
If no success, returns 'Behavior'
@param string $bname behavior name, e.g. 'timestampable'
@return string behavior class name, e.g. 'TimestampableBehavior'
@throws InvalidArgumentException | [
"Find",
"the",
"best",
"class",
"name",
"for",
"a",
"given",
"behavior",
"Looks",
"in",
"build",
".",
"properties",
"for",
"path",
"like",
"propel",
".",
"behavior",
".",
"[",
"bname",
"]",
".",
"class",
"If",
"not",
"found",
"tries",
"to",
"autoload",
"[",
"Bname",
"]",
"Behavior",
"If",
"no",
"success",
"returns",
"Behavior"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/XMLElement.php#L176-L190 |
propelorm/Propel | generator/lib/model/XMLElement.php | XMLElement.toString | public function toString()
{
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$this->appendXml($doc);
$xmlstr = $doc->saveXML();
return trim(preg_replace('/<\?xml.*?\?>/', '', $xmlstr));
} | php | public function toString()
{
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$this->appendXml($doc);
$xmlstr = $doc->saveXML();
return trim(preg_replace('/<\?xml.*?\?>/', '', $xmlstr));
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"doc",
"=",
"new",
"DOMDocument",
"(",
"'1.0'",
")",
";",
"$",
"doc",
"->",
"formatOutput",
"=",
"true",
";",
"$",
"this",
"->",
"appendXml",
"(",
"$",
"doc",
")",
";",
"$",
"xmlstr",
"=",
"$",
"doc",
"->",
"saveXML",
"(",
")",
";",
"return",
"trim",
"(",
"preg_replace",
"(",
"'/<\\?xml.*?\\?>/'",
",",
"''",
",",
"$",
"xmlstr",
")",
")",
";",
"}"
] | String representation of the current object.
This is an xml representation with the XML declaration removed.
@see appendXml() | [
"String",
"representation",
"of",
"the",
"current",
"object",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/XMLElement.php#L199-L207 |
propelorm/Propel | generator/lib/behavior/DelegateBehavior.php | DelegateBehavior.modifyTable | public function modifyTable()
{
$table = $this->getTable();
$database = $table->getDatabase();
$delegates = explode(',', $this->parameters['to']);
foreach ($delegates as $delegate) {
$delegate = $database->getTablePrefix() . trim($delegate);
if (!$database->hasTable($delegate)) {
throw new InvalidArgumentException(sprintf('No delegate table "%s" found for table "%s"', $delegate, $table->getName()));
}
if (in_array($delegate, $table->getForeignTableNames())) {
// existing many-to-one relationship
$type = self::MANY_TO_ONE;
} else {
// one_to_one relationship
$delegateTable = $this->getDelegateTable($delegate);
if (in_array($table->getName(), $delegateTable->getForeignTableNames())) {
// existing one-to-one relationship
$fks = $delegateTable->getForeignKeysReferencingTable($this->getTable()->getName());
$fk = $fks[0];
if (!$fk->isLocalPrimaryKey()) {
throw new InvalidArgumentException(sprintf('Delegate table "%s" has a relationship with table "%s", but it\'s a one-to-many relationship. The `delegate` behavior only supports one-to-one relationships in this case.', $delegate, $table->getName()));
}
} else {
// no relationship yet: must be created
$this->relateDelegateToMainTable($this->getDelegateTable($delegate), $table);
}
$type = self::ONE_TO_ONE;
}
$this->delegates[$delegate] = $type;
}
} | php | public function modifyTable()
{
$table = $this->getTable();
$database = $table->getDatabase();
$delegates = explode(',', $this->parameters['to']);
foreach ($delegates as $delegate) {
$delegate = $database->getTablePrefix() . trim($delegate);
if (!$database->hasTable($delegate)) {
throw new InvalidArgumentException(sprintf('No delegate table "%s" found for table "%s"', $delegate, $table->getName()));
}
if (in_array($delegate, $table->getForeignTableNames())) {
// existing many-to-one relationship
$type = self::MANY_TO_ONE;
} else {
// one_to_one relationship
$delegateTable = $this->getDelegateTable($delegate);
if (in_array($table->getName(), $delegateTable->getForeignTableNames())) {
// existing one-to-one relationship
$fks = $delegateTable->getForeignKeysReferencingTable($this->getTable()->getName());
$fk = $fks[0];
if (!$fk->isLocalPrimaryKey()) {
throw new InvalidArgumentException(sprintf('Delegate table "%s" has a relationship with table "%s", but it\'s a one-to-many relationship. The `delegate` behavior only supports one-to-one relationships in this case.', $delegate, $table->getName()));
}
} else {
// no relationship yet: must be created
$this->relateDelegateToMainTable($this->getDelegateTable($delegate), $table);
}
$type = self::ONE_TO_ONE;
}
$this->delegates[$delegate] = $type;
}
} | [
"public",
"function",
"modifyTable",
"(",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"database",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
";",
"$",
"delegates",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"parameters",
"[",
"'to'",
"]",
")",
";",
"foreach",
"(",
"$",
"delegates",
"as",
"$",
"delegate",
")",
"{",
"$",
"delegate",
"=",
"$",
"database",
"->",
"getTablePrefix",
"(",
")",
".",
"trim",
"(",
"$",
"delegate",
")",
";",
"if",
"(",
"!",
"$",
"database",
"->",
"hasTable",
"(",
"$",
"delegate",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No delegate table \"%s\" found for table \"%s\"'",
",",
"$",
"delegate",
",",
"$",
"table",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"delegate",
",",
"$",
"table",
"->",
"getForeignTableNames",
"(",
")",
")",
")",
"{",
"// existing many-to-one relationship",
"$",
"type",
"=",
"self",
"::",
"MANY_TO_ONE",
";",
"}",
"else",
"{",
"// one_to_one relationship",
"$",
"delegateTable",
"=",
"$",
"this",
"->",
"getDelegateTable",
"(",
"$",
"delegate",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"table",
"->",
"getName",
"(",
")",
",",
"$",
"delegateTable",
"->",
"getForeignTableNames",
"(",
")",
")",
")",
"{",
"// existing one-to-one relationship",
"$",
"fks",
"=",
"$",
"delegateTable",
"->",
"getForeignKeysReferencingTable",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"$",
"fk",
"=",
"$",
"fks",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"$",
"fk",
"->",
"isLocalPrimaryKey",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Delegate table \"%s\" has a relationship with table \"%s\", but it\\'s a one-to-many relationship. The `delegate` behavior only supports one-to-one relationships in this case.'",
",",
"$",
"delegate",
",",
"$",
"table",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}",
"else",
"{",
"// no relationship yet: must be created",
"$",
"this",
"->",
"relateDelegateToMainTable",
"(",
"$",
"this",
"->",
"getDelegateTable",
"(",
"$",
"delegate",
")",
",",
"$",
"table",
")",
";",
"}",
"$",
"type",
"=",
"self",
"::",
"ONE_TO_ONE",
";",
"}",
"$",
"this",
"->",
"delegates",
"[",
"$",
"delegate",
"]",
"=",
"$",
"type",
";",
"}",
"}"
] | Lists the delegates and checks that the behavior can use them,
And adds a fk from the delegate to the main table if not already set | [
"Lists",
"the",
"delegates",
"and",
"checks",
"that",
"the",
"behavior",
"can",
"use",
"them",
"And",
"adds",
"a",
"fk",
"from",
"the",
"delegate",
"to",
"the",
"main",
"table",
"if",
"not",
"already",
"set"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/behavior/DelegateBehavior.php#L33-L64 |
propelorm/Propel | runtime/lib/query/ModelCriterion.php | ModelCriterion.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::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;
case ModelCriteria::MODEL_CLAUSE:
// regular model clause, e.g. 'book.TITLE = ?'
$this->appendModelClauseToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_LIKE:
// regular model clause, e.g. 'book.TITLE = ?'
$this->appendModelClauseLikeToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_SEVERAL:
// Ternary model clause, e.G 'book.ID BETWEEN ? AND ?'
$this->appendModelClauseSeveralToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_ARRAY:
// IN or NOT IN model clause, e.g. 'book.TITLE NOT IN ?'
$this->appendModelClauseArrayToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_RAW:
// raw model clause, with type, e.g. 'foobar = ?'
$this->appendModelClauseRawToPs($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::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;
case ModelCriteria::MODEL_CLAUSE:
// regular model clause, e.g. 'book.TITLE = ?'
$this->appendModelClauseToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_LIKE:
// regular model clause, e.g. 'book.TITLE = ?'
$this->appendModelClauseLikeToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_SEVERAL:
// Ternary model clause, e.G 'book.ID BETWEEN ? AND ?'
$this->appendModelClauseSeveralToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_ARRAY:
// IN or NOT IN model clause, e.g. 'book.TITLE NOT IN ?'
$this->appendModelClauseArrayToPs($sb, $params);
break;
case ModelCriteria::MODEL_CLAUSE_RAW:
// raw model clause, with type, e.g. 'foobar = ?'
$this->appendModelClauseRawToPs($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",
"::",
"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",
";",
"case",
"ModelCriteria",
"::",
"MODEL_CLAUSE",
":",
"// regular model clause, e.g. 'book.TITLE = ?'",
"$",
"this",
"->",
"appendModelClauseToPs",
"(",
"$",
"sb",
",",
"$",
"params",
")",
";",
"break",
";",
"case",
"ModelCriteria",
"::",
"MODEL_CLAUSE_LIKE",
":",
"// regular model clause, e.g. 'book.TITLE = ?'",
"$",
"this",
"->",
"appendModelClauseLikeToPs",
"(",
"$",
"sb",
",",
"$",
"params",
")",
";",
"break",
";",
"case",
"ModelCriteria",
"::",
"MODEL_CLAUSE_SEVERAL",
":",
"// Ternary model clause, e.G 'book.ID BETWEEN ? AND ?'",
"$",
"this",
"->",
"appendModelClauseSeveralToPs",
"(",
"$",
"sb",
",",
"$",
"params",
")",
";",
"break",
";",
"case",
"ModelCriteria",
"::",
"MODEL_CLAUSE_ARRAY",
":",
"// IN or NOT IN model clause, e.g. 'book.TITLE NOT IN ?'",
"$",
"this",
"->",
"appendModelClauseArrayToPs",
"(",
"$",
"sb",
",",
"$",
"params",
")",
";",
"break",
";",
"case",
"ModelCriteria",
"::",
"MODEL_CLAUSE_RAW",
":",
"// raw model clause, with type, e.g. 'foobar = ?'",
"$",
"this",
"->",
"appendModelClauseRawToPs",
"(",
"$",
"sb",
",",
"$",
"params",
")",
";",
"break",
";",
"default",
":",
"// table.column = ? or table.column >= ? etc. (traditional expressions, the default)",
"$",
"this",
"->",
"appendBasicToPs",
"(",
"$",
"sb",
",",
"$",
"params",
")",
";",
"}",
"}"
] | Figure out which ModelCriterion 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.
For performance reasons, this method tests the cases of parent::dispatchPsHandling()
first, and that is not possible through inheritance ; that's why the parent
code is duplicated here.
@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",
"ModelCriterion",
"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",
".",
"For",
"performance",
"reasons",
"this",
"method",
"tests",
"the",
"cases",
"of",
"parent",
"::",
"dispatchPsHandling",
"()",
"first",
"and",
"that",
"is",
"not",
"possible",
"through",
"inheritance",
";",
"that",
"s",
"why",
"the",
"parent",
"code",
"is",
"duplicated",
"here",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/ModelCriterion.php#L71-L114 |
propelorm/Propel | runtime/lib/query/ModelCriterion.php | ModelCriterion.appendModelClauseToPs | public function appendModelClauseToPs(&$sb, array &$params)
{
if ($this->value !== null) {
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value);
$sb .= str_replace('?', ':p' . count($params), $this->clause);
} else {
$sb .= $this->clause;
}
} | php | public function appendModelClauseToPs(&$sb, array &$params)
{
if ($this->value !== null) {
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $this->value);
$sb .= str_replace('?', ':p' . count($params), $this->clause);
} else {
$sb .= $this->clause;
}
} | [
"public",
"function",
"appendModelClauseToPs",
"(",
"&",
"$",
"sb",
",",
"array",
"&",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"value",
"!==",
"null",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"array",
"(",
"'table'",
"=>",
"$",
"this",
"->",
"realtable",
",",
"'column'",
"=>",
"$",
"this",
"->",
"column",
",",
"'value'",
"=>",
"$",
"this",
"->",
"value",
")",
";",
"$",
"sb",
".=",
"str_replace",
"(",
"'?'",
",",
"':p'",
".",
"count",
"(",
"$",
"params",
")",
",",
"$",
"this",
"->",
"clause",
")",
";",
"}",
"else",
"{",
"$",
"sb",
".=",
"$",
"this",
"->",
"clause",
";",
"}",
"}"
] | Appends a Prepared Statement representation of the ModelCriterion onto the buffer
For regular model clauses, e.g. 'book.TITLE = ?'
@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",
"ModelCriterion",
"onto",
"the",
"buffer",
"For",
"regular",
"model",
"clauses",
"e",
".",
"g",
".",
"book",
".",
"TITLE",
"=",
"?"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/ModelCriterion.php#L123-L131 |
propelorm/Propel | runtime/lib/query/ModelCriterion.php | ModelCriterion.appendModelClauseLikeToPs | public function appendModelClauseLikeToPs(&$sb, array &$params)
{
// LIKE is case insensitive in mySQL and SQLite, but not in PostGres
// If the column is case insensitive, use ILIKE / NOT ILIKE instead of LIKE / NOT LIKE
if ($this->ignoreStringCase && $this->getDb() instanceof DBPostgres) {
$this->clause = preg_replace('/LIKE \?$/i', 'ILIKE ?', $this->clause);
}
$this->appendModelClauseToPs($sb, $params);
} | php | public function appendModelClauseLikeToPs(&$sb, array &$params)
{
// LIKE is case insensitive in mySQL and SQLite, but not in PostGres
// If the column is case insensitive, use ILIKE / NOT ILIKE instead of LIKE / NOT LIKE
if ($this->ignoreStringCase && $this->getDb() instanceof DBPostgres) {
$this->clause = preg_replace('/LIKE \?$/i', 'ILIKE ?', $this->clause);
}
$this->appendModelClauseToPs($sb, $params);
} | [
"public",
"function",
"appendModelClauseLikeToPs",
"(",
"&",
"$",
"sb",
",",
"array",
"&",
"$",
"params",
")",
"{",
"// LIKE is case insensitive in mySQL and SQLite, but not in PostGres",
"// If the column is case insensitive, use ILIKE / NOT ILIKE instead of LIKE / NOT LIKE",
"if",
"(",
"$",
"this",
"->",
"ignoreStringCase",
"&&",
"$",
"this",
"->",
"getDb",
"(",
")",
"instanceof",
"DBPostgres",
")",
"{",
"$",
"this",
"->",
"clause",
"=",
"preg_replace",
"(",
"'/LIKE \\?$/i'",
",",
"'ILIKE ?'",
",",
"$",
"this",
"->",
"clause",
")",
";",
"}",
"$",
"this",
"->",
"appendModelClauseToPs",
"(",
"$",
"sb",
",",
"$",
"params",
")",
";",
"}"
] | Appends a Prepared Statement representation of the ModelCriterion onto the buffer
For LIKE model clauses, e.g. 'book.TITLE LIKE ?'
Handles case insensitivity for VARCHAR columns
@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",
"ModelCriterion",
"onto",
"the",
"buffer",
"For",
"LIKE",
"model",
"clauses",
"e",
".",
"g",
".",
"book",
".",
"TITLE",
"LIKE",
"?",
"Handles",
"case",
"insensitivity",
"for",
"VARCHAR",
"columns"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/ModelCriterion.php#L141-L149 |
propelorm/Propel | runtime/lib/query/ModelCriterion.php | ModelCriterion.appendModelClauseSeveralToPs | public function appendModelClauseSeveralToPs(&$sb, array &$params)
{
$clause = $this->clause;
foreach ((array) $this->value as $value) {
if ($value === null) {
// FIXME we eventually need to translate a BETWEEN to
// something like WHERE (col < :p1 OR :p1 IS NULL) AND (col < :p2 OR :p2 IS NULL)
// in order to support null values
throw new PropelException('Null values are not supported inside BETWEEN clauses');
}
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
$clause = self::strReplaceOnce('?', ':p' . count($params), $clause);
}
$sb .= $clause;
} | php | public function appendModelClauseSeveralToPs(&$sb, array &$params)
{
$clause = $this->clause;
foreach ((array) $this->value as $value) {
if ($value === null) {
// FIXME we eventually need to translate a BETWEEN to
// something like WHERE (col < :p1 OR :p1 IS NULL) AND (col < :p2 OR :p2 IS NULL)
// in order to support null values
throw new PropelException('Null values are not supported inside BETWEEN clauses');
}
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
$clause = self::strReplaceOnce('?', ':p' . count($params), $clause);
}
$sb .= $clause;
} | [
"public",
"function",
"appendModelClauseSeveralToPs",
"(",
"&",
"$",
"sb",
",",
"array",
"&",
"$",
"params",
")",
"{",
"$",
"clause",
"=",
"$",
"this",
"->",
"clause",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"value",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"// FIXME we eventually need to translate a BETWEEN to",
"// something like WHERE (col < :p1 OR :p1 IS NULL) AND (col < :p2 OR :p2 IS NULL)",
"// in order to support null values",
"throw",
"new",
"PropelException",
"(",
"'Null values are not supported inside BETWEEN clauses'",
")",
";",
"}",
"$",
"params",
"[",
"]",
"=",
"array",
"(",
"'table'",
"=>",
"$",
"this",
"->",
"realtable",
",",
"'column'",
"=>",
"$",
"this",
"->",
"column",
",",
"'value'",
"=>",
"$",
"value",
")",
";",
"$",
"clause",
"=",
"self",
"::",
"strReplaceOnce",
"(",
"'?'",
",",
"':p'",
".",
"count",
"(",
"$",
"params",
")",
",",
"$",
"clause",
")",
";",
"}",
"$",
"sb",
".=",
"$",
"clause",
";",
"}"
] | Appends a Prepared Statement representation of the ModelCriterion onto the buffer
For ternary model clauses, e.G 'book.ID BETWEEN ? AND ?'
@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",
"ModelCriterion",
"onto",
"the",
"buffer",
"For",
"ternary",
"model",
"clauses",
"e",
".",
"G",
"book",
".",
"ID",
"BETWEEN",
"?",
"AND",
"?"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/ModelCriterion.php#L160-L174 |
propelorm/Propel | runtime/lib/query/ModelCriterion.php | ModelCriterion.appendModelClauseArrayToPs | public function appendModelClauseArrayToPs(&$sb, array &$params)
{
$_bindParams = array(); // the param names used in query building
$_idxstart = count($params);
$valuesLength = 0;
foreach ((array) $this->value as $value) {
$valuesLength++; // increment this first to correct for wanting bind params to start with :p1
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
$_bindParams[] = ':p' . ($_idxstart + $valuesLength);
}
if ($valuesLength !== 0) {
$sb .= str_replace('?', '(' . implode(',', $_bindParams) . ')', $this->clause);
} else {
$sb .= (stripos($this->clause, ' NOT IN ') === false) ? "1<>1" : "1=1";
}
unset($value, $valuesLength);
} | php | public function appendModelClauseArrayToPs(&$sb, array &$params)
{
$_bindParams = array(); // the param names used in query building
$_idxstart = count($params);
$valuesLength = 0;
foreach ((array) $this->value as $value) {
$valuesLength++; // increment this first to correct for wanting bind params to start with :p1
$params[] = array('table' => $this->realtable, 'column' => $this->column, 'value' => $value);
$_bindParams[] = ':p' . ($_idxstart + $valuesLength);
}
if ($valuesLength !== 0) {
$sb .= str_replace('?', '(' . implode(',', $_bindParams) . ')', $this->clause);
} else {
$sb .= (stripos($this->clause, ' NOT IN ') === false) ? "1<>1" : "1=1";
}
unset($value, $valuesLength);
} | [
"public",
"function",
"appendModelClauseArrayToPs",
"(",
"&",
"$",
"sb",
",",
"array",
"&",
"$",
"params",
")",
"{",
"$",
"_bindParams",
"=",
"array",
"(",
")",
";",
"// the param names used in query building",
"$",
"_idxstart",
"=",
"count",
"(",
"$",
"params",
")",
";",
"$",
"valuesLength",
"=",
"0",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"value",
"as",
"$",
"value",
")",
"{",
"$",
"valuesLength",
"++",
";",
"// increment this first to correct for wanting bind params to start with :p1",
"$",
"params",
"[",
"]",
"=",
"array",
"(",
"'table'",
"=>",
"$",
"this",
"->",
"realtable",
",",
"'column'",
"=>",
"$",
"this",
"->",
"column",
",",
"'value'",
"=>",
"$",
"value",
")",
";",
"$",
"_bindParams",
"[",
"]",
"=",
"':p'",
".",
"(",
"$",
"_idxstart",
"+",
"$",
"valuesLength",
")",
";",
"}",
"if",
"(",
"$",
"valuesLength",
"!==",
"0",
")",
"{",
"$",
"sb",
".=",
"str_replace",
"(",
"'?'",
",",
"'('",
".",
"implode",
"(",
"','",
",",
"$",
"_bindParams",
")",
".",
"')'",
",",
"$",
"this",
"->",
"clause",
")",
";",
"}",
"else",
"{",
"$",
"sb",
".=",
"(",
"stripos",
"(",
"$",
"this",
"->",
"clause",
",",
"' NOT IN '",
")",
"===",
"false",
")",
"?",
"\"1<>1\"",
":",
"\"1=1\"",
";",
"}",
"unset",
"(",
"$",
"value",
",",
"$",
"valuesLength",
")",
";",
"}"
] | Appends a Prepared Statement representation of the ModelCriterion onto the buffer
For IN or NOT IN model clauses, e.g. 'book.TITLE 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",
"ModelCriterion",
"onto",
"the",
"buffer",
"For",
"IN",
"or",
"NOT",
"IN",
"model",
"clauses",
"e",
".",
"g",
".",
"book",
".",
"TITLE",
"NOT",
"IN",
"?"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/ModelCriterion.php#L183-L199 |
propelorm/Propel | runtime/lib/query/ModelCriterion.php | ModelCriterion.appendModelClauseRawToPs | protected function appendModelClauseRawToPs(&$sb, array &$params)
{
if (substr_count($this->clause, '?') != 1) {
throw new PropelException(sprintf('Could not build SQL for expression "%s" because Criteria::RAW works only with a clause containing a single question mark placeholder', $this->column));
}
$params[] = array('table' => null, 'type' => $this->type, 'value' => $this->value);
$sb .= str_replace('?', ':p' . count($params), $this->clause);
} | php | protected function appendModelClauseRawToPs(&$sb, array &$params)
{
if (substr_count($this->clause, '?') != 1) {
throw new PropelException(sprintf('Could not build SQL for expression "%s" because Criteria::RAW works only with a clause containing a single question mark placeholder', $this->column));
}
$params[] = array('table' => null, 'type' => $this->type, 'value' => $this->value);
$sb .= str_replace('?', ':p' . count($params), $this->clause);
} | [
"protected",
"function",
"appendModelClauseRawToPs",
"(",
"&",
"$",
"sb",
",",
"array",
"&",
"$",
"params",
")",
"{",
"if",
"(",
"substr_count",
"(",
"$",
"this",
"->",
"clause",
",",
"'?'",
")",
"!=",
"1",
")",
"{",
"throw",
"new",
"PropelException",
"(",
"sprintf",
"(",
"'Could not build SQL for expression \"%s\" because Criteria::RAW works only with a clause containing a single question mark placeholder'",
",",
"$",
"this",
"->",
"column",
")",
")",
";",
"}",
"$",
"params",
"[",
"]",
"=",
"array",
"(",
"'table'",
"=>",
"null",
",",
"'type'",
"=>",
"$",
"this",
"->",
"type",
",",
"'value'",
"=>",
"$",
"this",
"->",
"value",
")",
";",
"$",
"sb",
".=",
"str_replace",
"(",
"'?'",
",",
"':p'",
".",
"count",
"(",
"$",
"params",
")",
",",
"$",
"this",
"->",
"clause",
")",
";",
"}"
] | Appends a Prepared Statement representation of the Criterion onto the buffer
For custom expressions with a typed binding, e.g. 'foobar = ?'
@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",
"custom",
"expressions",
"with",
"a",
"typed",
"binding",
"e",
".",
"g",
".",
"foobar",
"=",
"?"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/query/ModelCriterion.php#L210-L217 |
propelorm/Propel | generator/lib/model/diff/PropelForeignKeyComparator.php | PropelForeignKeyComparator.computeDiff | public static function computeDiff(ForeignKey $fromFk, ForeignKey $toFk, $caseInsensitive = false)
{
// Check for differences in local and remote table
$test = $caseInsensitive ?
strtolower($fromFk->getTableName()) != strtolower($toFk->getTableName()) :
$fromFk->getTableName() != $toFk->getTableName();
if ($test) {
return true;
}
$test = $caseInsensitive ?
strtolower($fromFk->getForeignTableName()) != strtolower($toFk->getForeignTableName()) :
$fromFk->getForeignTableName() != $toFk->getForeignTableName();
if ($test) {
return true;
}
// compare columns
$fromFkLocalColumns = $fromFk->getLocalColumns();
sort($fromFkLocalColumns);
$toFkLocalColumns = $toFk->getLocalColumns();
sort($toFkLocalColumns);
if (array_map('strtolower', $fromFkLocalColumns) != array_map('strtolower', $toFkLocalColumns)) {
return true;
}
$fromFkForeignColumns = $fromFk->getForeignColumns();
sort($fromFkForeignColumns);
$toFkForeignColumns = $toFk->getForeignColumns();
sort($toFkForeignColumns);
if (array_map('strtolower', $fromFkForeignColumns) != array_map('strtolower', $toFkForeignColumns)) {
return true;
}
/*
* Compare onDelete and onUpdate:
*
* "RESTRICT" and its synonym "NO ACTION" is default and is not being reported explicitly.
*/
$equalBehavior = array('', 'RESTRICT', 'NO ACTION');
$fromOnUpdate = strtoupper($fromFk->normalizeFKey($fromFk->getOnUpdate()));
$toOnUpdate = strtoupper($toFk->normalizeFKey($toFk->getOnUpdate()));
if ((in_array($fromOnUpdate, $equalBehavior) && !in_array($toOnUpdate, $equalBehavior)) || (!in_array($fromOnUpdate, $equalBehavior) && in_array($toOnUpdate, $equalBehavior))) {
return true;
}
$fromOnDelete = strtoupper($fromFk->normalizeFKey($fromFk->getOnDelete()));
$toOnDelete = strtoupper($toFk->normalizeFKey($toFk->getOnDelete()));
if ((in_array($fromOnDelete, $equalBehavior) && !in_array($toOnDelete, $equalBehavior)) || (!in_array($fromOnDelete, $equalBehavior) && in_array($toOnDelete, $equalBehavior))) {
return true;
}
// compare skipSql
if ($fromFk->isSkipSql() != $toFk->isSkipSql()) {
return true;
}
return false;
} | php | public static function computeDiff(ForeignKey $fromFk, ForeignKey $toFk, $caseInsensitive = false)
{
// Check for differences in local and remote table
$test = $caseInsensitive ?
strtolower($fromFk->getTableName()) != strtolower($toFk->getTableName()) :
$fromFk->getTableName() != $toFk->getTableName();
if ($test) {
return true;
}
$test = $caseInsensitive ?
strtolower($fromFk->getForeignTableName()) != strtolower($toFk->getForeignTableName()) :
$fromFk->getForeignTableName() != $toFk->getForeignTableName();
if ($test) {
return true;
}
// compare columns
$fromFkLocalColumns = $fromFk->getLocalColumns();
sort($fromFkLocalColumns);
$toFkLocalColumns = $toFk->getLocalColumns();
sort($toFkLocalColumns);
if (array_map('strtolower', $fromFkLocalColumns) != array_map('strtolower', $toFkLocalColumns)) {
return true;
}
$fromFkForeignColumns = $fromFk->getForeignColumns();
sort($fromFkForeignColumns);
$toFkForeignColumns = $toFk->getForeignColumns();
sort($toFkForeignColumns);
if (array_map('strtolower', $fromFkForeignColumns) != array_map('strtolower', $toFkForeignColumns)) {
return true;
}
/*
* Compare onDelete and onUpdate:
*
* "RESTRICT" and its synonym "NO ACTION" is default and is not being reported explicitly.
*/
$equalBehavior = array('', 'RESTRICT', 'NO ACTION');
$fromOnUpdate = strtoupper($fromFk->normalizeFKey($fromFk->getOnUpdate()));
$toOnUpdate = strtoupper($toFk->normalizeFKey($toFk->getOnUpdate()));
if ((in_array($fromOnUpdate, $equalBehavior) && !in_array($toOnUpdate, $equalBehavior)) || (!in_array($fromOnUpdate, $equalBehavior) && in_array($toOnUpdate, $equalBehavior))) {
return true;
}
$fromOnDelete = strtoupper($fromFk->normalizeFKey($fromFk->getOnDelete()));
$toOnDelete = strtoupper($toFk->normalizeFKey($toFk->getOnDelete()));
if ((in_array($fromOnDelete, $equalBehavior) && !in_array($toOnDelete, $equalBehavior)) || (!in_array($fromOnDelete, $equalBehavior) && in_array($toOnDelete, $equalBehavior))) {
return true;
}
// compare skipSql
if ($fromFk->isSkipSql() != $toFk->isSkipSql()) {
return true;
}
return false;
} | [
"public",
"static",
"function",
"computeDiff",
"(",
"ForeignKey",
"$",
"fromFk",
",",
"ForeignKey",
"$",
"toFk",
",",
"$",
"caseInsensitive",
"=",
"false",
")",
"{",
"// Check for differences in local and remote table",
"$",
"test",
"=",
"$",
"caseInsensitive",
"?",
"strtolower",
"(",
"$",
"fromFk",
"->",
"getTableName",
"(",
")",
")",
"!=",
"strtolower",
"(",
"$",
"toFk",
"->",
"getTableName",
"(",
")",
")",
":",
"$",
"fromFk",
"->",
"getTableName",
"(",
")",
"!=",
"$",
"toFk",
"->",
"getTableName",
"(",
")",
";",
"if",
"(",
"$",
"test",
")",
"{",
"return",
"true",
";",
"}",
"$",
"test",
"=",
"$",
"caseInsensitive",
"?",
"strtolower",
"(",
"$",
"fromFk",
"->",
"getForeignTableName",
"(",
")",
")",
"!=",
"strtolower",
"(",
"$",
"toFk",
"->",
"getForeignTableName",
"(",
")",
")",
":",
"$",
"fromFk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"toFk",
"->",
"getForeignTableName",
"(",
")",
";",
"if",
"(",
"$",
"test",
")",
"{",
"return",
"true",
";",
"}",
"// compare columns",
"$",
"fromFkLocalColumns",
"=",
"$",
"fromFk",
"->",
"getLocalColumns",
"(",
")",
";",
"sort",
"(",
"$",
"fromFkLocalColumns",
")",
";",
"$",
"toFkLocalColumns",
"=",
"$",
"toFk",
"->",
"getLocalColumns",
"(",
")",
";",
"sort",
"(",
"$",
"toFkLocalColumns",
")",
";",
"if",
"(",
"array_map",
"(",
"'strtolower'",
",",
"$",
"fromFkLocalColumns",
")",
"!=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"toFkLocalColumns",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"fromFkForeignColumns",
"=",
"$",
"fromFk",
"->",
"getForeignColumns",
"(",
")",
";",
"sort",
"(",
"$",
"fromFkForeignColumns",
")",
";",
"$",
"toFkForeignColumns",
"=",
"$",
"toFk",
"->",
"getForeignColumns",
"(",
")",
";",
"sort",
"(",
"$",
"toFkForeignColumns",
")",
";",
"if",
"(",
"array_map",
"(",
"'strtolower'",
",",
"$",
"fromFkForeignColumns",
")",
"!=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"toFkForeignColumns",
")",
")",
"{",
"return",
"true",
";",
"}",
"/*\n * Compare onDelete and onUpdate:\n *\n * \"RESTRICT\" and its synonym \"NO ACTION\" is default and is not being reported explicitly.\n */",
"$",
"equalBehavior",
"=",
"array",
"(",
"''",
",",
"'RESTRICT'",
",",
"'NO ACTION'",
")",
";",
"$",
"fromOnUpdate",
"=",
"strtoupper",
"(",
"$",
"fromFk",
"->",
"normalizeFKey",
"(",
"$",
"fromFk",
"->",
"getOnUpdate",
"(",
")",
")",
")",
";",
"$",
"toOnUpdate",
"=",
"strtoupper",
"(",
"$",
"toFk",
"->",
"normalizeFKey",
"(",
"$",
"toFk",
"->",
"getOnUpdate",
"(",
")",
")",
")",
";",
"if",
"(",
"(",
"in_array",
"(",
"$",
"fromOnUpdate",
",",
"$",
"equalBehavior",
")",
"&&",
"!",
"in_array",
"(",
"$",
"toOnUpdate",
",",
"$",
"equalBehavior",
")",
")",
"||",
"(",
"!",
"in_array",
"(",
"$",
"fromOnUpdate",
",",
"$",
"equalBehavior",
")",
"&&",
"in_array",
"(",
"$",
"toOnUpdate",
",",
"$",
"equalBehavior",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"fromOnDelete",
"=",
"strtoupper",
"(",
"$",
"fromFk",
"->",
"normalizeFKey",
"(",
"$",
"fromFk",
"->",
"getOnDelete",
"(",
")",
")",
")",
";",
"$",
"toOnDelete",
"=",
"strtoupper",
"(",
"$",
"toFk",
"->",
"normalizeFKey",
"(",
"$",
"toFk",
"->",
"getOnDelete",
"(",
")",
")",
")",
";",
"if",
"(",
"(",
"in_array",
"(",
"$",
"fromOnDelete",
",",
"$",
"equalBehavior",
")",
"&&",
"!",
"in_array",
"(",
"$",
"toOnDelete",
",",
"$",
"equalBehavior",
")",
")",
"||",
"(",
"!",
"in_array",
"(",
"$",
"fromOnDelete",
",",
"$",
"equalBehavior",
")",
"&&",
"in_array",
"(",
"$",
"toOnDelete",
",",
"$",
"equalBehavior",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"// compare skipSql",
"if",
"(",
"$",
"fromFk",
"->",
"isSkipSql",
"(",
")",
"!=",
"$",
"toFk",
"->",
"isSkipSql",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Compute the difference between two Foreign key objects
@param ForeignKey $fromFk
@param ForeignKey $toFk
@param boolean $caseInsensitive Whether the comparison is case insensitive.
False by default.
@return boolean false if the two fks are similar, true if they have differences | [
"Compute",
"the",
"difference",
"between",
"two",
"Foreign",
"key",
"objects"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/diff/PropelForeignKeyComparator.php#L33-L90 |
propelorm/Propel | runtime/lib/logger/MojaviLogAdapter.php | MojaviLogAdapter.log | public function log($message, $severity = null)
{
if (is_null($this->logger)) {
$this->logger = LogManager::getLogger('propel');
}
switch ($severity) {
case 'crit':
$method = 'fatal';
break;
case 'err':
$method = 'error';
break;
case 'alert':
case 'warning':
$method = 'warning';
break;
case 'notice':
case 'info':
$method = 'info';
break;
case 'debug':
default:
$method = 'debug';
}
// get a backtrace to pass class, function, file, & line to Mojavi logger
$trace = debug_backtrace();
// call the appropriate Mojavi logger method
$this->logger->{$method} (
$message,
$trace[2]['class'],
$trace[2]['function'],
$trace[1]['file'],
$trace[1]['line']
);
} | php | public function log($message, $severity = null)
{
if (is_null($this->logger)) {
$this->logger = LogManager::getLogger('propel');
}
switch ($severity) {
case 'crit':
$method = 'fatal';
break;
case 'err':
$method = 'error';
break;
case 'alert':
case 'warning':
$method = 'warning';
break;
case 'notice':
case 'info':
$method = 'info';
break;
case 'debug':
default:
$method = 'debug';
}
// get a backtrace to pass class, function, file, & line to Mojavi logger
$trace = debug_backtrace();
// call the appropriate Mojavi logger method
$this->logger->{$method} (
$message,
$trace[2]['class'],
$trace[2]['function'],
$trace[1]['file'],
$trace[1]['line']
);
} | [
"public",
"function",
"log",
"(",
"$",
"message",
",",
"$",
"severity",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"logger",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"=",
"LogManager",
"::",
"getLogger",
"(",
"'propel'",
")",
";",
"}",
"switch",
"(",
"$",
"severity",
")",
"{",
"case",
"'crit'",
":",
"$",
"method",
"=",
"'fatal'",
";",
"break",
";",
"case",
"'err'",
":",
"$",
"method",
"=",
"'error'",
";",
"break",
";",
"case",
"'alert'",
":",
"case",
"'warning'",
":",
"$",
"method",
"=",
"'warning'",
";",
"break",
";",
"case",
"'notice'",
":",
"case",
"'info'",
":",
"$",
"method",
"=",
"'info'",
";",
"break",
";",
"case",
"'debug'",
":",
"default",
":",
"$",
"method",
"=",
"'debug'",
";",
"}",
"// get a backtrace to pass class, function, file, & line to Mojavi logger",
"$",
"trace",
"=",
"debug_backtrace",
"(",
")",
";",
"// call the appropriate Mojavi logger method",
"$",
"this",
"->",
"logger",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"message",
",",
"$",
"trace",
"[",
"2",
"]",
"[",
"'class'",
"]",
",",
"$",
"trace",
"[",
"2",
"]",
"[",
"'function'",
"]",
",",
"$",
"trace",
"[",
"1",
"]",
"[",
"'file'",
"]",
",",
"$",
"trace",
"[",
"1",
"]",
"[",
"'line'",
"]",
")",
";",
"}"
] | Primary method to handle logging.
@param mixed $message String or Exception object containing the message to log.
@param integer $severity The numeric severity. Defaults to null so that no
assumptions are made about the logging backend. | [
"Primary",
"method",
"to",
"handle",
"logging",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/logger/MojaviLogAdapter.php#L113-L150 |
propelorm/Propel | runtime/lib/connection/DebugPDOStatement.php | DebugPDOStatement.getExecutedQueryString | public function getExecutedQueryString(array $values = array())
{
$sql = $this->queryString;
$boundValues = empty($values) ? $this->boundValues : $values;
$matches = array();
if (preg_match_all('/(:p[0-9]+\b)/', $sql, $matches)) {
$size = count($matches[1]);
for ($i = $size - 1; $i >= 0; $i--) {
$pos = $matches[1][$i];
// trimming extra quotes, making sure value is properly quoted afterwards
$boundValue = $boundValues[$pos];
if (is_string($boundValue)) { // quoting only needed for string values
$boundValue = trim($boundValue, "'");
$boundValue = $this->pdo->quote($boundValue);
}
$sql = str_replace($pos, $boundValue, $sql);
}
}
return $sql;
} | php | public function getExecutedQueryString(array $values = array())
{
$sql = $this->queryString;
$boundValues = empty($values) ? $this->boundValues : $values;
$matches = array();
if (preg_match_all('/(:p[0-9]+\b)/', $sql, $matches)) {
$size = count($matches[1]);
for ($i = $size - 1; $i >= 0; $i--) {
$pos = $matches[1][$i];
// trimming extra quotes, making sure value is properly quoted afterwards
$boundValue = $boundValues[$pos];
if (is_string($boundValue)) { // quoting only needed for string values
$boundValue = trim($boundValue, "'");
$boundValue = $this->pdo->quote($boundValue);
}
$sql = str_replace($pos, $boundValue, $sql);
}
}
return $sql;
} | [
"public",
"function",
"getExecutedQueryString",
"(",
"array",
"$",
"values",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"queryString",
";",
"$",
"boundValues",
"=",
"empty",
"(",
"$",
"values",
")",
"?",
"$",
"this",
"->",
"boundValues",
":",
"$",
"values",
";",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match_all",
"(",
"'/(:p[0-9]+\\b)/'",
",",
"$",
"sql",
",",
"$",
"matches",
")",
")",
"{",
"$",
"size",
"=",
"count",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"size",
"-",
"1",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"pos",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
";",
"// trimming extra quotes, making sure value is properly quoted afterwards",
"$",
"boundValue",
"=",
"$",
"boundValues",
"[",
"$",
"pos",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"boundValue",
")",
")",
"{",
"// quoting only needed for string values",
"$",
"boundValue",
"=",
"trim",
"(",
"$",
"boundValue",
",",
"\"'\"",
")",
";",
"$",
"boundValue",
"=",
"$",
"this",
"->",
"pdo",
"->",
"quote",
"(",
"$",
"boundValue",
")",
";",
"}",
"$",
"sql",
"=",
"str_replace",
"(",
"$",
"pos",
",",
"$",
"boundValue",
",",
"$",
"sql",
")",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | @param array $values Parameters which were passed to execute(), if any. Default: bound parameters.
@return string | [
"@param",
"array",
"$values",
"Parameters",
"which",
"were",
"passed",
"to",
"execute",
"()",
"if",
"any",
".",
"Default",
":",
"bound",
"parameters",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/connection/DebugPDOStatement.php#L68-L89 |
propelorm/Propel | runtime/lib/connection/DebugPDOStatement.php | DebugPDOStatement.execute | public function execute($input_parameters = null)
{
$debug = $this->pdo->getDebugSnapshot();
$return = parent::execute($input_parameters);
$sql = $this->getExecutedQueryString($input_parameters?$input_parameters:array());
$this->pdo->log($sql, null, __METHOD__, $debug);
$this->pdo->setLastExecutedQuery($sql);
$this->pdo->incrementQueryCount();
return $return;
} | php | public function execute($input_parameters = null)
{
$debug = $this->pdo->getDebugSnapshot();
$return = parent::execute($input_parameters);
$sql = $this->getExecutedQueryString($input_parameters?$input_parameters:array());
$this->pdo->log($sql, null, __METHOD__, $debug);
$this->pdo->setLastExecutedQuery($sql);
$this->pdo->incrementQueryCount();
return $return;
} | [
"public",
"function",
"execute",
"(",
"$",
"input_parameters",
"=",
"null",
")",
"{",
"$",
"debug",
"=",
"$",
"this",
"->",
"pdo",
"->",
"getDebugSnapshot",
"(",
")",
";",
"$",
"return",
"=",
"parent",
"::",
"execute",
"(",
"$",
"input_parameters",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"getExecutedQueryString",
"(",
"$",
"input_parameters",
"?",
"$",
"input_parameters",
":",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"pdo",
"->",
"log",
"(",
"$",
"sql",
",",
"null",
",",
"__METHOD__",
",",
"$",
"debug",
")",
";",
"$",
"this",
"->",
"pdo",
"->",
"setLastExecutedQuery",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"pdo",
"->",
"incrementQueryCount",
"(",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Executes a prepared statement. Returns a boolean value indicating success.
Overridden for query counting and logging.
@param string $input_parameters
@return boolean | [
"Executes",
"a",
"prepared",
"statement",
".",
"Returns",
"a",
"boolean",
"value",
"indicating",
"success",
".",
"Overridden",
"for",
"query",
"counting",
"and",
"logging",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/connection/DebugPDOStatement.php#L99-L110 |
propelorm/Propel | runtime/lib/connection/DebugPDOStatement.php | DebugPDOStatement.bindValue | public function bindValue($pos, $value, $type = PDO::PARAM_STR)
{
$debug = $this->pdo->getDebugSnapshot();
$typestr = isset(self::$typeMap[$type]) ? self::$typeMap[$type] : '(default)';
$return = parent::bindValue($pos, $value, $type);
$valuestr = $type == PDO::PARAM_LOB ? '[LOB value]' : var_export($value, true);
$msg = sprintf('Binding %s at position %s w/ PDO type %s', $valuestr, $pos, $typestr);
$this->boundValues[$pos] = $value;
$this->pdo->log($msg, null, __METHOD__, $debug);
return $return;
} | php | public function bindValue($pos, $value, $type = PDO::PARAM_STR)
{
$debug = $this->pdo->getDebugSnapshot();
$typestr = isset(self::$typeMap[$type]) ? self::$typeMap[$type] : '(default)';
$return = parent::bindValue($pos, $value, $type);
$valuestr = $type == PDO::PARAM_LOB ? '[LOB value]' : var_export($value, true);
$msg = sprintf('Binding %s at position %s w/ PDO type %s', $valuestr, $pos, $typestr);
$this->boundValues[$pos] = $value;
$this->pdo->log($msg, null, __METHOD__, $debug);
return $return;
} | [
"public",
"function",
"bindValue",
"(",
"$",
"pos",
",",
"$",
"value",
",",
"$",
"type",
"=",
"PDO",
"::",
"PARAM_STR",
")",
"{",
"$",
"debug",
"=",
"$",
"this",
"->",
"pdo",
"->",
"getDebugSnapshot",
"(",
")",
";",
"$",
"typestr",
"=",
"isset",
"(",
"self",
"::",
"$",
"typeMap",
"[",
"$",
"type",
"]",
")",
"?",
"self",
"::",
"$",
"typeMap",
"[",
"$",
"type",
"]",
":",
"'(default)'",
";",
"$",
"return",
"=",
"parent",
"::",
"bindValue",
"(",
"$",
"pos",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"$",
"valuestr",
"=",
"$",
"type",
"==",
"PDO",
"::",
"PARAM_LOB",
"?",
"'[LOB value]'",
":",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
";",
"$",
"msg",
"=",
"sprintf",
"(",
"'Binding %s at position %s w/ PDO type %s'",
",",
"$",
"valuestr",
",",
"$",
"pos",
",",
"$",
"typestr",
")",
";",
"$",
"this",
"->",
"boundValues",
"[",
"$",
"pos",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"pdo",
"->",
"log",
"(",
"$",
"msg",
",",
"null",
",",
"__METHOD__",
",",
"$",
"debug",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Binds a value to a corresponding named or question mark placeholder in the SQL statement
that was use to prepare the statement. Returns a boolean value indicating success.
@param integer $pos Parameter identifier (for determining what to replace in the query).
@param mixed $value The value to bind to the parameter.
@param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR.
@return boolean | [
"Binds",
"a",
"value",
"to",
"a",
"corresponding",
"named",
"or",
"question",
"mark",
"placeholder",
"in",
"the",
"SQL",
"statement",
"that",
"was",
"use",
"to",
"prepare",
"the",
"statement",
".",
"Returns",
"a",
"boolean",
"value",
"indicating",
"success",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/connection/DebugPDOStatement.php#L122-L135 |
propelorm/Propel | runtime/lib/connection/DebugPDOStatement.php | DebugPDOStatement.bindParam | public function bindParam($pos, &$value, $type = PDO::PARAM_STR, $length = 0, $driver_options = null)
{
$originalValue = $value;
$debug = $this->pdo->getDebugSnapshot();
$typestr = isset(self::$typeMap[$type]) ? self::$typeMap[$type] : '(default)';
$return = parent::bindParam($pos, $value, $type, $length, $driver_options);
$valuestr = $length > 100 ? '[Large value]' : var_export($value, true);
$msg = sprintf('Binding %s at position %s w/ PDO type %s', $valuestr, $pos, $typestr);
$this->boundValues[$pos] = $originalValue;
$this->pdo->log($msg, null, __METHOD__, $debug);
return $return;
} | php | public function bindParam($pos, &$value, $type = PDO::PARAM_STR, $length = 0, $driver_options = null)
{
$originalValue = $value;
$debug = $this->pdo->getDebugSnapshot();
$typestr = isset(self::$typeMap[$type]) ? self::$typeMap[$type] : '(default)';
$return = parent::bindParam($pos, $value, $type, $length, $driver_options);
$valuestr = $length > 100 ? '[Large value]' : var_export($value, true);
$msg = sprintf('Binding %s at position %s w/ PDO type %s', $valuestr, $pos, $typestr);
$this->boundValues[$pos] = $originalValue;
$this->pdo->log($msg, null, __METHOD__, $debug);
return $return;
} | [
"public",
"function",
"bindParam",
"(",
"$",
"pos",
",",
"&",
"$",
"value",
",",
"$",
"type",
"=",
"PDO",
"::",
"PARAM_STR",
",",
"$",
"length",
"=",
"0",
",",
"$",
"driver_options",
"=",
"null",
")",
"{",
"$",
"originalValue",
"=",
"$",
"value",
";",
"$",
"debug",
"=",
"$",
"this",
"->",
"pdo",
"->",
"getDebugSnapshot",
"(",
")",
";",
"$",
"typestr",
"=",
"isset",
"(",
"self",
"::",
"$",
"typeMap",
"[",
"$",
"type",
"]",
")",
"?",
"self",
"::",
"$",
"typeMap",
"[",
"$",
"type",
"]",
":",
"'(default)'",
";",
"$",
"return",
"=",
"parent",
"::",
"bindParam",
"(",
"$",
"pos",
",",
"$",
"value",
",",
"$",
"type",
",",
"$",
"length",
",",
"$",
"driver_options",
")",
";",
"$",
"valuestr",
"=",
"$",
"length",
">",
"100",
"?",
"'[Large value]'",
":",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
";",
"$",
"msg",
"=",
"sprintf",
"(",
"'Binding %s at position %s w/ PDO type %s'",
",",
"$",
"valuestr",
",",
"$",
"pos",
",",
"$",
"typestr",
")",
";",
"$",
"this",
"->",
"boundValues",
"[",
"$",
"pos",
"]",
"=",
"$",
"originalValue",
";",
"$",
"this",
"->",
"pdo",
"->",
"log",
"(",
"$",
"msg",
",",
"null",
",",
"__METHOD__",
",",
"$",
"debug",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Binds a PHP variable to a corresponding named or question mark placeholder in the SQL statement
that was use to prepare the statement. Unlike PDOStatement::bindValue(), the variable is bound
as a reference and will only be evaluated at the time that PDOStatement::execute() is called.
Returns a boolean value indicating success.
@param integer $pos Parameter identifier (for determining what to replace in the query).
@param mixed $value The value to bind to the parameter.
@param integer $type Explicit data type for the parameter using the PDO::PARAM_* constants. Defaults to PDO::PARAM_STR.
@param integer $length Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length.
@param mixed $driver_options
@return boolean | [
"Binds",
"a",
"PHP",
"variable",
"to",
"a",
"corresponding",
"named",
"or",
"question",
"mark",
"placeholder",
"in",
"the",
"SQL",
"statement",
"that",
"was",
"use",
"to",
"prepare",
"the",
"statement",
".",
"Unlike",
"PDOStatement",
"::",
"bindValue",
"()",
"the",
"variable",
"is",
"bound",
"as",
"a",
"reference",
"and",
"will",
"only",
"be",
"evaluated",
"at",
"the",
"time",
"that",
"PDOStatement",
"::",
"execute",
"()",
"is",
"called",
".",
"Returns",
"a",
"boolean",
"value",
"indicating",
"success",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/connection/DebugPDOStatement.php#L151-L165 |
propelorm/Propel | runtime/lib/parser/PropelCSVParser.php | PropelCSVParser.fromArray | public function fromArray($array, $isList = false, $includeHeading = true)
{
$rows = array();
if ($isList) {
if ($includeHeading) {
$rows[] = implode($this->formatRow(array_keys(reset($array))), $this->delimiter);
}
foreach ($array as $row) {
$rows[] = implode($this->formatRow($row), $this->delimiter);
}
} else {
if ($includeHeading) {
$rows[] = implode($this->formatRow(array_keys($array)), $this->delimiter);
}
$rows[] = implode($this->formatRow($array), $this->delimiter);
}
return implode($rows, $this->lineTerminator) . $this->lineTerminator;
} | php | public function fromArray($array, $isList = false, $includeHeading = true)
{
$rows = array();
if ($isList) {
if ($includeHeading) {
$rows[] = implode($this->formatRow(array_keys(reset($array))), $this->delimiter);
}
foreach ($array as $row) {
$rows[] = implode($this->formatRow($row), $this->delimiter);
}
} else {
if ($includeHeading) {
$rows[] = implode($this->formatRow(array_keys($array)), $this->delimiter);
}
$rows[] = implode($this->formatRow($array), $this->delimiter);
}
return implode($rows, $this->lineTerminator) . $this->lineTerminator;
} | [
"public",
"function",
"fromArray",
"(",
"$",
"array",
",",
"$",
"isList",
"=",
"false",
",",
"$",
"includeHeading",
"=",
"true",
")",
"{",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"isList",
")",
"{",
"if",
"(",
"$",
"includeHeading",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"implode",
"(",
"$",
"this",
"->",
"formatRow",
"(",
"array_keys",
"(",
"reset",
"(",
"$",
"array",
")",
")",
")",
",",
"$",
"this",
"->",
"delimiter",
")",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"row",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"implode",
"(",
"$",
"this",
"->",
"formatRow",
"(",
"$",
"row",
")",
",",
"$",
"this",
"->",
"delimiter",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"includeHeading",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"implode",
"(",
"$",
"this",
"->",
"formatRow",
"(",
"array_keys",
"(",
"$",
"array",
")",
")",
",",
"$",
"this",
"->",
"delimiter",
")",
";",
"}",
"$",
"rows",
"[",
"]",
"=",
"implode",
"(",
"$",
"this",
"->",
"formatRow",
"(",
"$",
"array",
")",
",",
"$",
"this",
"->",
"delimiter",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"rows",
",",
"$",
"this",
"->",
"lineTerminator",
")",
".",
"$",
"this",
"->",
"lineTerminator",
";",
"}"
] | Converts data from an associative array to CSV.
@param array $array Source data to convert
@param boolean $isList Whether the input data contains more than one row
@param boolean $includeHeading Whether the output should contain a heading line
@return string Converted data, as a CSV string | [
"Converts",
"data",
"from",
"an",
"associative",
"array",
"to",
"CSV",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/parser/PropelCSVParser.php#L43-L61 |
propelorm/Propel | runtime/lib/parser/PropelCSVParser.php | PropelCSVParser.formatRow | protected function formatRow($row)
{
foreach ($row as &$column) {
if (!is_scalar($column)) {
$column = $this->serialize($column);
}
switch ($this->quoting) {
case self::QUOTE_NONE:
// do nothing... no quoting is happening here
break;
case self::QUOTE_ALL:
$column = $this->quote($this->escape($column));
break;
case self::QUOTE_NONNUMERIC:
if (preg_match("/[^0-9]/", $column)) {
$column = $this->quote($this->escape($column));
}
break;
case self::QUOTE_MINIMAL:
default:
if ($this->containsSpecialChars($column)) {
$column = $this->quote($this->escape($column));
}
break;
}
}
return $row;
} | php | protected function formatRow($row)
{
foreach ($row as &$column) {
if (!is_scalar($column)) {
$column = $this->serialize($column);
}
switch ($this->quoting) {
case self::QUOTE_NONE:
// do nothing... no quoting is happening here
break;
case self::QUOTE_ALL:
$column = $this->quote($this->escape($column));
break;
case self::QUOTE_NONNUMERIC:
if (preg_match("/[^0-9]/", $column)) {
$column = $this->quote($this->escape($column));
}
break;
case self::QUOTE_MINIMAL:
default:
if ($this->containsSpecialChars($column)) {
$column = $this->quote($this->escape($column));
}
break;
}
}
return $row;
} | [
"protected",
"function",
"formatRow",
"(",
"$",
"row",
")",
"{",
"foreach",
"(",
"$",
"row",
"as",
"&",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"column",
")",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"serialize",
"(",
"$",
"column",
")",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"quoting",
")",
"{",
"case",
"self",
"::",
"QUOTE_NONE",
":",
"// do nothing... no quoting is happening here",
"break",
";",
"case",
"self",
"::",
"QUOTE_ALL",
":",
"$",
"column",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"this",
"->",
"escape",
"(",
"$",
"column",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"QUOTE_NONNUMERIC",
":",
"if",
"(",
"preg_match",
"(",
"\"/[^0-9]/\"",
",",
"$",
"column",
")",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"this",
"->",
"escape",
"(",
"$",
"column",
")",
")",
";",
"}",
"break",
";",
"case",
"self",
"::",
"QUOTE_MINIMAL",
":",
"default",
":",
"if",
"(",
"$",
"this",
"->",
"containsSpecialChars",
"(",
"$",
"column",
")",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"this",
"->",
"escape",
"(",
"$",
"column",
")",
")",
";",
"}",
"break",
";",
"}",
"}",
"return",
"$",
"row",
";",
"}"
] | Accepts a row of data and returns it formatted
@param array $row An array of data to be formatted for output to the file
@return array The formatted array | [
"Accepts",
"a",
"row",
"of",
"data",
"and",
"returns",
"it",
"formatted"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/parser/PropelCSVParser.php#L75-L103 |
propelorm/Propel | runtime/lib/parser/PropelCSVParser.php | PropelCSVParser.containsSpecialChars | protected function containsSpecialChars($input)
{
$special_chars = str_split($this->lineTerminator, 1);
$special_chars[] = $this->quotechar;
$special_chars[] = $this->delimiter;
foreach ($special_chars as $char) {
if (strpos($input, $char) !== false) {
return true;
}
}
return false;
} | php | protected function containsSpecialChars($input)
{
$special_chars = str_split($this->lineTerminator, 1);
$special_chars[] = $this->quotechar;
$special_chars[] = $this->delimiter;
foreach ($special_chars as $char) {
if (strpos($input, $char) !== false) {
return true;
}
}
return false;
} | [
"protected",
"function",
"containsSpecialChars",
"(",
"$",
"input",
")",
"{",
"$",
"special_chars",
"=",
"str_split",
"(",
"$",
"this",
"->",
"lineTerminator",
",",
"1",
")",
";",
"$",
"special_chars",
"[",
"]",
"=",
"$",
"this",
"->",
"quotechar",
";",
"$",
"special_chars",
"[",
"]",
"=",
"$",
"this",
"->",
"delimiter",
";",
"foreach",
"(",
"$",
"special_chars",
"as",
"$",
"char",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"input",
",",
"$",
"char",
")",
"!==",
"false",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if input contains quotechar, delimiter or any of the characters in lineTerminator
@param string $input A single value to be checked for special characters
@return boolean True if contains any special characters | [
"Returns",
"true",
"if",
"input",
"contains",
"quotechar",
"delimiter",
"or",
"any",
"of",
"the",
"characters",
"in",
"lineTerminator"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/parser/PropelCSVParser.php#L140-L152 |
propelorm/Propel | runtime/lib/parser/PropelCSVParser.php | PropelCSVParser.fromCSV | public function fromCSV($data, $isList = false, $includeHeading = true)
{
return $this->toArray($data, $isList, $includeHeading);
} | php | public function fromCSV($data, $isList = false, $includeHeading = true)
{
return $this->toArray($data, $isList, $includeHeading);
} | [
"public",
"function",
"fromCSV",
"(",
"$",
"data",
",",
"$",
"isList",
"=",
"false",
",",
"$",
"includeHeading",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"toArray",
"(",
"$",
"data",
",",
"$",
"isList",
",",
"$",
"includeHeading",
")",
";",
"}"
] | Alias for PropelCSVParser::toArray()
@param string $data Source data to convert, as a CSV string
@param boolean $isList Whether the input data contains more than one row
@param boolean $includeHeading Whether the input contains a heading line
@return array Converted data | [
"Alias",
"for",
"PropelCSVParser",
"::",
"toArray",
"()"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/parser/PropelCSVParser.php#L310-L313 |
propelorm/Propel | runtime/lib/adapter/DBAdapter.php | DBAdapter.factory | public static function factory($driver)
{
$adapterClass = isset(self::$adapters[$driver]) ? self::$adapters[$driver] : null;
if ($adapterClass !== null) {
$a = new $adapterClass();
return $a;
} else {
throw new PropelException("Unsupported Propel driver: " . $driver . ": Check your configuration file");
}
} | php | public static function factory($driver)
{
$adapterClass = isset(self::$adapters[$driver]) ? self::$adapters[$driver] : null;
if ($adapterClass !== null) {
$a = new $adapterClass();
return $a;
} else {
throw new PropelException("Unsupported Propel driver: " . $driver . ": Check your configuration file");
}
} | [
"public",
"static",
"function",
"factory",
"(",
"$",
"driver",
")",
"{",
"$",
"adapterClass",
"=",
"isset",
"(",
"self",
"::",
"$",
"adapters",
"[",
"$",
"driver",
"]",
")",
"?",
"self",
"::",
"$",
"adapters",
"[",
"$",
"driver",
"]",
":",
"null",
";",
"if",
"(",
"$",
"adapterClass",
"!==",
"null",
")",
"{",
"$",
"a",
"=",
"new",
"$",
"adapterClass",
"(",
")",
";",
"return",
"$",
"a",
";",
"}",
"else",
"{",
"throw",
"new",
"PropelException",
"(",
"\"Unsupported Propel driver: \"",
".",
"$",
"driver",
".",
"\": Check your configuration file\"",
")",
";",
"}",
"}"
] | Creates a new instance of the database adapter associated
with the specified Propel driver.
@param string $driver The name of the Propel driver to create a new adapter instance
for or a shorter form adapter key.
@throws PropelException If the adapter could not be instantiated.
@return DBAdapter An instance of a Propel database adapter. | [
"Creates",
"a",
"new",
"instance",
"of",
"the",
"database",
"adapter",
"associated",
"with",
"the",
"specified",
"Propel",
"driver",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/adapter/DBAdapter.php#L66-L76 |
propelorm/Propel | runtime/lib/adapter/DBAdapter.php | DBAdapter.formatTemporalValue | public function formatTemporalValue($value, $type)
{
/** @var $dt PropelDateTime */
if ($dt = PropelDateTime::newInstance($value)) {
if ($type instanceof ColumnMap) {
$type = $type->getType();
}
switch ($type) {
case PropelColumnTypes::TIMESTAMP:
case PropelColumnTypes::BU_TIMESTAMP:
$value = $dt->format($this->getTimestampFormatter());
break;
case PropelColumnTypes::DATE:
case PropelColumnTypes::BU_DATE:
$value = $dt->format($this->getDateFormatter());
break;
case PropelColumnTypes::TIME:
$value = $dt->format($this->getTimeFormatter());
break;
}
}
return $value;
} | php | public function formatTemporalValue($value, $type)
{
/** @var $dt PropelDateTime */
if ($dt = PropelDateTime::newInstance($value)) {
if ($type instanceof ColumnMap) {
$type = $type->getType();
}
switch ($type) {
case PropelColumnTypes::TIMESTAMP:
case PropelColumnTypes::BU_TIMESTAMP:
$value = $dt->format($this->getTimestampFormatter());
break;
case PropelColumnTypes::DATE:
case PropelColumnTypes::BU_DATE:
$value = $dt->format($this->getDateFormatter());
break;
case PropelColumnTypes::TIME:
$value = $dt->format($this->getTimeFormatter());
break;
}
}
return $value;
} | [
"public",
"function",
"formatTemporalValue",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"/** @var $dt PropelDateTime */",
"if",
"(",
"$",
"dt",
"=",
"PropelDateTime",
"::",
"newInstance",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"type",
"instanceof",
"ColumnMap",
")",
"{",
"$",
"type",
"=",
"$",
"type",
"->",
"getType",
"(",
")",
";",
"}",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"PropelColumnTypes",
"::",
"TIMESTAMP",
":",
"case",
"PropelColumnTypes",
"::",
"BU_TIMESTAMP",
":",
"$",
"value",
"=",
"$",
"dt",
"->",
"format",
"(",
"$",
"this",
"->",
"getTimestampFormatter",
"(",
")",
")",
";",
"break",
";",
"case",
"PropelColumnTypes",
"::",
"DATE",
":",
"case",
"PropelColumnTypes",
"::",
"BU_DATE",
":",
"$",
"value",
"=",
"$",
"dt",
"->",
"format",
"(",
"$",
"this",
"->",
"getDateFormatter",
"(",
")",
")",
";",
"break",
";",
"case",
"PropelColumnTypes",
"::",
"TIME",
":",
"$",
"value",
"=",
"$",
"dt",
"->",
"format",
"(",
"$",
"this",
"->",
"getTimeFormatter",
"(",
")",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | Formats a temporal value before binding, given a ColumnMap object.
@param mixed $value The temporal value
@param mixed $type PropelColumnTypes constant, or ColumnMap object
@return string The formatted temporal value | [
"Formats",
"a",
"temporal",
"value",
"before",
"binding",
"given",
"a",
"ColumnMap",
"object",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/adapter/DBAdapter.php#L288-L311 |
propelorm/Propel | runtime/lib/adapter/DBAdapter.php | DBAdapter.getDeleteFromClause | public function getDeleteFromClause($criteria, $tableName)
{
$sql = 'DELETE ';
if ($queryComment = $criteria->getComment()) {
$sql .= '/* ' . $queryComment . ' */ ';
}
if ($realTableName = $criteria->getTableForAlias($tableName)) {
if ($this->useQuoteIdentifier()) {
$realTableName = $this->quoteIdentifierTable($realTableName);
}
$sql .= $tableName . ' FROM ' . $realTableName . ' AS ' . $tableName;
} else {
if ($this->useQuoteIdentifier()) {
$tableName = $this->quoteIdentifierTable($tableName);
}
$sql .= 'FROM ' . $tableName;
}
return $sql;
} | php | public function getDeleteFromClause($criteria, $tableName)
{
$sql = 'DELETE ';
if ($queryComment = $criteria->getComment()) {
$sql .= '/* ' . $queryComment . ' */ ';
}
if ($realTableName = $criteria->getTableForAlias($tableName)) {
if ($this->useQuoteIdentifier()) {
$realTableName = $this->quoteIdentifierTable($realTableName);
}
$sql .= $tableName . ' FROM ' . $realTableName . ' AS ' . $tableName;
} else {
if ($this->useQuoteIdentifier()) {
$tableName = $this->quoteIdentifierTable($tableName);
}
$sql .= 'FROM ' . $tableName;
}
return $sql;
} | [
"public",
"function",
"getDeleteFromClause",
"(",
"$",
"criteria",
",",
"$",
"tableName",
")",
"{",
"$",
"sql",
"=",
"'DELETE '",
";",
"if",
"(",
"$",
"queryComment",
"=",
"$",
"criteria",
"->",
"getComment",
"(",
")",
")",
"{",
"$",
"sql",
".=",
"'/* '",
".",
"$",
"queryComment",
".",
"' */ '",
";",
"}",
"if",
"(",
"$",
"realTableName",
"=",
"$",
"criteria",
"->",
"getTableForAlias",
"(",
"$",
"tableName",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"useQuoteIdentifier",
"(",
")",
")",
"{",
"$",
"realTableName",
"=",
"$",
"this",
"->",
"quoteIdentifierTable",
"(",
"$",
"realTableName",
")",
";",
"}",
"$",
"sql",
".=",
"$",
"tableName",
".",
"' FROM '",
".",
"$",
"realTableName",
".",
"' AS '",
".",
"$",
"tableName",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"useQuoteIdentifier",
"(",
")",
")",
"{",
"$",
"tableName",
"=",
"$",
"this",
"->",
"quoteIdentifierTable",
"(",
"$",
"tableName",
")",
";",
"}",
"$",
"sql",
".=",
"'FROM '",
".",
"$",
"tableName",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Returns the "DELETE FROM <table> [AS <alias>]" part of DELETE query.
@param Criteria $criteria
@param string $tableName
@return string | [
"Returns",
"the",
"DELETE",
"FROM",
"<table",
">",
"[",
"AS",
"<alias",
">",
"]",
"part",
"of",
"DELETE",
"query",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/adapter/DBAdapter.php#L395-L414 |
propelorm/Propel | runtime/lib/adapter/DBAdapter.php | DBAdapter.createSelectSqlPart | public function createSelectSqlPart(Criteria $criteria, &$fromClause, $aliasAll = false)
{
$selectClause = array();
if ($aliasAll) {
$this->turnSelectColumnsToAliases($criteria);
// no select columns after that, they are all aliases
} else {
foreach ($criteria->getSelectColumns() as $columnName) {
// expect every column to be of "table.column" formation
// it could be a function: e.g. MAX(books.price)
$tableName = null;
$selectClause[] = $columnName; // the full column name: e.g. MAX(books.price)
$parenPos = strrpos($columnName, '(');
$dotPos = strrpos($columnName, '.', ($parenPos !== false ? $parenPos : 0));
if ($dotPos !== false) {
if ($parenPos === false) { // table.column
$tableName = substr($columnName, 0, $dotPos);
} else { // FUNC(table.column)
// functions may contain qualifiers so only take the last
// word as the table name.
// COUNT(DISTINCT books.price)
$tableName = substr($columnName, $parenPos + 1, $dotPos - ($parenPos + 1));
$lastSpace = strrpos($tableName, ' ');
if ($lastSpace !== false) { // COUNT(DISTINCT books.price)
$tableName = substr($tableName, $lastSpace + 1);
}
}
// is it a table alias?
$tableName2 = $criteria->getTableForAlias($tableName);
if ($tableName2 !== null) {
$fromClause[] = $tableName2 . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
}
} // if $dotPost !== false
}
}
// set the aliases
foreach ($criteria->getAsColumns() as $alias => $col) {
$selectClause[] = $col . ' AS ' . $this->quoteIdentifier($alias);
}
$selectModifiers = $criteria->getSelectModifiers();
$queryComment = $criteria->getComment();
// Build the SQL from the arrays we compiled
$sql = "SELECT "
. ($queryComment ? '/* ' . $queryComment . ' */ ' : '')
. ($selectModifiers ? (implode(' ', $selectModifiers) . ' ') : '')
. implode(", ", $selectClause);
return $sql;
} | php | public function createSelectSqlPart(Criteria $criteria, &$fromClause, $aliasAll = false)
{
$selectClause = array();
if ($aliasAll) {
$this->turnSelectColumnsToAliases($criteria);
// no select columns after that, they are all aliases
} else {
foreach ($criteria->getSelectColumns() as $columnName) {
// expect every column to be of "table.column" formation
// it could be a function: e.g. MAX(books.price)
$tableName = null;
$selectClause[] = $columnName; // the full column name: e.g. MAX(books.price)
$parenPos = strrpos($columnName, '(');
$dotPos = strrpos($columnName, '.', ($parenPos !== false ? $parenPos : 0));
if ($dotPos !== false) {
if ($parenPos === false) { // table.column
$tableName = substr($columnName, 0, $dotPos);
} else { // FUNC(table.column)
// functions may contain qualifiers so only take the last
// word as the table name.
// COUNT(DISTINCT books.price)
$tableName = substr($columnName, $parenPos + 1, $dotPos - ($parenPos + 1));
$lastSpace = strrpos($tableName, ' ');
if ($lastSpace !== false) { // COUNT(DISTINCT books.price)
$tableName = substr($tableName, $lastSpace + 1);
}
}
// is it a table alias?
$tableName2 = $criteria->getTableForAlias($tableName);
if ($tableName2 !== null) {
$fromClause[] = $tableName2 . ' ' . $tableName;
} else {
$fromClause[] = $tableName;
}
} // if $dotPost !== false
}
}
// set the aliases
foreach ($criteria->getAsColumns() as $alias => $col) {
$selectClause[] = $col . ' AS ' . $this->quoteIdentifier($alias);
}
$selectModifiers = $criteria->getSelectModifiers();
$queryComment = $criteria->getComment();
// Build the SQL from the arrays we compiled
$sql = "SELECT "
. ($queryComment ? '/* ' . $queryComment . ' */ ' : '')
. ($selectModifiers ? (implode(' ', $selectModifiers) . ' ') : '')
. implode(", ", $selectClause);
return $sql;
} | [
"public",
"function",
"createSelectSqlPart",
"(",
"Criteria",
"$",
"criteria",
",",
"&",
"$",
"fromClause",
",",
"$",
"aliasAll",
"=",
"false",
")",
"{",
"$",
"selectClause",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"aliasAll",
")",
"{",
"$",
"this",
"->",
"turnSelectColumnsToAliases",
"(",
"$",
"criteria",
")",
";",
"// no select columns after that, they are all aliases",
"}",
"else",
"{",
"foreach",
"(",
"$",
"criteria",
"->",
"getSelectColumns",
"(",
")",
"as",
"$",
"columnName",
")",
"{",
"// expect every column to be of \"table.column\" formation",
"// it could be a function: e.g. MAX(books.price)",
"$",
"tableName",
"=",
"null",
";",
"$",
"selectClause",
"[",
"]",
"=",
"$",
"columnName",
";",
"// the full column name: e.g. MAX(books.price)",
"$",
"parenPos",
"=",
"strrpos",
"(",
"$",
"columnName",
",",
"'('",
")",
";",
"$",
"dotPos",
"=",
"strrpos",
"(",
"$",
"columnName",
",",
"'.'",
",",
"(",
"$",
"parenPos",
"!==",
"false",
"?",
"$",
"parenPos",
":",
"0",
")",
")",
";",
"if",
"(",
"$",
"dotPos",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"parenPos",
"===",
"false",
")",
"{",
"// table.column",
"$",
"tableName",
"=",
"substr",
"(",
"$",
"columnName",
",",
"0",
",",
"$",
"dotPos",
")",
";",
"}",
"else",
"{",
"// FUNC(table.column)",
"// functions may contain qualifiers so only take the last",
"// word as the table name.",
"// COUNT(DISTINCT books.price)",
"$",
"tableName",
"=",
"substr",
"(",
"$",
"columnName",
",",
"$",
"parenPos",
"+",
"1",
",",
"$",
"dotPos",
"-",
"(",
"$",
"parenPos",
"+",
"1",
")",
")",
";",
"$",
"lastSpace",
"=",
"strrpos",
"(",
"$",
"tableName",
",",
"' '",
")",
";",
"if",
"(",
"$",
"lastSpace",
"!==",
"false",
")",
"{",
"// COUNT(DISTINCT books.price)",
"$",
"tableName",
"=",
"substr",
"(",
"$",
"tableName",
",",
"$",
"lastSpace",
"+",
"1",
")",
";",
"}",
"}",
"// is it a table alias?",
"$",
"tableName2",
"=",
"$",
"criteria",
"->",
"getTableForAlias",
"(",
"$",
"tableName",
")",
";",
"if",
"(",
"$",
"tableName2",
"!==",
"null",
")",
"{",
"$",
"fromClause",
"[",
"]",
"=",
"$",
"tableName2",
".",
"' '",
".",
"$",
"tableName",
";",
"}",
"else",
"{",
"$",
"fromClause",
"[",
"]",
"=",
"$",
"tableName",
";",
"}",
"}",
"// if $dotPost !== false",
"}",
"}",
"// set the aliases",
"foreach",
"(",
"$",
"criteria",
"->",
"getAsColumns",
"(",
")",
"as",
"$",
"alias",
"=>",
"$",
"col",
")",
"{",
"$",
"selectClause",
"[",
"]",
"=",
"$",
"col",
".",
"' AS '",
".",
"$",
"this",
"->",
"quoteIdentifier",
"(",
"$",
"alias",
")",
";",
"}",
"$",
"selectModifiers",
"=",
"$",
"criteria",
"->",
"getSelectModifiers",
"(",
")",
";",
"$",
"queryComment",
"=",
"$",
"criteria",
"->",
"getComment",
"(",
")",
";",
"// Build the SQL from the arrays we compiled",
"$",
"sql",
"=",
"\"SELECT \"",
".",
"(",
"$",
"queryComment",
"?",
"'/* '",
".",
"$",
"queryComment",
".",
"' */ '",
":",
"''",
")",
".",
"(",
"$",
"selectModifiers",
"?",
"(",
"implode",
"(",
"' '",
",",
"$",
"selectModifiers",
")",
".",
"' '",
")",
":",
"''",
")",
".",
"implode",
"(",
"\", \"",
",",
"$",
"selectClause",
")",
";",
"return",
"$",
"sql",
";",
"}"
] | Builds the SELECT part of a SQL statement based on a Criteria
taking into account select columns and 'as' columns (i.e. columns aliases)
Move from BasePeer to DBAdapter and turn from static to non static
@param Criteria $criteria
@param array $fromClause
@param boolean $aliasAll
@return string | [
"Builds",
"the",
"SELECT",
"part",
"of",
"a",
"SQL",
"statement",
"based",
"on",
"a",
"Criteria",
"taking",
"into",
"account",
"select",
"columns",
"and",
"as",
"columns",
"(",
"i",
".",
"e",
".",
"columns",
"aliases",
")",
"Move",
"from",
"BasePeer",
"to",
"DBAdapter",
"and",
"turn",
"from",
"static",
"to",
"non",
"static"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/adapter/DBAdapter.php#L427-L486 |
propelorm/Propel | generator/lib/model/diff/PropelColumnDiff.php | PropelColumnDiff.getReverseDiff | public function getReverseDiff()
{
$diff = new self();
// columns
$diff->setFromColumn($this->getToColumn());
$diff->setToColumn($this->getFromColumn());
// properties
$changedProperties = array();
foreach ($this->getChangedProperties() as $name => $propertyChange) {
$changedProperties[$name] = array_reverse($propertyChange);
}
$diff->setChangedProperties($changedProperties);
return $diff;
} | php | public function getReverseDiff()
{
$diff = new self();
// columns
$diff->setFromColumn($this->getToColumn());
$diff->setToColumn($this->getFromColumn());
// properties
$changedProperties = array();
foreach ($this->getChangedProperties() as $name => $propertyChange) {
$changedProperties[$name] = array_reverse($propertyChange);
}
$diff->setChangedProperties($changedProperties);
return $diff;
} | [
"public",
"function",
"getReverseDiff",
"(",
")",
"{",
"$",
"diff",
"=",
"new",
"self",
"(",
")",
";",
"// columns",
"$",
"diff",
"->",
"setFromColumn",
"(",
"$",
"this",
"->",
"getToColumn",
"(",
")",
")",
";",
"$",
"diff",
"->",
"setToColumn",
"(",
"$",
"this",
"->",
"getFromColumn",
"(",
")",
")",
";",
"// properties",
"$",
"changedProperties",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getChangedProperties",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"propertyChange",
")",
"{",
"$",
"changedProperties",
"[",
"$",
"name",
"]",
"=",
"array_reverse",
"(",
"$",
"propertyChange",
")",
";",
"}",
"$",
"diff",
"->",
"setChangedProperties",
"(",
"$",
"changedProperties",
")",
";",
"return",
"$",
"diff",
";",
"}"
] | Get the reverse diff for this diff
@return PropelColumnDiff | [
"Get",
"the",
"reverse",
"diff",
"for",
"this",
"diff"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/model/diff/PropelColumnDiff.php#L91-L107 |
propelorm/Propel | generator/lib/builder/om/PHP5NodeBuilder.php | PHP5NodeBuilder.addClassOpen | protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$script .= "
/**
* Base class that represents a row from the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* @package propel.generator." . $this->getPackage() . "
*/
abstract class " . $this->getClassname() . " implements IteratorAggregate {
";
} | php | protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$script .= "
/**
* Base class that represents a row from the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* @package propel.generator." . $this->getPackage() . "
*/
abstract class " . $this->getClassname() . " implements IteratorAggregate {
";
} | [
"protected",
"function",
"addClassOpen",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"tableName",
"=",
"$",
"table",
"->",
"getName",
"(",
")",
";",
"$",
"tableDesc",
"=",
"$",
"table",
"->",
"getDescription",
"(",
")",
";",
"$",
"script",
".=",
"\"\n/**\n * Base class that represents a row from 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 *\"",
";",
"}",
"$",
"script",
".=",
"\"\n * @package propel.generator.\"",
".",
"$",
"this",
"->",
"getPackage",
"(",
")",
".",
"\"\n */\nabstract class \"",
".",
"$",
"this",
"->",
"getClassname",
"(",
")",
".",
"\" implements IteratorAggregate {\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/PHP5NodeBuilder.php#L59-L85 |
propelorm/Propel | generator/lib/builder/om/PHP5NodeBuilder.php | PHP5NodeBuilder.addClassBody | protected function addClassBody(&$script)
{
$table = $this->getTable();
$this->addAttributes($script);
$this->addConstructor($script);
$this->addCallOverload($script);
$this->addSetIteratorOptions($script);
$this->addGetIterator($script);
$this->addGetNodeObj($script);
$this->addGetNodePath($script);
$this->addGetNodeIndex($script);
$this->addGetNodeLevel($script);
$this->addHasChildNode($script);
$this->addGetChildNodeAt($script);
$this->addGetFirstChildNode($script);
$this->addGetLastChildNode($script);
$this->addGetSiblingNode($script);
$this->addGetParentNode($script);
$this->addGetAncestors($script);
$this->addIsRootNode($script);
$this->addSetNew($script);
$this->addSetDeleted($script);
$this->addAddChildNode($script);
$this->addMoveChildNode($script);
$this->addSave($script);
$this->addDelete($script);
$this->addEquals($script);
$this->addAttachParentNode($script);
$this->addAttachChildNode($script);
$this->addDetachParentNode($script);
$this->addDetachChildNode($script);
$this->addShiftChildNodes($script);
$this->addInsertNewChildNode($script);
$this->addAdjustStatus($script);
$this->addAdjustNodePath($script);
} | php | protected function addClassBody(&$script)
{
$table = $this->getTable();
$this->addAttributes($script);
$this->addConstructor($script);
$this->addCallOverload($script);
$this->addSetIteratorOptions($script);
$this->addGetIterator($script);
$this->addGetNodeObj($script);
$this->addGetNodePath($script);
$this->addGetNodeIndex($script);
$this->addGetNodeLevel($script);
$this->addHasChildNode($script);
$this->addGetChildNodeAt($script);
$this->addGetFirstChildNode($script);
$this->addGetLastChildNode($script);
$this->addGetSiblingNode($script);
$this->addGetParentNode($script);
$this->addGetAncestors($script);
$this->addIsRootNode($script);
$this->addSetNew($script);
$this->addSetDeleted($script);
$this->addAddChildNode($script);
$this->addMoveChildNode($script);
$this->addSave($script);
$this->addDelete($script);
$this->addEquals($script);
$this->addAttachParentNode($script);
$this->addAttachChildNode($script);
$this->addDetachParentNode($script);
$this->addDetachChildNode($script);
$this->addShiftChildNodes($script);
$this->addInsertNewChildNode($script);
$this->addAdjustStatus($script);
$this->addAdjustNodePath($script);
} | [
"protected",
"function",
"addClassBody",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"this",
"->",
"addAttributes",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addConstructor",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addCallOverload",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetIteratorOptions",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetIterator",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetNodeObj",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetNodePath",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetNodeIndex",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetNodeLevel",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addHasChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetChildNodeAt",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetFirstChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetLastChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetSiblingNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetParentNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetAncestors",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addIsRootNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetNew",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetDeleted",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addAddChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addMoveChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSave",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDelete",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addEquals",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addAttachParentNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addAttachChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDetachParentNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDetachChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addShiftChildNodes",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInsertNewChildNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addAdjustStatus",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addAdjustNodePath",
"(",
"$",
"script",
")",
";",
"}"
] | Specifies the methods that are added as part of the basic OM class.
This can be overridden by subclasses that wish to add more methods.
@see ObjectBuilder::addClassBody() | [
"Specifies",
"the",
"methods",
"that",
"are",
"added",
"as",
"part",
"of",
"the",
"basic",
"OM",
"class",
".",
"This",
"can",
"be",
"overridden",
"by",
"subclasses",
"that",
"wish",
"to",
"add",
"more",
"methods",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5NodeBuilder.php#L93-L138 |
propelorm/Propel | generator/lib/builder/om/PHP5NodeBuilder.php | PHP5NodeBuilder.addConstructor | protected function addConstructor(&$script)
{
$script .= "
/**
* Constructor.
*
* @param " . $this->getStubObjectBuilder()->getClassname() . " \$obj Object wrapped by this node.
*/
public function __construct(\$obj = null)
{
if (\$obj !== null) {
\$this->obj = \$obj;
} else {
\$setNodePath = 'set' . " . $this->getStubNodePeerBuilder()->getClassname() . "::NPATH_PHPNAME;
\$this->obj = new " . $this->getStubObjectBuilder()->getClassname() . "();
\$this->obj->\$setNodePath('0');
}
}
";
} | php | protected function addConstructor(&$script)
{
$script .= "
/**
* Constructor.
*
* @param " . $this->getStubObjectBuilder()->getClassname() . " \$obj Object wrapped by this node.
*/
public function __construct(\$obj = null)
{
if (\$obj !== null) {
\$this->obj = \$obj;
} else {
\$setNodePath = 'set' . " . $this->getStubNodePeerBuilder()->getClassname() . "::NPATH_PHPNAME;
\$this->obj = new " . $this->getStubObjectBuilder()->getClassname() . "();
\$this->obj->\$setNodePath('0');
}
}
";
} | [
"protected",
"function",
"addConstructor",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"script",
".=",
"\"\n /**\n * Constructor.\n *\n * @param \"",
".",
"$",
"this",
"->",
"getStubObjectBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
".",
"\" \\$obj Object wrapped by this node.\n */\n public function __construct(\\$obj = null)\n {\n if (\\$obj !== null) {\n \\$this->obj = \\$obj;\n } else {\n \\$setNodePath = 'set' . \"",
".",
"$",
"this",
"->",
"getStubNodePeerBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
".",
"\"::NPATH_PHPNAME;\n \\$this->obj = new \"",
".",
"$",
"this",
"->",
"getStubObjectBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
".",
"\"();\n \\$this->obj->\\$setNodePath('0');\n }\n }\n\"",
";",
"}"
] | Adds the constructor.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"constructor",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5NodeBuilder.php#L184-L203 |
propelorm/Propel | runtime/lib/util/PropelDateTime.php | PropelDateTime.newInstance | public static function newInstance($value, DateTimeZone $timeZone = null, $dateTimeClass = 'DateTime')
{
if ($value instanceof DateTime) {
return $value;
}
if ($value === null || $value === '') {
// '' is seen as NULL for temporal objects
// because DateTime('') == DateTime('now') -- which is unexpected
return null;
}
try {
if (self::isTimestamp($value)) { // if it's a unix timestamp
$dateTimeObject = new $dateTimeClass('@' . $value, new DateTimeZone('UTC'));
// timezone must be explicitly specified and then changed
// because of a DateTime bug: http://bugs.php.net/bug.php?id=43003
$dateTimeObject->setTimeZone(new DateTimeZone(date_default_timezone_get()));
} else {
if ($timeZone === null) {
// stupid DateTime constructor signature
$dateTimeObject = new $dateTimeClass($value);
} else {
$dateTimeObject = new $dateTimeClass($value, $timeZone);
}
}
} catch (Exception $e) {
throw new PropelException('Error parsing date/time value: ' . var_export($value, true), $e);
}
return $dateTimeObject;
} | php | public static function newInstance($value, DateTimeZone $timeZone = null, $dateTimeClass = 'DateTime')
{
if ($value instanceof DateTime) {
return $value;
}
if ($value === null || $value === '') {
// '' is seen as NULL for temporal objects
// because DateTime('') == DateTime('now') -- which is unexpected
return null;
}
try {
if (self::isTimestamp($value)) { // if it's a unix timestamp
$dateTimeObject = new $dateTimeClass('@' . $value, new DateTimeZone('UTC'));
// timezone must be explicitly specified and then changed
// because of a DateTime bug: http://bugs.php.net/bug.php?id=43003
$dateTimeObject->setTimeZone(new DateTimeZone(date_default_timezone_get()));
} else {
if ($timeZone === null) {
// stupid DateTime constructor signature
$dateTimeObject = new $dateTimeClass($value);
} else {
$dateTimeObject = new $dateTimeClass($value, $timeZone);
}
}
} catch (Exception $e) {
throw new PropelException('Error parsing date/time value: ' . var_export($value, true), $e);
}
return $dateTimeObject;
} | [
"public",
"static",
"function",
"newInstance",
"(",
"$",
"value",
",",
"DateTimeZone",
"$",
"timeZone",
"=",
"null",
",",
"$",
"dateTimeClass",
"=",
"'DateTime'",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"DateTime",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"''",
")",
"{",
"// '' is seen as NULL for temporal objects",
"// because DateTime('') == DateTime('now') -- which is unexpected",
"return",
"null",
";",
"}",
"try",
"{",
"if",
"(",
"self",
"::",
"isTimestamp",
"(",
"$",
"value",
")",
")",
"{",
"// if it's a unix timestamp",
"$",
"dateTimeObject",
"=",
"new",
"$",
"dateTimeClass",
"(",
"'@'",
".",
"$",
"value",
",",
"new",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"// timezone must be explicitly specified and then changed",
"// because of a DateTime bug: http://bugs.php.net/bug.php?id=43003",
"$",
"dateTimeObject",
"->",
"setTimeZone",
"(",
"new",
"DateTimeZone",
"(",
"date_default_timezone_get",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"timeZone",
"===",
"null",
")",
"{",
"// stupid DateTime constructor signature",
"$",
"dateTimeObject",
"=",
"new",
"$",
"dateTimeClass",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"dateTimeObject",
"=",
"new",
"$",
"dateTimeClass",
"(",
"$",
"value",
",",
"$",
"timeZone",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"PropelException",
"(",
"'Error parsing date/time value: '",
".",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
",",
"$",
"e",
")",
";",
"}",
"return",
"$",
"dateTimeObject",
";",
"}"
] | Factory method to get a DateTime object from a temporal input
@param mixed $value The value to convert (can be a string, a timestamp, or another DateTime)
@param DateTimeZone $timeZone (optional) timezone
@param string $dateTimeClass The class of the object to create, defaults to DateTime
@return mixed null, or an instance of $dateTimeClass
@throws PropelException | [
"Factory",
"method",
"to",
"get",
"a",
"DateTime",
"object",
"from",
"a",
"temporal",
"input"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/util/PropelDateTime.php#L51-L80 |
propelorm/Propel | generator/lib/behavior/nestedset/NestedSetBehavior.php | NestedSetBehavior.modifyTable | public function modifyTable()
{
if (!$this->getTable()->containsColumn($this->getParameter('left_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('left_column'),
'type' => 'INTEGER'
));
}
if (!$this->getTable()->containsColumn($this->getParameter('right_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('right_column'),
'type' => 'INTEGER'
));
}
if (!$this->getTable()->containsColumn($this->getParameter('level_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('level_column'),
'type' => 'INTEGER'
));
}
if ($this->getParameter('use_scope') === 'true' &&
!$this->getTable()->containsColumn($this->getParameter('scope_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('scope_column'),
'type' => 'INTEGER'
));
}
} | php | public function modifyTable()
{
if (!$this->getTable()->containsColumn($this->getParameter('left_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('left_column'),
'type' => 'INTEGER'
));
}
if (!$this->getTable()->containsColumn($this->getParameter('right_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('right_column'),
'type' => 'INTEGER'
));
}
if (!$this->getTable()->containsColumn($this->getParameter('level_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('level_column'),
'type' => 'INTEGER'
));
}
if ($this->getParameter('use_scope') === 'true' &&
!$this->getTable()->containsColumn($this->getParameter('scope_column'))) {
$this->getTable()->addColumn(array(
'name' => $this->getParameter('scope_column'),
'type' => 'INTEGER'
));
}
} | [
"public",
"function",
"modifyTable",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"containsColumn",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'left_column'",
")",
")",
")",
"{",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"addColumn",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"getParameter",
"(",
"'left_column'",
")",
",",
"'type'",
"=>",
"'INTEGER'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"containsColumn",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'right_column'",
")",
")",
")",
"{",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"addColumn",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"getParameter",
"(",
"'right_column'",
")",
",",
"'type'",
"=>",
"'INTEGER'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"containsColumn",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'level_column'",
")",
")",
")",
"{",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"addColumn",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"getParameter",
"(",
"'level_column'",
")",
",",
"'type'",
"=>",
"'INTEGER'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'use_scope'",
")",
"===",
"'true'",
"&&",
"!",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"containsColumn",
"(",
"$",
"this",
"->",
"getParameter",
"(",
"'scope_column'",
")",
")",
")",
"{",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"addColumn",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"this",
"->",
"getParameter",
"(",
"'scope_column'",
")",
",",
"'type'",
"=>",
"'INTEGER'",
")",
")",
";",
"}",
"}"
] | Add the left, right and scope to the current table | [
"Add",
"the",
"left",
"right",
"and",
"scope",
"to",
"the",
"current",
"table"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/behavior/nestedset/NestedSetBehavior.php#L38-L65 |
propelorm/Propel | runtime/lib/validator/UniqueValidator.php | UniqueValidator.isValid | public function isValid(ValidatorMap $map, $str)
{
$column = $map->getColumn();
$c = new Criteria();
$c->add($column->getFullyQualifiedName(), $str, Criteria::EQUAL);
$table = $column->getTable()->getClassName();
$clazz = $table . 'Peer';
$count = call_user_func(array($clazz, 'doCount'), $c);
$isValid = ($count === 0);
return $isValid;
} | php | public function isValid(ValidatorMap $map, $str)
{
$column = $map->getColumn();
$c = new Criteria();
$c->add($column->getFullyQualifiedName(), $str, Criteria::EQUAL);
$table = $column->getTable()->getClassName();
$clazz = $table . 'Peer';
$count = call_user_func(array($clazz, 'doCount'), $c);
$isValid = ($count === 0);
return $isValid;
} | [
"public",
"function",
"isValid",
"(",
"ValidatorMap",
"$",
"map",
",",
"$",
"str",
")",
"{",
"$",
"column",
"=",
"$",
"map",
"->",
"getColumn",
"(",
")",
";",
"$",
"c",
"=",
"new",
"Criteria",
"(",
")",
";",
"$",
"c",
"->",
"add",
"(",
"$",
"column",
"->",
"getFullyQualifiedName",
"(",
")",
",",
"$",
"str",
",",
"Criteria",
"::",
"EQUAL",
")",
";",
"$",
"table",
"=",
"$",
"column",
"->",
"getTable",
"(",
")",
"->",
"getClassName",
"(",
")",
";",
"$",
"clazz",
"=",
"$",
"table",
".",
"'Peer'",
";",
"$",
"count",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"clazz",
",",
"'doCount'",
")",
",",
"$",
"c",
")",
";",
"$",
"isValid",
"=",
"(",
"$",
"count",
"===",
"0",
")",
";",
"return",
"$",
"isValid",
";",
"}"
] | @see BasicValidator::isValid()
@param ValidatorMap $map
@param string $str
@return boolean | [
"@see",
"BasicValidator",
"::",
"isValid",
"()"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/lib/validator/UniqueValidator.php#L36-L51 |
propelorm/Propel | generator/lib/builder/om/PHP5NestedSetBuilder.php | PHP5NestedSetBuilder.addClassBody | protected function addClassBody(&$script)
{
$table = $this->getTable();
$this->addAttributes($script);
$this->addGetIterator($script);
$this->addSave($script);
$this->addDelete($script);
$this->addMakeRoot($script);
$this->addGetLevel($script);
$this->addGetPath($script);
$this->addGetNumberOfChildren($script);
$this->addGetNumberOfDescendants($script);
$this->addGetChildren($script);
$this->addGetDescendants($script);
$this->addSetLevel($script);
$this->addSetChildren($script);
$this->addSetParentNode($script);
$this->addSetPrevSibling($script);
$this->addSetNextSibling($script);
$this->addIsRoot($script);
$this->addIsLeaf($script);
$this->addIsEqualTo($script);
$this->addHasParent($script);
$this->addHasChildren($script);
$this->addHasPrevSibling($script);
$this->addHasNextSibling($script);
$this->addRetrieveParent($script);
$this->addRetrieveFirstChild($script);
$this->addRetrieveLastChild($script);
$this->addRetrievePrevSibling($script);
$this->addRetrieveNextSibling($script);
$this->addInsertAsFirstChildOf($script);
$this->addInsertAsLastChildOf($script);
$this->addInsertAsPrevSiblingOf($script);
$this->addInsertAsNextSiblingOf($script);
$this->addMoveToFirstChildOf($script);
$this->addMoveToLastChildOf($script);
$this->addMoveToPrevSiblingOf($script);
$this->addMoveToNextSiblingOf($script);
$this->addInsertAsParentOf($script);
$this->addGetLeft($script);
$this->addGetRight($script);
$this->addGetScopeId($script);
$this->addSetLeft($script);
$this->addSetRight($script);
$this->addSetScopeId($script);
} | php | protected function addClassBody(&$script)
{
$table = $this->getTable();
$this->addAttributes($script);
$this->addGetIterator($script);
$this->addSave($script);
$this->addDelete($script);
$this->addMakeRoot($script);
$this->addGetLevel($script);
$this->addGetPath($script);
$this->addGetNumberOfChildren($script);
$this->addGetNumberOfDescendants($script);
$this->addGetChildren($script);
$this->addGetDescendants($script);
$this->addSetLevel($script);
$this->addSetChildren($script);
$this->addSetParentNode($script);
$this->addSetPrevSibling($script);
$this->addSetNextSibling($script);
$this->addIsRoot($script);
$this->addIsLeaf($script);
$this->addIsEqualTo($script);
$this->addHasParent($script);
$this->addHasChildren($script);
$this->addHasPrevSibling($script);
$this->addHasNextSibling($script);
$this->addRetrieveParent($script);
$this->addRetrieveFirstChild($script);
$this->addRetrieveLastChild($script);
$this->addRetrievePrevSibling($script);
$this->addRetrieveNextSibling($script);
$this->addInsertAsFirstChildOf($script);
$this->addInsertAsLastChildOf($script);
$this->addInsertAsPrevSiblingOf($script);
$this->addInsertAsNextSiblingOf($script);
$this->addMoveToFirstChildOf($script);
$this->addMoveToLastChildOf($script);
$this->addMoveToPrevSiblingOf($script);
$this->addMoveToNextSiblingOf($script);
$this->addInsertAsParentOf($script);
$this->addGetLeft($script);
$this->addGetRight($script);
$this->addGetScopeId($script);
$this->addSetLeft($script);
$this->addSetRight($script);
$this->addSetScopeId($script);
} | [
"protected",
"function",
"addClassBody",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"this",
"->",
"addAttributes",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetIterator",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSave",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDelete",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addMakeRoot",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetLevel",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetPath",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetNumberOfChildren",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetNumberOfDescendants",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetChildren",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetDescendants",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetLevel",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetChildren",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetParentNode",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetPrevSibling",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetNextSibling",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addIsRoot",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addIsLeaf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addIsEqualTo",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addHasParent",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addHasChildren",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addHasPrevSibling",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addHasNextSibling",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveParent",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveFirstChild",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveLastChild",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrievePrevSibling",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addRetrieveNextSibling",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInsertAsFirstChildOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInsertAsLastChildOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInsertAsPrevSiblingOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInsertAsNextSiblingOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addMoveToFirstChildOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addMoveToLastChildOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addMoveToPrevSiblingOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addMoveToNextSiblingOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInsertAsParentOf",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetLeft",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetRight",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addGetScopeId",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetLeft",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetRight",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addSetScopeId",
"(",
"$",
"script",
")",
";",
"}"
] | Specifies the methods that are added as part of the basic OM class.
This can be overridden by subclasses that wish to add more methods.
@see ObjectBuilder::addClassBody() | [
"Specifies",
"the",
"methods",
"that",
"are",
"added",
"as",
"part",
"of",
"the",
"basic",
"OM",
"class",
".",
"This",
"can",
"be",
"overridden",
"by",
"subclasses",
"that",
"wish",
"to",
"add",
"more",
"methods",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5NestedSetBuilder.php#L97-L162 |
propelorm/Propel | runtime/pear/BuildPropelPEARPackageTask.php | BuildPropelPEARPackageTask.main | public function main()
{
if ($this->dir === null) {
throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
}
if ($this->version === null) {
throw new BuildException("You must specify the \"version\" attribute for PEAR package task.");
}
$package = new PEAR_PackageFileManager2();
$this->setOptions($package);
// the hard-coded stuff
$package->setPackage('propel_runtime');
$package->setSummary('Runtime component of the Propel PHP object persistence layer');
$package->setDescription('Propel is an object persistence layer for PHP5 based on Apache Torque. This package provides the runtime engine that transparently handles object persistence and retrieval.');
$package->setChannel('pear.propelorm.org');
$package->setPackageType('php');
$package->setReleaseVersion($this->version);
$package->setAPIVersion($this->version);
$package->setReleaseStability($this->state);
$package->setAPIStability($this->state);
$package->setNotes($this->notes);
$package->setLicense('MIT', 'http://www.opensource.org/licenses/mit-license.php');
// Add package maintainers
$package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org');
$package->addMaintainer('lead', 'david', 'David Zuelke', 'dz@bitxtender.com');
$package->addMaintainer('lead', 'francois', 'Francois Zaninotto', 'fzaninotto@[gmail].com');
$package->addMaintainer('lead', 'couac', 'William Durand', 'william.durand1@[gmail].com');
// "core" dependencies
$package->setPhpDep('5.2.0');
$package->setPearinstallerDep('1.4.0');
// "package" dependencies
$package->addExtensionDep('required', 'pdo');
$package->addExtensionDep('required', 'spl');
// now we run this weird generateContents() method that apparently
// is necessary before we can add replacements ... ?
$package->generateContents();
$e = $package->writePackageFile();
if (PEAR::isError($e)) {
throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
}
} | php | public function main()
{
if ($this->dir === null) {
throw new BuildException("You must specify the \"dir\" attribute for PEAR package task.");
}
if ($this->version === null) {
throw new BuildException("You must specify the \"version\" attribute for PEAR package task.");
}
$package = new PEAR_PackageFileManager2();
$this->setOptions($package);
// the hard-coded stuff
$package->setPackage('propel_runtime');
$package->setSummary('Runtime component of the Propel PHP object persistence layer');
$package->setDescription('Propel is an object persistence layer for PHP5 based on Apache Torque. This package provides the runtime engine that transparently handles object persistence and retrieval.');
$package->setChannel('pear.propelorm.org');
$package->setPackageType('php');
$package->setReleaseVersion($this->version);
$package->setAPIVersion($this->version);
$package->setReleaseStability($this->state);
$package->setAPIStability($this->state);
$package->setNotes($this->notes);
$package->setLicense('MIT', 'http://www.opensource.org/licenses/mit-license.php');
// Add package maintainers
$package->addMaintainer('lead', 'hans', 'Hans Lellelid', 'hans@xmpl.org');
$package->addMaintainer('lead', 'david', 'David Zuelke', 'dz@bitxtender.com');
$package->addMaintainer('lead', 'francois', 'Francois Zaninotto', 'fzaninotto@[gmail].com');
$package->addMaintainer('lead', 'couac', 'William Durand', 'william.durand1@[gmail].com');
// "core" dependencies
$package->setPhpDep('5.2.0');
$package->setPearinstallerDep('1.4.0');
// "package" dependencies
$package->addExtensionDep('required', 'pdo');
$package->addExtensionDep('required', 'spl');
// now we run this weird generateContents() method that apparently
// is necessary before we can add replacements ... ?
$package->generateContents();
$e = $package->writePackageFile();
if (PEAR::isError($e)) {
throw new BuildException("Unable to write package file.", new Exception($e->getMessage()));
}
} | [
"public",
"function",
"main",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dir",
"===",
"null",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"You must specify the \\\"dir\\\" attribute for PEAR package task.\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"version",
"===",
"null",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"You must specify the \\\"version\\\" attribute for PEAR package task.\"",
")",
";",
"}",
"$",
"package",
"=",
"new",
"PEAR_PackageFileManager2",
"(",
")",
";",
"$",
"this",
"->",
"setOptions",
"(",
"$",
"package",
")",
";",
"// the hard-coded stuff",
"$",
"package",
"->",
"setPackage",
"(",
"'propel_runtime'",
")",
";",
"$",
"package",
"->",
"setSummary",
"(",
"'Runtime component of the Propel PHP object persistence layer'",
")",
";",
"$",
"package",
"->",
"setDescription",
"(",
"'Propel is an object persistence layer for PHP5 based on Apache Torque. This package provides the runtime engine that transparently handles object persistence and retrieval.'",
")",
";",
"$",
"package",
"->",
"setChannel",
"(",
"'pear.propelorm.org'",
")",
";",
"$",
"package",
"->",
"setPackageType",
"(",
"'php'",
")",
";",
"$",
"package",
"->",
"setReleaseVersion",
"(",
"$",
"this",
"->",
"version",
")",
";",
"$",
"package",
"->",
"setAPIVersion",
"(",
"$",
"this",
"->",
"version",
")",
";",
"$",
"package",
"->",
"setReleaseStability",
"(",
"$",
"this",
"->",
"state",
")",
";",
"$",
"package",
"->",
"setAPIStability",
"(",
"$",
"this",
"->",
"state",
")",
";",
"$",
"package",
"->",
"setNotes",
"(",
"$",
"this",
"->",
"notes",
")",
";",
"$",
"package",
"->",
"setLicense",
"(",
"'MIT'",
",",
"'http://www.opensource.org/licenses/mit-license.php'",
")",
";",
"// Add package maintainers",
"$",
"package",
"->",
"addMaintainer",
"(",
"'lead'",
",",
"'hans'",
",",
"'Hans Lellelid'",
",",
"'hans@xmpl.org'",
")",
";",
"$",
"package",
"->",
"addMaintainer",
"(",
"'lead'",
",",
"'david'",
",",
"'David Zuelke'",
",",
"'dz@bitxtender.com'",
")",
";",
"$",
"package",
"->",
"addMaintainer",
"(",
"'lead'",
",",
"'francois'",
",",
"'Francois Zaninotto'",
",",
"'fzaninotto@[gmail].com'",
")",
";",
"$",
"package",
"->",
"addMaintainer",
"(",
"'lead'",
",",
"'couac'",
",",
"'William Durand'",
",",
"'william.durand1@[gmail].com'",
")",
";",
"// \"core\" dependencies",
"$",
"package",
"->",
"setPhpDep",
"(",
"'5.2.0'",
")",
";",
"$",
"package",
"->",
"setPearinstallerDep",
"(",
"'1.4.0'",
")",
";",
"// \"package\" dependencies",
"$",
"package",
"->",
"addExtensionDep",
"(",
"'required'",
",",
"'pdo'",
")",
";",
"$",
"package",
"->",
"addExtensionDep",
"(",
"'required'",
",",
"'spl'",
")",
";",
"// now we run this weird generateContents() method that apparently",
"// is necessary before we can add replacements ... ?",
"$",
"package",
"->",
"generateContents",
"(",
")",
";",
"$",
"e",
"=",
"$",
"package",
"->",
"writePackageFile",
"(",
")",
";",
"if",
"(",
"PEAR",
"::",
"isError",
"(",
"$",
"e",
")",
")",
"{",
"throw",
"new",
"BuildException",
"(",
"\"Unable to write package file.\"",
",",
"new",
"Exception",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}"
] | Main entry point.
@return void
@throws BuildException | [
"Main",
"entry",
"point",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/runtime/pear/BuildPropelPEARPackageTask.php#L80-L134 |
propelorm/Propel | generator/lib/builder/om/ClassTools.php | ClassTools.getFilePath | public static function getFilePath($path, $classname = null, $extension = '.php')
{
$path = strtr(ltrim($path, '.'), '.', '/');
return self::createFilePath($path, $classname, $extension);
} | php | public static function getFilePath($path, $classname = null, $extension = '.php')
{
$path = strtr(ltrim($path, '.'), '.', '/');
return self::createFilePath($path, $classname, $extension);
} | [
"public",
"static",
"function",
"getFilePath",
"(",
"$",
"path",
",",
"$",
"classname",
"=",
"null",
",",
"$",
"extension",
"=",
"'.php'",
")",
"{",
"$",
"path",
"=",
"strtr",
"(",
"ltrim",
"(",
"$",
"path",
",",
"'.'",
")",
",",
"'.'",
",",
"'/'",
")",
";",
"return",
"self",
"::",
"createFilePath",
"(",
"$",
"path",
",",
"$",
"classname",
",",
"$",
"extension",
")",
";",
"}"
] | Gets the path to be used in include()/require() statement.
Supports multiple function signatures:
(1) getFilePath($dotPathClass);
(2) getFilePath($dotPathPrefix, $className);
(3) getFilePath($dotPathPrefix, $className, $extension);
@param string $path dot-path to class or to package prefix.
@param string $classname class name
@param string $extension The extension to use on the file.
@return string The constructed file path. | [
"Gets",
"the",
"path",
"to",
"be",
"used",
"in",
"include",
"()",
"/",
"require",
"()",
"statement",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/ClassTools.php#L54-L59 |
propelorm/Propel | generator/lib/builder/om/ClassTools.php | ClassTools.createFilePath | public static function createFilePath($path, $classname = null, $extension = '.php')
{
if ($classname !== null) {
if ($path !== '') {
$path .= '/';
}
return $path . $classname . $extension;
} else {
return $path . $extension;
}
} | php | public static function createFilePath($path, $classname = null, $extension = '.php')
{
if ($classname !== null) {
if ($path !== '') {
$path .= '/';
}
return $path . $classname . $extension;
} else {
return $path . $extension;
}
} | [
"public",
"static",
"function",
"createFilePath",
"(",
"$",
"path",
",",
"$",
"classname",
"=",
"null",
",",
"$",
"extension",
"=",
"'.php'",
")",
"{",
"if",
"(",
"$",
"classname",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"!==",
"''",
")",
"{",
"$",
"path",
".=",
"'/'",
";",
"}",
"return",
"$",
"path",
".",
"$",
"classname",
".",
"$",
"extension",
";",
"}",
"else",
"{",
"return",
"$",
"path",
".",
"$",
"extension",
";",
"}",
"}"
] | This method replaces the `getFilePath()` method in OMBuilder as we consider `$path` as
a real path instead of a dot-notation value. `$path` is generated by the `getPackagePath()`
method.
@param string $path path to class or to package prefix.
@param string $classname class name
@param string $extension The extension to use on the file.
@return string The constructed file path. | [
"This",
"method",
"replaces",
"the",
"getFilePath",
"()",
"method",
"in",
"OMBuilder",
"as",
"we",
"consider",
"$path",
"as",
"a",
"real",
"path",
"instead",
"of",
"a",
"dot",
"-",
"notation",
"value",
".",
"$path",
"is",
"generated",
"by",
"the",
"getPackagePath",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/ClassTools.php#L72-L83 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.validateModel | protected function validateModel()
{
parent::validateModel();
$table = $this->getTable();
// Check to see if any of the column constants are PHP reserved words.
$colConstants = array();
foreach ($table->getColumns() as $col) {
$colConstants[] = $this->getColumnName($col);
}
$reservedConstants = array_map('strtoupper', ClassTools::getPhpReservedWords());
$intersect = array_intersect($reservedConstants, $colConstants);
if (!empty($intersect)) {
throw new EngineException("One or more of your column names for [" . $table->getName() . "] table conflict with a PHP reserved word (" . implode(", ", $intersect) . ")");
}
} | php | protected function validateModel()
{
parent::validateModel();
$table = $this->getTable();
// Check to see if any of the column constants are PHP reserved words.
$colConstants = array();
foreach ($table->getColumns() as $col) {
$colConstants[] = $this->getColumnName($col);
}
$reservedConstants = array_map('strtoupper', ClassTools::getPhpReservedWords());
$intersect = array_intersect($reservedConstants, $colConstants);
if (!empty($intersect)) {
throw new EngineException("One or more of your column names for [" . $table->getName() . "] table conflict with a PHP reserved word (" . implode(", ", $intersect) . ")");
}
} | [
"protected",
"function",
"validateModel",
"(",
")",
"{",
"parent",
"::",
"validateModel",
"(",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"// Check to see if any of the column constants are PHP reserved words.",
"$",
"colConstants",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"$",
"colConstants",
"[",
"]",
"=",
"$",
"this",
"->",
"getColumnName",
"(",
"$",
"col",
")",
";",
"}",
"$",
"reservedConstants",
"=",
"array_map",
"(",
"'strtoupper'",
",",
"ClassTools",
"::",
"getPhpReservedWords",
"(",
")",
")",
";",
"$",
"intersect",
"=",
"array_intersect",
"(",
"$",
"reservedConstants",
",",
"$",
"colConstants",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"intersect",
")",
")",
"{",
"throw",
"new",
"EngineException",
"(",
"\"One or more of your column names for [\"",
".",
"$",
"table",
"->",
"getName",
"(",
")",
".",
"\"] table conflict with a PHP reserved word (\"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"intersect",
")",
".",
"\")\"",
")",
";",
"}",
"}"
] | Validates the current table to make sure that it won't
result in generated code that will not parse.
This method may emit warnings for code which may cause problems
and will throw exceptions for errors that will definitely cause
problems. | [
"Validates",
"the",
"current",
"table",
"to",
"make",
"sure",
"that",
"it",
"won",
"t",
"result",
"in",
"generated",
"code",
"that",
"will",
"not",
"parse",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L34-L53 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addClassOpen | protected function addClassOpen(&$script)
{
$tableName = $this->getTable()->getName();
$tableDesc = $this->getTable()->getDescription();
if ($this->getBuildProperty('addClassLevelComment')) {
$script .= "
/**
* Base static class for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* @package propel.generator." . $this->getPackage() . "
*/";
}
$extendingPeerClass = '';
$parentClass = $this->getBehaviorContent('parentClass');
if (null !== $parentClass) {
$extendingPeerClass = ' extends ' . $parentClass;
}
$script .= "
abstract class " . $this->getClassname() . $extendingPeerClass . "
{
";
} | php | protected function addClassOpen(&$script)
{
$tableName = $this->getTable()->getName();
$tableDesc = $this->getTable()->getDescription();
if ($this->getBuildProperty('addClassLevelComment')) {
$script .= "
/**
* Base static class for performing query and update operations on the '$tableName' table.
*
* $tableDesc
*";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "
* This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:
*
* $now
*";
}
$script .= "
* @package propel.generator." . $this->getPackage() . "
*/";
}
$extendingPeerClass = '';
$parentClass = $this->getBehaviorContent('parentClass');
if (null !== $parentClass) {
$extendingPeerClass = ' extends ' . $parentClass;
}
$script .= "
abstract class " . $this->getClassname() . $extendingPeerClass . "
{
";
} | [
"protected",
"function",
"addClassOpen",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"tableName",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"tableDesc",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getDescription",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getBuildProperty",
"(",
"'addClassLevelComment'",
")",
")",
"{",
"$",
"script",
".=",
"\"\n/**\n * Base static class for performing query and update operations on 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 *\"",
";",
"}",
"$",
"script",
".=",
"\"\n * @package propel.generator.\"",
".",
"$",
"this",
"->",
"getPackage",
"(",
")",
".",
"\"\n */\"",
";",
"}",
"$",
"extendingPeerClass",
"=",
"''",
";",
"$",
"parentClass",
"=",
"$",
"this",
"->",
"getBehaviorContent",
"(",
"'parentClass'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"parentClass",
")",
"{",
"$",
"extendingPeerClass",
"=",
"' extends '",
".",
"$",
"parentClass",
";",
"}",
"$",
"script",
".=",
"\"\nabstract class \"",
".",
"$",
"this",
"->",
"getClassname",
"(",
")",
".",
"$",
"extendingPeerClass",
".",
"\"\n{\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/PHP5PeerBuilder.php#L100-L136 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addClassClose | protected function addClassClose(&$script)
{
// apply behaviors
$this->applyBehaviorModifier('staticMethods', $script, " ");
$script .= "
} // " . $this->getClassname() . "
";
$this->addStaticTableMapRegistration($script);
} | php | protected function addClassClose(&$script)
{
// apply behaviors
$this->applyBehaviorModifier('staticMethods', $script, " ");
$script .= "
} // " . $this->getClassname() . "
";
$this->addStaticTableMapRegistration($script);
} | [
"protected",
"function",
"addClassClose",
"(",
"&",
"$",
"script",
")",
"{",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'staticMethods'",
",",
"$",
"script",
",",
"\"\t\"",
")",
";",
"$",
"script",
".=",
"\"\n} // \"",
".",
"$",
"this",
"->",
"getClassname",
"(",
")",
".",
"\"\n\"",
";",
"$",
"this",
"->",
"addStaticTableMapRegistration",
"(",
"$",
"script",
")",
";",
"}"
] | Closes class.
Adds closing brace at end of class and the static map builder registration code.
@param string &$script The script will be modified in this method.
@see addStaticTableMapRegistration() | [
"Closes",
"class",
".",
"Adds",
"closing",
"brace",
"at",
"end",
"of",
"class",
"and",
"the",
"static",
"map",
"builder",
"registration",
"code",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L154-L163 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addStaticTableMapRegistration | protected function addStaticTableMapRegistration(&$script)
{
$table = $this->getTable();
$script .= "
// This is the static code needed to register the TableMap for this table with the main Propel class.
//
" . $this->getClassName() . "::buildTableMap();
";
$this->applyBehaviorModifier('peerFilter', $script, "");
} | php | protected function addStaticTableMapRegistration(&$script)
{
$table = $this->getTable();
$script .= "
// This is the static code needed to register the TableMap for this table with the main Propel class.
//
" . $this->getClassName() . "::buildTableMap();
";
$this->applyBehaviorModifier('peerFilter', $script, "");
} | [
"protected",
"function",
"addStaticTableMapRegistration",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n// This is the static code needed to register the TableMap for this table with the main Propel class.\n//\n\"",
".",
"$",
"this",
"->",
"getClassName",
"(",
")",
".",
"\"::buildTableMap();\n\n\"",
";",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'peerFilter'",
",",
"$",
"script",
",",
"\"\"",
")",
";",
"}"
] | Adds the static map builder registration code.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"static",
"map",
"builder",
"registration",
"code",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L170-L181 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addConstantsAndAttributes | protected function addConstantsAndAttributes(&$script)
{
$dbName = $this->getDatabase()->getName();
$tableName = $this->getTable()->getName();
$tablePhpName = $this->getTable()->isAbstract() ? '' : addslashes($this->getStubObjectBuilder()->getFullyQualifiedClassname());
$script .= "
/** the default database name for this class */
const DATABASE_NAME = '$dbName';
/** the table name for this class */
const TABLE_NAME = '$tableName';
/** the related Propel class for this table */
const OM_CLASS = '$tablePhpName';
/** the related TableMap class for this table */
const TM_CLASS = '" . addslashes($this->getTableMapClass()) . "';
/** The total number of columns. */
const NUM_COLUMNS = " . $this->getTable()->getNumColumns() . ";
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = " . $this->getTable()->getNumLazyLoadColumns() . ";
/** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
const NUM_HYDRATE_COLUMNS = " . ($this->getTable()->getNumColumns() - $this->getTable()->getNumLazyLoadColumns()) . ";
";
$this->addColumnNameConstants($script);
$this->addInheritanceColumnConstants($script);
if ($this->getTable()->hasEnumColumns()) {
$this->addEnumColumnConstants($script);
}
$script .= "
/** The default string format for model objects of the related table **/
const DEFAULT_STRING_FORMAT = '" . $this->getTable()->getDefaultStringFormat() . "';
/**
* An identity map to hold any loaded instances of " . $this->getObjectClassname() . " objects.
* This must be public so that other peer classes can access this when hydrating from JOIN
* queries.
* @var array " . $this->getObjectClassname() . "[]
*/
public static \$instances = array();
";
// apply behaviors
$this->applyBehaviorModifier('staticConstants', $script, " ");
$this->applyBehaviorModifier('staticAttributes', $script, " ");
$this->addFieldNamesAttribute($script);
$this->addFieldKeysAttribute($script);
if ($this->getTable()->hasEnumColumns()) {
$this->addEnumColumnAttributes($script);
}
} | php | protected function addConstantsAndAttributes(&$script)
{
$dbName = $this->getDatabase()->getName();
$tableName = $this->getTable()->getName();
$tablePhpName = $this->getTable()->isAbstract() ? '' : addslashes($this->getStubObjectBuilder()->getFullyQualifiedClassname());
$script .= "
/** the default database name for this class */
const DATABASE_NAME = '$dbName';
/** the table name for this class */
const TABLE_NAME = '$tableName';
/** the related Propel class for this table */
const OM_CLASS = '$tablePhpName';
/** the related TableMap class for this table */
const TM_CLASS = '" . addslashes($this->getTableMapClass()) . "';
/** The total number of columns. */
const NUM_COLUMNS = " . $this->getTable()->getNumColumns() . ";
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = " . $this->getTable()->getNumLazyLoadColumns() . ";
/** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
const NUM_HYDRATE_COLUMNS = " . ($this->getTable()->getNumColumns() - $this->getTable()->getNumLazyLoadColumns()) . ";
";
$this->addColumnNameConstants($script);
$this->addInheritanceColumnConstants($script);
if ($this->getTable()->hasEnumColumns()) {
$this->addEnumColumnConstants($script);
}
$script .= "
/** The default string format for model objects of the related table **/
const DEFAULT_STRING_FORMAT = '" . $this->getTable()->getDefaultStringFormat() . "';
/**
* An identity map to hold any loaded instances of " . $this->getObjectClassname() . " objects.
* This must be public so that other peer classes can access this when hydrating from JOIN
* queries.
* @var array " . $this->getObjectClassname() . "[]
*/
public static \$instances = array();
";
// apply behaviors
$this->applyBehaviorModifier('staticConstants', $script, " ");
$this->applyBehaviorModifier('staticAttributes', $script, " ");
$this->addFieldNamesAttribute($script);
$this->addFieldKeysAttribute($script);
if ($this->getTable()->hasEnumColumns()) {
$this->addEnumColumnAttributes($script);
}
} | [
"protected",
"function",
"addConstantsAndAttributes",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"dbName",
"=",
"$",
"this",
"->",
"getDatabase",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"tableName",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"tablePhpName",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"isAbstract",
"(",
")",
"?",
"''",
":",
"addslashes",
"(",
"$",
"this",
"->",
"getStubObjectBuilder",
"(",
")",
"->",
"getFullyQualifiedClassname",
"(",
")",
")",
";",
"$",
"script",
".=",
"\"\n /** the default database name for this class */\n const DATABASE_NAME = '$dbName';\n\n /** the table name for this class */\n const TABLE_NAME = '$tableName';\n\n /** the related Propel class for this table */\n const OM_CLASS = '$tablePhpName';\n\n /** the related TableMap class for this table */\n const TM_CLASS = '\"",
".",
"addslashes",
"(",
"$",
"this",
"->",
"getTableMapClass",
"(",
")",
")",
".",
"\"';\n\n /** The total number of columns. */\n const NUM_COLUMNS = \"",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getNumColumns",
"(",
")",
".",
"\";\n\n /** The number of lazy-loaded columns. */\n const NUM_LAZY_LOAD_COLUMNS = \"",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getNumLazyLoadColumns",
"(",
")",
".",
"\";\n\n /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */\n const NUM_HYDRATE_COLUMNS = \"",
".",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getNumColumns",
"(",
")",
"-",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getNumLazyLoadColumns",
"(",
")",
")",
".",
"\";\n\"",
";",
"$",
"this",
"->",
"addColumnNameConstants",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addInheritanceColumnConstants",
"(",
"$",
"script",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"hasEnumColumns",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addEnumColumnConstants",
"(",
"$",
"script",
")",
";",
"}",
"$",
"script",
".=",
"\"\n /** The default string format for model objects of the related table **/\n const DEFAULT_STRING_FORMAT = '\"",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getDefaultStringFormat",
"(",
")",
".",
"\"';\n\n /**\n * An identity map to hold any loaded instances of \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" objects.\n * This must be public so that other peer classes can access this when hydrating from JOIN\n * queries.\n * @var array \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\"[]\n */\n public static \\$instances = array();\n\n\"",
";",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'staticConstants'",
",",
"$",
"script",
",",
"\"\t\"",
")",
";",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'staticAttributes'",
",",
"$",
"script",
",",
"\"\t\"",
")",
";",
"$",
"this",
"->",
"addFieldNamesAttribute",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addFieldKeysAttribute",
"(",
"$",
"script",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"hasEnumColumns",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addEnumColumnAttributes",
"(",
"$",
"script",
")",
";",
"}",
"}"
] | Adds constant and variable declarations that go at the top of the class.
@param string &$script The script will be modified in this method.
@see addColumnNameConstants() | [
"Adds",
"constant",
"and",
"variable",
"declarations",
"that",
"go",
"at",
"the",
"top",
"of",
"the",
"class",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L207-L264 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addEnumColumnConstants | protected function addEnumColumnConstants(&$script)
{
foreach ($this->getTable()->getColumns() as $col) {
if ($col->isEnumType() || $col->getValueSet()) {
$script .= "
/** The enumerated values for the " . $col->getName() . " field */";
foreach ($col->getValueSet() as $value) {
$script .= "
const " . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . " = '" . $value . "';";
}
$script .= "
";
}
}
} | php | protected function addEnumColumnConstants(&$script)
{
foreach ($this->getTable()->getColumns() as $col) {
if ($col->isEnumType() || $col->getValueSet()) {
$script .= "
/** The enumerated values for the " . $col->getName() . " field */";
foreach ($col->getValueSet() as $value) {
$script .= "
const " . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . " = '" . $value . "';";
}
$script .= "
";
}
}
} | [
"protected",
"function",
"addEnumColumnConstants",
"(",
"&",
"$",
"script",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"$",
"col",
"->",
"isEnumType",
"(",
")",
"||",
"$",
"col",
"->",
"getValueSet",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n /** The enumerated values for the \"",
".",
"$",
"col",
"->",
"getName",
"(",
")",
".",
"\" field */\"",
";",
"foreach",
"(",
"$",
"col",
"->",
"getValueSet",
"(",
")",
"as",
"$",
"value",
")",
"{",
"$",
"script",
".=",
"\"\n const \"",
".",
"$",
"this",
"->",
"getColumnName",
"(",
"$",
"col",
")",
".",
"'_'",
".",
"$",
"this",
"->",
"getEnumValueConstant",
"(",
"$",
"value",
")",
".",
"\" = '\"",
".",
"$",
"value",
".",
"\"';\"",
";",
"}",
"$",
"script",
".=",
"\"\n\"",
";",
"}",
"}",
"}"
] | Adds the valueSet constants for ENUM columns.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"valueSet",
"constants",
"for",
"ENUM",
"columns",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L286-L300 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addEnumColumnAttributes | protected function addEnumColumnAttributes(&$script)
{
$script .= "
/** The enumerated values for this table */
protected static \$enumValueSets = array(";
foreach ($this->getTable()->getColumns() as $col) {
if ($col->isEnumType() || $col->getValueSet()) {
$script .= "
" . $this->getPeerClassname() . "::" . $this->getColumnName($col) . " => array(
";
foreach ($col->getValueSet() as $value) {
$script .= " " . $this->getStubPeerBuilder()->getClassname() . '::' . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . ",
";
}
$script .= " ),";
}
}
$script .= "
);
";
} | php | protected function addEnumColumnAttributes(&$script)
{
$script .= "
/** The enumerated values for this table */
protected static \$enumValueSets = array(";
foreach ($this->getTable()->getColumns() as $col) {
if ($col->isEnumType() || $col->getValueSet()) {
$script .= "
" . $this->getPeerClassname() . "::" . $this->getColumnName($col) . " => array(
";
foreach ($col->getValueSet() as $value) {
$script .= " " . $this->getStubPeerBuilder()->getClassname() . '::' . $this->getColumnName($col) . '_' . $this->getEnumValueConstant($value) . ",
";
}
$script .= " ),";
}
}
$script .= "
);
";
} | [
"protected",
"function",
"addEnumColumnAttributes",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"script",
".=",
"\"\n /** The enumerated values for this table */\n protected static \\$enumValueSets = array(\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"$",
"col",
"->",
"isEnumType",
"(",
")",
"||",
"$",
"col",
"->",
"getValueSet",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::\"",
".",
"$",
"this",
"->",
"getColumnName",
"(",
"$",
"col",
")",
".",
"\" => array(\n\"",
";",
"foreach",
"(",
"$",
"col",
"->",
"getValueSet",
"(",
")",
"as",
"$",
"value",
")",
"{",
"$",
"script",
".=",
"\"\t\t\t\"",
".",
"$",
"this",
"->",
"getStubPeerBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
".",
"'::'",
".",
"$",
"this",
"->",
"getColumnName",
"(",
"$",
"col",
")",
".",
"'_'",
".",
"$",
"this",
"->",
"getEnumValueConstant",
"(",
"$",
"value",
")",
".",
"\",\n\"",
";",
"}",
"$",
"script",
".=",
"\"\t\t),\"",
";",
"}",
"}",
"$",
"script",
".=",
"\"\n );\n\"",
";",
"}"
] | Adds the valueSet attributes for ENUM columns.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"valueSet",
"attributes",
"for",
"ENUM",
"columns",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L408-L428 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addTranslateFieldName | protected function addTranslateFieldName(&$script)
{
$script .= "
/**
* Translates a fieldname to another type
*
* @param string \$name field name
* @param string \$fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
* BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
* @param string \$toType One of the class type constants
* @return string translated name of the field.
* @throws PropelException - if the specified name could not be found in the fieldname mappings.
*/
public static function translateFieldName(\$name, \$fromType, \$toType)
{
\$toNames = " . $this->getPeerClassname() . "::getFieldNames(\$toType);
\$key = isset(" . $this->getPeerClassname() . "::\$fieldKeys[\$fromType][\$name]) ? " . $this->getPeerClassname() . "::\$fieldKeys[\$fromType][\$name] : null;
if (\$key === null) {
throw new PropelException(\"'\$name' could not be found in the field names of type '\$fromType'. These are: \" . print_r(" . $this->getPeerClassname() . "::\$fieldKeys[\$fromType], true));
}
return \$toNames[\$key];
}
";
} | php | protected function addTranslateFieldName(&$script)
{
$script .= "
/**
* Translates a fieldname to another type
*
* @param string \$name field name
* @param string \$fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
* BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
* @param string \$toType One of the class type constants
* @return string translated name of the field.
* @throws PropelException - if the specified name could not be found in the fieldname mappings.
*/
public static function translateFieldName(\$name, \$fromType, \$toType)
{
\$toNames = " . $this->getPeerClassname() . "::getFieldNames(\$toType);
\$key = isset(" . $this->getPeerClassname() . "::\$fieldKeys[\$fromType][\$name]) ? " . $this->getPeerClassname() . "::\$fieldKeys[\$fromType][\$name] : null;
if (\$key === null) {
throw new PropelException(\"'\$name' could not be found in the field names of type '\$fromType'. These are: \" . print_r(" . $this->getPeerClassname() . "::\$fieldKeys[\$fromType], true));
}
return \$toNames[\$key];
}
";
} | [
"protected",
"function",
"addTranslateFieldName",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"script",
".=",
"\"\n /**\n * Translates a fieldname to another type\n *\n * @param string \\$name field name\n * @param string \\$fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME\n * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM\n * @param string \\$toType One of the class type constants\n * @return string translated name of the field.\n * @throws PropelException - if the specified name could not be found in the fieldname mappings.\n */\n public static function translateFieldName(\\$name, \\$fromType, \\$toType)\n {\n \\$toNames = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getFieldNames(\\$toType);\n \\$key = isset(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::\\$fieldKeys[\\$fromType][\\$name]) ? \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::\\$fieldKeys[\\$fromType][\\$name] : null;\n if (\\$key === null) {\n throw new PropelException(\\\"'\\$name' could not be found in the field names of type '\\$fromType'. These are: \\\" . print_r(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::\\$fieldKeys[\\$fromType], true));\n }\n\n return \\$toNames[\\$key];\n }\n\"",
";",
"}"
] | addGetFieldNames() | [
"addGetFieldNames",
"()"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L453-L477 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addGetValueSets | protected function addGetValueSets(&$script)
{
$this->declareClassFromBuilder($this->getTableMapBuilder());
$callingClass = $this->getStubPeerBuilder()->getClassname();
$script .= "
/**
* Gets the list of values for all ENUM columns
* @return array
*/
public static function getValueSets()
{
return {$callingClass}::\$enumValueSets;
}
";
} | php | protected function addGetValueSets(&$script)
{
$this->declareClassFromBuilder($this->getTableMapBuilder());
$callingClass = $this->getStubPeerBuilder()->getClassname();
$script .= "
/**
* Gets the list of values for all ENUM columns
* @return array
*/
public static function getValueSets()
{
return {$callingClass}::\$enumValueSets;
}
";
} | [
"protected",
"function",
"addGetValueSets",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"this",
"->",
"declareClassFromBuilder",
"(",
"$",
"this",
"->",
"getTableMapBuilder",
"(",
")",
")",
";",
"$",
"callingClass",
"=",
"$",
"this",
"->",
"getStubPeerBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Gets the list of values for all ENUM columns\n * @return array\n */\n public static function getValueSets()\n {\n return {$callingClass}::\\$enumValueSets;\n }\n\"",
";",
"}"
] | Adds the getValueSets() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"getValueSets",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L484-L498 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addEnumMethods | protected function addEnumMethods(&$script)
{
foreach ($this->getTable()->getColumns() as $col) {
/* @var $col Column */
if ($col->isEnumType()) {
$script .= "
/**
* Gets the SQL value for " . $col->getPhpName() . " ENUM value
*
* @param string \$enumVal ENUM value to get SQL value for
* @return int SQL value
*/
public static function get{$col->getPhpName()}SqlValue(\$enumVal)
{
return {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$enumVal);
}
";
}
}
} | php | protected function addEnumMethods(&$script)
{
foreach ($this->getTable()->getColumns() as $col) {
/* @var $col Column */
if ($col->isEnumType()) {
$script .= "
/**
* Gets the SQL value for " . $col->getPhpName() . " ENUM value
*
* @param string \$enumVal ENUM value to get SQL value for
* @return int SQL value
*/
public static function get{$col->getPhpName()}SqlValue(\$enumVal)
{
return {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \$enumVal);
}
";
}
}
} | [
"protected",
"function",
"addEnumMethods",
"(",
"&",
"$",
"script",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"/* @var $col Column */",
"if",
"(",
"$",
"col",
"->",
"isEnumType",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n /**\n * Gets the SQL value for \"",
".",
"$",
"col",
"->",
"getPhpName",
"(",
")",
".",
"\" ENUM value\n *\n * @param string \\$enumVal ENUM value to get SQL value for\n * @return int SQL value\n */\n public static function get{$col->getPhpName()}SqlValue(\\$enumVal)\n {\n return {$this->getPeerClassname()}::getSqlValueForEnum({$this->getColumnConstant($col)}, \\$enumVal);\n }\n\"",
";",
"}",
"}",
"}"
] | Adds methods for ENUM columns.
@param string &$script The script will be modified in this method. | [
"Adds",
"methods",
"for",
"ENUM",
"columns",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L563-L582 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addBuildTableMap | protected function addBuildTableMap(&$script)
{
$this->declareClassFromBuilder($this->getTableMapBuilder());
$script .= "
/**
* Add a TableMap instance to the database for this peer class.
*/
public static function buildTableMap()
{
\$dbMap = Propel::getDatabaseMap(" . $this->getClassname() . "::DATABASE_NAME);
if (!\$dbMap->hasTable(" . $this->getClassname() . "::TABLE_NAME)) {
\$dbMap->addTableObject(new \\" . $this->getTableMapClass() . "());
}
}
";
} | php | protected function addBuildTableMap(&$script)
{
$this->declareClassFromBuilder($this->getTableMapBuilder());
$script .= "
/**
* Add a TableMap instance to the database for this peer class.
*/
public static function buildTableMap()
{
\$dbMap = Propel::getDatabaseMap(" . $this->getClassname() . "::DATABASE_NAME);
if (!\$dbMap->hasTable(" . $this->getClassname() . "::TABLE_NAME)) {
\$dbMap->addTableObject(new \\" . $this->getTableMapClass() . "());
}
}
";
} | [
"protected",
"function",
"addBuildTableMap",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"this",
"->",
"declareClassFromBuilder",
"(",
"$",
"this",
"->",
"getTableMapBuilder",
"(",
")",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Add a TableMap instance to the database for this peer class.\n */\n public static function buildTableMap()\n {\n \\$dbMap = Propel::getDatabaseMap(\"",
".",
"$",
"this",
"->",
"getClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n if (!\\$dbMap->hasTable(\"",
".",
"$",
"this",
"->",
"getClassname",
"(",
")",
".",
"\"::TABLE_NAME)) {\n \\$dbMap->addTableObject(new \\\\\"",
".",
"$",
"this",
"->",
"getTableMapClass",
"(",
")",
".",
"\"());\n }\n }\n\"",
";",
"}"
] | Adds the buildTableMap() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"buildTableMap",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L589-L604 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addInheritanceColumnConstants | public function addInheritanceColumnConstants(&$script)
{
if ($this->getTable()->getChildrenColumn()) {
$col = $this->getTable()->getChildrenColumn();
$cfc = $col->getPhpName();
if ($col->isEnumeratedClasses()) {
if ($col->isPhpPrimitiveNumericType()) {
$quote = "";
} else {
$quote = '"';
}
foreach ($col->getChildren() as $child) {
$childBuilder = $this->getMultiExtendObjectBuilder();
$childBuilder->setChild($child);
$fqcn = addslashes($childBuilder->getFullyQualifiedClassname());
$script .= "
/** A key representing a particular subclass */
const CLASSKEY_" . strtoupper($child->getKey()) . " = '" . $child->getKey() . "';
";
if (strtoupper($child->getClassname()) != strtoupper($child->getKey())) {
$script .= "
/** A key representing a particular subclass */
const CLASSKEY_" . strtoupper($child->getClassname()) . " = '" . $child->getKey() . "';
";
}
$script .= "
/** A class that can be returned by this peer. */
const CLASSNAME_" . strtoupper($child->getKey()) . " = '" . $fqcn . "';
";
} /* foreach children */
} /* if col->isenumerated...() */
} /* if table->getchildrencolumn() */
} | php | public function addInheritanceColumnConstants(&$script)
{
if ($this->getTable()->getChildrenColumn()) {
$col = $this->getTable()->getChildrenColumn();
$cfc = $col->getPhpName();
if ($col->isEnumeratedClasses()) {
if ($col->isPhpPrimitiveNumericType()) {
$quote = "";
} else {
$quote = '"';
}
foreach ($col->getChildren() as $child) {
$childBuilder = $this->getMultiExtendObjectBuilder();
$childBuilder->setChild($child);
$fqcn = addslashes($childBuilder->getFullyQualifiedClassname());
$script .= "
/** A key representing a particular subclass */
const CLASSKEY_" . strtoupper($child->getKey()) . " = '" . $child->getKey() . "';
";
if (strtoupper($child->getClassname()) != strtoupper($child->getKey())) {
$script .= "
/** A key representing a particular subclass */
const CLASSKEY_" . strtoupper($child->getClassname()) . " = '" . $child->getKey() . "';
";
}
$script .= "
/** A class that can be returned by this peer. */
const CLASSNAME_" . strtoupper($child->getKey()) . " = '" . $fqcn . "';
";
} /* foreach children */
} /* if col->isenumerated...() */
} /* if table->getchildrencolumn() */
} | [
"public",
"function",
"addInheritanceColumnConstants",
"(",
"&",
"$",
"script",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"col",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getChildrenColumn",
"(",
")",
";",
"$",
"cfc",
"=",
"$",
"col",
"->",
"getPhpName",
"(",
")",
";",
"if",
"(",
"$",
"col",
"->",
"isEnumeratedClasses",
"(",
")",
")",
"{",
"if",
"(",
"$",
"col",
"->",
"isPhpPrimitiveNumericType",
"(",
")",
")",
"{",
"$",
"quote",
"=",
"\"\"",
";",
"}",
"else",
"{",
"$",
"quote",
"=",
"'\"'",
";",
"}",
"foreach",
"(",
"$",
"col",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"childBuilder",
"=",
"$",
"this",
"->",
"getMultiExtendObjectBuilder",
"(",
")",
";",
"$",
"childBuilder",
"->",
"setChild",
"(",
"$",
"child",
")",
";",
"$",
"fqcn",
"=",
"addslashes",
"(",
"$",
"childBuilder",
"->",
"getFullyQualifiedClassname",
"(",
")",
")",
";",
"$",
"script",
".=",
"\"\n /** A key representing a particular subclass */\n const CLASSKEY_\"",
".",
"strtoupper",
"(",
"$",
"child",
"->",
"getKey",
"(",
")",
")",
".",
"\" = '\"",
".",
"$",
"child",
"->",
"getKey",
"(",
")",
".",
"\"';\n\"",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"child",
"->",
"getClassname",
"(",
")",
")",
"!=",
"strtoupper",
"(",
"$",
"child",
"->",
"getKey",
"(",
")",
")",
")",
"{",
"$",
"script",
".=",
"\"\n /** A key representing a particular subclass */\n const CLASSKEY_\"",
".",
"strtoupper",
"(",
"$",
"child",
"->",
"getClassname",
"(",
")",
")",
".",
"\" = '\"",
".",
"$",
"child",
"->",
"getKey",
"(",
")",
".",
"\"';\n\"",
";",
"}",
"$",
"script",
".=",
"\"\n /** A class that can be returned by this peer. */\n const CLASSNAME_\"",
".",
"strtoupper",
"(",
"$",
"child",
"->",
"getKey",
"(",
")",
")",
".",
"\" = '\"",
".",
"$",
"fqcn",
".",
"\"';\n\"",
";",
"}",
"/* foreach children */",
"}",
"/* if col->isenumerated...() */",
"}",
"/* if table->getchildrencolumn() */",
"}"
] | Adds the CLASSKEY_* and CLASSNAME_* constants used for inheritance.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"CLASSKEY_",
"*",
"and",
"CLASSNAME_",
"*",
"constants",
"used",
"for",
"inheritance",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L611-L650 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addAddSelectColumns | protected function addAddSelectColumns(&$script)
{
$script .= "
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad=\"true\" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param Criteria \$criteria object containing the columns to add.
* @param string \$alias optional table alias
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria \$criteria, \$alias = null)
{
if (null === \$alias) {";
foreach ($this->getTable()->getColumns() as $col) {
if (!$col->isLazyLoad()) {
$script .= "
\$criteria->addSelectColumn(" . $this->getPeerClassname() . "::" . $this->getColumnName($col) . ");";
} // if !col->isLazyLoad
} // foreach
$script .= "
} else {";
foreach ($this->getTable()->getColumns() as $col) {
if (!$col->isLazyLoad()) {
$script .= "
\$criteria->addSelectColumn(\$alias . '." . $col->getName() . "');";
} // if !col->isLazyLoad
} // foreach
$script .= "
}";
$script .= "
}
";
} | php | protected function addAddSelectColumns(&$script)
{
$script .= "
/**
* Add all the columns needed to create a new object.
*
* Note: any columns that were marked with lazyLoad=\"true\" in the
* XML schema will not be added to the select list and only loaded
* on demand.
*
* @param Criteria \$criteria object containing the columns to add.
* @param string \$alias optional table alias
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function addSelectColumns(Criteria \$criteria, \$alias = null)
{
if (null === \$alias) {";
foreach ($this->getTable()->getColumns() as $col) {
if (!$col->isLazyLoad()) {
$script .= "
\$criteria->addSelectColumn(" . $this->getPeerClassname() . "::" . $this->getColumnName($col) . ");";
} // if !col->isLazyLoad
} // foreach
$script .= "
} else {";
foreach ($this->getTable()->getColumns() as $col) {
if (!$col->isLazyLoad()) {
$script .= "
\$criteria->addSelectColumn(\$alias . '." . $col->getName() . "');";
} // if !col->isLazyLoad
} // foreach
$script .= "
}";
$script .= "
}
";
} | [
"protected",
"function",
"addAddSelectColumns",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"script",
".=",
"\"\n /**\n * Add all the columns needed to create a new object.\n *\n * Note: any columns that were marked with lazyLoad=\\\"true\\\" in the\n * XML schema will not be added to the select list and only loaded\n * on demand.\n *\n * @param Criteria \\$criteria object containing the columns to add.\n * @param string \\$alias optional table alias\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function addSelectColumns(Criteria \\$criteria, \\$alias = null)\n {\n if (null === \\$alias) {\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"!",
"$",
"col",
"->",
"isLazyLoad",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$criteria->addSelectColumn(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::\"",
".",
"$",
"this",
"->",
"getColumnName",
"(",
"$",
"col",
")",
".",
"\");\"",
";",
"}",
"// if !col->isLazyLoad",
"}",
"// foreach",
"$",
"script",
".=",
"\"\n } else {\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"!",
"$",
"col",
"->",
"isLazyLoad",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$criteria->addSelectColumn(\\$alias . '.\"",
".",
"$",
"col",
"->",
"getName",
"(",
")",
".",
"\"');\"",
";",
"}",
"// if !col->isLazyLoad",
"}",
"// foreach",
"$",
"script",
".=",
"\"\n }\"",
";",
"$",
"script",
".=",
"\"\n }\n\"",
";",
"}"
] | Adds the addSelectColumns() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"addSelectColumns",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L684-L721 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoCount | protected function addDoCount(&$script)
{
$script .= "
/**
* Returns the number of rows matching criteria.
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @return int Number of matching rows.
*/
public static function doCount(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null)
{
// we may modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME); // Set the correct dbName
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}";
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
// BasePeer returns a PDOStatement
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}";
} | php | protected function addDoCount(&$script)
{
$script .= "
/**
* Returns the number of rows matching criteria.
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @return int Number of matching rows.
*/
public static function doCount(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null)
{
// we may modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME); // Set the correct dbName
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}";
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
// BasePeer returns a PDOStatement
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}";
} | [
"protected",
"function",
"addDoCount",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"script",
".=",
"\"\n /**\n * Returns the number of rows matching criteria.\n *\n * @param Criteria \\$criteria\n * @param boolean \\$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.\n * @param PropelPDO \\$con\n * @return int Number of matching rows.\n */\n public static function doCount(Criteria \\$criteria, \\$distinct = false, PropelPDO \\$con = null)\n {\n // we may modify criteria, so copy it first\n \\$criteria = clone \\$criteria;\n\n // We need to set the primary table name, since in the case that there are no WHERE columns\n // it will be impossible for the BasePeer::createSelectSql() method to determine which\n // tables go into the FROM clause.\n \\$criteria->setPrimaryTableName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME);\n\n if (\\$distinct && !in_array(Criteria::DISTINCT, \\$criteria->getSelectModifiers())) {\n \\$criteria->setDistinct();\n }\n\n if (!\\$criteria->hasSelectClause()) {\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n }\n\n \\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME); // Set the correct dbName\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\"",
";",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"$",
"script",
".=",
"\"\n // BasePeer returns a PDOStatement\n \\$stmt = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doCount(\\$criteria, \\$con);\n\n if (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$count = (int) \\$row[0];\n } else {\n \\$count = 0; // no rows returned; we infer that means 0 matches.\n }\n \\$stmt->closeCursor();\n\n return \\$count;\n }\"",
";",
"}"
] | Adds the doCount() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doCount",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L728-L780 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoSelectStmt | protected function addDoSelectStmt(&$script)
{
$script .= "
/**
* Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
*
* Use this method directly if you want to work with an executed statement directly (for example
* to perform your own object hydration).
*
* @param Criteria \$criteria The Criteria object used to build the SELECT statement.
* @param PropelPDO \$con The connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return PDOStatement The executed PDOStatement object.
* @see " . $this->basePeerClassname . "::doSelect()
*/
public static function doSelectStmt(Criteria \$criteria, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
if (!\$criteria->hasSelectClause()) {
\$criteria = clone \$criteria;
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);";
// apply behaviors
if ($this->hasBehaviorModifier('preSelect')) {
$this->applyBehaviorModifier('preSelect', $script);
}
$script .= "
// BasePeer returns a PDOStatement
return " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
}";
} | php | protected function addDoSelectStmt(&$script)
{
$script .= "
/**
* Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
*
* Use this method directly if you want to work with an executed statement directly (for example
* to perform your own object hydration).
*
* @param Criteria \$criteria The Criteria object used to build the SELECT statement.
* @param PropelPDO \$con The connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return PDOStatement The executed PDOStatement object.
* @see " . $this->basePeerClassname . "::doSelect()
*/
public static function doSelectStmt(Criteria \$criteria, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
if (!\$criteria->hasSelectClause()) {
\$criteria = clone \$criteria;
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);";
// apply behaviors
if ($this->hasBehaviorModifier('preSelect')) {
$this->applyBehaviorModifier('preSelect', $script);
}
$script .= "
// BasePeer returns a PDOStatement
return " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
}";
} | [
"protected",
"function",
"addDoSelectStmt",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"script",
".=",
"\"\n /**\n * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.\n *\n * Use this method directly if you want to work with an executed statement directly (for example\n * to perform your own object hydration).\n *\n * @param Criteria \\$criteria The Criteria object used to build the SELECT statement.\n * @param PropelPDO \\$con The connection to use\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n * @return PDOStatement The executed PDOStatement object.\n * @see \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doSelect()\n */\n public static function doSelectStmt(Criteria \\$criteria, PropelPDO \\$con = null)\n {\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n\n if (!\\$criteria->hasSelectClause()) {\n \\$criteria = clone \\$criteria;\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n }\n\n // Set the correct dbName\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\"",
";",
"// apply behaviors",
"if",
"(",
"$",
"this",
"->",
"hasBehaviorModifier",
"(",
"'preSelect'",
")",
")",
"{",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"}",
"$",
"script",
".=",
"\"\n\n // BasePeer returns a PDOStatement\n return \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doSelect(\\$criteria, \\$con);\n }\"",
";",
"}"
] | Adds the doSelectStmt() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doSelectStmt",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L840-L879 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.getInstancePoolKeySnippet | public function getInstancePoolKeySnippet($pkphp)
{
$pkphp = (array) $pkphp; // make it an array if it is not.
$script = "";
if (count($pkphp) > 1) {
$script .= "serialize(array(";
$i = 0;
foreach ($pkphp as $pkvar) {
$script .= ($i++ ? ', ' : '') . "(string) $pkvar";
}
$script .= "))";
} else {
$script .= "(string) " . $pkphp[0];
}
return $script;
} | php | public function getInstancePoolKeySnippet($pkphp)
{
$pkphp = (array) $pkphp; // make it an array if it is not.
$script = "";
if (count($pkphp) > 1) {
$script .= "serialize(array(";
$i = 0;
foreach ($pkphp as $pkvar) {
$script .= ($i++ ? ', ' : '') . "(string) $pkvar";
}
$script .= "))";
} else {
$script .= "(string) " . $pkphp[0];
}
return $script;
} | [
"public",
"function",
"getInstancePoolKeySnippet",
"(",
"$",
"pkphp",
")",
"{",
"$",
"pkphp",
"=",
"(",
"array",
")",
"$",
"pkphp",
";",
"// make it an array if it is not.",
"$",
"script",
"=",
"\"\"",
";",
"if",
"(",
"count",
"(",
"$",
"pkphp",
")",
">",
"1",
")",
"{",
"$",
"script",
".=",
"\"serialize(array(\"",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"pkphp",
"as",
"$",
"pkvar",
")",
"{",
"$",
"script",
".=",
"(",
"$",
"i",
"++",
"?",
"', '",
":",
"''",
")",
".",
"\"(string) $pkvar\"",
";",
"}",
"$",
"script",
".=",
"\"))\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"(string) \"",
".",
"$",
"pkphp",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"script",
";",
"}"
] | Adds the PHP code to return a instance pool key for the passed-in primary key variable names.
@param array $pkphp An array of PHP var names / method calls representing complete pk.
@return string | [
"Adds",
"the",
"PHP",
"code",
"to",
"return",
"a",
"instance",
"pool",
"key",
"for",
"the",
"passed",
"-",
"in",
"primary",
"key",
"variable",
"names",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L888-L904 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addAddInstanceToPool | protected function addAddInstanceToPool(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Adds an object to the instance pool.
*
* Propel keeps cached copies of objects in an instance pool when they are retrieved
* from the database. In some cases -- especially when you override doSelect*()
* methods in your stub classes -- you may need to explicitly add objects
* to the cache in order to ensure that the same objects are always returned by doSelect*()
* and retrieveByPK*() calls.
*
* @param " . $this->getObjectClassname() . " \$obj A " . $this->getObjectClassname() . " object.
* @param string \$key (optional) key to use for instance map (for performance boost if key was already calculated externally).
*/
public static function addInstanceToPool(\$obj, \$key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if (\$key === null) {";
$pks = $this->getTable()->getPrimaryKey();
$php = array();
foreach ($pks as $pk) {
if ($pk->isTemporalType()) {
$php[] = '$obj->get' . $pk->getPhpName() . "('U')";
} else {
$php[] = '$obj->get' . $pk->getPhpName() . '()';
}
}
$script .= "
\$key = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
} // if key === null
" . $this->getPeerClassname() . "::\$instances[\$key] = \$obj;
}
}
";
} | php | protected function addAddInstanceToPool(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Adds an object to the instance pool.
*
* Propel keeps cached copies of objects in an instance pool when they are retrieved
* from the database. In some cases -- especially when you override doSelect*()
* methods in your stub classes -- you may need to explicitly add objects
* to the cache in order to ensure that the same objects are always returned by doSelect*()
* and retrieveByPK*() calls.
*
* @param " . $this->getObjectClassname() . " \$obj A " . $this->getObjectClassname() . " object.
* @param string \$key (optional) key to use for instance map (for performance boost if key was already calculated externally).
*/
public static function addInstanceToPool(\$obj, \$key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if (\$key === null) {";
$pks = $this->getTable()->getPrimaryKey();
$php = array();
foreach ($pks as $pk) {
if ($pk->isTemporalType()) {
$php[] = '$obj->get' . $pk->getPhpName() . "('U')";
} else {
$php[] = '$obj->get' . $pk->getPhpName() . '()';
}
}
$script .= "
\$key = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
} // if key === null
" . $this->getPeerClassname() . "::\$instances[\$key] = \$obj;
}
}
";
} | [
"protected",
"function",
"addAddInstanceToPool",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Adds an object to the instance pool.\n *\n * Propel keeps cached copies of objects in an instance pool when they are retrieved\n * from the database. In some cases -- especially when you override doSelect*()\n * methods in your stub classes -- you may need to explicitly add objects\n * to the cache in order to ensure that the same objects are always returned by doSelect*()\n * and retrieveByPK*() calls.\n *\n * @param \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" \\$obj A \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object.\n * @param string \\$key (optional) key to use for instance map (for performance boost if key was already calculated externally).\n */\n public static function addInstanceToPool(\\$obj, \\$key = null)\n {\n if (Propel::isInstancePoolingEnabled()) {\n if (\\$key === null) {\"",
";",
"$",
"pks",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"php",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"pks",
"as",
"$",
"pk",
")",
"{",
"if",
"(",
"$",
"pk",
"->",
"isTemporalType",
"(",
")",
")",
"{",
"$",
"php",
"[",
"]",
"=",
"'$obj->get'",
".",
"$",
"pk",
"->",
"getPhpName",
"(",
")",
".",
"\"('U')\"",
";",
"}",
"else",
"{",
"$",
"php",
"[",
"]",
"=",
"'$obj->get'",
".",
"$",
"pk",
"->",
"getPhpName",
"(",
")",
".",
"'()'",
";",
"}",
"}",
"$",
"script",
".=",
"\"\n \\$key = \"",
".",
"$",
"this",
"->",
"getInstancePoolKeySnippet",
"(",
"$",
"php",
")",
".",
"\";\"",
";",
"$",
"script",
".=",
"\"\n } // if key === null\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::\\$instances[\\$key] = \\$obj;\n }\n }\n\"",
";",
"}"
] | Creates a convenience method to add objects to an instance pool.
@param string &$script The script will be modified in this method. | [
"Creates",
"a",
"convenience",
"method",
"to",
"add",
"objects",
"to",
"an",
"instance",
"pool",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L911-L950 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addRemoveInstanceFromPool | protected function addRemoveInstanceFromPool(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Removes an object from the instance pool.
*
* Propel keeps cached copies of objects in an instance pool when they are retrieved
* from the database. In some cases -- especially when you override doDelete
* methods in your stub classes -- you may need to explicitly remove objects
* from the cache in order to prevent returning objects that no longer exist.
*
* @param mixed \$value A " . $this->getObjectClassname() . " object or a primary key value.
*
* @return void
* @throws PropelException - if the value is invalid.
*/
public static function removeInstanceFromPool(\$value)
{";
$script .= "
if (Propel::isInstancePoolingEnabled() && \$value !== null) {";
$pks = $table->getPrimaryKey();
$script .= "
if (is_object(\$value) && \$value instanceof " . $this->getObjectClassname() . ") {";
$php = array();
foreach ($pks as $pk) {
$php[] = '$value->get' . $pk->getPhpName() . '()';
}
$script .= "
\$key = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
} elseif (" . (count($pks) > 1 ? "is_array(\$value) && count(\$value) === " . count($pks) : "is_scalar(\$value)") . ") {
// assume we've been passed a primary key";
if (count($pks) > 1) {
$php = array();
for ($i = 0; $i < count($pks); $i++) {
$php[] = "\$value[$i]";
}
} else {
$php = '$value';
}
$script .= "
\$key = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
} else {
\$e = new PropelException(\"Invalid value passed to removeInstanceFromPool(). Expected primary key or " . $this->getObjectClassname() . " object; got \" . (is_object(\$value) ? get_class(\$value) . ' object.' : var_export(\$value,true)));
throw \$e;
}
unset(" . $this->getPeerClassname() . "::\$instances[\$key]);
}
} // removeInstanceFromPool()
";
} | php | protected function addRemoveInstanceFromPool(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Removes an object from the instance pool.
*
* Propel keeps cached copies of objects in an instance pool when they are retrieved
* from the database. In some cases -- especially when you override doDelete
* methods in your stub classes -- you may need to explicitly remove objects
* from the cache in order to prevent returning objects that no longer exist.
*
* @param mixed \$value A " . $this->getObjectClassname() . " object or a primary key value.
*
* @return void
* @throws PropelException - if the value is invalid.
*/
public static function removeInstanceFromPool(\$value)
{";
$script .= "
if (Propel::isInstancePoolingEnabled() && \$value !== null) {";
$pks = $table->getPrimaryKey();
$script .= "
if (is_object(\$value) && \$value instanceof " . $this->getObjectClassname() . ") {";
$php = array();
foreach ($pks as $pk) {
$php[] = '$value->get' . $pk->getPhpName() . '()';
}
$script .= "
\$key = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
} elseif (" . (count($pks) > 1 ? "is_array(\$value) && count(\$value) === " . count($pks) : "is_scalar(\$value)") . ") {
// assume we've been passed a primary key";
if (count($pks) > 1) {
$php = array();
for ($i = 0; $i < count($pks); $i++) {
$php[] = "\$value[$i]";
}
} else {
$php = '$value';
}
$script .= "
\$key = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
} else {
\$e = new PropelException(\"Invalid value passed to removeInstanceFromPool(). Expected primary key or " . $this->getObjectClassname() . " object; got \" . (is_object(\$value) ? get_class(\$value) . ' object.' : var_export(\$value,true)));
throw \$e;
}
unset(" . $this->getPeerClassname() . "::\$instances[\$key]);
}
} // removeInstanceFromPool()
";
} | [
"protected",
"function",
"addRemoveInstanceFromPool",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Removes an object from the instance pool.\n *\n * Propel keeps cached copies of objects in an instance pool when they are retrieved\n * from the database. In some cases -- especially when you override doDelete\n * methods in your stub classes -- you may need to explicitly remove objects\n * from the cache in order to prevent returning objects that no longer exist.\n *\n * @param mixed \\$value A \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object or a primary key value.\n *\n * @return void\n * @throws PropelException - if the value is invalid.\n */\n public static function removeInstanceFromPool(\\$value)\n {\"",
";",
"$",
"script",
".=",
"\"\n if (Propel::isInstancePoolingEnabled() && \\$value !== null) {\"",
";",
"$",
"pks",
"=",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"script",
".=",
"\"\n if (is_object(\\$value) && \\$value instanceof \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\") {\"",
";",
"$",
"php",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"pks",
"as",
"$",
"pk",
")",
"{",
"$",
"php",
"[",
"]",
"=",
"'$value->get'",
".",
"$",
"pk",
"->",
"getPhpName",
"(",
")",
".",
"'()'",
";",
"}",
"$",
"script",
".=",
"\"\n \\$key = \"",
".",
"$",
"this",
"->",
"getInstancePoolKeySnippet",
"(",
"$",
"php",
")",
".",
"\";\"",
";",
"$",
"script",
".=",
"\"\n } elseif (\"",
".",
"(",
"count",
"(",
"$",
"pks",
")",
">",
"1",
"?",
"\"is_array(\\$value) && count(\\$value) === \"",
".",
"count",
"(",
"$",
"pks",
")",
":",
"\"is_scalar(\\$value)\"",
")",
".",
"\") {\n // assume we've been passed a primary key\"",
";",
"if",
"(",
"count",
"(",
"$",
"pks",
")",
">",
"1",
")",
"{",
"$",
"php",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"pks",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"php",
"[",
"]",
"=",
"\"\\$value[$i]\"",
";",
"}",
"}",
"else",
"{",
"$",
"php",
"=",
"'$value'",
";",
"}",
"$",
"script",
".=",
"\"\n \\$key = \"",
".",
"$",
"this",
"->",
"getInstancePoolKeySnippet",
"(",
"$",
"php",
")",
".",
"\";\"",
";",
"$",
"script",
".=",
"\"\n } else {\n \\$e = new PropelException(\\\"Invalid value passed to removeInstanceFromPool(). Expected primary key or \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object; got \\\" . (is_object(\\$value) ? get_class(\\$value) . ' object.' : var_export(\\$value,true)));\n throw \\$e;\n }\n\n unset(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::\\$instances[\\$key]);\n }\n } // removeInstanceFromPool()\n\"",
";",
"}"
] | Creates a convenience method to remove objects form an instance pool.
@param string &$script The script will be modified in this method. | [
"Creates",
"a",
"convenience",
"method",
"to",
"remove",
"objects",
"form",
"an",
"instance",
"pool",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L957-L1014 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addClearRelatedInstancePool | protected function addClearRelatedInstancePool(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Method to invalidate the instance pool of all tables related to " . $table->getName() . "
* by a foreign key with ON DELETE CASCADE
*/
public static function clearRelatedInstancePool()
{";
// Handle ON DELETE CASCADE for updating instance pool
foreach ($table->getReferrers() as $fk) {
// $fk is the foreign key in the other table, so localTableName will
// actually be the table name of other table
$tblFK = $fk->getTable();
$joinedTablePeerBuilder = $this->getNewStubPeerBuilder($tblFK);
$this->declareClassFromBuilder($joinedTablePeerBuilder);
$tblFKPackage = $joinedTablePeerBuilder->getStubPeerBuilder()->getPackage();
if (!$tblFK->isForReferenceOnly()) {
// we can't perform operations on tables that are
// not within the schema (i.e. that we have no map for, etc.)
if ($fk->getOnDelete() == ForeignKey::CASCADE || $fk->getOnDelete() == ForeignKey::SETNULL) {
$script .= "
// Invalidate objects in " . $joinedTablePeerBuilder->getClassname() . " instance pool,
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
" . $joinedTablePeerBuilder->getClassname() . "::clearInstancePool();";
} // if fk is on delete cascade
} // if (! for ref only)
} // foreach
$script .= "
}
";
} | php | protected function addClearRelatedInstancePool(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Method to invalidate the instance pool of all tables related to " . $table->getName() . "
* by a foreign key with ON DELETE CASCADE
*/
public static function clearRelatedInstancePool()
{";
// Handle ON DELETE CASCADE for updating instance pool
foreach ($table->getReferrers() as $fk) {
// $fk is the foreign key in the other table, so localTableName will
// actually be the table name of other table
$tblFK = $fk->getTable();
$joinedTablePeerBuilder = $this->getNewStubPeerBuilder($tblFK);
$this->declareClassFromBuilder($joinedTablePeerBuilder);
$tblFKPackage = $joinedTablePeerBuilder->getStubPeerBuilder()->getPackage();
if (!$tblFK->isForReferenceOnly()) {
// we can't perform operations on tables that are
// not within the schema (i.e. that we have no map for, etc.)
if ($fk->getOnDelete() == ForeignKey::CASCADE || $fk->getOnDelete() == ForeignKey::SETNULL) {
$script .= "
// Invalidate objects in " . $joinedTablePeerBuilder->getClassname() . " instance pool,
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
" . $joinedTablePeerBuilder->getClassname() . "::clearInstancePool();";
} // if fk is on delete cascade
} // if (! for ref only)
} // foreach
$script .= "
}
";
} | [
"protected",
"function",
"addClearRelatedInstancePool",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Method to invalidate the instance pool of all tables related to \"",
".",
"$",
"table",
"->",
"getName",
"(",
")",
".",
"\"\n * by a foreign key with ON DELETE CASCADE\n */\n public static function clearRelatedInstancePool()\n {\"",
";",
"// Handle ON DELETE CASCADE for updating instance pool",
"foreach",
"(",
"$",
"table",
"->",
"getReferrers",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"// $fk is the foreign key in the other table, so localTableName will",
"// actually be the table name of other table",
"$",
"tblFK",
"=",
"$",
"fk",
"->",
"getTable",
"(",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewStubPeerBuilder",
"(",
"$",
"tblFK",
")",
";",
"$",
"this",
"->",
"declareClassFromBuilder",
"(",
"$",
"joinedTablePeerBuilder",
")",
";",
"$",
"tblFKPackage",
"=",
"$",
"joinedTablePeerBuilder",
"->",
"getStubPeerBuilder",
"(",
")",
"->",
"getPackage",
"(",
")",
";",
"if",
"(",
"!",
"$",
"tblFK",
"->",
"isForReferenceOnly",
"(",
")",
")",
"{",
"// we can't perform operations on tables that are",
"// not within the schema (i.e. that we have no map for, etc.)",
"if",
"(",
"$",
"fk",
"->",
"getOnDelete",
"(",
")",
"==",
"ForeignKey",
"::",
"CASCADE",
"||",
"$",
"fk",
"->",
"getOnDelete",
"(",
")",
"==",
"ForeignKey",
"::",
"SETNULL",
")",
"{",
"$",
"script",
".=",
"\"\n // Invalidate objects in \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getClassname",
"(",
")",
".",
"\" instance pool,\n // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.\n \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getClassname",
"(",
")",
".",
"\"::clearInstancePool();\"",
";",
"}",
"// if fk is on delete cascade",
"}",
"// if (! for ref only)",
"}",
"// foreach",
"$",
"script",
".=",
"\"\n }\n\"",
";",
"}"
] | Adds method to clear the instance pool of related tables.
@param string &$script The script will be modified in this method. | [
"Adds",
"method",
"to",
"clear",
"the",
"instance",
"pool",
"of",
"related",
"tables",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1046-L1083 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addGetPrimaryKeyFromRow | protected function addGetPrimaryKeyFromRow(&$script)
{
$script .= "
/**
* Retrieves the primary key from the DB resultset row
* For tables with a single-column primary key, that simple pkey value will be returned. For tables with
* a multi-column primary key, an array of the primary key columns will be returned.
*
* @param array \$row PropelPDO resultset row.
* @param int \$startcol The 0-based offset for reading from the resultset row.
* @return mixed The primary key of the row
*/
public static function getPrimaryKeyFromRow(\$row, \$startcol = 0)
{";
// We have to iterate through all the columns so that we know the offset of the primary
// key columns.
$table = $this->getTable();
$n = 0;
$pks = array();
foreach ($table->getColumns() as $col) {
if (!$col->isLazyLoad()) {
if ($col->isPrimaryKey()) {
$pk = '(' . $col->getPhpType() . ') ' . ($n ? "\$row[\$startcol + $n]" : "\$row[\$startcol]");
if ($table->hasCompositePrimaryKey()) {
$pks[] = $pk;
}
}
$n++;
}
}
if ($table->hasCompositePrimaryKey()) {
$script .= "
return array(" . implode($pks, ', ') . ");";
} else {
$script .= "
return " . $pk . ";";
}
$script .= "
}
";
} | php | protected function addGetPrimaryKeyFromRow(&$script)
{
$script .= "
/**
* Retrieves the primary key from the DB resultset row
* For tables with a single-column primary key, that simple pkey value will be returned. For tables with
* a multi-column primary key, an array of the primary key columns will be returned.
*
* @param array \$row PropelPDO resultset row.
* @param int \$startcol The 0-based offset for reading from the resultset row.
* @return mixed The primary key of the row
*/
public static function getPrimaryKeyFromRow(\$row, \$startcol = 0)
{";
// We have to iterate through all the columns so that we know the offset of the primary
// key columns.
$table = $this->getTable();
$n = 0;
$pks = array();
foreach ($table->getColumns() as $col) {
if (!$col->isLazyLoad()) {
if ($col->isPrimaryKey()) {
$pk = '(' . $col->getPhpType() . ') ' . ($n ? "\$row[\$startcol + $n]" : "\$row[\$startcol]");
if ($table->hasCompositePrimaryKey()) {
$pks[] = $pk;
}
}
$n++;
}
}
if ($table->hasCompositePrimaryKey()) {
$script .= "
return array(" . implode($pks, ', ') . ");";
} else {
$script .= "
return " . $pk . ";";
}
$script .= "
}
";
} | [
"protected",
"function",
"addGetPrimaryKeyFromRow",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"script",
".=",
"\"\n /**\n * Retrieves the primary key from the DB resultset row\n * For tables with a single-column primary key, that simple pkey value will be returned. For tables with\n * a multi-column primary key, an array of the primary key columns will be returned.\n *\n * @param array \\$row PropelPDO resultset row.\n * @param int \\$startcol The 0-based offset for reading from the resultset row.\n * @return mixed The primary key of the row\n */\n public static function getPrimaryKeyFromRow(\\$row, \\$startcol = 0)\n {\"",
";",
"// We have to iterate through all the columns so that we know the offset of the primary",
"// key columns.",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"n",
"=",
"0",
";",
"$",
"pks",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"!",
"$",
"col",
"->",
"isLazyLoad",
"(",
")",
")",
"{",
"if",
"(",
"$",
"col",
"->",
"isPrimaryKey",
"(",
")",
")",
"{",
"$",
"pk",
"=",
"'('",
".",
"$",
"col",
"->",
"getPhpType",
"(",
")",
".",
"') '",
".",
"(",
"$",
"n",
"?",
"\"\\$row[\\$startcol + $n]\"",
":",
"\"\\$row[\\$startcol]\"",
")",
";",
"if",
"(",
"$",
"table",
"->",
"hasCompositePrimaryKey",
"(",
")",
")",
"{",
"$",
"pks",
"[",
"]",
"=",
"$",
"pk",
";",
"}",
"}",
"$",
"n",
"++",
";",
"}",
"}",
"if",
"(",
"$",
"table",
"->",
"hasCompositePrimaryKey",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n\n return array(\"",
".",
"implode",
"(",
"$",
"pks",
",",
"', '",
")",
".",
"\");\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n\n return \"",
".",
"$",
"pk",
".",
"\";\"",
";",
"}",
"$",
"script",
".=",
"\"\n }\n \"",
";",
"}"
] | Adds method to get the primary key from a row
@param string &$script The script will be modified in this method. | [
"Adds",
"method",
"to",
"get",
"the",
"primary",
"key",
"from",
"a",
"row"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1169-L1212 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addPopulateObjects | protected function addPopulateObjects(&$script)
{
$table = $this->getTable();
$script .= "
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(PDOStatement \$stmt)
{
\$results = array();
";
if (!$table->getChildrenColumn()) {
$script .= "
// set the class once to avoid overhead in the loop
\$cls = " . $this->getPeerClassname() . "::getOMClass();";
}
$script .= "
// populate the object(s)
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj->hydrate(\$row, 0, true); // rehydrate
\$results[] = \$obj;
} else {";
if ($table->getChildrenColumn()) {
$script .= "
// class must be set each time from the record row
\$cls = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$cls, strrpos('.'.\$cls, '.') + 1);
" . $this->buildObjectInstanceCreationCode('$obj', '$cls') . "
\$obj->hydrate(\$row);
\$results[] = \$obj;
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj, \$key);";
} else {
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj', '$cls') . "
\$obj->hydrate(\$row);
\$results[] = \$obj;
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj, \$key);";
}
$script .= "
} // if key exists
}
\$stmt->closeCursor();
return \$results;
}";
} | php | protected function addPopulateObjects(&$script)
{
$table = $this->getTable();
$script .= "
/**
* The returned array will contain objects of the default type or
* objects that inherit from the default.
*
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function populateObjects(PDOStatement \$stmt)
{
\$results = array();
";
if (!$table->getChildrenColumn()) {
$script .= "
// set the class once to avoid overhead in the loop
\$cls = " . $this->getPeerClassname() . "::getOMClass();";
}
$script .= "
// populate the object(s)
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj->hydrate(\$row, 0, true); // rehydrate
\$results[] = \$obj;
} else {";
if ($table->getChildrenColumn()) {
$script .= "
// class must be set each time from the record row
\$cls = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$cls, strrpos('.'.\$cls, '.') + 1);
" . $this->buildObjectInstanceCreationCode('$obj', '$cls') . "
\$obj->hydrate(\$row);
\$results[] = \$obj;
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj, \$key);";
} else {
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj', '$cls') . "
\$obj->hydrate(\$row);
\$results[] = \$obj;
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj, \$key);";
}
$script .= "
} // if key exists
}
\$stmt->closeCursor();
return \$results;
}";
} | [
"protected",
"function",
"addPopulateObjects",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * The returned array will contain objects of the default type or\n * objects that inherit from the default.\n *\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function populateObjects(PDOStatement \\$stmt)\n {\n \\$results = array();\n \"",
";",
"if",
"(",
"!",
"$",
"table",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n // set the class once to avoid overhead in the loop\n \\$cls = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass();\"",
";",
"}",
"$",
"script",
".=",
"\"\n // populate the object(s)\n while (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$key = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, 0);\n if (null !== (\\$obj = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key))) {\n // We no longer rehydrate the object, since this can cause data loss.\n // See http://www.propelorm.org/ticket/509\n // \\$obj->hydrate(\\$row, 0, true); // rehydrate\n \\$results[] = \\$obj;\n } else {\"",
";",
"if",
"(",
"$",
"table",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n // class must be set each time from the record row\n \\$cls = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, 0);\n \\$cls = substr('.'.\\$cls, strrpos('.'.\\$cls, '.') + 1);\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj'",
",",
"'$cls'",
")",
".",
"\"\n \\$obj->hydrate(\\$row);\n \\$results[] = \\$obj;\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj, \\$key);\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj'",
",",
"'$cls'",
")",
".",
"\"\n \\$obj->hydrate(\\$row);\n \\$results[] = \\$obj;\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj, \\$key);\"",
";",
"}",
"$",
"script",
".=",
"\"\n } // if key exists\n }\n \\$stmt->closeCursor();\n\n return \\$results;\n }\"",
";",
"}"
] | Adds the populateObjects() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"populateObjects",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1219-L1273 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addPopulateObject | protected function addPopulateObject(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Populates an object of the default type or an object that inherit from the default.
*
* @param array \$row PropelPDO resultset row.
* @param int \$startcol The 0-based offset for reading from the resultset row.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return array (" . $this->getStubObjectBuilder()->getClassName() . " object, last column rank)
*/
public static function populateObject(\$row, \$startcol = 0)
{
\$key = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol);
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj->hydrate(\$row, \$startcol, true); // rehydrate
\$col = \$startcol + " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;";
if ($table->isAbstract()) {
$script .= "
} elseif (null == \$key) {
// empty resultset, probably from a left join
// since this table is abstract, we can't hydrate an empty object
\$obj = null;
\$col = \$startcol + " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;";
}
$script .= "
} else {";
if (!$table->getChildrenColumn()) {
$script .= "
\$cls = " . $this->getPeerClassname() . "::OM_CLASS;";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass(\$row, \$startcol);";
}
$script .= "
\$obj = new \$cls();
\$col = \$obj->hydrate(\$row, \$startcol);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj, \$key);
}
return array(\$obj, \$col);
}
";
} | php | protected function addPopulateObject(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Populates an object of the default type or an object that inherit from the default.
*
* @param array \$row PropelPDO resultset row.
* @param int \$startcol The 0-based offset for reading from the resultset row.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return array (" . $this->getStubObjectBuilder()->getClassName() . " object, last column rank)
*/
public static function populateObject(\$row, \$startcol = 0)
{
\$key = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol);
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj->hydrate(\$row, \$startcol, true); // rehydrate
\$col = \$startcol + " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;";
if ($table->isAbstract()) {
$script .= "
} elseif (null == \$key) {
// empty resultset, probably from a left join
// since this table is abstract, we can't hydrate an empty object
\$obj = null;
\$col = \$startcol + " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;";
}
$script .= "
} else {";
if (!$table->getChildrenColumn()) {
$script .= "
\$cls = " . $this->getPeerClassname() . "::OM_CLASS;";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass(\$row, \$startcol);";
}
$script .= "
\$obj = new \$cls();
\$col = \$obj->hydrate(\$row, \$startcol);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj, \$key);
}
return array(\$obj, \$col);
}
";
} | [
"protected",
"function",
"addPopulateObject",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Populates an object of the default type or an object that inherit from the default.\n *\n * @param array \\$row PropelPDO resultset row.\n * @param int \\$startcol The 0-based offset for reading from the resultset row.\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n * @return array (\"",
".",
"$",
"this",
"->",
"getStubObjectBuilder",
"(",
")",
"->",
"getClassName",
"(",
")",
".",
"\" object, last column rank)\n */\n public static function populateObject(\\$row, \\$startcol = 0)\n {\n \\$key = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, \\$startcol);\n if (null !== (\\$obj = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key))) {\n // We no longer rehydrate the object, since this can cause data loss.\n // See http://www.propelorm.org/ticket/509\n // \\$obj->hydrate(\\$row, \\$startcol, true); // rehydrate\n \\$col = \\$startcol + \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::NUM_HYDRATE_COLUMNS;\"",
";",
"if",
"(",
"$",
"table",
"->",
"isAbstract",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n } elseif (null == \\$key) {\n // empty resultset, probably from a left join\n // since this table is abstract, we can't hydrate an empty object\n \\$obj = null;\n \\$col = \\$startcol + \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::NUM_HYDRATE_COLUMNS;\"",
";",
"}",
"$",
"script",
".=",
"\"\n } else {\"",
";",
"if",
"(",
"!",
"$",
"table",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::OM_CLASS;\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, \\$startcol);\"",
";",
"}",
"$",
"script",
".=",
"\"\n \\$obj = new \\$cls();\n \\$col = \\$obj->hydrate(\\$row, \\$startcol);\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj, \\$key);\n }\n\n return array(\\$obj, \\$col);\n }\n\"",
";",
"}"
] | Adds the populateObject() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"populateObject",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1280-L1327 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addGetOMClass_Inheritance | protected function addGetOMClass_Inheritance(&$script)
{
$col = $this->getTable()->getChildrenColumn();
$script .= "
/**
* The returned Class will contain objects of the default type or
* objects that inherit from the default.
*
* @param array \$row PropelPDO result row.
* @param int \$colnum Column to examine for OM class information (first is 0).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getOMClass(\$row = 0, \$colnum = 0)
{
try {
";
if ($col->isEnumeratedClasses()) {
$script .= "
\$omClass = null;
\$classKey = \$row[\$colnum + " . ($col->getPosition() - 1) . "];
switch (\$classKey) {
";
foreach ($col->getChildren() as $child) {
$script .= "
case " . $this->getPeerClassname() . "::CLASSKEY_" . strtoupper($child->getKey()) . ":
\$omClass = " . $this->getPeerClassname() . "::CLASSNAME_" . strtoupper($child->getKey()) . ";
break;
";
} /* foreach */
$script .= "
default:
\$omClass = " . $this->getPeerClassname() . "::OM_CLASS;
";
$script .= "
} // switch
";
} else { /* if not enumerated */
$script .= "
\$omClass = \$row[\$colnum + " . ($col->getPosition() - 1) . "];
\$omClass = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
}
$script .= "
} catch (Exception \$e) {
throw new PropelException('Unable to get OM class.', \$e);
}
return \$omClass;
}
";
} | php | protected function addGetOMClass_Inheritance(&$script)
{
$col = $this->getTable()->getChildrenColumn();
$script .= "
/**
* The returned Class will contain objects of the default type or
* objects that inherit from the default.
*
* @param array \$row PropelPDO result row.
* @param int \$colnum Column to examine for OM class information (first is 0).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function getOMClass(\$row = 0, \$colnum = 0)
{
try {
";
if ($col->isEnumeratedClasses()) {
$script .= "
\$omClass = null;
\$classKey = \$row[\$colnum + " . ($col->getPosition() - 1) . "];
switch (\$classKey) {
";
foreach ($col->getChildren() as $child) {
$script .= "
case " . $this->getPeerClassname() . "::CLASSKEY_" . strtoupper($child->getKey()) . ":
\$omClass = " . $this->getPeerClassname() . "::CLASSNAME_" . strtoupper($child->getKey()) . ";
break;
";
} /* foreach */
$script .= "
default:
\$omClass = " . $this->getPeerClassname() . "::OM_CLASS;
";
$script .= "
} // switch
";
} else { /* if not enumerated */
$script .= "
\$omClass = \$row[\$colnum + " . ($col->getPosition() - 1) . "];
\$omClass = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
}
$script .= "
} catch (Exception \$e) {
throw new PropelException('Unable to get OM class.', \$e);
}
return \$omClass;
}
";
} | [
"protected",
"function",
"addGetOMClass_Inheritance",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"col",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getChildrenColumn",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * The returned Class will contain objects of the default type or\n * objects that inherit from the default.\n *\n * @param array \\$row PropelPDO result row.\n * @param int \\$colnum Column to examine for OM class information (first is 0).\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function getOMClass(\\$row = 0, \\$colnum = 0)\n {\n try {\n\"",
";",
"if",
"(",
"$",
"col",
"->",
"isEnumeratedClasses",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$omClass = null;\n \\$classKey = \\$row[\\$colnum + \"",
".",
"(",
"$",
"col",
"->",
"getPosition",
"(",
")",
"-",
"1",
")",
".",
"\"];\n\n switch (\\$classKey) {\n\"",
";",
"foreach",
"(",
"$",
"col",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"script",
".=",
"\"\n case \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::CLASSKEY_\"",
".",
"strtoupper",
"(",
"$",
"child",
"->",
"getKey",
"(",
")",
")",
".",
"\":\n \\$omClass = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::CLASSNAME_\"",
".",
"strtoupper",
"(",
"$",
"child",
"->",
"getKey",
"(",
")",
")",
".",
"\";\n break;\n\"",
";",
"}",
"/* foreach */",
"$",
"script",
".=",
"\"\n default:\n \\$omClass = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::OM_CLASS;\n\"",
";",
"$",
"script",
".=",
"\"\n } // switch\n\"",
";",
"}",
"else",
"{",
"/* if not enumerated */",
"$",
"script",
".=",
"\"\n \\$omClass = \\$row[\\$colnum + \"",
".",
"(",
"$",
"col",
"->",
"getPosition",
"(",
")",
"-",
"1",
")",
".",
"\"];\n \\$omClass = substr('.'.\\$omClass, strrpos('.'.\\$omClass, '.') + 1);\n\"",
";",
"}",
"$",
"script",
".=",
"\"\n } catch (Exception \\$e) {\n throw new PropelException('Unable to get OM class.', \\$e);\n }\n\n return \\$omClass;\n }\n\"",
";",
"}"
] | Adds a getOMClass() for non-abstract tables that have inheritance.
@param string &$script The script will be modified in this method. | [
"Adds",
"a",
"getOMClass",
"()",
"for",
"non",
"-",
"abstract",
"tables",
"that",
"have",
"inheritance",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1334-L1386 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoInsert | protected function addDoInsert(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Performs an INSERT on the database, given a " . $this->getObjectClassname() . " or Criteria object.
*
* @param mixed \$values Criteria or " . $this->getObjectClassname() . " object containing data that is used to create the INSERT statement.
* @param PropelPDO \$con the PropelPDO connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert(\$values, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if (\$values instanceof Criteria) {
\$criteria = clone \$values; // rename for clarity
} else {
\$criteria = \$values->buildCriteria(); // build Criteria from " . $this->getObjectClassname() . " object
}
";
foreach ($table->getColumns() as $col) {
$cfc = $col->getPhpName();
if ($col->isPrimaryKey() && $col->isAutoIncrement() && $table->getIdMethod() != "none" && !$table->isAllowPkInsert()) {
$script .= "
if (\$criteria->containsKey(" . $this->getColumnConstant($col) . ") && \$criteria->keyContainsValue(" . $this->getColumnConstant($col) . ") ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('." . $this->getColumnConstant($col) . ".')');
}
";
if (!$this->getPlatform()->supportsInsertNullPk()) {
$script .= "
// remove pkey col since this table uses auto-increment and passing a null value for it is not valid
\$criteria->remove(" . $this->getColumnConstant($col) . ");
";
}
} elseif ($col->isPrimaryKey() && $col->isAutoIncrement() && $table->getIdMethod() != "none" && $table->isAllowPkInsert() && !$this->getPlatform()->supportsInsertNullPk()) {
$script .= "
// remove pkey col if it is null since this table does not accept that
if (\$criteria->containsKey(" . $this->getColumnConstant($col) . ") && !\$criteria->keyContainsValue(" . $this->getColumnConstant($col) . ") ) {
\$criteria->remove(" . $this->getColumnConstant($col) . ");
}
";
}
}
$script .= "
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
try {
// use transaction because \$criteria could contain info
// for more than one table (I guess, conceivably)
\$con->beginTransaction();
\$pk = " . $this->basePeerClassname . "::doInsert(\$criteria, \$con);
\$con->commit();
} catch (Exception \$e) {
\$con->rollBack();
throw \$e;
}
return \$pk;
}
";
} | php | protected function addDoInsert(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Performs an INSERT on the database, given a " . $this->getObjectClassname() . " or Criteria object.
*
* @param mixed \$values Criteria or " . $this->getObjectClassname() . " object containing data that is used to create the INSERT statement.
* @param PropelPDO \$con the PropelPDO connection to use
* @return mixed The new primary key.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doInsert(\$values, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if (\$values instanceof Criteria) {
\$criteria = clone \$values; // rename for clarity
} else {
\$criteria = \$values->buildCriteria(); // build Criteria from " . $this->getObjectClassname() . " object
}
";
foreach ($table->getColumns() as $col) {
$cfc = $col->getPhpName();
if ($col->isPrimaryKey() && $col->isAutoIncrement() && $table->getIdMethod() != "none" && !$table->isAllowPkInsert()) {
$script .= "
if (\$criteria->containsKey(" . $this->getColumnConstant($col) . ") && \$criteria->keyContainsValue(" . $this->getColumnConstant($col) . ") ) {
throw new PropelException('Cannot insert a value for auto-increment primary key ('." . $this->getColumnConstant($col) . ".')');
}
";
if (!$this->getPlatform()->supportsInsertNullPk()) {
$script .= "
// remove pkey col since this table uses auto-increment and passing a null value for it is not valid
\$criteria->remove(" . $this->getColumnConstant($col) . ");
";
}
} elseif ($col->isPrimaryKey() && $col->isAutoIncrement() && $table->getIdMethod() != "none" && $table->isAllowPkInsert() && !$this->getPlatform()->supportsInsertNullPk()) {
$script .= "
// remove pkey col if it is null since this table does not accept that
if (\$criteria->containsKey(" . $this->getColumnConstant($col) . ") && !\$criteria->keyContainsValue(" . $this->getColumnConstant($col) . ") ) {
\$criteria->remove(" . $this->getColumnConstant($col) . ");
}
";
}
}
$script .= "
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
try {
// use transaction because \$criteria could contain info
// for more than one table (I guess, conceivably)
\$con->beginTransaction();
\$pk = " . $this->basePeerClassname . "::doInsert(\$criteria, \$con);
\$con->commit();
} catch (Exception \$e) {
\$con->rollBack();
throw \$e;
}
return \$pk;
}
";
} | [
"protected",
"function",
"addDoInsert",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Performs an INSERT on the database, given a \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" or Criteria object.\n *\n * @param mixed \\$values Criteria or \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object containing data that is used to create the INSERT statement.\n * @param PropelPDO \\$con the PropelPDO connection to use\n * @return mixed The new primary key.\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function doInsert(\\$values, PropelPDO \\$con = null)\n {\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_WRITE);\n }\n\n if (\\$values instanceof Criteria) {\n \\$criteria = clone \\$values; // rename for clarity\n } else {\n \\$criteria = \\$values->buildCriteria(); // build Criteria from \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object\n }\n\"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"$",
"cfc",
"=",
"$",
"col",
"->",
"getPhpName",
"(",
")",
";",
"if",
"(",
"$",
"col",
"->",
"isPrimaryKey",
"(",
")",
"&&",
"$",
"col",
"->",
"isAutoIncrement",
"(",
")",
"&&",
"$",
"table",
"->",
"getIdMethod",
"(",
")",
"!=",
"\"none\"",
"&&",
"!",
"$",
"table",
"->",
"isAllowPkInsert",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n if (\\$criteria->containsKey(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\") && \\$criteria->keyContainsValue(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\") ) {\n throw new PropelException('Cannot insert a value for auto-increment primary key ('.\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\".')');\n }\n\"",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"getPlatform",
"(",
")",
"->",
"supportsInsertNullPk",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n // remove pkey col since this table uses auto-increment and passing a null value for it is not valid\n \\$criteria->remove(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\");\n\"",
";",
"}",
"}",
"elseif",
"(",
"$",
"col",
"->",
"isPrimaryKey",
"(",
")",
"&&",
"$",
"col",
"->",
"isAutoIncrement",
"(",
")",
"&&",
"$",
"table",
"->",
"getIdMethod",
"(",
")",
"!=",
"\"none\"",
"&&",
"$",
"table",
"->",
"isAllowPkInsert",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"getPlatform",
"(",
")",
"->",
"supportsInsertNullPk",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n // remove pkey col if it is null since this table does not accept that\n if (\\$criteria->containsKey(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\") && !\\$criteria->keyContainsValue(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\") ) {\n \\$criteria->remove(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\");\n }\n\"",
";",
"}",
"}",
"$",
"script",
".=",
"\"\n\n // Set the correct dbName\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n\n try {\n // use transaction because \\$criteria could contain info\n // for more than one table (I guess, conceivably)\n \\$con->beginTransaction();\n \\$pk = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doInsert(\\$criteria, \\$con);\n \\$con->commit();\n } catch (Exception \\$e) {\n \\$con->rollBack();\n throw \\$e;\n }\n\n return \\$pk;\n }\n\"",
";",
"}"
] | Adds the doInsert() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doInsert",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1443-L1511 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoUpdate | protected function addDoUpdate(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Performs an UPDATE on the database, given a " . $this->getObjectClassname() . " or Criteria object.
*
* @param mixed \$values Criteria or " . $this->getObjectClassname() . " object containing data that is used to create the UPDATE statement.
* @param PropelPDO \$con The connection to use (specify PropelPDO connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate(\$values, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
\$selectCriteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$values instanceof Criteria) {
\$criteria = clone \$values; // rename for clarity
";
foreach ($table->getColumns() as $col) {
if ($col->isPrimaryKey()) {
$script .= "
\$comparison = \$criteria->getComparison(" . $this->getColumnConstant($col) . ");
\$value = \$criteria->remove(" . $this->getColumnConstant($col) . ");
if (\$value) {
\$selectCriteria->add(" . $this->getColumnConstant($col) . ", \$value, \$comparison);
} else {
\$selectCriteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
}
";
} /* if col is prim key */
} /* foreach */
$script .= "
} else { // \$values is " . $this->getObjectClassname() . " object
\$criteria = \$values->buildCriteria(); // gets full criteria
\$selectCriteria = \$values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
return {$this->basePeerClassname}::doUpdate(\$selectCriteria, \$criteria, \$con);
}
";
} | php | protected function addDoUpdate(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Performs an UPDATE on the database, given a " . $this->getObjectClassname() . " or Criteria object.
*
* @param mixed \$values Criteria or " . $this->getObjectClassname() . " object containing data that is used to create the UPDATE statement.
* @param PropelPDO \$con The connection to use (specify PropelPDO connection object to exert more control over transactions).
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doUpdate(\$values, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
\$selectCriteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$values instanceof Criteria) {
\$criteria = clone \$values; // rename for clarity
";
foreach ($table->getColumns() as $col) {
if ($col->isPrimaryKey()) {
$script .= "
\$comparison = \$criteria->getComparison(" . $this->getColumnConstant($col) . ");
\$value = \$criteria->remove(" . $this->getColumnConstant($col) . ");
if (\$value) {
\$selectCriteria->add(" . $this->getColumnConstant($col) . ", \$value, \$comparison);
} else {
\$selectCriteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
}
";
} /* if col is prim key */
} /* foreach */
$script .= "
} else { // \$values is " . $this->getObjectClassname() . " object
\$criteria = \$values->buildCriteria(); // gets full criteria
\$selectCriteria = \$values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
}
// set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
return {$this->basePeerClassname}::doUpdate(\$selectCriteria, \$criteria, \$con);
}
";
} | [
"protected",
"function",
"addDoUpdate",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Performs an UPDATE on the database, given a \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" or Criteria object.\n *\n * @param mixed \\$values Criteria or \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object containing data that is used to create the UPDATE statement.\n * @param PropelPDO \\$con The connection to use (specify PropelPDO connection object to exert more control over transactions).\n * @return int The number of affected rows (if supported by underlying database driver).\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function doUpdate(\\$values, PropelPDO \\$con = null)\n {\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_WRITE);\n }\n\n \\$selectCriteria = new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n\n if (\\$values instanceof Criteria) {\n \\$criteria = clone \\$values; // rename for clarity\n\"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"$",
"col",
"->",
"isPrimaryKey",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$comparison = \\$criteria->getComparison(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\");\n \\$value = \\$criteria->remove(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\");\n if (\\$value) {\n \\$selectCriteria->add(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\", \\$value, \\$comparison);\n } else {\n \\$selectCriteria->setPrimaryTableName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME);\n }\n\"",
";",
"}",
"/* if col is prim key */",
"}",
"/* foreach */",
"$",
"script",
".=",
"\"\n } else { // \\$values is \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object\n \\$criteria = \\$values->buildCriteria(); // gets full criteria\n \\$selectCriteria = \\$values->buildPkeyCriteria(); // gets criteria w/ primary key(s)\n }\n\n // set the correct dbName\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n\n return {$this->basePeerClassname}::doUpdate(\\$selectCriteria, \\$criteria, \\$con);\n }\n\"",
";",
"}"
] | Adds the doUpdate() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doUpdate",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1518-L1568 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoDeleteAll | protected function addDoDeleteAll(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Deletes all rows from the " . $table->getName() . " table.
*
* @param PropelPDO \$con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException
*/
public static function doDeleteAll(PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
\$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because \$criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
\$con->beginTransaction();
";
if ($this->isDeleteCascadeEmulationNeeded()) {
$script .= "\$affectedRows += " . $this->getPeerClassname() . "::doOnDeleteCascade(new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME), \$con);
";
}
if ($this->isDeleteSetNullEmulationNeeded()) {
$script .= $this->getPeerClassname() . "::doOnDeleteSetNull(new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME), \$con);
";
}
$script .= "\$affectedRows += {$this->basePeerClassname}::doDeleteAll(" . $this->getPeerClassname() . "::TABLE_NAME, \$con, " . $this->getPeerClassname() . "::DATABASE_NAME);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
" . $this->getPeerClassname() . "::clearInstancePool();
" . $this->getPeerClassname() . "::clearRelatedInstancePool();
\$con->commit();
return \$affectedRows;
} catch (Exception \$e) {
\$con->rollBack();
throw \$e;
}
}
";
} | php | protected function addDoDeleteAll(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Deletes all rows from the " . $table->getName() . " table.
*
* @param PropelPDO \$con the connection to use
* @return int The number of affected rows (if supported by underlying database driver).
* @throws PropelException
*/
public static function doDeleteAll(PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
\$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because \$criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
\$con->beginTransaction();
";
if ($this->isDeleteCascadeEmulationNeeded()) {
$script .= "\$affectedRows += " . $this->getPeerClassname() . "::doOnDeleteCascade(new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME), \$con);
";
}
if ($this->isDeleteSetNullEmulationNeeded()) {
$script .= $this->getPeerClassname() . "::doOnDeleteSetNull(new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME), \$con);
";
}
$script .= "\$affectedRows += {$this->basePeerClassname}::doDeleteAll(" . $this->getPeerClassname() . "::TABLE_NAME, \$con, " . $this->getPeerClassname() . "::DATABASE_NAME);
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
" . $this->getPeerClassname() . "::clearInstancePool();
" . $this->getPeerClassname() . "::clearRelatedInstancePool();
\$con->commit();
return \$affectedRows;
} catch (Exception \$e) {
\$con->rollBack();
throw \$e;
}
}
";
} | [
"protected",
"function",
"addDoDeleteAll",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Deletes all rows from the \"",
".",
"$",
"table",
"->",
"getName",
"(",
")",
".",
"\" table.\n *\n * @param PropelPDO \\$con the connection to use\n * @return int The number of affected rows (if supported by underlying database driver).\n * @throws PropelException\n */\n public static function doDeleteAll(PropelPDO \\$con = null)\n {\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_WRITE);\n }\n \\$affectedRows = 0; // initialize var to track total num of affected rows\n try {\n // use transaction because \\$criteria could contain info\n // for more than one table or we could emulating ON DELETE CASCADE, etc.\n \\$con->beginTransaction();\n \"",
";",
"if",
"(",
"$",
"this",
"->",
"isDeleteCascadeEmulationNeeded",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\\$affectedRows += \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doOnDeleteCascade(new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME), \\$con);\n \"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isDeleteSetNullEmulationNeeded",
"(",
")",
")",
"{",
"$",
"script",
".=",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doOnDeleteSetNull(new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME), \\$con);\n \"",
";",
"}",
"$",
"script",
".=",
"\"\\$affectedRows += {$this->basePeerClassname}::doDeleteAll(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME, \\$con, \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n // Because this db requires some delete cascade/set null emulation, we have to\n // clear the cached instance *after* the emulation has happened (since\n // instances get re-added by the select statement contained therein).\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::clearInstancePool();\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::clearRelatedInstancePool();\n \\$con->commit();\n\n return \\$affectedRows;\n } catch (Exception \\$e) {\n \\$con->rollBack();\n throw \\$e;\n }\n }\n\"",
";",
"}"
] | Adds the doDeleteAll() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doDeleteAll",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1575-L1620 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoDelete | protected function addDoDelete(&$script)
{
$table = $this->getTable();
$emulateCascade = $this->isDeleteCascadeEmulationNeeded() || $this->isDeleteSetNullEmulationNeeded();
$script .= "
/**
* Performs a DELETE on the database, given a " . $this->getObjectClassname() . " or Criteria object OR a primary key value.
*
* @param mixed \$values Criteria or " . $this->getObjectClassname() . " object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param PropelPDO \$con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete(\$values, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if (\$values instanceof Criteria) {";
if (!$emulateCascade) {
$script .= "
// invalidate the cache for all objects of this type, since we have no
// way of knowing (without running a query) what objects should be invalidated
// from the cache based on this Criteria.
" . $this->getPeerClassname() . "::clearInstancePool();";
}
$script .= "
// rename for clarity
\$criteria = clone \$values;
} elseif (\$values instanceof " . $this->getObjectClassname() . ") { // it's a model object";
if (!$emulateCascade) {
$script .= "
// invalidate the cache for this single object
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$values);";
}
if (count($table->getPrimaryKey()) > 0) {
$script .= "
// create criteria based on pk values
\$criteria = \$values->buildPkeyCriteria();";
} else {
$script .= "
// create criteria based on pk value
\$criteria = \$values->buildCriteria();";
}
$script .= "
} else { // it's a primary key, or an array of pks";
$script .= "
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
if (count($table->getPrimaryKey()) === 1) {
$pkey = $table->getPrimaryKey();
$col = array_shift($pkey);
$script .= "
\$criteria->add(" . $this->getColumnConstant($col) . ", (array) \$values, Criteria::IN);";
if (!$emulateCascade) {
$script .= "
// invalidate the cache for this object(s)
foreach ((array) \$values as \$singleval) {
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$singleval);
}";
}
} else {
$script .= "
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey values
if (count(\$values) == count(\$values, COUNT_RECURSIVE)) {
// array is not multi-dimensional
\$values = array(\$values);
}
foreach (\$values as \$value) {";
$i = 0;
foreach ($table->getPrimaryKey() as $col) {
if ($i == 0) {
$script .= "
\$criterion = \$criteria->getNewCriterion(" . $this->getColumnConstant($col) . ", \$value[$i]);";
} else {
$script .= "
\$criterion->addAnd(\$criteria->getNewCriterion(" . $this->getColumnConstant($col) . ", \$value[$i]));";
}
$i++;
}
$script .= "
\$criteria->addOr(\$criterion);";
if (!$emulateCascade) {
$script .= "
// we can invalidate the cache for this single PK
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$value);";
}
$script .= "
}";
} /* if count(table->getPrimaryKeys()) */
$script .= "
}
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because \$criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
\$con->beginTransaction();
";
if ($this->isDeleteCascadeEmulationNeeded()) {
$script .= "
// cloning the Criteria in case it's modified by doSelect() or doSelectStmt()
\$c = clone \$criteria;
\$affectedRows += " . $this->getPeerClassname() . "::doOnDeleteCascade(\$c, \$con);
";
}
if ($this->isDeleteSetNullEmulationNeeded()) {
$script .= "
// cloning the Criteria in case it's modified by doSelect() or doSelectStmt()
\$c = clone \$criteria;
" . $this->getPeerClassname() . "::doOnDeleteSetNull(\$c, \$con);
";
}
if ($emulateCascade) {
$script .= "
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
if (\$values instanceof Criteria) {
" . $this->getPeerClassname() . "::clearInstancePool();
} elseif (\$values instanceof " . $this->getObjectClassname() . ") { // it's a model object
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$values);
} else { // it's a primary key, or an array of pks
foreach ((array) \$values as \$singleval) {
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$singleval);
}
}
";
}
$script .= "
\$affectedRows += {$this->basePeerClassname}::doDelete(\$criteria, \$con);
" . $this->getPeerClassname() . "::clearRelatedInstancePool();
\$con->commit();
return \$affectedRows;
} catch (Exception \$e) {
\$con->rollBack();
throw \$e;
}
}
";
} | php | protected function addDoDelete(&$script)
{
$table = $this->getTable();
$emulateCascade = $this->isDeleteCascadeEmulationNeeded() || $this->isDeleteSetNullEmulationNeeded();
$script .= "
/**
* Performs a DELETE on the database, given a " . $this->getObjectClassname() . " or Criteria object OR a primary key value.
*
* @param mixed \$values Criteria or " . $this->getObjectClassname() . " object or primary key or array of primary keys
* which is used to create the DELETE statement
* @param PropelPDO \$con the connection to use
* @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
* if supported by native driver or if emulated using Propel.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doDelete(\$values, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_WRITE);
}
if (\$values instanceof Criteria) {";
if (!$emulateCascade) {
$script .= "
// invalidate the cache for all objects of this type, since we have no
// way of knowing (without running a query) what objects should be invalidated
// from the cache based on this Criteria.
" . $this->getPeerClassname() . "::clearInstancePool();";
}
$script .= "
// rename for clarity
\$criteria = clone \$values;
} elseif (\$values instanceof " . $this->getObjectClassname() . ") { // it's a model object";
if (!$emulateCascade) {
$script .= "
// invalidate the cache for this single object
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$values);";
}
if (count($table->getPrimaryKey()) > 0) {
$script .= "
// create criteria based on pk values
\$criteria = \$values->buildPkeyCriteria();";
} else {
$script .= "
// create criteria based on pk value
\$criteria = \$values->buildCriteria();";
}
$script .= "
} else { // it's a primary key, or an array of pks";
$script .= "
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
if (count($table->getPrimaryKey()) === 1) {
$pkey = $table->getPrimaryKey();
$col = array_shift($pkey);
$script .= "
\$criteria->add(" . $this->getColumnConstant($col) . ", (array) \$values, Criteria::IN);";
if (!$emulateCascade) {
$script .= "
// invalidate the cache for this object(s)
foreach ((array) \$values as \$singleval) {
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$singleval);
}";
}
} else {
$script .= "
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey values
if (count(\$values) == count(\$values, COUNT_RECURSIVE)) {
// array is not multi-dimensional
\$values = array(\$values);
}
foreach (\$values as \$value) {";
$i = 0;
foreach ($table->getPrimaryKey() as $col) {
if ($i == 0) {
$script .= "
\$criterion = \$criteria->getNewCriterion(" . $this->getColumnConstant($col) . ", \$value[$i]);";
} else {
$script .= "
\$criterion->addAnd(\$criteria->getNewCriterion(" . $this->getColumnConstant($col) . ", \$value[$i]));";
}
$i++;
}
$script .= "
\$criteria->addOr(\$criterion);";
if (!$emulateCascade) {
$script .= "
// we can invalidate the cache for this single PK
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$value);";
}
$script .= "
}";
} /* if count(table->getPrimaryKeys()) */
$script .= "
}
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$affectedRows = 0; // initialize var to track total num of affected rows
try {
// use transaction because \$criteria could contain info
// for more than one table or we could emulating ON DELETE CASCADE, etc.
\$con->beginTransaction();
";
if ($this->isDeleteCascadeEmulationNeeded()) {
$script .= "
// cloning the Criteria in case it's modified by doSelect() or doSelectStmt()
\$c = clone \$criteria;
\$affectedRows += " . $this->getPeerClassname() . "::doOnDeleteCascade(\$c, \$con);
";
}
if ($this->isDeleteSetNullEmulationNeeded()) {
$script .= "
// cloning the Criteria in case it's modified by doSelect() or doSelectStmt()
\$c = clone \$criteria;
" . $this->getPeerClassname() . "::doOnDeleteSetNull(\$c, \$con);
";
}
if ($emulateCascade) {
$script .= "
// Because this db requires some delete cascade/set null emulation, we have to
// clear the cached instance *after* the emulation has happened (since
// instances get re-added by the select statement contained therein).
if (\$values instanceof Criteria) {
" . $this->getPeerClassname() . "::clearInstancePool();
} elseif (\$values instanceof " . $this->getObjectClassname() . ") { // it's a model object
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$values);
} else { // it's a primary key, or an array of pks
foreach ((array) \$values as \$singleval) {
" . $this->getPeerClassname() . "::removeInstanceFromPool(\$singleval);
}
}
";
}
$script .= "
\$affectedRows += {$this->basePeerClassname}::doDelete(\$criteria, \$con);
" . $this->getPeerClassname() . "::clearRelatedInstancePool();
\$con->commit();
return \$affectedRows;
} catch (Exception \$e) {
\$con->rollBack();
throw \$e;
}
}
";
} | [
"protected",
"function",
"addDoDelete",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"emulateCascade",
"=",
"$",
"this",
"->",
"isDeleteCascadeEmulationNeeded",
"(",
")",
"||",
"$",
"this",
"->",
"isDeleteSetNullEmulationNeeded",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Performs a DELETE on the database, given a \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" or Criteria object OR a primary key value.\n *\n * @param mixed \\$values Criteria or \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object or primary key or array of primary keys\n * which is used to create the DELETE statement\n * @param PropelPDO \\$con the connection to use\n * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows\n *\t\t\t\tif supported by native driver or if emulated using Propel.\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function doDelete(\\$values, PropelPDO \\$con = null)\n {\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_WRITE);\n }\n\n if (\\$values instanceof Criteria) {\"",
";",
"if",
"(",
"!",
"$",
"emulateCascade",
")",
"{",
"$",
"script",
".=",
"\"\n // invalidate the cache for all objects of this type, since we have no\n // way of knowing (without running a query) what objects should be invalidated\n // from the cache based on this Criteria.\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::clearInstancePool();\"",
";",
"}",
"$",
"script",
".=",
"\"\n // rename for clarity\n \\$criteria = clone \\$values;\n } elseif (\\$values instanceof \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\") { // it's a model object\"",
";",
"if",
"(",
"!",
"$",
"emulateCascade",
")",
"{",
"$",
"script",
".=",
"\"\n // invalidate the cache for this single object\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::removeInstanceFromPool(\\$values);\"",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"script",
".=",
"\"\n // create criteria based on pk values\n \\$criteria = \\$values->buildPkeyCriteria();\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n // create criteria based on pk value\n \\$criteria = \\$values->buildCriteria();\"",
";",
"}",
"$",
"script",
".=",
"\"\n } else { // it's a primary key, or an array of pks\"",
";",
"$",
"script",
".=",
"\"\n \\$criteria = new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\"",
";",
"if",
"(",
"count",
"(",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
")",
"===",
"1",
")",
"{",
"$",
"pkey",
"=",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"col",
"=",
"array_shift",
"(",
"$",
"pkey",
")",
";",
"$",
"script",
".=",
"\"\n \\$criteria->add(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\", (array) \\$values, Criteria::IN);\"",
";",
"if",
"(",
"!",
"$",
"emulateCascade",
")",
"{",
"$",
"script",
".=",
"\"\n // invalidate the cache for this object(s)\n foreach ((array) \\$values as \\$singleval) {\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::removeInstanceFromPool(\\$singleval);\n }\"",
";",
"}",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n // primary key is composite; we therefore, expect\n // the primary key passed to be an array of pkey values\n if (count(\\$values) == count(\\$values, COUNT_RECURSIVE)) {\n // array is not multi-dimensional\n \\$values = array(\\$values);\n }\n foreach (\\$values as \\$value) {\"",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"$",
"i",
"==",
"0",
")",
"{",
"$",
"script",
".=",
"\"\n \\$criterion = \\$criteria->getNewCriterion(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\", \\$value[$i]);\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$criterion->addAnd(\\$criteria->getNewCriterion(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\", \\$value[$i]));\"",
";",
"}",
"$",
"i",
"++",
";",
"}",
"$",
"script",
".=",
"\"\n \\$criteria->addOr(\\$criterion);\"",
";",
"if",
"(",
"!",
"$",
"emulateCascade",
")",
"{",
"$",
"script",
".=",
"\"\n // we can invalidate the cache for this single PK\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::removeInstanceFromPool(\\$value);\"",
";",
"}",
"$",
"script",
".=",
"\"\n }\"",
";",
"}",
"/* if count(table->getPrimaryKeys()) */",
"$",
"script",
".=",
"\"\n }\n\n // Set the correct dbName\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n\n \\$affectedRows = 0; // initialize var to track total num of affected rows\n\n try {\n // use transaction because \\$criteria could contain info\n // for more than one table or we could emulating ON DELETE CASCADE, etc.\n \\$con->beginTransaction();\n \"",
";",
"if",
"(",
"$",
"this",
"->",
"isDeleteCascadeEmulationNeeded",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n // cloning the Criteria in case it's modified by doSelect() or doSelectStmt()\n \\$c = clone \\$criteria;\n \\$affectedRows += \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doOnDeleteCascade(\\$c, \\$con);\n \"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isDeleteSetNullEmulationNeeded",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n // cloning the Criteria in case it's modified by doSelect() or doSelectStmt()\n \\$c = clone \\$criteria;\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doOnDeleteSetNull(\\$c, \\$con);\n \"",
";",
"}",
"if",
"(",
"$",
"emulateCascade",
")",
"{",
"$",
"script",
".=",
"\"\n // Because this db requires some delete cascade/set null emulation, we have to\n // clear the cached instance *after* the emulation has happened (since\n // instances get re-added by the select statement contained therein).\n if (\\$values instanceof Criteria) {\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::clearInstancePool();\n } elseif (\\$values instanceof \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\") { // it's a model object\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::removeInstanceFromPool(\\$values);\n } else { // it's a primary key, or an array of pks\n foreach ((array) \\$values as \\$singleval) {\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::removeInstanceFromPool(\\$singleval);\n }\n }\n \"",
";",
"}",
"$",
"script",
".=",
"\"\n \\$affectedRows += {$this->basePeerClassname}::doDelete(\\$criteria, \\$con);\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::clearRelatedInstancePool();\n \\$con->commit();\n\n return \\$affectedRows;\n } catch (Exception \\$e) {\n \\$con->rollBack();\n throw \\$e;\n }\n }\n\"",
";",
"}"
] | Adds the doDelete() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doDelete",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1627-L1782 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoOnDeleteCascade | protected function addDoOnDeleteCascade(&$script)
{
$table = $this->getTable();
$script .= "
/**
* This is a method for emulating ON DELETE CASCADE for DBs that don't support this
* feature (like MySQL or SQLite).
*
* This method is not very speedy because it must perform a query first to get
* the implicated records and then perform the deletes by calling those Peer classes.
*
* This method should be used within a transaction if possible.
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @return int The number of affected rows (if supported by underlying database driver).
*/
protected static function doOnDeleteCascade(Criteria \$criteria, PropelPDO \$con)
{
// initialize var to track total num of affected rows
\$affectedRows = 0;
// first find the objects that are implicated by the \$criteria
\$objects = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
foreach (\$objects as \$obj) {
";
foreach ($table->getReferrers() as $fk) {
// $fk is the foreign key in the other table, so localTableName will
// actually be the table name of other table
$tblFK = $fk->getTable();
$joinedTablePeerBuilder = $this->getNewPeerBuilder($tblFK);
$tblFKPackage = $joinedTablePeerBuilder->getStubPeerBuilder()->getPackage();
if (!$tblFK->isForReferenceOnly()) {
// we can't perform operations on tables that are
// not within the schema (i.e. that we have no map for, etc.)
$fkClassName = $joinedTablePeerBuilder->getObjectClassname();
if ($fk->getOnDelete() == ForeignKey::CASCADE) {
// backwards on purpose
$columnNamesF = $fk->getLocalColumns();
$columnNamesL = $fk->getForeignColumns();
$script .= "
// delete related $fkClassName objects
\$criteria = new Criteria(" . $joinedTablePeerBuilder->getPeerClassname() . "::DATABASE_NAME);
";
for ($x = 0, $xlen = count($columnNamesF); $x < $xlen; $x++) {
$columnFK = $tblFK->getColumn($columnNamesF[$x]);
$columnL = $table->getColumn($columnNamesL[$x]);
$script .= "
\$criteria->add(" . $joinedTablePeerBuilder->getColumnConstant($columnFK) . ", \$obj->get" . $columnL->getPhpName() . "());";
}
$script .= "
\$affectedRows += " . $joinedTablePeerBuilder->getPeerClassname() . "::doDelete(\$criteria, \$con);";
} // if cascade && fkey table name != curr table name
} // if not for ref only
} // foreach foreign keys
$script .= "
}
return \$affectedRows;
}
";
} | php | protected function addDoOnDeleteCascade(&$script)
{
$table = $this->getTable();
$script .= "
/**
* This is a method for emulating ON DELETE CASCADE for DBs that don't support this
* feature (like MySQL or SQLite).
*
* This method is not very speedy because it must perform a query first to get
* the implicated records and then perform the deletes by calling those Peer classes.
*
* This method should be used within a transaction if possible.
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @return int The number of affected rows (if supported by underlying database driver).
*/
protected static function doOnDeleteCascade(Criteria \$criteria, PropelPDO \$con)
{
// initialize var to track total num of affected rows
\$affectedRows = 0;
// first find the objects that are implicated by the \$criteria
\$objects = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
foreach (\$objects as \$obj) {
";
foreach ($table->getReferrers() as $fk) {
// $fk is the foreign key in the other table, so localTableName will
// actually be the table name of other table
$tblFK = $fk->getTable();
$joinedTablePeerBuilder = $this->getNewPeerBuilder($tblFK);
$tblFKPackage = $joinedTablePeerBuilder->getStubPeerBuilder()->getPackage();
if (!$tblFK->isForReferenceOnly()) {
// we can't perform operations on tables that are
// not within the schema (i.e. that we have no map for, etc.)
$fkClassName = $joinedTablePeerBuilder->getObjectClassname();
if ($fk->getOnDelete() == ForeignKey::CASCADE) {
// backwards on purpose
$columnNamesF = $fk->getLocalColumns();
$columnNamesL = $fk->getForeignColumns();
$script .= "
// delete related $fkClassName objects
\$criteria = new Criteria(" . $joinedTablePeerBuilder->getPeerClassname() . "::DATABASE_NAME);
";
for ($x = 0, $xlen = count($columnNamesF); $x < $xlen; $x++) {
$columnFK = $tblFK->getColumn($columnNamesF[$x]);
$columnL = $table->getColumn($columnNamesL[$x]);
$script .= "
\$criteria->add(" . $joinedTablePeerBuilder->getColumnConstant($columnFK) . ", \$obj->get" . $columnL->getPhpName() . "());";
}
$script .= "
\$affectedRows += " . $joinedTablePeerBuilder->getPeerClassname() . "::doDelete(\$criteria, \$con);";
} // if cascade && fkey table name != curr table name
} // if not for ref only
} // foreach foreign keys
$script .= "
}
return \$affectedRows;
}
";
} | [
"protected",
"function",
"addDoOnDeleteCascade",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * This is a method for emulating ON DELETE CASCADE for DBs that don't support this\n * feature (like MySQL or SQLite).\n *\n * This method is not very speedy because it must perform a query first to get\n * the implicated records and then perform the deletes by calling those Peer classes.\n *\n * This method should be used within a transaction if possible.\n *\n * @param Criteria \\$criteria\n * @param PropelPDO \\$con\n * @return int The number of affected rows (if supported by underlying database driver).\n */\n protected static function doOnDeleteCascade(Criteria \\$criteria, PropelPDO \\$con)\n {\n // initialize var to track total num of affected rows\n \\$affectedRows = 0;\n\n // first find the objects that are implicated by the \\$criteria\n \\$objects = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doSelect(\\$criteria, \\$con);\n foreach (\\$objects as \\$obj) {\n\"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getReferrers",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"// $fk is the foreign key in the other table, so localTableName will",
"// actually be the table name of other table",
"$",
"tblFK",
"=",
"$",
"fk",
"->",
"getTable",
"(",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"tblFK",
")",
";",
"$",
"tblFKPackage",
"=",
"$",
"joinedTablePeerBuilder",
"->",
"getStubPeerBuilder",
"(",
")",
"->",
"getPackage",
"(",
")",
";",
"if",
"(",
"!",
"$",
"tblFK",
"->",
"isForReferenceOnly",
"(",
")",
")",
"{",
"// we can't perform operations on tables that are",
"// not within the schema (i.e. that we have no map for, etc.)",
"$",
"fkClassName",
"=",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"if",
"(",
"$",
"fk",
"->",
"getOnDelete",
"(",
")",
"==",
"ForeignKey",
"::",
"CASCADE",
")",
"{",
"// backwards on purpose",
"$",
"columnNamesF",
"=",
"$",
"fk",
"->",
"getLocalColumns",
"(",
")",
";",
"$",
"columnNamesL",
"=",
"$",
"fk",
"->",
"getForeignColumns",
"(",
")",
";",
"$",
"script",
".=",
"\"\n\n // delete related $fkClassName objects\n \\$criteria = new Criteria(\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n \"",
";",
"for",
"(",
"$",
"x",
"=",
"0",
",",
"$",
"xlen",
"=",
"count",
"(",
"$",
"columnNamesF",
")",
";",
"$",
"x",
"<",
"$",
"xlen",
";",
"$",
"x",
"++",
")",
"{",
"$",
"columnFK",
"=",
"$",
"tblFK",
"->",
"getColumn",
"(",
"$",
"columnNamesF",
"[",
"$",
"x",
"]",
")",
";",
"$",
"columnL",
"=",
"$",
"table",
"->",
"getColumn",
"(",
"$",
"columnNamesL",
"[",
"$",
"x",
"]",
")",
";",
"$",
"script",
".=",
"\"\n \\$criteria->add(\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getColumnConstant",
"(",
"$",
"columnFK",
")",
".",
"\", \\$obj->get\"",
".",
"$",
"columnL",
"->",
"getPhpName",
"(",
")",
".",
"\"());\"",
";",
"}",
"$",
"script",
".=",
"\"\n \\$affectedRows += \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doDelete(\\$criteria, \\$con);\"",
";",
"}",
"// if cascade && fkey table name != curr table name",
"}",
"// if not for ref only",
"}",
"// foreach foreign keys",
"$",
"script",
".=",
"\"\n }\n\n return \\$affectedRows;\n }\n\"",
";",
"}"
] | Adds the doOnDeleteCascade() method, which provides ON DELETE CASCADE emulation.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doOnDeleteCascade",
"()",
"method",
"which",
"provides",
"ON",
"DELETE",
"CASCADE",
"emulation",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1789-L1862 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoOnDeleteSetNull | protected function addDoOnDeleteSetNull(&$script)
{
$table = $this->getTable();
$script .= "
/**
* This is a method for emulating ON DELETE SET NULL DBs that don't support this
* feature (like MySQL or SQLite).
*
* This method is not very speedy because it must perform a query first to get
* the implicated records and then perform the deletes by calling those Peer classes.
*
* This method should be used within a transaction if possible.
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @return void
*/
protected static function doOnDeleteSetNull(Criteria \$criteria, PropelPDO \$con)
{
// first find the objects that are implicated by the \$criteria
\$objects = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
foreach (\$objects as \$obj) {
";
// This logic is almost exactly the same as that in doOnDeleteCascade()
// it may make sense to refactor this, provided that things don't
// get too complicated.
foreach ($table->getReferrers() as $fk) {
// $fk is the foreign key in the other table, so localTableName will
// actually be the table name of other table
$tblFK = $fk->getTable();
$refTablePeerBuilder = $this->getNewPeerBuilder($tblFK);
if (!$tblFK->isForReferenceOnly()) {
// we can't perform operations on tables that are
// not within the schema (i.e. that we have no map for, etc.)
$fkClassName = $refTablePeerBuilder->getObjectClassname();
if ($fk->getOnDelete() == ForeignKey::SETNULL) {
// backwards on purpose
$columnNamesF = $fk->getLocalColumns();
$columnNamesL = $fk->getForeignColumns(); // should be same num as foreign
$script .= "
// set fkey col in related $fkClassName rows to null
\$selectCriteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$updateValues = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
for ($x = 0, $xlen = count($columnNamesF); $x < $xlen; $x++) {
$columnFK = $tblFK->getColumn($columnNamesF[$x]);
$columnL = $table->getColumn($columnNamesL[$x]);
$script .= "
\$selectCriteria->add(" . $refTablePeerBuilder->getColumnConstant($columnFK) . ", \$obj->get" . $columnL->getPhpName() . "());
\$updateValues->add(" . $refTablePeerBuilder->getColumnConstant($columnFK) . ", null);
";
}
$script .= "
{$this->basePeerClassname}::doUpdate(\$selectCriteria, \$updateValues, \$con); // use BasePeer because generated Peer doUpdate() methods only update using pkey
";
} // if setnull && fkey table name != curr table name
} // if not for ref only
} // foreach foreign keys
$script .= "
}
}
";
} | php | protected function addDoOnDeleteSetNull(&$script)
{
$table = $this->getTable();
$script .= "
/**
* This is a method for emulating ON DELETE SET NULL DBs that don't support this
* feature (like MySQL or SQLite).
*
* This method is not very speedy because it must perform a query first to get
* the implicated records and then perform the deletes by calling those Peer classes.
*
* This method should be used within a transaction if possible.
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @return void
*/
protected static function doOnDeleteSetNull(Criteria \$criteria, PropelPDO \$con)
{
// first find the objects that are implicated by the \$criteria
\$objects = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
foreach (\$objects as \$obj) {
";
// This logic is almost exactly the same as that in doOnDeleteCascade()
// it may make sense to refactor this, provided that things don't
// get too complicated.
foreach ($table->getReferrers() as $fk) {
// $fk is the foreign key in the other table, so localTableName will
// actually be the table name of other table
$tblFK = $fk->getTable();
$refTablePeerBuilder = $this->getNewPeerBuilder($tblFK);
if (!$tblFK->isForReferenceOnly()) {
// we can't perform operations on tables that are
// not within the schema (i.e. that we have no map for, etc.)
$fkClassName = $refTablePeerBuilder->getObjectClassname();
if ($fk->getOnDelete() == ForeignKey::SETNULL) {
// backwards on purpose
$columnNamesF = $fk->getLocalColumns();
$columnNamesL = $fk->getForeignColumns(); // should be same num as foreign
$script .= "
// set fkey col in related $fkClassName rows to null
\$selectCriteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$updateValues = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
for ($x = 0, $xlen = count($columnNamesF); $x < $xlen; $x++) {
$columnFK = $tblFK->getColumn($columnNamesF[$x]);
$columnL = $table->getColumn($columnNamesL[$x]);
$script .= "
\$selectCriteria->add(" . $refTablePeerBuilder->getColumnConstant($columnFK) . ", \$obj->get" . $columnL->getPhpName() . "());
\$updateValues->add(" . $refTablePeerBuilder->getColumnConstant($columnFK) . ", null);
";
}
$script .= "
{$this->basePeerClassname}::doUpdate(\$selectCriteria, \$updateValues, \$con); // use BasePeer because generated Peer doUpdate() methods only update using pkey
";
} // if setnull && fkey table name != curr table name
} // if not for ref only
} // foreach foreign keys
$script .= "
}
}
";
} | [
"protected",
"function",
"addDoOnDeleteSetNull",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * This is a method for emulating ON DELETE SET NULL DBs that don't support this\n * feature (like MySQL or SQLite).\n *\n * This method is not very speedy because it must perform a query first to get\n * the implicated records and then perform the deletes by calling those Peer classes.\n *\n * This method should be used within a transaction if possible.\n *\n * @param Criteria \\$criteria\n * @param PropelPDO \\$con\n * @return void\n */\n protected static function doOnDeleteSetNull(Criteria \\$criteria, PropelPDO \\$con)\n {\n\n // first find the objects that are implicated by the \\$criteria\n \\$objects = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doSelect(\\$criteria, \\$con);\n foreach (\\$objects as \\$obj) {\n\"",
";",
"// This logic is almost exactly the same as that in doOnDeleteCascade()",
"// it may make sense to refactor this, provided that things don't",
"// get too complicated.",
"foreach",
"(",
"$",
"table",
"->",
"getReferrers",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"// $fk is the foreign key in the other table, so localTableName will",
"// actually be the table name of other table",
"$",
"tblFK",
"=",
"$",
"fk",
"->",
"getTable",
"(",
")",
";",
"$",
"refTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"tblFK",
")",
";",
"if",
"(",
"!",
"$",
"tblFK",
"->",
"isForReferenceOnly",
"(",
")",
")",
"{",
"// we can't perform operations on tables that are",
"// not within the schema (i.e. that we have no map for, etc.)",
"$",
"fkClassName",
"=",
"$",
"refTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"if",
"(",
"$",
"fk",
"->",
"getOnDelete",
"(",
")",
"==",
"ForeignKey",
"::",
"SETNULL",
")",
"{",
"// backwards on purpose",
"$",
"columnNamesF",
"=",
"$",
"fk",
"->",
"getLocalColumns",
"(",
")",
";",
"$",
"columnNamesL",
"=",
"$",
"fk",
"->",
"getForeignColumns",
"(",
")",
";",
"// should be same num as foreign",
"$",
"script",
".=",
"\"\n // set fkey col in related $fkClassName rows to null\n \\$selectCriteria = new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n \\$updateValues = new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\"",
";",
"for",
"(",
"$",
"x",
"=",
"0",
",",
"$",
"xlen",
"=",
"count",
"(",
"$",
"columnNamesF",
")",
";",
"$",
"x",
"<",
"$",
"xlen",
";",
"$",
"x",
"++",
")",
"{",
"$",
"columnFK",
"=",
"$",
"tblFK",
"->",
"getColumn",
"(",
"$",
"columnNamesF",
"[",
"$",
"x",
"]",
")",
";",
"$",
"columnL",
"=",
"$",
"table",
"->",
"getColumn",
"(",
"$",
"columnNamesL",
"[",
"$",
"x",
"]",
")",
";",
"$",
"script",
".=",
"\"\n \\$selectCriteria->add(\"",
".",
"$",
"refTablePeerBuilder",
"->",
"getColumnConstant",
"(",
"$",
"columnFK",
")",
".",
"\", \\$obj->get\"",
".",
"$",
"columnL",
"->",
"getPhpName",
"(",
")",
".",
"\"());\n \\$updateValues->add(\"",
".",
"$",
"refTablePeerBuilder",
"->",
"getColumnConstant",
"(",
"$",
"columnFK",
")",
".",
"\", null);\n\"",
";",
"}",
"$",
"script",
".=",
"\"\n {$this->basePeerClassname}::doUpdate(\\$selectCriteria, \\$updateValues, \\$con); // use BasePeer because generated Peer doUpdate() methods only update using pkey\n\"",
";",
"}",
"// if setnull && fkey table name != curr table name",
"}",
"// if not for ref only",
"}",
"// foreach foreign keys",
"$",
"script",
".=",
"\"\n }\n }\n\"",
";",
"}"
] | Adds the doOnDeleteSetNull() method, which provides ON DELETE SET NULL emulation.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doOnDeleteSetNull",
"()",
"method",
"which",
"provides",
"ON",
"DELETE",
"SET",
"NULL",
"emulation",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1869-L1941 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoValidate | protected function addDoValidate(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Validates all modified columns of given " . $this->getObjectClassname() . " object.
* If parameter \$columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param " . $this->getObjectClassname() . " \$obj The object to validate.
* @param mixed \$cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(\$obj, \$cols = null)
{
\$columns = array();
if (\$cols) {
\$dbMap = Propel::getDatabaseMap(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$tableMap = \$dbMap->getTable(" . $this->getPeerClassname() . "::TABLE_NAME);
if (! is_array(\$cols)) {
\$cols = array(\$cols);
}
foreach (\$cols as \$colName) {
if (\$tableMap->hasColumn(\$colName)) {
\$get = 'get' . \$tableMap->getColumn(\$colName)->getPhpName();
\$columns[\$colName] = \$obj->\$get();
}
}
} else {
";
foreach ($table->getValidators() as $val) {
$col = $val->getColumn();
if (!$col->isAutoIncrement()) {
$script .= "
if (\$obj->isNew() || \$obj->isColumnModified(" . $this->getColumnConstant($col) . "))
\$columns[" . $this->getColumnConstant($col) . "] = \$obj->get" . $col->getPhpName() . "();
";
} // if
} // foreach
$script .= "
}
return {$this->basePeerClassname}::doValidate(" . $this->getPeerClassname() . "::DATABASE_NAME, " . $this->getPeerClassname() . "::TABLE_NAME, \$columns);
}
";
} | php | protected function addDoValidate(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Validates all modified columns of given " . $this->getObjectClassname() . " object.
* If parameter \$columns is either a single column name or an array of column names
* than only those columns are validated.
*
* NOTICE: This does not apply to primary or foreign keys for now.
*
* @param " . $this->getObjectClassname() . " \$obj The object to validate.
* @param mixed \$cols Column name or array of column names.
*
* @return mixed TRUE if all columns are valid or the error message of the first invalid column.
*/
public static function doValidate(\$obj, \$cols = null)
{
\$columns = array();
if (\$cols) {
\$dbMap = Propel::getDatabaseMap(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$tableMap = \$dbMap->getTable(" . $this->getPeerClassname() . "::TABLE_NAME);
if (! is_array(\$cols)) {
\$cols = array(\$cols);
}
foreach (\$cols as \$colName) {
if (\$tableMap->hasColumn(\$colName)) {
\$get = 'get' . \$tableMap->getColumn(\$colName)->getPhpName();
\$columns[\$colName] = \$obj->\$get();
}
}
} else {
";
foreach ($table->getValidators() as $val) {
$col = $val->getColumn();
if (!$col->isAutoIncrement()) {
$script .= "
if (\$obj->isNew() || \$obj->isColumnModified(" . $this->getColumnConstant($col) . "))
\$columns[" . $this->getColumnConstant($col) . "] = \$obj->get" . $col->getPhpName() . "();
";
} // if
} // foreach
$script .= "
}
return {$this->basePeerClassname}::doValidate(" . $this->getPeerClassname() . "::DATABASE_NAME, " . $this->getPeerClassname() . "::TABLE_NAME, \$columns);
}
";
} | [
"protected",
"function",
"addDoValidate",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Validates all modified columns of given \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" object.\n * If parameter \\$columns is either a single column name or an array of column names\n * than only those columns are validated.\n *\n * NOTICE: This does not apply to primary or foreign keys for now.\n *\n * @param \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" \\$obj The object to validate.\n * @param mixed \\$cols Column name or array of column names.\n *\n * @return mixed TRUE if all columns are valid or the error message of the first invalid column.\n */\n public static function doValidate(\\$obj, \\$cols = null)\n {\n \\$columns = array();\n\n if (\\$cols) {\n \\$dbMap = Propel::getDatabaseMap(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n \\$tableMap = \\$dbMap->getTable(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME);\n\n if (! is_array(\\$cols)) {\n \\$cols = array(\\$cols);\n }\n\n foreach (\\$cols as \\$colName) {\n if (\\$tableMap->hasColumn(\\$colName)) {\n \\$get = 'get' . \\$tableMap->getColumn(\\$colName)->getPhpName();\n \\$columns[\\$colName] = \\$obj->\\$get();\n }\n }\n } else {\n\"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getValidators",
"(",
")",
"as",
"$",
"val",
")",
"{",
"$",
"col",
"=",
"$",
"val",
"->",
"getColumn",
"(",
")",
";",
"if",
"(",
"!",
"$",
"col",
"->",
"isAutoIncrement",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n if (\\$obj->isNew() || \\$obj->isColumnModified(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\"))\n \\$columns[\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\"] = \\$obj->get\"",
".",
"$",
"col",
"->",
"getPhpName",
"(",
")",
".",
"\"();\n\"",
";",
"}",
"// if",
"}",
"// foreach",
"$",
"script",
".=",
"\"\n }\n\n return {$this->basePeerClassname}::doValidate(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME, \\$columns);\n }\n\"",
";",
"}"
] | Adds the doValidate() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doValidate",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L1948-L2000 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addRetrieveByPK_SinglePK | protected function addRetrieveByPK_SinglePK(&$script)
{
$table = $this->getTable();
$pks = $table->getPrimaryKey();
$col = $pks[0];
$script .= "
/**
* Retrieve a single object by pkey.
*
* @param " . $col->getPhpType() . " \$pk the primary key.
* @param PropelPDO \$con the connection to use
* @return " . $this->getObjectClassname() . "
*/
public static function " . $this->getRetrieveMethodName() . "(\$pk, PropelPDO \$con = null)
{
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(" . $this->getInstancePoolKeySnippet('$pk') . "))) {
return \$obj;
}
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$criteria->add(" . $this->getColumnConstant($col) . ", \$pk);
\$v = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
return !empty(\$v) > 0 ? \$v[0] : null;
}
";
} | php | protected function addRetrieveByPK_SinglePK(&$script)
{
$table = $this->getTable();
$pks = $table->getPrimaryKey();
$col = $pks[0];
$script .= "
/**
* Retrieve a single object by pkey.
*
* @param " . $col->getPhpType() . " \$pk the primary key.
* @param PropelPDO \$con the connection to use
* @return " . $this->getObjectClassname() . "
*/
public static function " . $this->getRetrieveMethodName() . "(\$pk, PropelPDO \$con = null)
{
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(" . $this->getInstancePoolKeySnippet('$pk') . "))) {
return \$obj;
}
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);
\$criteria->add(" . $this->getColumnConstant($col) . ", \$pk);
\$v = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
return !empty(\$v) > 0 ? \$v[0] : null;
}
";
} | [
"protected",
"function",
"addRetrieveByPK_SinglePK",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"pks",
"=",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"col",
"=",
"$",
"pks",
"[",
"0",
"]",
";",
"$",
"script",
".=",
"\"\n /**\n * Retrieve a single object by pkey.\n *\n * @param \"",
".",
"$",
"col",
"->",
"getPhpType",
"(",
")",
".",
"\" \\$pk the primary key.\n * @param PropelPDO \\$con the connection to use\n * @return \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\"\n */\n public static function \"",
".",
"$",
"this",
"->",
"getRetrieveMethodName",
"(",
")",
".",
"\"(\\$pk, PropelPDO \\$con = null)\n {\n\n if (null !== (\\$obj = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\"",
".",
"$",
"this",
"->",
"getInstancePoolKeySnippet",
"(",
"'$pk'",
")",
".",
"\"))) {\n return \\$obj;\n }\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n\n \\$criteria = new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n \\$criteria->add(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\", \\$pk);\n\n \\$v = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doSelect(\\$criteria, \\$con);\n\n return !empty(\\$v) > 0 ? \\$v[0] : null;\n }\n\"",
";",
"}"
] | Adds the retrieveByPK method for tables with single-column primary key.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"retrieveByPK",
"method",
"for",
"tables",
"with",
"single",
"-",
"column",
"primary",
"key",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2007-L2040 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addRetrieveByPKs_SinglePK | protected function addRetrieveByPKs_SinglePK(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Retrieve multiple objects by pkey.
*
* @param array \$pks List of primary keys
* @param PropelPDO \$con the connection to use
* @return " . $this->getObjectClassname() . "[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function " . $this->getRetrieveMethodName() . "s(\$pks, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
\$objs = null;
if (empty(\$pks)) {
\$objs = array();
} else {
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
$k1 = $table->getPrimaryKey();
$script .= "
\$criteria->add(" . $this->getColumnConstant($k1[0]) . ", \$pks, Criteria::IN);";
$script .= "
\$objs = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
}
return \$objs;
}
";
} | php | protected function addRetrieveByPKs_SinglePK(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Retrieve multiple objects by pkey.
*
* @param array \$pks List of primary keys
* @param PropelPDO \$con the connection to use
* @return " . $this->getObjectClassname() . "[]
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function " . $this->getRetrieveMethodName() . "s(\$pks, PropelPDO \$con = null)
{
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
\$objs = null;
if (empty(\$pks)) {
\$objs = array();
} else {
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
$k1 = $table->getPrimaryKey();
$script .= "
\$criteria->add(" . $this->getColumnConstant($k1[0]) . ", \$pks, Criteria::IN);";
$script .= "
\$objs = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
}
return \$objs;
}
";
} | [
"protected",
"function",
"addRetrieveByPKs_SinglePK",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Retrieve multiple objects by pkey.\n *\n * @param array \\$pks List of primary keys\n * @param PropelPDO \\$con the connection to use\n * @return \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\"[]\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function \"",
".",
"$",
"this",
"->",
"getRetrieveMethodName",
"(",
")",
".",
"\"s(\\$pks, PropelPDO \\$con = null)\n {\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n\n \\$objs = null;\n if (empty(\\$pks)) {\n \\$objs = array();\n } else {\n \\$criteria = new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\"",
";",
"$",
"k1",
"=",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
";",
"$",
"script",
".=",
"\"\n \\$criteria->add(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"k1",
"[",
"0",
"]",
")",
".",
"\", \\$pks, Criteria::IN);\"",
";",
"$",
"script",
".=",
"\"\n \\$objs = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doSelect(\\$criteria, \\$con);\n }\n\n return \\$objs;\n }\n\"",
";",
"}"
] | Adds the retrieveByPKs method for tables with single-column primary key.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"retrieveByPKs",
"method",
"for",
"tables",
"with",
"single",
"-",
"column",
"primary",
"key",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2047-L2081 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addRetrieveByPK_MultiPK | protected function addRetrieveByPK_MultiPK(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Retrieve object using using composite pkey values.";
foreach ($table->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$cptype = $col->getPhpType();
$script .= "
* @param $cptype $" . $clo;
}
$script .= "
* @param PropelPDO \$con
* @return " . $this->getObjectClassname() . "
*/
public static function " . $this->getRetrieveMethodName() . "(";
$php = array();
foreach ($table->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$php[] = '$' . $clo;
} /* foreach */
$script .= implode(', ', $php);
$script .= ", PropelPDO \$con = null) {
\$_instancePoolKey = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(\$_instancePoolKey))) {
return \$obj;
}
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
foreach ($table->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$script .= "
\$criteria->add(" . $this->getColumnConstant($col) . ", $" . $clo . ");";
}
$script .= "
\$v = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
return !empty(\$v) ? \$v[0] : null;
}";
} | php | protected function addRetrieveByPK_MultiPK(&$script)
{
$table = $this->getTable();
$script .= "
/**
* Retrieve object using using composite pkey values.";
foreach ($table->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$cptype = $col->getPhpType();
$script .= "
* @param $cptype $" . $clo;
}
$script .= "
* @param PropelPDO \$con
* @return " . $this->getObjectClassname() . "
*/
public static function " . $this->getRetrieveMethodName() . "(";
$php = array();
foreach ($table->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$php[] = '$' . $clo;
} /* foreach */
$script .= implode(', ', $php);
$script .= ", PropelPDO \$con = null) {
\$_instancePoolKey = " . $this->getInstancePoolKeySnippet($php) . ";";
$script .= "
if (null !== (\$obj = " . $this->getPeerClassname() . "::getInstanceFromPool(\$_instancePoolKey))) {
return \$obj;
}
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
\$criteria = new Criteria(" . $this->getPeerClassname() . "::DATABASE_NAME);";
foreach ($table->getPrimaryKey() as $col) {
$clo = strtolower($col->getName());
$script .= "
\$criteria->add(" . $this->getColumnConstant($col) . ", $" . $clo . ");";
}
$script .= "
\$v = " . $this->getPeerClassname() . "::doSelect(\$criteria, \$con);
return !empty(\$v) ? \$v[0] : null;
}";
} | [
"protected",
"function",
"addRetrieveByPK_MultiPK",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"script",
".=",
"\"\n /**\n * Retrieve object using using composite pkey values.\"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
"as",
"$",
"col",
")",
"{",
"$",
"clo",
"=",
"strtolower",
"(",
"$",
"col",
"->",
"getName",
"(",
")",
")",
";",
"$",
"cptype",
"=",
"$",
"col",
"->",
"getPhpType",
"(",
")",
";",
"$",
"script",
".=",
"\"\n * @param $cptype $\"",
".",
"$",
"clo",
";",
"}",
"$",
"script",
".=",
"\"\n * @param PropelPDO \\$con\n * @return \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\"\n */\n public static function \"",
".",
"$",
"this",
"->",
"getRetrieveMethodName",
"(",
")",
".",
"\"(\"",
";",
"$",
"php",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
"as",
"$",
"col",
")",
"{",
"$",
"clo",
"=",
"strtolower",
"(",
"$",
"col",
"->",
"getName",
"(",
")",
")",
";",
"$",
"php",
"[",
"]",
"=",
"'$'",
".",
"$",
"clo",
";",
"}",
"/* foreach */",
"$",
"script",
".=",
"implode",
"(",
"', '",
",",
"$",
"php",
")",
";",
"$",
"script",
".=",
"\", PropelPDO \\$con = null) {\n \\$_instancePoolKey = \"",
".",
"$",
"this",
"->",
"getInstancePoolKeySnippet",
"(",
"$",
"php",
")",
".",
"\";\"",
";",
"$",
"script",
".=",
"\"\n if (null !== (\\$obj = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$_instancePoolKey))) {\n return \\$obj;\n }\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n \\$criteria = new Criteria(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getPrimaryKey",
"(",
")",
"as",
"$",
"col",
")",
"{",
"$",
"clo",
"=",
"strtolower",
"(",
"$",
"col",
"->",
"getName",
"(",
")",
")",
";",
"$",
"script",
".=",
"\"\n \\$criteria->add(\"",
".",
"$",
"this",
"->",
"getColumnConstant",
"(",
"$",
"col",
")",
".",
"\", $\"",
".",
"$",
"clo",
".",
"\");\"",
";",
"}",
"$",
"script",
".=",
"\"\n \\$v = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::doSelect(\\$criteria, \\$con);\n\n return !empty(\\$v) ? \\$v[0] : null;\n }\"",
";",
"}"
] | Adds the retrieveByPK method for tables with multi-column primary key.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"retrieveByPK",
"method",
"for",
"tables",
"with",
"multi",
"-",
"column",
"primary",
"key",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2088-L2135 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addSelectMethods | protected function addSelectMethods(&$script)
{
$table = $this->getTable();
parent::addSelectMethods($script);
$this->addEnumMethods($script);
$this->addDoCountJoin($script);
$this->addDoSelectJoin($script);
$countFK = count($table->getForeignKeys());
$includeJoinAll = true;
foreach ($this->getTable()->getForeignKeys() as $fk) {
$tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
$this->declareClassFromBuilder($this->getNewStubPeerBuilder($tblFK));
if ($tblFK->isForReferenceOnly()) {
$includeJoinAll = false;
}
}
if ($includeJoinAll) {
if ($countFK > 0) {
$this->addDoCountJoinAll($script);
$this->addDoSelectJoinAll($script);
}
if ($countFK > 1) {
$this->addDoCountJoinAllExcept($script);
$this->addDoSelectJoinAllExcept($script);
}
}
} | php | protected function addSelectMethods(&$script)
{
$table = $this->getTable();
parent::addSelectMethods($script);
$this->addEnumMethods($script);
$this->addDoCountJoin($script);
$this->addDoSelectJoin($script);
$countFK = count($table->getForeignKeys());
$includeJoinAll = true;
foreach ($this->getTable()->getForeignKeys() as $fk) {
$tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
$this->declareClassFromBuilder($this->getNewStubPeerBuilder($tblFK));
if ($tblFK->isForReferenceOnly()) {
$includeJoinAll = false;
}
}
if ($includeJoinAll) {
if ($countFK > 0) {
$this->addDoCountJoinAll($script);
$this->addDoSelectJoinAll($script);
}
if ($countFK > 1) {
$this->addDoCountJoinAllExcept($script);
$this->addDoSelectJoinAllExcept($script);
}
}
} | [
"protected",
"function",
"addSelectMethods",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"parent",
"::",
"addSelectMethods",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addEnumMethods",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDoCountJoin",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDoSelectJoin",
"(",
"$",
"script",
")",
";",
"$",
"countFK",
"=",
"count",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
")",
";",
"$",
"includeJoinAll",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"$",
"tblFK",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"this",
"->",
"declareClassFromBuilder",
"(",
"$",
"this",
"->",
"getNewStubPeerBuilder",
"(",
"$",
"tblFK",
")",
")",
";",
"if",
"(",
"$",
"tblFK",
"->",
"isForReferenceOnly",
"(",
")",
")",
"{",
"$",
"includeJoinAll",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"includeJoinAll",
")",
"{",
"if",
"(",
"$",
"countFK",
">",
"0",
")",
"{",
"$",
"this",
"->",
"addDoCountJoinAll",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDoSelectJoinAll",
"(",
"$",
"script",
")",
";",
"}",
"if",
"(",
"$",
"countFK",
">",
"1",
")",
"{",
"$",
"this",
"->",
"addDoCountJoinAllExcept",
"(",
"$",
"script",
")",
";",
"$",
"this",
"->",
"addDoSelectJoinAllExcept",
"(",
"$",
"script",
")",
";",
"}",
"}",
"}"
] | Adds the complex OM methods to the base addSelectMethods() function.
@param string &$script The script will be modified in this method.
@see PeerBuilder::addSelectMethods() | [
"Adds",
"the",
"complex",
"OM",
"methods",
"to",
"the",
"base",
"addSelectMethods",
"()",
"function",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2166-L2198 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.getPrimaryKeyColOffsets | protected function getPrimaryKeyColOffsets(Table $tbl)
{
$offsets = array();
$idx = 0;
foreach ($tbl->getColumns() as $col) {
if ($col->isPrimaryKey()) {
$offsets[] = $idx;
}
$idx++;
}
return $offsets;
} | php | protected function getPrimaryKeyColOffsets(Table $tbl)
{
$offsets = array();
$idx = 0;
foreach ($tbl->getColumns() as $col) {
if ($col->isPrimaryKey()) {
$offsets[] = $idx;
}
$idx++;
}
return $offsets;
} | [
"protected",
"function",
"getPrimaryKeyColOffsets",
"(",
"Table",
"$",
"tbl",
")",
"{",
"$",
"offsets",
"=",
"array",
"(",
")",
";",
"$",
"idx",
"=",
"0",
";",
"foreach",
"(",
"$",
"tbl",
"->",
"getColumns",
"(",
")",
"as",
"$",
"col",
")",
"{",
"if",
"(",
"$",
"col",
"->",
"isPrimaryKey",
"(",
")",
")",
"{",
"$",
"offsets",
"[",
"]",
"=",
"$",
"idx",
";",
"}",
"$",
"idx",
"++",
";",
"}",
"return",
"$",
"offsets",
";",
"}"
] | Get the column offsets of the primary key(s) for specified table.
@param Table $tbl
@return array int[] The column offsets of the primary key(s). | [
"Get",
"the",
"column",
"offsets",
"of",
"the",
"primary",
"key",
"(",
"s",
")",
"for",
"specified",
"table",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2207-L2219 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoSelectJoin | protected function addDoSelectJoin(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$countFK = count($table->getForeignKeys());
$join_behavior = $this->getJoinBehavior();
if ($countFK >= 1) {
foreach ($table->getForeignKeys() as $fk) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
if (!$joinTable->isForReferenceOnly()) {
// This condition is necessary because Propel lacks a system for
// aliasing the table if it is the same table.
if ($fk->getForeignTableName() != $table->getName()) {
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Selects a collection of $className objects pre-filled with their $joinClassName objects.
* @param Criteria \$criteria
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return array Array of $className objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoin" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$con = null, \$join_behavior = $join_behavior)
{
\$criteria = clone \$criteria;
// Set the correct dbName if it has not been overridden
if (\$criteria->getDbName() == Propel::getDefaultDB()) {
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
}
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
" . $joinedTablePeerBuilder->getPeerClassname() . "::addSelectColumns(\$criteria);
";
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
\$results = array();
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key1 = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj1 = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj1->hydrate(\$row, 0, true); // rehydrate
} else {
";
if ($table->getChildrenColumn()) {
$script .= "
\$omClass = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj1', '$cls') . "
\$obj1->hydrate(\$row);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj1, \$key1);
} // if \$obj1 already loaded
\$key2 = " . $joinedTablePeerBuilder->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol);
if (\$key2 !== null) {
\$obj2 = " . $joinedTablePeerBuilder->getPeerClassname() . "::getInstanceFromPool(\$key2);
if (!\$obj2) {
";
if ($joinTable->getChildrenColumn()) {
$script .= "
\$omClass = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass(\$row, \$startcol);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj2', '$cls') . "
\$obj2->hydrate(\$row, \$startcol);
" . $joinedTablePeerBuilder->getPeerClassname() . "::addInstanceToPool(\$obj2, \$key2);
} // if obj2 already loaded
// Add the \$obj1 (" . $this->getObjectClassname() . ") to \$obj2 (" . $joinedTablePeerBuilder->getObjectClassname() . ")";
if ($fk->isLocalPrimaryKey()) {
$script .= "
// one to one relationship
\$obj1->set" . $joinedTablePeerBuilder->getObjectClassname() . "(\$obj2);";
} else {
$script .= "
\$obj2->add" . $joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false) . "(\$obj1);";
}
$script .= "
} // if joined row was not null
\$results[] = \$obj1;
}
\$stmt->closeCursor();
return \$results;
}
";
} // if fk table name != this table name
} // if ! is reference only
} // foreach column
} // if count(fk) > 1
} | php | protected function addDoSelectJoin(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$countFK = count($table->getForeignKeys());
$join_behavior = $this->getJoinBehavior();
if ($countFK >= 1) {
foreach ($table->getForeignKeys() as $fk) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
if (!$joinTable->isForReferenceOnly()) {
// This condition is necessary because Propel lacks a system for
// aliasing the table if it is the same table.
if ($fk->getForeignTableName() != $table->getName()) {
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Selects a collection of $className objects pre-filled with their $joinClassName objects.
* @param Criteria \$criteria
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return array Array of $className objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoin" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$con = null, \$join_behavior = $join_behavior)
{
\$criteria = clone \$criteria;
// Set the correct dbName if it has not been overridden
if (\$criteria->getDbName() == Propel::getDefaultDB()) {
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
}
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
" . $joinedTablePeerBuilder->getPeerClassname() . "::addSelectColumns(\$criteria);
";
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
\$results = array();
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key1 = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj1 = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj1->hydrate(\$row, 0, true); // rehydrate
} else {
";
if ($table->getChildrenColumn()) {
$script .= "
\$omClass = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj1', '$cls') . "
\$obj1->hydrate(\$row);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj1, \$key1);
} // if \$obj1 already loaded
\$key2 = " . $joinedTablePeerBuilder->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol);
if (\$key2 !== null) {
\$obj2 = " . $joinedTablePeerBuilder->getPeerClassname() . "::getInstanceFromPool(\$key2);
if (!\$obj2) {
";
if ($joinTable->getChildrenColumn()) {
$script .= "
\$omClass = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass(\$row, \$startcol);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj2', '$cls') . "
\$obj2->hydrate(\$row, \$startcol);
" . $joinedTablePeerBuilder->getPeerClassname() . "::addInstanceToPool(\$obj2, \$key2);
} // if obj2 already loaded
// Add the \$obj1 (" . $this->getObjectClassname() . ") to \$obj2 (" . $joinedTablePeerBuilder->getObjectClassname() . ")";
if ($fk->isLocalPrimaryKey()) {
$script .= "
// one to one relationship
\$obj1->set" . $joinedTablePeerBuilder->getObjectClassname() . "(\$obj2);";
} else {
$script .= "
\$obj2->add" . $joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false) . "(\$obj1);";
}
$script .= "
} // if joined row was not null
\$results[] = \$obj1;
}
\$stmt->closeCursor();
return \$results;
}
";
} // if fk table name != this table name
} // if ! is reference only
} // foreach column
} // if count(fk) > 1
} | [
"protected",
"function",
"addDoSelectJoin",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"countFK",
"=",
"count",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
")",
";",
"$",
"join_behavior",
"=",
"$",
"this",
"->",
"getJoinBehavior",
"(",
")",
";",
"if",
"(",
"$",
"countFK",
">=",
"1",
")",
"{",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"joinTable",
"->",
"isForReferenceOnly",
"(",
")",
")",
"{",
"// This condition is necessary because Propel lacks a system for",
"// aliasing the table if it is the same table.",
"if",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"thisTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"table",
")",
";",
"$",
"joinedTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinedTableObjectBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"script",
".=",
"\"\n\n /**\n * Selects a collection of $className objects pre-filled with their $joinClassName objects.\n * @param Criteria \\$criteria\n * @param PropelPDO \\$con\n * @param String \\$join_behavior the type of joins to use, defaults to $join_behavior\n * @return array Array of $className objects.\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function doSelectJoin\"",
".",
"$",
"thisTableObjectBuilder",
"->",
"getFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\"(Criteria \\$criteria, \\$con = null, \\$join_behavior = $join_behavior)\n {\n \\$criteria = clone \\$criteria;\n\n // Set the correct dbName if it has not been overridden\n if (\\$criteria->getDbName() == Propel::getDefaultDB()) {\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n }\n\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n \\$startcol = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::NUM_HYDRATE_COLUMNS;\n \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n\"",
";",
"$",
"script",
".=",
"$",
"this",
"->",
"addCriteriaJoin",
"(",
"$",
"fk",
",",
"$",
"table",
",",
"$",
"joinTable",
",",
"$",
"joinedTablePeerBuilder",
")",
";",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"$",
"script",
".=",
"\"\n \\$stmt = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doSelect(\\$criteria, \\$con);\n \\$results = array();\n\n while (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$key1 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, 0);\n if (null !== (\\$obj1 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key1))) {\n // We no longer rehydrate the object, since this can cause data loss.\n // See http://www.propelorm.org/ticket/509\n // \\$obj1->hydrate(\\$row, 0, true); // rehydrate\n } else {\n\"",
";",
"if",
"(",
"$",
"table",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$omClass = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, 0);\n \\$cls = substr('.'.\\$omClass, strrpos('.'.\\$omClass, '.') + 1);\n\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass();\n\"",
";",
"}",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj1'",
",",
"'$cls'",
")",
".",
"\"\n \\$obj1->hydrate(\\$row);\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj1, \\$key1);\n } // if \\$obj1 already loaded\n\n \\$key2 = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, \\$startcol);\n if (\\$key2 !== null) {\n \\$obj2 = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key2);\n if (!\\$obj2) {\n\"",
";",
"if",
"(",
"$",
"joinTable",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$omClass = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, \\$startcol);\n \\$cls = substr('.'.\\$omClass, strrpos('.'.\\$omClass, '.') + 1);\n\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass();\n\"",
";",
"}",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj2'",
",",
"'$cls'",
")",
".",
"\"\n \\$obj2->hydrate(\\$row, \\$startcol);\n \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj2, \\$key2);\n } // if obj2 already loaded\n\n // Add the \\$obj1 (\"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\") to \\$obj2 (\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
".",
"\")\"",
";",
"if",
"(",
"$",
"fk",
"->",
"isLocalPrimaryKey",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n // one to one relationship\n \\$obj1->set\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
".",
"\"(\\$obj2);\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$obj2->add\"",
".",
"$",
"joinedTableObjectBuilder",
"->",
"getRefFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\"(\\$obj1);\"",
";",
"}",
"$",
"script",
".=",
"\"\n\n } // if joined row was not null\n\n \\$results[] = \\$obj1;\n }\n \\$stmt->closeCursor();\n\n return \\$results;\n }\n\"",
";",
"}",
"// if fk table name != this table name",
"}",
"// if ! is reference only",
"}",
"// foreach column",
"}",
"// if count(fk) > 1",
"}"
] | Adds the doSelectJoin*() methods.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doSelectJoin",
"*",
"()",
"methods",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2253-L2383 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoCountJoin | protected function addDoCountJoin(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$countFK = count($table->getForeignKeys());
$join_behavior = $this->getJoinBehavior();
if ($countFK >= 1) {
foreach ($table->getForeignKeys() as $fk) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
if (!$joinTable->isForReferenceOnly()) {
if ($fk->getForeignTableName() != $table->getName()) {
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Returns the number of rows matching criteria, joining the related " . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . " table
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return int Number of matching rows.
*/
public static function doCountJoin" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null, \$join_behavior = $join_behavior)
{
// we're going to modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
";
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}
";
} // if fk table name != this table name
} // if ! is reference only
} // foreach column
} // if count(fk) > 1
} | php | protected function addDoCountJoin(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$countFK = count($table->getForeignKeys());
$join_behavior = $this->getJoinBehavior();
if ($countFK >= 1) {
foreach ($table->getForeignKeys() as $fk) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
if (!$joinTable->isForReferenceOnly()) {
if ($fk->getForeignTableName() != $table->getName()) {
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Returns the number of rows matching criteria, joining the related " . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . " table
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return int Number of matching rows.
*/
public static function doCountJoin" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null, \$join_behavior = $join_behavior)
{
// we're going to modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
";
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}
";
} // if fk table name != this table name
} // if ! is reference only
} // foreach column
} // if count(fk) > 1
} | [
"protected",
"function",
"addDoCountJoin",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"countFK",
"=",
"count",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
")",
";",
"$",
"join_behavior",
"=",
"$",
"this",
"->",
"getJoinBehavior",
"(",
")",
";",
"if",
"(",
"$",
"countFK",
">=",
"1",
")",
"{",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"joinTable",
"->",
"isForReferenceOnly",
"(",
")",
")",
"{",
"if",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"thisTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"table",
")",
";",
"$",
"joinedTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinedTableObjectBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"script",
".=",
"\"\n\n /**\n * Returns the number of rows matching criteria, joining the related \"",
".",
"$",
"thisTableObjectBuilder",
"->",
"getFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\" table\n *\n * @param Criteria \\$criteria\n * @param boolean \\$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.\n * @param PropelPDO \\$con\n * @param String \\$join_behavior the type of joins to use, defaults to $join_behavior\n * @return int Number of matching rows.\n */\n public static function doCountJoin\"",
".",
"$",
"thisTableObjectBuilder",
"->",
"getFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\"(Criteria \\$criteria, \\$distinct = false, PropelPDO \\$con = null, \\$join_behavior = $join_behavior)\n {\n // we're going to modify criteria, so copy it first\n \\$criteria = clone \\$criteria;\n\n // We need to set the primary table name, since in the case that there are no WHERE columns\n // it will be impossible for the BasePeer::createSelectSql() method to determine which\n // tables go into the FROM clause.\n \\$criteria->setPrimaryTableName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME);\n\n if (\\$distinct && !in_array(Criteria::DISTINCT, \\$criteria->getSelectModifiers())) {\n \\$criteria->setDistinct();\n }\n\n if (!\\$criteria->hasSelectClause()) {\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n }\n\n \\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count\n\n // Set the correct dbName\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n\"",
";",
"$",
"script",
".=",
"$",
"this",
"->",
"addCriteriaJoin",
"(",
"$",
"fk",
",",
"$",
"table",
",",
"$",
"joinTable",
",",
"$",
"joinedTablePeerBuilder",
")",
";",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"$",
"script",
".=",
"\"\n \\$stmt = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doCount(\\$criteria, \\$con);\n\n if (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$count = (int) \\$row[0];\n } else {\n \\$count = 0; // no rows returned; we infer that means 0 matches.\n }\n \\$stmt->closeCursor();\n\n return \\$count;\n }\n\"",
";",
"}",
"// if fk table name != this table name",
"}",
"// if ! is reference only",
"}",
"// foreach column",
"}",
"// if count(fk) > 1",
"}"
] | Adds the doCountJoin*() methods.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doCountJoin",
"*",
"()",
"methods",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2390-L2474 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoSelectJoinAll | protected function addDoSelectJoinAll(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$join_behavior = $this->getJoinBehavior();
$script .= "
/**
* Selects a collection of $className objects pre-filled with all related objects.
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return array Array of $className objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAll(Criteria \$criteria, \$con = null, \$join_behavior = $join_behavior)
{
\$criteria = clone \$criteria;
// Set the correct dbName if it has not been overridden
if (\$criteria->getDbName() == Propel::getDefaultDB()) {
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
}
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol2 = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = 2;
foreach ($table->getForeignKeys() as $fk) {
// Want to cover this case, but the code is not there yet.
// Propel lacks a system for aliasing tables of the same name.
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$new_index = $index + 1;
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTablePeerBuilder->getObjectClassname();
$script .= "
" . $joinedTablePeerBuilder->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol$new_index = \$startcol$index + " . $joinedTablePeerBuilder->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = $new_index;
} // if fk->getForeignTableName != table->getName
} // foreach [sub] foreign keys
foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet.
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
}
}
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
\$results = array();
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key1 = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj1 = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj1->hydrate(\$row, 0, true); // rehydrate
} else {";
if ($table->getChildrenColumn()) {
$script .= "
\$omClass = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj1', '$cls') . "
\$obj1->hydrate(\$row);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj1, \$key1);
} // if obj1 already loaded
";
$index = 1;
foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet.
// Why not? -because we'd have to alias the tables in the JOIN
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$interfaceName = $joinClassName;
if ($joinTable->getInterface()) {
$interfaceName = $this->prefixClassname($joinTable->getInterface());
}
$index++;
$script .= "
// Add objects for joined $joinClassName rows
\$key$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol$index);
if (\$key$index !== null) {
\$obj$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getInstanceFromPool(\$key$index);
if (!\$obj$index) {
";
if ($joinTable->getChildrenColumn()) {
$script .= "
\$omClass = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass(\$row, \$startcol$index);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass();
";
} /* $joinTable->getChildrenColumn() */
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj' . $index, '$cls') . "
\$obj" . $index . "->hydrate(\$row, \$startcol$index);
" . $joinedTablePeerBuilder->getPeerClassname() . "::addInstanceToPool(\$obj$index, \$key$index);
} // if obj$index loaded
// Add the \$obj1 (" . $this->getObjectClassname() . ") to the collection in \$obj" . $index . " (" . $joinedTablePeerBuilder->getObjectClassname() . ")";
if ($fk->isLocalPrimaryKey()) {
$script .= "
\$obj1->set" . $joinedTablePeerBuilder->getObjectClassname() . "(\$obj" . $index . ");";
} else {
$script .= "
\$obj" . $index . "->add" . $joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false) . "(\$obj1);";
}
$script .= "
} // if joined row not null
";
} // $fk->getForeignTableName() != $table->getName()
} //foreach foreign key
$script .= "
\$results[] = \$obj1;
}
\$stmt->closeCursor();
return \$results;
}
";
} | php | protected function addDoSelectJoinAll(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$join_behavior = $this->getJoinBehavior();
$script .= "
/**
* Selects a collection of $className objects pre-filled with all related objects.
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return array Array of $className objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAll(Criteria \$criteria, \$con = null, \$join_behavior = $join_behavior)
{
\$criteria = clone \$criteria;
// Set the correct dbName if it has not been overridden
if (\$criteria->getDbName() == Propel::getDefaultDB()) {
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
}
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol2 = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = 2;
foreach ($table->getForeignKeys() as $fk) {
// Want to cover this case, but the code is not there yet.
// Propel lacks a system for aliasing tables of the same name.
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$new_index = $index + 1;
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTablePeerBuilder->getObjectClassname();
$script .= "
" . $joinedTablePeerBuilder->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol$new_index = \$startcol$index + " . $joinedTablePeerBuilder->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = $new_index;
} // if fk->getForeignTableName != table->getName
} // foreach [sub] foreign keys
foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet.
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
}
}
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
\$results = array();
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key1 = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj1 = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj1->hydrate(\$row, 0, true); // rehydrate
} else {";
if ($table->getChildrenColumn()) {
$script .= "
\$omClass = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj1', '$cls') . "
\$obj1->hydrate(\$row);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj1, \$key1);
} // if obj1 already loaded
";
$index = 1;
foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet.
// Why not? -because we'd have to alias the tables in the JOIN
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$interfaceName = $joinClassName;
if ($joinTable->getInterface()) {
$interfaceName = $this->prefixClassname($joinTable->getInterface());
}
$index++;
$script .= "
// Add objects for joined $joinClassName rows
\$key$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol$index);
if (\$key$index !== null) {
\$obj$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getInstanceFromPool(\$key$index);
if (!\$obj$index) {
";
if ($joinTable->getChildrenColumn()) {
$script .= "
\$omClass = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass(\$row, \$startcol$index);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass();
";
} /* $joinTable->getChildrenColumn() */
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj' . $index, '$cls') . "
\$obj" . $index . "->hydrate(\$row, \$startcol$index);
" . $joinedTablePeerBuilder->getPeerClassname() . "::addInstanceToPool(\$obj$index, \$key$index);
} // if obj$index loaded
// Add the \$obj1 (" . $this->getObjectClassname() . ") to the collection in \$obj" . $index . " (" . $joinedTablePeerBuilder->getObjectClassname() . ")";
if ($fk->isLocalPrimaryKey()) {
$script .= "
\$obj1->set" . $joinedTablePeerBuilder->getObjectClassname() . "(\$obj" . $index . ");";
} else {
$script .= "
\$obj" . $index . "->add" . $joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false) . "(\$obj1);";
}
$script .= "
} // if joined row not null
";
} // $fk->getForeignTableName() != $table->getName()
} //foreach foreign key
$script .= "
\$results[] = \$obj1;
}
\$stmt->closeCursor();
return \$results;
}
";
} | [
"protected",
"function",
"addDoSelectJoinAll",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"join_behavior",
"=",
"$",
"this",
"->",
"getJoinBehavior",
"(",
")",
";",
"$",
"script",
".=",
"\"\n\n /**\n * Selects a collection of $className objects pre-filled with all related objects.\n *\n * @param Criteria \\$criteria\n * @param PropelPDO \\$con\n * @param String \\$join_behavior the type of joins to use, defaults to $join_behavior\n * @return array Array of $className objects.\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function doSelectJoinAll(Criteria \\$criteria, \\$con = null, \\$join_behavior = $join_behavior)\n {\n \\$criteria = clone \\$criteria;\n\n // Set the correct dbName if it has not been overridden\n if (\\$criteria->getDbName() == Propel::getDefaultDB()) {\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n }\n\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n \\$startcol2 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::NUM_HYDRATE_COLUMNS;\n\"",
";",
"$",
"index",
"=",
"2",
";",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"// Want to cover this case, but the code is not there yet.",
"// Propel lacks a system for aliasing tables of the same name.",
"if",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"new_index",
"=",
"$",
"index",
"+",
"1",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n \\$startcol$new_index = \\$startcol$index + \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::NUM_HYDRATE_COLUMNS;\n\"",
";",
"$",
"index",
"=",
"$",
"new_index",
";",
"}",
"// if fk->getForeignTableName != table->getName",
"}",
"// foreach [sub] foreign keys",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"// want to cover this case, but the code is not there yet.",
"if",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"script",
".=",
"$",
"this",
"->",
"addCriteriaJoin",
"(",
"$",
"fk",
",",
"$",
"table",
",",
"$",
"joinTable",
",",
"$",
"joinedTablePeerBuilder",
")",
";",
"}",
"}",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"$",
"script",
".=",
"\"\n \\$stmt = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doSelect(\\$criteria, \\$con);\n \\$results = array();\n\n while (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$key1 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, 0);\n if (null !== (\\$obj1 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key1))) {\n // We no longer rehydrate the object, since this can cause data loss.\n // See http://www.propelorm.org/ticket/509\n // \\$obj1->hydrate(\\$row, 0, true); // rehydrate\n } else {\"",
";",
"if",
"(",
"$",
"table",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$omClass = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, 0);\n \\$cls = substr('.'.\\$omClass, strrpos('.'.\\$omClass, '.') + 1);\n\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass();\n\"",
";",
"}",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj1'",
",",
"'$cls'",
")",
".",
"\"\n \\$obj1->hydrate(\\$row);\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj1, \\$key1);\n } // if obj1 already loaded\n\"",
";",
"$",
"index",
"=",
"1",
";",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"// want to cover this case, but the code is not there yet.",
"// Why not? -because we'd have to alias the tables in the JOIN",
"if",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"thisTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"table",
")",
";",
"$",
"joinedTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinedTableObjectBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"interfaceName",
"=",
"$",
"joinClassName",
";",
"if",
"(",
"$",
"joinTable",
"->",
"getInterface",
"(",
")",
")",
"{",
"$",
"interfaceName",
"=",
"$",
"this",
"->",
"prefixClassname",
"(",
"$",
"joinTable",
"->",
"getInterface",
"(",
")",
")",
";",
"}",
"$",
"index",
"++",
";",
"$",
"script",
".=",
"\"\n // Add objects for joined $joinClassName rows\n\n \\$key$index = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, \\$startcol$index);\n if (\\$key$index !== null) {\n \\$obj$index = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key$index);\n if (!\\$obj$index) {\n\"",
";",
"if",
"(",
"$",
"joinTable",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$omClass = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, \\$startcol$index);\n \\$cls = substr('.'.\\$omClass, strrpos('.'.\\$omClass, '.') + 1);\n\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass();\n\"",
";",
"}",
"/* $joinTable->getChildrenColumn() */",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj'",
".",
"$",
"index",
",",
"'$cls'",
")",
".",
"\"\n \\$obj\"",
".",
"$",
"index",
".",
"\"->hydrate(\\$row, \\$startcol$index);\n \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj$index, \\$key$index);\n } // if obj$index loaded\n\n // Add the \\$obj1 (\"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\") to the collection in \\$obj\"",
".",
"$",
"index",
".",
"\" (\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
".",
"\")\"",
";",
"if",
"(",
"$",
"fk",
"->",
"isLocalPrimaryKey",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$obj1->set\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
".",
"\"(\\$obj\"",
".",
"$",
"index",
".",
"\");\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$obj\"",
".",
"$",
"index",
".",
"\"->add\"",
".",
"$",
"joinedTableObjectBuilder",
"->",
"getRefFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\"(\\$obj1);\"",
";",
"}",
"$",
"script",
".=",
"\"\n } // if joined row not null\n\"",
";",
"}",
"// $fk->getForeignTableName() != $table->getName()",
"}",
"//foreach foreign key",
"$",
"script",
".=",
"\"\n \\$results[] = \\$obj1;\n }\n \\$stmt->closeCursor();\n\n return \\$results;\n }\n\"",
";",
"}"
] | Adds the doSelectJoinAll() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doSelectJoinAll",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2481-L2641 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoCountJoinAll | protected function addDoCountJoinAll(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$join_behavior = $this->getJoinBehavior();
$script .= "
/**
* Returns the number of rows matching criteria, joining all related tables
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return int Number of matching rows.
*/
public static function doCountJoinAll(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null, \$join_behavior = $join_behavior)
{
// we're going to modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
";
foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet.
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
} // if fk->getForeignTableName != table->getName
} // foreach [sub] foreign keys
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}";
} | php | protected function addDoCountJoinAll(&$script)
{
$table = $this->getTable();
$className = $this->getObjectClassname();
$join_behavior = $this->getJoinBehavior();
$script .= "
/**
* Returns the number of rows matching criteria, joining all related tables
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return int Number of matching rows.
*/
public static function doCountJoinAll(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null, \$join_behavior = $join_behavior)
{
// we're going to modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
";
foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet.
if ($fk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$script .= $this->addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder);
} // if fk->getForeignTableName != table->getName
} // foreach [sub] foreign keys
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}";
} | [
"protected",
"function",
"addDoCountJoinAll",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"join_behavior",
"=",
"$",
"this",
"->",
"getJoinBehavior",
"(",
")",
";",
"$",
"script",
".=",
"\"\n\n /**\n * Returns the number of rows matching criteria, joining all related tables\n *\n * @param Criteria \\$criteria\n * @param boolean \\$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.\n * @param PropelPDO \\$con\n * @param String \\$join_behavior the type of joins to use, defaults to $join_behavior\n * @return int Number of matching rows.\n */\n public static function doCountJoinAll(Criteria \\$criteria, \\$distinct = false, PropelPDO \\$con = null, \\$join_behavior = $join_behavior)\n {\n // we're going to modify criteria, so copy it first\n \\$criteria = clone \\$criteria;\n\n // We need to set the primary table name, since in the case that there are no WHERE columns\n // it will be impossible for the BasePeer::createSelectSql() method to determine which\n // tables go into the FROM clause.\n \\$criteria->setPrimaryTableName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME);\n\n if (\\$distinct && !in_array(Criteria::DISTINCT, \\$criteria->getSelectModifiers())) {\n \\$criteria->setDistinct();\n }\n\n if (!\\$criteria->hasSelectClause()) {\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n }\n\n \\$criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count\n\n // Set the correct dbName\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n\"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"fk",
")",
"{",
"// want to cover this case, but the code is not there yet.",
"if",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"script",
".=",
"$",
"this",
"->",
"addCriteriaJoin",
"(",
"$",
"fk",
",",
"$",
"table",
",",
"$",
"joinTable",
",",
"$",
"joinedTablePeerBuilder",
")",
";",
"}",
"// if fk->getForeignTableName != table->getName",
"}",
"// foreach [sub] foreign keys",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"$",
"script",
".=",
"\"\n \\$stmt = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doCount(\\$criteria, \\$con);\n\n if (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$count = (int) \\$row[0];\n } else {\n \\$count = 0; // no rows returned; we infer that means 0 matches.\n }\n \\$stmt->closeCursor();\n\n return \\$count;\n }\"",
";",
"}"
] | Adds the doCountJoinAll() method.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doCountJoinAll",
"()",
"method",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2649-L2718 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoSelectJoinAllExcept | protected function addDoSelectJoinAllExcept(&$script)
{
$table = $this->getTable();
$join_behavior = $this->getJoinBehavior();
// ------------------------------------------------------------------------
// doSelectJoinAllExcept*()
// ------------------------------------------------------------------------
// 2) create a bunch of doSelectJoinAllExcept*() methods
// -- these were existing in original Torque, so we should keep them for compatibility
$fkeys = $table->getForeignKeys(); // this sep assignment is necessary otherwise sub-loops over
// getForeignKeys() will cause this to only execute one time.
foreach ($fkeys as $fk) {
$tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
$excludedTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$excludedTableObjectBuilder = $this->getNewObjectBuilder($excludedTable);
$excludedTablePeerBuilder = $this->getNewPeerBuilder($excludedTable);
$excludedClassName = $excludedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Selects a collection of " . $this->getObjectClassname() . " objects pre-filled with all related objects except " . $thisTableObjectBuilder->getFKPhpNameAffix($fk) . ".
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return array Array of " . $this->getObjectClassname() . " objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAllExcept" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$con = null, \$join_behavior = $join_behavior)
{
\$criteria = clone \$criteria;
// Set the correct dbName if it has not been overridden
// \$criteria->getDbName() will return the same object if not set to another value
// so == check is okay and faster
if (\$criteria->getDbName() == Propel::getDefaultDB()) {
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
}
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol2 = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = 2;
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
// Why not? - because we would have to alias the tables in the join
if (!($subfk->getForeignTableName() == $table->getName())) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinTablePeerBuilder->getObjectClassname();
if ($joinClassName != $excludedClassName) {
$new_index = $index + 1;
$script .= "
" . $joinTablePeerBuilder->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol$new_index = \$startcol$index + " . $joinTablePeerBuilder->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = $new_index;
} // if joinClassName not excludeClassName
} // if subfk is not curr table
} // foreach [sub] foreign keys
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
if ($subfk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTablePeerBuilder->getObjectClassname();
if ($joinClassName != $excludedClassName) {
$script .= $this->addCriteriaJoin($subfk, $table, $joinTable, $joinedTablePeerBuilder);
}
}
} // foreach fkeys
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
\$results = array();
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key1 = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj1 = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj1->hydrate(\$row, 0, true); // rehydrate
} else {";
if ($table->getChildrenColumn()) {
$script .= "
\$omClass = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj1', '$cls') . "
\$obj1->hydrate(\$row);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj1, \$key1);
} // if obj1 already loaded
";
$index = 1;
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
if ($subfk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$interfaceName = $joinClassName;
if ($joinTable->getInterface()) {
$interfaceName = $this->prefixClassname($joinTable->getInterface());
}
if ($joinClassName != $excludedClassName) {
$index++;
$script .= "
// Add objects for joined $joinClassName rows
\$key$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol$index);
if (\$key$index !== null) {
\$obj$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getInstanceFromPool(\$key$index);
if (!\$obj$index) {
";
if ($joinTable->getChildrenColumn()) {
$script .= "
\$omClass = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass(\$row, \$startcol$index);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass();
";
} /* $joinTable->getChildrenColumn() */
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj' . $index, '$cls') . "
\$obj" . $index . "->hydrate(\$row, \$startcol$index);
" . $joinedTablePeerBuilder->getPeerClassname() . "::addInstanceToPool(\$obj$index, \$key$index);
} // if \$obj$index already loaded
// Add the \$obj1 (" . $this->getObjectClassname() . ") to the collection in \$obj" . $index . " (" . $joinedTablePeerBuilder->getObjectClassname() . ")";
if ($subfk->isLocalPrimaryKey()) {
$script .= "
\$obj1->set" . $joinedTablePeerBuilder->getObjectClassname() . "(\$obj" . $index . ");";
} else {
$script .= "
\$obj" . $index . "->add" . $joinedTableObjectBuilder->getRefFKPhpNameAffix($subfk, $plural = false) . "(\$obj1);";
}
$script .= "
} // if joined row is not null
";
} // if ($joinClassName != $excludedClassName) {
} // $subfk->getForeignTableName() != $table->getName()
} // foreach
$script .= "
\$results[] = \$obj1;
}
\$stmt->closeCursor();
return \$results;
}
";
} // foreach fk
} | php | protected function addDoSelectJoinAllExcept(&$script)
{
$table = $this->getTable();
$join_behavior = $this->getJoinBehavior();
// ------------------------------------------------------------------------
// doSelectJoinAllExcept*()
// ------------------------------------------------------------------------
// 2) create a bunch of doSelectJoinAllExcept*() methods
// -- these were existing in original Torque, so we should keep them for compatibility
$fkeys = $table->getForeignKeys(); // this sep assignment is necessary otherwise sub-loops over
// getForeignKeys() will cause this to only execute one time.
foreach ($fkeys as $fk) {
$tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
$excludedTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$excludedTableObjectBuilder = $this->getNewObjectBuilder($excludedTable);
$excludedTablePeerBuilder = $this->getNewPeerBuilder($excludedTable);
$excludedClassName = $excludedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Selects a collection of " . $this->getObjectClassname() . " objects pre-filled with all related objects except " . $thisTableObjectBuilder->getFKPhpNameAffix($fk) . ".
*
* @param Criteria \$criteria
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return array Array of " . $this->getObjectClassname() . " objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAllExcept" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$con = null, \$join_behavior = $join_behavior)
{
\$criteria = clone \$criteria;
// Set the correct dbName if it has not been overridden
// \$criteria->getDbName() will return the same object if not set to another value
// so == check is okay and faster
if (\$criteria->getDbName() == Propel::getDefaultDB()) {
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
}
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol2 = " . $this->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = 2;
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
// Why not? - because we would have to alias the tables in the join
if (!($subfk->getForeignTableName() == $table->getName())) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinTablePeerBuilder->getObjectClassname();
if ($joinClassName != $excludedClassName) {
$new_index = $index + 1;
$script .= "
" . $joinTablePeerBuilder->getPeerClassname() . "::addSelectColumns(\$criteria);
\$startcol$new_index = \$startcol$index + " . $joinTablePeerBuilder->getPeerClassname() . "::NUM_HYDRATE_COLUMNS;
";
$index = $new_index;
} // if joinClassName not excludeClassName
} // if subfk is not curr table
} // foreach [sub] foreign keys
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
if ($subfk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTablePeerBuilder->getObjectClassname();
if ($joinClassName != $excludedClassName) {
$script .= $this->addCriteriaJoin($subfk, $table, $joinTable, $joinedTablePeerBuilder);
}
}
} // foreach fkeys
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doSelect(\$criteria, \$con);
\$results = array();
while (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$key1 = " . $this->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, 0);
if (null !== (\$obj1 = " . $this->getPeerClassname() . "::getInstanceFromPool(\$key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://www.propelorm.org/ticket/509
// \$obj1->hydrate(\$row, 0, true); // rehydrate
} else {";
if ($table->getChildrenColumn()) {
$script .= "
\$omClass = " . $this->getPeerClassname() . "::getOMClass(\$row, 0);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $this->getPeerClassname() . "::getOMClass();
";
}
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj1', '$cls') . "
\$obj1->hydrate(\$row);
" . $this->getPeerClassname() . "::addInstanceToPool(\$obj1, \$key1);
} // if obj1 already loaded
";
$index = 1;
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
if ($subfk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinedTableObjectBuilder = $this->getNewObjectBuilder($joinTable);
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTableObjectBuilder->getObjectClassname();
$interfaceName = $joinClassName;
if ($joinTable->getInterface()) {
$interfaceName = $this->prefixClassname($joinTable->getInterface());
}
if ($joinClassName != $excludedClassName) {
$index++;
$script .= "
// Add objects for joined $joinClassName rows
\$key$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getPrimaryKeyHashFromRow(\$row, \$startcol$index);
if (\$key$index !== null) {
\$obj$index = " . $joinedTablePeerBuilder->getPeerClassname() . "::getInstanceFromPool(\$key$index);
if (!\$obj$index) {
";
if ($joinTable->getChildrenColumn()) {
$script .= "
\$omClass = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass(\$row, \$startcol$index);
\$cls = substr('.'.\$omClass, strrpos('.'.\$omClass, '.') + 1);
";
} else {
$script .= "
\$cls = " . $joinedTablePeerBuilder->getPeerClassname() . "::getOMClass();
";
} /* $joinTable->getChildrenColumn() */
$script .= "
" . $this->buildObjectInstanceCreationCode('$obj' . $index, '$cls') . "
\$obj" . $index . "->hydrate(\$row, \$startcol$index);
" . $joinedTablePeerBuilder->getPeerClassname() . "::addInstanceToPool(\$obj$index, \$key$index);
} // if \$obj$index already loaded
// Add the \$obj1 (" . $this->getObjectClassname() . ") to the collection in \$obj" . $index . " (" . $joinedTablePeerBuilder->getObjectClassname() . ")";
if ($subfk->isLocalPrimaryKey()) {
$script .= "
\$obj1->set" . $joinedTablePeerBuilder->getObjectClassname() . "(\$obj" . $index . ");";
} else {
$script .= "
\$obj" . $index . "->add" . $joinedTableObjectBuilder->getRefFKPhpNameAffix($subfk, $plural = false) . "(\$obj1);";
}
$script .= "
} // if joined row is not null
";
} // if ($joinClassName != $excludedClassName) {
} // $subfk->getForeignTableName() != $table->getName()
} // foreach
$script .= "
\$results[] = \$obj1;
}
\$stmt->closeCursor();
return \$results;
}
";
} // foreach fk
} | [
"protected",
"function",
"addDoSelectJoinAllExcept",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"join_behavior",
"=",
"$",
"this",
"->",
"getJoinBehavior",
"(",
")",
";",
"// ------------------------------------------------------------------------",
"// doSelectJoinAllExcept*()",
"// ------------------------------------------------------------------------",
"// 2) create a bunch of doSelectJoinAllExcept*() methods",
"// -- these were existing in original Torque, so we should keep them for compatibility",
"$",
"fkeys",
"=",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
";",
"// this sep assignment is necessary otherwise sub-loops over",
"// getForeignKeys() will cause this to only execute one time.",
"foreach",
"(",
"$",
"fkeys",
"as",
"$",
"fk",
")",
"{",
"$",
"tblFK",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"excludedTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"thisTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"table",
")",
";",
"$",
"excludedTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"excludedTable",
")",
";",
"$",
"excludedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"excludedTable",
")",
";",
"$",
"excludedClassName",
"=",
"$",
"excludedTableObjectBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"script",
".=",
"\"\n\n /**\n * Selects a collection of \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" objects pre-filled with all related objects except \"",
".",
"$",
"thisTableObjectBuilder",
"->",
"getFKPhpNameAffix",
"(",
"$",
"fk",
")",
".",
"\".\n *\n * @param Criteria \\$criteria\n * @param PropelPDO \\$con\n * @param String \\$join_behavior the type of joins to use, defaults to $join_behavior\n * @return array Array of \"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\" objects.\n * @throws PropelException Any exceptions caught during processing will be\n *\t\t rethrown wrapped into a PropelException.\n */\n public static function doSelectJoinAllExcept\"",
".",
"$",
"thisTableObjectBuilder",
"->",
"getFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\"(Criteria \\$criteria, \\$con = null, \\$join_behavior = $join_behavior)\n {\n \\$criteria = clone \\$criteria;\n\n // Set the correct dbName if it has not been overridden\n // \\$criteria->getDbName() will return the same object if not set to another value\n // so == check is okay and faster\n if (\\$criteria->getDbName() == Propel::getDefaultDB()) {\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n }\n\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n \\$startcol2 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::NUM_HYDRATE_COLUMNS;\n\"",
";",
"$",
"index",
"=",
"2",
";",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"subfk",
")",
"{",
"// want to cover this case, but the code is not there yet.",
"// Why not? - because we would have to alias the tables in the join",
"if",
"(",
"!",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
"==",
"$",
"table",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"joinTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"if",
"(",
"$",
"joinClassName",
"!=",
"$",
"excludedClassName",
")",
"{",
"$",
"new_index",
"=",
"$",
"index",
"+",
"1",
";",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"joinTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n \\$startcol$new_index = \\$startcol$index + \"",
".",
"$",
"joinTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::NUM_HYDRATE_COLUMNS;\n\"",
";",
"$",
"index",
"=",
"$",
"new_index",
";",
"}",
"// if joinClassName not excludeClassName",
"}",
"// if subfk is not curr table",
"}",
"// foreach [sub] foreign keys",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"subfk",
")",
"{",
"// want to cover this case, but the code is not there yet.",
"if",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"if",
"(",
"$",
"joinClassName",
"!=",
"$",
"excludedClassName",
")",
"{",
"$",
"script",
".=",
"$",
"this",
"->",
"addCriteriaJoin",
"(",
"$",
"subfk",
",",
"$",
"table",
",",
"$",
"joinTable",
",",
"$",
"joinedTablePeerBuilder",
")",
";",
"}",
"}",
"}",
"// foreach fkeys",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"$",
"script",
".=",
"\"\n\n \\$stmt = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doSelect(\\$criteria, \\$con);\n \\$results = array();\n\n while (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$key1 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, 0);\n if (null !== (\\$obj1 = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key1))) {\n // We no longer rehydrate the object, since this can cause data loss.\n // See http://www.propelorm.org/ticket/509\n // \\$obj1->hydrate(\\$row, 0, true); // rehydrate\n } else {\"",
";",
"if",
"(",
"$",
"table",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$omClass = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, 0);\n \\$cls = substr('.'.\\$omClass, strrpos('.'.\\$omClass, '.') + 1);\n\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass();\n\"",
";",
"}",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj1'",
",",
"'$cls'",
")",
".",
"\"\n \\$obj1->hydrate(\\$row);\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj1, \\$key1);\n } // if obj1 already loaded\n\"",
";",
"$",
"index",
"=",
"1",
";",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"subfk",
")",
"{",
"// want to cover this case, but the code is not there yet.",
"if",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"joinedTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinedTableObjectBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"interfaceName",
"=",
"$",
"joinClassName",
";",
"if",
"(",
"$",
"joinTable",
"->",
"getInterface",
"(",
")",
")",
"{",
"$",
"interfaceName",
"=",
"$",
"this",
"->",
"prefixClassname",
"(",
"$",
"joinTable",
"->",
"getInterface",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"joinClassName",
"!=",
"$",
"excludedClassName",
")",
"{",
"$",
"index",
"++",
";",
"$",
"script",
".=",
"\"\n // Add objects for joined $joinClassName rows\n\n \\$key$index = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getPrimaryKeyHashFromRow(\\$row, \\$startcol$index);\n if (\\$key$index !== null) {\n \\$obj$index = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getInstanceFromPool(\\$key$index);\n if (!\\$obj$index) {\n \"",
";",
"if",
"(",
"$",
"joinTable",
"->",
"getChildrenColumn",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$omClass = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass(\\$row, \\$startcol$index);\n \\$cls = substr('.'.\\$omClass, strrpos('.'.\\$omClass, '.') + 1);\n\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$cls = \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::getOMClass();\n\"",
";",
"}",
"/* $joinTable->getChildrenColumn() */",
"$",
"script",
".=",
"\"\n \"",
".",
"$",
"this",
"->",
"buildObjectInstanceCreationCode",
"(",
"'$obj'",
".",
"$",
"index",
",",
"'$cls'",
")",
".",
"\"\n \\$obj\"",
".",
"$",
"index",
".",
"\"->hydrate(\\$row, \\$startcol$index);\n \"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addInstanceToPool(\\$obj$index, \\$key$index);\n } // if \\$obj$index already loaded\n\n // Add the \\$obj1 (\"",
".",
"$",
"this",
"->",
"getObjectClassname",
"(",
")",
".",
"\") to the collection in \\$obj\"",
".",
"$",
"index",
".",
"\" (\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
".",
"\")\"",
";",
"if",
"(",
"$",
"subfk",
"->",
"isLocalPrimaryKey",
"(",
")",
")",
"{",
"$",
"script",
".=",
"\"\n \\$obj1->set\"",
".",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
".",
"\"(\\$obj\"",
".",
"$",
"index",
".",
"\");\"",
";",
"}",
"else",
"{",
"$",
"script",
".=",
"\"\n \\$obj\"",
".",
"$",
"index",
".",
"\"->add\"",
".",
"$",
"joinedTableObjectBuilder",
"->",
"getRefFKPhpNameAffix",
"(",
"$",
"subfk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\"(\\$obj1);\"",
";",
"}",
"$",
"script",
".=",
"\"\n\n } // if joined row is not null\n\"",
";",
"}",
"// if ($joinClassName != $excludedClassName) {",
"}",
"// $subfk->getForeignTableName() != $table->getName()",
"}",
"// foreach",
"$",
"script",
".=",
"\"\n \\$results[] = \\$obj1;\n }\n \\$stmt->closeCursor();\n\n return \\$results;\n }\n\"",
";",
"}",
"// foreach fk",
"}"
] | Adds the doSelectJoinAllExcept*() methods.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doSelectJoinAllExcept",
"*",
"()",
"methods",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2725-L2915 |
propelorm/Propel | generator/lib/builder/om/PHP5PeerBuilder.php | PHP5PeerBuilder.addDoCountJoinAllExcept | protected function addDoCountJoinAllExcept(&$script)
{
$table = $this->getTable();
$join_behavior = $this->getJoinBehavior();
$fkeys = $table->getForeignKeys(); // this sep assignment is necessary otherwise sub-loops over
// getForeignKeys() will cause this to only execute one time.
foreach ($fkeys as $fk) {
$tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
$excludedTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$excludedTableObjectBuilder = $this->getNewObjectBuilder($excludedTable);
$excludedTablePeerBuilder = $this->getNewPeerBuilder($excludedTable);
$excludedClassName = $excludedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Returns the number of rows matching criteria, joining the related " . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . " table
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return int Number of matching rows.
*/
public static function doCountJoinAllExcept" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null, \$join_behavior = $join_behavior)
{
// we're going to modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY should not affect count
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
";
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
if ($subfk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTablePeerBuilder->getObjectClassname();
if ($joinClassName != $excludedClassName) {
$script .= $this->addCriteriaJoin($subfk, $table, $joinTable, $joinedTablePeerBuilder);
}
}
} // foreach fkeys
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}
";
} // foreach fk
} | php | protected function addDoCountJoinAllExcept(&$script)
{
$table = $this->getTable();
$join_behavior = $this->getJoinBehavior();
$fkeys = $table->getForeignKeys(); // this sep assignment is necessary otherwise sub-loops over
// getForeignKeys() will cause this to only execute one time.
foreach ($fkeys as $fk) {
$tblFK = $table->getDatabase()->getTable($fk->getForeignTableName());
$excludedTable = $table->getDatabase()->getTable($fk->getForeignTableName());
$thisTableObjectBuilder = $this->getNewObjectBuilder($table);
$excludedTableObjectBuilder = $this->getNewObjectBuilder($excludedTable);
$excludedTablePeerBuilder = $this->getNewPeerBuilder($excludedTable);
$excludedClassName = $excludedTableObjectBuilder->getObjectClassname();
$script .= "
/**
* Returns the number of rows matching criteria, joining the related " . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . " table
*
* @param Criteria \$criteria
* @param boolean \$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
* @param PropelPDO \$con
* @param String \$join_behavior the type of joins to use, defaults to $join_behavior
* @return int Number of matching rows.
*/
public static function doCountJoinAllExcept" . $thisTableObjectBuilder->getFKPhpNameAffix($fk, $plural = false) . "(Criteria \$criteria, \$distinct = false, PropelPDO \$con = null, \$join_behavior = $join_behavior)
{
// we're going to modify criteria, so copy it first
\$criteria = clone \$criteria;
// We need to set the primary table name, since in the case that there are no WHERE columns
// it will be impossible for the BasePeer::createSelectSql() method to determine which
// tables go into the FROM clause.
\$criteria->setPrimaryTableName(" . $this->getPeerClassname() . "::TABLE_NAME);
if (\$distinct && !in_array(Criteria::DISTINCT, \$criteria->getSelectModifiers())) {
\$criteria->setDistinct();
}
if (!\$criteria->hasSelectClause()) {
" . $this->getPeerClassname() . "::addSelectColumns(\$criteria);
}
\$criteria->clearOrderByColumns(); // ORDER BY should not affect count
// Set the correct dbName
\$criteria->setDbName(" . $this->getPeerClassname() . "::DATABASE_NAME);
if (\$con === null) {
\$con = Propel::getConnection(" . $this->getPeerClassname() . "::DATABASE_NAME, Propel::CONNECTION_READ);
}
";
foreach ($table->getForeignKeys() as $subfk) {
// want to cover this case, but the code is not there yet.
if ($subfk->getForeignTableName() != $table->getName()) {
$joinTable = $table->getDatabase()->getTable($subfk->getForeignTableName());
$joinedTablePeerBuilder = $this->getNewPeerBuilder($joinTable);
$joinClassName = $joinedTablePeerBuilder->getObjectClassname();
if ($joinClassName != $excludedClassName) {
$script .= $this->addCriteriaJoin($subfk, $table, $joinTable, $joinedTablePeerBuilder);
}
}
} // foreach fkeys
// apply behaviors
$this->applyBehaviorModifier('preSelect', $script);
$script .= "
\$stmt = " . $this->basePeerClassname . "::doCount(\$criteria, \$con);
if (\$row = \$stmt->fetch(PDO::FETCH_NUM)) {
\$count = (int) \$row[0];
} else {
\$count = 0; // no rows returned; we infer that means 0 matches.
}
\$stmt->closeCursor();
return \$count;
}
";
} // foreach fk
} | [
"protected",
"function",
"addDoCountJoinAllExcept",
"(",
"&",
"$",
"script",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"join_behavior",
"=",
"$",
"this",
"->",
"getJoinBehavior",
"(",
")",
";",
"$",
"fkeys",
"=",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
";",
"// this sep assignment is necessary otherwise sub-loops over",
"// getForeignKeys() will cause this to only execute one time.",
"foreach",
"(",
"$",
"fkeys",
"as",
"$",
"fk",
")",
"{",
"$",
"tblFK",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"excludedTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"fk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"thisTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"table",
")",
";",
"$",
"excludedTableObjectBuilder",
"=",
"$",
"this",
"->",
"getNewObjectBuilder",
"(",
"$",
"excludedTable",
")",
";",
"$",
"excludedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"excludedTable",
")",
";",
"$",
"excludedClassName",
"=",
"$",
"excludedTableObjectBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"$",
"script",
".=",
"\"\n\n /**\n * Returns the number of rows matching criteria, joining the related \"",
".",
"$",
"thisTableObjectBuilder",
"->",
"getFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\" table\n *\n * @param Criteria \\$criteria\n * @param boolean \\$distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.\n * @param PropelPDO \\$con\n * @param String \\$join_behavior the type of joins to use, defaults to $join_behavior\n * @return int Number of matching rows.\n */\n public static function doCountJoinAllExcept\"",
".",
"$",
"thisTableObjectBuilder",
"->",
"getFKPhpNameAffix",
"(",
"$",
"fk",
",",
"$",
"plural",
"=",
"false",
")",
".",
"\"(Criteria \\$criteria, \\$distinct = false, PropelPDO \\$con = null, \\$join_behavior = $join_behavior)\n {\n // we're going to modify criteria, so copy it first\n \\$criteria = clone \\$criteria;\n\n // We need to set the primary table name, since in the case that there are no WHERE columns\n // it will be impossible for the BasePeer::createSelectSql() method to determine which\n // tables go into the FROM clause.\n \\$criteria->setPrimaryTableName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::TABLE_NAME);\n\n if (\\$distinct && !in_array(Criteria::DISTINCT, \\$criteria->getSelectModifiers())) {\n \\$criteria->setDistinct();\n }\n\n if (!\\$criteria->hasSelectClause()) {\n \"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::addSelectColumns(\\$criteria);\n }\n\n \\$criteria->clearOrderByColumns(); // ORDER BY should not affect count\n\n // Set the correct dbName\n \\$criteria->setDbName(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME);\n\n if (\\$con === null) {\n \\$con = Propel::getConnection(\"",
".",
"$",
"this",
"->",
"getPeerClassname",
"(",
")",
".",
"\"::DATABASE_NAME, Propel::CONNECTION_READ);\n }\n \"",
";",
"foreach",
"(",
"$",
"table",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"subfk",
")",
"{",
"// want to cover this case, but the code is not there yet.",
"if",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
"!=",
"$",
"table",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"joinTable",
"=",
"$",
"table",
"->",
"getDatabase",
"(",
")",
"->",
"getTable",
"(",
"$",
"subfk",
"->",
"getForeignTableName",
"(",
")",
")",
";",
"$",
"joinedTablePeerBuilder",
"=",
"$",
"this",
"->",
"getNewPeerBuilder",
"(",
"$",
"joinTable",
")",
";",
"$",
"joinClassName",
"=",
"$",
"joinedTablePeerBuilder",
"->",
"getObjectClassname",
"(",
")",
";",
"if",
"(",
"$",
"joinClassName",
"!=",
"$",
"excludedClassName",
")",
"{",
"$",
"script",
".=",
"$",
"this",
"->",
"addCriteriaJoin",
"(",
"$",
"subfk",
",",
"$",
"table",
",",
"$",
"joinTable",
",",
"$",
"joinedTablePeerBuilder",
")",
";",
"}",
"}",
"}",
"// foreach fkeys",
"// apply behaviors",
"$",
"this",
"->",
"applyBehaviorModifier",
"(",
"'preSelect'",
",",
"$",
"script",
")",
";",
"$",
"script",
".=",
"\"\n \\$stmt = \"",
".",
"$",
"this",
"->",
"basePeerClassname",
".",
"\"::doCount(\\$criteria, \\$con);\n\n if (\\$row = \\$stmt->fetch(PDO::FETCH_NUM)) {\n \\$count = (int) \\$row[0];\n } else {\n \\$count = 0; // no rows returned; we infer that means 0 matches.\n }\n \\$stmt->closeCursor();\n\n return \\$count;\n }\n\"",
";",
"}",
"// foreach fk",
"}"
] | Adds the doCountJoinAllExcept*() methods.
@param string &$script The script will be modified in this method. | [
"Adds",
"the",
"doCountJoinAllExcept",
"*",
"()",
"methods",
"."
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/om/PHP5PeerBuilder.php#L2922-L3011 |
propelorm/Propel | generator/lib/behavior/i18n/I18nBehaviorObjectBuilderModifier.php | I18nBehaviorObjectBuilderModifier.addTranslatedColumnSetter | protected function addTranslatedColumnSetter(Column $column)
{
$i18nTablePhpName = $this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable())->getClassname();
$tablePhpName = $this->builder->getStubObjectBuilder()->getClassname();
$objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
$comment = '';
$functionStatement = '';
if ($column->getType() === PropelTypes::DATE || $column->getType() === PropelTypes::TIME || $column->getType() === PropelTypes::TIMESTAMP) {
$objectBuilder->addTemporalMutatorComment($comment, $column);
$objectBuilder->addMutatorOpenOpen($functionStatement, $column);
} else {
$objectBuilder->addMutatorComment($comment, $column);
$objectBuilder->addMutatorOpenOpen($functionStatement, $column);
}
$comment = preg_replace('/^\t/m', '', $comment);
$comment = str_replace('@return ' . $i18nTablePhpName, '@return ' . $tablePhpName, $comment);
$functionStatement = preg_replace('/^\t/m', '', $functionStatement);
preg_match_all('/\$[a-z]+/i', $functionStatement, $params);
return $this->behavior->renderTemplate('objectTranslatedColumnSetter', array(
'comment' => $comment,
'functionStatement' => $functionStatement,
'columnPhpName' => $column->getPhpName(),
'params' => implode(', ', $params[0]),
));
} | php | protected function addTranslatedColumnSetter(Column $column)
{
$i18nTablePhpName = $this->builder->getNewStubObjectBuilder($this->behavior->getI18nTable())->getClassname();
$tablePhpName = $this->builder->getStubObjectBuilder()->getClassname();
$objectBuilder = $this->builder->getNewObjectBuilder($this->behavior->getI18nTable());
$comment = '';
$functionStatement = '';
if ($column->getType() === PropelTypes::DATE || $column->getType() === PropelTypes::TIME || $column->getType() === PropelTypes::TIMESTAMP) {
$objectBuilder->addTemporalMutatorComment($comment, $column);
$objectBuilder->addMutatorOpenOpen($functionStatement, $column);
} else {
$objectBuilder->addMutatorComment($comment, $column);
$objectBuilder->addMutatorOpenOpen($functionStatement, $column);
}
$comment = preg_replace('/^\t/m', '', $comment);
$comment = str_replace('@return ' . $i18nTablePhpName, '@return ' . $tablePhpName, $comment);
$functionStatement = preg_replace('/^\t/m', '', $functionStatement);
preg_match_all('/\$[a-z]+/i', $functionStatement, $params);
return $this->behavior->renderTemplate('objectTranslatedColumnSetter', array(
'comment' => $comment,
'functionStatement' => $functionStatement,
'columnPhpName' => $column->getPhpName(),
'params' => implode(', ', $params[0]),
));
} | [
"protected",
"function",
"addTranslatedColumnSetter",
"(",
"Column",
"$",
"column",
")",
"{",
"$",
"i18nTablePhpName",
"=",
"$",
"this",
"->",
"builder",
"->",
"getNewStubObjectBuilder",
"(",
"$",
"this",
"->",
"behavior",
"->",
"getI18nTable",
"(",
")",
")",
"->",
"getClassname",
"(",
")",
";",
"$",
"tablePhpName",
"=",
"$",
"this",
"->",
"builder",
"->",
"getStubObjectBuilder",
"(",
")",
"->",
"getClassname",
"(",
")",
";",
"$",
"objectBuilder",
"=",
"$",
"this",
"->",
"builder",
"->",
"getNewObjectBuilder",
"(",
"$",
"this",
"->",
"behavior",
"->",
"getI18nTable",
"(",
")",
")",
";",
"$",
"comment",
"=",
"''",
";",
"$",
"functionStatement",
"=",
"''",
";",
"if",
"(",
"$",
"column",
"->",
"getType",
"(",
")",
"===",
"PropelTypes",
"::",
"DATE",
"||",
"$",
"column",
"->",
"getType",
"(",
")",
"===",
"PropelTypes",
"::",
"TIME",
"||",
"$",
"column",
"->",
"getType",
"(",
")",
"===",
"PropelTypes",
"::",
"TIMESTAMP",
")",
"{",
"$",
"objectBuilder",
"->",
"addTemporalMutatorComment",
"(",
"$",
"comment",
",",
"$",
"column",
")",
";",
"$",
"objectBuilder",
"->",
"addMutatorOpenOpen",
"(",
"$",
"functionStatement",
",",
"$",
"column",
")",
";",
"}",
"else",
"{",
"$",
"objectBuilder",
"->",
"addMutatorComment",
"(",
"$",
"comment",
",",
"$",
"column",
")",
";",
"$",
"objectBuilder",
"->",
"addMutatorOpenOpen",
"(",
"$",
"functionStatement",
",",
"$",
"column",
")",
";",
"}",
"$",
"comment",
"=",
"preg_replace",
"(",
"'/^\\t/m'",
",",
"''",
",",
"$",
"comment",
")",
";",
"$",
"comment",
"=",
"str_replace",
"(",
"'@return '",
".",
"$",
"i18nTablePhpName",
",",
"'@return '",
".",
"$",
"tablePhpName",
",",
"$",
"comment",
")",
";",
"$",
"functionStatement",
"=",
"preg_replace",
"(",
"'/^\\t/m'",
",",
"''",
",",
"$",
"functionStatement",
")",
";",
"preg_match_all",
"(",
"'/\\$[a-z]+/i'",
",",
"$",
"functionStatement",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"behavior",
"->",
"renderTemplate",
"(",
"'objectTranslatedColumnSetter'",
",",
"array",
"(",
"'comment'",
"=>",
"$",
"comment",
",",
"'functionStatement'",
"=>",
"$",
"functionStatement",
",",
"'columnPhpName'",
"=>",
"$",
"column",
"->",
"getPhpName",
"(",
")",
",",
"'params'",
"=>",
"implode",
"(",
"', '",
",",
"$",
"params",
"[",
"0",
"]",
")",
",",
")",
")",
";",
"}"
] | cannot be specified by the user | [
"cannot",
"be",
"specified",
"by",
"the",
"user"
] | train | https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/behavior/i18n/I18nBehaviorObjectBuilderModifier.php#L171-L196 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.