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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
helios-ag/FMElfinderBundle | src/Controller/ElFinderController.php | ElFinderController.getAssetsUrl | protected function getAssetsUrl($inputUrl)
{
/** @var $assets \Symfony\Component\Templating\Helper\CoreAssetsHelper */
$assets = $this->container->get('templating.helper.assets');
$url = preg_replace('/^asset\[(.+)\]$/i', '$1', $inputUrl);
if ($inputUrl !== $url) {
return $assets->getUrl($url);
}
return $inputUrl;
} | php | protected function getAssetsUrl($inputUrl)
{
/** @var $assets \Symfony\Component\Templating\Helper\CoreAssetsHelper */
$assets = $this->container->get('templating.helper.assets');
$url = preg_replace('/^asset\[(.+)\]$/i', '$1', $inputUrl);
if ($inputUrl !== $url) {
return $assets->getUrl($url);
}
return $inputUrl;
} | [
"protected",
"function",
"getAssetsUrl",
"(",
"$",
"inputUrl",
")",
"{",
"/** @var $assets \\Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper */",
"$",
"assets",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'templating.helper.assets'",
")",
";",
"$",
... | Get url from config string.
@param string $inputUrl
@return string | [
"Get",
"url",
"from",
"config",
"string",
"."
] | eb51696c7e72c7c53ffa26850faca20402fa9236 | https://github.com/helios-ag/FMElfinderBundle/blob/eb51696c7e72c7c53ffa26850faca20402fa9236/src/Controller/ElFinderController.php#L247-L259 | train |
helios-ag/FMElfinderBundle | src/ElFinder/ElFinder.php | ElFinder.mountVolumes | protected function mountVolumes($opts)
{
foreach ($opts['roots'] as $i => $o) {
$class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : '');
if (class_exists($class)) {
$volume = new $class();
try {
if ($this->maxArcFilesSize && (empty($o['maxArcFilesSize']) || $this->maxArcFilesSize < $o['maxArcFilesSize'])) {
$o['maxArcFilesSize'] = $this->maxArcFilesSize;
}
// pass session handler
$volume->setSession($this->session);
if ($volume->mount($o)) {
// unique volume id (ends on "_") - used as prefix to files hash
$id = $volume->id();
$this->volumes[$id] = $volume;
if ((!$this->default || $volume->root() !== $volume->defaultPath()) && $volume->isReadable()) {
$this->default = $this->volumes[$id];
}
} else {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" : '.implode(' ', $volume->error());
}
} catch (Exception $e) {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" : '.$e->getMessage();
}
} else {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" does not exist';
}
}
} | php | protected function mountVolumes($opts)
{
foreach ($opts['roots'] as $i => $o) {
$class = 'elFinderVolume'.(isset($o['driver']) ? $o['driver'] : '');
if (class_exists($class)) {
$volume = new $class();
try {
if ($this->maxArcFilesSize && (empty($o['maxArcFilesSize']) || $this->maxArcFilesSize < $o['maxArcFilesSize'])) {
$o['maxArcFilesSize'] = $this->maxArcFilesSize;
}
// pass session handler
$volume->setSession($this->session);
if ($volume->mount($o)) {
// unique volume id (ends on "_") - used as prefix to files hash
$id = $volume->id();
$this->volumes[$id] = $volume;
if ((!$this->default || $volume->root() !== $volume->defaultPath()) && $volume->isReadable()) {
$this->default = $this->volumes[$id];
}
} else {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" : '.implode(' ', $volume->error());
}
} catch (Exception $e) {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" : '.$e->getMessage();
}
} else {
$this->removeNetVolume($i, $volume);
$this->mountErrors[] = 'Driver "'.$class.'" does not exist';
}
}
} | [
"protected",
"function",
"mountVolumes",
"(",
"$",
"opts",
")",
"{",
"foreach",
"(",
"$",
"opts",
"[",
"'roots'",
"]",
"as",
"$",
"i",
"=>",
"$",
"o",
")",
"{",
"$",
"class",
"=",
"'elFinderVolume'",
".",
"(",
"isset",
"(",
"$",
"o",
"[",
"'driver'... | Mount volumes.
Instantiate corresponding driver class and
add it to the list of volumes.
@param array $opts | [
"Mount",
"volumes",
"."
] | eb51696c7e72c7c53ffa26850faca20402fa9236 | https://github.com/helios-ag/FMElfinderBundle/blob/eb51696c7e72c7c53ffa26850faca20402fa9236/src/ElFinder/ElFinder.php#L251-L286 | train |
helios-ag/FMElfinderBundle | src/DependencyInjection/Configuration.php | Configuration.createNode | private function createNode($name)
{
$treeBuilder = new TreeBuilder($name);
if (\method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
$rootNode = $treeBuilder->root($name);
}
return $rootNode;
} | php | private function createNode($name)
{
$treeBuilder = new TreeBuilder($name);
if (\method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
$rootNode = $treeBuilder->root($name);
}
return $rootNode;
} | [
"private",
"function",
"createNode",
"(",
"$",
"name",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
"$",
"name",
")",
";",
"if",
"(",
"\\",
"method_exists",
"(",
"$",
"treeBuilder",
",",
"'getRootNode'",
")",
")",
"{",
"$",
"rootNode",
... | Creates a node.
@param string $name the node name
@return \Symfony\Component\Config\Definition\Builder\NodeDefinition the node | [
"Creates",
"a",
"node",
"."
] | eb51696c7e72c7c53ffa26850faca20402fa9236 | https://github.com/helios-ag/FMElfinderBundle/blob/eb51696c7e72c7c53ffa26850faca20402fa9236/src/DependencyInjection/Configuration.php#L482-L492 | train |
djoos/Symfony-coding-standard | Symfony/Sniffs/Commenting/FunctionCommentSniff.php | FunctionCommentSniff.isMatchingReturn | protected function isMatchingReturn($tokens, $returnPos)
{
do {
$returnPos++;
} while ($tokens[$returnPos]['code'] === T_WHITESPACE);
return $tokens[$returnPos]['code'] !== T_SEMICOLON;
} | php | protected function isMatchingReturn($tokens, $returnPos)
{
do {
$returnPos++;
} while ($tokens[$returnPos]['code'] === T_WHITESPACE);
return $tokens[$returnPos]['code'] !== T_SEMICOLON;
} | [
"protected",
"function",
"isMatchingReturn",
"(",
"$",
"tokens",
",",
"$",
"returnPos",
")",
"{",
"do",
"{",
"$",
"returnPos",
"++",
";",
"}",
"while",
"(",
"$",
"tokens",
"[",
"$",
"returnPos",
"]",
"[",
"'code'",
"]",
"===",
"T_WHITESPACE",
")",
";",... | Is the return statement matching?
@param array $tokens Array of tokens
@param int $returnPos Stack position of the T_RETURN token to process
@return boolean True if the return does not return anything | [
"Is",
"the",
"return",
"statement",
"matching?"
] | 19cb6f30babb2cf6285967e67f14d1cb9c8c09f5 | https://github.com/djoos/Symfony-coding-standard/blob/19cb6f30babb2cf6285967e67f14d1cb9c8c09f5/Symfony/Sniffs/Commenting/FunctionCommentSniff.php#L142-L149 | train |
djoos/Symfony-coding-standard | Symfony/Sniffs/Commenting/ClassCommentSniff.php | ClassCommentSniff.processTags | protected function processTags($phpcsFile, $stackPtr, $commentStart)
{
$tokens = $phpcsFile->getTokens();
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
$name = $tokens[$tag]['content'];
if (in_array($name, $this->blacklist)) {
$error = sprintf('The %s tag is not allowed.', $name);
$phpcsFile->addError($error, $tag, 'Blacklisted');
}
}
parent::processTags($phpcsFile, $stackPtr, $commentStart);
} | php | protected function processTags($phpcsFile, $stackPtr, $commentStart)
{
$tokens = $phpcsFile->getTokens();
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
$name = $tokens[$tag]['content'];
if (in_array($name, $this->blacklist)) {
$error = sprintf('The %s tag is not allowed.', $name);
$phpcsFile->addError($error, $tag, 'Blacklisted');
}
}
parent::processTags($phpcsFile, $stackPtr, $commentStart);
} | [
"protected",
"function",
"processTags",
"(",
"$",
"phpcsFile",
",",
"$",
"stackPtr",
",",
"$",
"commentStart",
")",
"{",
"$",
"tokens",
"=",
"$",
"phpcsFile",
"->",
"getTokens",
"(",
")",
";",
"foreach",
"(",
"$",
"tokens",
"[",
"$",
"commentStart",
"]",... | Processes each tag and raise an error if there are blacklisted tags.
@param File $phpcsFile The file where the token was found.
@param int $stackPtr The position of the current token
in the stack passed in $tokens.
@param int $commentStart Position in the stack where the comment started.
@return void | [
"Processes",
"each",
"tag",
"and",
"raise",
"an",
"error",
"if",
"there",
"are",
"blacklisted",
"tags",
"."
] | 19cb6f30babb2cf6285967e67f14d1cb9c8c09f5 | https://github.com/djoos/Symfony-coding-standard/blob/19cb6f30babb2cf6285967e67f14d1cb9c8c09f5/Symfony/Sniffs/Commenting/ClassCommentSniff.php#L117-L131 | train |
adminarchitect/core | src/Providers/Handlers/PasswordsManager.php | PasswordsManager.isAdminArea | protected function isAdminArea(RouteMatched $event)
{
if ($action = $event->route->getAction()) {
return config('administrator.prefix') === array_get($action, 'prefix');
}
return false;
} | php | protected function isAdminArea(RouteMatched $event)
{
if ($action = $event->route->getAction()) {
return config('administrator.prefix') === array_get($action, 'prefix');
}
return false;
} | [
"protected",
"function",
"isAdminArea",
"(",
"RouteMatched",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"action",
"=",
"$",
"event",
"->",
"route",
"->",
"getAction",
"(",
")",
")",
"{",
"return",
"config",
"(",
"'administrator.prefix'",
")",
"===",
"array_ge... | Check if running under admin area.
@param RouteMatched $event
@return bool | [
"Check",
"if",
"running",
"under",
"admin",
"area",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Providers/Handlers/PasswordsManager.php#L54-L61 | train |
adminarchitect/core | src/Services/Saver.php | Saver.sync | public function sync()
{
$this->connection()->transaction(function () {
foreach ($this->editable() as $field) {
// get original HTML input
$field = $field->getInput();
$name = $field->getName();
if ($this->isKey($field) || $this->isTranslatable($field) || $this->isMediaFile($field)) {
continue;
}
$this->collectRelations($field, $name);
$value = $this->isFile($field) ? $this->request->file($name) : $this->request->get($name);
$value = $this->isBoolean($field) ? (bool) $value : $value;
$value = $this->handleJsonType($name, $value);
$this->data[$name] = $value;
}
$this->cleanData();
$this->collectTranslatable();
$this->appendTranslationsToRelations();
Model::unguard();
/*
|-------------------------------------------------------
| Save main data
|-------------------------------------------------------
*/
$this->save();
/*
|-------------------------------------------------------
| Relationships
|-------------------------------------------------------
| Save related data, fetched by "relation" from related tables
*/
$this->saveRelations();
$this->saveMedia();
Model::reguard();
});
return $this->repository;
} | php | public function sync()
{
$this->connection()->transaction(function () {
foreach ($this->editable() as $field) {
// get original HTML input
$field = $field->getInput();
$name = $field->getName();
if ($this->isKey($field) || $this->isTranslatable($field) || $this->isMediaFile($field)) {
continue;
}
$this->collectRelations($field, $name);
$value = $this->isFile($field) ? $this->request->file($name) : $this->request->get($name);
$value = $this->isBoolean($field) ? (bool) $value : $value;
$value = $this->handleJsonType($name, $value);
$this->data[$name] = $value;
}
$this->cleanData();
$this->collectTranslatable();
$this->appendTranslationsToRelations();
Model::unguard();
/*
|-------------------------------------------------------
| Save main data
|-------------------------------------------------------
*/
$this->save();
/*
|-------------------------------------------------------
| Relationships
|-------------------------------------------------------
| Save related data, fetched by "relation" from related tables
*/
$this->saveRelations();
$this->saveMedia();
Model::reguard();
});
return $this->repository;
} | [
"public",
"function",
"sync",
"(",
")",
"{",
"$",
"this",
"->",
"connection",
"(",
")",
"->",
"transaction",
"(",
"function",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"editable",
"(",
")",
"as",
"$",
"field",
")",
"{",
"// get original HTML in... | Process request and persist data.
@return mixed | [
"Process",
"request",
"and",
"persist",
"data",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Saver.php#L70-L123 | train |
adminarchitect/core | src/Services/Saver.php | Saver.cleanData | protected function cleanData()
{
$this->data = array_except($this->data, [
'_token',
'save',
'save_create',
'save_return',
$this->repository->getKeyName(),
]);
// leave only fillable columns
$this->data = array_only($this->data, $this->repository->getFillable());
} | php | protected function cleanData()
{
$this->data = array_except($this->data, [
'_token',
'save',
'save_create',
'save_return',
$this->repository->getKeyName(),
]);
// leave only fillable columns
$this->data = array_only($this->data, $this->repository->getFillable());
} | [
"protected",
"function",
"cleanData",
"(",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"array_except",
"(",
"$",
"this",
"->",
"data",
",",
"[",
"'_token'",
",",
"'save'",
",",
"'save_create'",
",",
"'save_return'",
",",
"$",
"this",
"->",
"repository",
"-... | Protect request data against external data. | [
"Protect",
"request",
"data",
"against",
"external",
"data",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Saver.php#L168-L180 | train |
adminarchitect/core | src/Services/Saver.php | Saver.forgetNullValues | protected function forgetNullValues($relation, $values)
{
$keys = explode('.', $this->getQualifiedRelatedKeyName($relation));
$key = array_pop($keys);
return array_filter((array) $values[$key], function ($value) {
return null !== $value;
});
} | php | protected function forgetNullValues($relation, $values)
{
$keys = explode('.', $this->getQualifiedRelatedKeyName($relation));
$key = array_pop($keys);
return array_filter((array) $values[$key], function ($value) {
return null !== $value;
});
} | [
"protected",
"function",
"forgetNullValues",
"(",
"$",
"relation",
",",
"$",
"values",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"this",
"->",
"getQualifiedRelatedKeyName",
"(",
"$",
"relation",
")",
")",
";",
"$",
"key",
"=",
"array_p... | Remove null values from data.
@param $relation
@param $values
@return array | [
"Remove",
"null",
"values",
"from",
"data",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Saver.php#L238-L246 | train |
adminarchitect/core | src/Services/Saver.php | Saver.collectRelations | protected function collectRelations($field, $name)
{
if ($field instanceof HasOne && $field->hasRelation()) {
$relation = $field->getRelation();
$this->relations[$relation][$name] = $this->input($name);
}
if ($field->hasRelation()) {
$relation = $field->getRelation();
// register relation
if (!array_has($this->relations, $relation)) {
$this->relations[$relation] = [];
}
if (!$field->getTranslatable()) {
$this->relations[$relation][$name] = $this->input("{$relation}.{$name}");
}
}
} | php | protected function collectRelations($field, $name)
{
if ($field instanceof HasOne && $field->hasRelation()) {
$relation = $field->getRelation();
$this->relations[$relation][$name] = $this->input($name);
}
if ($field->hasRelation()) {
$relation = $field->getRelation();
// register relation
if (!array_has($this->relations, $relation)) {
$this->relations[$relation] = [];
}
if (!$field->getTranslatable()) {
$this->relations[$relation][$name] = $this->input("{$relation}.{$name}");
}
}
} | [
"protected",
"function",
"collectRelations",
"(",
"$",
"field",
",",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"field",
"instanceof",
"HasOne",
"&&",
"$",
"field",
"->",
"hasRelation",
"(",
")",
")",
"{",
"$",
"relation",
"=",
"$",
"field",
"->",
"getRela... | Collect relations for saving.
@param $field
@param $name | [
"Collect",
"relations",
"for",
"saving",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Saver.php#L254-L273 | train |
adminarchitect/core | src/Services/Saver.php | Saver.collectTranslatable | protected function collectTranslatable()
{
foreach ($this->request->get('translatable', []) as $key => $value) {
$this->data[$key] = $value;
}
} | php | protected function collectTranslatable()
{
foreach ($this->request->get('translatable', []) as $key => $value) {
$this->data[$key] = $value;
}
} | [
"protected",
"function",
"collectTranslatable",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"request",
"->",
"get",
"(",
"'translatable'",
",",
"[",
"]",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
... | Collect translations. | [
"Collect",
"translations",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Saver.php#L309-L314 | train |
adminarchitect/core | src/Services/Saver.php | Saver.nullifyEmptyNullables | protected function nullifyEmptyNullables($table)
{
$columns = scheme()->columns($table);
foreach ($this->data as $key => &$value) {
if (!array_key_exists($key, $columns)) {
continue;
}
if (!$columns[$key]->getNotnull() && empty($value)) {
$value = null;
}
}
} | php | protected function nullifyEmptyNullables($table)
{
$columns = scheme()->columns($table);
foreach ($this->data as $key => &$value) {
if (!array_key_exists($key, $columns)) {
continue;
}
if (!$columns[$key]->getNotnull() && empty($value)) {
$value = null;
}
}
} | [
"protected",
"function",
"nullifyEmptyNullables",
"(",
"$",
"table",
")",
"{",
"$",
"columns",
"=",
"scheme",
"(",
")",
"->",
"columns",
"(",
"$",
"table",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
"=>",
"&",
"$",
"value"... | Set empty "nullable" values to null.
@param $table | [
"Set",
"empty",
"nullable",
"values",
"to",
"null",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Saver.php#L344-L357 | train |
adminarchitect/core | src/Scaffolding.php | Scaffolding.template | public function template()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Templates'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('template')) {
return $value;
}
return $this->template;
} | php | public function template()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Templates'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('template')) {
return $value;
}
return $this->template;
} | [
"public",
"function",
"template",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getQualifiedClassNameOfType",
"(",
"'Templates'",
")",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"if",
"(",
"list",
"(",
"/*$fl... | The module Templates manager.
@return string | [
"The",
"module",
"Templates",
"manager",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Scaffolding.php#L164-L175 | train |
adminarchitect/core | src/Scaffolding.php | Scaffolding.finder | public function finder()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Finders'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('finder')) {
return $value;
}
return $this->finder;
} | php | public function finder()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Finders'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('finder')) {
return $value;
}
return $this->finder;
} | [
"public",
"function",
"finder",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getQualifiedClassNameOfType",
"(",
"'Finders'",
")",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"if",
"(",
"list",
"(",
"/*$flag*/... | Define the class responsive for fetching items.
@return mixed | [
"Define",
"the",
"class",
"responsive",
"for",
"fetching",
"items",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Scaffolding.php#L196-L207 | train |
adminarchitect/core | src/Scaffolding.php | Scaffolding.saver | public function saver()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Savers'))) {
return $file;
}
if (list(/*$flag*/, $saver) = $this->hasCommentFlag('saver')) {
return $saver;
}
return $this->saver;
} | php | public function saver()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Savers'))) {
return $file;
}
if (list(/*$flag*/, $saver) = $this->hasCommentFlag('saver')) {
return $saver;
}
return $this->saver;
} | [
"public",
"function",
"saver",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getQualifiedClassNameOfType",
"(",
"'Savers'",
")",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"if",
"(",
"list",
"(",
"/*$flag*/",... | Define the class responsive for persisting items.
@return mixed | [
"Define",
"the",
"class",
"responsive",
"for",
"persisting",
"items",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Scaffolding.php#L214-L225 | train |
adminarchitect/core | src/Scaffolding.php | Scaffolding.breadcrumbs | public function breadcrumbs()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Breadcrumbs'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('breadcrumbs')) {
return $value;
}
return $this->breadcrumbs;
} | php | public function breadcrumbs()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Breadcrumbs'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('breadcrumbs')) {
return $value;
}
return $this->breadcrumbs;
} | [
"public",
"function",
"breadcrumbs",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getQualifiedClassNameOfType",
"(",
"'Breadcrumbs'",
")",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"if",
"(",
"list",
"(",
"... | Breadcrumbs provider
First parse Module doc block for provider declaration.
@return mixed | [
"Breadcrumbs",
"provider",
"First",
"parse",
"Module",
"doc",
"block",
"for",
"provider",
"declaration",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Scaffolding.php#L233-L244 | train |
adminarchitect/core | src/Scaffolding.php | Scaffolding.actions | public function actions()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Actions'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('actions')) {
return $value;
}
return $this->actions;
} | php | public function actions()
{
if (class_exists($file = $this->getQualifiedClassNameOfType('Actions'))) {
return $file;
}
if (list(/*$flag*/, $value) = $this->hasCommentFlag('actions')) {
return $value;
}
return $this->actions;
} | [
"public",
"function",
"actions",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getQualifiedClassNameOfType",
"(",
"'Actions'",
")",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"if",
"(",
"list",
"(",
"/*$flag*... | Define the Actions provider - object responsive for
CRUD operations, Export, etc...
as like as checks action permissions.
@return mixed | [
"Define",
"the",
"Actions",
"provider",
"-",
"object",
"responsive",
"for",
"CRUD",
"operations",
"Export",
"etc",
"...",
"as",
"like",
"as",
"checks",
"action",
"permissions",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Scaffolding.php#L253-L264 | train |
adminarchitect/core | src/Filter.php | Filter.setFilters | public function setFilters(Mutable $filters = null)
{
if ($filters) {
$filters = $filters->map(function ($element) {
if ($this->request->has($id = $element->id())) {
$element->getInput()->setValue(
$this->request->get($id)
);
}
return $element;
});
}
$this->filters = $filters;
return $this;
} | php | public function setFilters(Mutable $filters = null)
{
if ($filters) {
$filters = $filters->map(function ($element) {
if ($this->request->has($id = $element->id())) {
$element->getInput()->setValue(
$this->request->get($id)
);
}
return $element;
});
}
$this->filters = $filters;
return $this;
} | [
"public",
"function",
"setFilters",
"(",
"Mutable",
"$",
"filters",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"filters",
")",
"{",
"$",
"filters",
"=",
"$",
"filters",
"->",
"map",
"(",
"function",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"this"... | Set collection of filters.
@param null|Mutable $filters
@return mixed|void | [
"Set",
"collection",
"of",
"filters",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Filter.php#L55-L72 | train |
adminarchitect/core | src/Filter.php | Filter.setScopes | public function setScopes(Mutable $scopes = null)
{
if ($scopes && $scopes->count()) {
$scopes->prepend(
new Scope('all')
);
}
$this->scopes = $scopes;
return $this;
} | php | public function setScopes(Mutable $scopes = null)
{
if ($scopes && $scopes->count()) {
$scopes->prepend(
new Scope('all')
);
}
$this->scopes = $scopes;
return $this;
} | [
"public",
"function",
"setScopes",
"(",
"Mutable",
"$",
"scopes",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"scopes",
"&&",
"$",
"scopes",
"->",
"count",
"(",
")",
")",
"{",
"$",
"scopes",
"->",
"prepend",
"(",
"new",
"Scope",
"(",
"'all'",
")",
")",
... | Set scopes.
@param Mutable $scopes
@return $this | [
"Set",
"scopes",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Filter.php#L81-L92 | train |
adminarchitect/core | src/Filter.php | Filter.has | public function has($name)
{
foreach ($this->filters() as $filter) {
if ($filter->id() === $name) {
return true;
}
}
return false;
} | php | public function has($name)
{
foreach ($this->filters() as $filter) {
if ($filter->id() === $name) {
return true;
}
}
return false;
} | [
"public",
"function",
"has",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"(",
")",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"filter",
"->",
"id",
"(",
")",
"===",
"$",
"name",
")",
"{",
"return",
"true",
";",... | Check if filter has element with name.
@param $name
@return bool | [
"Check",
"if",
"filter",
"has",
"element",
"with",
"name",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Filter.php#L146-L155 | train |
adminarchitect/core | src/Columns/Element.php | Element.sortable | public function sortable(\Closure $callback = null)
{
return tap($this, function ($element) use ($callback) {
app('scaffold.module')->addSortable(
$element->id(),
$callback
);
});
} | php | public function sortable(\Closure $callback = null)
{
return tap($this, function ($element) use ($callback) {
app('scaffold.module')->addSortable(
$element->id(),
$callback
);
});
} | [
"public",
"function",
"sortable",
"(",
"\\",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"return",
"tap",
"(",
"$",
"this",
",",
"function",
"(",
"$",
"element",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"app",
"(",
"'scaffold.module'",
")",
... | Make column sortable.
@param null|\Closure $callback
@return $this | [
"Make",
"column",
"sortable",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Columns/Element.php#L129-L137 | train |
adminarchitect/core | src/Columns/Element.php | Element.fetchValue | protected function fetchValue($eloquent)
{
$id = $this->id();
// Treat (Has)Many(ToMany|Through) relations as "count()" subQuery.
if (($relation = $this->hasRelation($eloquent, $id)) && $this->isCountableRelation($relation)) {
return $this->fetchRelationValue($eloquent, $id, [$id => $relation], true);
}
if ($this->relations) {
return $this->fetchRelationValue($eloquent, $id, $this->relations, true);
}
return \admin\helpers\eloquent_attribute($eloquent, $id);
} | php | protected function fetchValue($eloquent)
{
$id = $this->id();
// Treat (Has)Many(ToMany|Through) relations as "count()" subQuery.
if (($relation = $this->hasRelation($eloquent, $id)) && $this->isCountableRelation($relation)) {
return $this->fetchRelationValue($eloquent, $id, [$id => $relation], true);
}
if ($this->relations) {
return $this->fetchRelationValue($eloquent, $id, $this->relations, true);
}
return \admin\helpers\eloquent_attribute($eloquent, $id);
} | [
"protected",
"function",
"fetchValue",
"(",
"$",
"eloquent",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"id",
"(",
")",
";",
"// Treat (Has)Many(ToMany|Through) relations as \"count()\" subQuery.",
"if",
"(",
"(",
"$",
"relation",
"=",
"$",
"this",
"->",
"ha... | Fetch element value from eloquent.
@param $eloquent
@return mixed | [
"Fetch",
"element",
"value",
"from",
"eloquent",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Columns/Element.php#L158-L172 | train |
adminarchitect/core | src/Dashboard/Panels/GoogleAnalyticsPanel.php | GoogleAnalyticsPanel.fakeData | protected function fakeData($period)
{
$data = collect([]);
for ($date = Carbon::parse($period->startDate); $date->lte($period->endDate); $date->addDay()) {
$data->push([
'date' => Carbon::parse($date),
'visitors' => rand(100, 1000),
'pageViews' => rand(100, 1000),
]);
}
return $data;
} | php | protected function fakeData($period)
{
$data = collect([]);
for ($date = Carbon::parse($period->startDate); $date->lte($period->endDate); $date->addDay()) {
$data->push([
'date' => Carbon::parse($date),
'visitors' => rand(100, 1000),
'pageViews' => rand(100, 1000),
]);
}
return $data;
} | [
"protected",
"function",
"fakeData",
"(",
"$",
"period",
")",
"{",
"$",
"data",
"=",
"collect",
"(",
"[",
"]",
")",
";",
"for",
"(",
"$",
"date",
"=",
"Carbon",
"::",
"parse",
"(",
"$",
"period",
"->",
"startDate",
")",
";",
"$",
"date",
"->",
"l... | Provide fake analytics data for demo purposes.
@param $period
@return \Illuminate\Support\Collection | [
"Provide",
"fake",
"analytics",
"data",
"for",
"demo",
"purposes",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Dashboard/Panels/GoogleAnalyticsPanel.php#L113-L126 | train |
adminarchitect/core | src/Form/Type/Media.php | Media.render | public function render()
{
$media = $this->getRepository()->getMedia(
$name = $this->getFormName()
)->map(function ($item) {
return array_merge($item->toArray(), [
'url' => $item->getUrl(),
'conversions' => $this->conversions($item),
]);
});
return view('administrator::edit.controls.media', [
'name' => $name,
'media' => $media->toJson(),
'arrows' => $this->arrows,
'indicators' => $this->indicators,
'width' => $this->width,
'conversion' => $this->conversion,
'editable' => $this->editable,
]);
} | php | public function render()
{
$media = $this->getRepository()->getMedia(
$name = $this->getFormName()
)->map(function ($item) {
return array_merge($item->toArray(), [
'url' => $item->getUrl(),
'conversions' => $this->conversions($item),
]);
});
return view('administrator::edit.controls.media', [
'name' => $name,
'media' => $media->toJson(),
'arrows' => $this->arrows,
'indicators' => $this->indicators,
'width' => $this->width,
'conversion' => $this->conversion,
'editable' => $this->editable,
]);
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"media",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getMedia",
"(",
"$",
"name",
"=",
"$",
"this",
"->",
"getFormName",
"(",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item"... | Each subclass should have this method realized.
@return mixed | [
"Each",
"subclass",
"should",
"have",
"this",
"method",
"realized",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Form/Type/Media.php#L18-L38 | train |
adminarchitect/core | src/Actions/Collection.php | Collection.find | public function find($name)
{
return $this->first(function ($action) use ($name) {
return class_basename($action) === studly_case($name);
});
} | php | public function find($name)
{
return $this->first(function ($action) use ($name) {
return class_basename($action) === studly_case($name);
});
} | [
"public",
"function",
"find",
"(",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"first",
"(",
"function",
"(",
"$",
"action",
")",
"use",
"(",
"$",
"name",
")",
"{",
"return",
"class_basename",
"(",
"$",
"action",
")",
"===",
"studly_case",
"(... | Find action by name.
@param $name
@return mixed | [
"Find",
"action",
"by",
"name",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Actions/Collection.php#L30-L35 | train |
adminarchitect/core | src/Schema.php | Schema.indexedColumns | public function indexedColumns($table)
{
return Cache::remember("{$table}_indexed_columns", $this->lifetime(), function () use ($table) {
$indexedColumns = array_reduce($this->indexes($table), function ($indexedColumns, $index) {
return array_merge($indexedColumns, $index->getColumns());
}, []);
return array_unique($indexedColumns);
});
} | php | public function indexedColumns($table)
{
return Cache::remember("{$table}_indexed_columns", $this->lifetime(), function () use ($table) {
$indexedColumns = array_reduce($this->indexes($table), function ($indexedColumns, $index) {
return array_merge($indexedColumns, $index->getColumns());
}, []);
return array_unique($indexedColumns);
});
} | [
"public",
"function",
"indexedColumns",
"(",
"$",
"table",
")",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"\"{$table}_indexed_columns\"",
",",
"$",
"this",
"->",
"lifetime",
"(",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"table",
")",
"{",
"$... | Get list of indexed columns.
@param $table
@return array | [
"Get",
"list",
"of",
"indexed",
"columns",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Schema.php#L29-L38 | train |
adminarchitect/core | src/Schema.php | Schema.indexes | public function indexes($table)
{
return Cache::remember("{$table}_indexes", $this->lifetime(), function () use ($table) {
return $this->manager->listTableIndexes($table);
});
} | php | public function indexes($table)
{
return Cache::remember("{$table}_indexes", $this->lifetime(), function () use ($table) {
return $this->manager->listTableIndexes($table);
});
} | [
"public",
"function",
"indexes",
"(",
"$",
"table",
")",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"\"{$table}_indexes\"",
",",
"$",
"this",
"->",
"lifetime",
"(",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"table",
")",
"{",
"return",
"$",
... | List table indexes.
@param $table
@return \Doctrine\DBAL\Schema\Index[] | [
"List",
"table",
"indexes",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Schema.php#L47-L52 | train |
adminarchitect/core | src/Schema.php | Schema.columns | public function columns($table)
{
return Cache::remember("{$table}_columns", $this->lifetime(), function () use ($table) {
$columns = $this->manager->listTableColumns($table);
$keys = array_keys($columns);
$vals = array_values($columns);
$keys = array_map(function ($key) {
return trim(str_replace(['`', '"'], '', $key));
}, $keys);
return array_combine($keys, $vals);
});
} | php | public function columns($table)
{
return Cache::remember("{$table}_columns", $this->lifetime(), function () use ($table) {
$columns = $this->manager->listTableColumns($table);
$keys = array_keys($columns);
$vals = array_values($columns);
$keys = array_map(function ($key) {
return trim(str_replace(['`', '"'], '', $key));
}, $keys);
return array_combine($keys, $vals);
});
} | [
"public",
"function",
"columns",
"(",
"$",
"table",
")",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"\"{$table}_columns\"",
",",
"$",
"this",
"->",
"lifetime",
"(",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"table",
")",
"{",
"$",
"columns",... | List table columns.
@param $table
@return \Doctrine\DBAL\Schema\Column[] | [
"List",
"table",
"columns",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Schema.php#L61-L74 | train |
adminarchitect/core | src/Schema.php | Schema.foreignKeys | public function foreignKeys($table)
{
return Cache::remember("{$table}_foreign_keys", $this->lifetime(), function () use ($table) {
return $this->manager->listTableForeignKeys($table);
});
} | php | public function foreignKeys($table)
{
return Cache::remember("{$table}_foreign_keys", $this->lifetime(), function () use ($table) {
return $this->manager->listTableForeignKeys($table);
});
} | [
"public",
"function",
"foreignKeys",
"(",
"$",
"table",
")",
"{",
"return",
"Cache",
"::",
"remember",
"(",
"\"{$table}_foreign_keys\"",
",",
"$",
"this",
"->",
"lifetime",
"(",
")",
",",
"function",
"(",
")",
"use",
"(",
"$",
"table",
")",
"{",
"return"... | list table foreign keys.
@param $table
@return mixed | [
"list",
"table",
"foreign",
"keys",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Schema.php#L83-L88 | train |
adminarchitect/core | src/Traits/ExportsCollection.php | ExportsCollection.export | public function export(Builder $query, $format)
{
$method = 'to'.strtoupper($format);
if (method_exists($this, $method)) {
return call_user_func_array([$this, $method], [$query]);
}
if (method_exists($this->module, $method)) {
return call_user_func_array([$this->module, $method], [$query]);
}
throw new Exception(sprintf('Don\'t know how to export to %s format.', $format));
} | php | public function export(Builder $query, $format)
{
$method = 'to'.strtoupper($format);
if (method_exists($this, $method)) {
return call_user_func_array([$this, $method], [$query]);
}
if (method_exists($this->module, $method)) {
return call_user_func_array([$this->module, $method], [$query]);
}
throw new Exception(sprintf('Don\'t know how to export to %s format.', $format));
} | [
"public",
"function",
"export",
"(",
"Builder",
"$",
"query",
",",
"$",
"format",
")",
"{",
"$",
"method",
"=",
"'to'",
".",
"strtoupper",
"(",
"$",
"format",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{"... | Export collection to a specific format.
@param Builder $query
@param $format
@return mixed
@throws Exception | [
"Export",
"collection",
"to",
"a",
"specific",
"format",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ExportsCollection.php#L25-L38 | train |
adminarchitect/core | src/Traits/ExportsCollection.php | ExportsCollection.toJSON | public function toJSON(Builder $query)
{
file_put_contents(
$file = $this->getFilename(),
json_encode($this->exportableQuery($query)->get())
);
return $this->sendDownloadResponse($file, 'json', ['Content-Type' => 'application/json']);
} | php | public function toJSON(Builder $query)
{
file_put_contents(
$file = $this->getFilename(),
json_encode($this->exportableQuery($query)->get())
);
return $this->sendDownloadResponse($file, 'json', ['Content-Type' => 'application/json']);
} | [
"public",
"function",
"toJSON",
"(",
"Builder",
"$",
"query",
")",
"{",
"file_put_contents",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getFilename",
"(",
")",
",",
"json_encode",
"(",
"$",
"this",
"->",
"exportableQuery",
"(",
"$",
"query",
")",
"->",
... | Convert & download collection in JSON format.
@param $query
@return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response | [
"Convert",
"&",
"download",
"collection",
"in",
"JSON",
"format",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ExportsCollection.php#L47-L55 | train |
adminarchitect/core | src/Traits/ExportsCollection.php | ExportsCollection.toXML | public function toXML(Builder $query)
{
$root = with($dom = new DOMDocument())->createElement('root');
foreach ($this->each($query) as $object) {
$item = $dom->createElement('item');
foreach ($this->toScalar($object) as $column => $value) {
$column = $dom->createElement($column, htmlspecialchars($value));
$item->appendChild($column);
}
$root->appendChild($item);
}
$dom->appendChild($root);
file_put_contents(
$file = $this->getFilename(),
$dom->saveXML()
);
return $this->sendDownloadResponse($file, 'xml', ['Content-Type' => 'text/xml']);
} | php | public function toXML(Builder $query)
{
$root = with($dom = new DOMDocument())->createElement('root');
foreach ($this->each($query) as $object) {
$item = $dom->createElement('item');
foreach ($this->toScalar($object) as $column => $value) {
$column = $dom->createElement($column, htmlspecialchars($value));
$item->appendChild($column);
}
$root->appendChild($item);
}
$dom->appendChild($root);
file_put_contents(
$file = $this->getFilename(),
$dom->saveXML()
);
return $this->sendDownloadResponse($file, 'xml', ['Content-Type' => 'text/xml']);
} | [
"public",
"function",
"toXML",
"(",
"Builder",
"$",
"query",
")",
"{",
"$",
"root",
"=",
"with",
"(",
"$",
"dom",
"=",
"new",
"DOMDocument",
"(",
")",
")",
"->",
"createElement",
"(",
"'root'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"each",
"... | Convert & download collection in XML format.
@param $query
@return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response | [
"Convert",
"&",
"download",
"collection",
"in",
"XML",
"format",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ExportsCollection.php#L64-L87 | train |
adminarchitect/core | src/Traits/ExportsCollection.php | ExportsCollection.toCSV | public function toCSV(Builder $query)
{
$out = fopen(
$file = $this->getFilename(),
'a+'
);
$headersPrinted = false;
foreach ($this->each($query, 100) as $item) {
$data = $this->toScalar($item);
if (!$headersPrinted) {
fputcsv($out, array_keys($data));
$headersPrinted = true;
}
fputcsv($out, $data);
}
fclose($out);
return $this->sendDownloadResponse($file, 'csv', ['Content-Type' => 'text/csv']);
} | php | public function toCSV(Builder $query)
{
$out = fopen(
$file = $this->getFilename(),
'a+'
);
$headersPrinted = false;
foreach ($this->each($query, 100) as $item) {
$data = $this->toScalar($item);
if (!$headersPrinted) {
fputcsv($out, array_keys($data));
$headersPrinted = true;
}
fputcsv($out, $data);
}
fclose($out);
return $this->sendDownloadResponse($file, 'csv', ['Content-Type' => 'text/csv']);
} | [
"public",
"function",
"toCSV",
"(",
"Builder",
"$",
"query",
")",
"{",
"$",
"out",
"=",
"fopen",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getFilename",
"(",
")",
",",
"'a+'",
")",
";",
"$",
"headersPrinted",
"=",
"false",
";",
"foreach",
"(",
"$"... | Convert & download collection in CSV format.
@param $query
@return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response | [
"Convert",
"&",
"download",
"collection",
"in",
"CSV",
"format",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ExportsCollection.php#L96-L117 | train |
adminarchitect/core | src/Traits/ExportsCollection.php | ExportsCollection.exportableQuery | protected function exportableQuery(Builder $query): Builder
{
// Allow executing custom exportable query.
if (method_exists($this->module, 'exportableQuery')) {
return $this->module->exportableQuery($query);
}
return $query
->when($query->getModel() instanceof Translatable, function ($query) {
$query->translated();
})
// leave select after joining with translations
// table in order to rewrite selected columns
->select($this->exportableColumns());
} | php | protected function exportableQuery(Builder $query): Builder
{
// Allow executing custom exportable query.
if (method_exists($this->module, 'exportableQuery')) {
return $this->module->exportableQuery($query);
}
return $query
->when($query->getModel() instanceof Translatable, function ($query) {
$query->translated();
})
// leave select after joining with translations
// table in order to rewrite selected columns
->select($this->exportableColumns());
} | [
"protected",
"function",
"exportableQuery",
"(",
"Builder",
"$",
"query",
")",
":",
"Builder",
"{",
"// Allow executing custom exportable query.",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"module",
",",
"'exportableQuery'",
")",
")",
"{",
"return",
"$",... | Fetch exportable items by query.
@param Builder $query
@return Builder | [
"Fetch",
"exportable",
"items",
"by",
"query",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ExportsCollection.php#L157-L171 | train |
adminarchitect/core | src/Traits/ExportsCollection.php | ExportsCollection.each | protected function each(Builder $query, $count = 100): Generator
{
$query = $this->exportableQuery($query);
// enforce order by statement.
if (empty($query->orders) && empty($query->unionOrders)) {
$query->orderBy($query->getModel()->getQualifiedKeyName(), 'asc');
}
$page = 1;
do {
// We'll execute the query for the given page and get the results. If there are
// no results we can just break and return from here. When there are results
// we will call the callback with the current chunk of these results here.
$results = $query->forPage($page, $count)->get();
$countResults = $results->count();
if (0 === $countResults) {
break;
}
// On each chunk result set, we will pass them to the callback and then let the
// developer take care of everything within the callback, which allows us to
// keep the memory low for spinning through large result sets for working.
foreach ($results as $index => $item) {
yield $index = $item;
}
unset($results);
++$page;
} while ($countResults === $count);
} | php | protected function each(Builder $query, $count = 100): Generator
{
$query = $this->exportableQuery($query);
// enforce order by statement.
if (empty($query->orders) && empty($query->unionOrders)) {
$query->orderBy($query->getModel()->getQualifiedKeyName(), 'asc');
}
$page = 1;
do {
// We'll execute the query for the given page and get the results. If there are
// no results we can just break and return from here. When there are results
// we will call the callback with the current chunk of these results here.
$results = $query->forPage($page, $count)->get();
$countResults = $results->count();
if (0 === $countResults) {
break;
}
// On each chunk result set, we will pass them to the callback and then let the
// developer take care of everything within the callback, which allows us to
// keep the memory low for spinning through large result sets for working.
foreach ($results as $index => $item) {
yield $index = $item;
}
unset($results);
++$page;
} while ($countResults === $count);
} | [
"protected",
"function",
"each",
"(",
"Builder",
"$",
"query",
",",
"$",
"count",
"=",
"100",
")",
":",
"Generator",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"exportableQuery",
"(",
"$",
"query",
")",
";",
"// enforce order by statement.",
"if",
"(",
"... | Creates a all items generator.
@param Builder $query
@param int $count
@return Generator | [
"Creates",
"a",
"all",
"items",
"generator",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ExportsCollection.php#L217-L251 | train |
adminarchitect/core | src/Traits/ExportsCollection.php | ExportsCollection.exportableColumns | protected function exportableColumns(): array
{
if (method_exists($this->module, 'exportableColumns')) {
return $this->module->exportableColumns();
}
/**
* @var Model
*/
$model = $this->module->model();
return collect($model->getFillable())
->prepend('id')
->diff($model->getHidden())
->map(function ($column) use ($model) {
return "{$model->getTable()}.{$column}";
})
->when($model instanceof Translatable, function (Collection $collection) use ($model) {
return $collection->merge(
collect($model->getTranslatedAttributes())
->map(function ($column) use ($model) {
return "tt.{$column}";
})
);
})
->all();
} | php | protected function exportableColumns(): array
{
if (method_exists($this->module, 'exportableColumns')) {
return $this->module->exportableColumns();
}
/**
* @var Model
*/
$model = $this->module->model();
return collect($model->getFillable())
->prepend('id')
->diff($model->getHidden())
->map(function ($column) use ($model) {
return "{$model->getTable()}.{$column}";
})
->when($model instanceof Translatable, function (Collection $collection) use ($model) {
return $collection->merge(
collect($model->getTranslatedAttributes())
->map(function ($column) use ($model) {
return "tt.{$column}";
})
);
})
->all();
} | [
"protected",
"function",
"exportableColumns",
"(",
")",
":",
"array",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"module",
",",
"'exportableColumns'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"module",
"->",
"exportableColumns",
"(",
")",
... | Generate a list of exportable columns.
@return array | [
"Generate",
"a",
"list",
"of",
"exportable",
"columns",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ExportsCollection.php#L258-L284 | train |
adminarchitect/core | src/Services/Translations/Reader.php | Reader.read | public function read(Collection $files, Collection $locales)
{
return $locales->reduce(function ($translations, $locale) use ($files) {
$files->each(function ($file) use ($locale, &$translations) {
if (file_exists($path = $this->pathToFile($file, $locale))) {
$content[$file] = include_once $path;
foreach (array_dot($content) as $key => $value) {
$translations[$key][$locale->iso6391()] = $value ? $value : '';
}
}
});
return $translations;
}, []);
} | php | public function read(Collection $files, Collection $locales)
{
return $locales->reduce(function ($translations, $locale) use ($files) {
$files->each(function ($file) use ($locale, &$translations) {
if (file_exists($path = $this->pathToFile($file, $locale))) {
$content[$file] = include_once $path;
foreach (array_dot($content) as $key => $value) {
$translations[$key][$locale->iso6391()] = $value ? $value : '';
}
}
});
return $translations;
}, []);
} | [
"public",
"function",
"read",
"(",
"Collection",
"$",
"files",
",",
"Collection",
"$",
"locales",
")",
"{",
"return",
"$",
"locales",
"->",
"reduce",
"(",
"function",
"(",
"$",
"translations",
",",
"$",
"locale",
")",
"use",
"(",
"$",
"files",
")",
"{"... | Reads the translation file's contents.
@param Collection $files
@param Collection $locales
@return mixed | [
"Reads",
"the",
"translation",
"file",
"s",
"contents",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Translations/Reader.php#L18-L33 | train |
adminarchitect/core | src/Services/Translations/Reader.php | Reader.pathToFile | public function pathToFile($file, $locale): string
{
return resource_path('lang'.DIRECTORY_SEPARATOR.(is_a($locale, Locale::class) ? $locale->iso6391() : $locale).DIRECTORY_SEPARATOR.$file.'.php');
} | php | public function pathToFile($file, $locale): string
{
return resource_path('lang'.DIRECTORY_SEPARATOR.(is_a($locale, Locale::class) ? $locale->iso6391() : $locale).DIRECTORY_SEPARATOR.$file.'.php');
} | [
"public",
"function",
"pathToFile",
"(",
"$",
"file",
",",
"$",
"locale",
")",
":",
"string",
"{",
"return",
"resource_path",
"(",
"'lang'",
".",
"DIRECTORY_SEPARATOR",
".",
"(",
"is_a",
"(",
"$",
"locale",
",",
"Locale",
"::",
"class",
")",
"?",
"$",
... | Retrieves the real path to a translation file.
@param $file
@param $locale
@return string | [
"Retrieves",
"the",
"real",
"path",
"to",
"a",
"translation",
"file",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Translations/Reader.php#L43-L46 | train |
adminarchitect/core | src/ActionsManager.php | ActionsManager.readonly | public function readonly()
{
if (null === $this->readonly) {
$this->readonly = false;
// check for <Resource>::hideActions() method.
if (method_exists($this->module, 'readonly')) {
$this->readonly = $this->module->readonly();
}
// check for <Actions>::readonly() method.
elseif (method_exists($this->service, 'readonly')) {
$this->readonly = $this->service->readonly();
}
}
return $this->readonly;
} | php | public function readonly()
{
if (null === $this->readonly) {
$this->readonly = false;
// check for <Resource>::hideActions() method.
if (method_exists($this->module, 'readonly')) {
$this->readonly = $this->module->readonly();
}
// check for <Actions>::readonly() method.
elseif (method_exists($this->service, 'readonly')) {
$this->readonly = $this->service->readonly();
}
}
return $this->readonly;
} | [
"public",
"function",
"readonly",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"readonly",
")",
"{",
"$",
"this",
"->",
"readonly",
"=",
"false",
";",
"// check for <Resource>::hideActions() method.",
"if",
"(",
"method_exists",
"(",
"$",
"thi... | check if resource has no Actions at all. | [
"check",
"if",
"resource",
"has",
"no",
"Actions",
"at",
"all",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/ActionsManager.php#L93-L110 | train |
adminarchitect/core | src/ActionsManager.php | ActionsManager.exec | public function exec($method, array $arguments = [])
{
// execute custom action
if (starts_with($method, 'action::')) {
$handler = $this->scaffoldActions()->find(
str_replace('action::', '', $method)
);
return call_user_func_array([$handler, 'handle'], $arguments);
}
// Execute batch action
if (starts_with($method, 'batch::')) {
$handler = $this->scaffoldBatch()->find(
str_replace('batch::', '', $method)
);
return call_user_func_array([$handler, 'handle'], $arguments);
}
// Execute CRUD action
return call_user_func_array([$this->service, $method], (array) $arguments);
} | php | public function exec($method, array $arguments = [])
{
// execute custom action
if (starts_with($method, 'action::')) {
$handler = $this->scaffoldActions()->find(
str_replace('action::', '', $method)
);
return call_user_func_array([$handler, 'handle'], $arguments);
}
// Execute batch action
if (starts_with($method, 'batch::')) {
$handler = $this->scaffoldBatch()->find(
str_replace('batch::', '', $method)
);
return call_user_func_array([$handler, 'handle'], $arguments);
}
// Execute CRUD action
return call_user_func_array([$this->service, $method], (array) $arguments);
} | [
"public",
"function",
"exec",
"(",
"$",
"method",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"// execute custom action",
"if",
"(",
"starts_with",
"(",
"$",
"method",
",",
"'action::'",
")",
")",
"{",
"$",
"handler",
"=",
"$",
"this",
"->... | Call handler method.
@param $method
@param array $arguments
@return mixed | [
"Call",
"handler",
"method",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/ActionsManager.php#L120-L142 | train |
adminarchitect/core | src/Traits/SortableTrait.php | SortableTrait.isSortable | public function isSortable()
{
if (property_exists($this, 'sortable')) {
return is_string($this->sortable) || is_callable($this->sortable);
}
return false;
} | php | public function isSortable()
{
if (property_exists($this, 'sortable')) {
return is_string($this->sortable) || is_callable($this->sortable);
}
return false;
} | [
"public",
"function",
"isSortable",
"(",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"'sortable'",
")",
")",
"{",
"return",
"is_string",
"(",
"$",
"this",
"->",
"sortable",
")",
"||",
"is_callable",
"(",
"$",
"this",
"->",
"sortable",
... | Is Sortable item.
@return bool | [
"Is",
"Sortable",
"item",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/SortableTrait.php#L20-L27 | train |
adminarchitect/core | src/Services/Finder.php | Finder.getQuery | public function getQuery()
{
// prevent duplicated execution
if (null === $this->query && $this->model) {
$this->initQuery()
->applyFilters()
->applySorting();
$this->query = $this->assembler()->getQuery();
}
return $this->query;
} | php | public function getQuery()
{
// prevent duplicated execution
if (null === $this->query && $this->model) {
$this->initQuery()
->applyFilters()
->applySorting();
$this->query = $this->assembler()->getQuery();
}
return $this->query;
} | [
"public",
"function",
"getQuery",
"(",
")",
"{",
"// prevent duplicated execution",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"query",
"&&",
"$",
"this",
"->",
"model",
")",
"{",
"$",
"this",
"->",
"initQuery",
"(",
")",
"->",
"applyFilters",
"(",
")"... | Build Scaffolding Index page query.
@return mixed | [
"Build",
"Scaffolding",
"Index",
"page",
"query",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Finder.php#L63-L75 | train |
adminarchitect/core | src/Services/Finder.php | Finder.find | public function find($key, $columns = ['*'])
{
$this->model = $this->model->newQueryWithoutScopes()->findOrFail($key, $columns);
return $this->model;
} | php | public function find($key, $columns = ['*'])
{
$this->model = $this->model->newQueryWithoutScopes()->findOrFail($key, $columns);
return $this->model;
} | [
"public",
"function",
"find",
"(",
"$",
"key",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"newQueryWithoutScopes",
"(",
")",
"->",
"findOrFail",
"(",
"$",
"key",
",",
"$",... | Find a record by id or fail.
@param $key
@param array $columns
@return mixed | [
"Find",
"a",
"record",
"by",
"id",
"or",
"fail",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Finder.php#L85-L90 | train |
adminarchitect/core | src/Services/Finder.php | Finder.assembler | protected function assembler()
{
if (null === $this->assembler) {
$this->assembler = (new Assembler($this->model));
}
return $this->assembler;
} | php | protected function assembler()
{
if (null === $this->assembler) {
$this->assembler = (new Assembler($this->model));
}
return $this->assembler;
} | [
"protected",
"function",
"assembler",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"assembler",
")",
"{",
"$",
"this",
"->",
"assembler",
"=",
"(",
"new",
"Assembler",
"(",
"$",
"this",
"->",
"model",
")",
")",
";",
"}",
"return",
"$... | Get the query assembler object.
@return Assembler | [
"Get",
"the",
"query",
"assembler",
"object",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Finder.php#L97-L104 | train |
adminarchitect/core | src/Services/Finder.php | Finder.removeDuplicates | protected function removeDuplicates($magnet, $filters)
{
$magnetKeys = $magnet->toArray();
foreach ($filters as $filter) {
if (array_has($magnetKeys, $filter->id())) {
unset($magnetKeys[$filter->id()]);
}
}
$class = get_class(app('scaffold.magnet'));
return new $class(app('request'), $magnetKeys);
} | php | protected function removeDuplicates($magnet, $filters)
{
$magnetKeys = $magnet->toArray();
foreach ($filters as $filter) {
if (array_has($magnetKeys, $filter->id())) {
unset($magnetKeys[$filter->id()]);
}
}
$class = get_class(app('scaffold.magnet'));
return new $class(app('request'), $magnetKeys);
} | [
"protected",
"function",
"removeDuplicates",
"(",
"$",
"magnet",
",",
"$",
"filters",
")",
"{",
"$",
"magnetKeys",
"=",
"$",
"magnet",
"->",
"toArray",
"(",
")",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"array_has"... | Solving problem then magnet params gets used for auto-filtering
even if there is another filter defined with the same name.
@param $magnet
@param $filters
@return array | [
"Solving",
"problem",
"then",
"magnet",
"params",
"gets",
"used",
"for",
"auto",
"-",
"filtering",
"even",
"if",
"there",
"is",
"another",
"filter",
"defined",
"with",
"the",
"same",
"name",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Finder.php#L151-L164 | train |
adminarchitect/core | src/Services/Finder.php | Finder.applyMagnetFilter | protected function applyMagnetFilter(MagnetParams $magnet)
{
$filters = new Administrator\Form\Collection\Mutable();
foreach ($magnet->toArray() as $key) {
$element = new FormElement($key);
$element->setInput(
InputFactory::make($key, 'text')
);
$filters->push($element);
}
$magnetFilters = new Administrator\Filter(
app('request'),
$filters
);
$this->assembler()->filters($magnetFilters->filters());
} | php | protected function applyMagnetFilter(MagnetParams $magnet)
{
$filters = new Administrator\Form\Collection\Mutable();
foreach ($magnet->toArray() as $key) {
$element = new FormElement($key);
$element->setInput(
InputFactory::make($key, 'text')
);
$filters->push($element);
}
$magnetFilters = new Administrator\Filter(
app('request'),
$filters
);
$this->assembler()->filters($magnetFilters->filters());
} | [
"protected",
"function",
"applyMagnetFilter",
"(",
"MagnetParams",
"$",
"magnet",
")",
"{",
"$",
"filters",
"=",
"new",
"Administrator",
"\\",
"Form",
"\\",
"Collection",
"\\",
"Mutable",
"(",
")",
";",
"foreach",
"(",
"$",
"magnet",
"->",
"toArray",
"(",
... | Auto-scope fetching items to magnet parameter.
@param MagnetParams $magnet | [
"Auto",
"-",
"scope",
"fetching",
"items",
"to",
"magnet",
"parameter",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Finder.php#L171-L189 | train |
adminarchitect/core | src/Services/Finder.php | Finder.applySorting | protected function applySorting()
{
$sortable = app('scaffold.sortable');
$element = $sortable->element();
$direction = $sortable->direction();
if ($element && $direction) {
if (is_string($element)) {
$this->assembler()->sort($element, $direction);
}
}
return $this;
} | php | protected function applySorting()
{
$sortable = app('scaffold.sortable');
$element = $sortable->element();
$direction = $sortable->direction();
if ($element && $direction) {
if (is_string($element)) {
$this->assembler()->sort($element, $direction);
}
}
return $this;
} | [
"protected",
"function",
"applySorting",
"(",
")",
"{",
"$",
"sortable",
"=",
"app",
"(",
"'scaffold.sortable'",
")",
";",
"$",
"element",
"=",
"$",
"sortable",
"->",
"element",
"(",
")",
";",
"$",
"direction",
"=",
"$",
"sortable",
"->",
"direction",
"(... | Extend query with Order By Statement. | [
"Extend",
"query",
"with",
"Order",
"By",
"Statement",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Finder.php#L194-L207 | train |
adminarchitect/core | src/Actions/SaveOrder.php | SaveOrder.handle | public function handle(Model $eloquent, Request $request)
{
return $eloquent->syncRanking($request->get($eloquent->getRankableColumn(), []));
} | php | public function handle(Model $eloquent, Request $request)
{
return $eloquent->syncRanking($request->get($eloquent->getRankableColumn(), []));
} | [
"public",
"function",
"handle",
"(",
"Model",
"$",
"eloquent",
",",
"Request",
"$",
"request",
")",
"{",
"return",
"$",
"eloquent",
"->",
"syncRanking",
"(",
"$",
"request",
"->",
"get",
"(",
"$",
"eloquent",
"->",
"getRankableColumn",
"(",
")",
",",
"["... | Batch update elements ranking value.
@param Model $eloquent
@param Request $request
@return mixed | [
"Batch",
"update",
"elements",
"ranking",
"value",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Actions/SaveOrder.php#L22-L25 | train |
adminarchitect/core | src/Controllers/SettingsController.php | SettingsController.update | public function update(UpdateRequest $request)
{
$this->authorize('update', $eloquent = app('scaffold.model'));
options_save(array_except(
$request->all(),
['_token', 'save']
));
return back()->with('messages', ['Settings saved successfully']);
} | php | public function update(UpdateRequest $request)
{
$this->authorize('update', $eloquent = app('scaffold.model'));
options_save(array_except(
$request->all(),
['_token', 'save']
));
return back()->with('messages', ['Settings saved successfully']);
} | [
"public",
"function",
"update",
"(",
"UpdateRequest",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'update'",
",",
"$",
"eloquent",
"=",
"app",
"(",
"'scaffold.model'",
")",
")",
";",
"options_save",
"(",
"array_except",
"(",
"$",
"reque... | Save settings per page.
@param UpdateRequest $request
@return \Illuminate\Http\RedirectResponse | [
"Save",
"settings",
"per",
"page",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Controllers/SettingsController.php#L30-L40 | train |
adminarchitect/core | publishes/Navigation.php | Navigation.makeSidebar | protected function makeSidebar()
{
$this->navigation->create(Navigable::MENU_SIDEBAR, function (MenuBuilder $sidebar) {
$sidebar->header('Main Menu');
// Dashboard
$sidebar->route('scaffold.dashboard', trans('administrator::module.dashboard'), [], 1, [
'id' => 'dashboard',
'icon' => 'fa fa-dashboard',
'active' => str_is(request()->route()->getName(), 'scaffold.dashboard'),
]);
// Create new users group
$sidebar->dropdown(trans('administrator::module.groups.users'), function (MenuItem $sub) {
$sub->route('scaffold.create', trans('administrator::buttons.create_item', ['resource' => 'User']), ['module' => 'users'], 1, []);
}, 2, ['id' => 'groups', 'icon' => 'fa fa-group']);
});
} | php | protected function makeSidebar()
{
$this->navigation->create(Navigable::MENU_SIDEBAR, function (MenuBuilder $sidebar) {
$sidebar->header('Main Menu');
// Dashboard
$sidebar->route('scaffold.dashboard', trans('administrator::module.dashboard'), [], 1, [
'id' => 'dashboard',
'icon' => 'fa fa-dashboard',
'active' => str_is(request()->route()->getName(), 'scaffold.dashboard'),
]);
// Create new users group
$sidebar->dropdown(trans('administrator::module.groups.users'), function (MenuItem $sub) {
$sub->route('scaffold.create', trans('administrator::buttons.create_item', ['resource' => 'User']), ['module' => 'users'], 1, []);
}, 2, ['id' => 'groups', 'icon' => 'fa fa-group']);
});
} | [
"protected",
"function",
"makeSidebar",
"(",
")",
"{",
"$",
"this",
"->",
"navigation",
"->",
"create",
"(",
"Navigable",
"::",
"MENU_SIDEBAR",
",",
"function",
"(",
"MenuBuilder",
"$",
"sidebar",
")",
"{",
"$",
"sidebar",
"->",
"header",
"(",
"'Main Menu'",... | Make SideBar navigation. | [
"Make",
"SideBar",
"navigation",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/publishes/Navigation.php#L31-L48 | train |
adminarchitect/core | src/Actions/RemoveSelected.php | RemoveSelected.handle | public function handle(Model $eloquent, Request $request)
{
return $this->fetchForDelete($eloquent, $request)
->each(function ($item) {
return $this->canDelete($item) ? $item->delete() : $item;
});
} | php | public function handle(Model $eloquent, Request $request)
{
return $this->fetchForDelete($eloquent, $request)
->each(function ($item) {
return $this->canDelete($item) ? $item->delete() : $item;
});
} | [
"public",
"function",
"handle",
"(",
"Model",
"$",
"eloquent",
",",
"Request",
"$",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"fetchForDelete",
"(",
"$",
"eloquent",
",",
"$",
"request",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"item",
")"... | Delete collection elements.
@param Model $eloquent
@param Request $request
@return mixed | [
"Delete",
"collection",
"elements",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Actions/RemoveSelected.php#L22-L28 | train |
adminarchitect/core | src/Traits/Module/AllowFormats.php | AllowFormats.makeExportableUrl | public function makeExportableUrl($format)
{
$payload = array_merge([
'module' => $this->url(),
'format' => $format,
], Request::all());
return route('scaffold.export', $payload);
} | php | public function makeExportableUrl($format)
{
$payload = array_merge([
'module' => $this->url(),
'format' => $format,
], Request::all());
return route('scaffold.export', $payload);
} | [
"public",
"function",
"makeExportableUrl",
"(",
"$",
"format",
")",
"{",
"$",
"payload",
"=",
"array_merge",
"(",
"[",
"'module'",
"=>",
"$",
"this",
"->",
"url",
"(",
")",
",",
"'format'",
"=>",
"$",
"format",
",",
"]",
",",
"Request",
"::",
"all",
... | Get exportable url.
@param $format
@return string | [
"Get",
"exportable",
"url",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/AllowFormats.php#L26-L34 | train |
adminarchitect/core | src/Traits/Module/AllowsNavigation.php | AllowsNavigation.title | public function title()
{
return $this->translator()->has($key = $this->translationKey())
? trans($key)
: StringHumanizer::humanize(class_basename($this));
} | php | public function title()
{
return $this->translator()->has($key = $this->translationKey())
? trans($key)
: StringHumanizer::humanize(class_basename($this));
} | [
"public",
"function",
"title",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"translator",
"(",
")",
"->",
"has",
"(",
"$",
"key",
"=",
"$",
"this",
"->",
"translationKey",
"(",
")",
")",
"?",
"trans",
"(",
"$",
"key",
")",
":",
"StringHumanizer",
":... | The module title.
@return mixed | [
"The",
"module",
"title",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/AllowsNavigation.php#L37-L42 | train |
adminarchitect/core | src/Traits/Module/HasForm.php | HasForm.scaffoldForm | protected function scaffoldForm()
{
$editable = new Mutable();
if ($eloquent = $this->model()) {
$editable = $editable
->merge($translatable = $this->scaffoldTranslatable($eloquent))
->merge($eloquent->getFillable());
return $editable->map(function ($name) use ($eloquent, $translatable) {
$formElement = InputFactory::make(
$name,
$this->inputType($name, $eloquent)
);
if (in_array($name, $translatable, true)) {
$formElement->setTranslatable(true);
}
// For Enums (Select|Radio) try to extract values from database.
if (is_a($formElement, Select::class)
&& empty($formElement->getOptions())
&& connection('mysql')
) {
$formElement->setOptions(
$values = enum_values($table = $eloquent->getTable(), $name)
);
// set appropriate styling
if (count($values) > 5) {
$formElement->setStyle([
'display' => 'block',
]);
}
// set default value
if ($default = scheme()->columns($table)[$name]->getDefault()) {
$formElement->setValue($default);
}
}
$container = new FormElement($name);
return $container->setInput($formElement);
});
}
return $editable;
} | php | protected function scaffoldForm()
{
$editable = new Mutable();
if ($eloquent = $this->model()) {
$editable = $editable
->merge($translatable = $this->scaffoldTranslatable($eloquent))
->merge($eloquent->getFillable());
return $editable->map(function ($name) use ($eloquent, $translatable) {
$formElement = InputFactory::make(
$name,
$this->inputType($name, $eloquent)
);
if (in_array($name, $translatable, true)) {
$formElement->setTranslatable(true);
}
// For Enums (Select|Radio) try to extract values from database.
if (is_a($formElement, Select::class)
&& empty($formElement->getOptions())
&& connection('mysql')
) {
$formElement->setOptions(
$values = enum_values($table = $eloquent->getTable(), $name)
);
// set appropriate styling
if (count($values) > 5) {
$formElement->setStyle([
'display' => 'block',
]);
}
// set default value
if ($default = scheme()->columns($table)[$name]->getDefault()) {
$formElement->setValue($default);
}
}
$container = new FormElement($name);
return $container->setInput($formElement);
});
}
return $editable;
} | [
"protected",
"function",
"scaffoldForm",
"(",
")",
"{",
"$",
"editable",
"=",
"new",
"Mutable",
"(",
")",
";",
"if",
"(",
"$",
"eloquent",
"=",
"$",
"this",
"->",
"model",
"(",
")",
")",
"{",
"$",
"editable",
"=",
"$",
"editable",
"->",
"merge",
"(... | Build editable columns based on table columns metadata.
@return Mutable | [
"Build",
"editable",
"columns",
"based",
"on",
"table",
"columns",
"metadata",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/HasForm.php#L43-L91 | train |
adminarchitect/core | src/Services/Translations/Finder.php | Finder.paginate | protected function paginate($keys, $page, $perPage)
{
return new LengthAwarePaginator(
$this->chunk($keys, $page, $perPage),
count($keys),
20,
$page,
[
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page',
]
);
} | php | protected function paginate($keys, $page, $perPage)
{
return new LengthAwarePaginator(
$this->chunk($keys, $page, $perPage),
count($keys),
20,
$page,
[
'path' => Paginator::resolveCurrentPath(),
'pageName' => 'page',
]
);
} | [
"protected",
"function",
"paginate",
"(",
"$",
"keys",
",",
"$",
"page",
",",
"$",
"perPage",
")",
"{",
"return",
"new",
"LengthAwarePaginator",
"(",
"$",
"this",
"->",
"chunk",
"(",
"$",
"keys",
",",
"$",
"page",
",",
"$",
"perPage",
")",
",",
"coun... | Builds a Paginator instance.
@param $keys
@param $page
@param $perPage
@return LengthAwarePaginator | [
"Builds",
"a",
"Paginator",
"instance",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Translations/Finder.php#L46-L58 | train |
adminarchitect/core | src/Services/Translations/Finder.php | Finder.chunk | protected function chunk($translations, $page = 1, $perPage = 20)
{
if (!$count = count($translations)) {
return [];
}
$pages = array_chunk($translations, $perPage, true);
$min = 1;
$max = ceil($count / $perPage);
if ($page < $min || $page > $max) {
$page = 1;
}
return $pages[$page - 1];
} | php | protected function chunk($translations, $page = 1, $perPage = 20)
{
if (!$count = count($translations)) {
return [];
}
$pages = array_chunk($translations, $perPage, true);
$min = 1;
$max = ceil($count / $perPage);
if ($page < $min || $page > $max) {
$page = 1;
}
return $pages[$page - 1];
} | [
"protected",
"function",
"chunk",
"(",
"$",
"translations",
",",
"$",
"page",
"=",
"1",
",",
"$",
"perPage",
"=",
"20",
")",
"{",
"if",
"(",
"!",
"$",
"count",
"=",
"count",
"(",
"$",
"translations",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
... | Retrieves the current page chunk.
@param $translations
@param int $page
@param int $perPage
@return array | [
"Retrieves",
"the",
"current",
"page",
"chunk",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Translations/Finder.php#L69-L85 | train |
adminarchitect/core | src/Traits/ResolvesClasses.php | ResolvesClasses.resolveClass | public function resolveClass(SplFileInfo $fileInfo, Closure $callback = null)
{
/** @noinspection PhpIncludeInspection */
require_once $fileInfo->getPathname();
$instance = app()->make($this->getModuleClassName($fileInfo));
if (is_callable($callback)) {
$callback($instance);
}
} | php | public function resolveClass(SplFileInfo $fileInfo, Closure $callback = null)
{
/** @noinspection PhpIncludeInspection */
require_once $fileInfo->getPathname();
$instance = app()->make($this->getModuleClassName($fileInfo));
if (is_callable($callback)) {
$callback($instance);
}
} | [
"public",
"function",
"resolveClass",
"(",
"SplFileInfo",
"$",
"fileInfo",
",",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"/** @noinspection PhpIncludeInspection */",
"require_once",
"$",
"fileInfo",
"->",
"getPathname",
"(",
")",
";",
"$",
"instance",
"=... | Resolves and Initializes Class by filename.
@param SplFileInfo $fileInfo
@param null|Closure $callback | [
"Resolves",
"and",
"Initializes",
"Class",
"by",
"filename",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/ResolvesClasses.php#L16-L26 | train |
adminarchitect/core | src/Traits/Module/HasColumns.php | HasColumns.scaffoldViewColumns | public function scaffoldViewColumns(Model $model)
{
$items = new Mutable();
$attributes = \admin\helpers\eloquent_attributes($model);
foreach ($attributes as $key => $value) {
$items->push($key);
}
return $items->build(
new GridDecorator($model)
);
} | php | public function scaffoldViewColumns(Model $model)
{
$items = new Mutable();
$attributes = \admin\helpers\eloquent_attributes($model);
foreach ($attributes as $key => $value) {
$items->push($key);
}
return $items->build(
new GridDecorator($model)
);
} | [
"public",
"function",
"scaffoldViewColumns",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"items",
"=",
"new",
"Mutable",
"(",
")",
";",
"$",
"attributes",
"=",
"\\",
"admin",
"\\",
"helpers",
"\\",
"eloquent_attributes",
"(",
"$",
"model",
")",
";",
"fore... | Fetch "viewable" columns.
@param Model $model
@return Mutable | [
"Fetch",
"viewable",
"columns",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/HasColumns.php#L43-L56 | train |
adminarchitect/core | src/Console/AdministratorCreateCommand.php | AdministratorCreateCommand.prepareData | protected function prepareData($name, $email, $password)
{
$data = compact('name', 'email', 'password');
if (app('scaffold.config')->get('manage_passwords')) {
$data['password'] = $this->hasher->make($data['password']);
}
return $data;
} | php | protected function prepareData($name, $email, $password)
{
$data = compact('name', 'email', 'password');
if (app('scaffold.config')->get('manage_passwords')) {
$data['password'] = $this->hasher->make($data['password']);
}
return $data;
} | [
"protected",
"function",
"prepareData",
"(",
"$",
"name",
",",
"$",
"email",
",",
"$",
"password",
")",
"{",
"$",
"data",
"=",
"compact",
"(",
"'name'",
",",
"'email'",
",",
"'password'",
")",
";",
"if",
"(",
"app",
"(",
"'scaffold.config'",
")",
"->",... | Prepare administrator's data.
@param $name
@param $email
@param $password
@return array | [
"Prepare",
"administrator",
"s",
"data",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Console/AdministratorCreateCommand.php#L69-L78 | train |
adminarchitect/core | src/Console/AdministratorCreateCommand.php | AdministratorCreateCommand.createUserInstance | protected function createUserInstance($data)
{
$config = app('scaffold.config');
if (!$model = $this->fetchModel($config)) {
throw new Exception('Could not find a model to create user.');
}
try {
$model::unguard();
return (new $model())->create($this->dataWithId($data));
} catch (Exception $e) {
return (new $model())->create($data);
}
} | php | protected function createUserInstance($data)
{
$config = app('scaffold.config');
if (!$model = $this->fetchModel($config)) {
throw new Exception('Could not find a model to create user.');
}
try {
$model::unguard();
return (new $model())->create($this->dataWithId($data));
} catch (Exception $e) {
return (new $model())->create($data);
}
} | [
"protected",
"function",
"createUserInstance",
"(",
"$",
"data",
")",
"{",
"$",
"config",
"=",
"app",
"(",
"'scaffold.config'",
")",
";",
"if",
"(",
"!",
"$",
"model",
"=",
"$",
"this",
"->",
"fetchModel",
"(",
"$",
"config",
")",
")",
"{",
"throw",
... | Insert new user into database.
@param $data
@throws Exception
@return Model | [
"Insert",
"new",
"user",
"into",
"database",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Console/AdministratorCreateCommand.php#L105-L120 | train |
adminarchitect/core | src/Form/Type/Radio.php | Radio.setStyle | public function setStyle(array $style = [], $update = true)
{
$this->style = $update
? array_merge($this->style, $style)
: $style;
return $this;
} | php | public function setStyle(array $style = [], $update = true)
{
$this->style = $update
? array_merge($this->style, $style)
: $style;
return $this;
} | [
"public",
"function",
"setStyle",
"(",
"array",
"$",
"style",
"=",
"[",
"]",
",",
"$",
"update",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"style",
"=",
"$",
"update",
"?",
"array_merge",
"(",
"$",
"this",
"->",
"style",
",",
"$",
"style",
")",
"... | Apply a style to a single element.
@param array $style
@param bool $update
@return $this | [
"Apply",
"a",
"style",
"to",
"a",
"single",
"element",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Form/Type/Radio.php#L46-L53 | train |
adminarchitect/core | src/Controllers/ScaffoldController.php | ScaffoldController.view | public function view($page, $id)
{
$this->authorize('view', $eloquent = app('scaffold.model'));
app('scaffold.widget')->add(
(new EloquentWidget($eloquent))
->setOrder(0)
->setTab(AbstractWidget::TAB_DEFAULT)
->setPlacement('model')
);
return view(app('scaffold.template')->view('index'), [
'item' => $eloquent,
]);
} | php | public function view($page, $id)
{
$this->authorize('view', $eloquent = app('scaffold.model'));
app('scaffold.widget')->add(
(new EloquentWidget($eloquent))
->setOrder(0)
->setTab(AbstractWidget::TAB_DEFAULT)
->setPlacement('model')
);
return view(app('scaffold.template')->view('index'), [
'item' => $eloquent,
]);
} | [
"public",
"function",
"view",
"(",
"$",
"page",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'view'",
",",
"$",
"eloquent",
"=",
"app",
"(",
"'scaffold.model'",
")",
")",
";",
"app",
"(",
"'scaffold.widget'",
")",
"->",
"add",
"(",... | View resource.
@param $page
@param $id
@return \Illuminate\View\View | [
"View",
"resource",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Controllers/ScaffoldController.php#L38-L52 | train |
adminarchitect/core | src/Controllers/ScaffoldController.php | ScaffoldController.edit | public function edit($page, $id)
{
$this->authorize('update', $eloquent = app('scaffold.model'));
return view(app('scaffold.template')->edit('index'), [
'item' => $eloquent,
]);
} | php | public function edit($page, $id)
{
$this->authorize('update', $eloquent = app('scaffold.model'));
return view(app('scaffold.template')->edit('index'), [
'item' => $eloquent,
]);
} | [
"public",
"function",
"edit",
"(",
"$",
"page",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'update'",
",",
"$",
"eloquent",
"=",
"app",
"(",
"'scaffold.model'",
")",
")",
";",
"return",
"view",
"(",
"app",
"(",
"'scaffold.template'... | Edit resource.
@param $page
@param $id
@return \Illuminate\View\View | [
"Edit",
"resource",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Controllers/ScaffoldController.php#L62-L69 | train |
adminarchitect/core | src/Controllers/ScaffoldController.php | ScaffoldController.delete | public function delete(Module $module)
{
$this->authorize('delete', $eloquent = app('scaffold.model'));
$id = $eloquent->id;
app('scaffold.actions')->exec('delete', [$eloquent]);
$message = trans('administrator::messages.remove_success', ['item' => app('scaffold.module')->singular()]);
if (URL::previous() === route('scaffold.view', ['module' => $module, 'id' => $id])) {
return back()->with('messages', [$message]);
}
return redirect()->to(route('scaffold.index', ['module' => $module]))->with('messages', [$message]);
} | php | public function delete(Module $module)
{
$this->authorize('delete', $eloquent = app('scaffold.model'));
$id = $eloquent->id;
app('scaffold.actions')->exec('delete', [$eloquent]);
$message = trans('administrator::messages.remove_success', ['item' => app('scaffold.module')->singular()]);
if (URL::previous() === route('scaffold.view', ['module' => $module, 'id' => $id])) {
return back()->with('messages', [$message]);
}
return redirect()->to(route('scaffold.index', ['module' => $module]))->with('messages', [$message]);
} | [
"public",
"function",
"delete",
"(",
"Module",
"$",
"module",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'delete'",
",",
"$",
"eloquent",
"=",
"app",
"(",
"'scaffold.model'",
")",
")",
";",
"$",
"id",
"=",
"$",
"eloquent",
"->",
"id",
";",
"app"... | Destroy item.
@param Module $module
@return \Illuminate\Http\RedirectResponse | [
"Destroy",
"item",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Controllers/ScaffoldController.php#L141-L156 | train |
adminarchitect/core | src/Controllers/ScaffoldController.php | ScaffoldController.deleteAttachment | public function deleteAttachment($page, $id, $attachment)
{
$this->authorize('update', $eloquent = app('scaffold.model'));
app('scaffold.actions')->exec('detachFile', [$eloquent, $attachment]);
return back()->with('messages',
[trans('administrator::messages.remove_success', ['item' => 'Attachment'])]);
} | php | public function deleteAttachment($page, $id, $attachment)
{
$this->authorize('update', $eloquent = app('scaffold.model'));
app('scaffold.actions')->exec('detachFile', [$eloquent, $attachment]);
return back()->with('messages',
[trans('administrator::messages.remove_success', ['item' => 'Attachment'])]);
} | [
"public",
"function",
"deleteAttachment",
"(",
"$",
"page",
",",
"$",
"id",
",",
"$",
"attachment",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"'update'",
",",
"$",
"eloquent",
"=",
"app",
"(",
"'scaffold.model'",
")",
")",
";",
"app",
"(",
"'scaff... | Destroy attachment.
@param $page
@param $id
@param $attachment
@return \Illuminate\Http\RedirectResponse | [
"Destroy",
"attachment",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Controllers/ScaffoldController.php#L167-L175 | train |
adminarchitect/core | src/Controllers/ScaffoldController.php | ScaffoldController.action | public function action($page, $id, $action)
{
$this->authorize($action, $eloquent = app('scaffold.model'));
$response = app('scaffold.actions')->exec('action::' . $action, [$eloquent]);
if ($response instanceof Response || $response instanceof Renderable) {
return $response;
}
return back()->with(
'messages',
[trans('administrator::messages.action_success')]
);
} | php | public function action($page, $id, $action)
{
$this->authorize($action, $eloquent = app('scaffold.model'));
$response = app('scaffold.actions')->exec('action::' . $action, [$eloquent]);
if ($response instanceof Response || $response instanceof Renderable) {
return $response;
}
return back()->with(
'messages',
[trans('administrator::messages.action_success')]
);
} | [
"public",
"function",
"action",
"(",
"$",
"page",
",",
"$",
"id",
",",
"$",
"action",
")",
"{",
"$",
"this",
"->",
"authorize",
"(",
"$",
"action",
",",
"$",
"eloquent",
"=",
"app",
"(",
"'scaffold.model'",
")",
")",
";",
"$",
"response",
"=",
"app... | Custom action related to item.
@param $page
@param $id
@param $action
@return \Illuminate\Http\RedirectResponse | [
"Custom",
"action",
"related",
"to",
"item",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Controllers/ScaffoldController.php#L186-L200 | train |
adminarchitect/core | src/Services/Breadcrumbs.php | Breadcrumbs.render | public function render()
{
$action = $this->currentAction();
// assembly breadcrumbs
$this->assembly($action);
return $this->manager->render($action);
} | php | public function render()
{
$action = $this->currentAction();
// assembly breadcrumbs
$this->assembly($action);
return $this->manager->render($action);
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"currentAction",
"(",
")",
";",
"// assembly breadcrumbs",
"$",
"this",
"->",
"assembly",
"(",
"$",
"action",
")",
";",
"return",
"$",
"this",
"->",
"manager",
"->",
... | Render breadcrumbs.
@return string | [
"Render",
"breadcrumbs",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Breadcrumbs.php#L45-L53 | train |
adminarchitect/core | src/Services/Breadcrumbs.php | Breadcrumbs.currentAction | protected function currentAction()
{
$action = substr($action = Route::currentRouteAction(), strpos($action, '@') + 1);
if (!method_exists($this, $action)) {
$action = 'index';
}
return $action;
} | php | protected function currentAction()
{
$action = substr($action = Route::currentRouteAction(), strpos($action, '@') + 1);
if (!method_exists($this, $action)) {
$action = 'index';
}
return $action;
} | [
"protected",
"function",
"currentAction",
"(",
")",
"{",
"$",
"action",
"=",
"substr",
"(",
"$",
"action",
"=",
"Route",
"::",
"currentRouteAction",
"(",
")",
",",
"strpos",
"(",
"$",
"action",
",",
"'@'",
")",
"+",
"1",
")",
";",
"if",
"(",
"!",
"... | Detect current action.
@return null|string | [
"Detect",
"current",
"action",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Breadcrumbs.php#L60-L69 | train |
adminarchitect/core | src/Traits/Module/HasSortable.php | HasSortable.addSortable | public function addSortable($element, Closure $callback = null)
{
$this->scaffoldSortable();
if (null === $callback) {
$this->sortable[] = $element;
} else {
$this->sortable[$element] = $callback;
}
return $this;
} | php | public function addSortable($element, Closure $callback = null)
{
$this->scaffoldSortable();
if (null === $callback) {
$this->sortable[] = $element;
} else {
$this->sortable[$element] = $callback;
}
return $this;
} | [
"public",
"function",
"addSortable",
"(",
"$",
"element",
",",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"scaffoldSortable",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"sortable",
... | Register a Sortable element.
@param $element
@param null|Closure $callback
@return $this | [
"Register",
"a",
"Sortable",
"element",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/HasSortable.php#L25-L36 | train |
adminarchitect/core | src/Traits/Module/HasSortable.php | HasSortable.removeSortable | public function removeSortable($element)
{
if (array_has($this->sortable, $element)) {
return $this->sortable = array_except($this->sortable, $element);
}
if (in_array($element, $this->sortable(), true)) {
return $this->sortable = array_except(
$this->sortable,
array_search($element, $this->sortable, true)
);
}
return $this->sortable;
} | php | public function removeSortable($element)
{
if (array_has($this->sortable, $element)) {
return $this->sortable = array_except($this->sortable, $element);
}
if (in_array($element, $this->sortable(), true)) {
return $this->sortable = array_except(
$this->sortable,
array_search($element, $this->sortable, true)
);
}
return $this->sortable;
} | [
"public",
"function",
"removeSortable",
"(",
"$",
"element",
")",
"{",
"if",
"(",
"array_has",
"(",
"$",
"this",
"->",
"sortable",
",",
"$",
"element",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sortable",
"=",
"array_except",
"(",
"$",
"this",
"->",... | Remove an element from Sortable collection.
@param $element
@return null|array | [
"Remove",
"an",
"element",
"from",
"Sortable",
"collection",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/HasSortable.php#L45-L59 | train |
adminarchitect/core | src/Traits/Module/DetectsCommentFlag.php | DetectsCommentFlag.hasCommentFlag | protected function hasCommentFlag($flag, $reflection = null)
{
if (null === $reflection) {
$reflection = new \ReflectionClass(new static());
}
$flag = "@{$flag}";
$lines = explode("\n", $reflection->getDocComment());
foreach ($lines as $line) {
if (false !== stripos($line, $flag)) {
$props = array_filter(explode(' ', $line), function ($prop) {
return '' !== trim($prop) && '*' !== $prop;
});
if (head($props) !== $flag) {
continue;
}
return $props ? array_values($props) : true;
}
}
return false;
} | php | protected function hasCommentFlag($flag, $reflection = null)
{
if (null === $reflection) {
$reflection = new \ReflectionClass(new static());
}
$flag = "@{$flag}";
$lines = explode("\n", $reflection->getDocComment());
foreach ($lines as $line) {
if (false !== stripos($line, $flag)) {
$props = array_filter(explode(' ', $line), function ($prop) {
return '' !== trim($prop) && '*' !== $prop;
});
if (head($props) !== $flag) {
continue;
}
return $props ? array_values($props) : true;
}
}
return false;
} | [
"protected",
"function",
"hasCommentFlag",
"(",
"$",
"flag",
",",
"$",
"reflection",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"reflection",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"new",
"static",
"(",
")",
"... | Search class doc comment for specific flag.
@param $flag
@param null $reflection
@return bool | [
"Search",
"class",
"doc",
"comment",
"for",
"specific",
"flag",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/DetectsCommentFlag.php#L15-L40 | train |
adminarchitect/core | src/Form/Type/Select.php | Select.callableOptions | protected function callableOptions($callable)
{
// resolve closure
if (is_callable($callable)) {
return $callable;
}
// resolve callable "Class@method" style
if (is_string($callable) && list($class, $method) = explode('@', $callable)) {
return [app()->make($class), $method];
}
// resolve callable [$object, "method"]
if (2 === count($callable) && array_key_exists(0, $callable) && array_key_exists(1, $callable)) {
if (is_object($class = $callable[0]) && is_string($method = $callable[1]) && method_exists($class, $method)) {
return [$class, $method];
}
}
return false;
} | php | protected function callableOptions($callable)
{
// resolve closure
if (is_callable($callable)) {
return $callable;
}
// resolve callable "Class@method" style
if (is_string($callable) && list($class, $method) = explode('@', $callable)) {
return [app()->make($class), $method];
}
// resolve callable [$object, "method"]
if (2 === count($callable) && array_key_exists(0, $callable) && array_key_exists(1, $callable)) {
if (is_object($class = $callable[0]) && is_string($method = $callable[1]) && method_exists($class, $method)) {
return [$class, $method];
}
}
return false;
} | [
"protected",
"function",
"callableOptions",
"(",
"$",
"callable",
")",
"{",
"// resolve closure",
"if",
"(",
"is_callable",
"(",
"$",
"callable",
")",
")",
"{",
"return",
"$",
"callable",
";",
"}",
"// resolve callable \"Class@method\" style",
"if",
"(",
"is_strin... | Parse options and try to resolve values.
@param $callable
@return mixed bool|array|callable | [
"Parse",
"options",
"and",
"try",
"to",
"resolve",
"values",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Form/Type/Select.php#L95-L115 | train |
adminarchitect/core | src/Services/Sorter.php | Sorter.makeUrl | public function makeUrl($element)
{
return \admin\helpers\qsRoute(null, [
'sort_by' => $element,
'sort_dir' => $this->proposeDirection($element),
]);
} | php | public function makeUrl($element)
{
return \admin\helpers\qsRoute(null, [
'sort_by' => $element,
'sort_dir' => $this->proposeDirection($element),
]);
} | [
"public",
"function",
"makeUrl",
"(",
"$",
"element",
")",
"{",
"return",
"\\",
"admin",
"\\",
"helpers",
"\\",
"qsRoute",
"(",
"null",
",",
"[",
"'sort_by'",
"=>",
"$",
"element",
",",
"'sort_dir'",
"=>",
"$",
"this",
"->",
"proposeDirection",
"(",
"$",... | Build sortable url.
@param $element
@return string | [
"Build",
"sortable",
"url",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Sorter.php#L29-L35 | train |
adminarchitect/core | src/Services/Sorter.php | Sorter.canSortBy | public function canSortBy($column)
{
return array_key_exists($column, $this->sortable) || in_array($column, $this->sortable, true);
} | php | public function canSortBy($column)
{
return array_key_exists($column, $this->sortable) || in_array($column, $this->sortable, true);
} | [
"public",
"function",
"canSortBy",
"(",
"$",
"column",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"column",
",",
"$",
"this",
"->",
"sortable",
")",
"||",
"in_array",
"(",
"$",
"column",
",",
"$",
"this",
"->",
"sortable",
",",
"true",
")",
";",... | Check if a column is sortable.
@param $column
@return bool | [
"Check",
"if",
"a",
"column",
"is",
"sortable",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Sorter.php#L64-L67 | train |
adminarchitect/core | src/Services/Sorter.php | Sorter.first | protected function first()
{
foreach ($this->sortable as $key => $value) {
if (is_numeric($key)) {
return $value;
}
return $key;
}
return null;
} | php | protected function first()
{
foreach ($this->sortable as $key => $value) {
if (is_numeric($key)) {
return $value;
}
return $key;
}
return null;
} | [
"protected",
"function",
"first",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sortable",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"return",
"... | Retrieve first sortable element.
@return mixed | [
"Retrieve",
"first",
"sortable",
"element",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Sorter.php#L74-L85 | train |
adminarchitect/core | src/Services/Sorter.php | Sorter.proposeDirection | protected function proposeDirection($forElement)
{
$sortDir = $this->direction();
return $forElement === $this->element() ? $this->reverseDirection($sortDir) : $sortDir;
} | php | protected function proposeDirection($forElement)
{
$sortDir = $this->direction();
return $forElement === $this->element() ? $this->reverseDirection($sortDir) : $sortDir;
} | [
"protected",
"function",
"proposeDirection",
"(",
"$",
"forElement",
")",
"{",
"$",
"sortDir",
"=",
"$",
"this",
"->",
"direction",
"(",
")",
";",
"return",
"$",
"forElement",
"===",
"$",
"this",
"->",
"element",
"(",
")",
"?",
"$",
"this",
"->",
"reve... | Propose new sort direction for element.
@param $forElement
@return string | [
"Propose",
"new",
"sort",
"direction",
"for",
"element",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Sorter.php#L94-L99 | train |
adminarchitect/core | src/Filters/FilterElement.php | FilterElement.custom | public static function custom($id, $input)
{
return (new static($id))->setInput($input instanceof Queryable ? $input : new $input($id));
} | php | public static function custom($id, $input)
{
return (new static($id))->setInput($input instanceof Queryable ? $input : new $input($id));
} | [
"public",
"static",
"function",
"custom",
"(",
"$",
"id",
",",
"$",
"input",
")",
"{",
"return",
"(",
"new",
"static",
"(",
"$",
"id",
")",
")",
"->",
"setInput",
"(",
"$",
"input",
"instanceof",
"Queryable",
"?",
"$",
"input",
":",
"new",
"$",
"in... | Create a custom Filter element.
@param $id
@param mixed string|Queryable $input
@return mixed | [
"Create",
"a",
"custom",
"Filter",
"element",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Filters/FilterElement.php#L71-L74 | train |
adminarchitect/core | src/Form/Collection/Mutable.php | Mutable.create | public function create($element, $inputType = null, $position = null)
{
if (!(is_string($element) || $element instanceof FormElement)) {
throw new Exception('$element must be string or FormElement instance.');
}
// Create new element from string declaration ("title").
if (is_string($element)) {
$element = (new FormElement($element));
}
// Create Form Input Element from string declaration ("textarea")
if (is_string($inputType)) {
$oldInput = $element->getInput();
$newInput = InputFactory::make($element->id(), $inputType);
$newInput->setRelation(
$oldInput->getRelation()
)->setTranslatable(
$oldInput->getTranslatable()
);
$element->setInput(
$newInput
);
}
// Allow a callable input type.
if (is_callable($inputType)) {
call_user_func_array($inputType, [$element]);
}
if (is_numeric($position)) {
return $this->insert($element, $position);
}
// Push element
$this->push($element);
if (null !== $position) {
return $this->move($element->id(), $position);
}
return $this;
} | php | public function create($element, $inputType = null, $position = null)
{
if (!(is_string($element) || $element instanceof FormElement)) {
throw new Exception('$element must be string or FormElement instance.');
}
// Create new element from string declaration ("title").
if (is_string($element)) {
$element = (new FormElement($element));
}
// Create Form Input Element from string declaration ("textarea")
if (is_string($inputType)) {
$oldInput = $element->getInput();
$newInput = InputFactory::make($element->id(), $inputType);
$newInput->setRelation(
$oldInput->getRelation()
)->setTranslatable(
$oldInput->getTranslatable()
);
$element->setInput(
$newInput
);
}
// Allow a callable input type.
if (is_callable($inputType)) {
call_user_func_array($inputType, [$element]);
}
if (is_numeric($position)) {
return $this->insert($element, $position);
}
// Push element
$this->push($element);
if (null !== $position) {
return $this->move($element->id(), $position);
}
return $this;
} | [
"public",
"function",
"create",
"(",
"$",
"element",
",",
"$",
"inputType",
"=",
"null",
",",
"$",
"position",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"is_string",
"(",
"$",
"element",
")",
"||",
"$",
"element",
"instanceof",
"FormElement",
")",
... | Insert a new form element.
@param $element
@param mixed string|Closure $inputType
@param mixed null|int|string $position
@throws Exception
@return $this | [
"Insert",
"a",
"new",
"form",
"element",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Form/Collection/Mutable.php#L29-L73 | train |
adminarchitect/core | src/Form/Collection/Mutable.php | Mutable.section | public function section($section, $position = null)
{
if (is_string($section)) {
$section = new FormSection($section);
}
return null !== $position ? $this->insert($section, $position) : $this->push($section);
} | php | public function section($section, $position = null)
{
if (is_string($section)) {
$section = new FormSection($section);
}
return null !== $position ? $this->insert($section, $position) : $this->push($section);
} | [
"public",
"function",
"section",
"(",
"$",
"section",
",",
"$",
"position",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"section",
")",
")",
"{",
"$",
"section",
"=",
"new",
"FormSection",
"(",
"$",
"section",
")",
";",
"}",
"return",
... | Create a section.
@param $section
@param null $position
@return $this | [
"Create",
"a",
"section",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Form/Collection/Mutable.php#L83-L90 | train |
adminarchitect/core | src/Traits/Collection/ElementContainer.php | ElementContainer.setId | public function setId($id)
{
$id = $this->buildId($id);
if ($this->isRelation($id)) {
$relations = explode('.', $id);
$lastElement = array_pop($relations);
if (!$this->keepOriginalID) {
$id = $lastElement;
}
$this->relations = $relations;
}
$this->id = $id;
return $this;
} | php | public function setId($id)
{
$id = $this->buildId($id);
if ($this->isRelation($id)) {
$relations = explode('.', $id);
$lastElement = array_pop($relations);
if (!$this->keepOriginalID) {
$id = $lastElement;
}
$this->relations = $relations;
}
$this->id = $id;
return $this;
} | [
"public",
"function",
"setId",
"(",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"buildId",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRelation",
"(",
"$",
"id",
")",
")",
"{",
"$",
"relations",
"=",
"explode",
"(",
... | Set element ID.
@param $id
@return $this | [
"Set",
"element",
"ID",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Collection/ElementContainer.php#L74-L93 | train |
adminarchitect/core | src/Traits/Form/FormControl.php | FormControl.setName | public function setName($name)
{
if (false !== stripos($name, '.')) {
$relations = explode('.', $name);
$name = array_pop($relations);
$this->relation = implode('.', $relations);
}
$this->name = $name;
return $this;
} | php | public function setName($name)
{
if (false !== stripos($name, '.')) {
$relations = explode('.', $name);
$name = array_pop($relations);
$this->relation = implode('.', $relations);
}
$this->name = $name;
return $this;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"!==",
"stripos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"$",
"relations",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"name",
"=",
"array_pop... | Set element name.
@param $name
@return mixed | [
"Set",
"element",
"name",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Form/FormControl.php#L65-L76 | train |
adminarchitect/core | src/Traits/Form/FormControl.php | FormControl.setValue | public function setValue($value = null)
{
if (is_callable($value)) {
$value = call_user_func($value);
}
$value = $this->handleJsonType($value);
$this->value = $value;
return $this;
} | php | public function setValue($value = null)
{
if (is_callable($value)) {
$value = call_user_func($value);
}
$value = $this->handleJsonType($value);
$this->value = $value;
return $this;
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"call_user_func",
"(",
"$",
"value",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"... | Set element implicit value.
@param mixed $value
@return $this | [
"Set",
"element",
"implicit",
"value",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Form/FormControl.php#L95-L106 | train |
adminarchitect/core | src/Traits/Module/HasFilters.php | HasFilters.scaffoldScopes | protected function scaffoldScopes()
{
$this->scopes = new Mutable();
if ($model = $this->model()) {
$this->fetchModelScopes($model);
$this->addSoftDeletesScopes($model);
}
return $this->scopes;
} | php | protected function scaffoldScopes()
{
$this->scopes = new Mutable();
if ($model = $this->model()) {
$this->fetchModelScopes($model);
$this->addSoftDeletesScopes($model);
}
return $this->scopes;
} | [
"protected",
"function",
"scaffoldScopes",
"(",
")",
"{",
"$",
"this",
"->",
"scopes",
"=",
"new",
"Mutable",
"(",
")",
";",
"if",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"(",
")",
")",
"{",
"$",
"this",
"->",
"fetchModelScopes",
"(",
"... | Find all public scopes in current model.
@return Mutable | [
"Find",
"all",
"public",
"scopes",
"in",
"current",
"model",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/HasFilters.php#L138-L149 | train |
adminarchitect/core | src/Traits/Module/HasFilters.php | HasFilters.fetchModelScopes | protected function fetchModelScopes($model)
{
$reflection = new \ReflectionClass($model);
foreach ($reflection->getMethods() as $method) {
if (preg_match('~^scope(.+)$~i', $method->name, $match)) {
if ($this->isHiddenScope($name = $match[1])
|| $this->isDynamicScope($method)
|| $this->hasHiddenFlag($method->getDocComment())
|| 'scopeTranslated' === $match[0]) {
continue;
}
$scope = with(new Scope($name))->setQuery([$model, $name]);
if ($icon = $this->hasIconFlag($method->getDocComment())) {
$scope->setIcon($icon);
}
$this->addScope($scope);
}
}
} | php | protected function fetchModelScopes($model)
{
$reflection = new \ReflectionClass($model);
foreach ($reflection->getMethods() as $method) {
if (preg_match('~^scope(.+)$~i', $method->name, $match)) {
if ($this->isHiddenScope($name = $match[1])
|| $this->isDynamicScope($method)
|| $this->hasHiddenFlag($method->getDocComment())
|| 'scopeTranslated' === $match[0]) {
continue;
}
$scope = with(new Scope($name))->setQuery([$model, $name]);
if ($icon = $this->hasIconFlag($method->getDocComment())) {
$scope->setIcon($icon);
}
$this->addScope($scope);
}
}
} | [
"protected",
"function",
"fetchModelScopes",
"(",
"$",
"model",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"model",
")",
";",
"foreach",
"(",
"$",
"reflection",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",... | Parse the model for scopes.
@param $model | [
"Parse",
"the",
"model",
"for",
"scopes",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/HasFilters.php#L173-L194 | train |
adminarchitect/core | src/Traits/Module/HasFilters.php | HasFilters.addSoftDeletesScopes | protected function addSoftDeletesScopes($model)
{
if (array_key_exists('Illuminate\Database\Eloquent\SoftDeletes', class_uses($model))) {
foreach ($this->softDeletesScopes() as $method => $name) {
$this->addScope(
with(new Scope($method))
->setTitle($name)
->setQuery([$model, $method])
);
}
}
} | php | protected function addSoftDeletesScopes($model)
{
if (array_key_exists('Illuminate\Database\Eloquent\SoftDeletes', class_uses($model))) {
foreach ($this->softDeletesScopes() as $method => $name) {
$this->addScope(
with(new Scope($method))
->setTitle($name)
->setQuery([$model, $method])
);
}
}
} | [
"protected",
"function",
"addSoftDeletesScopes",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'Illuminate\\Database\\Eloquent\\SoftDeletes'",
",",
"class_uses",
"(",
"$",
"model",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"softD... | Add SoftDeletes scopes if model uses that trait.
@param $model | [
"Add",
"SoftDeletes",
"scopes",
"if",
"model",
"uses",
"that",
"trait",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/HasFilters.php#L249-L260 | train |
adminarchitect/core | src/Services/FileStorage.php | FileStorage.files | public function files($directory)
{
return collect([])
->merge($this->filesystem->files($directory))
->map(function ($file) {
return new File($file, $this);
});
} | php | public function files($directory)
{
return collect([])
->merge($this->filesystem->files($directory))
->map(function ($file) {
return new File($file, $this);
});
} | [
"public",
"function",
"files",
"(",
"$",
"directory",
")",
"{",
"return",
"collect",
"(",
"[",
"]",
")",
"->",
"merge",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"files",
"(",
"$",
"directory",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"f... | Files list.
@param $directory
@return Collection | [
"Files",
"list",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/FileStorage.php#L46-L53 | train |
adminarchitect/core | src/Services/FileStorage.php | FileStorage.directories | public function directories($directory)
{
return collect($this->filesystem->directories($directory))
->map(function ($file) {
return new File($file, $this);
});
} | php | public function directories($directory)
{
return collect($this->filesystem->directories($directory))
->map(function ($file) {
return new File($file, $this);
});
} | [
"public",
"function",
"directories",
"(",
"$",
"directory",
")",
"{",
"return",
"collect",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"directories",
"(",
"$",
"directory",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"file",
")",
"{",
"return",
"... | Directories list.
@param $directory
@return Collection | [
"Directories",
"list",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/FileStorage.php#L62-L68 | train |
adminarchitect/core | src/Services/Template.php | Template.index | public function index($partial = 'index')
{
$partials = $this->map(
'index',
['index', 'create', 'export', 'filters', 'scopes', 'header', 'batch', 'row', 'scripts', 'paginator']
);
return null === $partial ? $partials : $partials[$partial];
} | php | public function index($partial = 'index')
{
$partials = $this->map(
'index',
['index', 'create', 'export', 'filters', 'scopes', 'header', 'batch', 'row', 'scripts', 'paginator']
);
return null === $partial ? $partials : $partials[$partial];
} | [
"public",
"function",
"index",
"(",
"$",
"partial",
"=",
"'index'",
")",
"{",
"$",
"partials",
"=",
"$",
"this",
"->",
"map",
"(",
"'index'",
",",
"[",
"'index'",
",",
"'create'",
",",
"'export'",
",",
"'filters'",
",",
"'scopes'",
",",
"'header'",
","... | Scaffold index templates.
@param $partial
@return mixed array|string | [
"Scaffold",
"index",
"templates",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Template.php#L29-L37 | train |
adminarchitect/core | src/Traits/Module/ValidatesForm.php | ValidatesForm.scaffoldRules | protected function scaffoldRules()
{
$rules = [];
$eloquent = $this->model();
$table = $eloquent->getTable();
foreach (scheme()->columns($table) as $column) {
$name = $column->getName();
// skip Primary Key
if ($name === $eloquent->getKeyName()) {
continue;
}
// skip rankable field
if ($eloquent instanceof Rankable && $name === $eloquent->getRankableColumn()) {
continue;
}
if (!empty($columnRules = $this->proposeColumnRules($eloquent, $column))) {
$rules[$name] = implode('|', $columnRules);
}
}
return $rules;
} | php | protected function scaffoldRules()
{
$rules = [];
$eloquent = $this->model();
$table = $eloquent->getTable();
foreach (scheme()->columns($table) as $column) {
$name = $column->getName();
// skip Primary Key
if ($name === $eloquent->getKeyName()) {
continue;
}
// skip rankable field
if ($eloquent instanceof Rankable && $name === $eloquent->getRankableColumn()) {
continue;
}
if (!empty($columnRules = $this->proposeColumnRules($eloquent, $column))) {
$rules[$name] = implode('|', $columnRules);
}
}
return $rules;
} | [
"protected",
"function",
"scaffoldRules",
"(",
")",
"{",
"$",
"rules",
"=",
"[",
"]",
";",
"$",
"eloquent",
"=",
"$",
"this",
"->",
"model",
"(",
")",
";",
"$",
"table",
"=",
"$",
"eloquent",
"->",
"getTable",
"(",
")",
";",
"foreach",
"(",
"scheme... | Build a list of supposed validators based on columns and indexes information.
@return array | [
"Build",
"a",
"list",
"of",
"supposed",
"validators",
"based",
"on",
"columns",
"and",
"indexes",
"information",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/ValidatesForm.php#L24-L49 | train |
adminarchitect/core | src/Traits/Module/ValidatesForm.php | ValidatesForm.proposeColumnRules | protected function proposeColumnRules($eloquent, Column $column)
{
$rules = [];
if ((($this->fillable($column->getName(), $eloquent) || $this->isForeignKey($column, $eloquent))
&& $column->getNotnull())) {
// make required rule first
array_unshift($rules, 'required');
}
if ($this->isUnique($column, $eloquent)) {
$rules[] = 'unique';
}
if ('BooleanType' === ($classname = class_basename($column->getType()))) {
$rules[] = 'numeric';
$rules[] = 'boolean';
if (app()->runningUnitTests()) {
$rules = array_diff($rules, ['required']);
}
}
if (in_array($classname, ['IntegerType', 'DecimalType'], true)) {
$rules[] = 'numeric';
if ($column->getUnsigned()) {
$rules[] = 'unsigned';
}
}
if ($this->isForeignKey($column, $eloquent)) {
$rules[] = 'foreign';
}
return array_map(function ($rule) use ($column, $eloquent) {
$method = 'make'.ucfirst($rule).'Rule';
return call_user_func_array([$this, $method], [$column, $eloquent]);
}, $rules);
} | php | protected function proposeColumnRules($eloquent, Column $column)
{
$rules = [];
if ((($this->fillable($column->getName(), $eloquent) || $this->isForeignKey($column, $eloquent))
&& $column->getNotnull())) {
// make required rule first
array_unshift($rules, 'required');
}
if ($this->isUnique($column, $eloquent)) {
$rules[] = 'unique';
}
if ('BooleanType' === ($classname = class_basename($column->getType()))) {
$rules[] = 'numeric';
$rules[] = 'boolean';
if (app()->runningUnitTests()) {
$rules = array_diff($rules, ['required']);
}
}
if (in_array($classname, ['IntegerType', 'DecimalType'], true)) {
$rules[] = 'numeric';
if ($column->getUnsigned()) {
$rules[] = 'unsigned';
}
}
if ($this->isForeignKey($column, $eloquent)) {
$rules[] = 'foreign';
}
return array_map(function ($rule) use ($column, $eloquent) {
$method = 'make'.ucfirst($rule).'Rule';
return call_user_func_array([$this, $method], [$column, $eloquent]);
}, $rules);
} | [
"protected",
"function",
"proposeColumnRules",
"(",
"$",
"eloquent",
",",
"Column",
"$",
"column",
")",
"{",
"$",
"rules",
"=",
"[",
"]",
";",
"if",
"(",
"(",
"(",
"$",
"this",
"->",
"fillable",
"(",
"$",
"column",
"->",
"getName",
"(",
")",
",",
"... | Build a list of validators for a column.
@param $eloquent
@param Column $column
@return array | [
"Build",
"a",
"list",
"of",
"validators",
"for",
"a",
"column",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/ValidatesForm.php#L59-L99 | train |
adminarchitect/core | src/Traits/Module/ValidatesForm.php | ValidatesForm.isForeignKey | protected function isForeignKey($column, $eloquent)
{
foreach ($foreign = scheme()->foreignKeys($eloquent->getTable()) as $foreign) {
if (in_array($column->getName(), $foreign->getLocalColumns(), true)) {
return $foreign;
}
}
return false;
} | php | protected function isForeignKey($column, $eloquent)
{
foreach ($foreign = scheme()->foreignKeys($eloquent->getTable()) as $foreign) {
if (in_array($column->getName(), $foreign->getLocalColumns(), true)) {
return $foreign;
}
}
return false;
} | [
"protected",
"function",
"isForeignKey",
"(",
"$",
"column",
",",
"$",
"eloquent",
")",
"{",
"foreach",
"(",
"$",
"foreign",
"=",
"scheme",
"(",
")",
"->",
"foreignKeys",
"(",
"$",
"eloquent",
"->",
"getTable",
"(",
")",
")",
"as",
"$",
"foreign",
")",... | Check if column is a part of foreign keys.
@param $column
@param $eloquent
@return bool | [
"Check",
"if",
"column",
"is",
"a",
"part",
"of",
"foreign",
"keys",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/ValidatesForm.php#L122-L131 | train |
adminarchitect/core | src/Traits/Module/ValidatesForm.php | ValidatesForm.makeForeignRule | protected function makeForeignRule(Column $column, $eloquent)
{
$foreign = $this->isForeignKey($column, $eloquent);
$foreignTable = $foreign->getForeignTableName();
$foreignKey = head($foreign->getForeignColumns());
return "exists:{$foreignTable},{$foreignKey}";
} | php | protected function makeForeignRule(Column $column, $eloquent)
{
$foreign = $this->isForeignKey($column, $eloquent);
$foreignTable = $foreign->getForeignTableName();
$foreignKey = head($foreign->getForeignColumns());
return "exists:{$foreignTable},{$foreignKey}";
} | [
"protected",
"function",
"makeForeignRule",
"(",
"Column",
"$",
"column",
",",
"$",
"eloquent",
")",
"{",
"$",
"foreign",
"=",
"$",
"this",
"->",
"isForeignKey",
"(",
"$",
"column",
",",
"$",
"eloquent",
")",
";",
"$",
"foreignTable",
"=",
"$",
"foreign"... | Parse foreign keys for column presence.
@param Column $column
@param $eloquent
@return array | [
"Parse",
"foreign",
"keys",
"for",
"column",
"presence",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Module/ValidatesForm.php#L205-L212 | train |
adminarchitect/core | src/Services/Translator.php | Translator.filters | public function filters()
{
$filters = $this->files();
if ($only = config('administrator.translations.filters.only', [])) {
$filters = $filters->intersect($only);
}
if ($except = config('administrator.translations.filters.except', [])) {
$filters = $filters->diff($except);
}
return $filters;
} | php | public function filters()
{
$filters = $this->files();
if ($only = config('administrator.translations.filters.only', [])) {
$filters = $filters->intersect($only);
}
if ($except = config('administrator.translations.filters.except', [])) {
$filters = $filters->diff($except);
}
return $filters;
} | [
"public",
"function",
"filters",
"(",
")",
"{",
"$",
"filters",
"=",
"$",
"this",
"->",
"files",
"(",
")",
";",
"if",
"(",
"$",
"only",
"=",
"config",
"(",
"'administrator.translations.filters.only'",
",",
"[",
"]",
")",
")",
"{",
"$",
"filters",
"=",
... | Retrieves public filters.
@return mixed | [
"Retrieves",
"public",
"filters",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Services/Translator.php#L59-L72 | train |
adminarchitect/core | src/Navigation/Presenters/Bootstrap/SidebarMenuPresenter.php | SidebarMenuPresenter.handleItemsCount | protected function handleItemsCount($item)
{
if ($item->route
&& 'scaffold.index' === array_get($item->route, 0)
&& $module = array_get($item->route, '1.module')
) {
$module = app('scaffold.module.'.$module);
if ($count = $module->appendCount()) {
$item->count = $count;
}
}
return $item;
} | php | protected function handleItemsCount($item)
{
if ($item->route
&& 'scaffold.index' === array_get($item->route, 0)
&& $module = array_get($item->route, '1.module')
) {
$module = app('scaffold.module.'.$module);
if ($count = $module->appendCount()) {
$item->count = $count;
}
}
return $item;
} | [
"protected",
"function",
"handleItemsCount",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"route",
"&&",
"'scaffold.index'",
"===",
"array_get",
"(",
"$",
"item",
"->",
"route",
",",
"0",
")",
"&&",
"$",
"module",
"=",
"array_get",
"(",
"$... | Appends Items count to a title if needed.
@param $item | [
"Appends",
"Items",
"count",
"to",
"a",
"title",
"if",
"needed",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Navigation/Presenters/Bootstrap/SidebarMenuPresenter.php#L123-L137 | train |
adminarchitect/core | src/Traits/Actions/Skeleton.php | Skeleton.render | public function render(Eloquent $entity = null)
{
$action = app('scaffold.module')->url().'-'.$this->action($entity);
return
<<<OUTPUT
<a data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}>
<i class="fa {$this->icon($entity)}"></i> {$this->name($entity)}
</a>
OUTPUT;
} | php | public function render(Eloquent $entity = null)
{
$action = app('scaffold.module')->url().'-'.$this->action($entity);
return
<<<OUTPUT
<a data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}>
<i class="fa {$this->icon($entity)}"></i> {$this->name($entity)}
</a>
OUTPUT;
} | [
"public",
"function",
"render",
"(",
"Eloquent",
"$",
"entity",
"=",
"null",
")",
"{",
"$",
"action",
"=",
"app",
"(",
"'scaffold.module'",
")",
"->",
"url",
"(",
")",
".",
"'-'",
".",
"$",
"this",
"->",
"action",
"(",
"$",
"entity",
")",
";",
"ret... | Render action button.
@param Eloquent $entity
@return string | [
"Render",
"action",
"button",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Actions/Skeleton.php#L16-L26 | train |
adminarchitect/core | src/Traits/Actions/Skeleton.php | Skeleton.name | protected function name(Eloquent $entity = null)
{
return app('translator')->has($key = $this->translationKey())
? trans($key)
: title_case(str_replace('_', ' ', snake_case(class_basename($this))));
} | php | protected function name(Eloquent $entity = null)
{
return app('translator')->has($key = $this->translationKey())
? trans($key)
: title_case(str_replace('_', ' ', snake_case(class_basename($this))));
} | [
"protected",
"function",
"name",
"(",
"Eloquent",
"$",
"entity",
"=",
"null",
")",
"{",
"return",
"app",
"(",
"'translator'",
")",
"->",
"has",
"(",
"$",
"key",
"=",
"$",
"this",
"->",
"translationKey",
"(",
")",
")",
"?",
"trans",
"(",
"$",
"key",
... | Action name.
@param Eloquent $entity
@return string | [
"Action",
"name",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Traits/Actions/Skeleton.php#L45-L50 | train |
adminarchitect/core | src/Form/FormElement.php | FormElement.custom | public static function custom($id, $input)
{
return (new static($id))->setInput($input instanceof BasicFormElement ? $input : new $input($id));
} | php | public static function custom($id, $input)
{
return (new static($id))->setInput($input instanceof BasicFormElement ? $input : new $input($id));
} | [
"public",
"static",
"function",
"custom",
"(",
"$",
"id",
",",
"$",
"input",
")",
"{",
"return",
"(",
"new",
"static",
"(",
"$",
"id",
")",
")",
"->",
"setInput",
"(",
"$",
"input",
"instanceof",
"BasicFormElement",
"?",
"$",
"input",
":",
"new",
"$"... | Create a custom Form element.
@param $id
@param mixed string|BasicFormElement $input
@return mixed | [
"Create",
"a",
"custom",
"Form",
"element",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Form/FormElement.php#L135-L138 | train |
adminarchitect/core | src/Form/FormElement.php | FormElement.setInput | public function setInput($input)
{
if (!(is_string($input) || $input instanceof BasicFormElement)) {
throw new Exception('Input must be a String or instance of FormElement Contract');
}
if (is_string($input)) {
$input = $this->makeInput($input);
}
$this->input = $input;
return $this;
} | php | public function setInput($input)
{
if (!(is_string($input) || $input instanceof BasicFormElement)) {
throw new Exception('Input must be a String or instance of FormElement Contract');
}
if (is_string($input)) {
$input = $this->makeInput($input);
}
$this->input = $input;
return $this;
} | [
"public",
"function",
"setInput",
"(",
"$",
"input",
")",
"{",
"if",
"(",
"!",
"(",
"is_string",
"(",
"$",
"input",
")",
"||",
"$",
"input",
"instanceof",
"BasicFormElement",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Input must be a String or instan... | Set wrapped input object.
@param mixed string|FormElement $input
@throws Exception
@return $this | [
"Set",
"wrapped",
"input",
"object",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Form/FormElement.php#L157-L170 | train |
adminarchitect/core | src/Filters/Assembler.php | Assembler.scope | public function scope(Scope $scope)
{
$callable = $scope->getQuery();
if (is_string($callable)) {
/*
* Adds a Class "ClassName::class" syntax.
*
* @note In this case Query class should implement Contracts\Module\Queryable interface.
* @example: (new Scope('name'))->setQuery(Queryable::class);
*/
if (class_exists($callable)) {
$object = app($callable);
if (!method_exists($object, 'query')) {
throw new \Terranet\Administrator\Exception(
sprintf(
'Query object %s should implement %s interface',
get_class($object),
\Terranet\Administrator\Contracts\Module\Queryable::class
)
);
}
$this->query = $object->query($this->query);
return $this;
}
/*
* Allows "SomeClass@method" syntax.
*
* @example: (new Scope('name'))->addQuery("User@active")
*/
if (str_contains($callable, '@')) {
list($object, $method) = explode('@', $callable);
$this->query = app($object)->$method($this->query);
return $this;
}
}
/*
* Allows adding a \Closure as a query;
*
* @example: (new Scope('name'))->setQuery(function($query) { return $this->modify(); })
*/
if ($callable instanceof Closure) {
$this->query = $callable($this->query);
return $this;
}
/*
* Accepts callable builder
*
* @example: (new Scope('name'))->setQuery([SomeClass::class, "queryMethod"]);
*/
if (is_callable($callable)) {
list($object, $method) = $callable;
if (is_string($object)) {
$object = app($object);
}
// Call Model Scope immediately when detected.
//
// @note: We don't use call_user_func_array() here
// because of missing columns in returned query.
$this->query = with(
$this->model->is($object) ? $this->query : $object
)->{$method}($this->query);
}
return $this;
} | php | public function scope(Scope $scope)
{
$callable = $scope->getQuery();
if (is_string($callable)) {
/*
* Adds a Class "ClassName::class" syntax.
*
* @note In this case Query class should implement Contracts\Module\Queryable interface.
* @example: (new Scope('name'))->setQuery(Queryable::class);
*/
if (class_exists($callable)) {
$object = app($callable);
if (!method_exists($object, 'query')) {
throw new \Terranet\Administrator\Exception(
sprintf(
'Query object %s should implement %s interface',
get_class($object),
\Terranet\Administrator\Contracts\Module\Queryable::class
)
);
}
$this->query = $object->query($this->query);
return $this;
}
/*
* Allows "SomeClass@method" syntax.
*
* @example: (new Scope('name'))->addQuery("User@active")
*/
if (str_contains($callable, '@')) {
list($object, $method) = explode('@', $callable);
$this->query = app($object)->$method($this->query);
return $this;
}
}
/*
* Allows adding a \Closure as a query;
*
* @example: (new Scope('name'))->setQuery(function($query) { return $this->modify(); })
*/
if ($callable instanceof Closure) {
$this->query = $callable($this->query);
return $this;
}
/*
* Accepts callable builder
*
* @example: (new Scope('name'))->setQuery([SomeClass::class, "queryMethod"]);
*/
if (is_callable($callable)) {
list($object, $method) = $callable;
if (is_string($object)) {
$object = app($object);
}
// Call Model Scope immediately when detected.
//
// @note: We don't use call_user_func_array() here
// because of missing columns in returned query.
$this->query = with(
$this->model->is($object) ? $this->query : $object
)->{$method}($this->query);
}
return $this;
} | [
"public",
"function",
"scope",
"(",
"Scope",
"$",
"scope",
")",
"{",
"$",
"callable",
"=",
"$",
"scope",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"callable",
")",
")",
"{",
"/*\n * Adds a Class \"ClassName::class\" syntax.... | Apply scope.
@param Scope $scope
@throws \Terranet\Administrator\Exception
@return $this | [
"Apply",
"scope",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Filters/Assembler.php#L78-L154 | train |
adminarchitect/core | src/Filters/Assembler.php | Assembler.sort | public function sort($element, $direction)
{
// simple sorting
if (in_array($element, $sortable = app('scaffold.module')->sortable(), true)) {
if ($table = app('scaffold.module')->model()->getTable()) {
$element = "{$table}.{$element}";
}
$this->query->orderBy($element, $direction);
}
if (array_key_exists($element, $sortable) && is_callable($callback = $sortable[$element])) {
$this->query = call_user_func_array($callback, [$this->query, $element, $direction]);
}
if (array_key_exists($element, $sortable) && is_string($handler = $sortable[$element])) {
$handler = new $handler($this->query, $element, $direction);
if (!$handler instanceof QueryBuilder || !method_exists($handler, 'build')) {
throw new \Exception('Handler class must implement '.QueryBuilder::class.' contract');
}
$this->query = $handler->build();
}
return $this;
} | php | public function sort($element, $direction)
{
// simple sorting
if (in_array($element, $sortable = app('scaffold.module')->sortable(), true)) {
if ($table = app('scaffold.module')->model()->getTable()) {
$element = "{$table}.{$element}";
}
$this->query->orderBy($element, $direction);
}
if (array_key_exists($element, $sortable) && is_callable($callback = $sortable[$element])) {
$this->query = call_user_func_array($callback, [$this->query, $element, $direction]);
}
if (array_key_exists($element, $sortable) && is_string($handler = $sortable[$element])) {
$handler = new $handler($this->query, $element, $direction);
if (!$handler instanceof QueryBuilder || !method_exists($handler, 'build')) {
throw new \Exception('Handler class must implement '.QueryBuilder::class.' contract');
}
$this->query = $handler->build();
}
return $this;
} | [
"public",
"function",
"sort",
"(",
"$",
"element",
",",
"$",
"direction",
")",
"{",
"// simple sorting",
"if",
"(",
"in_array",
"(",
"$",
"element",
",",
"$",
"sortable",
"=",
"app",
"(",
"'scaffold.module'",
")",
"->",
"sortable",
"(",
")",
",",
"true",... | Apply ordering.
@param $element
@param $direction
@throws \Exception
@return $this | [
"Apply",
"ordering",
"."
] | 817ead2640631b81ae15bc2a8555bc22159058bb | https://github.com/adminarchitect/core/blob/817ead2640631b81ae15bc2a8555bc22159058bb/src/Filters/Assembler.php#L166-L190 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.