repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildSelectQuery | protected function buildSelectQuery(SQLSelect $query, array &$parameters)
{
$sql = $this->buildSelectFragment($query, $parameters);
$sql .= $this->buildFromFragment($query, $parameters);
$sql .= $this->buildWhereFragment($query, $parameters);
$sql .= $this->buildGroupByFragment($query, $parameters);
$sql .= $this->buildHavingFragment($query, $parameters);
$sql .= $this->buildOrderByFragment($query, $parameters);
$sql .= $this->buildLimitFragment($query, $parameters);
return $sql;
} | php | protected function buildSelectQuery(SQLSelect $query, array &$parameters)
{
$sql = $this->buildSelectFragment($query, $parameters);
$sql .= $this->buildFromFragment($query, $parameters);
$sql .= $this->buildWhereFragment($query, $parameters);
$sql .= $this->buildGroupByFragment($query, $parameters);
$sql .= $this->buildHavingFragment($query, $parameters);
$sql .= $this->buildOrderByFragment($query, $parameters);
$sql .= $this->buildLimitFragment($query, $parameters);
return $sql;
} | [
"protected",
"function",
"buildSelectQuery",
"(",
"SQLSelect",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"buildSelectFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildFromFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildWhereFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildGroupByFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildHavingFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildOrderByFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildLimitFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"sql",
";",
"}"
]
| Builds a query from a SQLSelect expression
@param SQLSelect $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed SQL string | [
"Builds",
"a",
"query",
"from",
"a",
"SQLSelect",
"expression"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L69-L79 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildDeleteQuery | protected function buildDeleteQuery(SQLDelete $query, array &$parameters)
{
$sql = $this->buildDeleteFragment($query, $parameters);
$sql .= $this->buildFromFragment($query, $parameters);
$sql .= $this->buildWhereFragment($query, $parameters);
return $sql;
} | php | protected function buildDeleteQuery(SQLDelete $query, array &$parameters)
{
$sql = $this->buildDeleteFragment($query, $parameters);
$sql .= $this->buildFromFragment($query, $parameters);
$sql .= $this->buildWhereFragment($query, $parameters);
return $sql;
} | [
"protected",
"function",
"buildDeleteQuery",
"(",
"SQLDelete",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"buildDeleteFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildFromFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildWhereFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"sql",
";",
"}"
]
| Builds a query from a SQLDelete expression
@param SQLDelete $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed SQL string | [
"Builds",
"a",
"query",
"from",
"a",
"SQLDelete",
"expression"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L88-L94 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildInsertQuery | protected function buildInsertQuery(SQLInsert $query, array &$parameters)
{
$nl = $this->getSeparator();
$into = $query->getInto();
// Column identifiers
$columns = $query->getColumns();
$sql = "INSERT INTO {$into}{$nl}(" . implode(', ', $columns) . ")";
// Values
$sql .= "{$nl}VALUES";
// Build all rows
$rowParts = array();
foreach ($query->getRows() as $row) {
// Build all columns in this row
$assignments = $row->getAssignments();
// Join SET components together, considering parameters
$parts = array();
foreach ($columns as $column) {
// Check if this column has a value for this row
if (isset($assignments[$column])) {
// Assigment is a single item array, expand with a loop here
foreach ($assignments[$column] as $assignmentSQL => $assignmentParameters) {
$parts[] = $assignmentSQL;
$parameters = array_merge($parameters, $assignmentParameters);
break;
}
} else {
// This row is missing a value for a column used by another row
$parts[] = '?';
$parameters[] = null;
}
}
$rowParts[] = '(' . implode(', ', $parts) . ')';
}
$sql .= $nl . implode(",$nl", $rowParts);
return $sql;
} | php | protected function buildInsertQuery(SQLInsert $query, array &$parameters)
{
$nl = $this->getSeparator();
$into = $query->getInto();
// Column identifiers
$columns = $query->getColumns();
$sql = "INSERT INTO {$into}{$nl}(" . implode(', ', $columns) . ")";
// Values
$sql .= "{$nl}VALUES";
// Build all rows
$rowParts = array();
foreach ($query->getRows() as $row) {
// Build all columns in this row
$assignments = $row->getAssignments();
// Join SET components together, considering parameters
$parts = array();
foreach ($columns as $column) {
// Check if this column has a value for this row
if (isset($assignments[$column])) {
// Assigment is a single item array, expand with a loop here
foreach ($assignments[$column] as $assignmentSQL => $assignmentParameters) {
$parts[] = $assignmentSQL;
$parameters = array_merge($parameters, $assignmentParameters);
break;
}
} else {
// This row is missing a value for a column used by another row
$parts[] = '?';
$parameters[] = null;
}
}
$rowParts[] = '(' . implode(', ', $parts) . ')';
}
$sql .= $nl . implode(",$nl", $rowParts);
return $sql;
} | [
"protected",
"function",
"buildInsertQuery",
"(",
"SQLInsert",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"$",
"into",
"=",
"$",
"query",
"->",
"getInto",
"(",
")",
";",
"// Column identifiers",
"$",
"columns",
"=",
"$",
"query",
"->",
"getColumns",
"(",
")",
";",
"$",
"sql",
"=",
"\"INSERT INTO {$into}{$nl}(\"",
".",
"implode",
"(",
"', '",
",",
"$",
"columns",
")",
".",
"\")\"",
";",
"// Values",
"$",
"sql",
".=",
"\"{$nl}VALUES\"",
";",
"// Build all rows",
"$",
"rowParts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"query",
"->",
"getRows",
"(",
")",
"as",
"$",
"row",
")",
"{",
"// Build all columns in this row",
"$",
"assignments",
"=",
"$",
"row",
"->",
"getAssignments",
"(",
")",
";",
"// Join SET components together, considering parameters",
"$",
"parts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"column",
")",
"{",
"// Check if this column has a value for this row",
"if",
"(",
"isset",
"(",
"$",
"assignments",
"[",
"$",
"column",
"]",
")",
")",
"{",
"// Assigment is a single item array, expand with a loop here",
"foreach",
"(",
"$",
"assignments",
"[",
"$",
"column",
"]",
"as",
"$",
"assignmentSQL",
"=>",
"$",
"assignmentParameters",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"$",
"assignmentSQL",
";",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"assignmentParameters",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"// This row is missing a value for a column used by another row",
"$",
"parts",
"[",
"]",
"=",
"'?'",
";",
"$",
"parameters",
"[",
"]",
"=",
"null",
";",
"}",
"}",
"$",
"rowParts",
"[",
"]",
"=",
"'('",
".",
"implode",
"(",
"', '",
",",
"$",
"parts",
")",
".",
"')'",
";",
"}",
"$",
"sql",
".=",
"$",
"nl",
".",
"implode",
"(",
"\",$nl\"",
",",
"$",
"rowParts",
")",
";",
"return",
"$",
"sql",
";",
"}"
]
| Builds a query from a SQLInsert expression
@param SQLInsert $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed SQL string | [
"Builds",
"a",
"query",
"from",
"a",
"SQLInsert",
"expression"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L103-L142 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildUpdateQuery | protected function buildUpdateQuery(SQLUpdate $query, array &$parameters)
{
$sql = $this->buildUpdateFragment($query, $parameters);
$sql .= $this->buildWhereFragment($query, $parameters);
return $sql;
} | php | protected function buildUpdateQuery(SQLUpdate $query, array &$parameters)
{
$sql = $this->buildUpdateFragment($query, $parameters);
$sql .= $this->buildWhereFragment($query, $parameters);
return $sql;
} | [
"protected",
"function",
"buildUpdateQuery",
"(",
"SQLUpdate",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"buildUpdateFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"$",
"sql",
".=",
"$",
"this",
"->",
"buildWhereFragment",
"(",
"$",
"query",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"sql",
";",
"}"
]
| Builds a query from a SQLUpdate expression
@param SQLUpdate $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed SQL string | [
"Builds",
"a",
"query",
"from",
"a",
"SQLUpdate",
"expression"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L151-L156 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildSelectFragment | protected function buildSelectFragment(SQLSelect $query, array &$parameters)
{
$distinct = $query->getDistinct();
$select = $query->getSelect();
$clauses = array();
foreach ($select as $alias => $field) {
// Don't include redundant aliases.
$fieldAlias = "\"{$alias}\"";
if ($alias === $field || substr($field, -strlen($fieldAlias)) === $fieldAlias) {
$clauses[] = $field;
} else {
$clauses[] = "$field AS $fieldAlias";
}
}
$text = 'SELECT ';
if ($distinct) {
$text .= 'DISTINCT ';
}
return $text . implode(', ', $clauses);
} | php | protected function buildSelectFragment(SQLSelect $query, array &$parameters)
{
$distinct = $query->getDistinct();
$select = $query->getSelect();
$clauses = array();
foreach ($select as $alias => $field) {
// Don't include redundant aliases.
$fieldAlias = "\"{$alias}\"";
if ($alias === $field || substr($field, -strlen($fieldAlias)) === $fieldAlias) {
$clauses[] = $field;
} else {
$clauses[] = "$field AS $fieldAlias";
}
}
$text = 'SELECT ';
if ($distinct) {
$text .= 'DISTINCT ';
}
return $text . implode(', ', $clauses);
} | [
"protected",
"function",
"buildSelectFragment",
"(",
"SQLSelect",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"distinct",
"=",
"$",
"query",
"->",
"getDistinct",
"(",
")",
";",
"$",
"select",
"=",
"$",
"query",
"->",
"getSelect",
"(",
")",
";",
"$",
"clauses",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"select",
"as",
"$",
"alias",
"=>",
"$",
"field",
")",
"{",
"// Don't include redundant aliases.",
"$",
"fieldAlias",
"=",
"\"\\\"{$alias}\\\"\"",
";",
"if",
"(",
"$",
"alias",
"===",
"$",
"field",
"||",
"substr",
"(",
"$",
"field",
",",
"-",
"strlen",
"(",
"$",
"fieldAlias",
")",
")",
"===",
"$",
"fieldAlias",
")",
"{",
"$",
"clauses",
"[",
"]",
"=",
"$",
"field",
";",
"}",
"else",
"{",
"$",
"clauses",
"[",
"]",
"=",
"\"$field AS $fieldAlias\"",
";",
"}",
"}",
"$",
"text",
"=",
"'SELECT '",
";",
"if",
"(",
"$",
"distinct",
")",
"{",
"$",
"text",
".=",
"'DISTINCT '",
";",
"}",
"return",
"$",
"text",
".",
"implode",
"(",
"', '",
",",
"$",
"clauses",
")",
";",
"}"
]
| Returns the SELECT clauses ready for inserting into a query.
@param SQLSelect $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed select part of statement | [
"Returns",
"the",
"SELECT",
"clauses",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L165-L186 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildDeleteFragment | public function buildDeleteFragment(SQLDelete $query, array &$parameters)
{
$text = 'DELETE';
// If doing a multiple table delete then list the target deletion tables here
// Note that some schemas don't support multiple table deletion
$delete = $query->getDelete();
if (!empty($delete)) {
$text .= ' ' . implode(', ', $delete);
}
return $text;
} | php | public function buildDeleteFragment(SQLDelete $query, array &$parameters)
{
$text = 'DELETE';
// If doing a multiple table delete then list the target deletion tables here
// Note that some schemas don't support multiple table deletion
$delete = $query->getDelete();
if (!empty($delete)) {
$text .= ' ' . implode(', ', $delete);
}
return $text;
} | [
"public",
"function",
"buildDeleteFragment",
"(",
"SQLDelete",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"text",
"=",
"'DELETE'",
";",
"// If doing a multiple table delete then list the target deletion tables here",
"// Note that some schemas don't support multiple table deletion",
"$",
"delete",
"=",
"$",
"query",
"->",
"getDelete",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"delete",
")",
")",
"{",
"$",
"text",
".=",
"' '",
".",
"implode",
"(",
"', '",
",",
"$",
"delete",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
]
| Return the DELETE clause ready for inserting into a query.
@param SQLDelete $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed delete part of statement | [
"Return",
"the",
"DELETE",
"clause",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L195-L206 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildUpdateFragment | public function buildUpdateFragment(SQLUpdate $query, array &$parameters)
{
$table = $query->getTable();
$text = "UPDATE $table";
// Join SET components together, considering parameters
$parts = array();
foreach ($query->getAssignments() as $column => $assignment) {
// Assigment is a single item array, expand with a loop here
foreach ($assignment as $assignmentSQL => $assignmentParameters) {
$parts[] = "$column = $assignmentSQL";
$parameters = array_merge($parameters, $assignmentParameters);
break;
}
}
$nl = $this->getSeparator();
$text .= "{$nl}SET " . implode(', ', $parts);
return $text;
} | php | public function buildUpdateFragment(SQLUpdate $query, array &$parameters)
{
$table = $query->getTable();
$text = "UPDATE $table";
// Join SET components together, considering parameters
$parts = array();
foreach ($query->getAssignments() as $column => $assignment) {
// Assigment is a single item array, expand with a loop here
foreach ($assignment as $assignmentSQL => $assignmentParameters) {
$parts[] = "$column = $assignmentSQL";
$parameters = array_merge($parameters, $assignmentParameters);
break;
}
}
$nl = $this->getSeparator();
$text .= "{$nl}SET " . implode(', ', $parts);
return $text;
} | [
"public",
"function",
"buildUpdateFragment",
"(",
"SQLUpdate",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"table",
"=",
"$",
"query",
"->",
"getTable",
"(",
")",
";",
"$",
"text",
"=",
"\"UPDATE $table\"",
";",
"// Join SET components together, considering parameters",
"$",
"parts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"query",
"->",
"getAssignments",
"(",
")",
"as",
"$",
"column",
"=>",
"$",
"assignment",
")",
"{",
"// Assigment is a single item array, expand with a loop here",
"foreach",
"(",
"$",
"assignment",
"as",
"$",
"assignmentSQL",
"=>",
"$",
"assignmentParameters",
")",
"{",
"$",
"parts",
"[",
"]",
"=",
"\"$column = $assignmentSQL\"",
";",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"assignmentParameters",
")",
";",
"break",
";",
"}",
"}",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"$",
"text",
".=",
"\"{$nl}SET \"",
".",
"implode",
"(",
"', '",
",",
"$",
"parts",
")",
";",
"return",
"$",
"text",
";",
"}"
]
| Return the UPDATE clause ready for inserting into a query.
@param SQLUpdate $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed from part of statement | [
"Return",
"the",
"UPDATE",
"clause",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L215-L233 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildFromFragment | public function buildFromFragment(SQLConditionalExpression $query, array &$parameters)
{
$from = $query->getJoins($joinParameters);
$parameters = array_merge($parameters, $joinParameters);
$nl = $this->getSeparator();
return "{$nl}FROM " . implode(' ', $from);
} | php | public function buildFromFragment(SQLConditionalExpression $query, array &$parameters)
{
$from = $query->getJoins($joinParameters);
$parameters = array_merge($parameters, $joinParameters);
$nl = $this->getSeparator();
return "{$nl}FROM " . implode(' ', $from);
} | [
"public",
"function",
"buildFromFragment",
"(",
"SQLConditionalExpression",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"from",
"=",
"$",
"query",
"->",
"getJoins",
"(",
"$",
"joinParameters",
")",
";",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"joinParameters",
")",
";",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"return",
"\"{$nl}FROM \"",
".",
"implode",
"(",
"' '",
",",
"$",
"from",
")",
";",
"}"
]
| Return the FROM clause ready for inserting into a query.
@param SQLConditionalExpression $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed from part of statement | [
"Return",
"the",
"FROM",
"clause",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L242-L248 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildWhereFragment | public function buildWhereFragment(SQLConditionalExpression $query, array &$parameters)
{
// Get parameterised elements
$where = $query->getWhereParameterised($whereParameters);
if (empty($where)) {
return '';
}
// Join conditions
$connective = $query->getConnective();
$parameters = array_merge($parameters, $whereParameters);
$nl = $this->getSeparator();
return "{$nl}WHERE (" . implode("){$nl}{$connective} (", $where) . ")";
} | php | public function buildWhereFragment(SQLConditionalExpression $query, array &$parameters)
{
// Get parameterised elements
$where = $query->getWhereParameterised($whereParameters);
if (empty($where)) {
return '';
}
// Join conditions
$connective = $query->getConnective();
$parameters = array_merge($parameters, $whereParameters);
$nl = $this->getSeparator();
return "{$nl}WHERE (" . implode("){$nl}{$connective} (", $where) . ")";
} | [
"public",
"function",
"buildWhereFragment",
"(",
"SQLConditionalExpression",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"// Get parameterised elements",
"$",
"where",
"=",
"$",
"query",
"->",
"getWhereParameterised",
"(",
"$",
"whereParameters",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"where",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Join conditions",
"$",
"connective",
"=",
"$",
"query",
"->",
"getConnective",
"(",
")",
";",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"whereParameters",
")",
";",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"return",
"\"{$nl}WHERE (\"",
".",
"implode",
"(",
"\"){$nl}{$connective} (\"",
",",
"$",
"where",
")",
".",
"\")\"",
";",
"}"
]
| Returns the WHERE clauses ready for inserting into a query.
@param SQLConditionalExpression $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed where condition | [
"Returns",
"the",
"WHERE",
"clauses",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L257-L270 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildOrderByFragment | public function buildOrderByFragment(SQLSelect $query, array &$parameters)
{
$orderBy = $query->getOrderBy();
if (empty($orderBy)) {
return '';
}
// Build orders, each with direction considered
$statements = array();
foreach ($orderBy as $clause => $dir) {
$statements[] = trim("$clause $dir");
}
$nl = $this->getSeparator();
return "{$nl}ORDER BY " . implode(', ', $statements);
} | php | public function buildOrderByFragment(SQLSelect $query, array &$parameters)
{
$orderBy = $query->getOrderBy();
if (empty($orderBy)) {
return '';
}
// Build orders, each with direction considered
$statements = array();
foreach ($orderBy as $clause => $dir) {
$statements[] = trim("$clause $dir");
}
$nl = $this->getSeparator();
return "{$nl}ORDER BY " . implode(', ', $statements);
} | [
"public",
"function",
"buildOrderByFragment",
"(",
"SQLSelect",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"orderBy",
"=",
"$",
"query",
"->",
"getOrderBy",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"orderBy",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Build orders, each with direction considered",
"$",
"statements",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"clause",
"=>",
"$",
"dir",
")",
"{",
"$",
"statements",
"[",
"]",
"=",
"trim",
"(",
"\"$clause $dir\"",
")",
";",
"}",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"return",
"\"{$nl}ORDER BY \"",
".",
"implode",
"(",
"', '",
",",
"$",
"statements",
")",
";",
"}"
]
| Returns the ORDER BY clauses ready for inserting into a query.
@param SQLSelect $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed order by part of statement | [
"Returns",
"the",
"ORDER",
"BY",
"clauses",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L279-L294 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildGroupByFragment | public function buildGroupByFragment(SQLSelect $query, array &$parameters)
{
$groupBy = $query->getGroupBy();
if (empty($groupBy)) {
return '';
}
$nl = $this->getSeparator();
return "{$nl}GROUP BY " . implode(', ', $groupBy);
} | php | public function buildGroupByFragment(SQLSelect $query, array &$parameters)
{
$groupBy = $query->getGroupBy();
if (empty($groupBy)) {
return '';
}
$nl = $this->getSeparator();
return "{$nl}GROUP BY " . implode(', ', $groupBy);
} | [
"public",
"function",
"buildGroupByFragment",
"(",
"SQLSelect",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"groupBy",
"=",
"$",
"query",
"->",
"getGroupBy",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"groupBy",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"return",
"\"{$nl}GROUP BY \"",
".",
"implode",
"(",
"', '",
",",
"$",
"groupBy",
")",
";",
"}"
]
| Returns the GROUP BY clauses ready for inserting into a query.
@param SQLSelect $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string Completed group part of statement | [
"Returns",
"the",
"GROUP",
"BY",
"clauses",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L303-L312 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildHavingFragment | public function buildHavingFragment(SQLSelect $query, array &$parameters)
{
$having = $query->getHavingParameterised($havingParameters);
if (empty($having)) {
return '';
}
// Generate having, considering parameters present
$connective = $query->getConnective();
$parameters = array_merge($parameters, $havingParameters);
$nl = $this->getSeparator();
return "{$nl}HAVING (" . implode("){$nl}{$connective} (", $having) . ")";
} | php | public function buildHavingFragment(SQLSelect $query, array &$parameters)
{
$having = $query->getHavingParameterised($havingParameters);
if (empty($having)) {
return '';
}
// Generate having, considering parameters present
$connective = $query->getConnective();
$parameters = array_merge($parameters, $havingParameters);
$nl = $this->getSeparator();
return "{$nl}HAVING (" . implode("){$nl}{$connective} (", $having) . ")";
} | [
"public",
"function",
"buildHavingFragment",
"(",
"SQLSelect",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"having",
"=",
"$",
"query",
"->",
"getHavingParameterised",
"(",
"$",
"havingParameters",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"having",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Generate having, considering parameters present",
"$",
"connective",
"=",
"$",
"query",
"->",
"getConnective",
"(",
")",
";",
"$",
"parameters",
"=",
"array_merge",
"(",
"$",
"parameters",
",",
"$",
"havingParameters",
")",
";",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"return",
"\"{$nl}HAVING (\"",
".",
"implode",
"(",
"\"){$nl}{$connective} (\"",
",",
"$",
"having",
")",
".",
"\")\"",
";",
"}"
]
| Returns the HAVING clauses ready for inserting into a query.
@param SQLSelect $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string | [
"Returns",
"the",
"HAVING",
"clauses",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L321-L333 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/DBQueryBuilder.php | DBQueryBuilder.buildLimitFragment | public function buildLimitFragment(SQLSelect $query, array &$parameters)
{
$nl = $this->getSeparator();
// Ensure limit is given
$limit = $query->getLimit();
if (empty($limit)) {
return '';
}
// For literal values return this as the limit SQL
if (!is_array($limit)) {
return "{$nl}LIMIT $limit";
}
// Assert that the array version provides the 'limit' key
if (!isset($limit['limit']) || !is_numeric($limit['limit'])) {
throw new InvalidArgumentException(
'DBQueryBuilder::buildLimitSQL(): Wrong format for $limit: ' . var_export($limit, true)
);
}
// Format the array limit, given an optional start key
$clause = "{$nl}LIMIT {$limit['limit']}";
if (isset($limit['start']) && is_numeric($limit['start']) && $limit['start'] !== 0) {
$clause .= " OFFSET {$limit['start']}";
}
return $clause;
} | php | public function buildLimitFragment(SQLSelect $query, array &$parameters)
{
$nl = $this->getSeparator();
// Ensure limit is given
$limit = $query->getLimit();
if (empty($limit)) {
return '';
}
// For literal values return this as the limit SQL
if (!is_array($limit)) {
return "{$nl}LIMIT $limit";
}
// Assert that the array version provides the 'limit' key
if (!isset($limit['limit']) || !is_numeric($limit['limit'])) {
throw new InvalidArgumentException(
'DBQueryBuilder::buildLimitSQL(): Wrong format for $limit: ' . var_export($limit, true)
);
}
// Format the array limit, given an optional start key
$clause = "{$nl}LIMIT {$limit['limit']}";
if (isset($limit['start']) && is_numeric($limit['start']) && $limit['start'] !== 0) {
$clause .= " OFFSET {$limit['start']}";
}
return $clause;
} | [
"public",
"function",
"buildLimitFragment",
"(",
"SQLSelect",
"$",
"query",
",",
"array",
"&",
"$",
"parameters",
")",
"{",
"$",
"nl",
"=",
"$",
"this",
"->",
"getSeparator",
"(",
")",
";",
"// Ensure limit is given",
"$",
"limit",
"=",
"$",
"query",
"->",
"getLimit",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"limit",
")",
")",
"{",
"return",
"''",
";",
"}",
"// For literal values return this as the limit SQL",
"if",
"(",
"!",
"is_array",
"(",
"$",
"limit",
")",
")",
"{",
"return",
"\"{$nl}LIMIT $limit\"",
";",
"}",
"// Assert that the array version provides the 'limit' key",
"if",
"(",
"!",
"isset",
"(",
"$",
"limit",
"[",
"'limit'",
"]",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"limit",
"[",
"'limit'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'DBQueryBuilder::buildLimitSQL(): Wrong format for $limit: '",
".",
"var_export",
"(",
"$",
"limit",
",",
"true",
")",
")",
";",
"}",
"// Format the array limit, given an optional start key",
"$",
"clause",
"=",
"\"{$nl}LIMIT {$limit['limit']}\"",
";",
"if",
"(",
"isset",
"(",
"$",
"limit",
"[",
"'start'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"limit",
"[",
"'start'",
"]",
")",
"&&",
"$",
"limit",
"[",
"'start'",
"]",
"!==",
"0",
")",
"{",
"$",
"clause",
".=",
"\" OFFSET {$limit['start']}\"",
";",
"}",
"return",
"$",
"clause",
";",
"}"
]
| Return the LIMIT clause ready for inserting into a query.
@param SQLSelect $query The expression object to build from
@param array $parameters Out parameter for the resulting query parameters
@return string The finalised limit SQL fragment | [
"Return",
"the",
"LIMIT",
"clause",
"ready",
"for",
"inserting",
"into",
"a",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/DBQueryBuilder.php#L342-L370 | train |
silverstripe/silverstripe-framework | src/Security/RequestAuthenticationHandler.php | RequestAuthenticationHandler.logIn | public function logIn(Member $member, $persistent = false, HTTPRequest $request = null)
{
$member->beforeMemberLoggedIn();
foreach ($this->getHandlers() as $handler) {
$handler->logIn($member, $persistent, $request);
}
Security::setCurrentUser($member);
$member->afterMemberLoggedIn();
} | php | public function logIn(Member $member, $persistent = false, HTTPRequest $request = null)
{
$member->beforeMemberLoggedIn();
foreach ($this->getHandlers() as $handler) {
$handler->logIn($member, $persistent, $request);
}
Security::setCurrentUser($member);
$member->afterMemberLoggedIn();
} | [
"public",
"function",
"logIn",
"(",
"Member",
"$",
"member",
",",
"$",
"persistent",
"=",
"false",
",",
"HTTPRequest",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"member",
"->",
"beforeMemberLoggedIn",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getHandlers",
"(",
")",
"as",
"$",
"handler",
")",
"{",
"$",
"handler",
"->",
"logIn",
"(",
"$",
"member",
",",
"$",
"persistent",
",",
"$",
"request",
")",
";",
"}",
"Security",
"::",
"setCurrentUser",
"(",
"$",
"member",
")",
";",
"$",
"member",
"->",
"afterMemberLoggedIn",
"(",
")",
";",
"}"
]
| Log into the identity-store handlers attached to this request filter
@param Member $member
@param bool $persistent
@param HTTPRequest $request | [
"Log",
"into",
"the",
"identity",
"-",
"store",
"handlers",
"attached",
"to",
"this",
"request",
"filter"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Security/RequestAuthenticationHandler.php#L58-L68 | train |
silverstripe/silverstripe-framework | src/Security/RequestAuthenticationHandler.php | RequestAuthenticationHandler.logOut | public function logOut(HTTPRequest $request = null)
{
$member = Security::getCurrentUser();
if ($member) {
$member->beforeMemberLoggedOut($request);
}
foreach ($this->getHandlers() as $handler) {
$handler->logOut($request);
}
Security::setCurrentUser(null);
if ($member) {
$member->afterMemberLoggedOut($request);
}
} | php | public function logOut(HTTPRequest $request = null)
{
$member = Security::getCurrentUser();
if ($member) {
$member->beforeMemberLoggedOut($request);
}
foreach ($this->getHandlers() as $handler) {
$handler->logOut($request);
}
Security::setCurrentUser(null);
if ($member) {
$member->afterMemberLoggedOut($request);
}
} | [
"public",
"function",
"logOut",
"(",
"HTTPRequest",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"member",
"=",
"Security",
"::",
"getCurrentUser",
"(",
")",
";",
"if",
"(",
"$",
"member",
")",
"{",
"$",
"member",
"->",
"beforeMemberLoggedOut",
"(",
"$",
"request",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getHandlers",
"(",
")",
"as",
"$",
"handler",
")",
"{",
"$",
"handler",
"->",
"logOut",
"(",
"$",
"request",
")",
";",
"}",
"Security",
"::",
"setCurrentUser",
"(",
"null",
")",
";",
"if",
"(",
"$",
"member",
")",
"{",
"$",
"member",
"->",
"afterMemberLoggedOut",
"(",
"$",
"request",
")",
";",
"}",
"}"
]
| Log out of all the identity-store handlers attached to this request filter
@param HTTPRequest $request | [
"Log",
"out",
"of",
"all",
"the",
"identity",
"-",
"store",
"handlers",
"attached",
"to",
"this",
"request",
"filter"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Security/RequestAuthenticationHandler.php#L75-L91 | train |
silverstripe/silverstripe-framework | src/Dev/CliDebugView.php | CliDebugView.renderError | public function renderError($httpRequest, $errno, $errstr, $errfile, $errline)
{
if (!isset(self::$error_types[$errno])) {
$errorTypeTitle = "UNKNOWN TYPE, ERRNO $errno";
} else {
$errorTypeTitle = self::$error_types[$errno]['title'];
}
$output = CLI::text("ERROR [" . $errorTypeTitle . "]: $errstr\nIN $httpRequest\n", "red", null, true);
$output .= CLI::text("Line $errline in $errfile\n\n", "red");
return $output;
} | php | public function renderError($httpRequest, $errno, $errstr, $errfile, $errline)
{
if (!isset(self::$error_types[$errno])) {
$errorTypeTitle = "UNKNOWN TYPE, ERRNO $errno";
} else {
$errorTypeTitle = self::$error_types[$errno]['title'];
}
$output = CLI::text("ERROR [" . $errorTypeTitle . "]: $errstr\nIN $httpRequest\n", "red", null, true);
$output .= CLI::text("Line $errline in $errfile\n\n", "red");
return $output;
} | [
"public",
"function",
"renderError",
"(",
"$",
"httpRequest",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"error_types",
"[",
"$",
"errno",
"]",
")",
")",
"{",
"$",
"errorTypeTitle",
"=",
"\"UNKNOWN TYPE, ERRNO $errno\"",
";",
"}",
"else",
"{",
"$",
"errorTypeTitle",
"=",
"self",
"::",
"$",
"error_types",
"[",
"$",
"errno",
"]",
"[",
"'title'",
"]",
";",
"}",
"$",
"output",
"=",
"CLI",
"::",
"text",
"(",
"\"ERROR [\"",
".",
"$",
"errorTypeTitle",
".",
"\"]: $errstr\\nIN $httpRequest\\n\"",
",",
"\"red\"",
",",
"null",
",",
"true",
")",
";",
"$",
"output",
".=",
"CLI",
"::",
"text",
"(",
"\"Line $errline in $errfile\\n\\n\"",
",",
"\"red\"",
")",
";",
"return",
"$",
"output",
";",
"}"
]
| Write information about the error to the screen
@param string $httpRequest
@param int $errno
@param string $errstr
@param string $errfile
@param int $errline
@return string | [
"Write",
"information",
"about",
"the",
"error",
"to",
"the",
"screen"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Dev/CliDebugView.php#L46-L57 | train |
silverstripe/silverstripe-framework | src/Dev/CliDebugView.php | CliDebugView.renderSourceFragment | public function renderSourceFragment($lines, $errline)
{
$output = "Source\n======\n";
foreach ($lines as $offset => $line) {
$output .= ($offset == $errline) ? "* " : " ";
$output .= str_pad("$offset:", 5);
$output .= wordwrap($line, self::config()->columns, "\n ");
}
$output .= "\n";
return $output;
} | php | public function renderSourceFragment($lines, $errline)
{
$output = "Source\n======\n";
foreach ($lines as $offset => $line) {
$output .= ($offset == $errline) ? "* " : " ";
$output .= str_pad("$offset:", 5);
$output .= wordwrap($line, self::config()->columns, "\n ");
}
$output .= "\n";
return $output;
} | [
"public",
"function",
"renderSourceFragment",
"(",
"$",
"lines",
",",
"$",
"errline",
")",
"{",
"$",
"output",
"=",
"\"Source\\n======\\n\"",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"offset",
"=>",
"$",
"line",
")",
"{",
"$",
"output",
".=",
"(",
"$",
"offset",
"==",
"$",
"errline",
")",
"?",
"\"* \"",
":",
"\" \"",
";",
"$",
"output",
".=",
"str_pad",
"(",
"\"$offset:\"",
",",
"5",
")",
";",
"$",
"output",
".=",
"wordwrap",
"(",
"$",
"line",
",",
"self",
"::",
"config",
"(",
")",
"->",
"columns",
",",
"\"\\n \"",
")",
";",
"}",
"$",
"output",
".=",
"\"\\n\"",
";",
"return",
"$",
"output",
";",
"}"
]
| Write a fragment of the a source file
@param array $lines An array of file lines; the keys should be the original line numbers
@param int $errline Index of the line in $lines which has the error
@return string | [
"Write",
"a",
"fragment",
"of",
"the",
"a",
"source",
"file"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Dev/CliDebugView.php#L66-L77 | train |
silverstripe/silverstripe-framework | src/Dev/CliDebugView.php | CliDebugView.renderTrace | public function renderTrace($trace = null)
{
$output = "Trace\n=====\n";
$output .= Backtrace::get_rendered_backtrace($trace ? $trace : debug_backtrace(), true);
return $output;
} | php | public function renderTrace($trace = null)
{
$output = "Trace\n=====\n";
$output .= Backtrace::get_rendered_backtrace($trace ? $trace : debug_backtrace(), true);
return $output;
} | [
"public",
"function",
"renderTrace",
"(",
"$",
"trace",
"=",
"null",
")",
"{",
"$",
"output",
"=",
"\"Trace\\n=====\\n\"",
";",
"$",
"output",
".=",
"Backtrace",
"::",
"get_rendered_backtrace",
"(",
"$",
"trace",
"?",
"$",
"trace",
":",
"debug_backtrace",
"(",
")",
",",
"true",
")",
";",
"return",
"$",
"output",
";",
"}"
]
| Write a backtrace
@param array $trace
@return string | [
"Write",
"a",
"backtrace"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Dev/CliDebugView.php#L85-L91 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/VersionProvider.php | VersionProvider.getVersion | public function getVersion()
{
$modules = $this->getModules();
$lockModules = $this->getModuleVersionFromComposer(array_keys($modules));
$output = [];
foreach ($modules as $module => $title) {
$version = isset($lockModules[$module])
? $lockModules[$module]
: _t(__CLASS__ . '.VERSIONUNKNOWN', 'Unknown');
$output[] = $title . ': ' . $version;
}
return implode(', ', $output);
} | php | public function getVersion()
{
$modules = $this->getModules();
$lockModules = $this->getModuleVersionFromComposer(array_keys($modules));
$output = [];
foreach ($modules as $module => $title) {
$version = isset($lockModules[$module])
? $lockModules[$module]
: _t(__CLASS__ . '.VERSIONUNKNOWN', 'Unknown');
$output[] = $title . ': ' . $version;
}
return implode(', ', $output);
} | [
"public",
"function",
"getVersion",
"(",
")",
"{",
"$",
"modules",
"=",
"$",
"this",
"->",
"getModules",
"(",
")",
";",
"$",
"lockModules",
"=",
"$",
"this",
"->",
"getModuleVersionFromComposer",
"(",
"array_keys",
"(",
"$",
"modules",
")",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"module",
"=>",
"$",
"title",
")",
"{",
"$",
"version",
"=",
"isset",
"(",
"$",
"lockModules",
"[",
"$",
"module",
"]",
")",
"?",
"$",
"lockModules",
"[",
"$",
"module",
"]",
":",
"_t",
"(",
"__CLASS__",
".",
"'.VERSIONUNKNOWN'",
",",
"'Unknown'",
")",
";",
"$",
"output",
"[",
"]",
"=",
"$",
"title",
".",
"': '",
".",
"$",
"version",
";",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"output",
")",
";",
"}"
]
| Gets a comma delimited string of package titles and versions
@return string | [
"Gets",
"a",
"comma",
"delimited",
"string",
"of",
"package",
"titles",
"and",
"versions"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/VersionProvider.php#L32-L44 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/VersionProvider.php | VersionProvider.getModuleVersionFromComposer | public function getModuleVersionFromComposer($modules = [])
{
$versions = [];
$lockData = $this->getComposerLock();
if ($lockData && !empty($lockData['packages'])) {
foreach ($lockData['packages'] as $package) {
if (in_array($package['name'], $modules) && isset($package['version'])) {
$versions[$package['name']] = $package['version'];
}
}
}
return $versions;
} | php | public function getModuleVersionFromComposer($modules = [])
{
$versions = [];
$lockData = $this->getComposerLock();
if ($lockData && !empty($lockData['packages'])) {
foreach ($lockData['packages'] as $package) {
if (in_array($package['name'], $modules) && isset($package['version'])) {
$versions[$package['name']] = $package['version'];
}
}
}
return $versions;
} | [
"public",
"function",
"getModuleVersionFromComposer",
"(",
"$",
"modules",
"=",
"[",
"]",
")",
"{",
"$",
"versions",
"=",
"[",
"]",
";",
"$",
"lockData",
"=",
"$",
"this",
"->",
"getComposerLock",
"(",
")",
";",
"if",
"(",
"$",
"lockData",
"&&",
"!",
"empty",
"(",
"$",
"lockData",
"[",
"'packages'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"lockData",
"[",
"'packages'",
"]",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"package",
"[",
"'name'",
"]",
",",
"$",
"modules",
")",
"&&",
"isset",
"(",
"$",
"package",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"versions",
"[",
"$",
"package",
"[",
"'name'",
"]",
"]",
"=",
"$",
"package",
"[",
"'version'",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"versions",
";",
"}"
]
| Tries to obtain version number from composer.lock if it exists
@param array $modules
@return array | [
"Tries",
"to",
"obtain",
"version",
"number",
"from",
"composer",
".",
"lock",
"if",
"it",
"exists"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/VersionProvider.php#L64-L76 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/VersionProvider.php | VersionProvider.getComposerLock | protected function getComposerLock($cache = true)
{
$composerLockPath = BASE_PATH . '/composer.lock';
if (!file_exists($composerLockPath)) {
return [];
}
$lockData = [];
$jsonData = file_get_contents($composerLockPath);
if ($cache) {
$cache = Injector::inst()->get(CacheInterface::class . '.VersionProvider_composerlock');
$cacheKey = md5($jsonData);
if ($versions = $cache->get($cacheKey)) {
$lockData = json_decode($versions, true);
}
}
if (empty($lockData) && $jsonData) {
$lockData = json_decode($jsonData, true);
if ($cache) {
$cache->set($cacheKey, $jsonData);
}
}
return $lockData;
} | php | protected function getComposerLock($cache = true)
{
$composerLockPath = BASE_PATH . '/composer.lock';
if (!file_exists($composerLockPath)) {
return [];
}
$lockData = [];
$jsonData = file_get_contents($composerLockPath);
if ($cache) {
$cache = Injector::inst()->get(CacheInterface::class . '.VersionProvider_composerlock');
$cacheKey = md5($jsonData);
if ($versions = $cache->get($cacheKey)) {
$lockData = json_decode($versions, true);
}
}
if (empty($lockData) && $jsonData) {
$lockData = json_decode($jsonData, true);
if ($cache) {
$cache->set($cacheKey, $jsonData);
}
}
return $lockData;
} | [
"protected",
"function",
"getComposerLock",
"(",
"$",
"cache",
"=",
"true",
")",
"{",
"$",
"composerLockPath",
"=",
"BASE_PATH",
".",
"'/composer.lock'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"composerLockPath",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"lockData",
"=",
"[",
"]",
";",
"$",
"jsonData",
"=",
"file_get_contents",
"(",
"$",
"composerLockPath",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"$",
"cache",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"CacheInterface",
"::",
"class",
".",
"'.VersionProvider_composerlock'",
")",
";",
"$",
"cacheKey",
"=",
"md5",
"(",
"$",
"jsonData",
")",
";",
"if",
"(",
"$",
"versions",
"=",
"$",
"cache",
"->",
"get",
"(",
"$",
"cacheKey",
")",
")",
"{",
"$",
"lockData",
"=",
"json_decode",
"(",
"$",
"versions",
",",
"true",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"lockData",
")",
"&&",
"$",
"jsonData",
")",
"{",
"$",
"lockData",
"=",
"json_decode",
"(",
"$",
"jsonData",
",",
"true",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"$",
"cache",
"->",
"set",
"(",
"$",
"cacheKey",
",",
"$",
"jsonData",
")",
";",
"}",
"}",
"return",
"$",
"lockData",
";",
"}"
]
| Load composer.lock's contents and return it
@param bool $cache
@return array | [
"Load",
"composer",
".",
"lock",
"s",
"contents",
"and",
"return",
"it"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/VersionProvider.php#L84-L111 | train |
silverstripe/silverstripe-framework | src/View/Parsers/Transliterator.php | Transliterator.toASCII | public function toASCII($source)
{
if (function_exists('iconv') && $this->config()->use_iconv) {
return $this->useIconv($source);
} else {
return $this->useStrTr($source);
}
} | php | public function toASCII($source)
{
if (function_exists('iconv') && $this->config()->use_iconv) {
return $this->useIconv($source);
} else {
return $this->useStrTr($source);
}
} | [
"public",
"function",
"toASCII",
"(",
"$",
"source",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'iconv'",
")",
"&&",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"use_iconv",
")",
"{",
"return",
"$",
"this",
"->",
"useIconv",
"(",
"$",
"source",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"useStrTr",
"(",
"$",
"source",
")",
";",
"}",
"}"
]
| Convert the given utf8 string to a safe ASCII source
@param string $source
@return string | [
"Convert",
"the",
"given",
"utf8",
"string",
"to",
"a",
"safe",
"ASCII",
"source"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/View/Parsers/Transliterator.php#L36-L43 | train |
silverstripe/silverstripe-framework | src/Forms/FileUploadReceiver.php | FileUploadReceiver.getRelationAutosetClass | public function getRelationAutosetClass($default = File::class)
{
// Don't autodetermine relation if no relationship between parent record
if (!$this->getRelationAutoSetting()) {
return $default;
}
// Check record and name
$name = $this->getName();
$record = $this->getRecord();
if (empty($name) || empty($record)) {
return $default;
} else {
$class = $record->getRelationClass($name);
return empty($class) ? $default : $class;
}
} | php | public function getRelationAutosetClass($default = File::class)
{
// Don't autodetermine relation if no relationship between parent record
if (!$this->getRelationAutoSetting()) {
return $default;
}
// Check record and name
$name = $this->getName();
$record = $this->getRecord();
if (empty($name) || empty($record)) {
return $default;
} else {
$class = $record->getRelationClass($name);
return empty($class) ? $default : $class;
}
} | [
"public",
"function",
"getRelationAutosetClass",
"(",
"$",
"default",
"=",
"File",
"::",
"class",
")",
"{",
"// Don't autodetermine relation if no relationship between parent record",
"if",
"(",
"!",
"$",
"this",
"->",
"getRelationAutoSetting",
"(",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// Check record and name",
"$",
"name",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"record",
"=",
"$",
"this",
"->",
"getRecord",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"name",
")",
"||",
"empty",
"(",
"$",
"record",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"$",
"record",
"->",
"getRelationClass",
"(",
"$",
"name",
")",
";",
"return",
"empty",
"(",
"$",
"class",
")",
"?",
"$",
"default",
":",
"$",
"class",
";",
"}",
"}"
]
| Gets the foreign class that needs to be created, or 'File' as default if there
is no relationship, or it cannot be determined.
@param string $default Default value to return if no value could be calculated
@return string Foreign class name. | [
"Gets",
"the",
"foreign",
"class",
"that",
"needs",
"to",
"be",
"created",
"or",
"File",
"as",
"default",
"if",
"there",
"is",
"no",
"relationship",
"or",
"it",
"cannot",
"be",
"determined",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/FileUploadReceiver.php#L351-L367 | train |
silverstripe/silverstripe-framework | src/Forms/FileUploadReceiver.php | FileUploadReceiver.extractUploadedFileData | protected function extractUploadedFileData($postVars)
{
// Note: Format of posted file parameters in php is a feature of using
// <input name='{$Name}[Uploads][]' /> for multiple file uploads
$tmpFiles = array();
if (!empty($postVars['tmp_name'])
&& is_array($postVars['tmp_name'])
&& !empty($postVars['tmp_name']['Uploads'])
) {
for ($i = 0; $i < count($postVars['tmp_name']['Uploads']); $i++) {
// Skip if "empty" file
if (empty($postVars['tmp_name']['Uploads'][$i])) {
continue;
}
$tmpFile = array();
foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $field) {
$tmpFile[$field] = $postVars[$field]['Uploads'][$i];
}
$tmpFiles[] = $tmpFile;
}
} elseif (!empty($postVars['tmp_name'])) {
// Fallback to allow single file uploads (method used by AssetUploadField)
$tmpFiles[] = $postVars;
}
return $tmpFiles;
} | php | protected function extractUploadedFileData($postVars)
{
// Note: Format of posted file parameters in php is a feature of using
// <input name='{$Name}[Uploads][]' /> for multiple file uploads
$tmpFiles = array();
if (!empty($postVars['tmp_name'])
&& is_array($postVars['tmp_name'])
&& !empty($postVars['tmp_name']['Uploads'])
) {
for ($i = 0; $i < count($postVars['tmp_name']['Uploads']); $i++) {
// Skip if "empty" file
if (empty($postVars['tmp_name']['Uploads'][$i])) {
continue;
}
$tmpFile = array();
foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $field) {
$tmpFile[$field] = $postVars[$field]['Uploads'][$i];
}
$tmpFiles[] = $tmpFile;
}
} elseif (!empty($postVars['tmp_name'])) {
// Fallback to allow single file uploads (method used by AssetUploadField)
$tmpFiles[] = $postVars;
}
return $tmpFiles;
} | [
"protected",
"function",
"extractUploadedFileData",
"(",
"$",
"postVars",
")",
"{",
"// Note: Format of posted file parameters in php is a feature of using",
"// <input name='{$Name}[Uploads][]' /> for multiple file uploads",
"$",
"tmpFiles",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"postVars",
"[",
"'tmp_name'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"postVars",
"[",
"'tmp_name'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"postVars",
"[",
"'tmp_name'",
"]",
"[",
"'Uploads'",
"]",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"postVars",
"[",
"'tmp_name'",
"]",
"[",
"'Uploads'",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"// Skip if \"empty\" file",
"if",
"(",
"empty",
"(",
"$",
"postVars",
"[",
"'tmp_name'",
"]",
"[",
"'Uploads'",
"]",
"[",
"$",
"i",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"tmpFile",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array",
"(",
"'name'",
",",
"'type'",
",",
"'tmp_name'",
",",
"'error'",
",",
"'size'",
")",
"as",
"$",
"field",
")",
"{",
"$",
"tmpFile",
"[",
"$",
"field",
"]",
"=",
"$",
"postVars",
"[",
"$",
"field",
"]",
"[",
"'Uploads'",
"]",
"[",
"$",
"i",
"]",
";",
"}",
"$",
"tmpFiles",
"[",
"]",
"=",
"$",
"tmpFile",
";",
"}",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"postVars",
"[",
"'tmp_name'",
"]",
")",
")",
"{",
"// Fallback to allow single file uploads (method used by AssetUploadField)",
"$",
"tmpFiles",
"[",
"]",
"=",
"$",
"postVars",
";",
"}",
"return",
"$",
"tmpFiles",
";",
"}"
]
| Given an array of post variables, extract all temporary file data into an array
@param array $postVars Array of posted form data
@return array List of temporary file data | [
"Given",
"an",
"array",
"of",
"post",
"variables",
"extract",
"all",
"temporary",
"file",
"data",
"into",
"an",
"array"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/FileUploadReceiver.php#L397-L423 | train |
silverstripe/silverstripe-framework | src/ORM/Filters/FulltextFilter.php | FulltextFilter.prepareColumns | protected function prepareColumns($columns)
{
$prefix = DataQuery::applyRelationPrefix($this->relation);
$table = DataObject::getSchema()->tableForField($this->model, current($columns));
$fullTable = $prefix . $table;
$columns = array_map(function ($col) use ($fullTable) {
return "\"{$fullTable}\".\"{$col}\"";
}, $columns);
return implode(',', $columns);
} | php | protected function prepareColumns($columns)
{
$prefix = DataQuery::applyRelationPrefix($this->relation);
$table = DataObject::getSchema()->tableForField($this->model, current($columns));
$fullTable = $prefix . $table;
$columns = array_map(function ($col) use ($fullTable) {
return "\"{$fullTable}\".\"{$col}\"";
}, $columns);
return implode(',', $columns);
} | [
"protected",
"function",
"prepareColumns",
"(",
"$",
"columns",
")",
"{",
"$",
"prefix",
"=",
"DataQuery",
"::",
"applyRelationPrefix",
"(",
"$",
"this",
"->",
"relation",
")",
";",
"$",
"table",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"tableForField",
"(",
"$",
"this",
"->",
"model",
",",
"current",
"(",
"$",
"columns",
")",
")",
";",
"$",
"fullTable",
"=",
"$",
"prefix",
".",
"$",
"table",
";",
"$",
"columns",
"=",
"array_map",
"(",
"function",
"(",
"$",
"col",
")",
"use",
"(",
"$",
"fullTable",
")",
"{",
"return",
"\"\\\"{$fullTable}\\\".\\\"{$col}\\\"\"",
";",
"}",
",",
"$",
"columns",
")",
";",
"return",
"implode",
"(",
"','",
",",
"$",
"columns",
")",
";",
"}"
]
| Adds table identifier to the every column.
Columns must have table identifier to prevent duplicate column name error.
@param array $columns
@return string | [
"Adds",
"table",
"identifier",
"to",
"the",
"every",
"column",
".",
"Columns",
"must",
"have",
"table",
"identifier",
"to",
"prevent",
"duplicate",
"column",
"name",
"error",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Filters/FulltextFilter.php#L92-L101 | train |
silverstripe/silverstripe-framework | src/Forms/TreeMultiselectField.php | TreeMultiselectField.getItems | public function getItems()
{
$items = new ArrayList();
// If the value has been set, use that
if ($this->value != 'unchanged') {
$sourceObject = $this->getSourceObject();
if (is_array($sourceObject)) {
$values = is_array($this->value) ? $this->value : preg_split('/ *, */', trim($this->value));
foreach ($values as $value) {
$item = new stdClass;
$item->ID = $value;
$item->Title = $sourceObject[$value];
$items->push($item);
}
return $items;
}
// Otherwise, look data up from the linked relation
if (is_string($this->value)) {
$ids = explode(',', $this->value);
foreach ($ids as $id) {
if (!is_numeric($id)) {
continue;
}
$item = DataObject::get_by_id($sourceObject, $id);
if ($item) {
$items->push($item);
}
}
return $items;
}
}
if ($this->form) {
$fieldName = $this->name;
$record = $this->form->getRecord();
if (is_object($record) && $record->hasMethod($fieldName)) {
return $record->$fieldName();
}
}
return $items;
} | php | public function getItems()
{
$items = new ArrayList();
// If the value has been set, use that
if ($this->value != 'unchanged') {
$sourceObject = $this->getSourceObject();
if (is_array($sourceObject)) {
$values = is_array($this->value) ? $this->value : preg_split('/ *, */', trim($this->value));
foreach ($values as $value) {
$item = new stdClass;
$item->ID = $value;
$item->Title = $sourceObject[$value];
$items->push($item);
}
return $items;
}
// Otherwise, look data up from the linked relation
if (is_string($this->value)) {
$ids = explode(',', $this->value);
foreach ($ids as $id) {
if (!is_numeric($id)) {
continue;
}
$item = DataObject::get_by_id($sourceObject, $id);
if ($item) {
$items->push($item);
}
}
return $items;
}
}
if ($this->form) {
$fieldName = $this->name;
$record = $this->form->getRecord();
if (is_object($record) && $record->hasMethod($fieldName)) {
return $record->$fieldName();
}
}
return $items;
} | [
"public",
"function",
"getItems",
"(",
")",
"{",
"$",
"items",
"=",
"new",
"ArrayList",
"(",
")",
";",
"// If the value has been set, use that",
"if",
"(",
"$",
"this",
"->",
"value",
"!=",
"'unchanged'",
")",
"{",
"$",
"sourceObject",
"=",
"$",
"this",
"->",
"getSourceObject",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"sourceObject",
")",
")",
"{",
"$",
"values",
"=",
"is_array",
"(",
"$",
"this",
"->",
"value",
")",
"?",
"$",
"this",
"->",
"value",
":",
"preg_split",
"(",
"'/ *, */'",
",",
"trim",
"(",
"$",
"this",
"->",
"value",
")",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"item",
"=",
"new",
"stdClass",
";",
"$",
"item",
"->",
"ID",
"=",
"$",
"value",
";",
"$",
"item",
"->",
"Title",
"=",
"$",
"sourceObject",
"[",
"$",
"value",
"]",
";",
"$",
"items",
"->",
"push",
"(",
"$",
"item",
")",
";",
"}",
"return",
"$",
"items",
";",
"}",
"// Otherwise, look data up from the linked relation",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"ids",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"value",
")",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"continue",
";",
"}",
"$",
"item",
"=",
"DataObject",
"::",
"get_by_id",
"(",
"$",
"sourceObject",
",",
"$",
"id",
")",
";",
"if",
"(",
"$",
"item",
")",
"{",
"$",
"items",
"->",
"push",
"(",
"$",
"item",
")",
";",
"}",
"}",
"return",
"$",
"items",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"form",
")",
"{",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"name",
";",
"$",
"record",
"=",
"$",
"this",
"->",
"form",
"->",
"getRecord",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"record",
")",
"&&",
"$",
"record",
"->",
"hasMethod",
"(",
"$",
"fieldName",
")",
")",
"{",
"return",
"$",
"record",
"->",
"$",
"fieldName",
"(",
")",
";",
"}",
"}",
"return",
"$",
"items",
";",
"}"
]
| Return this field's linked items
@return ArrayList|DataList $items | [
"Return",
"this",
"field",
"s",
"linked",
"items"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TreeMultiselectField.php#L120-L164 | train |
silverstripe/silverstripe-framework | src/Forms/TreeMultiselectField.php | TreeMultiselectField.Field | public function Field($properties = array())
{
$value = '';
$titleArray = array();
$idArray = array();
$items = $this->getItems();
$emptyTitle = _t('SilverStripe\\Forms\\DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');
if ($items && count($items)) {
foreach ($items as $item) {
$idArray[] = $item->ID;
$titleArray[] = ($item instanceof ViewableData)
? $item->obj($this->getLabelField())->forTemplate()
: Convert::raw2xml($item->{$this->getLabelField()});
}
$title = implode(", ", $titleArray);
sort($idArray);
$value = implode(",", $idArray);
} else {
$title = $emptyTitle;
}
$dataUrlTree = '';
if ($this->form) {
$dataUrlTree = $this->Link('tree');
if (!empty($idArray)) {
$dataUrlTree = Controller::join_links($dataUrlTree, '?forceValue=' . implode(',', $idArray));
}
}
$properties = array_merge(
$properties,
array(
'Title' => $title,
'EmptyTitle' => $emptyTitle,
'Link' => $dataUrlTree,
'Value' => $value
)
);
return FormField::Field($properties);
} | php | public function Field($properties = array())
{
$value = '';
$titleArray = array();
$idArray = array();
$items = $this->getItems();
$emptyTitle = _t('SilverStripe\\Forms\\DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');
if ($items && count($items)) {
foreach ($items as $item) {
$idArray[] = $item->ID;
$titleArray[] = ($item instanceof ViewableData)
? $item->obj($this->getLabelField())->forTemplate()
: Convert::raw2xml($item->{$this->getLabelField()});
}
$title = implode(", ", $titleArray);
sort($idArray);
$value = implode(",", $idArray);
} else {
$title = $emptyTitle;
}
$dataUrlTree = '';
if ($this->form) {
$dataUrlTree = $this->Link('tree');
if (!empty($idArray)) {
$dataUrlTree = Controller::join_links($dataUrlTree, '?forceValue=' . implode(',', $idArray));
}
}
$properties = array_merge(
$properties,
array(
'Title' => $title,
'EmptyTitle' => $emptyTitle,
'Link' => $dataUrlTree,
'Value' => $value
)
);
return FormField::Field($properties);
} | [
"public",
"function",
"Field",
"(",
"$",
"properties",
"=",
"array",
"(",
")",
")",
"{",
"$",
"value",
"=",
"''",
";",
"$",
"titleArray",
"=",
"array",
"(",
")",
";",
"$",
"idArray",
"=",
"array",
"(",
")",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"getItems",
"(",
")",
";",
"$",
"emptyTitle",
"=",
"_t",
"(",
"'SilverStripe\\\\Forms\\\\DropdownField.CHOOSE'",
",",
"'(Choose)'",
",",
"'start value of a dropdown'",
")",
";",
"if",
"(",
"$",
"items",
"&&",
"count",
"(",
"$",
"items",
")",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"idArray",
"[",
"]",
"=",
"$",
"item",
"->",
"ID",
";",
"$",
"titleArray",
"[",
"]",
"=",
"(",
"$",
"item",
"instanceof",
"ViewableData",
")",
"?",
"$",
"item",
"->",
"obj",
"(",
"$",
"this",
"->",
"getLabelField",
"(",
")",
")",
"->",
"forTemplate",
"(",
")",
":",
"Convert",
"::",
"raw2xml",
"(",
"$",
"item",
"->",
"{",
"$",
"this",
"->",
"getLabelField",
"(",
")",
"}",
")",
";",
"}",
"$",
"title",
"=",
"implode",
"(",
"\", \"",
",",
"$",
"titleArray",
")",
";",
"sort",
"(",
"$",
"idArray",
")",
";",
"$",
"value",
"=",
"implode",
"(",
"\",\"",
",",
"$",
"idArray",
")",
";",
"}",
"else",
"{",
"$",
"title",
"=",
"$",
"emptyTitle",
";",
"}",
"$",
"dataUrlTree",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"form",
")",
"{",
"$",
"dataUrlTree",
"=",
"$",
"this",
"->",
"Link",
"(",
"'tree'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"idArray",
")",
")",
"{",
"$",
"dataUrlTree",
"=",
"Controller",
"::",
"join_links",
"(",
"$",
"dataUrlTree",
",",
"'?forceValue='",
".",
"implode",
"(",
"','",
",",
"$",
"idArray",
")",
")",
";",
"}",
"}",
"$",
"properties",
"=",
"array_merge",
"(",
"$",
"properties",
",",
"array",
"(",
"'Title'",
"=>",
"$",
"title",
",",
"'EmptyTitle'",
"=>",
"$",
"emptyTitle",
",",
"'Link'",
"=>",
"$",
"dataUrlTree",
",",
"'Value'",
"=>",
"$",
"value",
")",
")",
";",
"return",
"FormField",
"::",
"Field",
"(",
"$",
"properties",
")",
";",
"}"
]
| We overwrite the field attribute to add our hidden fields, as this
formfield can contain multiple values.
@param array $properties
@return DBHTMLText | [
"We",
"overwrite",
"the",
"field",
"attribute",
"to",
"add",
"our",
"hidden",
"fields",
"as",
"this",
"formfield",
"can",
"contain",
"multiple",
"values",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TreeMultiselectField.php#L173-L213 | train |
silverstripe/silverstripe-framework | src/Forms/TreeMultiselectField.php | TreeMultiselectField.performReadonlyTransformation | public function performReadonlyTransformation()
{
/** @var TreeMultiselectField_Readonly $copy */
$copy = $this->castedCopy(TreeMultiselectField_Readonly::class);
$copy->setKeyField($this->getKeyField());
$copy->setLabelField($this->getLabelField());
$copy->setSourceObject($this->getSourceObject());
$copy->setTitleField($this->getTitleField());
return $copy;
} | php | public function performReadonlyTransformation()
{
/** @var TreeMultiselectField_Readonly $copy */
$copy = $this->castedCopy(TreeMultiselectField_Readonly::class);
$copy->setKeyField($this->getKeyField());
$copy->setLabelField($this->getLabelField());
$copy->setSourceObject($this->getSourceObject());
$copy->setTitleField($this->getTitleField());
return $copy;
} | [
"public",
"function",
"performReadonlyTransformation",
"(",
")",
"{",
"/** @var TreeMultiselectField_Readonly $copy */",
"$",
"copy",
"=",
"$",
"this",
"->",
"castedCopy",
"(",
"TreeMultiselectField_Readonly",
"::",
"class",
")",
";",
"$",
"copy",
"->",
"setKeyField",
"(",
"$",
"this",
"->",
"getKeyField",
"(",
")",
")",
";",
"$",
"copy",
"->",
"setLabelField",
"(",
"$",
"this",
"->",
"getLabelField",
"(",
")",
")",
";",
"$",
"copy",
"->",
"setSourceObject",
"(",
"$",
"this",
"->",
"getSourceObject",
"(",
")",
")",
";",
"$",
"copy",
"->",
"setTitleField",
"(",
"$",
"this",
"->",
"getTitleField",
"(",
")",
")",
";",
"return",
"$",
"copy",
";",
"}"
]
| Changes this field to the readonly field. | [
"Changes",
"this",
"field",
"to",
"the",
"readonly",
"field",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Forms/TreeMultiselectField.php#L260-L269 | train |
silverstripe/silverstripe-framework | src/ORM/ListDecorator.php | ListDecorator.setList | public function setList($list)
{
$this->list = $list;
$this->failover = $this->list;
return $this;
} | php | public function setList($list)
{
$this->list = $list;
$this->failover = $this->list;
return $this;
} | [
"public",
"function",
"setList",
"(",
"$",
"list",
")",
"{",
"$",
"this",
"->",
"list",
"=",
"$",
"list",
";",
"$",
"this",
"->",
"failover",
"=",
"$",
"this",
"->",
"list",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the list this decorator wraps around.
Useful for keeping a decorator/paginated list configuration intact while modifying
the underlying list.
@return SS_List | [
"Set",
"the",
"list",
"this",
"decorator",
"wraps",
"around",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/ListDecorator.php#L46-L51 | train |
silverstripe/silverstripe-framework | src/ORM/FieldType/DBMoney.php | DBMoney.getFormatter | public function getFormatter()
{
$locale = $this->getLocale();
$currency = $this->getCurrency();
if ($currency) {
$locale .= '@currency=' . $currency;
}
return NumberFormatter::create($locale, NumberFormatter::CURRENCY);
} | php | public function getFormatter()
{
$locale = $this->getLocale();
$currency = $this->getCurrency();
if ($currency) {
$locale .= '@currency=' . $currency;
}
return NumberFormatter::create($locale, NumberFormatter::CURRENCY);
} | [
"public",
"function",
"getFormatter",
"(",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
")",
";",
"$",
"currency",
"=",
"$",
"this",
"->",
"getCurrency",
"(",
")",
";",
"if",
"(",
"$",
"currency",
")",
"{",
"$",
"locale",
".=",
"'@currency='",
".",
"$",
"currency",
";",
"}",
"return",
"NumberFormatter",
"::",
"create",
"(",
"$",
"locale",
",",
"NumberFormatter",
"::",
"CURRENCY",
")",
";",
"}"
]
| Get currency formatter
@return NumberFormatter | [
"Get",
"currency",
"formatter"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/FieldType/DBMoney.php#L34-L42 | train |
silverstripe/silverstripe-framework | src/ORM/Search/SearchContext.php | SearchContext.getQuery | public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null)
{
/** DataList $query */
$query = null;
if ($existingQuery) {
if (!($existingQuery instanceof DataList)) {
throw new InvalidArgumentException("existingQuery must be DataList");
}
if ($existingQuery->dataClass() != $this->modelClass) {
throw new InvalidArgumentException("existingQuery's dataClass is " . $existingQuery->dataClass()
. ", $this->modelClass expected.");
}
$query = $existingQuery;
} else {
$query = DataList::create($this->modelClass);
}
if (is_array($limit)) {
$query = $query->limit(
isset($limit['limit']) ? $limit['limit'] : null,
isset($limit['start']) ? $limit['start'] : null
);
} else {
$query = $query->limit($limit);
}
/** @var DataList $query */
$query = $query->sort($sort);
$this->setSearchParams($searchParams);
foreach ($this->searchParams as $key => $value) {
$key = str_replace('__', '.', $key);
if ($filter = $this->getFilter($key)) {
$filter->setModel($this->modelClass);
$filter->setValue($value);
if (!$filter->isEmpty()) {
$query = $query->alterDataQuery(array($filter, 'apply'));
}
}
}
if ($this->connective != "AND") {
throw new Exception("SearchContext connective '$this->connective' not supported after ORM-rewrite.");
}
return $query;
} | php | public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null)
{
/** DataList $query */
$query = null;
if ($existingQuery) {
if (!($existingQuery instanceof DataList)) {
throw new InvalidArgumentException("existingQuery must be DataList");
}
if ($existingQuery->dataClass() != $this->modelClass) {
throw new InvalidArgumentException("existingQuery's dataClass is " . $existingQuery->dataClass()
. ", $this->modelClass expected.");
}
$query = $existingQuery;
} else {
$query = DataList::create($this->modelClass);
}
if (is_array($limit)) {
$query = $query->limit(
isset($limit['limit']) ? $limit['limit'] : null,
isset($limit['start']) ? $limit['start'] : null
);
} else {
$query = $query->limit($limit);
}
/** @var DataList $query */
$query = $query->sort($sort);
$this->setSearchParams($searchParams);
foreach ($this->searchParams as $key => $value) {
$key = str_replace('__', '.', $key);
if ($filter = $this->getFilter($key)) {
$filter->setModel($this->modelClass);
$filter->setValue($value);
if (!$filter->isEmpty()) {
$query = $query->alterDataQuery(array($filter, 'apply'));
}
}
}
if ($this->connective != "AND") {
throw new Exception("SearchContext connective '$this->connective' not supported after ORM-rewrite.");
}
return $query;
} | [
"public",
"function",
"getQuery",
"(",
"$",
"searchParams",
",",
"$",
"sort",
"=",
"false",
",",
"$",
"limit",
"=",
"false",
",",
"$",
"existingQuery",
"=",
"null",
")",
"{",
"/** DataList $query */",
"$",
"query",
"=",
"null",
";",
"if",
"(",
"$",
"existingQuery",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"existingQuery",
"instanceof",
"DataList",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"existingQuery must be DataList\"",
")",
";",
"}",
"if",
"(",
"$",
"existingQuery",
"->",
"dataClass",
"(",
")",
"!=",
"$",
"this",
"->",
"modelClass",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"existingQuery's dataClass is \"",
".",
"$",
"existingQuery",
"->",
"dataClass",
"(",
")",
".",
"\", $this->modelClass expected.\"",
")",
";",
"}",
"$",
"query",
"=",
"$",
"existingQuery",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"DataList",
"::",
"create",
"(",
"$",
"this",
"->",
"modelClass",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"limit",
"(",
"isset",
"(",
"$",
"limit",
"[",
"'limit'",
"]",
")",
"?",
"$",
"limit",
"[",
"'limit'",
"]",
":",
"null",
",",
"isset",
"(",
"$",
"limit",
"[",
"'start'",
"]",
")",
"?",
"$",
"limit",
"[",
"'start'",
"]",
":",
"null",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"limit",
"(",
"$",
"limit",
")",
";",
"}",
"/** @var DataList $query */",
"$",
"query",
"=",
"$",
"query",
"->",
"sort",
"(",
"$",
"sort",
")",
";",
"$",
"this",
"->",
"setSearchParams",
"(",
"$",
"searchParams",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"searchParams",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"'__'",
",",
"'.'",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"key",
")",
")",
"{",
"$",
"filter",
"->",
"setModel",
"(",
"$",
"this",
"->",
"modelClass",
")",
";",
"$",
"filter",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"$",
"filter",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"query",
"=",
"$",
"query",
"->",
"alterDataQuery",
"(",
"array",
"(",
"$",
"filter",
",",
"'apply'",
")",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"connective",
"!=",
"\"AND\"",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"SearchContext connective '$this->connective' not supported after ORM-rewrite.\"",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
]
| Returns a SQL object representing the search context for the given
list of query parameters.
@param array $searchParams Map of search criteria, mostly taken from $_REQUEST.
If a filter is applied to a relationship in dot notation,
the parameter name should have the dots replaced with double underscores,
for example "Comments__Name" instead of the filter name "Comments.Name".
@param array|bool|string $sort Database column to sort on.
Falls back to {@link DataObject::$default_sort} if not provided.
@param array|bool|string $limit
@param DataList $existingQuery
@return DataList
@throws Exception | [
"Returns",
"a",
"SQL",
"object",
"representing",
"the",
"search",
"context",
"for",
"the",
"given",
"list",
"of",
"query",
"parameters",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Search/SearchContext.php#L146-L192 | train |
silverstripe/silverstripe-framework | src/ORM/Search/SearchContext.php | SearchContext.getResults | public function getResults($searchParams, $sort = false, $limit = false)
{
$searchParams = array_filter((array)$searchParams, array($this, 'clearEmptySearchFields'));
// getQuery actually returns a DataList
return $this->getQuery($searchParams, $sort, $limit);
} | php | public function getResults($searchParams, $sort = false, $limit = false)
{
$searchParams = array_filter((array)$searchParams, array($this, 'clearEmptySearchFields'));
// getQuery actually returns a DataList
return $this->getQuery($searchParams, $sort, $limit);
} | [
"public",
"function",
"getResults",
"(",
"$",
"searchParams",
",",
"$",
"sort",
"=",
"false",
",",
"$",
"limit",
"=",
"false",
")",
"{",
"$",
"searchParams",
"=",
"array_filter",
"(",
"(",
"array",
")",
"$",
"searchParams",
",",
"array",
"(",
"$",
"this",
",",
"'clearEmptySearchFields'",
")",
")",
";",
"// getQuery actually returns a DataList",
"return",
"$",
"this",
"->",
"getQuery",
"(",
"$",
"searchParams",
",",
"$",
"sort",
",",
"$",
"limit",
")",
";",
"}"
]
| Returns a result set from the given search parameters.
@todo rearrange start and limit params to reflect DataObject
@param array $searchParams
@param array|bool|string $sort
@param array|bool|string $limit
@return DataList
@throws Exception | [
"Returns",
"a",
"result",
"set",
"from",
"the",
"given",
"search",
"parameters",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Search/SearchContext.php#L205-L211 | train |
silverstripe/silverstripe-framework | src/ORM/Search/SearchContext.php | SearchContext.getFilter | public function getFilter($name)
{
if (isset($this->filters[$name])) {
return $this->filters[$name];
} else {
return null;
}
} | php | public function getFilter($name)
{
if (isset($this->filters[$name])) {
return $this->filters[$name];
} else {
return null;
}
} | [
"public",
"function",
"getFilter",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"filters",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
]
| Accessor for the filter attached to a named field.
@param string $name
@return SearchFilter | [
"Accessor",
"for",
"the",
"filter",
"attached",
"to",
"a",
"named",
"field",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Search/SearchContext.php#L231-L238 | train |
silverstripe/silverstripe-framework | src/ORM/Search/SearchContext.php | SearchContext.setSearchParams | public function setSearchParams($searchParams)
{
// hack to work with $searchParams when it's an Object
if ($searchParams instanceof HTTPRequest) {
$this->searchParams = $searchParams->getVars();
} else {
$this->searchParams = $searchParams;
}
return $this;
} | php | public function setSearchParams($searchParams)
{
// hack to work with $searchParams when it's an Object
if ($searchParams instanceof HTTPRequest) {
$this->searchParams = $searchParams->getVars();
} else {
$this->searchParams = $searchParams;
}
return $this;
} | [
"public",
"function",
"setSearchParams",
"(",
"$",
"searchParams",
")",
"{",
"// hack to work with $searchParams when it's an Object",
"if",
"(",
"$",
"searchParams",
"instanceof",
"HTTPRequest",
")",
"{",
"$",
"this",
"->",
"searchParams",
"=",
"$",
"searchParams",
"->",
"getVars",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"searchParams",
"=",
"$",
"searchParams",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set search param values
@param array|HTTPRequest $searchParams
@return $this | [
"Set",
"search",
"param",
"values"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Search/SearchContext.php#L326-L335 | train |
silverstripe/silverstripe-framework | src/ORM/Search/SearchContext.php | SearchContext.getSummary | public function getSummary()
{
$list = ArrayList::create();
foreach ($this->searchParams as $searchField => $searchValue) {
if (empty($searchValue)) {
continue;
}
$filter = $this->getFilter($searchField);
if (!$filter) {
continue;
}
$field = $this->fields->fieldByName($filter->getFullName());
if (!$field) {
continue;
}
// For dropdowns, checkboxes, etc, get the value that was presented to the user
// e.g. not an ID
if ($field instanceof SelectField) {
$source = $field->getSource();
if (isset($source[$searchValue])) {
$searchValue = $source[$searchValue];
}
} else {
// For checkboxes, it suffices to simply include the field in the list, since it's binary
if ($field instanceof CheckboxField) {
$searchValue = null;
}
}
$list->push(ArrayData::create([
'Field' => $field->Title(),
'Value' => $searchValue,
]));
}
return $list;
} | php | public function getSummary()
{
$list = ArrayList::create();
foreach ($this->searchParams as $searchField => $searchValue) {
if (empty($searchValue)) {
continue;
}
$filter = $this->getFilter($searchField);
if (!$filter) {
continue;
}
$field = $this->fields->fieldByName($filter->getFullName());
if (!$field) {
continue;
}
// For dropdowns, checkboxes, etc, get the value that was presented to the user
// e.g. not an ID
if ($field instanceof SelectField) {
$source = $field->getSource();
if (isset($source[$searchValue])) {
$searchValue = $source[$searchValue];
}
} else {
// For checkboxes, it suffices to simply include the field in the list, since it's binary
if ($field instanceof CheckboxField) {
$searchValue = null;
}
}
$list->push(ArrayData::create([
'Field' => $field->Title(),
'Value' => $searchValue,
]));
}
return $list;
} | [
"public",
"function",
"getSummary",
"(",
")",
"{",
"$",
"list",
"=",
"ArrayList",
"::",
"create",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"searchParams",
"as",
"$",
"searchField",
"=>",
"$",
"searchValue",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"searchValue",
")",
")",
"{",
"continue",
";",
"}",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"searchField",
")",
";",
"if",
"(",
"!",
"$",
"filter",
")",
"{",
"continue",
";",
"}",
"$",
"field",
"=",
"$",
"this",
"->",
"fields",
"->",
"fieldByName",
"(",
"$",
"filter",
"->",
"getFullName",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"field",
")",
"{",
"continue",
";",
"}",
"// For dropdowns, checkboxes, etc, get the value that was presented to the user",
"// e.g. not an ID",
"if",
"(",
"$",
"field",
"instanceof",
"SelectField",
")",
"{",
"$",
"source",
"=",
"$",
"field",
"->",
"getSource",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"source",
"[",
"$",
"searchValue",
"]",
")",
")",
"{",
"$",
"searchValue",
"=",
"$",
"source",
"[",
"$",
"searchValue",
"]",
";",
"}",
"}",
"else",
"{",
"// For checkboxes, it suffices to simply include the field in the list, since it's binary",
"if",
"(",
"$",
"field",
"instanceof",
"CheckboxField",
")",
"{",
"$",
"searchValue",
"=",
"null",
";",
"}",
"}",
"$",
"list",
"->",
"push",
"(",
"ArrayData",
"::",
"create",
"(",
"[",
"'Field'",
"=>",
"$",
"field",
"->",
"Title",
"(",
")",
",",
"'Value'",
"=>",
"$",
"searchValue",
",",
"]",
")",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
]
| Gets a list of what fields were searched and the values provided
for each field. Returns an ArrayList of ArrayData, suitable for
rendering on a template.
@return ArrayList | [
"Gets",
"a",
"list",
"of",
"what",
"fields",
"were",
"searched",
"and",
"the",
"values",
"provided",
"for",
"each",
"field",
".",
"Returns",
"an",
"ArrayList",
"of",
"ArrayData",
"suitable",
"for",
"rendering",
"on",
"a",
"template",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Search/SearchContext.php#L352-L390 | train |
silverstripe/silverstripe-framework | src/Security/BasicAuth.php | BasicAuth.requireLogin | public static function requireLogin(
HTTPRequest $request,
$realm,
$permissionCode = null,
$tryUsingSessionLogin = true
) {
if ((Director::is_cli() && static::config()->get('ignore_cli'))) {
return true;
}
$member = null;
try {
if ($request->getHeader('PHP_AUTH_USER') && $request->getHeader('PHP_AUTH_PW')) {
/** @var MemberAuthenticator $authenticator */
$authenticators = Security::singleton()->getApplicableAuthenticators(Authenticator::LOGIN);
foreach ($authenticators as $name => $authenticator) {
$member = $authenticator->authenticate([
'Email' => $request->getHeader('PHP_AUTH_USER'),
'Password' => $request->getHeader('PHP_AUTH_PW'),
], $request);
if ($member instanceof Member) {
break;
}
}
}
} catch (DatabaseException $e) {
// Database isn't ready, let people in
return true;
}
if (!$member && $tryUsingSessionLogin) {
$member = Security::getCurrentUser();
}
// If we've failed the authentication mechanism, then show the login form
if (!$member) {
$response = new HTTPResponse(null, 401);
$response->addHeader('WWW-Authenticate', "Basic realm=\"$realm\"");
if ($request->getHeader('PHP_AUTH_USER')) {
$response->setBody(
_t(
'SilverStripe\\Security\\BasicAuth.ERRORNOTREC',
"That username / password isn't recognised"
)
);
} else {
$response->setBody(
_t(
'SilverStripe\\Security\\BasicAuth.ENTERINFO',
'Please enter a username and password.'
)
);
}
// Exception is caught by RequestHandler->handleRequest() and will halt further execution
$e = new HTTPResponse_Exception(null, 401);
$e->setResponse($response);
throw $e;
}
if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) {
$response = new HTTPResponse(null, 401);
$response->addHeader('WWW-Authenticate', "Basic realm=\"$realm\"");
if ($request->getHeader('PHP_AUTH_USER')) {
$response->setBody(
_t(
'SilverStripe\\Security\\BasicAuth.ERRORNOTADMIN',
'That user is not an administrator.'
)
);
}
// Exception is caught by RequestHandler->handleRequest() and will halt further execution
$e = new HTTPResponse_Exception(null, 401);
$e->setResponse($response);
throw $e;
}
return $member;
} | php | public static function requireLogin(
HTTPRequest $request,
$realm,
$permissionCode = null,
$tryUsingSessionLogin = true
) {
if ((Director::is_cli() && static::config()->get('ignore_cli'))) {
return true;
}
$member = null;
try {
if ($request->getHeader('PHP_AUTH_USER') && $request->getHeader('PHP_AUTH_PW')) {
/** @var MemberAuthenticator $authenticator */
$authenticators = Security::singleton()->getApplicableAuthenticators(Authenticator::LOGIN);
foreach ($authenticators as $name => $authenticator) {
$member = $authenticator->authenticate([
'Email' => $request->getHeader('PHP_AUTH_USER'),
'Password' => $request->getHeader('PHP_AUTH_PW'),
], $request);
if ($member instanceof Member) {
break;
}
}
}
} catch (DatabaseException $e) {
// Database isn't ready, let people in
return true;
}
if (!$member && $tryUsingSessionLogin) {
$member = Security::getCurrentUser();
}
// If we've failed the authentication mechanism, then show the login form
if (!$member) {
$response = new HTTPResponse(null, 401);
$response->addHeader('WWW-Authenticate', "Basic realm=\"$realm\"");
if ($request->getHeader('PHP_AUTH_USER')) {
$response->setBody(
_t(
'SilverStripe\\Security\\BasicAuth.ERRORNOTREC',
"That username / password isn't recognised"
)
);
} else {
$response->setBody(
_t(
'SilverStripe\\Security\\BasicAuth.ENTERINFO',
'Please enter a username and password.'
)
);
}
// Exception is caught by RequestHandler->handleRequest() and will halt further execution
$e = new HTTPResponse_Exception(null, 401);
$e->setResponse($response);
throw $e;
}
if ($permissionCode && !Permission::checkMember($member->ID, $permissionCode)) {
$response = new HTTPResponse(null, 401);
$response->addHeader('WWW-Authenticate', "Basic realm=\"$realm\"");
if ($request->getHeader('PHP_AUTH_USER')) {
$response->setBody(
_t(
'SilverStripe\\Security\\BasicAuth.ERRORNOTADMIN',
'That user is not an administrator.'
)
);
}
// Exception is caught by RequestHandler->handleRequest() and will halt further execution
$e = new HTTPResponse_Exception(null, 401);
$e->setResponse($response);
throw $e;
}
return $member;
} | [
"public",
"static",
"function",
"requireLogin",
"(",
"HTTPRequest",
"$",
"request",
",",
"$",
"realm",
",",
"$",
"permissionCode",
"=",
"null",
",",
"$",
"tryUsingSessionLogin",
"=",
"true",
")",
"{",
"if",
"(",
"(",
"Director",
"::",
"is_cli",
"(",
")",
"&&",
"static",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'ignore_cli'",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"member",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"$",
"request",
"->",
"getHeader",
"(",
"'PHP_AUTH_USER'",
")",
"&&",
"$",
"request",
"->",
"getHeader",
"(",
"'PHP_AUTH_PW'",
")",
")",
"{",
"/** @var MemberAuthenticator $authenticator */",
"$",
"authenticators",
"=",
"Security",
"::",
"singleton",
"(",
")",
"->",
"getApplicableAuthenticators",
"(",
"Authenticator",
"::",
"LOGIN",
")",
";",
"foreach",
"(",
"$",
"authenticators",
"as",
"$",
"name",
"=>",
"$",
"authenticator",
")",
"{",
"$",
"member",
"=",
"$",
"authenticator",
"->",
"authenticate",
"(",
"[",
"'Email'",
"=>",
"$",
"request",
"->",
"getHeader",
"(",
"'PHP_AUTH_USER'",
")",
",",
"'Password'",
"=>",
"$",
"request",
"->",
"getHeader",
"(",
"'PHP_AUTH_PW'",
")",
",",
"]",
",",
"$",
"request",
")",
";",
"if",
"(",
"$",
"member",
"instanceof",
"Member",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"DatabaseException",
"$",
"e",
")",
"{",
"// Database isn't ready, let people in",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"member",
"&&",
"$",
"tryUsingSessionLogin",
")",
"{",
"$",
"member",
"=",
"Security",
"::",
"getCurrentUser",
"(",
")",
";",
"}",
"// If we've failed the authentication mechanism, then show the login form",
"if",
"(",
"!",
"$",
"member",
")",
"{",
"$",
"response",
"=",
"new",
"HTTPResponse",
"(",
"null",
",",
"401",
")",
";",
"$",
"response",
"->",
"addHeader",
"(",
"'WWW-Authenticate'",
",",
"\"Basic realm=\\\"$realm\\\"\"",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getHeader",
"(",
"'PHP_AUTH_USER'",
")",
")",
"{",
"$",
"response",
"->",
"setBody",
"(",
"_t",
"(",
"'SilverStripe\\\\Security\\\\BasicAuth.ERRORNOTREC'",
",",
"\"That username / password isn't recognised\"",
")",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"setBody",
"(",
"_t",
"(",
"'SilverStripe\\\\Security\\\\BasicAuth.ENTERINFO'",
",",
"'Please enter a username and password.'",
")",
")",
";",
"}",
"// Exception is caught by RequestHandler->handleRequest() and will halt further execution",
"$",
"e",
"=",
"new",
"HTTPResponse_Exception",
"(",
"null",
",",
"401",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"$",
"permissionCode",
"&&",
"!",
"Permission",
"::",
"checkMember",
"(",
"$",
"member",
"->",
"ID",
",",
"$",
"permissionCode",
")",
")",
"{",
"$",
"response",
"=",
"new",
"HTTPResponse",
"(",
"null",
",",
"401",
")",
";",
"$",
"response",
"->",
"addHeader",
"(",
"'WWW-Authenticate'",
",",
"\"Basic realm=\\\"$realm\\\"\"",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getHeader",
"(",
"'PHP_AUTH_USER'",
")",
")",
"{",
"$",
"response",
"->",
"setBody",
"(",
"_t",
"(",
"'SilverStripe\\\\Security\\\\BasicAuth.ERRORNOTADMIN'",
",",
"'That user is not an administrator.'",
")",
")",
";",
"}",
"// Exception is caught by RequestHandler->handleRequest() and will halt further execution",
"$",
"e",
"=",
"new",
"HTTPResponse_Exception",
"(",
"null",
",",
"401",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"member",
";",
"}"
]
| Require basic authentication. Will request a username and password if none is given.
Used by {@link Controller::init()}.
@param HTTPRequest $request
@param string $realm
@param string|array $permissionCode Optional
@param boolean $tryUsingSessionLogin If true, then the method with authenticate against the
session log-in if those credentials are disabled.
@return bool|Member
@throws HTTPResponse_Exception | [
"Require",
"basic",
"authentication",
".",
"Will",
"request",
"a",
"username",
"and",
"password",
"if",
"none",
"is",
"given",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Security/BasicAuth.php#L81-L164 | train |
silverstripe/silverstripe-framework | src/Security/BasicAuth.php | BasicAuth.protect_entire_site | public static function protect_entire_site($protect = true, $code = self::AUTH_PERMISSION, $message = null)
{
static::config()
->set('entire_site_protected', $protect)
->set('entire_site_protected_code', $code);
if ($message) {
static::config()->set('entire_site_protected_message', $message);
}
} | php | public static function protect_entire_site($protect = true, $code = self::AUTH_PERMISSION, $message = null)
{
static::config()
->set('entire_site_protected', $protect)
->set('entire_site_protected_code', $code);
if ($message) {
static::config()->set('entire_site_protected_message', $message);
}
} | [
"public",
"static",
"function",
"protect_entire_site",
"(",
"$",
"protect",
"=",
"true",
",",
"$",
"code",
"=",
"self",
"::",
"AUTH_PERMISSION",
",",
"$",
"message",
"=",
"null",
")",
"{",
"static",
"::",
"config",
"(",
")",
"->",
"set",
"(",
"'entire_site_protected'",
",",
"$",
"protect",
")",
"->",
"set",
"(",
"'entire_site_protected_code'",
",",
"$",
"code",
")",
";",
"if",
"(",
"$",
"message",
")",
"{",
"static",
"::",
"config",
"(",
")",
"->",
"set",
"(",
"'entire_site_protected_message'",
",",
"$",
"message",
")",
";",
"}",
"}"
]
| Enable protection of the entire site with basic authentication.
This log-in uses the Member database for authentication, but doesn't interfere with the
regular log-in form. This can be useful for test sites, where you want to hide the site
away from prying eyes, but still be able to test the regular log-in features of the site.
You can also enable this feature by adding this line to your .env. Set this to a permission
code you wish to require.
SS_USE_BASIC_AUTH=ADMIN
@param boolean $protect Set this to false to disable protection.
@param string $code {@link Permission} code that is required from the user.
Defaults to "ADMIN". Set to NULL to just require a valid login, regardless
of the permission codes a user has.
@param string $message | [
"Enable",
"protection",
"of",
"the",
"entire",
"site",
"with",
"basic",
"authentication",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Security/BasicAuth.php#L184-L192 | train |
silverstripe/silverstripe-framework | src/ORM/FieldType/DBHTMLText.php | DBHTMLText.setWhitelist | public function setWhitelist($whitelist)
{
if (!is_array($whitelist)) {
$whitelist = preg_split('/\s*,\s*/', $whitelist);
}
$this->whitelist = $whitelist;
return $this;
} | php | public function setWhitelist($whitelist)
{
if (!is_array($whitelist)) {
$whitelist = preg_split('/\s*,\s*/', $whitelist);
}
$this->whitelist = $whitelist;
return $this;
} | [
"public",
"function",
"setWhitelist",
"(",
"$",
"whitelist",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"whitelist",
")",
")",
"{",
"$",
"whitelist",
"=",
"preg_split",
"(",
"'/\\s*,\\s*/'",
",",
"$",
"whitelist",
")",
";",
"}",
"$",
"this",
"->",
"whitelist",
"=",
"$",
"whitelist",
";",
"return",
"$",
"this",
";",
"}"
]
| Set list of html properties to whitelist
@param array $whitelist
@return $this | [
"Set",
"list",
"of",
"html",
"properties",
"to",
"whitelist"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/FieldType/DBHTMLText.php#L91-L98 | train |
silverstripe/silverstripe-framework | src/ORM/FieldType/DBHTMLText.php | DBHTMLText.Plain | public function Plain()
{
// Preserve line breaks
$text = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $this->RAW());
// Convert paragraph breaks to multi-lines
$text = preg_replace('/\<\/p\>/i', "\n\n", $text);
// Strip out HTML tags
$text = strip_tags($text);
// Implode >3 consecutive linebreaks into 2
$text = preg_replace('~(\R){2,}~', "\n\n", $text);
// Decode HTML entities back to plain text
return trim(Convert::xml2raw($text));
} | php | public function Plain()
{
// Preserve line breaks
$text = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $this->RAW());
// Convert paragraph breaks to multi-lines
$text = preg_replace('/\<\/p\>/i', "\n\n", $text);
// Strip out HTML tags
$text = strip_tags($text);
// Implode >3 consecutive linebreaks into 2
$text = preg_replace('~(\R){2,}~', "\n\n", $text);
// Decode HTML entities back to plain text
return trim(Convert::xml2raw($text));
} | [
"public",
"function",
"Plain",
"(",
")",
"{",
"// Preserve line breaks",
"$",
"text",
"=",
"preg_replace",
"(",
"'/\\<br(\\s*)?\\/?\\>/i'",
",",
"\"\\n\"",
",",
"$",
"this",
"->",
"RAW",
"(",
")",
")",
";",
"// Convert paragraph breaks to multi-lines",
"$",
"text",
"=",
"preg_replace",
"(",
"'/\\<\\/p\\>/i'",
",",
"\"\\n\\n\"",
",",
"$",
"text",
")",
";",
"// Strip out HTML tags",
"$",
"text",
"=",
"strip_tags",
"(",
"$",
"text",
")",
";",
"// Implode >3 consecutive linebreaks into 2",
"$",
"text",
"=",
"preg_replace",
"(",
"'~(\\R){2,}~'",
",",
"\"\\n\\n\"",
",",
"$",
"text",
")",
";",
"// Decode HTML entities back to plain text",
"return",
"trim",
"(",
"Convert",
"::",
"xml2raw",
"(",
"$",
"text",
")",
")",
";",
"}"
]
| Get plain-text version
@return string | [
"Get",
"plain",
"-",
"text",
"version"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/FieldType/DBHTMLText.php#L219-L235 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/MySQLDatabase.php | MySQLDatabase.getTransactionManager | protected function getTransactionManager()
{
if (!$this->transactionManager) {
// PDOConnector providers this
if ($this->connector instanceof TransactionManager) {
$this->transactionManager = new NestedTransactionManager($this->connector);
// Direct database access does not
} else {
$this->transactionManager = new NestedTransactionManager(new MySQLTransactionManager($this));
}
}
return $this->transactionManager;
} | php | protected function getTransactionManager()
{
if (!$this->transactionManager) {
// PDOConnector providers this
if ($this->connector instanceof TransactionManager) {
$this->transactionManager = new NestedTransactionManager($this->connector);
// Direct database access does not
} else {
$this->transactionManager = new NestedTransactionManager(new MySQLTransactionManager($this));
}
}
return $this->transactionManager;
} | [
"protected",
"function",
"getTransactionManager",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"transactionManager",
")",
"{",
"// PDOConnector providers this",
"if",
"(",
"$",
"this",
"->",
"connector",
"instanceof",
"TransactionManager",
")",
"{",
"$",
"this",
"->",
"transactionManager",
"=",
"new",
"NestedTransactionManager",
"(",
"$",
"this",
"->",
"connector",
")",
";",
"// Direct database access does not",
"}",
"else",
"{",
"$",
"this",
"->",
"transactionManager",
"=",
"new",
"NestedTransactionManager",
"(",
"new",
"MySQLTransactionManager",
"(",
"$",
"this",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"transactionManager",
";",
"}"
]
| Returns the TransactionManager to handle transactions for this database.
@return TransactionManager | [
"Returns",
"the",
"TransactionManager",
"to",
"handle",
"transactions",
"for",
"this",
"database",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/MySQLDatabase.php#L309-L321 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/MySQLDatabase.php | MySQLDatabase.resetTransactionNesting | protected function resetTransactionNesting()
{
// Check whether to use a connector's built-in transaction methods
if ($this->connector instanceof TransactionalDBConnector) {
if ($this->transactionNesting > 0) {
$this->connector->transactionRollback();
}
}
$this->transactionNesting = 0;
} | php | protected function resetTransactionNesting()
{
// Check whether to use a connector's built-in transaction methods
if ($this->connector instanceof TransactionalDBConnector) {
if ($this->transactionNesting > 0) {
$this->connector->transactionRollback();
}
}
$this->transactionNesting = 0;
} | [
"protected",
"function",
"resetTransactionNesting",
"(",
")",
"{",
"// Check whether to use a connector's built-in transaction methods",
"if",
"(",
"$",
"this",
"->",
"connector",
"instanceof",
"TransactionalDBConnector",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"transactionNesting",
">",
"0",
")",
"{",
"$",
"this",
"->",
"connector",
"->",
"transactionRollback",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"transactionNesting",
"=",
"0",
";",
"}"
]
| In error condition, set transactionNesting to zero | [
"In",
"error",
"condition",
"set",
"transactionNesting",
"to",
"zero"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/MySQLDatabase.php#L366-L375 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/MySQLDatabase.php | MySQLDatabase.inspectQuery | protected function inspectQuery($sql)
{
// Any DDL discards transactions.
// See https://dev.mysql.com/doc/internals/en/transactions-notes-on-ddl-and-normal-transaction.html
// on why we need to be over-eager
$isDDL = $this->getConnector()->isQueryDDL($sql);
if ($isDDL) {
$this->resetTransactionNesting();
}
} | php | protected function inspectQuery($sql)
{
// Any DDL discards transactions.
// See https://dev.mysql.com/doc/internals/en/transactions-notes-on-ddl-and-normal-transaction.html
// on why we need to be over-eager
$isDDL = $this->getConnector()->isQueryDDL($sql);
if ($isDDL) {
$this->resetTransactionNesting();
}
} | [
"protected",
"function",
"inspectQuery",
"(",
"$",
"sql",
")",
"{",
"// Any DDL discards transactions.",
"// See https://dev.mysql.com/doc/internals/en/transactions-notes-on-ddl-and-normal-transaction.html",
"// on why we need to be over-eager",
"$",
"isDDL",
"=",
"$",
"this",
"->",
"getConnector",
"(",
")",
"->",
"isQueryDDL",
"(",
"$",
"sql",
")",
";",
"if",
"(",
"$",
"isDDL",
")",
"{",
"$",
"this",
"->",
"resetTransactionNesting",
"(",
")",
";",
"}",
"}"
]
| Inspect a SQL query prior to execution
@param string $sql | [
"Inspect",
"a",
"SQL",
"query",
"prior",
"to",
"execution"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/MySQLDatabase.php#L394-L403 | train |
silverstripe/silverstripe-framework | src/ORM/Connect/MySQLDatabase.php | MySQLDatabase.clearTable | public function clearTable($table)
{
$this->query("DELETE FROM \"$table\"");
// Check if resetting the auto-increment is needed
$autoIncrement = $this->preparedQuery(
'SELECT "AUTO_INCREMENT" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?',
[ $this->getSelectedDatabase(), $table]
)->value();
if ($autoIncrement > 1) {
$this->query("ALTER TABLE \"$table\" AUTO_INCREMENT = 1");
}
} | php | public function clearTable($table)
{
$this->query("DELETE FROM \"$table\"");
// Check if resetting the auto-increment is needed
$autoIncrement = $this->preparedQuery(
'SELECT "AUTO_INCREMENT" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?',
[ $this->getSelectedDatabase(), $table]
)->value();
if ($autoIncrement > 1) {
$this->query("ALTER TABLE \"$table\" AUTO_INCREMENT = 1");
}
} | [
"public",
"function",
"clearTable",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"query",
"(",
"\"DELETE FROM \\\"$table\\\"\"",
")",
";",
"// Check if resetting the auto-increment is needed",
"$",
"autoIncrement",
"=",
"$",
"this",
"->",
"preparedQuery",
"(",
"'SELECT \"AUTO_INCREMENT\" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?'",
",",
"[",
"$",
"this",
"->",
"getSelectedDatabase",
"(",
")",
",",
"$",
"table",
"]",
")",
"->",
"value",
"(",
")",
";",
"if",
"(",
"$",
"autoIncrement",
">",
"1",
")",
"{",
"$",
"this",
"->",
"query",
"(",
"\"ALTER TABLE \\\"$table\\\" AUTO_INCREMENT = 1\"",
")",
";",
"}",
"}"
]
| Clear all data in a given table
@param string $table Name of table | [
"Clear",
"all",
"data",
"in",
"a",
"given",
"table"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Connect/MySQLDatabase.php#L532-L545 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/ModuleResourceLoader.php | ModuleResourceLoader.resolveURL | public function resolveURL($resource)
{
// Skip blank resources
if (empty($resource)) {
return null;
}
// Resolve resource to reference
$resource = $this->resolveResource($resource);
// Resolve resource to url
/** @var ResourceURLGenerator $generator */
$generator = Injector::inst()->get(ResourceURLGenerator::class);
return $generator->urlForResource($resource);
} | php | public function resolveURL($resource)
{
// Skip blank resources
if (empty($resource)) {
return null;
}
// Resolve resource to reference
$resource = $this->resolveResource($resource);
// Resolve resource to url
/** @var ResourceURLGenerator $generator */
$generator = Injector::inst()->get(ResourceURLGenerator::class);
return $generator->urlForResource($resource);
} | [
"public",
"function",
"resolveURL",
"(",
"$",
"resource",
")",
"{",
"// Skip blank resources",
"if",
"(",
"empty",
"(",
"$",
"resource",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Resolve resource to reference",
"$",
"resource",
"=",
"$",
"this",
"->",
"resolveResource",
"(",
"$",
"resource",
")",
";",
"// Resolve resource to url",
"/** @var ResourceURLGenerator $generator */",
"$",
"generator",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"ResourceURLGenerator",
"::",
"class",
")",
";",
"return",
"$",
"generator",
"->",
"urlForResource",
"(",
"$",
"resource",
")",
";",
"}"
]
| Resolves resource specifier to the given url.
@param string $resource
@return string | [
"Resolves",
"resource",
"specifier",
"to",
"the",
"given",
"url",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/ModuleResourceLoader.php#L43-L57 | train |
silverstripe/silverstripe-framework | src/Core/Manifest/ModuleResourceLoader.php | ModuleResourceLoader.resolveResource | public function resolveResource($resource)
{
// String of the form vendor/package:resource. Excludes "http://bla" as that's an absolute URL
if (!preg_match('#^ *(?<module>[^/: ]+/[^/: ]+) *: *(?<resource>[^ ]*)$#', $resource, $matches)) {
return $resource;
}
$module = $matches['module'];
$resource = $matches['resource'];
$moduleObj = ModuleLoader::getModule($module);
if (!$moduleObj) {
throw new InvalidArgumentException("Can't find module '$module', the composer.json file may be missing from the modules installation directory");
}
$resourceObj = $moduleObj->getResource($resource);
return $resourceObj;
} | php | public function resolveResource($resource)
{
// String of the form vendor/package:resource. Excludes "http://bla" as that's an absolute URL
if (!preg_match('#^ *(?<module>[^/: ]+/[^/: ]+) *: *(?<resource>[^ ]*)$#', $resource, $matches)) {
return $resource;
}
$module = $matches['module'];
$resource = $matches['resource'];
$moduleObj = ModuleLoader::getModule($module);
if (!$moduleObj) {
throw new InvalidArgumentException("Can't find module '$module', the composer.json file may be missing from the modules installation directory");
}
$resourceObj = $moduleObj->getResource($resource);
return $resourceObj;
} | [
"public",
"function",
"resolveResource",
"(",
"$",
"resource",
")",
"{",
"// String of the form vendor/package:resource. Excludes \"http://bla\" as that's an absolute URL",
"if",
"(",
"!",
"preg_match",
"(",
"'#^ *(?<module>[^/: ]+/[^/: ]+) *: *(?<resource>[^ ]*)$#'",
",",
"$",
"resource",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"resource",
";",
"}",
"$",
"module",
"=",
"$",
"matches",
"[",
"'module'",
"]",
";",
"$",
"resource",
"=",
"$",
"matches",
"[",
"'resource'",
"]",
";",
"$",
"moduleObj",
"=",
"ModuleLoader",
"::",
"getModule",
"(",
"$",
"module",
")",
";",
"if",
"(",
"!",
"$",
"moduleObj",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Can't find module '$module', the composer.json file may be missing from the modules installation directory\"",
")",
";",
"}",
"$",
"resourceObj",
"=",
"$",
"moduleObj",
"->",
"getResource",
"(",
"$",
"resource",
")",
";",
"return",
"$",
"resourceObj",
";",
"}"
]
| Return module resource for the given path, if specified as one.
Returns the original resource otherwise.
@param string $resource
@return ModuleResource|string The resource, or input string if not a module resource | [
"Return",
"module",
"resource",
"for",
"the",
"given",
"path",
"if",
"specified",
"as",
"one",
".",
"Returns",
"the",
"original",
"resource",
"otherwise",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Manifest/ModuleResourceLoader.php#L96-L111 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.create | public static function create(
$select = "*",
$from = array(),
$where = array(),
$orderby = array(),
$groupby = array(),
$having = array(),
$limit = array()
) {
return Injector::inst()->createWithArgs(__CLASS__, func_get_args());
} | php | public static function create(
$select = "*",
$from = array(),
$where = array(),
$orderby = array(),
$groupby = array(),
$having = array(),
$limit = array()
) {
return Injector::inst()->createWithArgs(__CLASS__, func_get_args());
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"select",
"=",
"\"*\"",
",",
"$",
"from",
"=",
"array",
"(",
")",
",",
"$",
"where",
"=",
"array",
"(",
")",
",",
"$",
"orderby",
"=",
"array",
"(",
")",
",",
"$",
"groupby",
"=",
"array",
"(",
")",
",",
"$",
"having",
"=",
"array",
"(",
")",
",",
"$",
"limit",
"=",
"array",
"(",
")",
")",
"{",
"return",
"Injector",
"::",
"inst",
"(",
")",
"->",
"createWithArgs",
"(",
"__CLASS__",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
]
| Construct a new SQLSelect.
@param array|string $select An array of SELECT fields.
@param array|string $from An array of FROM clauses. The first one should be just the table name.
Each should be ANSI quoted.
@param array $where An array of WHERE clauses.
@param array $orderby An array ORDER BY clause.
@param array $groupby An array of GROUP BY clauses.
@param array $having An array of HAVING clauses.
@param array|string $limit A LIMIT clause or array with limit and offset keys
@return static | [
"Construct",
"a",
"new",
"SQLSelect",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L79-L89 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.setSelect | public function setSelect($fields)
{
$this->select = array();
if (func_num_args() > 1) {
$fields = func_get_args();
} elseif (!is_array($fields)) {
$fields = array($fields);
}
return $this->addSelect($fields);
} | php | public function setSelect($fields)
{
$this->select = array();
if (func_num_args() > 1) {
$fields = func_get_args();
} elseif (!is_array($fields)) {
$fields = array($fields);
}
return $this->addSelect($fields);
} | [
"public",
"function",
"setSelect",
"(",
"$",
"fields",
")",
"{",
"$",
"this",
"->",
"select",
"=",
"array",
"(",
")",
";",
"if",
"(",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"$",
"fields",
"=",
"func_get_args",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
"$",
"fields",
")",
";",
"}",
"return",
"$",
"this",
"->",
"addSelect",
"(",
"$",
"fields",
")",
";",
"}"
]
| Set the list of columns to be selected by the query.
<code>
// pass fields to select as single parameter array
$query->setSelect(array('"Col1"', '"Col2"'))->setFrom('"MyTable"');
// pass fields to select as multiple parameters
$query->setSelect('"Col1"', '"Col2"')->setFrom('"MyTable"');
// Set a list of selected fields as aliases
$query->setSelect(array('Name' => '"Col1"', 'Details' => '"Col2"')->setFrom('"MyTable"');
</code>
@param string|array $fields Field names should be ANSI SQL quoted. Array keys should be unquoted.
@return $this Self reference | [
"Set",
"the",
"list",
"of",
"columns",
"to",
"be",
"selected",
"by",
"the",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L139-L148 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.addSelect | public function addSelect($fields)
{
if (func_num_args() > 1) {
$fields = func_get_args();
} elseif (!is_array($fields)) {
$fields = array($fields);
}
foreach ($fields as $idx => $field) {
$this->selectField($field, is_numeric($idx) ? null : $idx);
}
return $this;
} | php | public function addSelect($fields)
{
if (func_num_args() > 1) {
$fields = func_get_args();
} elseif (!is_array($fields)) {
$fields = array($fields);
}
foreach ($fields as $idx => $field) {
$this->selectField($field, is_numeric($idx) ? null : $idx);
}
return $this;
} | [
"public",
"function",
"addSelect",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"$",
"fields",
"=",
"func_get_args",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
"$",
"fields",
")",
";",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"idx",
"=>",
"$",
"field",
")",
"{",
"$",
"this",
"->",
"selectField",
"(",
"$",
"field",
",",
"is_numeric",
"(",
"$",
"idx",
")",
"?",
"null",
":",
"$",
"idx",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add to the list of columns to be selected by the query.
@see setSelect for example usage
@param string|array $fields Field names should be ANSI SQL quoted. Array keys should be unquoted.
@return $this Self reference | [
"Add",
"to",
"the",
"list",
"of",
"columns",
"to",
"be",
"selected",
"by",
"the",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L158-L170 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.selectField | public function selectField($field, $alias = null)
{
if (!$alias) {
if (preg_match('/"([^"]+)"$/', $field, $matches)) {
$alias = $matches[1];
} else {
$alias = $field;
}
}
$this->select[$alias] = $field;
return $this;
} | php | public function selectField($field, $alias = null)
{
if (!$alias) {
if (preg_match('/"([^"]+)"$/', $field, $matches)) {
$alias = $matches[1];
} else {
$alias = $field;
}
}
$this->select[$alias] = $field;
return $this;
} | [
"public",
"function",
"selectField",
"(",
"$",
"field",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"alias",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\"([^\"]+)\"$/'",
",",
"$",
"field",
",",
"$",
"matches",
")",
")",
"{",
"$",
"alias",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"alias",
"=",
"$",
"field",
";",
"}",
"}",
"$",
"this",
"->",
"select",
"[",
"$",
"alias",
"]",
"=",
"$",
"field",
";",
"return",
"$",
"this",
";",
"}"
]
| Select an additional field.
@param string $field The field to select (ansi quoted SQL identifier or statement)
@param string|null $alias The alias of that field (unquoted SQL identifier).
Defaults to the unquoted column name of the $field parameter.
@return $this Self reference | [
"Select",
"an",
"additional",
"field",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L180-L191 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.setLimit | public function setLimit($limit, $offset = 0)
{
if ((is_numeric($limit) && $limit < 0) || (is_numeric($offset) && $offset < 0)) {
throw new InvalidArgumentException("SQLSelect::setLimit() only takes positive values");
}
if ($limit === 0) {
Deprecation::notice(
'4.3',
"setLimit(0) is deprecated in SS4. To clear limit, call setLimit(null). " .
"In SS5 a limit of 0 will instead return no records."
);
}
if (is_numeric($limit) && ($limit || $offset)) {
$this->limit = array(
'start' => (int)$offset,
'limit' => (int)$limit,
);
} elseif ($limit && is_string($limit)) {
if (strpos($limit, ',') !== false) {
list($start, $innerLimit) = explode(',', $limit, 2);
} else {
list($innerLimit, $start) = explode(' OFFSET ', strtoupper($limit), 2);
}
$this->limit = array(
'start' => (int)$start,
'limit' => (int)$innerLimit,
);
} elseif ($limit === null && $offset) {
$this->limit = array(
'start' => (int)$offset,
'limit' => $limit
);
} else {
$this->limit = $limit;
}
return $this;
} | php | public function setLimit($limit, $offset = 0)
{
if ((is_numeric($limit) && $limit < 0) || (is_numeric($offset) && $offset < 0)) {
throw new InvalidArgumentException("SQLSelect::setLimit() only takes positive values");
}
if ($limit === 0) {
Deprecation::notice(
'4.3',
"setLimit(0) is deprecated in SS4. To clear limit, call setLimit(null). " .
"In SS5 a limit of 0 will instead return no records."
);
}
if (is_numeric($limit) && ($limit || $offset)) {
$this->limit = array(
'start' => (int)$offset,
'limit' => (int)$limit,
);
} elseif ($limit && is_string($limit)) {
if (strpos($limit, ',') !== false) {
list($start, $innerLimit) = explode(',', $limit, 2);
} else {
list($innerLimit, $start) = explode(' OFFSET ', strtoupper($limit), 2);
}
$this->limit = array(
'start' => (int)$start,
'limit' => (int)$innerLimit,
);
} elseif ($limit === null && $offset) {
$this->limit = array(
'start' => (int)$offset,
'limit' => $limit
);
} else {
$this->limit = $limit;
}
return $this;
} | [
"public",
"function",
"setLimit",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"if",
"(",
"(",
"is_numeric",
"(",
"$",
"limit",
")",
"&&",
"$",
"limit",
"<",
"0",
")",
"||",
"(",
"is_numeric",
"(",
"$",
"offset",
")",
"&&",
"$",
"offset",
"<",
"0",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"SQLSelect::setLimit() only takes positive values\"",
")",
";",
"}",
"if",
"(",
"$",
"limit",
"===",
"0",
")",
"{",
"Deprecation",
"::",
"notice",
"(",
"'4.3'",
",",
"\"setLimit(0) is deprecated in SS4. To clear limit, call setLimit(null). \"",
".",
"\"In SS5 a limit of 0 will instead return no records.\"",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"limit",
")",
"&&",
"(",
"$",
"limit",
"||",
"$",
"offset",
")",
")",
"{",
"$",
"this",
"->",
"limit",
"=",
"array",
"(",
"'start'",
"=>",
"(",
"int",
")",
"$",
"offset",
",",
"'limit'",
"=>",
"(",
"int",
")",
"$",
"limit",
",",
")",
";",
"}",
"elseif",
"(",
"$",
"limit",
"&&",
"is_string",
"(",
"$",
"limit",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"limit",
",",
"','",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"start",
",",
"$",
"innerLimit",
")",
"=",
"explode",
"(",
"','",
",",
"$",
"limit",
",",
"2",
")",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"innerLimit",
",",
"$",
"start",
")",
"=",
"explode",
"(",
"' OFFSET '",
",",
"strtoupper",
"(",
"$",
"limit",
")",
",",
"2",
")",
";",
"}",
"$",
"this",
"->",
"limit",
"=",
"array",
"(",
"'start'",
"=>",
"(",
"int",
")",
"$",
"start",
",",
"'limit'",
"=>",
"(",
"int",
")",
"$",
"innerLimit",
",",
")",
";",
"}",
"elseif",
"(",
"$",
"limit",
"===",
"null",
"&&",
"$",
"offset",
")",
"{",
"$",
"this",
"->",
"limit",
"=",
"array",
"(",
"'start'",
"=>",
"(",
"int",
")",
"$",
"offset",
",",
"'limit'",
"=>",
"$",
"limit",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"limit",
"=",
"$",
"limit",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Pass LIMIT clause either as SQL snippet or in array format.
Internally, limit will always be stored as a map containing the keys 'start' and 'limit'
@param int|string|array|null $limit If passed as a string or array, assumes SQL escaped data.
Only applies for positive values.
@param int $offset
@throws InvalidArgumentException
@return $this Self reference | [
"Pass",
"LIMIT",
"clause",
"either",
"as",
"SQL",
"snippet",
"or",
"in",
"array",
"format",
".",
"Internally",
"limit",
"will",
"always",
"be",
"stored",
"as",
"a",
"map",
"containing",
"the",
"keys",
"start",
"and",
"limit"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L247-L287 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.setOrderBy | public function setOrderBy($clauses = null, $direction = null)
{
$this->orderby = array();
return $this->addOrderBy($clauses, $direction);
} | php | public function setOrderBy($clauses = null, $direction = null)
{
$this->orderby = array();
return $this->addOrderBy($clauses, $direction);
} | [
"public",
"function",
"setOrderBy",
"(",
"$",
"clauses",
"=",
"null",
",",
"$",
"direction",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"orderby",
"=",
"array",
"(",
")",
";",
"return",
"$",
"this",
"->",
"addOrderBy",
"(",
"$",
"clauses",
",",
"$",
"direction",
")",
";",
"}"
]
| Set ORDER BY clause either as SQL snippet or in array format.
@example $sql->setOrderBy("Column");
@example $sql->setOrderBy("Column DESC");
@example $sql->setOrderBy("Column DESC, ColumnTwo ASC");
@example $sql->setOrderBy("Column", "DESC");
@example $sql->setOrderBy(array("Column" => "ASC", "ColumnTwo" => "DESC"));
@param string|array $clauses Clauses to add (escaped SQL statement)
@param string $direction Sort direction, ASC or DESC
@return $this Self reference | [
"Set",
"ORDER",
"BY",
"clause",
"either",
"as",
"SQL",
"snippet",
"or",
"in",
"array",
"format",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L303-L307 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.addOrderBy | public function addOrderBy($clauses = null, $direction = null)
{
if (empty($clauses)) {
return $this;
}
if (is_string($clauses)) {
if (strpos($clauses, "(") !== false) {
$sort = preg_split("/,(?![^()]*+\\))/", $clauses);
} else {
$sort = explode(",", $clauses);
}
$clauses = array();
foreach ($sort as $clause) {
list($column, $direction) = $this->getDirectionFromString($clause, $direction);
$clauses[$column] = $direction;
}
}
if (is_array($clauses)) {
foreach ($clauses as $key => $value) {
if (!is_numeric($key)) {
$column = trim($key);
$columnDir = strtoupper(trim($value));
} else {
list($column, $columnDir) = $this->getDirectionFromString($value);
}
$this->orderby[$column] = $columnDir;
}
} else {
user_error('SQLSelect::orderby() incorrect format for $orderby', E_USER_WARNING);
}
// If sort contains a public function call, let's move the sort clause into a
// separate selected field.
//
// Some versions of MySQL choke if you have a group public function referenced
// directly in the ORDER BY
if ($this->orderby) {
$i = 0;
$orderby = array();
foreach ($this->orderby as $clause => $dir) {
// public function calls and multi-word columns like "CASE WHEN ..."
if (strpos($clause, '(') !== false || strpos($clause, " ") !== false) {
// Move the clause to the select fragment, substituting a placeholder column in the sort fragment.
$clause = trim($clause);
do {
$column = "_SortColumn{$i}";
++$i;
} while (array_key_exists('"' . $column . '"', $this->orderby));
$this->selectField($clause, $column);
$clause = '"' . $column . '"';
}
$orderby[$clause] = $dir;
}
$this->orderby = $orderby;
}
return $this;
} | php | public function addOrderBy($clauses = null, $direction = null)
{
if (empty($clauses)) {
return $this;
}
if (is_string($clauses)) {
if (strpos($clauses, "(") !== false) {
$sort = preg_split("/,(?![^()]*+\\))/", $clauses);
} else {
$sort = explode(",", $clauses);
}
$clauses = array();
foreach ($sort as $clause) {
list($column, $direction) = $this->getDirectionFromString($clause, $direction);
$clauses[$column] = $direction;
}
}
if (is_array($clauses)) {
foreach ($clauses as $key => $value) {
if (!is_numeric($key)) {
$column = trim($key);
$columnDir = strtoupper(trim($value));
} else {
list($column, $columnDir) = $this->getDirectionFromString($value);
}
$this->orderby[$column] = $columnDir;
}
} else {
user_error('SQLSelect::orderby() incorrect format for $orderby', E_USER_WARNING);
}
// If sort contains a public function call, let's move the sort clause into a
// separate selected field.
//
// Some versions of MySQL choke if you have a group public function referenced
// directly in the ORDER BY
if ($this->orderby) {
$i = 0;
$orderby = array();
foreach ($this->orderby as $clause => $dir) {
// public function calls and multi-word columns like "CASE WHEN ..."
if (strpos($clause, '(') !== false || strpos($clause, " ") !== false) {
// Move the clause to the select fragment, substituting a placeholder column in the sort fragment.
$clause = trim($clause);
do {
$column = "_SortColumn{$i}";
++$i;
} while (array_key_exists('"' . $column . '"', $this->orderby));
$this->selectField($clause, $column);
$clause = '"' . $column . '"';
}
$orderby[$clause] = $dir;
}
$this->orderby = $orderby;
}
return $this;
} | [
"public",
"function",
"addOrderBy",
"(",
"$",
"clauses",
"=",
"null",
",",
"$",
"direction",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"clauses",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"clauses",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"clauses",
",",
"\"(\"",
")",
"!==",
"false",
")",
"{",
"$",
"sort",
"=",
"preg_split",
"(",
"\"/,(?![^()]*+\\\\))/\"",
",",
"$",
"clauses",
")",
";",
"}",
"else",
"{",
"$",
"sort",
"=",
"explode",
"(",
"\",\"",
",",
"$",
"clauses",
")",
";",
"}",
"$",
"clauses",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sort",
"as",
"$",
"clause",
")",
"{",
"list",
"(",
"$",
"column",
",",
"$",
"direction",
")",
"=",
"$",
"this",
"->",
"getDirectionFromString",
"(",
"$",
"clause",
",",
"$",
"direction",
")",
";",
"$",
"clauses",
"[",
"$",
"column",
"]",
"=",
"$",
"direction",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"clauses",
")",
")",
"{",
"foreach",
"(",
"$",
"clauses",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"column",
"=",
"trim",
"(",
"$",
"key",
")",
";",
"$",
"columnDir",
"=",
"strtoupper",
"(",
"trim",
"(",
"$",
"value",
")",
")",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"column",
",",
"$",
"columnDir",
")",
"=",
"$",
"this",
"->",
"getDirectionFromString",
"(",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"orderby",
"[",
"$",
"column",
"]",
"=",
"$",
"columnDir",
";",
"}",
"}",
"else",
"{",
"user_error",
"(",
"'SQLSelect::orderby() incorrect format for $orderby'",
",",
"E_USER_WARNING",
")",
";",
"}",
"// If sort contains a public function call, let's move the sort clause into a",
"// separate selected field.",
"//",
"// Some versions of MySQL choke if you have a group public function referenced",
"// directly in the ORDER BY",
"if",
"(",
"$",
"this",
"->",
"orderby",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"orderby",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"orderby",
"as",
"$",
"clause",
"=>",
"$",
"dir",
")",
"{",
"// public function calls and multi-word columns like \"CASE WHEN ...\"",
"if",
"(",
"strpos",
"(",
"$",
"clause",
",",
"'('",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"clause",
",",
"\" \"",
")",
"!==",
"false",
")",
"{",
"// Move the clause to the select fragment, substituting a placeholder column in the sort fragment.",
"$",
"clause",
"=",
"trim",
"(",
"$",
"clause",
")",
";",
"do",
"{",
"$",
"column",
"=",
"\"_SortColumn{$i}\"",
";",
"++",
"$",
"i",
";",
"}",
"while",
"(",
"array_key_exists",
"(",
"'\"'",
".",
"$",
"column",
".",
"'\"'",
",",
"$",
"this",
"->",
"orderby",
")",
")",
";",
"$",
"this",
"->",
"selectField",
"(",
"$",
"clause",
",",
"$",
"column",
")",
";",
"$",
"clause",
"=",
"'\"'",
".",
"$",
"column",
".",
"'\"'",
";",
"}",
"$",
"orderby",
"[",
"$",
"clause",
"]",
"=",
"$",
"dir",
";",
"}",
"$",
"this",
"->",
"orderby",
"=",
"$",
"orderby",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add ORDER BY clause either as SQL snippet or in array format.
@example $sql->addOrderBy("Column");
@example $sql->addOrderBy("Column DESC");
@example $sql->addOrderBy("Column DESC, ColumnTwo ASC");
@example $sql->addOrderBy("Column", "DESC");
@example $sql->addOrderBy(array("Column" => "ASC", "ColumnTwo" => "DESC"));
@param string|array $clauses Clauses to add (escaped SQL statements)
@param string $direction Sort direction, ASC or DESC
@return $this Self reference | [
"Add",
"ORDER",
"BY",
"clause",
"either",
"as",
"SQL",
"snippet",
"or",
"in",
"array",
"format",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L322-L384 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.getDirectionFromString | private function getDirectionFromString($value, $defaultDirection = null)
{
if (preg_match('/^(.*)(asc|desc)$/i', $value, $matches)) {
$column = trim($matches[1]);
$direction = strtoupper($matches[2]);
} else {
$column = $value;
$direction = $defaultDirection ? $defaultDirection : "ASC";
}
return array($column, $direction);
} | php | private function getDirectionFromString($value, $defaultDirection = null)
{
if (preg_match('/^(.*)(asc|desc)$/i', $value, $matches)) {
$column = trim($matches[1]);
$direction = strtoupper($matches[2]);
} else {
$column = $value;
$direction = $defaultDirection ? $defaultDirection : "ASC";
}
return array($column, $direction);
} | [
"private",
"function",
"getDirectionFromString",
"(",
"$",
"value",
",",
"$",
"defaultDirection",
"=",
"null",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^(.*)(asc|desc)$/i'",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"$",
"column",
"=",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"$",
"direction",
"=",
"strtoupper",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"}",
"else",
"{",
"$",
"column",
"=",
"$",
"value",
";",
"$",
"direction",
"=",
"$",
"defaultDirection",
"?",
"$",
"defaultDirection",
":",
"\"ASC\"",
";",
"}",
"return",
"array",
"(",
"$",
"column",
",",
"$",
"direction",
")",
";",
"}"
]
| Extract the direction part of a single-column order by clause.
@param string $value
@param string $defaultDirection
@return array A two element array: array($column, $direction) | [
"Extract",
"the",
"direction",
"part",
"of",
"a",
"single",
"-",
"column",
"order",
"by",
"clause",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L393-L403 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.getOrderBy | public function getOrderBy()
{
$orderby = $this->orderby;
if (!$orderby) {
$orderby = array();
}
if (!is_array($orderby)) {
// spilt by any commas not within brackets
$orderby = preg_split('/,(?![^()]*+\\))/', $orderby);
}
foreach ($orderby as $k => $v) {
if (strpos($v, ' ') !== false) {
unset($orderby[$k]);
$rule = explode(' ', trim($v));
$clause = $rule[0];
$dir = (isset($rule[1])) ? $rule[1] : 'ASC';
$orderby[$clause] = $dir;
}
}
return $orderby;
} | php | public function getOrderBy()
{
$orderby = $this->orderby;
if (!$orderby) {
$orderby = array();
}
if (!is_array($orderby)) {
// spilt by any commas not within brackets
$orderby = preg_split('/,(?![^()]*+\\))/', $orderby);
}
foreach ($orderby as $k => $v) {
if (strpos($v, ' ') !== false) {
unset($orderby[$k]);
$rule = explode(' ', trim($v));
$clause = $rule[0];
$dir = (isset($rule[1])) ? $rule[1] : 'ASC';
$orderby[$clause] = $dir;
}
}
return $orderby;
} | [
"public",
"function",
"getOrderBy",
"(",
")",
"{",
"$",
"orderby",
"=",
"$",
"this",
"->",
"orderby",
";",
"if",
"(",
"!",
"$",
"orderby",
")",
"{",
"$",
"orderby",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"orderby",
")",
")",
"{",
"// spilt by any commas not within brackets",
"$",
"orderby",
"=",
"preg_split",
"(",
"'/,(?![^()]*+\\\\))/'",
",",
"$",
"orderby",
")",
";",
"}",
"foreach",
"(",
"$",
"orderby",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"v",
",",
"' '",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"orderby",
"[",
"$",
"k",
"]",
")",
";",
"$",
"rule",
"=",
"explode",
"(",
"' '",
",",
"trim",
"(",
"$",
"v",
")",
")",
";",
"$",
"clause",
"=",
"$",
"rule",
"[",
"0",
"]",
";",
"$",
"dir",
"=",
"(",
"isset",
"(",
"$",
"rule",
"[",
"1",
"]",
")",
")",
"?",
"$",
"rule",
"[",
"1",
"]",
":",
"'ASC'",
";",
"$",
"orderby",
"[",
"$",
"clause",
"]",
"=",
"$",
"dir",
";",
"}",
"}",
"return",
"$",
"orderby",
";",
"}"
]
| Returns the current order by as array if not already. To handle legacy
statements which are stored as strings. Without clauses and directions,
convert the orderby clause to something readable.
@return array | [
"Returns",
"the",
"current",
"order",
"by",
"as",
"array",
"if",
"not",
"already",
".",
"To",
"handle",
"legacy",
"statements",
"which",
"are",
"stored",
"as",
"strings",
".",
"Without",
"clauses",
"and",
"directions",
"convert",
"the",
"orderby",
"clause",
"to",
"something",
"readable",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L412-L437 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.reverseOrderBy | public function reverseOrderBy()
{
$order = $this->getOrderBy();
$this->orderby = array();
foreach ($order as $clause => $dir) {
$dir = (strtoupper($dir) == 'DESC') ? 'ASC' : 'DESC';
$this->addOrderBy($clause, $dir);
}
return $this;
} | php | public function reverseOrderBy()
{
$order = $this->getOrderBy();
$this->orderby = array();
foreach ($order as $clause => $dir) {
$dir = (strtoupper($dir) == 'DESC') ? 'ASC' : 'DESC';
$this->addOrderBy($clause, $dir);
}
return $this;
} | [
"public",
"function",
"reverseOrderBy",
"(",
")",
"{",
"$",
"order",
"=",
"$",
"this",
"->",
"getOrderBy",
"(",
")",
";",
"$",
"this",
"->",
"orderby",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"order",
"as",
"$",
"clause",
"=>",
"$",
"dir",
")",
"{",
"$",
"dir",
"=",
"(",
"strtoupper",
"(",
"$",
"dir",
")",
"==",
"'DESC'",
")",
"?",
"'ASC'",
":",
"'DESC'",
";",
"$",
"this",
"->",
"addOrderBy",
"(",
"$",
"clause",
",",
"$",
"dir",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Reverses the order by clause by replacing ASC or DESC references in the
current order by with it's corollary.
@return $this Self reference | [
"Reverses",
"the",
"order",
"by",
"clause",
"by",
"replacing",
"ASC",
"or",
"DESC",
"references",
"in",
"the",
"current",
"order",
"by",
"with",
"it",
"s",
"corollary",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L445-L456 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.addGroupBy | public function addGroupBy($groupby)
{
if (is_array($groupby)) {
$this->groupby = array_merge($this->groupby, $groupby);
} elseif (!empty($groupby)) {
$this->groupby[] = $groupby;
}
return $this;
} | php | public function addGroupBy($groupby)
{
if (is_array($groupby)) {
$this->groupby = array_merge($this->groupby, $groupby);
} elseif (!empty($groupby)) {
$this->groupby[] = $groupby;
}
return $this;
} | [
"public",
"function",
"addGroupBy",
"(",
"$",
"groupby",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"groupby",
")",
")",
"{",
"$",
"this",
"->",
"groupby",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"groupby",
",",
"$",
"groupby",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"groupby",
")",
")",
"{",
"$",
"this",
"->",
"groupby",
"[",
"]",
"=",
"$",
"groupby",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add a GROUP BY clause.
@param string|array $groupby Escaped SQL statement
@return $this Self reference | [
"Add",
"a",
"GROUP",
"BY",
"clause",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L476-L485 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.setHaving | public function setHaving($having)
{
$having = func_num_args() > 1 ? func_get_args() : $having;
$this->having = array();
return $this->addHaving($having);
} | php | public function setHaving($having)
{
$having = func_num_args() > 1 ? func_get_args() : $having;
$this->having = array();
return $this->addHaving($having);
} | [
"public",
"function",
"setHaving",
"(",
"$",
"having",
")",
"{",
"$",
"having",
"=",
"func_num_args",
"(",
")",
">",
"1",
"?",
"func_get_args",
"(",
")",
":",
"$",
"having",
";",
"$",
"this",
"->",
"having",
"=",
"array",
"(",
")",
";",
"return",
"$",
"this",
"->",
"addHaving",
"(",
"$",
"having",
")",
";",
"}"
]
| Set a HAVING clause.
@see SQLSelect::addWhere() for syntax examples
@param mixed $having Predicate(s) to set, as escaped SQL statements or parameterised queries
@param mixed $having,... Unlimited additional predicates
@return $this Self reference | [
"Set",
"a",
"HAVING",
"clause",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L496-L501 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.addHaving | public function addHaving($having)
{
$having = $this->normalisePredicates(func_get_args());
// If the function is called with an array of items
$this->having = array_merge($this->having, $having);
return $this;
} | php | public function addHaving($having)
{
$having = $this->normalisePredicates(func_get_args());
// If the function is called with an array of items
$this->having = array_merge($this->having, $having);
return $this;
} | [
"public",
"function",
"addHaving",
"(",
"$",
"having",
")",
"{",
"$",
"having",
"=",
"$",
"this",
"->",
"normalisePredicates",
"(",
"func_get_args",
"(",
")",
")",
";",
"// If the function is called with an array of items",
"$",
"this",
"->",
"having",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"having",
",",
"$",
"having",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add a HAVING clause
@see SQLSelect::addWhere() for syntax examples
@param mixed $having Predicate(s) to set, as escaped SQL statements or parameterised queries
@param mixed $having,... Unlimited additional predicates
@return $this Self reference | [
"Add",
"a",
"HAVING",
"clause"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L512-L520 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.unlimitedRowCount | public function unlimitedRowCount($column = null)
{
// we can't clear the select if we're relying on its output by a HAVING clause
if (count($this->having)) {
$records = $this->execute();
return $records->numRecords();
}
$clone = clone $this;
$clone->limit = null;
$clone->orderby = null;
// Choose a default column
if ($column == null) {
if ($this->groupby) {
// @todo Test case required here
$countQuery = new SQLSelect();
$countQuery->setSelect("count(*)");
$countQuery->setFrom(array('(' . $clone->sql($innerParameters) . ') all_distinct'));
$sql = $countQuery->sql($parameters); // $parameters should be empty
$result = DB::prepared_query($sql, $innerParameters);
return (int)$result->value();
} else {
$clone->setSelect(array("count(*)"));
}
} else {
$clone->setSelect(array("count($column)"));
}
$clone->setGroupBy(array());
return (int)$clone->execute()->value();
} | php | public function unlimitedRowCount($column = null)
{
// we can't clear the select if we're relying on its output by a HAVING clause
if (count($this->having)) {
$records = $this->execute();
return $records->numRecords();
}
$clone = clone $this;
$clone->limit = null;
$clone->orderby = null;
// Choose a default column
if ($column == null) {
if ($this->groupby) {
// @todo Test case required here
$countQuery = new SQLSelect();
$countQuery->setSelect("count(*)");
$countQuery->setFrom(array('(' . $clone->sql($innerParameters) . ') all_distinct'));
$sql = $countQuery->sql($parameters); // $parameters should be empty
$result = DB::prepared_query($sql, $innerParameters);
return (int)$result->value();
} else {
$clone->setSelect(array("count(*)"));
}
} else {
$clone->setSelect(array("count($column)"));
}
$clone->setGroupBy(array());
return (int)$clone->execute()->value();
} | [
"public",
"function",
"unlimitedRowCount",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"// we can't clear the select if we're relying on its output by a HAVING clause",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"having",
")",
")",
"{",
"$",
"records",
"=",
"$",
"this",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"records",
"->",
"numRecords",
"(",
")",
";",
"}",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"limit",
"=",
"null",
";",
"$",
"clone",
"->",
"orderby",
"=",
"null",
";",
"// Choose a default column",
"if",
"(",
"$",
"column",
"==",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"groupby",
")",
"{",
"// @todo Test case required here",
"$",
"countQuery",
"=",
"new",
"SQLSelect",
"(",
")",
";",
"$",
"countQuery",
"->",
"setSelect",
"(",
"\"count(*)\"",
")",
";",
"$",
"countQuery",
"->",
"setFrom",
"(",
"array",
"(",
"'('",
".",
"$",
"clone",
"->",
"sql",
"(",
"$",
"innerParameters",
")",
".",
"') all_distinct'",
")",
")",
";",
"$",
"sql",
"=",
"$",
"countQuery",
"->",
"sql",
"(",
"$",
"parameters",
")",
";",
"// $parameters should be empty",
"$",
"result",
"=",
"DB",
"::",
"prepared_query",
"(",
"$",
"sql",
",",
"$",
"innerParameters",
")",
";",
"return",
"(",
"int",
")",
"$",
"result",
"->",
"value",
"(",
")",
";",
"}",
"else",
"{",
"$",
"clone",
"->",
"setSelect",
"(",
"array",
"(",
"\"count(*)\"",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"clone",
"->",
"setSelect",
"(",
"array",
"(",
"\"count($column)\"",
")",
")",
";",
"}",
"$",
"clone",
"->",
"setGroupBy",
"(",
"array",
"(",
")",
")",
";",
"return",
"(",
"int",
")",
"$",
"clone",
"->",
"execute",
"(",
")",
"->",
"value",
"(",
")",
";",
"}"
]
| Return the number of rows in this query if the limit were removed. Useful in paged data sets.
@param string $column
@return int | [
"Return",
"the",
"number",
"of",
"rows",
"in",
"this",
"query",
"if",
"the",
"limit",
"were",
"removed",
".",
"Useful",
"in",
"paged",
"data",
"sets",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L574-L605 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.count | public function count($column = null)
{
// we can't clear the select if we're relying on its output by a HAVING clause
if (!empty($this->having)) {
$records = $this->execute();
return $records->numRecords();
} elseif ($column == null) {
// Choose a default column
if ($this->groupby) {
$column = 'DISTINCT ' . implode(", ", $this->groupby);
} else {
$column = '*';
}
}
$clone = clone $this;
$clone->select = array('Count' => "count($column)");
$clone->limit = null;
$clone->orderby = null;
$clone->groupby = null;
$count = (int)$clone->execute()->value();
// If there's a limit set, then that limit is going to heavily affect the count
if ($this->limit) {
if ($this->limit['limit'] !== null && $count >= ($this->limit['start'] + $this->limit['limit'])) {
return $this->limit['limit'];
} else {
return max(0, $count - $this->limit['start']);
}
// Otherwise, the count is going to be the output of the SQL query
} else {
return $count;
}
} | php | public function count($column = null)
{
// we can't clear the select if we're relying on its output by a HAVING clause
if (!empty($this->having)) {
$records = $this->execute();
return $records->numRecords();
} elseif ($column == null) {
// Choose a default column
if ($this->groupby) {
$column = 'DISTINCT ' . implode(", ", $this->groupby);
} else {
$column = '*';
}
}
$clone = clone $this;
$clone->select = array('Count' => "count($column)");
$clone->limit = null;
$clone->orderby = null;
$clone->groupby = null;
$count = (int)$clone->execute()->value();
// If there's a limit set, then that limit is going to heavily affect the count
if ($this->limit) {
if ($this->limit['limit'] !== null && $count >= ($this->limit['start'] + $this->limit['limit'])) {
return $this->limit['limit'];
} else {
return max(0, $count - $this->limit['start']);
}
// Otherwise, the count is going to be the output of the SQL query
} else {
return $count;
}
} | [
"public",
"function",
"count",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"// we can't clear the select if we're relying on its output by a HAVING clause",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"having",
")",
")",
"{",
"$",
"records",
"=",
"$",
"this",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"records",
"->",
"numRecords",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"column",
"==",
"null",
")",
"{",
"// Choose a default column",
"if",
"(",
"$",
"this",
"->",
"groupby",
")",
"{",
"$",
"column",
"=",
"'DISTINCT '",
".",
"implode",
"(",
"\", \"",
",",
"$",
"this",
"->",
"groupby",
")",
";",
"}",
"else",
"{",
"$",
"column",
"=",
"'*'",
";",
"}",
"}",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"$",
"clone",
"->",
"select",
"=",
"array",
"(",
"'Count'",
"=>",
"\"count($column)\"",
")",
";",
"$",
"clone",
"->",
"limit",
"=",
"null",
";",
"$",
"clone",
"->",
"orderby",
"=",
"null",
";",
"$",
"clone",
"->",
"groupby",
"=",
"null",
";",
"$",
"count",
"=",
"(",
"int",
")",
"$",
"clone",
"->",
"execute",
"(",
")",
"->",
"value",
"(",
")",
";",
"// If there's a limit set, then that limit is going to heavily affect the count",
"if",
"(",
"$",
"this",
"->",
"limit",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"limit",
"[",
"'limit'",
"]",
"!==",
"null",
"&&",
"$",
"count",
">=",
"(",
"$",
"this",
"->",
"limit",
"[",
"'start'",
"]",
"+",
"$",
"this",
"->",
"limit",
"[",
"'limit'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"limit",
"[",
"'limit'",
"]",
";",
"}",
"else",
"{",
"return",
"max",
"(",
"0",
",",
"$",
"count",
"-",
"$",
"this",
"->",
"limit",
"[",
"'start'",
"]",
")",
";",
"}",
"// Otherwise, the count is going to be the output of the SQL query",
"}",
"else",
"{",
"return",
"$",
"count",
";",
"}",
"}"
]
| Return the number of rows in this query, respecting limit and offset.
@param string $column Quoted, escaped column name
@return int | [
"Return",
"the",
"number",
"of",
"rows",
"in",
"this",
"query",
"respecting",
"limit",
"and",
"offset",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L627-L661 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.aggregate | public function aggregate($column, $alias = null)
{
$clone = clone $this;
// don't set an ORDER BY clause if no limit has been set. It doesn't make
// sense to add an ORDER BY if there is no limit, and it will break
// queries to databases like MSSQL if you do so. Note that the reason
// this came up is because DataQuery::initialiseQuery() introduces
// a default sort.
if ($this->limit) {
$clone->setLimit($this->limit);
$clone->setOrderBy($this->orderby);
} else {
$clone->setOrderBy(array());
}
$clone->setGroupBy($this->groupby);
if ($alias) {
$clone->setSelect(array());
$clone->selectField($column, $alias);
} else {
$clone->setSelect($column);
}
return $clone;
} | php | public function aggregate($column, $alias = null)
{
$clone = clone $this;
// don't set an ORDER BY clause if no limit has been set. It doesn't make
// sense to add an ORDER BY if there is no limit, and it will break
// queries to databases like MSSQL if you do so. Note that the reason
// this came up is because DataQuery::initialiseQuery() introduces
// a default sort.
if ($this->limit) {
$clone->setLimit($this->limit);
$clone->setOrderBy($this->orderby);
} else {
$clone->setOrderBy(array());
}
$clone->setGroupBy($this->groupby);
if ($alias) {
$clone->setSelect(array());
$clone->selectField($column, $alias);
} else {
$clone->setSelect($column);
}
return $clone;
} | [
"public",
"function",
"aggregate",
"(",
"$",
"column",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"// don't set an ORDER BY clause if no limit has been set. It doesn't make",
"// sense to add an ORDER BY if there is no limit, and it will break",
"// queries to databases like MSSQL if you do so. Note that the reason",
"// this came up is because DataQuery::initialiseQuery() introduces",
"// a default sort.",
"if",
"(",
"$",
"this",
"->",
"limit",
")",
"{",
"$",
"clone",
"->",
"setLimit",
"(",
"$",
"this",
"->",
"limit",
")",
";",
"$",
"clone",
"->",
"setOrderBy",
"(",
"$",
"this",
"->",
"orderby",
")",
";",
"}",
"else",
"{",
"$",
"clone",
"->",
"setOrderBy",
"(",
"array",
"(",
")",
")",
";",
"}",
"$",
"clone",
"->",
"setGroupBy",
"(",
"$",
"this",
"->",
"groupby",
")",
";",
"if",
"(",
"$",
"alias",
")",
"{",
"$",
"clone",
"->",
"setSelect",
"(",
"array",
"(",
")",
")",
";",
"$",
"clone",
"->",
"selectField",
"(",
"$",
"column",
",",
"$",
"alias",
")",
";",
"}",
"else",
"{",
"$",
"clone",
"->",
"setSelect",
"(",
"$",
"column",
")",
";",
"}",
"return",
"$",
"clone",
";",
"}"
]
| Return a new SQLSelect that calls the given aggregate functions on this data.
@param string $column An aggregate expression, such as 'MAX("Balance")', or a set of them
(as an escaped SQL statement)
@param string $alias An optional alias for the aggregate column.
@return SQLSelect A clone of this object with the given aggregate function | [
"Return",
"a",
"new",
"SQLSelect",
"that",
"calls",
"the",
"given",
"aggregate",
"functions",
"on",
"this",
"data",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L671-L697 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.firstRow | public function firstRow()
{
$query = clone $this;
$offset = $this->limit ? $this->limit['start'] : 0;
$query->setLimit(1, $offset);
return $query;
} | php | public function firstRow()
{
$query = clone $this;
$offset = $this->limit ? $this->limit['start'] : 0;
$query->setLimit(1, $offset);
return $query;
} | [
"public",
"function",
"firstRow",
"(",
")",
"{",
"$",
"query",
"=",
"clone",
"$",
"this",
";",
"$",
"offset",
"=",
"$",
"this",
"->",
"limit",
"?",
"$",
"this",
"->",
"limit",
"[",
"'start'",
"]",
":",
"0",
";",
"$",
"query",
"->",
"setLimit",
"(",
"1",
",",
"$",
"offset",
")",
";",
"return",
"$",
"query",
";",
"}"
]
| Returns a query that returns only the first row of this query
@return SQLSelect A clone of this object with the first row only | [
"Returns",
"a",
"query",
"that",
"returns",
"only",
"the",
"first",
"row",
"of",
"this",
"query"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L704-L710 | train |
silverstripe/silverstripe-framework | src/ORM/Queries/SQLSelect.php | SQLSelect.lastRow | public function lastRow()
{
$query = clone $this;
$offset = $this->limit ? $this->limit['start'] : 0;
// Limit index to start in case of empty results
$index = max($this->count() + $offset - 1, 0);
$query->setLimit(1, $index);
return $query;
} | php | public function lastRow()
{
$query = clone $this;
$offset = $this->limit ? $this->limit['start'] : 0;
// Limit index to start in case of empty results
$index = max($this->count() + $offset - 1, 0);
$query->setLimit(1, $index);
return $query;
} | [
"public",
"function",
"lastRow",
"(",
")",
"{",
"$",
"query",
"=",
"clone",
"$",
"this",
";",
"$",
"offset",
"=",
"$",
"this",
"->",
"limit",
"?",
"$",
"this",
"->",
"limit",
"[",
"'start'",
"]",
":",
"0",
";",
"// Limit index to start in case of empty results",
"$",
"index",
"=",
"max",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"$",
"offset",
"-",
"1",
",",
"0",
")",
";",
"$",
"query",
"->",
"setLimit",
"(",
"1",
",",
"$",
"index",
")",
";",
"return",
"$",
"query",
";",
"}"
]
| Returns a query that returns only the last row of this query
@return SQLSelect A clone of this object with the last row only | [
"Returns",
"a",
"query",
"that",
"returns",
"only",
"the",
"last",
"row",
"of",
"this",
"query"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/Queries/SQLSelect.php#L717-L726 | train |
silverstripe/silverstripe-framework | src/ORM/DatabaseAdmin.php | DatabaseAdmin.groupedDataClasses | public function groupedDataClasses()
{
// Get all root data objects
$allClasses = get_declared_classes();
$rootClasses = [];
foreach ($allClasses as $class) {
if (get_parent_class($class) == DataObject::class) {
$rootClasses[$class] = array();
}
}
// Assign every other data object one of those
foreach ($allClasses as $class) {
if (!isset($rootClasses[$class]) && is_subclass_of($class, DataObject::class)) {
foreach ($rootClasses as $rootClass => $dummy) {
if (is_subclass_of($class, $rootClass)) {
$rootClasses[$rootClass][] = $class;
break;
}
}
}
}
return $rootClasses;
} | php | public function groupedDataClasses()
{
// Get all root data objects
$allClasses = get_declared_classes();
$rootClasses = [];
foreach ($allClasses as $class) {
if (get_parent_class($class) == DataObject::class) {
$rootClasses[$class] = array();
}
}
// Assign every other data object one of those
foreach ($allClasses as $class) {
if (!isset($rootClasses[$class]) && is_subclass_of($class, DataObject::class)) {
foreach ($rootClasses as $rootClass => $dummy) {
if (is_subclass_of($class, $rootClass)) {
$rootClasses[$rootClass][] = $class;
break;
}
}
}
}
return $rootClasses;
} | [
"public",
"function",
"groupedDataClasses",
"(",
")",
"{",
"// Get all root data objects",
"$",
"allClasses",
"=",
"get_declared_classes",
"(",
")",
";",
"$",
"rootClasses",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"allClasses",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"get_parent_class",
"(",
"$",
"class",
")",
"==",
"DataObject",
"::",
"class",
")",
"{",
"$",
"rootClasses",
"[",
"$",
"class",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}",
"// Assign every other data object one of those",
"foreach",
"(",
"$",
"allClasses",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"rootClasses",
"[",
"$",
"class",
"]",
")",
"&&",
"is_subclass_of",
"(",
"$",
"class",
",",
"DataObject",
"::",
"class",
")",
")",
"{",
"foreach",
"(",
"$",
"rootClasses",
"as",
"$",
"rootClass",
"=>",
"$",
"dummy",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"rootClass",
")",
")",
"{",
"$",
"rootClasses",
"[",
"$",
"rootClass",
"]",
"[",
"]",
"=",
"$",
"class",
";",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"rootClasses",
";",
"}"
]
| Get the data classes, grouped by their root class
@return array Array of data classes, grouped by their root class | [
"Get",
"the",
"data",
"classes",
"grouped",
"by",
"their",
"root",
"class"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DatabaseAdmin.php#L90-L113 | train |
silverstripe/silverstripe-framework | src/ORM/DatabaseAdmin.php | DatabaseAdmin.getReturnURL | protected function getReturnURL()
{
$url = $this->request->getVar('returnURL');
// Check that this url is a site url
if (empty($url) || !Director::is_site_url($url)) {
return null;
}
// Convert to absolute URL
return Director::absoluteURL($url, true);
} | php | protected function getReturnURL()
{
$url = $this->request->getVar('returnURL');
// Check that this url is a site url
if (empty($url) || !Director::is_site_url($url)) {
return null;
}
// Convert to absolute URL
return Director::absoluteURL($url, true);
} | [
"protected",
"function",
"getReturnURL",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"request",
"->",
"getVar",
"(",
"'returnURL'",
")",
";",
"// Check that this url is a site url",
"if",
"(",
"empty",
"(",
"$",
"url",
")",
"||",
"!",
"Director",
"::",
"is_site_url",
"(",
"$",
"url",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Convert to absolute URL",
"return",
"Director",
"::",
"absoluteURL",
"(",
"$",
"url",
",",
"true",
")",
";",
"}"
]
| Gets the url to return to after build
@return string|null | [
"Gets",
"the",
"url",
"to",
"return",
"to",
"after",
"build"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DatabaseAdmin.php#L159-L170 | train |
silverstripe/silverstripe-framework | src/ORM/DatabaseAdmin.php | DatabaseAdmin.buildDefaults | public function buildDefaults()
{
$dataClasses = ClassInfo::subclassesFor(DataObject::class);
array_shift($dataClasses);
if (!Director::is_cli()) {
echo "<ul>";
}
foreach ($dataClasses as $dataClass) {
singleton($dataClass)->requireDefaultRecords();
if (Director::is_cli()) {
echo "Defaults loaded for $dataClass\n";
} else {
echo "<li>Defaults loaded for $dataClass</li>\n";
}
}
if (!Director::is_cli()) {
echo "</ul>";
}
} | php | public function buildDefaults()
{
$dataClasses = ClassInfo::subclassesFor(DataObject::class);
array_shift($dataClasses);
if (!Director::is_cli()) {
echo "<ul>";
}
foreach ($dataClasses as $dataClass) {
singleton($dataClass)->requireDefaultRecords();
if (Director::is_cli()) {
echo "Defaults loaded for $dataClass\n";
} else {
echo "<li>Defaults loaded for $dataClass</li>\n";
}
}
if (!Director::is_cli()) {
echo "</ul>";
}
} | [
"public",
"function",
"buildDefaults",
"(",
")",
"{",
"$",
"dataClasses",
"=",
"ClassInfo",
"::",
"subclassesFor",
"(",
"DataObject",
"::",
"class",
")",
";",
"array_shift",
"(",
"$",
"dataClasses",
")",
";",
"if",
"(",
"!",
"Director",
"::",
"is_cli",
"(",
")",
")",
"{",
"echo",
"\"<ul>\"",
";",
"}",
"foreach",
"(",
"$",
"dataClasses",
"as",
"$",
"dataClass",
")",
"{",
"singleton",
"(",
"$",
"dataClass",
")",
"->",
"requireDefaultRecords",
"(",
")",
";",
"if",
"(",
"Director",
"::",
"is_cli",
"(",
")",
")",
"{",
"echo",
"\"Defaults loaded for $dataClass\\n\"",
";",
"}",
"else",
"{",
"echo",
"\"<li>Defaults loaded for $dataClass</li>\\n\"",
";",
"}",
"}",
"if",
"(",
"!",
"Director",
"::",
"is_cli",
"(",
")",
")",
"{",
"echo",
"\"</ul>\"",
";",
"}",
"}"
]
| Build the default data, calling requireDefaultRecords on all
DataObject classes | [
"Build",
"the",
"default",
"data",
"calling",
"requireDefaultRecords",
"on",
"all",
"DataObject",
"classes"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DatabaseAdmin.php#L176-L197 | train |
silverstripe/silverstripe-framework | src/ORM/DatabaseAdmin.php | DatabaseAdmin.lastBuilt | public static function lastBuilt()
{
$file = TEMP_PATH
. DIRECTORY_SEPARATOR
. 'database-last-generated-'
. str_replace(array('\\','/',':'), '.', Director::baseFolder());
if (file_exists($file)) {
return filemtime($file);
}
return null;
} | php | public static function lastBuilt()
{
$file = TEMP_PATH
. DIRECTORY_SEPARATOR
. 'database-last-generated-'
. str_replace(array('\\','/',':'), '.', Director::baseFolder());
if (file_exists($file)) {
return filemtime($file);
}
return null;
} | [
"public",
"static",
"function",
"lastBuilt",
"(",
")",
"{",
"$",
"file",
"=",
"TEMP_PATH",
".",
"DIRECTORY_SEPARATOR",
".",
"'database-last-generated-'",
".",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"'/'",
",",
"':'",
")",
",",
"'.'",
",",
"Director",
"::",
"baseFolder",
"(",
")",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"filemtime",
"(",
"$",
"file",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Returns the timestamp of the time that the database was last built
@return string Returns the timestamp of the time that the database was
last built | [
"Returns",
"the",
"timestamp",
"of",
"the",
"time",
"that",
"the",
"database",
"was",
"last",
"built"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DatabaseAdmin.php#L205-L216 | train |
silverstripe/silverstripe-framework | src/ORM/DatabaseAdmin.php | DatabaseAdmin.getClassNameRemappingFields | protected function getClassNameRemappingFields()
{
$dataClasses = ClassInfo::getValidSubClasses(DataObject::class);
$schema = DataObject::getSchema();
$remapping = [];
foreach ($dataClasses as $className) {
$fieldSpecs = $schema->fieldSpecs($className);
foreach ($fieldSpecs as $fieldName => $fieldSpec) {
if (Injector::inst()->create($fieldSpec, 'Dummy') instanceof DBClassName) {
$remapping[$className][] = $fieldName;
}
}
}
return $remapping;
} | php | protected function getClassNameRemappingFields()
{
$dataClasses = ClassInfo::getValidSubClasses(DataObject::class);
$schema = DataObject::getSchema();
$remapping = [];
foreach ($dataClasses as $className) {
$fieldSpecs = $schema->fieldSpecs($className);
foreach ($fieldSpecs as $fieldName => $fieldSpec) {
if (Injector::inst()->create($fieldSpec, 'Dummy') instanceof DBClassName) {
$remapping[$className][] = $fieldName;
}
}
}
return $remapping;
} | [
"protected",
"function",
"getClassNameRemappingFields",
"(",
")",
"{",
"$",
"dataClasses",
"=",
"ClassInfo",
"::",
"getValidSubClasses",
"(",
"DataObject",
"::",
"class",
")",
";",
"$",
"schema",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
";",
"$",
"remapping",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dataClasses",
"as",
"$",
"className",
")",
"{",
"$",
"fieldSpecs",
"=",
"$",
"schema",
"->",
"fieldSpecs",
"(",
"$",
"className",
")",
";",
"foreach",
"(",
"$",
"fieldSpecs",
"as",
"$",
"fieldName",
"=>",
"$",
"fieldSpec",
")",
"{",
"if",
"(",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"fieldSpec",
",",
"'Dummy'",
")",
"instanceof",
"DBClassName",
")",
"{",
"$",
"remapping",
"[",
"$",
"className",
"]",
"[",
"]",
"=",
"$",
"fieldName",
";",
"}",
"}",
"}",
"return",
"$",
"remapping",
";",
"}"
]
| Find all DBClassName fields on valid subclasses of DataObject that should be remapped. This includes
`ClassName` fields as well as polymorphic class name fields.
@return array[] | [
"Find",
"all",
"DBClassName",
"fields",
"on",
"valid",
"subclasses",
"of",
"DataObject",
"that",
"should",
"be",
"remapped",
".",
"This",
"includes",
"ClassName",
"fields",
"as",
"well",
"as",
"polymorphic",
"class",
"name",
"fields",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DatabaseAdmin.php#L464-L480 | train |
silverstripe/silverstripe-framework | src/ORM/DatabaseAdmin.php | DatabaseAdmin.cleanup | public function cleanup()
{
$baseClasses = [];
foreach (ClassInfo::subclassesFor(DataObject::class) as $class) {
if (get_parent_class($class) == DataObject::class) {
$baseClasses[] = $class;
}
}
$schema = DataObject::getSchema();
foreach ($baseClasses as $baseClass) {
// Get data classes
$baseTable = $schema->baseDataTable($baseClass);
$subclasses = ClassInfo::subclassesFor($baseClass);
unset($subclasses[0]);
foreach ($subclasses as $k => $subclass) {
if (!DataObject::getSchema()->classHasTable($subclass)) {
unset($subclasses[$k]);
}
}
if ($subclasses) {
$records = DB::query("SELECT * FROM \"$baseTable\"");
foreach ($subclasses as $subclass) {
$subclassTable = $schema->tableName($subclass);
$recordExists[$subclass] =
DB::query("SELECT \"ID\" FROM \"$subclassTable\"")->keyedColumn();
}
foreach ($records as $record) {
foreach ($subclasses as $subclass) {
$subclassTable = $schema->tableName($subclass);
$id = $record['ID'];
if (($record['ClassName'] != $subclass)
&& (!is_subclass_of($record['ClassName'], $subclass))
&& isset($recordExists[$subclass][$id])
) {
$sql = "DELETE FROM \"$subclassTable\" WHERE \"ID\" = ?";
echo "<li>$sql [{$id}]</li>";
DB::prepared_query($sql, [$id]);
}
}
}
}
}
} | php | public function cleanup()
{
$baseClasses = [];
foreach (ClassInfo::subclassesFor(DataObject::class) as $class) {
if (get_parent_class($class) == DataObject::class) {
$baseClasses[] = $class;
}
}
$schema = DataObject::getSchema();
foreach ($baseClasses as $baseClass) {
// Get data classes
$baseTable = $schema->baseDataTable($baseClass);
$subclasses = ClassInfo::subclassesFor($baseClass);
unset($subclasses[0]);
foreach ($subclasses as $k => $subclass) {
if (!DataObject::getSchema()->classHasTable($subclass)) {
unset($subclasses[$k]);
}
}
if ($subclasses) {
$records = DB::query("SELECT * FROM \"$baseTable\"");
foreach ($subclasses as $subclass) {
$subclassTable = $schema->tableName($subclass);
$recordExists[$subclass] =
DB::query("SELECT \"ID\" FROM \"$subclassTable\"")->keyedColumn();
}
foreach ($records as $record) {
foreach ($subclasses as $subclass) {
$subclassTable = $schema->tableName($subclass);
$id = $record['ID'];
if (($record['ClassName'] != $subclass)
&& (!is_subclass_of($record['ClassName'], $subclass))
&& isset($recordExists[$subclass][$id])
) {
$sql = "DELETE FROM \"$subclassTable\" WHERE \"ID\" = ?";
echo "<li>$sql [{$id}]</li>";
DB::prepared_query($sql, [$id]);
}
}
}
}
}
} | [
"public",
"function",
"cleanup",
"(",
")",
"{",
"$",
"baseClasses",
"=",
"[",
"]",
";",
"foreach",
"(",
"ClassInfo",
"::",
"subclassesFor",
"(",
"DataObject",
"::",
"class",
")",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"get_parent_class",
"(",
"$",
"class",
")",
"==",
"DataObject",
"::",
"class",
")",
"{",
"$",
"baseClasses",
"[",
"]",
"=",
"$",
"class",
";",
"}",
"}",
"$",
"schema",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
";",
"foreach",
"(",
"$",
"baseClasses",
"as",
"$",
"baseClass",
")",
"{",
"// Get data classes",
"$",
"baseTable",
"=",
"$",
"schema",
"->",
"baseDataTable",
"(",
"$",
"baseClass",
")",
";",
"$",
"subclasses",
"=",
"ClassInfo",
"::",
"subclassesFor",
"(",
"$",
"baseClass",
")",
";",
"unset",
"(",
"$",
"subclasses",
"[",
"0",
"]",
")",
";",
"foreach",
"(",
"$",
"subclasses",
"as",
"$",
"k",
"=>",
"$",
"subclass",
")",
"{",
"if",
"(",
"!",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"classHasTable",
"(",
"$",
"subclass",
")",
")",
"{",
"unset",
"(",
"$",
"subclasses",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"subclasses",
")",
"{",
"$",
"records",
"=",
"DB",
"::",
"query",
"(",
"\"SELECT * FROM \\\"$baseTable\\\"\"",
")",
";",
"foreach",
"(",
"$",
"subclasses",
"as",
"$",
"subclass",
")",
"{",
"$",
"subclassTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"subclass",
")",
";",
"$",
"recordExists",
"[",
"$",
"subclass",
"]",
"=",
"DB",
"::",
"query",
"(",
"\"SELECT \\\"ID\\\" FROM \\\"$subclassTable\\\"\"",
")",
"->",
"keyedColumn",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"foreach",
"(",
"$",
"subclasses",
"as",
"$",
"subclass",
")",
"{",
"$",
"subclassTable",
"=",
"$",
"schema",
"->",
"tableName",
"(",
"$",
"subclass",
")",
";",
"$",
"id",
"=",
"$",
"record",
"[",
"'ID'",
"]",
";",
"if",
"(",
"(",
"$",
"record",
"[",
"'ClassName'",
"]",
"!=",
"$",
"subclass",
")",
"&&",
"(",
"!",
"is_subclass_of",
"(",
"$",
"record",
"[",
"'ClassName'",
"]",
",",
"$",
"subclass",
")",
")",
"&&",
"isset",
"(",
"$",
"recordExists",
"[",
"$",
"subclass",
"]",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"sql",
"=",
"\"DELETE FROM \\\"$subclassTable\\\" WHERE \\\"ID\\\" = ?\"",
";",
"echo",
"\"<li>$sql [{$id}]</li>\"",
";",
"DB",
"::",
"prepared_query",
"(",
"$",
"sql",
",",
"[",
"$",
"id",
"]",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
]
| Remove invalid records from tables - that is, records that don't have
corresponding records in their parent class tables. | [
"Remove",
"invalid",
"records",
"from",
"tables",
"-",
"that",
"is",
"records",
"that",
"don",
"t",
"have",
"corresponding",
"records",
"in",
"their",
"parent",
"class",
"tables",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DatabaseAdmin.php#L486-L533 | train |
silverstripe/silverstripe-framework | src/Security/MemberAuthenticator/MemberLoginForm.php | MemberLoginForm.getFormFields | protected function getFormFields()
{
$request = $this->getRequest();
if ($request->getVar('BackURL')) {
$backURL = $request->getVar('BackURL');
} else {
$backURL = $request->getSession()->get('BackURL');
}
$label = Member::singleton()->fieldLabel(Member::config()->get('unique_identifier_field'));
$fields = FieldList::create(
HiddenField::create("AuthenticationMethod", null, $this->getAuthenticatorClass(), $this),
// Regardless of what the unique identifer field is (usually 'Email'), it will be held in the
// 'Email' value, below:
// @todo Rename the field to a more generic covering name
$emailField = TextField::create("Email", $label, null, null, $this),
PasswordField::create("Password", _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
);
$emailField->setAttribute('autofocus', 'true');
if (Security::config()->get('remember_username')) {
$emailField->setValue($this->getSession()->get('SessionForms.MemberLoginForm.Email'));
} else {
// Some browsers won't respect this attribute unless it's added to the form
$this->setAttribute('autocomplete', 'off');
$emailField->setAttribute('autocomplete', 'off');
}
if (Security::config()->get('autologin_enabled')) {
$fields->push(
CheckboxField::create(
"Remember",
_t('SilverStripe\\Security\\Member.KEEPMESIGNEDIN', "Keep me signed in")
)->setAttribute(
'title',
_t(
'SilverStripe\\Security\\Member.REMEMBERME',
"Remember me next time? (for {count} days on this device)",
[ 'count' => RememberLoginHash::config()->uninherited('token_expiry_days') ]
)
)
);
}
if (isset($backURL)) {
$fields->push(HiddenField::create('BackURL', 'BackURL', $backURL));
}
return $fields;
} | php | protected function getFormFields()
{
$request = $this->getRequest();
if ($request->getVar('BackURL')) {
$backURL = $request->getVar('BackURL');
} else {
$backURL = $request->getSession()->get('BackURL');
}
$label = Member::singleton()->fieldLabel(Member::config()->get('unique_identifier_field'));
$fields = FieldList::create(
HiddenField::create("AuthenticationMethod", null, $this->getAuthenticatorClass(), $this),
// Regardless of what the unique identifer field is (usually 'Email'), it will be held in the
// 'Email' value, below:
// @todo Rename the field to a more generic covering name
$emailField = TextField::create("Email", $label, null, null, $this),
PasswordField::create("Password", _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
);
$emailField->setAttribute('autofocus', 'true');
if (Security::config()->get('remember_username')) {
$emailField->setValue($this->getSession()->get('SessionForms.MemberLoginForm.Email'));
} else {
// Some browsers won't respect this attribute unless it's added to the form
$this->setAttribute('autocomplete', 'off');
$emailField->setAttribute('autocomplete', 'off');
}
if (Security::config()->get('autologin_enabled')) {
$fields->push(
CheckboxField::create(
"Remember",
_t('SilverStripe\\Security\\Member.KEEPMESIGNEDIN', "Keep me signed in")
)->setAttribute(
'title',
_t(
'SilverStripe\\Security\\Member.REMEMBERME',
"Remember me next time? (for {count} days on this device)",
[ 'count' => RememberLoginHash::config()->uninherited('token_expiry_days') ]
)
)
);
}
if (isset($backURL)) {
$fields->push(HiddenField::create('BackURL', 'BackURL', $backURL));
}
return $fields;
} | [
"protected",
"function",
"getFormFields",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getVar",
"(",
"'BackURL'",
")",
")",
"{",
"$",
"backURL",
"=",
"$",
"request",
"->",
"getVar",
"(",
"'BackURL'",
")",
";",
"}",
"else",
"{",
"$",
"backURL",
"=",
"$",
"request",
"->",
"getSession",
"(",
")",
"->",
"get",
"(",
"'BackURL'",
")",
";",
"}",
"$",
"label",
"=",
"Member",
"::",
"singleton",
"(",
")",
"->",
"fieldLabel",
"(",
"Member",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'unique_identifier_field'",
")",
")",
";",
"$",
"fields",
"=",
"FieldList",
"::",
"create",
"(",
"HiddenField",
"::",
"create",
"(",
"\"AuthenticationMethod\"",
",",
"null",
",",
"$",
"this",
"->",
"getAuthenticatorClass",
"(",
")",
",",
"$",
"this",
")",
",",
"// Regardless of what the unique identifer field is (usually 'Email'), it will be held in the",
"// 'Email' value, below:",
"// @todo Rename the field to a more generic covering name",
"$",
"emailField",
"=",
"TextField",
"::",
"create",
"(",
"\"Email\"",
",",
"$",
"label",
",",
"null",
",",
"null",
",",
"$",
"this",
")",
",",
"PasswordField",
"::",
"create",
"(",
"\"Password\"",
",",
"_t",
"(",
"'SilverStripe\\\\Security\\\\Member.PASSWORD'",
",",
"'Password'",
")",
")",
")",
";",
"$",
"emailField",
"->",
"setAttribute",
"(",
"'autofocus'",
",",
"'true'",
")",
";",
"if",
"(",
"Security",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'remember_username'",
")",
")",
"{",
"$",
"emailField",
"->",
"setValue",
"(",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"get",
"(",
"'SessionForms.MemberLoginForm.Email'",
")",
")",
";",
"}",
"else",
"{",
"// Some browsers won't respect this attribute unless it's added to the form",
"$",
"this",
"->",
"setAttribute",
"(",
"'autocomplete'",
",",
"'off'",
")",
";",
"$",
"emailField",
"->",
"setAttribute",
"(",
"'autocomplete'",
",",
"'off'",
")",
";",
"}",
"if",
"(",
"Security",
"::",
"config",
"(",
")",
"->",
"get",
"(",
"'autologin_enabled'",
")",
")",
"{",
"$",
"fields",
"->",
"push",
"(",
"CheckboxField",
"::",
"create",
"(",
"\"Remember\"",
",",
"_t",
"(",
"'SilverStripe\\\\Security\\\\Member.KEEPMESIGNEDIN'",
",",
"\"Keep me signed in\"",
")",
")",
"->",
"setAttribute",
"(",
"'title'",
",",
"_t",
"(",
"'SilverStripe\\\\Security\\\\Member.REMEMBERME'",
",",
"\"Remember me next time? (for {count} days on this device)\"",
",",
"[",
"'count'",
"=>",
"RememberLoginHash",
"::",
"config",
"(",
")",
"->",
"uninherited",
"(",
"'token_expiry_days'",
")",
"]",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"backURL",
")",
")",
"{",
"$",
"fields",
"->",
"push",
"(",
"HiddenField",
"::",
"create",
"(",
"'BackURL'",
",",
"'BackURL'",
",",
"$",
"backURL",
")",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
]
| Build the FieldList for the login form
@skipUpgrade
@return FieldList | [
"Build",
"the",
"FieldList",
"for",
"the",
"login",
"form"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Security/MemberAuthenticator/MemberLoginForm.php#L125-L173 | train |
silverstripe/silverstripe-framework | src/Security/MemberAuthenticator/MemberLoginForm.php | MemberLoginForm.getFormActions | protected function getFormActions()
{
$actions = FieldList::create(
FormAction::create('doLogin', _t('SilverStripe\\Security\\Member.BUTTONLOGIN', "Log in")),
LiteralField::create(
'forgotPassword',
'<p id="ForgotPassword"><a href="' . Security::lost_password_url() . '">'
. _t('SilverStripe\\Security\\Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
)
);
return $actions;
} | php | protected function getFormActions()
{
$actions = FieldList::create(
FormAction::create('doLogin', _t('SilverStripe\\Security\\Member.BUTTONLOGIN', "Log in")),
LiteralField::create(
'forgotPassword',
'<p id="ForgotPassword"><a href="' . Security::lost_password_url() . '">'
. _t('SilverStripe\\Security\\Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'
)
);
return $actions;
} | [
"protected",
"function",
"getFormActions",
"(",
")",
"{",
"$",
"actions",
"=",
"FieldList",
"::",
"create",
"(",
"FormAction",
"::",
"create",
"(",
"'doLogin'",
",",
"_t",
"(",
"'SilverStripe\\\\Security\\\\Member.BUTTONLOGIN'",
",",
"\"Log in\"",
")",
")",
",",
"LiteralField",
"::",
"create",
"(",
"'forgotPassword'",
",",
"'<p id=\"ForgotPassword\"><a href=\"'",
".",
"Security",
"::",
"lost_password_url",
"(",
")",
".",
"'\">'",
".",
"_t",
"(",
"'SilverStripe\\\\Security\\\\Member.BUTTONLOSTPASSWORD'",
",",
"\"I've lost my password\"",
")",
".",
"'</a></p>'",
")",
")",
";",
"return",
"$",
"actions",
";",
"}"
]
| Build default login form action FieldList
@return FieldList | [
"Build",
"default",
"login",
"form",
"action",
"FieldList"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Security/MemberAuthenticator/MemberLoginForm.php#L180-L192 | train |
silverstripe/silverstripe-framework | src/View/Embed/EmbedResource.php | EmbedResource.getName | public function getName()
{
if ($this->getEmbed()->title) {
return $this->getEmbed()->title;
}
return preg_replace('/\?.*/', '', basename($this->getEmbed()->getUrl()));
} | php | public function getName()
{
if ($this->getEmbed()->title) {
return $this->getEmbed()->title;
}
return preg_replace('/\?.*/', '', basename($this->getEmbed()->getUrl()));
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getEmbed",
"(",
")",
"->",
"title",
")",
"{",
"return",
"$",
"this",
"->",
"getEmbed",
"(",
")",
"->",
"title",
";",
"}",
"return",
"preg_replace",
"(",
"'/\\?.*/'",
",",
"''",
",",
"basename",
"(",
"$",
"this",
"->",
"getEmbed",
"(",
")",
"->",
"getUrl",
"(",
")",
")",
")",
";",
"}"
]
| Get human readable name for this resource
@return string | [
"Get",
"human",
"readable",
"name",
"for",
"this",
"resource"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/View/Embed/EmbedResource.php#L80-L87 | train |
silverstripe/silverstripe-framework | src/View/Embed/EmbedResource.php | EmbedResource.getEmbed | public function getEmbed()
{
if (!$this->embed) {
$this->embed = Embed::create($this->url, $this->getOptions(), $this->getDispatcher());
}
return $this->embed;
} | php | public function getEmbed()
{
if (!$this->embed) {
$this->embed = Embed::create($this->url, $this->getOptions(), $this->getDispatcher());
}
return $this->embed;
} | [
"public",
"function",
"getEmbed",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"embed",
")",
"{",
"$",
"this",
"->",
"embed",
"=",
"Embed",
"::",
"create",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"this",
"->",
"getOptions",
"(",
")",
",",
"$",
"this",
"->",
"getDispatcher",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"embed",
";",
"}"
]
| Returns a bootstrapped Embed object
@return Adapter | [
"Returns",
"a",
"bootstrapped",
"Embed",
"object"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/View/Embed/EmbedResource.php#L140-L146 | train |
silverstripe/silverstripe-framework | src/Dev/TaskRunner.php | TaskRunner.runTask | public function runTask($request)
{
$name = $request->param('TaskName');
$tasks = $this->getTasks();
$title = function ($content) {
printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content);
};
$message = function ($content) {
printf(Director::is_cli() ? "%s\n" : '<p>%s</p>', $content);
};
foreach ($tasks as $task) {
if ($task['segment'] == $name) {
/** @var BuildTask $inst */
$inst = Injector::inst()->create($task['class']);
$title(sprintf('Running Task %s', $inst->getTitle()));
if (!$inst->isEnabled()) {
$message('The task is disabled');
return;
}
$inst->run($request);
return;
}
}
$message(sprintf('The build task "%s" could not be found', Convert::raw2xml($name)));
} | php | public function runTask($request)
{
$name = $request->param('TaskName');
$tasks = $this->getTasks();
$title = function ($content) {
printf(Director::is_cli() ? "%s\n\n" : '<h1>%s</h1>', $content);
};
$message = function ($content) {
printf(Director::is_cli() ? "%s\n" : '<p>%s</p>', $content);
};
foreach ($tasks as $task) {
if ($task['segment'] == $name) {
/** @var BuildTask $inst */
$inst = Injector::inst()->create($task['class']);
$title(sprintf('Running Task %s', $inst->getTitle()));
if (!$inst->isEnabled()) {
$message('The task is disabled');
return;
}
$inst->run($request);
return;
}
}
$message(sprintf('The build task "%s" could not be found', Convert::raw2xml($name)));
} | [
"public",
"function",
"runTask",
"(",
"$",
"request",
")",
"{",
"$",
"name",
"=",
"$",
"request",
"->",
"param",
"(",
"'TaskName'",
")",
";",
"$",
"tasks",
"=",
"$",
"this",
"->",
"getTasks",
"(",
")",
";",
"$",
"title",
"=",
"function",
"(",
"$",
"content",
")",
"{",
"printf",
"(",
"Director",
"::",
"is_cli",
"(",
")",
"?",
"\"%s\\n\\n\"",
":",
"'<h1>%s</h1>'",
",",
"$",
"content",
")",
";",
"}",
";",
"$",
"message",
"=",
"function",
"(",
"$",
"content",
")",
"{",
"printf",
"(",
"Director",
"::",
"is_cli",
"(",
")",
"?",
"\"%s\\n\"",
":",
"'<p>%s</p>'",
",",
"$",
"content",
")",
";",
"}",
";",
"foreach",
"(",
"$",
"tasks",
"as",
"$",
"task",
")",
"{",
"if",
"(",
"$",
"task",
"[",
"'segment'",
"]",
"==",
"$",
"name",
")",
"{",
"/** @var BuildTask $inst */",
"$",
"inst",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"task",
"[",
"'class'",
"]",
")",
";",
"$",
"title",
"(",
"sprintf",
"(",
"'Running Task %s'",
",",
"$",
"inst",
"->",
"getTitle",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"inst",
"->",
"isEnabled",
"(",
")",
")",
"{",
"$",
"message",
"(",
"'The task is disabled'",
")",
";",
"return",
";",
"}",
"$",
"inst",
"->",
"run",
"(",
"$",
"request",
")",
";",
"return",
";",
"}",
"}",
"$",
"message",
"(",
"sprintf",
"(",
"'The build task \"%s\" could not be found'",
",",
"Convert",
"::",
"raw2xml",
"(",
"$",
"name",
")",
")",
")",
";",
"}"
]
| Runs a BuildTask
@param HTTPRequest $request | [
"Runs",
"a",
"BuildTask"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Dev/TaskRunner.php#L80-L110 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.setDataQueryParam | public function setDataQueryParam($keyOrArray, $val = null)
{
$clone = clone $this;
if (is_array($keyOrArray)) {
foreach ($keyOrArray as $key => $value) {
$clone->dataQuery->setQueryParam($key, $value);
}
} else {
$clone->dataQuery->setQueryParam($keyOrArray, $val);
}
return $clone;
} | php | public function setDataQueryParam($keyOrArray, $val = null)
{
$clone = clone $this;
if (is_array($keyOrArray)) {
foreach ($keyOrArray as $key => $value) {
$clone->dataQuery->setQueryParam($key, $value);
}
} else {
$clone->dataQuery->setQueryParam($keyOrArray, $val);
}
return $clone;
} | [
"public",
"function",
"setDataQueryParam",
"(",
"$",
"keyOrArray",
",",
"$",
"val",
"=",
"null",
")",
"{",
"$",
"clone",
"=",
"clone",
"$",
"this",
";",
"if",
"(",
"is_array",
"(",
"$",
"keyOrArray",
")",
")",
"{",
"foreach",
"(",
"$",
"keyOrArray",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"clone",
"->",
"dataQuery",
"->",
"setQueryParam",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"$",
"clone",
"->",
"dataQuery",
"->",
"setQueryParam",
"(",
"$",
"keyOrArray",
",",
"$",
"val",
")",
";",
"}",
"return",
"$",
"clone",
";",
"}"
]
| Returns a new DataList instance with the specified query parameter assigned
@param string|array $keyOrArray Either the single key to set, or an array of key value pairs to set
@param mixed $val If $keyOrArray is not an array, this is the value to set
@return static | [
"Returns",
"a",
"new",
"DataList",
"instance",
"with",
"the",
"specified",
"query",
"parameter",
"assigned"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L168-L181 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.where | public function where($filter)
{
return $this->alterDataQuery(function (DataQuery $query) use ($filter) {
$query->where($filter);
});
} | php | public function where($filter)
{
return $this->alterDataQuery(function (DataQuery $query) use ($filter) {
$query->where($filter);
});
} | [
"public",
"function",
"where",
"(",
"$",
"filter",
")",
"{",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"filter",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"filter",
")",
";",
"}",
")",
";",
"}"
]
| Return a new DataList instance with a WHERE clause added to this list's query.
Supports parameterised queries.
See SQLSelect::addWhere() for syntax examples, although DataList
won't expand multiple method arguments as SQLSelect does.
@param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
paramaterised queries
@return static | [
"Return",
"a",
"new",
"DataList",
"instance",
"with",
"a",
"WHERE",
"clause",
"added",
"to",
"this",
"list",
"s",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L205-L210 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.whereAny | public function whereAny($filter)
{
return $this->alterDataQuery(function (DataQuery $query) use ($filter) {
$query->whereAny($filter);
});
} | php | public function whereAny($filter)
{
return $this->alterDataQuery(function (DataQuery $query) use ($filter) {
$query->whereAny($filter);
});
} | [
"public",
"function",
"whereAny",
"(",
"$",
"filter",
")",
"{",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"filter",
")",
"{",
"$",
"query",
"->",
"whereAny",
"(",
"$",
"filter",
")",
";",
"}",
")",
";",
"}"
]
| Return a new DataList instance with a WHERE clause added to this list's query.
All conditions provided in the filter will be joined with an OR
Supports parameterised queries.
See SQLSelect::addWhere() for syntax examples, although DataList
won't expand multiple method arguments as SQLSelect does.
@param string|array|SQLConditionGroup $filter Predicate(s) to set, as escaped SQL statements or
paramaterised queries
@return static | [
"Return",
"a",
"new",
"DataList",
"instance",
"with",
"a",
"WHERE",
"clause",
"added",
"to",
"this",
"list",
"s",
"query",
".",
"All",
"conditions",
"provided",
"in",
"the",
"filter",
"will",
"be",
"joined",
"with",
"an",
"OR"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L224-L229 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.canFilterBy | public function canFilterBy($fieldName)
{
$model = singleton($this->dataClass);
$relations = explode(".", $fieldName);
// First validate the relationships
$fieldName = array_pop($relations);
foreach ($relations as $r) {
$relationClass = $model->getRelationClass($r);
if (!$relationClass) {
return false;
}
$model = singleton($relationClass);
if (!$model) {
return false;
}
}
// Then check field
if ($model->hasDatabaseField($fieldName)) {
return true;
}
return false;
} | php | public function canFilterBy($fieldName)
{
$model = singleton($this->dataClass);
$relations = explode(".", $fieldName);
// First validate the relationships
$fieldName = array_pop($relations);
foreach ($relations as $r) {
$relationClass = $model->getRelationClass($r);
if (!$relationClass) {
return false;
}
$model = singleton($relationClass);
if (!$model) {
return false;
}
}
// Then check field
if ($model->hasDatabaseField($fieldName)) {
return true;
}
return false;
} | [
"public",
"function",
"canFilterBy",
"(",
"$",
"fieldName",
")",
"{",
"$",
"model",
"=",
"singleton",
"(",
"$",
"this",
"->",
"dataClass",
")",
";",
"$",
"relations",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"fieldName",
")",
";",
"// First validate the relationships",
"$",
"fieldName",
"=",
"array_pop",
"(",
"$",
"relations",
")",
";",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"r",
")",
"{",
"$",
"relationClass",
"=",
"$",
"model",
"->",
"getRelationClass",
"(",
"$",
"r",
")",
";",
"if",
"(",
"!",
"$",
"relationClass",
")",
"{",
"return",
"false",
";",
"}",
"$",
"model",
"=",
"singleton",
"(",
"$",
"relationClass",
")",
";",
"if",
"(",
"!",
"$",
"model",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// Then check field",
"if",
"(",
"$",
"model",
"->",
"hasDatabaseField",
"(",
"$",
"fieldName",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Returns true if this DataList can be filtered by the given field.
@param string $fieldName (May be a related field in dot notation like Member.FirstName)
@return boolean | [
"Returns",
"true",
"if",
"this",
"DataList",
"can",
"be",
"filtered",
"by",
"the",
"given",
"field",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L250-L271 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.limit | public function limit($limit, $offset = 0)
{
return $this->alterDataQuery(function (DataQuery $query) use ($limit, $offset) {
$query->limit($limit, $offset);
});
} | php | public function limit($limit, $offset = 0)
{
return $this->alterDataQuery(function (DataQuery $query) use ($limit, $offset) {
$query->limit($limit, $offset);
});
} | [
"public",
"function",
"limit",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"limit",
",",
"$",
"offset",
")",
"{",
"$",
"query",
"->",
"limit",
"(",
"$",
"limit",
",",
"$",
"offset",
")",
";",
"}",
")",
";",
"}"
]
| Return a new DataList instance with the records returned in this query
restricted by a limit clause.
@param int $limit
@param int $offset
@return static | [
"Return",
"a",
"new",
"DataList",
"instance",
"with",
"the",
"records",
"returned",
"in",
"this",
"query",
"restricted",
"by",
"a",
"limit",
"clause",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L281-L286 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.distinct | public function distinct($value)
{
return $this->alterDataQuery(function (DataQuery $query) use ($value) {
$query->distinct($value);
});
} | php | public function distinct($value)
{
return $this->alterDataQuery(function (DataQuery $query) use ($value) {
$query->distinct($value);
});
} | [
"public",
"function",
"distinct",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"value",
")",
"{",
"$",
"query",
"->",
"distinct",
"(",
"$",
"value",
")",
";",
"}",
")",
";",
"}"
]
| Return a new DataList instance with distinct records or not
@param bool $value
@return static | [
"Return",
"a",
"new",
"DataList",
"instance",
"with",
"distinct",
"records",
"or",
"not"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L294-L299 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.sort | public function sort()
{
$count = func_num_args();
if ($count == 0) {
return $this;
}
if ($count > 2) {
throw new InvalidArgumentException('This method takes zero, one or two arguments');
}
if ($count == 2) {
$col = null;
$dir = null;
list($col, $dir) = func_get_args();
// Validate direction
if (!in_array(strtolower($dir), ['desc', 'asc'])) {
user_error('Second argument to sort must be either ASC or DESC');
}
$sort = [$col => $dir];
} else {
$sort = func_get_arg(0);
}
return $this->alterDataQuery(function (DataQuery $query, DataList $list) use ($sort) {
if (is_string($sort) && $sort) {
if (false !== stripos($sort, ' asc') || false !== stripos($sort, ' desc')) {
$query->sort($sort);
} else {
$list->applyRelation($sort, $column, true);
$query->sort($column, 'ASC');
}
} elseif (is_array($sort)) {
// sort(array('Name'=>'desc'));
$query->sort(null, null); // wipe the sort
foreach ($sort as $column => $direction) {
// Convert column expressions to SQL fragment, while still allowing the passing of raw SQL
// fragments.
$list->applyRelation($column, $relationColumn, true);
$query->sort($relationColumn, $direction, false);
}
}
});
} | php | public function sort()
{
$count = func_num_args();
if ($count == 0) {
return $this;
}
if ($count > 2) {
throw new InvalidArgumentException('This method takes zero, one or two arguments');
}
if ($count == 2) {
$col = null;
$dir = null;
list($col, $dir) = func_get_args();
// Validate direction
if (!in_array(strtolower($dir), ['desc', 'asc'])) {
user_error('Second argument to sort must be either ASC or DESC');
}
$sort = [$col => $dir];
} else {
$sort = func_get_arg(0);
}
return $this->alterDataQuery(function (DataQuery $query, DataList $list) use ($sort) {
if (is_string($sort) && $sort) {
if (false !== stripos($sort, ' asc') || false !== stripos($sort, ' desc')) {
$query->sort($sort);
} else {
$list->applyRelation($sort, $column, true);
$query->sort($column, 'ASC');
}
} elseif (is_array($sort)) {
// sort(array('Name'=>'desc'));
$query->sort(null, null); // wipe the sort
foreach ($sort as $column => $direction) {
// Convert column expressions to SQL fragment, while still allowing the passing of raw SQL
// fragments.
$list->applyRelation($column, $relationColumn, true);
$query->sort($relationColumn, $direction, false);
}
}
});
} | [
"public",
"function",
"sort",
"(",
")",
"{",
"$",
"count",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"$",
"count",
"==",
"0",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"count",
">",
"2",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'This method takes zero, one or two arguments'",
")",
";",
"}",
"if",
"(",
"$",
"count",
"==",
"2",
")",
"{",
"$",
"col",
"=",
"null",
";",
"$",
"dir",
"=",
"null",
";",
"list",
"(",
"$",
"col",
",",
"$",
"dir",
")",
"=",
"func_get_args",
"(",
")",
";",
"// Validate direction",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"dir",
")",
",",
"[",
"'desc'",
",",
"'asc'",
"]",
")",
")",
"{",
"user_error",
"(",
"'Second argument to sort must be either ASC or DESC'",
")",
";",
"}",
"$",
"sort",
"=",
"[",
"$",
"col",
"=>",
"$",
"dir",
"]",
";",
"}",
"else",
"{",
"$",
"sort",
"=",
"func_get_arg",
"(",
"0",
")",
";",
"}",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
",",
"DataList",
"$",
"list",
")",
"use",
"(",
"$",
"sort",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"sort",
")",
"&&",
"$",
"sort",
")",
"{",
"if",
"(",
"false",
"!==",
"stripos",
"(",
"$",
"sort",
",",
"' asc'",
")",
"||",
"false",
"!==",
"stripos",
"(",
"$",
"sort",
",",
"' desc'",
")",
")",
"{",
"$",
"query",
"->",
"sort",
"(",
"$",
"sort",
")",
";",
"}",
"else",
"{",
"$",
"list",
"->",
"applyRelation",
"(",
"$",
"sort",
",",
"$",
"column",
",",
"true",
")",
";",
"$",
"query",
"->",
"sort",
"(",
"$",
"column",
",",
"'ASC'",
")",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"sort",
")",
")",
"{",
"// sort(array('Name'=>'desc'));",
"$",
"query",
"->",
"sort",
"(",
"null",
",",
"null",
")",
";",
"// wipe the sort",
"foreach",
"(",
"$",
"sort",
"as",
"$",
"column",
"=>",
"$",
"direction",
")",
"{",
"// Convert column expressions to SQL fragment, while still allowing the passing of raw SQL",
"// fragments.",
"$",
"list",
"->",
"applyRelation",
"(",
"$",
"column",
",",
"$",
"relationColumn",
",",
"true",
")",
";",
"$",
"query",
"->",
"sort",
"(",
"$",
"relationColumn",
",",
"$",
"direction",
",",
"false",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
]
| Return a new DataList instance as a copy of this data list with the sort
order set.
@see SS_List::sort()
@see SQLSelect::orderby
@example $list = $list->sort('Name'); // default ASC sorting
@example $list = $list->sort('Name DESC'); // DESC sorting
@example $list = $list->sort('Name', 'ASC');
@example $list = $list->sort(array('Name'=>'ASC', 'Age'=>'DESC'));
@param String|array Escaped SQL statement. If passed as array, all keys and values are assumed to be escaped.
@return static | [
"Return",
"a",
"new",
"DataList",
"instance",
"as",
"a",
"copy",
"of",
"this",
"data",
"list",
"with",
"the",
"sort",
"order",
"set",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L315-L363 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.filter | public function filter()
{
// Validate and process arguments
$arguments = func_get_args();
switch (sizeof($arguments)) {
case 1:
$filters = $arguments[0];
break;
case 2:
$filters = [$arguments[0] => $arguments[1]];
break;
default:
throw new InvalidArgumentException('Incorrect number of arguments passed to filter()');
}
return $this->addFilter($filters);
} | php | public function filter()
{
// Validate and process arguments
$arguments = func_get_args();
switch (sizeof($arguments)) {
case 1:
$filters = $arguments[0];
break;
case 2:
$filters = [$arguments[0] => $arguments[1]];
break;
default:
throw new InvalidArgumentException('Incorrect number of arguments passed to filter()');
}
return $this->addFilter($filters);
} | [
"public",
"function",
"filter",
"(",
")",
"{",
"// Validate and process arguments",
"$",
"arguments",
"=",
"func_get_args",
"(",
")",
";",
"switch",
"(",
"sizeof",
"(",
"$",
"arguments",
")",
")",
"{",
"case",
"1",
":",
"$",
"filters",
"=",
"$",
"arguments",
"[",
"0",
"]",
";",
"break",
";",
"case",
"2",
":",
"$",
"filters",
"=",
"[",
"$",
"arguments",
"[",
"0",
"]",
"=>",
"$",
"arguments",
"[",
"1",
"]",
"]",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Incorrect number of arguments passed to filter()'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"addFilter",
"(",
"$",
"filters",
")",
";",
"}"
]
| Return a copy of this list which only includes items with these charactaristics
@see SS_List::filter()
@example $list = $list->filter('Name', 'bob'); // only bob in the list
@example $list = $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
@example $list = $list->filter(array('Name'=>'bob', 'Age'=>21)); // bob with the age 21
@example $list = $list->filter(array('Name'=>'bob', 'Age'=>array(21, 43))); // bob with the Age 21 or 43
@example $list = $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43)));
// aziz with the age 21 or 43 and bob with the Age 21 or 43
Note: When filtering on nullable columns, null checks will be automatically added.
E.g. ->filter('Field:not', 'value) will generate '... OR "Field" IS NULL', and
->filter('Field:not', null) will generate '"Field" IS NOT NULL'
@todo extract the sql from $customQuery into a SQLGenerator class
@param string|array Escaped SQL statement. If passed as array, all keys and values will be escaped internally
@return $this | [
"Return",
"a",
"copy",
"of",
"this",
"list",
"which",
"only",
"includes",
"items",
"with",
"these",
"charactaristics"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L386-L404 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.addFilter | public function addFilter($filterArray)
{
$list = $this;
foreach ($filterArray as $expression => $value) {
$filter = $this->createSearchFilter($expression, $value);
$list = $list->alterDataQuery([$filter, 'apply']);
}
return $list;
} | php | public function addFilter($filterArray)
{
$list = $this;
foreach ($filterArray as $expression => $value) {
$filter = $this->createSearchFilter($expression, $value);
$list = $list->alterDataQuery([$filter, 'apply']);
}
return $list;
} | [
"public",
"function",
"addFilter",
"(",
"$",
"filterArray",
")",
"{",
"$",
"list",
"=",
"$",
"this",
";",
"foreach",
"(",
"$",
"filterArray",
"as",
"$",
"expression",
"=>",
"$",
"value",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"createSearchFilter",
"(",
"$",
"expression",
",",
"$",
"value",
")",
";",
"$",
"list",
"=",
"$",
"list",
"->",
"alterDataQuery",
"(",
"[",
"$",
"filter",
",",
"'apply'",
"]",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
]
| Return a new instance of the list with an added filter
@param array $filterArray
@return $this | [
"Return",
"a",
"new",
"instance",
"of",
"the",
"list",
"with",
"an",
"added",
"filter"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L412-L422 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.applyRelation | public function applyRelation($field, &$columnName = null, $linearOnly = false)
{
// If field is invalid, return it without modification
if (!$this->isValidRelationName($field)) {
$columnName = $field;
return $this;
}
// Simple fields without relations are mapped directly
if (strpos($field, '.') === false) {
$columnName = '"' . $field . '"';
return $this;
}
return $this->alterDataQuery(
function (DataQuery $query) use ($field, &$columnName, $linearOnly) {
$relations = explode('.', $field);
$fieldName = array_pop($relations);
// Apply relation
$relationModelName = $query->applyRelation($relations, $linearOnly);
$relationPrefix = $query->applyRelationPrefix($relations);
// Find the db field the relation belongs to
$columnName = DataObject::getSchema()
->sqlColumnForField($relationModelName, $fieldName, $relationPrefix);
}
);
} | php | public function applyRelation($field, &$columnName = null, $linearOnly = false)
{
// If field is invalid, return it without modification
if (!$this->isValidRelationName($field)) {
$columnName = $field;
return $this;
}
// Simple fields without relations are mapped directly
if (strpos($field, '.') === false) {
$columnName = '"' . $field . '"';
return $this;
}
return $this->alterDataQuery(
function (DataQuery $query) use ($field, &$columnName, $linearOnly) {
$relations = explode('.', $field);
$fieldName = array_pop($relations);
// Apply relation
$relationModelName = $query->applyRelation($relations, $linearOnly);
$relationPrefix = $query->applyRelationPrefix($relations);
// Find the db field the relation belongs to
$columnName = DataObject::getSchema()
->sqlColumnForField($relationModelName, $fieldName, $relationPrefix);
}
);
} | [
"public",
"function",
"applyRelation",
"(",
"$",
"field",
",",
"&",
"$",
"columnName",
"=",
"null",
",",
"$",
"linearOnly",
"=",
"false",
")",
"{",
"// If field is invalid, return it without modification",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidRelationName",
"(",
"$",
"field",
")",
")",
"{",
"$",
"columnName",
"=",
"$",
"field",
";",
"return",
"$",
"this",
";",
"}",
"// Simple fields without relations are mapped directly",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"$",
"columnName",
"=",
"'\"'",
".",
"$",
"field",
".",
"'\"'",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"field",
",",
"&",
"$",
"columnName",
",",
"$",
"linearOnly",
")",
"{",
"$",
"relations",
"=",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
";",
"$",
"fieldName",
"=",
"array_pop",
"(",
"$",
"relations",
")",
";",
"// Apply relation",
"$",
"relationModelName",
"=",
"$",
"query",
"->",
"applyRelation",
"(",
"$",
"relations",
",",
"$",
"linearOnly",
")",
";",
"$",
"relationPrefix",
"=",
"$",
"query",
"->",
"applyRelationPrefix",
"(",
"$",
"relations",
")",
";",
"// Find the db field the relation belongs to",
"$",
"columnName",
"=",
"DataObject",
"::",
"getSchema",
"(",
")",
"->",
"sqlColumnForField",
"(",
"$",
"relationModelName",
",",
"$",
"fieldName",
",",
"$",
"relationPrefix",
")",
";",
"}",
")",
";",
"}"
]
| Given a field or relation name, apply it safely to this datalist.
Unlike getRelationName, this is immutable and will fallback to the quoted field
name if not a relation.
@param string $field Name of field or relation to apply
@param string &$columnName Quoted column name
@param bool $linearOnly Set to true to restrict to linear relations only. Set this
if this relation will be used for sorting, and should not include duplicate rows.
@return $this DataList with this relation applied | [
"Given",
"a",
"field",
"or",
"relation",
"name",
"apply",
"it",
"safely",
"to",
"this",
"datalist",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L510-L538 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.exclude | public function exclude()
{
$numberFuncArgs = count(func_get_args());
$whereArguments = [];
if ($numberFuncArgs == 1 && is_array(func_get_arg(0))) {
$whereArguments = func_get_arg(0);
} elseif ($numberFuncArgs == 2) {
$whereArguments[func_get_arg(0)] = func_get_arg(1);
} else {
throw new InvalidArgumentException('Incorrect number of arguments passed to exclude()');
}
return $this->alterDataQuery(function (DataQuery $query) use ($whereArguments) {
$subquery = $query->disjunctiveGroup();
foreach ($whereArguments as $field => $value) {
$filter = $this->createSearchFilter($field, $value);
$filter->exclude($subquery);
}
});
} | php | public function exclude()
{
$numberFuncArgs = count(func_get_args());
$whereArguments = [];
if ($numberFuncArgs == 1 && is_array(func_get_arg(0))) {
$whereArguments = func_get_arg(0);
} elseif ($numberFuncArgs == 2) {
$whereArguments[func_get_arg(0)] = func_get_arg(1);
} else {
throw new InvalidArgumentException('Incorrect number of arguments passed to exclude()');
}
return $this->alterDataQuery(function (DataQuery $query) use ($whereArguments) {
$subquery = $query->disjunctiveGroup();
foreach ($whereArguments as $field => $value) {
$filter = $this->createSearchFilter($field, $value);
$filter->exclude($subquery);
}
});
} | [
"public",
"function",
"exclude",
"(",
")",
"{",
"$",
"numberFuncArgs",
"=",
"count",
"(",
"func_get_args",
"(",
")",
")",
";",
"$",
"whereArguments",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"numberFuncArgs",
"==",
"1",
"&&",
"is_array",
"(",
"func_get_arg",
"(",
"0",
")",
")",
")",
"{",
"$",
"whereArguments",
"=",
"func_get_arg",
"(",
"0",
")",
";",
"}",
"elseif",
"(",
"$",
"numberFuncArgs",
"==",
"2",
")",
"{",
"$",
"whereArguments",
"[",
"func_get_arg",
"(",
"0",
")",
"]",
"=",
"func_get_arg",
"(",
"1",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Incorrect number of arguments passed to exclude()'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"whereArguments",
")",
"{",
"$",
"subquery",
"=",
"$",
"query",
"->",
"disjunctiveGroup",
"(",
")",
";",
"foreach",
"(",
"$",
"whereArguments",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"createSearchFilter",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"$",
"filter",
"->",
"exclude",
"(",
"$",
"subquery",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Return a copy of this list which does not contain any items that match all params
@example $list = $list->exclude('Name', 'bob'); // exclude bob from list
@example $list = $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
@example $list = $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21
@example $list = $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
@example $list = $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
// bob age 21 or 43, phil age 21 or 43 would be excluded
@todo extract the sql from this method into a SQLGenerator class
@param string|array
@param string [optional]
@return $this | [
"Return",
"a",
"copy",
"of",
"this",
"list",
"which",
"does",
"not",
"contain",
"any",
"items",
"that",
"match",
"all",
"params"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L606-L627 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.excludeAny | public function excludeAny()
{
$numberFuncArgs = count(func_get_args());
$whereArguments = [];
if ($numberFuncArgs == 1 && is_array(func_get_arg(0))) {
$whereArguments = func_get_arg(0);
} elseif ($numberFuncArgs == 2) {
$whereArguments[func_get_arg(0)] = func_get_arg(1);
} else {
throw new InvalidArgumentException('Incorrect number of arguments passed to excludeAny()');
}
return $this->alterDataQuery(function (DataQuery $dataQuery) use ($whereArguments) {
foreach ($whereArguments as $field => $value) {
$filter = $this->createSearchFilter($field, $value);
$filter->exclude($dataQuery);
}
return $dataQuery;
});
} | php | public function excludeAny()
{
$numberFuncArgs = count(func_get_args());
$whereArguments = [];
if ($numberFuncArgs == 1 && is_array(func_get_arg(0))) {
$whereArguments = func_get_arg(0);
} elseif ($numberFuncArgs == 2) {
$whereArguments[func_get_arg(0)] = func_get_arg(1);
} else {
throw new InvalidArgumentException('Incorrect number of arguments passed to excludeAny()');
}
return $this->alterDataQuery(function (DataQuery $dataQuery) use ($whereArguments) {
foreach ($whereArguments as $field => $value) {
$filter = $this->createSearchFilter($field, $value);
$filter->exclude($dataQuery);
}
return $dataQuery;
});
} | [
"public",
"function",
"excludeAny",
"(",
")",
"{",
"$",
"numberFuncArgs",
"=",
"count",
"(",
"func_get_args",
"(",
")",
")",
";",
"$",
"whereArguments",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"numberFuncArgs",
"==",
"1",
"&&",
"is_array",
"(",
"func_get_arg",
"(",
"0",
")",
")",
")",
"{",
"$",
"whereArguments",
"=",
"func_get_arg",
"(",
"0",
")",
";",
"}",
"elseif",
"(",
"$",
"numberFuncArgs",
"==",
"2",
")",
"{",
"$",
"whereArguments",
"[",
"func_get_arg",
"(",
"0",
")",
"]",
"=",
"func_get_arg",
"(",
"1",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Incorrect number of arguments passed to excludeAny()'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"dataQuery",
")",
"use",
"(",
"$",
"whereArguments",
")",
"{",
"foreach",
"(",
"$",
"whereArguments",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"filter",
"=",
"$",
"this",
"->",
"createSearchFilter",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"$",
"filter",
"->",
"exclude",
"(",
"$",
"dataQuery",
")",
";",
"}",
"return",
"$",
"dataQuery",
";",
"}",
")",
";",
"}"
]
| Return a copy of this list which does not contain any items with any of these params
@example $list = $list->excludeAny('Name', 'bob'); // exclude bob from list
@example $list = $list->excludeAny('Name', array('aziz', 'bob'); // exclude aziz and bob from list
@example $list = $list->excludeAny(array('Name'=>'bob, 'Age'=>21)); // exclude bob or Age 21
@example $list = $list->excludeAny(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob or Age 21 or 43
@example $list = $list->excludeAny(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
// bob, phil, 21 or 43 would be excluded
@param string|array
@param string [optional]
@return $this | [
"Return",
"a",
"copy",
"of",
"this",
"list",
"which",
"does",
"not",
"contain",
"any",
"items",
"with",
"any",
"of",
"these",
"params"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L644-L664 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.innerJoin | public function innerJoin($table, $onClause, $alias = null, $order = 20, $parameters = [])
{
return $this->alterDataQuery(function (DataQuery $query) use ($table, $onClause, $alias, $order, $parameters) {
$query->innerJoin($table, $onClause, $alias, $order, $parameters);
});
} | php | public function innerJoin($table, $onClause, $alias = null, $order = 20, $parameters = [])
{
return $this->alterDataQuery(function (DataQuery $query) use ($table, $onClause, $alias, $order, $parameters) {
$query->innerJoin($table, $onClause, $alias, $order, $parameters);
});
} | [
"public",
"function",
"innerJoin",
"(",
"$",
"table",
",",
"$",
"onClause",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"order",
"=",
"20",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"table",
",",
"$",
"onClause",
",",
"$",
"alias",
",",
"$",
"order",
",",
"$",
"parameters",
")",
"{",
"$",
"query",
"->",
"innerJoin",
"(",
"$",
"table",
",",
"$",
"onClause",
",",
"$",
"alias",
",",
"$",
"order",
",",
"$",
"parameters",
")",
";",
"}",
")",
";",
"}"
]
| Return a new DataList instance with an inner join clause added to this list's query.
@param string $table Table name (unquoted and as escaped SQL)
@param string $onClause Escaped SQL statement, e.g. '"Table1"."ID" = "Table2"."ID"'
@param string $alias - if you want this table to be aliased under another name
@param int $order A numerical index to control the order that joins are added to the query; lower order values
will cause the query to appear first. The default is 20, and joins created automatically by the
ORM have a value of 10.
@param array $parameters Any additional parameters if the join is a parameterised subquery
@return static | [
"Return",
"a",
"new",
"DataList",
"instance",
"with",
"an",
"inner",
"join",
"clause",
"added",
"to",
"this",
"list",
"s",
"query",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L698-L703 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.toArray | public function toArray()
{
$query = $this->dataQuery->query();
$rows = $query->execute();
$results = [];
foreach ($rows as $row) {
$results[] = $this->createDataObject($row);
}
return $results;
} | php | public function toArray()
{
$query = $this->dataQuery->query();
$rows = $query->execute();
$results = [];
foreach ($rows as $row) {
$results[] = $this->createDataObject($row);
}
return $results;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"dataQuery",
"->",
"query",
"(",
")",
";",
"$",
"rows",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"$",
"this",
"->",
"createDataObject",
"(",
"$",
"row",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
]
| Return an array of the actual items that this DataList contains at this stage.
This is when the query is actually executed.
@return array | [
"Return",
"an",
"array",
"of",
"the",
"actual",
"items",
"that",
"this",
"DataList",
"contains",
"at",
"this",
"stage",
".",
"This",
"is",
"when",
"the",
"query",
"is",
"actually",
"executed",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L730-L741 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.getGenerator | public function getGenerator()
{
$query = $this->dataQuery->query()->execute();
while ($row = $query->record()) {
yield $this->createDataObject($row);
}
} | php | public function getGenerator()
{
$query = $this->dataQuery->query()->execute();
while ($row = $query->record()) {
yield $this->createDataObject($row);
}
} | [
"public",
"function",
"getGenerator",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"dataQuery",
"->",
"query",
"(",
")",
"->",
"execute",
"(",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"query",
"->",
"record",
"(",
")",
")",
"{",
"yield",
"$",
"this",
"->",
"createDataObject",
"(",
"$",
"row",
")",
";",
"}",
"}"
]
| Returns a generator for this DataList
@return \Generator&DataObject[] | [
"Returns",
"a",
"generator",
"for",
"this",
"DataList"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L779-L786 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.createDataObject | public function createDataObject($row)
{
$class = $this->dataClass;
if (empty($row['ClassName'])) {
$row['ClassName'] = $class;
}
// Failover from RecordClassName to ClassName
if (empty($row['RecordClassName'])) {
$row['RecordClassName'] = $row['ClassName'];
}
// Instantiate the class mentioned in RecordClassName only if it exists, otherwise default to $this->dataClass
if (class_exists($row['RecordClassName'])) {
$class = $row['RecordClassName'];
}
$item = Injector::inst()->create($class, $row, false, $this->getQueryParams());
return $item;
} | php | public function createDataObject($row)
{
$class = $this->dataClass;
if (empty($row['ClassName'])) {
$row['ClassName'] = $class;
}
// Failover from RecordClassName to ClassName
if (empty($row['RecordClassName'])) {
$row['RecordClassName'] = $row['ClassName'];
}
// Instantiate the class mentioned in RecordClassName only if it exists, otherwise default to $this->dataClass
if (class_exists($row['RecordClassName'])) {
$class = $row['RecordClassName'];
}
$item = Injector::inst()->create($class, $row, false, $this->getQueryParams());
return $item;
} | [
"public",
"function",
"createDataObject",
"(",
"$",
"row",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dataClass",
";",
"if",
"(",
"empty",
"(",
"$",
"row",
"[",
"'ClassName'",
"]",
")",
")",
"{",
"$",
"row",
"[",
"'ClassName'",
"]",
"=",
"$",
"class",
";",
"}",
"// Failover from RecordClassName to ClassName",
"if",
"(",
"empty",
"(",
"$",
"row",
"[",
"'RecordClassName'",
"]",
")",
")",
"{",
"$",
"row",
"[",
"'RecordClassName'",
"]",
"=",
"$",
"row",
"[",
"'ClassName'",
"]",
";",
"}",
"// Instantiate the class mentioned in RecordClassName only if it exists, otherwise default to $this->dataClass",
"if",
"(",
"class_exists",
"(",
"$",
"row",
"[",
"'RecordClassName'",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"row",
"[",
"'RecordClassName'",
"]",
";",
"}",
"$",
"item",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"class",
",",
"$",
"row",
",",
"false",
",",
"$",
"this",
"->",
"getQueryParams",
"(",
")",
")",
";",
"return",
"$",
"item",
";",
"}"
]
| Create a DataObject from the given SQL row
@param array $row
@return DataObject | [
"Create",
"a",
"DataObject",
"from",
"the",
"given",
"SQL",
"row"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L816-L837 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.first | public function first()
{
foreach ($this->dataQuery->firstRow()->execute() as $row) {
return $this->createDataObject($row);
}
return null;
} | php | public function first()
{
foreach ($this->dataQuery->firstRow()->execute() as $row) {
return $this->createDataObject($row);
}
return null;
} | [
"public",
"function",
"first",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dataQuery",
"->",
"firstRow",
"(",
")",
"->",
"execute",
"(",
")",
"as",
"$",
"row",
")",
"{",
"return",
"$",
"this",
"->",
"createDataObject",
"(",
"$",
"row",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Returns the first item in this DataList
@return DataObject | [
"Returns",
"the",
"first",
"item",
"in",
"this",
"DataList"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L921-L927 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.last | public function last()
{
foreach ($this->dataQuery->lastRow()->execute() as $row) {
return $this->createDataObject($row);
}
return null;
} | php | public function last()
{
foreach ($this->dataQuery->lastRow()->execute() as $row) {
return $this->createDataObject($row);
}
return null;
} | [
"public",
"function",
"last",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dataQuery",
"->",
"lastRow",
"(",
")",
"->",
"execute",
"(",
")",
"as",
"$",
"row",
")",
"{",
"return",
"$",
"this",
"->",
"createDataObject",
"(",
"$",
"row",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Returns the last item in this DataList
@return DataObject | [
"Returns",
"the",
"last",
"item",
"in",
"this",
"DataList"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L934-L940 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.setQueriedColumns | public function setQueriedColumns($queriedColumns)
{
return $this->alterDataQuery(function (DataQuery $query) use ($queriedColumns) {
$query->setQueriedColumns($queriedColumns);
});
} | php | public function setQueriedColumns($queriedColumns)
{
return $this->alterDataQuery(function (DataQuery $query) use ($queriedColumns) {
$query->setQueriedColumns($queriedColumns);
});
} | [
"public",
"function",
"setQueriedColumns",
"(",
"$",
"queriedColumns",
")",
"{",
"return",
"$",
"this",
"->",
"alterDataQuery",
"(",
"function",
"(",
"DataQuery",
"$",
"query",
")",
"use",
"(",
"$",
"queriedColumns",
")",
"{",
"$",
"query",
"->",
"setQueriedColumns",
"(",
"$",
"queriedColumns",
")",
";",
"}",
")",
";",
"}"
]
| Restrict the columns to fetch into this DataList
@param array $queriedColumns
@return static | [
"Restrict",
"the",
"columns",
"to",
"fetch",
"into",
"this",
"DataList"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L970-L975 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.setByIDList | public function setByIDList($idList)
{
$has = [];
// Index current data
foreach ($this->column() as $id) {
$has[$id] = true;
}
// Keep track of items to delete
$itemsToDelete = $has;
// add items in the list
// $id is the database ID of the record
if ($idList) {
foreach ($idList as $id) {
unset($itemsToDelete[$id]);
if ($id && !isset($has[$id])) {
$this->add($id);
}
}
}
// Remove any items that haven't been mentioned
$this->removeMany(array_keys($itemsToDelete));
} | php | public function setByIDList($idList)
{
$has = [];
// Index current data
foreach ($this->column() as $id) {
$has[$id] = true;
}
// Keep track of items to delete
$itemsToDelete = $has;
// add items in the list
// $id is the database ID of the record
if ($idList) {
foreach ($idList as $id) {
unset($itemsToDelete[$id]);
if ($id && !isset($has[$id])) {
$this->add($id);
}
}
}
// Remove any items that haven't been mentioned
$this->removeMany(array_keys($itemsToDelete));
} | [
"public",
"function",
"setByIDList",
"(",
"$",
"idList",
")",
"{",
"$",
"has",
"=",
"[",
"]",
";",
"// Index current data",
"foreach",
"(",
"$",
"this",
"->",
"column",
"(",
")",
"as",
"$",
"id",
")",
"{",
"$",
"has",
"[",
"$",
"id",
"]",
"=",
"true",
";",
"}",
"// Keep track of items to delete",
"$",
"itemsToDelete",
"=",
"$",
"has",
";",
"// add items in the list",
"// $id is the database ID of the record",
"if",
"(",
"$",
"idList",
")",
"{",
"foreach",
"(",
"$",
"idList",
"as",
"$",
"id",
")",
"{",
"unset",
"(",
"$",
"itemsToDelete",
"[",
"$",
"id",
"]",
")",
";",
"if",
"(",
"$",
"id",
"&&",
"!",
"isset",
"(",
"$",
"has",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"id",
")",
";",
"}",
"}",
"}",
"// Remove any items that haven't been mentioned",
"$",
"this",
"->",
"removeMany",
"(",
"array_keys",
"(",
"$",
"itemsToDelete",
")",
")",
";",
"}"
]
| Sets the ComponentSet to be the given ID list.
Records will be added and deleted as appropriate.
@param array $idList List of IDs. | [
"Sets",
"the",
"ComponentSet",
"to",
"be",
"the",
"given",
"ID",
"list",
".",
"Records",
"will",
"be",
"added",
"and",
"deleted",
"as",
"appropriate",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L1029-L1054 | train |
silverstripe/silverstripe-framework | src/ORM/DataList.php | DataList.newObject | public function newObject($initialFields = null)
{
$class = $this->dataClass;
return Injector::inst()->create($class, $initialFields, false);
} | php | public function newObject($initialFields = null)
{
$class = $this->dataClass;
return Injector::inst()->create($class, $initialFields, false);
} | [
"public",
"function",
"newObject",
"(",
"$",
"initialFields",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dataClass",
";",
"return",
"Injector",
"::",
"inst",
"(",
")",
"->",
"create",
"(",
"$",
"class",
",",
"$",
"initialFields",
",",
"false",
")",
";",
"}"
]
| Return a new item to add to this DataList.
@todo This doesn't factor in filters.
@param array $initialFields
@return DataObject | [
"Return",
"a",
"new",
"item",
"to",
"add",
"to",
"this",
"DataList",
"."
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/ORM/DataList.php#L1168-L1172 | train |
silverstripe/silverstripe-framework | src/Core/Injector/SilverStripeServiceConfigurationLocator.php | SilverStripeServiceConfigurationLocator.configFor | protected function configFor($name)
{
// Return cached result
if (array_key_exists($name, $this->configs)) {
return $this->configs[$name];
}
$config = Config::inst()->get(Injector::class, $name);
$this->configs[$name] = $config;
return $config;
} | php | protected function configFor($name)
{
// Return cached result
if (array_key_exists($name, $this->configs)) {
return $this->configs[$name];
}
$config = Config::inst()->get(Injector::class, $name);
$this->configs[$name] = $config;
return $config;
} | [
"protected",
"function",
"configFor",
"(",
"$",
"name",
")",
"{",
"// Return cached result",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"configs",
")",
")",
"{",
"return",
"$",
"this",
"->",
"configs",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"config",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"Injector",
"::",
"class",
",",
"$",
"name",
")",
";",
"$",
"this",
"->",
"configs",
"[",
"$",
"name",
"]",
"=",
"$",
"config",
";",
"return",
"$",
"config",
";",
"}"
]
| Retrieves the config for a named service without performing a hierarchy walk
@param string $name Name of service
@return mixed Get config for this service | [
"Retrieves",
"the",
"config",
"for",
"a",
"named",
"service",
"without",
"performing",
"a",
"hierarchy",
"walk"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/Core/Injector/SilverStripeServiceConfigurationLocator.php#L47-L57 | train |
silverstripe/silverstripe-framework | src/View/SSViewer.php | SSViewer.fromString | public static function fromString($content, $cacheTemplate = null)
{
$viewer = SSViewer_FromString::create($content);
if ($cacheTemplate !== null) {
$viewer->setCacheTemplate($cacheTemplate);
}
return $viewer;
} | php | public static function fromString($content, $cacheTemplate = null)
{
$viewer = SSViewer_FromString::create($content);
if ($cacheTemplate !== null) {
$viewer->setCacheTemplate($cacheTemplate);
}
return $viewer;
} | [
"public",
"static",
"function",
"fromString",
"(",
"$",
"content",
",",
"$",
"cacheTemplate",
"=",
"null",
")",
"{",
"$",
"viewer",
"=",
"SSViewer_FromString",
"::",
"create",
"(",
"$",
"content",
")",
";",
"if",
"(",
"$",
"cacheTemplate",
"!==",
"null",
")",
"{",
"$",
"viewer",
"->",
"setCacheTemplate",
"(",
"$",
"cacheTemplate",
")",
";",
"}",
"return",
"$",
"viewer",
";",
"}"
]
| Create a template from a string instead of a .ss file
@param string $content The template content
@param bool|void $cacheTemplate Whether or not to cache the template from string
@return SSViewer | [
"Create",
"a",
"template",
"from",
"a",
"string",
"instead",
"of",
"a",
".",
"ss",
"file"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/View/SSViewer.php#L235-L242 | train |
silverstripe/silverstripe-framework | src/View/SSViewer.php | SSViewer.add_themes | public static function add_themes($themes = [])
{
$currentThemes = SSViewer::get_themes();
$finalThemes = array_merge($themes, $currentThemes);
// array_values is used to ensure sequential array keys as array_unique can leave gaps
static::set_themes(array_values(array_unique($finalThemes)));
} | php | public static function add_themes($themes = [])
{
$currentThemes = SSViewer::get_themes();
$finalThemes = array_merge($themes, $currentThemes);
// array_values is used to ensure sequential array keys as array_unique can leave gaps
static::set_themes(array_values(array_unique($finalThemes)));
} | [
"public",
"static",
"function",
"add_themes",
"(",
"$",
"themes",
"=",
"[",
"]",
")",
"{",
"$",
"currentThemes",
"=",
"SSViewer",
"::",
"get_themes",
"(",
")",
";",
"$",
"finalThemes",
"=",
"array_merge",
"(",
"$",
"themes",
",",
"$",
"currentThemes",
")",
";",
"// array_values is used to ensure sequential array keys as array_unique can leave gaps",
"static",
"::",
"set_themes",
"(",
"array_values",
"(",
"array_unique",
"(",
"$",
"finalThemes",
")",
")",
")",
";",
"}"
]
| Add to the list of active themes to apply
@param array $themes | [
"Add",
"to",
"the",
"list",
"of",
"active",
"themes",
"to",
"apply"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/View/SSViewer.php#L260-L266 | train |
silverstripe/silverstripe-framework | src/View/SSViewer.php | SSViewer.get_themes | public static function get_themes()
{
$default = [self::PUBLIC_THEME, self::DEFAULT_THEME];
if (!SSViewer::config()->uninherited('theme_enabled')) {
return $default;
}
// Explicit list is assigned
$themes = static::$current_themes;
if (!isset($themes)) {
$themes = SSViewer::config()->uninherited('themes');
}
if ($themes) {
return $themes;
}
// Support legacy behaviour
if ($theme = SSViewer::config()->uninherited('theme')) {
return [self::PUBLIC_THEME, $theme, self::DEFAULT_THEME];
}
return $default;
} | php | public static function get_themes()
{
$default = [self::PUBLIC_THEME, self::DEFAULT_THEME];
if (!SSViewer::config()->uninherited('theme_enabled')) {
return $default;
}
// Explicit list is assigned
$themes = static::$current_themes;
if (!isset($themes)) {
$themes = SSViewer::config()->uninherited('themes');
}
if ($themes) {
return $themes;
}
// Support legacy behaviour
if ($theme = SSViewer::config()->uninherited('theme')) {
return [self::PUBLIC_THEME, $theme, self::DEFAULT_THEME];
}
return $default;
} | [
"public",
"static",
"function",
"get_themes",
"(",
")",
"{",
"$",
"default",
"=",
"[",
"self",
"::",
"PUBLIC_THEME",
",",
"self",
"::",
"DEFAULT_THEME",
"]",
";",
"if",
"(",
"!",
"SSViewer",
"::",
"config",
"(",
")",
"->",
"uninherited",
"(",
"'theme_enabled'",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// Explicit list is assigned",
"$",
"themes",
"=",
"static",
"::",
"$",
"current_themes",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"themes",
")",
")",
"{",
"$",
"themes",
"=",
"SSViewer",
"::",
"config",
"(",
")",
"->",
"uninherited",
"(",
"'themes'",
")",
";",
"}",
"if",
"(",
"$",
"themes",
")",
"{",
"return",
"$",
"themes",
";",
"}",
"// Support legacy behaviour",
"if",
"(",
"$",
"theme",
"=",
"SSViewer",
"::",
"config",
"(",
")",
"->",
"uninherited",
"(",
"'theme'",
")",
")",
"{",
"return",
"[",
"self",
"::",
"PUBLIC_THEME",
",",
"$",
"theme",
",",
"self",
"::",
"DEFAULT_THEME",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
]
| Get the list of active themes
@return array | [
"Get",
"the",
"list",
"of",
"active",
"themes"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/View/SSViewer.php#L273-L296 | train |
silverstripe/silverstripe-framework | src/View/SSViewer.php | SSViewer.getParser | public function getParser()
{
if (!$this->parser) {
$this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'));
}
return $this->parser;
} | php | public function getParser()
{
if (!$this->parser) {
$this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'));
}
return $this->parser;
} | [
"public",
"function",
"getParser",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parser",
")",
"{",
"$",
"this",
"->",
"setParser",
"(",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"'SilverStripe\\\\View\\\\SSTemplateParser'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parser",
";",
"}"
]
| Returns the parser that is set for template generation
@return TemplateParser | [
"Returns",
"the",
"parser",
"that",
"is",
"set",
"for",
"template",
"generation"
]
| ed7aaff7da61eefa172fe213ec25e35d2568bc20 | https://github.com/silverstripe/silverstripe-framework/blob/ed7aaff7da61eefa172fe213ec25e35d2568bc20/src/View/SSViewer.php#L448-L454 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.