id int32 0 241k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
30,600 | tylercd100/lern | src/Components/Recorder.php | Recorder.excludeKeys | protected function excludeKeys(array $data) {
$keys = isset($this->config['excludeKeys']) ? $this->config['excludeKeys'] : [];
foreach ($data as $key => &$value) {
if (in_array($key, $keys)) {
unset($data[$key]);
} else if (is_array($value)) {
$value = $this->excludeKeys($value);
}
}
return $data;
} | php | protected function excludeKeys(array $data) {
$keys = isset($this->config['excludeKeys']) ? $this->config['excludeKeys'] : [];
foreach ($data as $key => &$value) {
if (in_array($key, $keys)) {
unset($data[$key]);
} else if (is_array($value)) {
$value = $this->excludeKeys($value);
}
}
return $data;
} | [
"protected",
"function",
"excludeKeys",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"keys",
"=",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'excludeKeys'",
"]",
")",
"?",
"$",
"this",
"->",
"config",
"[",
"'excludeKeys'",
"]",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"keys",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"excludeKeys",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | This function will remove all keys from an array recursively as defined in the config file
@param array $data The array to remove keys from
@return void | [
"This",
"function",
"will",
"remove",
"all",
"keys",
"from",
"an",
"array",
"recursively",
"as",
"defined",
"in",
"the",
"config",
"file"
] | ab6b602d11447d305770aa8cbb79278428dd2244 | https://github.com/tylercd100/lern/blob/ab6b602d11447d305770aa8cbb79278428dd2244/src/Components/Recorder.php#L203-L214 |
30,601 | BKWLD/decoy | classes/Commands/Admin.php | Admin.handle | public function handle()
{
$firstName = $this->ask('First Name');
$lastName = $this->ask('Last Name');
$email = $this->ask('Email');
// Check the email to see if its already being used
if ($admin = BkwldAdmin::where('email', $email)->exists()) {
$this->error('That email is already in use');
return;
}
$password = $this->secret('Enter your password');
$confirm = $this->secret('Confirm your password');
// password matching check
if ($password != $confirm) {
$this->error('Your passwords do not match.');
return;
}
// Create a new admin
$admin = new BkwldAdmin;
$admin->first_name = $firstName;
$admin->last_name = $lastName;
$admin->email = $email;
$admin->password = $password;
// Save out the new admin
$admin->save();
$this->info('Admin created!');
} | php | public function handle()
{
$firstName = $this->ask('First Name');
$lastName = $this->ask('Last Name');
$email = $this->ask('Email');
// Check the email to see if its already being used
if ($admin = BkwldAdmin::where('email', $email)->exists()) {
$this->error('That email is already in use');
return;
}
$password = $this->secret('Enter your password');
$confirm = $this->secret('Confirm your password');
// password matching check
if ($password != $confirm) {
$this->error('Your passwords do not match.');
return;
}
// Create a new admin
$admin = new BkwldAdmin;
$admin->first_name = $firstName;
$admin->last_name = $lastName;
$admin->email = $email;
$admin->password = $password;
// Save out the new admin
$admin->save();
$this->info('Admin created!');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"firstName",
"=",
"$",
"this",
"->",
"ask",
"(",
"'First Name'",
")",
";",
"$",
"lastName",
"=",
"$",
"this",
"->",
"ask",
"(",
"'Last Name'",
")",
";",
"$",
"email",
"=",
"$",
"this",
"->",
"ask",
"(",
"'Email'",
")",
";",
"// Check the email to see if its already being used",
"if",
"(",
"$",
"admin",
"=",
"BkwldAdmin",
"::",
"where",
"(",
"'email'",
",",
"$",
"email",
")",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'That email is already in use'",
")",
";",
"return",
";",
"}",
"$",
"password",
"=",
"$",
"this",
"->",
"secret",
"(",
"'Enter your password'",
")",
";",
"$",
"confirm",
"=",
"$",
"this",
"->",
"secret",
"(",
"'Confirm your password'",
")",
";",
"// password matching check",
"if",
"(",
"$",
"password",
"!=",
"$",
"confirm",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Your passwords do not match.'",
")",
";",
"return",
";",
"}",
"// Create a new admin",
"$",
"admin",
"=",
"new",
"BkwldAdmin",
";",
"$",
"admin",
"->",
"first_name",
"=",
"$",
"firstName",
";",
"$",
"admin",
"->",
"last_name",
"=",
"$",
"lastName",
";",
"$",
"admin",
"->",
"email",
"=",
"$",
"email",
";",
"$",
"admin",
"->",
"password",
"=",
"$",
"password",
";",
"// Save out the new admin",
"$",
"admin",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Admin created!'",
")",
";",
"}"
] | Create the new admin with input from the user
@return void | [
"Create",
"the",
"new",
"admin",
"with",
"input",
"from",
"the",
"user"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Admin.php#L29-L62 |
30,602 | BKWLD/decoy | classes/Models/RedirectRule.php | RedirectRule.onValidating | public function onValidating($validation)
{
// Clean up "from" route, stripping host and leading slash
$this->from = preg_replace('#^([^/]*//[^/]+)?/?#', '', $this->from);
// Make an absolute path if the current domain is entered
$this->to = Utils\URL::urlToAbsolutePath($this->to);
// Add row exception for unique
if ($this->exists) {
$rules = $validation->getRules();
$rules['from'][1] .= ','.$this->getKey();
$validation->setRules($rules);
}
} | php | public function onValidating($validation)
{
// Clean up "from" route, stripping host and leading slash
$this->from = preg_replace('#^([^/]*//[^/]+)?/?#', '', $this->from);
// Make an absolute path if the current domain is entered
$this->to = Utils\URL::urlToAbsolutePath($this->to);
// Add row exception for unique
if ($this->exists) {
$rules = $validation->getRules();
$rules['from'][1] .= ','.$this->getKey();
$validation->setRules($rules);
}
} | [
"public",
"function",
"onValidating",
"(",
"$",
"validation",
")",
"{",
"// Clean up \"from\" route, stripping host and leading slash",
"$",
"this",
"->",
"from",
"=",
"preg_replace",
"(",
"'#^([^/]*//[^/]+)?/?#'",
",",
"''",
",",
"$",
"this",
"->",
"from",
")",
";",
"// Make an absolute path if the current domain is entered",
"$",
"this",
"->",
"to",
"=",
"Utils",
"\\",
"URL",
"::",
"urlToAbsolutePath",
"(",
"$",
"this",
"->",
"to",
")",
";",
"// Add row exception for unique",
"if",
"(",
"$",
"this",
"->",
"exists",
")",
"{",
"$",
"rules",
"=",
"$",
"validation",
"->",
"getRules",
"(",
")",
";",
"$",
"rules",
"[",
"'from'",
"]",
"[",
"1",
"]",
".=",
"','",
".",
"$",
"this",
"->",
"getKey",
"(",
")",
";",
"$",
"validation",
"->",
"setRules",
"(",
"$",
"rules",
")",
";",
"}",
"}"
] | Pre-validation rules
@param Illuminate\Validation\Validator $validation
@return null | [
"Pre",
"-",
"validation",
"rules"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/RedirectRule.php#L72-L86 |
30,603 | BKWLD/decoy | classes/Models/RedirectRule.php | RedirectRule.scopeMatchUsingRequest | public function scopeMatchUsingRequest($query)
{
return $query->where(function ($query) {
$from = $this->pathAndQuery();
$escaped_from = DB::connection()->getPdo()->quote($from);
$from_col = DB::getDriverName() == 'sqlsrv' ? '[from]' : '`from`';
$query->where('from', $from)->orWhereRaw("{$escaped_from} LIKE {$from_col}");
if (Config::get('decoy::core.allow_regex_in_redirects')) {
$query->orWhereRaw("{$escaped_from} REGEXP {$from_col}");
}
});
} | php | public function scopeMatchUsingRequest($query)
{
return $query->where(function ($query) {
$from = $this->pathAndQuery();
$escaped_from = DB::connection()->getPdo()->quote($from);
$from_col = DB::getDriverName() == 'sqlsrv' ? '[from]' : '`from`';
$query->where('from', $from)->orWhereRaw("{$escaped_from} LIKE {$from_col}");
if (Config::get('decoy::core.allow_regex_in_redirects')) {
$query->orWhereRaw("{$escaped_from} REGEXP {$from_col}");
}
});
} | [
"public",
"function",
"scopeMatchUsingRequest",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"from",
"=",
"$",
"this",
"->",
"pathAndQuery",
"(",
")",
";",
"$",
"escaped_from",
"=",
"DB",
"::",
"connection",
"(",
")",
"->",
"getPdo",
"(",
")",
"->",
"quote",
"(",
"$",
"from",
")",
";",
"$",
"from_col",
"=",
"DB",
"::",
"getDriverName",
"(",
")",
"==",
"'sqlsrv'",
"?",
"'[from]'",
":",
"'`from`'",
";",
"$",
"query",
"->",
"where",
"(",
"'from'",
",",
"$",
"from",
")",
"->",
"orWhereRaw",
"(",
"\"{$escaped_from} LIKE {$from_col}\"",
")",
";",
"if",
"(",
"Config",
"::",
"get",
"(",
"'decoy::core.allow_regex_in_redirects'",
")",
")",
"{",
"$",
"query",
"->",
"orWhereRaw",
"(",
"\"{$escaped_from} REGEXP {$from_col}\"",
")",
";",
"}",
"}",
")",
";",
"}"
] | See if the current request matches the "FROM" using progressively more
expensive ways to match the from column.
@param Illuminate\Database\Query\Builder $query
@return void | [
"See",
"if",
"the",
"current",
"request",
"matches",
"the",
"FROM",
"using",
"progressively",
"more",
"expensive",
"ways",
"to",
"match",
"the",
"from",
"column",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/RedirectRule.php#L107-L118 |
30,604 | BKWLD/decoy | classes/Models/RedirectRule.php | RedirectRule.pathAndQuery | public function pathAndQuery()
{
$query = Request::getQueryString();
$path = ltrim(Request::path(), '/'); // ltrim fixes homepage
return $query ? $path.'?'.$query : $path;
} | php | public function pathAndQuery()
{
$query = Request::getQueryString();
$path = ltrim(Request::path(), '/'); // ltrim fixes homepage
return $query ? $path.'?'.$query : $path;
} | [
"public",
"function",
"pathAndQuery",
"(",
")",
"{",
"$",
"query",
"=",
"Request",
"::",
"getQueryString",
"(",
")",
";",
"$",
"path",
"=",
"ltrim",
"(",
"Request",
"::",
"path",
"(",
")",
",",
"'/'",
")",
";",
"// ltrim fixes homepage",
"return",
"$",
"query",
"?",
"$",
"path",
".",
"'?'",
".",
"$",
"query",
":",
"$",
"path",
";",
"}"
] | Get the path and query from the request
@return string | [
"Get",
"the",
"path",
"and",
"query",
"from",
"the",
"request"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/RedirectRule.php#L125-L130 |
30,605 | BKWLD/decoy | classes/Fields/Listing.php | Listing.createFromController | public static function createFromController($controller, $items)
{
$model = $controller->model();
return Former::listing($model, null, null, null, [
'controller' => $controller,
'items' => $items,
]);
} | php | public static function createFromController($controller, $items)
{
$model = $controller->model();
return Former::listing($model, null, null, null, [
'controller' => $controller,
'items' => $items,
]);
} | [
"public",
"static",
"function",
"createFromController",
"(",
"$",
"controller",
",",
"$",
"items",
")",
"{",
"$",
"model",
"=",
"$",
"controller",
"->",
"model",
"(",
")",
";",
"return",
"Former",
"::",
"listing",
"(",
"$",
"model",
",",
"null",
",",
"null",
",",
"null",
",",
"[",
"'controller'",
"=>",
"$",
"controller",
",",
"'items'",
"=>",
"$",
"items",
",",
"]",
")",
";",
"}"
] | A factory to create an instance using the passed controller. This is to prevent
duplicate controller instantations when invoked from the base controller.
@param Bkwld\Decoy\Controllers\Base $controller
@param LengthAwarePaginator $items
@return Bkwld\Decoy\Field\Listing | [
"A",
"factory",
"to",
"create",
"an",
"instance",
"using",
"the",
"passed",
"controller",
".",
"This",
"is",
"to",
"prevent",
"duplicate",
"controller",
"instantations",
"when",
"invoked",
"from",
"the",
"base",
"controller",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L136-L144 |
30,606 | BKWLD/decoy | classes/Fields/Listing.php | Listing.controller | public function controller($controller)
{
// Instantiate a string controller
if (is_string($controller)
&& class_exists($controller)
&& is_subclass_of($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = $controller;
$this->controller = new $controller;
// Apply the parent if one was set
if ($this->parent_item && $this->controller) {
$this->controller->parent($this->parent_item);
}
// Or, validate a passed controller instance
} elseif (is_object($controller)
&& is_a($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = get_class($controller);
$this->controller = $controller;
}
// Chain
return $this;
} | php | public function controller($controller)
{
// Instantiate a string controller
if (is_string($controller)
&& class_exists($controller)
&& is_subclass_of($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = $controller;
$this->controller = new $controller;
// Apply the parent if one was set
if ($this->parent_item && $this->controller) {
$this->controller->parent($this->parent_item);
}
// Or, validate a passed controller instance
} elseif (is_object($controller)
&& is_a($controller, 'Bkwld\Decoy\Controllers\Base')) {
$this->controller_name = get_class($controller);
$this->controller = $controller;
}
// Chain
return $this;
} | [
"public",
"function",
"controller",
"(",
"$",
"controller",
")",
"{",
"// Instantiate a string controller",
"if",
"(",
"is_string",
"(",
"$",
"controller",
")",
"&&",
"class_exists",
"(",
"$",
"controller",
")",
"&&",
"is_subclass_of",
"(",
"$",
"controller",
",",
"'Bkwld\\Decoy\\Controllers\\Base'",
")",
")",
"{",
"$",
"this",
"->",
"controller_name",
"=",
"$",
"controller",
";",
"$",
"this",
"->",
"controller",
"=",
"new",
"$",
"controller",
";",
"// Apply the parent if one was set",
"if",
"(",
"$",
"this",
"->",
"parent_item",
"&&",
"$",
"this",
"->",
"controller",
")",
"{",
"$",
"this",
"->",
"controller",
"->",
"parent",
"(",
"$",
"this",
"->",
"parent_item",
")",
";",
"}",
"// Or, validate a passed controller instance",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"controller",
")",
"&&",
"is_a",
"(",
"$",
"controller",
",",
"'Bkwld\\Decoy\\Controllers\\Base'",
")",
")",
"{",
"$",
"this",
"->",
"controller_name",
"=",
"get_class",
"(",
"$",
"controller",
")",
";",
"$",
"this",
"->",
"controller",
"=",
"$",
"controller",
";",
"}",
"// Chain",
"return",
"$",
"this",
";",
"}"
] | Replace the controller
@param Bkwld\Decoy\Controllers\Base | string $controller
@return Field This field | [
"Replace",
"the",
"controller"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L152-L176 |
30,607 | BKWLD/decoy | classes/Fields/Listing.php | Listing.wrapAndRender | public function wrapAndRender()
{
// Don't set an id
$this->setAttribute('id', false);
// Because it's a field, Former will add this. But it's not really
// appropriate for a listing
$this->removeClass('form-control');
// Render the markup
if ($this->layout == 'form') {
return $this->wrapInControlGroup();
}
return $this->render();
} | php | public function wrapAndRender()
{
// Don't set an id
$this->setAttribute('id', false);
// Because it's a field, Former will add this. But it's not really
// appropriate for a listing
$this->removeClass('form-control');
// Render the markup
if ($this->layout == 'form') {
return $this->wrapInControlGroup();
}
return $this->render();
} | [
"public",
"function",
"wrapAndRender",
"(",
")",
"{",
"// Don't set an id",
"$",
"this",
"->",
"setAttribute",
"(",
"'id'",
",",
"false",
")",
";",
"// Because it's a field, Former will add this. But it's not really",
"// appropriate for a listing",
"$",
"this",
"->",
"removeClass",
"(",
"'form-control'",
")",
";",
"// Render the markup",
"if",
"(",
"$",
"this",
"->",
"layout",
"==",
"'form'",
")",
"{",
"return",
"$",
"this",
"->",
"wrapInControlGroup",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
")",
";",
"}"
] | Render the layout, .i.e. put it in a control group or a different
wrapper
@return string HTML | [
"Render",
"the",
"layout",
".",
"i",
".",
"e",
".",
"put",
"it",
"in",
"a",
"control",
"group",
"or",
"a",
"different",
"wrapper"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L254-L269 |
30,608 | BKWLD/decoy | classes/Fields/Listing.php | Listing.wrapInControlGroup | protected function wrapInControlGroup()
{
// Add generic stuff
$this->addGroupClass('list-form-group');
// Use the controller description for blockhelp
if (!$this->hasHelp()) {
$this->blockhelp($this->controller->description());
}
// Show no results if there is no parent specified
if (empty($this->parent_item)) {
$this->addGroupClass('note');
return $this->group->wrapField(Former::note($this->label_text, trans('decoy::form.listing.pending_save', ['model' => $this->label_text, 'description' => $this->controller->description()])));
}
// Add create button if we have permission and if there is a parent item
if (app('decoy.user')->can('create', $this->controller)) {
$this->group->setLabel(
'<a href="'.$this->getIndexURL().'">'
.$this->label_text
.'</a>'
.$this->makeCreateBtn()
);
}
// Return the wrapped field
return $this->group->wrapField($this);
} | php | protected function wrapInControlGroup()
{
// Add generic stuff
$this->addGroupClass('list-form-group');
// Use the controller description for blockhelp
if (!$this->hasHelp()) {
$this->blockhelp($this->controller->description());
}
// Show no results if there is no parent specified
if (empty($this->parent_item)) {
$this->addGroupClass('note');
return $this->group->wrapField(Former::note($this->label_text, trans('decoy::form.listing.pending_save', ['model' => $this->label_text, 'description' => $this->controller->description()])));
}
// Add create button if we have permission and if there is a parent item
if (app('decoy.user')->can('create', $this->controller)) {
$this->group->setLabel(
'<a href="'.$this->getIndexURL().'">'
.$this->label_text
.'</a>'
.$this->makeCreateBtn()
);
}
// Return the wrapped field
return $this->group->wrapField($this);
} | [
"protected",
"function",
"wrapInControlGroup",
"(",
")",
"{",
"// Add generic stuff",
"$",
"this",
"->",
"addGroupClass",
"(",
"'list-form-group'",
")",
";",
"// Use the controller description for blockhelp",
"if",
"(",
"!",
"$",
"this",
"->",
"hasHelp",
"(",
")",
")",
"{",
"$",
"this",
"->",
"blockhelp",
"(",
"$",
"this",
"->",
"controller",
"->",
"description",
"(",
")",
")",
";",
"}",
"// Show no results if there is no parent specified",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parent_item",
")",
")",
"{",
"$",
"this",
"->",
"addGroupClass",
"(",
"'note'",
")",
";",
"return",
"$",
"this",
"->",
"group",
"->",
"wrapField",
"(",
"Former",
"::",
"note",
"(",
"$",
"this",
"->",
"label_text",
",",
"trans",
"(",
"'decoy::form.listing.pending_save'",
",",
"[",
"'model'",
"=>",
"$",
"this",
"->",
"label_text",
",",
"'description'",
"=>",
"$",
"this",
"->",
"controller",
"->",
"description",
"(",
")",
"]",
")",
")",
")",
";",
"}",
"// Add create button if we have permission and if there is a parent item",
"if",
"(",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'create'",
",",
"$",
"this",
"->",
"controller",
")",
")",
"{",
"$",
"this",
"->",
"group",
"->",
"setLabel",
"(",
"'<a href=\"'",
".",
"$",
"this",
"->",
"getIndexURL",
"(",
")",
".",
"'\">'",
".",
"$",
"this",
"->",
"label_text",
".",
"'</a>'",
".",
"$",
"this",
"->",
"makeCreateBtn",
"(",
")",
")",
";",
"}",
"// Return the wrapped field",
"return",
"$",
"this",
"->",
"group",
"->",
"wrapField",
"(",
"$",
"this",
")",
";",
"}"
] | Add customization to the control group rendering
@return string HTML | [
"Add",
"customization",
"to",
"the",
"control",
"group",
"rendering"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L276-L305 |
30,609 | BKWLD/decoy | classes/Fields/Listing.php | Listing.getIndexURL | protected function getIndexURL()
{
return $this->controller->isChildInManyToMany() ?
DecoyURL::action($this->controller_name.'@index') :
DecoyURL::relative('index', null, $this->controller_name);
} | php | protected function getIndexURL()
{
return $this->controller->isChildInManyToMany() ?
DecoyURL::action($this->controller_name.'@index') :
DecoyURL::relative('index', null, $this->controller_name);
} | [
"protected",
"function",
"getIndexURL",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"controller",
"->",
"isChildInManyToMany",
"(",
")",
"?",
"DecoyURL",
"::",
"action",
"(",
"$",
"this",
"->",
"controller_name",
".",
"'@index'",
")",
":",
"DecoyURL",
"::",
"relative",
"(",
"'index'",
",",
"null",
",",
"$",
"this",
"->",
"controller_name",
")",
";",
"}"
] | Get the index URL for this controller
@return string URL | [
"Get",
"the",
"index",
"URL",
"for",
"this",
"controller"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L383-L388 |
30,610 | BKWLD/decoy | classes/Fields/Listing.php | Listing.getColumns | protected function getColumns($controller)
{
// If user has defined columns, use them
if ($this->columns) {
return $this->columns;
}
// Read columns from the controller
$columns = $controller->columns();
// If showing in sidebar, only show the first column
// http://stackoverflow.com/a/1028677/59160
if ($this->layout == 'sidebar') {
$val = reset($columns); // Making sure this gets called before `key()`
return [key($columns) => $val];
// Otherwise, just return all columns
}
return $columns;
} | php | protected function getColumns($controller)
{
// If user has defined columns, use them
if ($this->columns) {
return $this->columns;
}
// Read columns from the controller
$columns = $controller->columns();
// If showing in sidebar, only show the first column
// http://stackoverflow.com/a/1028677/59160
if ($this->layout == 'sidebar') {
$val = reset($columns); // Making sure this gets called before `key()`
return [key($columns) => $val];
// Otherwise, just return all columns
}
return $columns;
} | [
"protected",
"function",
"getColumns",
"(",
"$",
"controller",
")",
"{",
"// If user has defined columns, use them",
"if",
"(",
"$",
"this",
"->",
"columns",
")",
"{",
"return",
"$",
"this",
"->",
"columns",
";",
"}",
"// Read columns from the controller",
"$",
"columns",
"=",
"$",
"controller",
"->",
"columns",
"(",
")",
";",
"// If showing in sidebar, only show the first column",
"// http://stackoverflow.com/a/1028677/59160",
"if",
"(",
"$",
"this",
"->",
"layout",
"==",
"'sidebar'",
")",
"{",
"$",
"val",
"=",
"reset",
"(",
"$",
"columns",
")",
";",
"// Making sure this gets called before `key()`",
"return",
"[",
"key",
"(",
"$",
"columns",
")",
"=>",
"$",
"val",
"]",
";",
"// Otherwise, just return all columns",
"}",
"return",
"$",
"columns",
";",
"}"
] | Get the list of columns of the controller
@param Bkwld\Decoy\Controller\Base $controller A controller instance
@return array Associative array of column keys and values | [
"Get",
"the",
"list",
"of",
"columns",
"of",
"the",
"controller"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L408-L428 |
30,611 | BKWLD/decoy | classes/Fields/Listing.php | Listing.queryForItems | protected function queryForItems()
{
// If there is a parent, run the query through the relationship to this model
// from the parent
if ($this->parent_item) {
$relationship = Decoy::hasManyName($this->name);
$query = $this->parent_item->$relationship()->ordered();
}
// Otherwise, open up the query using ordered
else {
$query = call_user_func($this->name.'::ordered');
}
// Apply any custom scope
if ($this->scope) {
call_user_func($this->scope, $query);
}
// Retrieve the results through paginator
return $query->paginate($this->perPage());
} | php | protected function queryForItems()
{
// If there is a parent, run the query through the relationship to this model
// from the parent
if ($this->parent_item) {
$relationship = Decoy::hasManyName($this->name);
$query = $this->parent_item->$relationship()->ordered();
}
// Otherwise, open up the query using ordered
else {
$query = call_user_func($this->name.'::ordered');
}
// Apply any custom scope
if ($this->scope) {
call_user_func($this->scope, $query);
}
// Retrieve the results through paginator
return $query->paginate($this->perPage());
} | [
"protected",
"function",
"queryForItems",
"(",
")",
"{",
"// If there is a parent, run the query through the relationship to this model",
"// from the parent",
"if",
"(",
"$",
"this",
"->",
"parent_item",
")",
"{",
"$",
"relationship",
"=",
"Decoy",
"::",
"hasManyName",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"parent_item",
"->",
"$",
"relationship",
"(",
")",
"->",
"ordered",
"(",
")",
";",
"}",
"// Otherwise, open up the query using ordered",
"else",
"{",
"$",
"query",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"name",
".",
"'::ordered'",
")",
";",
"}",
"// Apply any custom scope",
"if",
"(",
"$",
"this",
"->",
"scope",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"scope",
",",
"$",
"query",
")",
";",
"}",
"// Retrieve the results through paginator",
"return",
"$",
"query",
"->",
"paginate",
"(",
"$",
"this",
"->",
"perPage",
"(",
")",
")",
";",
"}"
] | Write an execute a query to get the list of items
@return LengthAwarePaginator | [
"Write",
"an",
"execute",
"a",
"query",
"to",
"get",
"the",
"list",
"of",
"items"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L451-L472 |
30,612 | BKWLD/decoy | classes/Fields/Listing.php | Listing.perPage | protected function perPage()
{
// If the user specified a limit, use it
if ($this->take) {
return $this->take;
}
// If a sidebar, use the default
if ($this->layout == 'sidebar') {
$name = $this->controller_name;
return $name::$per_sidebar;
}
// Else, use the controller's pagination logic
return $this->controller->perPage();
} | php | protected function perPage()
{
// If the user specified a limit, use it
if ($this->take) {
return $this->take;
}
// If a sidebar, use the default
if ($this->layout == 'sidebar') {
$name = $this->controller_name;
return $name::$per_sidebar;
}
// Else, use the controller's pagination logic
return $this->controller->perPage();
} | [
"protected",
"function",
"perPage",
"(",
")",
"{",
"// If the user specified a limit, use it",
"if",
"(",
"$",
"this",
"->",
"take",
")",
"{",
"return",
"$",
"this",
"->",
"take",
";",
"}",
"// If a sidebar, use the default",
"if",
"(",
"$",
"this",
"->",
"layout",
"==",
"'sidebar'",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"controller_name",
";",
"return",
"$",
"name",
"::",
"$",
"per_sidebar",
";",
"}",
"// Else, use the controller's pagination logic",
"return",
"$",
"this",
"->",
"controller",
"->",
"perPage",
"(",
")",
";",
"}"
] | Get the amount per page be looking at a number of different sources
@return int The amount | [
"Get",
"the",
"amount",
"per",
"page",
"be",
"looking",
"at",
"a",
"number",
"of",
"different",
"sources"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Listing.php#L479-L495 |
30,613 | BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.registerDirectories | public function registerDirectories()
{
// Publish config files
$this->publishes([
__DIR__.'/../config' => config_path('decoy')
], 'config');
// Publish decoy css and js to public directory
$this->publishes([
__DIR__.'/../dist' => public_path('assets/decoy')
], 'assets');
// Publish lanaguage files
$this->publishes([
__DIR__.'/../lang' => resource_path('lang/vendor/decoy')
], 'lang');
// Register views
$this->loadViewsFrom(__DIR__.'/../views', 'decoy');
// Load translations
$this->loadTranslationsFrom(__DIR__.'/../lang', 'decoy');
// Load migrations
$this->loadMigrationsFrom(__DIR__.'/../migrations/');
} | php | public function registerDirectories()
{
// Publish config files
$this->publishes([
__DIR__.'/../config' => config_path('decoy')
], 'config');
// Publish decoy css and js to public directory
$this->publishes([
__DIR__.'/../dist' => public_path('assets/decoy')
], 'assets');
// Publish lanaguage files
$this->publishes([
__DIR__.'/../lang' => resource_path('lang/vendor/decoy')
], 'lang');
// Register views
$this->loadViewsFrom(__DIR__.'/../views', 'decoy');
// Load translations
$this->loadTranslationsFrom(__DIR__.'/../lang', 'decoy');
// Load migrations
$this->loadMigrationsFrom(__DIR__.'/../migrations/');
} | [
"public",
"function",
"registerDirectories",
"(",
")",
"{",
"// Publish config files",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../config'",
"=>",
"config_path",
"(",
"'decoy'",
")",
"]",
",",
"'config'",
")",
";",
"// Publish decoy css and js to public directory",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../dist'",
"=>",
"public_path",
"(",
"'assets/decoy'",
")",
"]",
",",
"'assets'",
")",
";",
"// Publish lanaguage files",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../lang'",
"=>",
"resource_path",
"(",
"'lang/vendor/decoy'",
")",
"]",
",",
"'lang'",
")",
";",
"// Register views",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"__DIR__",
".",
"'/../views'",
",",
"'decoy'",
")",
";",
"// Load translations",
"$",
"this",
"->",
"loadTranslationsFrom",
"(",
"__DIR__",
".",
"'/../lang'",
",",
"'decoy'",
")",
";",
"// Load migrations",
"$",
"this",
"->",
"loadMigrationsFrom",
"(",
"__DIR__",
".",
"'/../migrations/'",
")",
";",
"}"
] | Register configs, migrations, etc
@return void | [
"Register",
"configs",
"migrations",
"etc"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L61-L86 |
30,614 | BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.usingAdmin | public function usingAdmin()
{
// Define constants that Decoy uses
if (!defined('FORMAT_DATE')) {
define('FORMAT_DATE', __('decoy::base.constants.format_date'));
}
if (!defined('FORMAT_DATETIME')) {
define('FORMAT_DATETIME', __('decoy::base.constants.format_datetime'));
}
if (!defined('FORMAT_TIME')) {
define('FORMAT_TIME', __('decoy::base.constants.format_time'));
}
// Register global and named middlewares
$this->registerMiddlewares();
// Use Decoy's auth by default, while at an admin path
Config::set('auth.defaults', [
'guard' => 'decoy',
'passwords' => 'decoy',
]);
// Set the default mailer settings
Config::set('mail.from', [
'address' => Config::get('decoy.core.mail_from_address'),
'name' => Config::get('decoy.core.mail_from_name'),
]);
// Config Former
$this->configureFormer();
// Delegate events to Decoy observers
$this->delegateAdminObservers();
// Use Boostrap 3 classes in Laravel 5.6
if (method_exists(Paginator::class, 'useBootstrapThree')) {
Paginator::useBootstrapThree();
}
} | php | public function usingAdmin()
{
// Define constants that Decoy uses
if (!defined('FORMAT_DATE')) {
define('FORMAT_DATE', __('decoy::base.constants.format_date'));
}
if (!defined('FORMAT_DATETIME')) {
define('FORMAT_DATETIME', __('decoy::base.constants.format_datetime'));
}
if (!defined('FORMAT_TIME')) {
define('FORMAT_TIME', __('decoy::base.constants.format_time'));
}
// Register global and named middlewares
$this->registerMiddlewares();
// Use Decoy's auth by default, while at an admin path
Config::set('auth.defaults', [
'guard' => 'decoy',
'passwords' => 'decoy',
]);
// Set the default mailer settings
Config::set('mail.from', [
'address' => Config::get('decoy.core.mail_from_address'),
'name' => Config::get('decoy.core.mail_from_name'),
]);
// Config Former
$this->configureFormer();
// Delegate events to Decoy observers
$this->delegateAdminObservers();
// Use Boostrap 3 classes in Laravel 5.6
if (method_exists(Paginator::class, 'useBootstrapThree')) {
Paginator::useBootstrapThree();
}
} | [
"public",
"function",
"usingAdmin",
"(",
")",
"{",
"// Define constants that Decoy uses",
"if",
"(",
"!",
"defined",
"(",
"'FORMAT_DATE'",
")",
")",
"{",
"define",
"(",
"'FORMAT_DATE'",
",",
"__",
"(",
"'decoy::base.constants.format_date'",
")",
")",
";",
"}",
"if",
"(",
"!",
"defined",
"(",
"'FORMAT_DATETIME'",
")",
")",
"{",
"define",
"(",
"'FORMAT_DATETIME'",
",",
"__",
"(",
"'decoy::base.constants.format_datetime'",
")",
")",
";",
"}",
"if",
"(",
"!",
"defined",
"(",
"'FORMAT_TIME'",
")",
")",
"{",
"define",
"(",
"'FORMAT_TIME'",
",",
"__",
"(",
"'decoy::base.constants.format_time'",
")",
")",
";",
"}",
"// Register global and named middlewares",
"$",
"this",
"->",
"registerMiddlewares",
"(",
")",
";",
"// Use Decoy's auth by default, while at an admin path",
"Config",
"::",
"set",
"(",
"'auth.defaults'",
",",
"[",
"'guard'",
"=>",
"'decoy'",
",",
"'passwords'",
"=>",
"'decoy'",
",",
"]",
")",
";",
"// Set the default mailer settings",
"Config",
"::",
"set",
"(",
"'mail.from'",
",",
"[",
"'address'",
"=>",
"Config",
"::",
"get",
"(",
"'decoy.core.mail_from_address'",
")",
",",
"'name'",
"=>",
"Config",
"::",
"get",
"(",
"'decoy.core.mail_from_name'",
")",
",",
"]",
")",
";",
"// Config Former",
"$",
"this",
"->",
"configureFormer",
"(",
")",
";",
"// Delegate events to Decoy observers",
"$",
"this",
"->",
"delegateAdminObservers",
"(",
")",
";",
"// Use Boostrap 3 classes in Laravel 5.6",
"if",
"(",
"method_exists",
"(",
"Paginator",
"::",
"class",
",",
"'useBootstrapThree'",
")",
")",
"{",
"Paginator",
"::",
"useBootstrapThree",
"(",
")",
";",
"}",
"}"
] | Things that happen only if the request is for the admin | [
"Things",
"that",
"happen",
"only",
"if",
"the",
"request",
"is",
"for",
"the",
"admin"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L91-L130 |
30,615 | BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.bootAuth | public function bootAuth()
{
// Inject Decoy's auth config
Config::set('auth.guards.decoy', [
'driver' => 'session',
'provider' => 'decoy',
]);
Config::set('auth.providers.decoy', [
'driver' => 'eloquent',
'model' => Models\Admin::class,
]);
Config::set('auth.passwords.decoy', [
'provider' => 'decoy',
'email' => 'decoy::emails.reset',
'table' => 'password_resets',
'expire' => 60,
]);
// Point to the Gate policy
$this->app[Gate::class]->define('decoy.auth', config('decoy.core.policy'));
} | php | public function bootAuth()
{
// Inject Decoy's auth config
Config::set('auth.guards.decoy', [
'driver' => 'session',
'provider' => 'decoy',
]);
Config::set('auth.providers.decoy', [
'driver' => 'eloquent',
'model' => Models\Admin::class,
]);
Config::set('auth.passwords.decoy', [
'provider' => 'decoy',
'email' => 'decoy::emails.reset',
'table' => 'password_resets',
'expire' => 60,
]);
// Point to the Gate policy
$this->app[Gate::class]->define('decoy.auth', config('decoy.core.policy'));
} | [
"public",
"function",
"bootAuth",
"(",
")",
"{",
"// Inject Decoy's auth config",
"Config",
"::",
"set",
"(",
"'auth.guards.decoy'",
",",
"[",
"'driver'",
"=>",
"'session'",
",",
"'provider'",
"=>",
"'decoy'",
",",
"]",
")",
";",
"Config",
"::",
"set",
"(",
"'auth.providers.decoy'",
",",
"[",
"'driver'",
"=>",
"'eloquent'",
",",
"'model'",
"=>",
"Models",
"\\",
"Admin",
"::",
"class",
",",
"]",
")",
";",
"Config",
"::",
"set",
"(",
"'auth.passwords.decoy'",
",",
"[",
"'provider'",
"=>",
"'decoy'",
",",
"'email'",
"=>",
"'decoy::emails.reset'",
",",
"'table'",
"=>",
"'password_resets'",
",",
"'expire'",
"=>",
"60",
",",
"]",
")",
";",
"// Point to the Gate policy",
"$",
"this",
"->",
"app",
"[",
"Gate",
"::",
"class",
"]",
"->",
"define",
"(",
"'decoy.auth'",
",",
"config",
"(",
"'decoy.core.policy'",
")",
")",
";",
"}"
] | Boot Decoy's auth integration
@return void | [
"Boot",
"Decoy",
"s",
"auth",
"integration"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L137-L159 |
30,616 | BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.delegateAdminObservers | protected function delegateAdminObservers()
{
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Localize');
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Encoding@onSaving');
$this->app['events']->listen('eloquent.saved:*',
'Bkwld\Decoy\Observers\ManyToManyChecklist');
$this->app['events']->listen('eloquent.deleted:*',
'Bkwld\Decoy\Observers\Encoding@onDeleted');
$this->app['events']->listen('decoy::model.validating:*',
'Bkwld\Decoy\Observers\ValidateExistingFiles@onValidating');
} | php | protected function delegateAdminObservers()
{
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Localize');
$this->app['events']->listen('eloquent.saving:*',
'Bkwld\Decoy\Observers\Encoding@onSaving');
$this->app['events']->listen('eloquent.saved:*',
'Bkwld\Decoy\Observers\ManyToManyChecklist');
$this->app['events']->listen('eloquent.deleted:*',
'Bkwld\Decoy\Observers\Encoding@onDeleted');
$this->app['events']->listen('decoy::model.validating:*',
'Bkwld\Decoy\Observers\ValidateExistingFiles@onValidating');
} | [
"protected",
"function",
"delegateAdminObservers",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"listen",
"(",
"'eloquent.saving:*'",
",",
"'Bkwld\\Decoy\\Observers\\Localize'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"listen",
"(",
"'eloquent.saving:*'",
",",
"'Bkwld\\Decoy\\Observers\\Encoding@onSaving'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"listen",
"(",
"'eloquent.saved:*'",
",",
"'Bkwld\\Decoy\\Observers\\ManyToManyChecklist'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"listen",
"(",
"'eloquent.deleted:*'",
",",
"'Bkwld\\Decoy\\Observers\\Encoding@onDeleted'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"listen",
"(",
"'decoy::model.validating:*'",
",",
"'Bkwld\\Decoy\\Observers\\ValidateExistingFiles@onValidating'",
")",
";",
"}"
] | Delegate events to Decoy observers
@return void | [
"Delegate",
"events",
"to",
"Decoy",
"observers"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L191-L203 |
30,617 | BKWLD/decoy | classes/ServiceProvider.php | ServiceProvider.registerPackages | private function registerPackages()
{
// Form field generation
AliasLoader::getInstance()->alias('Former', \Former\Facades\Former::class);
$this->app->register('Former\FormerServiceProvider');
// Image resizing
AliasLoader::getInstance()->alias('Croppa', \Bkwld\Croppa\Facade::class);
$this->app->register('Bkwld\Croppa\ServiceProvider');
// PHP utils
$this->app->register('Bkwld\Library\ServiceProvider');
// HAML
$this->app->register('Bkwld\LaravelHaml\ServiceProvider');
// BrowserDetect
AliasLoader::getInstance()->alias('Agent', \Jenssegers\Agent\Facades\Agent::class);
$this->app->register('Jenssegers\Agent\AgentServiceProvider');
// File uploading
$this->app->register('Bkwld\Upchuck\ServiceProvider');
// Creation of slugs
$this->app->register('Cviebrock\EloquentSluggable\ServiceProvider');
// Support for cloning models
$this->app->register('Bkwld\Cloner\ServiceProvider');
} | php | private function registerPackages()
{
// Form field generation
AliasLoader::getInstance()->alias('Former', \Former\Facades\Former::class);
$this->app->register('Former\FormerServiceProvider');
// Image resizing
AliasLoader::getInstance()->alias('Croppa', \Bkwld\Croppa\Facade::class);
$this->app->register('Bkwld\Croppa\ServiceProvider');
// PHP utils
$this->app->register('Bkwld\Library\ServiceProvider');
// HAML
$this->app->register('Bkwld\LaravelHaml\ServiceProvider');
// BrowserDetect
AliasLoader::getInstance()->alias('Agent', \Jenssegers\Agent\Facades\Agent::class);
$this->app->register('Jenssegers\Agent\AgentServiceProvider');
// File uploading
$this->app->register('Bkwld\Upchuck\ServiceProvider');
// Creation of slugs
$this->app->register('Cviebrock\EloquentSluggable\ServiceProvider');
// Support for cloning models
$this->app->register('Bkwld\Cloner\ServiceProvider');
} | [
"private",
"function",
"registerPackages",
"(",
")",
"{",
"// Form field generation",
"AliasLoader",
"::",
"getInstance",
"(",
")",
"->",
"alias",
"(",
"'Former'",
",",
"\\",
"Former",
"\\",
"Facades",
"\\",
"Former",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Former\\FormerServiceProvider'",
")",
";",
"// Image resizing",
"AliasLoader",
"::",
"getInstance",
"(",
")",
"->",
"alias",
"(",
"'Croppa'",
",",
"\\",
"Bkwld",
"\\",
"Croppa",
"\\",
"Facade",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Bkwld\\Croppa\\ServiceProvider'",
")",
";",
"// PHP utils",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Bkwld\\Library\\ServiceProvider'",
")",
";",
"// HAML",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Bkwld\\LaravelHaml\\ServiceProvider'",
")",
";",
"// BrowserDetect",
"AliasLoader",
"::",
"getInstance",
"(",
")",
"->",
"alias",
"(",
"'Agent'",
",",
"\\",
"Jenssegers",
"\\",
"Agent",
"\\",
"Facades",
"\\",
"Agent",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Jenssegers\\Agent\\AgentServiceProvider'",
")",
";",
"// File uploading",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Bkwld\\Upchuck\\ServiceProvider'",
")",
";",
"// Creation of slugs",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Cviebrock\\EloquentSluggable\\ServiceProvider'",
")",
";",
"// Support for cloning models",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Bkwld\\Cloner\\ServiceProvider'",
")",
";",
"}"
] | Register external dependencies | [
"Register",
"external",
"dependencies"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/ServiceProvider.php#L330-L358 |
30,618 | BKWLD/decoy | classes/Models/Traits/Exportable.php | Exportable.mapExportAttributes | protected function mapExportAttributes($attributes)
{
return collect($attributes->toArray())->map(function($value, $key) {
return $this->mapExportAttribute($value, $key);
})->toArray();
} | php | protected function mapExportAttributes($attributes)
{
return collect($attributes->toArray())->map(function($value, $key) {
return $this->mapExportAttribute($value, $key);
})->toArray();
} | [
"protected",
"function",
"mapExportAttributes",
"(",
"$",
"attributes",
")",
"{",
"return",
"collect",
"(",
"$",
"attributes",
"->",
"toArray",
"(",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"mapExportAttribute",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"}",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Massage attribute values. The CSV needs a flat array.
@return array | [
"Massage",
"attribute",
"values",
".",
"The",
"CSV",
"needs",
"a",
"flat",
"array",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Exportable.php#L64-L69 |
30,619 | BKWLD/decoy | classes/Models/Traits/Exportable.php | Exportable.mapExportAttribute | protected function mapExportAttribute($value, $key)
{
// If an images relationship
if ($key == 'images') {
return implode(',', array_map(function($image) {
return $image['file'];
}, $value));
}
// If another array...
if (is_array($value)) {
return implode(',', array_map(function($child) {
// If sub array, like if this was some relation, return the id
// so this becomes an array of those ids
if (is_array($child) && isset($child['id'])) {
return $child['id'];
}
// If anything else, just return it
return $child;
}, $value));
}
// Otherwise, just pass through value
return $value;
} | php | protected function mapExportAttribute($value, $key)
{
// If an images relationship
if ($key == 'images') {
return implode(',', array_map(function($image) {
return $image['file'];
}, $value));
}
// If another array...
if (is_array($value)) {
return implode(',', array_map(function($child) {
// If sub array, like if this was some relation, return the id
// so this becomes an array of those ids
if (is_array($child) && isset($child['id'])) {
return $child['id'];
}
// If anything else, just return it
return $child;
}, $value));
}
// Otherwise, just pass through value
return $value;
} | [
"protected",
"function",
"mapExportAttribute",
"(",
"$",
"value",
",",
"$",
"key",
")",
"{",
"// If an images relationship",
"if",
"(",
"$",
"key",
"==",
"'images'",
")",
"{",
"return",
"implode",
"(",
"','",
",",
"array_map",
"(",
"function",
"(",
"$",
"image",
")",
"{",
"return",
"$",
"image",
"[",
"'file'",
"]",
";",
"}",
",",
"$",
"value",
")",
")",
";",
"}",
"// If another array...",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"implode",
"(",
"','",
",",
"array_map",
"(",
"function",
"(",
"$",
"child",
")",
"{",
"// If sub array, like if this was some relation, return the id",
"// so this becomes an array of those ids",
"if",
"(",
"is_array",
"(",
"$",
"child",
")",
"&&",
"isset",
"(",
"$",
"child",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
"$",
"child",
"[",
"'id'",
"]",
";",
"}",
"// If anything else, just return it",
"return",
"$",
"child",
";",
"}",
",",
"$",
"value",
")",
")",
";",
"}",
"// Otherwise, just pass through value",
"return",
"$",
"value",
";",
"}"
] | Massage attribute values for export
@return scalar | [
"Massage",
"attribute",
"values",
"for",
"export"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Exportable.php#L76-L102 |
30,620 | BKWLD/decoy | classes/Models/Traits/Exportable.php | Exportable.makeCsvHeaderNames | public function makeCsvHeaderNames()
{
$headers = array_keys($this->forExport());
return array_map(function($key) {
switch($key) {
// id must be lowercase for opening in excel
// https://annalear.ca/2010/06/10/why-excel-thinks-your-csv-is-a-sylk/
case 'id': return $key;
// Make common acronyms upper case
case 'uid':
case 'pid':
case 'guid':
case 'cta':
case 'url': return strtoupper($key);
// Default to title casing fields
default: return TextUtils::titleFromKey($key);
}
}, $headers);
} | php | public function makeCsvHeaderNames()
{
$headers = array_keys($this->forExport());
return array_map(function($key) {
switch($key) {
// id must be lowercase for opening in excel
// https://annalear.ca/2010/06/10/why-excel-thinks-your-csv-is-a-sylk/
case 'id': return $key;
// Make common acronyms upper case
case 'uid':
case 'pid':
case 'guid':
case 'cta':
case 'url': return strtoupper($key);
// Default to title casing fields
default: return TextUtils::titleFromKey($key);
}
}, $headers);
} | [
"public",
"function",
"makeCsvHeaderNames",
"(",
")",
"{",
"$",
"headers",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"forExport",
"(",
")",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"// id must be lowercase for opening in excel",
"// https://annalear.ca/2010/06/10/why-excel-thinks-your-csv-is-a-sylk/",
"case",
"'id'",
":",
"return",
"$",
"key",
";",
"// Make common acronyms upper case",
"case",
"'uid'",
":",
"case",
"'pid'",
":",
"case",
"'guid'",
":",
"case",
"'cta'",
":",
"case",
"'url'",
":",
"return",
"strtoupper",
"(",
"$",
"key",
")",
";",
"// Default to title casing fields",
"default",
":",
"return",
"TextUtils",
"::",
"titleFromKey",
"(",
"$",
"key",
")",
";",
"}",
"}",
",",
"$",
"headers",
")",
";",
"}"
] | Make the header the CSV header row
@return array | [
"Make",
"the",
"header",
"the",
"CSV",
"header",
"row"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Exportable.php#L109-L130 |
30,621 | BKWLD/decoy | classes/Models/Image.php | Image.deletedBecauseEmpty | public function deletedBecauseEmpty()
{
if ($file = $this->getAttributeValue('file')) {
return false;
}
if ($this->exists) {
$this->delete();
}
return true;
} | php | public function deletedBecauseEmpty()
{
if ($file = $this->getAttributeValue('file')) {
return false;
}
if ($this->exists) {
$this->delete();
}
return true;
} | [
"public",
"function",
"deletedBecauseEmpty",
"(",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"'file'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"exists",
")",
"{",
"$",
"this",
"->",
"delete",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | If the file attribtue is empty, this Image has been marked for deletion.
Return true to signal the image was deleted
@return bool | [
"If",
"the",
"file",
"attribtue",
"is",
"empty",
"this",
"Image",
"has",
"been",
"marked",
"for",
"deletion",
".",
"Return",
"true",
"to",
"signal",
"the",
"image",
"was",
"deleted"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L169-L180 |
30,622 | BKWLD/decoy | classes/Models/Image.php | Image.populateFileMeta | public function populateFileMeta()
{
$file = $this->getAttributeValue('file');
if (!is_a($file, UploadedFile::class)) {
return;
}
$size = getimagesize($file->getPathname());
$this->fill([
'file_type' => $this->guessFileType($file),
'file_size' => $file->getSize(),
'width' => $size[0],
'height' => $size[1],
]);
} | php | public function populateFileMeta()
{
$file = $this->getAttributeValue('file');
if (!is_a($file, UploadedFile::class)) {
return;
}
$size = getimagesize($file->getPathname());
$this->fill([
'file_type' => $this->guessFileType($file),
'file_size' => $file->getSize(),
'width' => $size[0],
'height' => $size[1],
]);
} | [
"public",
"function",
"populateFileMeta",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"'file'",
")",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"file",
",",
"UploadedFile",
"::",
"class",
")",
")",
"{",
"return",
";",
"}",
"$",
"size",
"=",
"getimagesize",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"$",
"this",
"->",
"fill",
"(",
"[",
"'file_type'",
"=>",
"$",
"this",
"->",
"guessFileType",
"(",
"$",
"file",
")",
",",
"'file_size'",
"=>",
"$",
"file",
"->",
"getSize",
"(",
")",
",",
"'width'",
"=>",
"$",
"size",
"[",
"0",
"]",
",",
"'height'",
"=>",
"$",
"size",
"[",
"1",
"]",
",",
"]",
")",
";",
"}"
] | Store file meta info in the database if a new File object is present
@return void | [
"Store",
"file",
"meta",
"info",
"in",
"the",
"database",
"if",
"a",
"new",
"File",
"object",
"is",
"present"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L187-L200 |
30,623 | BKWLD/decoy | classes/Models/Image.php | Image.crop | public function crop($width = null, $height = null, $options = null)
{
$this->config = [
'width' => $width,
'height' => $height,
'options' => $options,
];
return $this;
} | php | public function crop($width = null, $height = null, $options = null)
{
$this->config = [
'width' => $width,
'height' => $height,
'options' => $options,
];
return $this;
} | [
"public",
"function",
"crop",
"(",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"[",
"'width'",
"=>",
"$",
"width",
",",
"'height'",
"=>",
"$",
"height",
",",
"'options'",
"=>",
"$",
"options",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Set the crop dimenions
@param integer $width
@param integer $height
@param array $options Croppa options array
@return $this | [
"Set",
"the",
"crop",
"dimenions"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L241-L250 |
30,624 | BKWLD/decoy | classes/Models/Image.php | Image.getConfig | public function getConfig()
{
// Create default keys for the config
$config = array_merge([
'width' => null,
'height' => null,
'options' => null,
], $this->config);
// Add crops
if ($crop = $this->getAttributeValue('crop_box')) {
if (!is_array($config['options'])) {
$config['options'] = [];
}
$config['options']['trim_perc'] = [
round($crop->x1, 4),
round($crop->y1, 4),
round($crop->x2, 4),
round($crop->y2, 4),
];
}
// Return config
return $config;
} | php | public function getConfig()
{
// Create default keys for the config
$config = array_merge([
'width' => null,
'height' => null,
'options' => null,
], $this->config);
// Add crops
if ($crop = $this->getAttributeValue('crop_box')) {
if (!is_array($config['options'])) {
$config['options'] = [];
}
$config['options']['trim_perc'] = [
round($crop->x1, 4),
round($crop->y1, 4),
round($crop->x2, 4),
round($crop->y2, 4),
];
}
// Return config
return $config;
} | [
"public",
"function",
"getConfig",
"(",
")",
"{",
"// Create default keys for the config",
"$",
"config",
"=",
"array_merge",
"(",
"[",
"'width'",
"=>",
"null",
",",
"'height'",
"=>",
"null",
",",
"'options'",
"=>",
"null",
",",
"]",
",",
"$",
"this",
"->",
"config",
")",
";",
"// Add crops",
"if",
"(",
"$",
"crop",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"'crop_box'",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'options'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"config",
"[",
"'options'",
"]",
"[",
"'trim_perc'",
"]",
"=",
"[",
"round",
"(",
"$",
"crop",
"->",
"x1",
",",
"4",
")",
",",
"round",
"(",
"$",
"crop",
"->",
"y1",
",",
"4",
")",
",",
"round",
"(",
"$",
"crop",
"->",
"x2",
",",
"4",
")",
",",
"round",
"(",
"$",
"crop",
"->",
"y2",
",",
"4",
")",
",",
"]",
";",
"}",
"// Return config",
"return",
"$",
"config",
";",
"}"
] | Get the config, merging defaults in so that all keys in the array are
present. This also applies the crop choices from the DB.
@return array | [
"Get",
"the",
"config",
"merging",
"defaults",
"in",
"so",
"that",
"all",
"keys",
"in",
"the",
"array",
"are",
"present",
".",
"This",
"also",
"applies",
"the",
"crop",
"choices",
"from",
"the",
"DB",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L258-L282 |
30,625 | BKWLD/decoy | classes/Models/Image.php | Image.urlify | public function urlify($size, $multiplier = 1)
{
// Get fluent config
$config = $this->getConfig();
// Setup vars
$size = $this->sizes[$size];
$scale = $size[0] / $this->bench;
$width = $height = null;
// Figure out percentage sizes. First one of the dimensnios is tested
// to see if it looks a percentage. If so, make it a percentage of one of
// the hard coded sizes. Otherwise, scale the dimension by comaring the
// size to a the benchmark (laptop).
if ($perc = $this->perc($config['width'])) {
$width = $perc * $size[0] * $multiplier;
} elseif ($config['width']) {
$width = $config['width'] * $scale * $multiplier;
}
if ($perc = $this->perc($config['height'])) {
$height = $perc * $size[1] * $multiplier;
} elseif ($config['height']) {
$height = $config['height'] * $scale * $multiplier;
}
// Produce the Croppa URL
$path = Croppa::url($this->getAttributeValue('file'),
$width,
$height,
$config['options']
);
if ($path) {
return asset($path);
}
} | php | public function urlify($size, $multiplier = 1)
{
// Get fluent config
$config = $this->getConfig();
// Setup vars
$size = $this->sizes[$size];
$scale = $size[0] / $this->bench;
$width = $height = null;
// Figure out percentage sizes. First one of the dimensnios is tested
// to see if it looks a percentage. If so, make it a percentage of one of
// the hard coded sizes. Otherwise, scale the dimension by comaring the
// size to a the benchmark (laptop).
if ($perc = $this->perc($config['width'])) {
$width = $perc * $size[0] * $multiplier;
} elseif ($config['width']) {
$width = $config['width'] * $scale * $multiplier;
}
if ($perc = $this->perc($config['height'])) {
$height = $perc * $size[1] * $multiplier;
} elseif ($config['height']) {
$height = $config['height'] * $scale * $multiplier;
}
// Produce the Croppa URL
$path = Croppa::url($this->getAttributeValue('file'),
$width,
$height,
$config['options']
);
if ($path) {
return asset($path);
}
} | [
"public",
"function",
"urlify",
"(",
"$",
"size",
",",
"$",
"multiplier",
"=",
"1",
")",
"{",
"// Get fluent config",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"// Setup vars",
"$",
"size",
"=",
"$",
"this",
"->",
"sizes",
"[",
"$",
"size",
"]",
";",
"$",
"scale",
"=",
"$",
"size",
"[",
"0",
"]",
"/",
"$",
"this",
"->",
"bench",
";",
"$",
"width",
"=",
"$",
"height",
"=",
"null",
";",
"// Figure out percentage sizes. First one of the dimensnios is tested",
"// to see if it looks a percentage. If so, make it a percentage of one of",
"// the hard coded sizes. Otherwise, scale the dimension by comaring the",
"// size to a the benchmark (laptop).",
"if",
"(",
"$",
"perc",
"=",
"$",
"this",
"->",
"perc",
"(",
"$",
"config",
"[",
"'width'",
"]",
")",
")",
"{",
"$",
"width",
"=",
"$",
"perc",
"*",
"$",
"size",
"[",
"0",
"]",
"*",
"$",
"multiplier",
";",
"}",
"elseif",
"(",
"$",
"config",
"[",
"'width'",
"]",
")",
"{",
"$",
"width",
"=",
"$",
"config",
"[",
"'width'",
"]",
"*",
"$",
"scale",
"*",
"$",
"multiplier",
";",
"}",
"if",
"(",
"$",
"perc",
"=",
"$",
"this",
"->",
"perc",
"(",
"$",
"config",
"[",
"'height'",
"]",
")",
")",
"{",
"$",
"height",
"=",
"$",
"perc",
"*",
"$",
"size",
"[",
"1",
"]",
"*",
"$",
"multiplier",
";",
"}",
"elseif",
"(",
"$",
"config",
"[",
"'height'",
"]",
")",
"{",
"$",
"height",
"=",
"$",
"config",
"[",
"'height'",
"]",
"*",
"$",
"scale",
"*",
"$",
"multiplier",
";",
"}",
"// Produce the Croppa URL",
"$",
"path",
"=",
"Croppa",
"::",
"url",
"(",
"$",
"this",
"->",
"getAttributeValue",
"(",
"'file'",
")",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"config",
"[",
"'options'",
"]",
")",
";",
"if",
"(",
"$",
"path",
")",
"{",
"return",
"asset",
"(",
"$",
"path",
")",
";",
"}",
"}"
] | Make paths full URLs so these can be used directly in APIs or for Open
Graph tags, for example.
@param string $size
@param number $scale
@return string url | [
"Make",
"paths",
"full",
"URLs",
"so",
"these",
"can",
"be",
"used",
"directly",
"in",
"APIs",
"or",
"for",
"Open",
"Graph",
"tags",
"for",
"example",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Image.php#L482-L516 |
30,626 | BKWLD/decoy | classes/Commands/Generate.php | Generate.generateModel | private function generateModel()
{
// Figure out the naming
$model = ucfirst($this->argument('model'));
$path = 'app/'.$model.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (file_exists($file)) {
return $this->comment('Model already exists: '.$path);
}
file_put_contents($file, str_replace('{{model}}', $model, file_get_contents($this->stubs.'/model.stub')));
$this->info('Model created: '.$path);
} | php | private function generateModel()
{
// Figure out the naming
$model = ucfirst($this->argument('model'));
$path = 'app/'.$model.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (file_exists($file)) {
return $this->comment('Model already exists: '.$path);
}
file_put_contents($file, str_replace('{{model}}', $model, file_get_contents($this->stubs.'/model.stub')));
$this->info('Model created: '.$path);
} | [
"private",
"function",
"generateModel",
"(",
")",
"{",
"// Figure out the naming",
"$",
"model",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"argument",
"(",
"'model'",
")",
")",
";",
"$",
"path",
"=",
"'app/'",
".",
"$",
"model",
".",
"'.php'",
";",
"$",
"file",
"=",
"base_path",
"(",
")",
".",
"'/'",
".",
"$",
"path",
";",
"// Copy the stub over",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"comment",
"(",
"'Model already exists: '",
".",
"$",
"path",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
",",
"str_replace",
"(",
"'{{model}}'",
",",
"$",
"model",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"stubs",
".",
"'/model.stub'",
")",
")",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Model created: '",
".",
"$",
"path",
")",
";",
"}"
] | Create the model file | [
"Create",
"the",
"model",
"file"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Generate.php#L49-L62 |
30,627 | BKWLD/decoy | classes/Commands/Generate.php | Generate.generateView | private function generateView()
{
// Figure out the naming
$path = 'resources/views/admin/'
. Str::plural(Str::snake($this->argument('model')))
. '/edit.haml';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('View already exists: '.$path);
}
copy($this->stubs.'/view.stub', $file);
$this->info('View created: '.$path);
} | php | private function generateView()
{
// Figure out the naming
$path = 'resources/views/admin/'
. Str::plural(Str::snake($this->argument('model')))
. '/edit.haml';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('View already exists: '.$path);
}
copy($this->stubs.'/view.stub', $file);
$this->info('View created: '.$path);
} | [
"private",
"function",
"generateView",
"(",
")",
"{",
"// Figure out the naming",
"$",
"path",
"=",
"'resources/views/admin/'",
".",
"Str",
"::",
"plural",
"(",
"Str",
"::",
"snake",
"(",
"$",
"this",
"->",
"argument",
"(",
"'model'",
")",
")",
")",
".",
"'/edit.haml'",
";",
"$",
"file",
"=",
"base_path",
"(",
")",
".",
"'/'",
".",
"$",
"path",
";",
"// Copy the stub over",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"file",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"file",
")",
",",
"0744",
",",
"true",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"comment",
"(",
"'View already exists: '",
".",
"$",
"path",
")",
";",
"}",
"copy",
"(",
"$",
"this",
"->",
"stubs",
".",
"'/view.stub'",
",",
"$",
"file",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'View created: '",
".",
"$",
"path",
")",
";",
"}"
] | Create the view file | [
"Create",
"the",
"view",
"file"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Generate.php#L67-L84 |
30,628 | BKWLD/decoy | classes/Commands/Generate.php | Generate.generateController | private function generateController()
{
// Figure out the naming
$controller = Str::plural(ucfirst($this->argument('model')));
$path = 'app/Http/Controllers/Admin/'.$controller.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('Controller already exists: '.$path);
}
file_put_contents($file, str_replace('{{controller}}', $controller, file_get_contents($this->stubs.'/controller.stub')));
$this->info('Controller created: '.$path);
} | php | private function generateController()
{
// Figure out the naming
$controller = Str::plural(ucfirst($this->argument('model')));
$path = 'app/Http/Controllers/Admin/'.$controller.'.php';
$file = base_path().'/'.$path;
// Copy the stub over
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0744, true);
}
if (file_exists($file)) {
return $this->comment('Controller already exists: '.$path);
}
file_put_contents($file, str_replace('{{controller}}', $controller, file_get_contents($this->stubs.'/controller.stub')));
$this->info('Controller created: '.$path);
} | [
"private",
"function",
"generateController",
"(",
")",
"{",
"// Figure out the naming",
"$",
"controller",
"=",
"Str",
"::",
"plural",
"(",
"ucfirst",
"(",
"$",
"this",
"->",
"argument",
"(",
"'model'",
")",
")",
")",
";",
"$",
"path",
"=",
"'app/Http/Controllers/Admin/'",
".",
"$",
"controller",
".",
"'.php'",
";",
"$",
"file",
"=",
"base_path",
"(",
")",
".",
"'/'",
".",
"$",
"path",
";",
"// Copy the stub over",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"file",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"file",
")",
",",
"0744",
",",
"true",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"this",
"->",
"comment",
"(",
"'Controller already exists: '",
".",
"$",
"path",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
",",
"str_replace",
"(",
"'{{controller}}'",
",",
"$",
"controller",
",",
"file_get_contents",
"(",
"$",
"this",
"->",
"stubs",
".",
"'/controller.stub'",
")",
")",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Controller created: '",
".",
"$",
"path",
")",
";",
"}"
] | Create the controller file | [
"Create",
"the",
"controller",
"file"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Commands/Generate.php#L89-L105 |
30,629 | BKWLD/decoy | classes/Input/Localize.php | Localize.item | public function item($item)
{
if (!$this->model) {
$this->model = get_class($item);
}
$this->item = $item;
return $this;
} | php | public function item($item)
{
if (!$this->model) {
$this->model = get_class($item);
}
$this->item = $item;
return $this;
} | [
"public",
"function",
"item",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"model",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"get_class",
"(",
"$",
"item",
")",
";",
"}",
"$",
"this",
"->",
"item",
"=",
"$",
"item",
";",
"return",
"$",
"this",
";",
"}"
] | Store a model instance
@param Illuminate\Database\Eloquent\Model $item
@return $this | [
"Store",
"a",
"model",
"instance"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L44-L53 |
30,630 | BKWLD/decoy | classes/Input/Localize.php | Localize.hidden | public function hidden()
{
$class = $this->model; // Must be a local var to test
// There aren't multiple locales specified
if (count(config('decoy.site.locales')) <= 1 ) return true;
// We're editing a model with no locale attribute
if ($this->item && !$this->item->locale) return true;
// The model was explicitly disabled
if ($class::$localizable === false ) return true;
// Auto localize is turned on and we're on a child model
if (config('decoy.site.auto_localize_root_models')
&& app('decoy.wildcard')->detectParent()) return true;
// If auto-localizeable is turned off and this model doesn't have it
// turned on
if (!config('decoy.site.auto_localize_root_models')
&& !$class::$localizable) return true;
// Otherwise, allow localization
return false;
} | php | public function hidden()
{
$class = $this->model; // Must be a local var to test
// There aren't multiple locales specified
if (count(config('decoy.site.locales')) <= 1 ) return true;
// We're editing a model with no locale attribute
if ($this->item && !$this->item->locale) return true;
// The model was explicitly disabled
if ($class::$localizable === false ) return true;
// Auto localize is turned on and we're on a child model
if (config('decoy.site.auto_localize_root_models')
&& app('decoy.wildcard')->detectParent()) return true;
// If auto-localizeable is turned off and this model doesn't have it
// turned on
if (!config('decoy.site.auto_localize_root_models')
&& !$class::$localizable) return true;
// Otherwise, allow localization
return false;
} | [
"public",
"function",
"hidden",
"(",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"model",
";",
"// Must be a local var to test",
"// There aren't multiple locales specified",
"if",
"(",
"count",
"(",
"config",
"(",
"'decoy.site.locales'",
")",
")",
"<=",
"1",
")",
"return",
"true",
";",
"// We're editing a model with no locale attribute",
"if",
"(",
"$",
"this",
"->",
"item",
"&&",
"!",
"$",
"this",
"->",
"item",
"->",
"locale",
")",
"return",
"true",
";",
"// The model was explicitly disabled",
"if",
"(",
"$",
"class",
"::",
"$",
"localizable",
"===",
"false",
")",
"return",
"true",
";",
"// Auto localize is turned on and we're on a child model",
"if",
"(",
"config",
"(",
"'decoy.site.auto_localize_root_models'",
")",
"&&",
"app",
"(",
"'decoy.wildcard'",
")",
"->",
"detectParent",
"(",
")",
")",
"return",
"true",
";",
"// If auto-localizeable is turned off and this model doesn't have it",
"// turned on",
"if",
"(",
"!",
"config",
"(",
"'decoy.site.auto_localize_root_models'",
")",
"&&",
"!",
"$",
"class",
"::",
"$",
"localizable",
")",
"return",
"true",
";",
"// Otherwise, allow localization",
"return",
"false",
";",
"}"
] | Check if the localize UI should be displayed
@return boolean | [
"Check",
"if",
"the",
"localize",
"UI",
"should",
"be",
"displayed"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L86-L110 |
30,631 | BKWLD/decoy | classes/Input/Localize.php | Localize.localizableLocales | public function localizableLocales()
{
// Keep only locales that don't exist in ...
return array_diff_key(
Config::get('decoy.site.locales'),
// ... the locales of other localizations ...
$this->other()->pluck('locale')->flip()->toArray(),
// ... and the model's locale
[$this->item->locale => null]
);
} | php | public function localizableLocales()
{
// Keep only locales that don't exist in ...
return array_diff_key(
Config::get('decoy.site.locales'),
// ... the locales of other localizations ...
$this->other()->pluck('locale')->flip()->toArray(),
// ... and the model's locale
[$this->item->locale => null]
);
} | [
"public",
"function",
"localizableLocales",
"(",
")",
"{",
"// Keep only locales that don't exist in ...",
"return",
"array_diff_key",
"(",
"Config",
"::",
"get",
"(",
"'decoy.site.locales'",
")",
",",
"// ... the locales of other localizations ...",
"$",
"this",
"->",
"other",
"(",
")",
"->",
"pluck",
"(",
"'locale'",
")",
"->",
"flip",
"(",
")",
"->",
"toArray",
"(",
")",
",",
"// ... and the model's locale",
"[",
"$",
"this",
"->",
"item",
"->",
"locale",
"=>",
"null",
"]",
")",
";",
"}"
] | Get a hash of locales that are available for the item
@return array | [
"Get",
"a",
"hash",
"of",
"locales",
"that",
"are",
"available",
"for",
"the",
"item"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L117-L129 |
30,632 | BKWLD/decoy | classes/Input/Localize.php | Localize.other | public function other()
{
if ($this->other_localizations === null) {
$this->other_localizations = $this->item->otherLocalizations()->get();
}
return $this->other_localizations;
} | php | public function other()
{
if ($this->other_localizations === null) {
$this->other_localizations = $this->item->otherLocalizations()->get();
}
return $this->other_localizations;
} | [
"public",
"function",
"other",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"other_localizations",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"other_localizations",
"=",
"$",
"this",
"->",
"item",
"->",
"otherLocalizations",
"(",
")",
"->",
"get",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"other_localizations",
";",
"}"
] | Get other localizations, storing them internally for use in multiple places
@return Illuminate\Database\Eloquent\Collection | [
"Get",
"other",
"localizations",
"storing",
"them",
"internally",
"for",
"use",
"in",
"multiple",
"places"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Localize.php#L136-L143 |
30,633 | BKWLD/decoy | classes/Controllers/Admins.php | Admins.search | public function search()
{
$options = [
'first_name' => [
'label' => __('decoy::admins.controller.search.first_name'),
'type' => 'text',
],
'last_name' => [
'label' => __('decoy::admins.controller.search.last_name'),
'type' => 'text',
],
'email' => [
'label' => __('decoy::admins.controller.search.email'),
'type' => 'text',
],
'status' => [
'label' => __('decoy::admins.controller.search.status'),
'type' => 'select',
'options' => [
1 => __('decoy::admins.controller.search.enabled'),
0 => __('decoy::admins.controller.search.disabled'),
],
],
];
if (($roles = Admin::getRoleTitles()) && count($roles)) {
$options['role'] = [
'label' => __('decoy::admins.controller.search.role'),
'type' => 'select',
'options' => $roles,
];
}
return $options;
} | php | public function search()
{
$options = [
'first_name' => [
'label' => __('decoy::admins.controller.search.first_name'),
'type' => 'text',
],
'last_name' => [
'label' => __('decoy::admins.controller.search.last_name'),
'type' => 'text',
],
'email' => [
'label' => __('decoy::admins.controller.search.email'),
'type' => 'text',
],
'status' => [
'label' => __('decoy::admins.controller.search.status'),
'type' => 'select',
'options' => [
1 => __('decoy::admins.controller.search.enabled'),
0 => __('decoy::admins.controller.search.disabled'),
],
],
];
if (($roles = Admin::getRoleTitles()) && count($roles)) {
$options['role'] = [
'label' => __('decoy::admins.controller.search.role'),
'type' => 'select',
'options' => $roles,
];
}
return $options;
} | [
"public",
"function",
"search",
"(",
")",
"{",
"$",
"options",
"=",
"[",
"'first_name'",
"=>",
"[",
"'label'",
"=>",
"__",
"(",
"'decoy::admins.controller.search.first_name'",
")",
",",
"'type'",
"=>",
"'text'",
",",
"]",
",",
"'last_name'",
"=>",
"[",
"'label'",
"=>",
"__",
"(",
"'decoy::admins.controller.search.last_name'",
")",
",",
"'type'",
"=>",
"'text'",
",",
"]",
",",
"'email'",
"=>",
"[",
"'label'",
"=>",
"__",
"(",
"'decoy::admins.controller.search.email'",
")",
",",
"'type'",
"=>",
"'text'",
",",
"]",
",",
"'status'",
"=>",
"[",
"'label'",
"=>",
"__",
"(",
"'decoy::admins.controller.search.status'",
")",
",",
"'type'",
"=>",
"'select'",
",",
"'options'",
"=>",
"[",
"1",
"=>",
"__",
"(",
"'decoy::admins.controller.search.enabled'",
")",
",",
"0",
"=>",
"__",
"(",
"'decoy::admins.controller.search.disabled'",
")",
",",
"]",
",",
"]",
",",
"]",
";",
"if",
"(",
"(",
"$",
"roles",
"=",
"Admin",
"::",
"getRoleTitles",
"(",
")",
")",
"&&",
"count",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"options",
"[",
"'role'",
"]",
"=",
"[",
"'label'",
"=>",
"__",
"(",
"'decoy::admins.controller.search.role'",
")",
",",
"'type'",
"=>",
"'select'",
",",
"'options'",
"=>",
"$",
"roles",
",",
"]",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Make search options dependent on whether the site is using roles
@return array | [
"Make",
"search",
"options",
"dependent",
"on",
"whether",
"the",
"site",
"is",
"using",
"roles"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Admins.php#L26-L60 |
30,634 | BKWLD/decoy | classes/Controllers/Admins.php | Admins.update | public function update($id)
{
// Encorce permissions on updating ones own role
if (!app('decoy.user')->can('update', 'admins') && Request::has('role')) {
throw new AccessDeniedHttpException;
}
// If the password is empty, remove the key from the input so it isn't cleared
if (!Request::has('password')) {
Request::replace(array_except(Request::input(), ['password']));
}
// Continue processing
return parent::update($id);
} | php | public function update($id)
{
// Encorce permissions on updating ones own role
if (!app('decoy.user')->can('update', 'admins') && Request::has('role')) {
throw new AccessDeniedHttpException;
}
// If the password is empty, remove the key from the input so it isn't cleared
if (!Request::has('password')) {
Request::replace(array_except(Request::input(), ['password']));
}
// Continue processing
return parent::update($id);
} | [
"public",
"function",
"update",
"(",
"$",
"id",
")",
"{",
"// Encorce permissions on updating ones own role",
"if",
"(",
"!",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'update'",
",",
"'admins'",
")",
"&&",
"Request",
"::",
"has",
"(",
"'role'",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
";",
"}",
"// If the password is empty, remove the key from the input so it isn't cleared",
"if",
"(",
"!",
"Request",
"::",
"has",
"(",
"'password'",
")",
")",
"{",
"Request",
"::",
"replace",
"(",
"array_except",
"(",
"Request",
"::",
"input",
"(",
")",
",",
"[",
"'password'",
"]",
")",
")",
";",
"}",
"// Continue processing",
"return",
"parent",
"::",
"update",
"(",
"$",
"id",
")",
";",
"}"
] | Don't let unauthorize folks update their role by passing in role values
in the GET
@param int $id Model key
@throws AccessDeniedHttpException
@return Symfony\Component\HttpFoundation\Response | [
"Don",
"t",
"let",
"unauthorize",
"folks",
"update",
"their",
"role",
"by",
"passing",
"in",
"role",
"values",
"in",
"the",
"GET"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Admins.php#L110-L124 |
30,635 | BKWLD/decoy | classes/Controllers/Admins.php | Admins.enable | public function enable($id)
{
if (!app('decoy.user')->can('grant', 'admins')) {
throw new AccessDeniedHttpException;
}
if (!($admin = Admin::find($id))) {
return App::abort(404);
}
$admin->active = 1;
$admin->save();
return Redirect::back();
} | php | public function enable($id)
{
if (!app('decoy.user')->can('grant', 'admins')) {
throw new AccessDeniedHttpException;
}
if (!($admin = Admin::find($id))) {
return App::abort(404);
}
$admin->active = 1;
$admin->save();
return Redirect::back();
} | [
"public",
"function",
"enable",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'grant'",
",",
"'admins'",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"admin",
"=",
"Admin",
"::",
"find",
"(",
"$",
"id",
")",
")",
")",
"{",
"return",
"App",
"::",
"abort",
"(",
"404",
")",
";",
"}",
"$",
"admin",
"->",
"active",
"=",
"1",
";",
"$",
"admin",
"->",
"save",
"(",
")",
";",
"return",
"Redirect",
"::",
"back",
"(",
")",
";",
"}"
] | Enable the admin
@return Illuminate\Http\RedirectResponse | [
"Enable",
"the",
"admin"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Admins.php#L152-L166 |
30,636 | BKWLD/decoy | classes/Controllers/Base.php | Base.init | private function init()
{
// Set the layout from the Config file
$this->layout = View::make(config('decoy.core.layout'));
// Store the controller class for routing
$this->controller = get_class($this);
// Get the controller name
$controller_name = $this->controllerName($this->controller);
// Make a default title based on the controller name
if (empty($this->title)) {
$this->title = $this->title($controller_name);
}
// Figure out what the show view should be. This is the path to the show
// view file. Such as 'admin.news.edit'
if (empty($this->show_view)) {
$this->show_view = $this->detailPath($this->controller);
}
// Try to suss out the model by singularizing the controller
if (empty($this->model)) {
$this->model = $this->model($this->controller);
if (!class_exists($this->model)) {
$this->model = null;
}
}
// If the input contains info on the parent, immediately instantiate
// the parent instance. These are populated by some AJAX calls like
// autocomplete on a many to many and the attach method.
if (($parent_id = request('parent_id'))
&& ($parent_controller = request('parent_controller'))) {
$parent_model_class = $this->model($parent_controller);
$this->parent($parent_model_class::findOrFail($parent_id));
}
} | php | private function init()
{
// Set the layout from the Config file
$this->layout = View::make(config('decoy.core.layout'));
// Store the controller class for routing
$this->controller = get_class($this);
// Get the controller name
$controller_name = $this->controllerName($this->controller);
// Make a default title based on the controller name
if (empty($this->title)) {
$this->title = $this->title($controller_name);
}
// Figure out what the show view should be. This is the path to the show
// view file. Such as 'admin.news.edit'
if (empty($this->show_view)) {
$this->show_view = $this->detailPath($this->controller);
}
// Try to suss out the model by singularizing the controller
if (empty($this->model)) {
$this->model = $this->model($this->controller);
if (!class_exists($this->model)) {
$this->model = null;
}
}
// If the input contains info on the parent, immediately instantiate
// the parent instance. These are populated by some AJAX calls like
// autocomplete on a many to many and the attach method.
if (($parent_id = request('parent_id'))
&& ($parent_controller = request('parent_controller'))) {
$parent_model_class = $this->model($parent_controller);
$this->parent($parent_model_class::findOrFail($parent_id));
}
} | [
"private",
"function",
"init",
"(",
")",
"{",
"// Set the layout from the Config file",
"$",
"this",
"->",
"layout",
"=",
"View",
"::",
"make",
"(",
"config",
"(",
"'decoy.core.layout'",
")",
")",
";",
"// Store the controller class for routing",
"$",
"this",
"->",
"controller",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"// Get the controller name",
"$",
"controller_name",
"=",
"$",
"this",
"->",
"controllerName",
"(",
"$",
"this",
"->",
"controller",
")",
";",
"// Make a default title based on the controller name",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"title",
")",
")",
"{",
"$",
"this",
"->",
"title",
"=",
"$",
"this",
"->",
"title",
"(",
"$",
"controller_name",
")",
";",
"}",
"// Figure out what the show view should be. This is the path to the show",
"// view file. Such as 'admin.news.edit'",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"show_view",
")",
")",
"{",
"$",
"this",
"->",
"show_view",
"=",
"$",
"this",
"->",
"detailPath",
"(",
"$",
"this",
"->",
"controller",
")",
";",
"}",
"// Try to suss out the model by singularizing the controller",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"model",
")",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"this",
"->",
"model",
"(",
"$",
"this",
"->",
"controller",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"this",
"->",
"model",
")",
")",
"{",
"$",
"this",
"->",
"model",
"=",
"null",
";",
"}",
"}",
"// If the input contains info on the parent, immediately instantiate",
"// the parent instance. These are populated by some AJAX calls like",
"// autocomplete on a many to many and the attach method.",
"if",
"(",
"(",
"$",
"parent_id",
"=",
"request",
"(",
"'parent_id'",
")",
")",
"&&",
"(",
"$",
"parent_controller",
"=",
"request",
"(",
"'parent_controller'",
")",
")",
")",
"{",
"$",
"parent_model_class",
"=",
"$",
"this",
"->",
"model",
"(",
"$",
"parent_controller",
")",
";",
"$",
"this",
"->",
"parent",
"(",
"$",
"parent_model_class",
"::",
"findOrFail",
"(",
"$",
"parent_id",
")",
")",
";",
"}",
"}"
] | Populate the controller's protected properties
@return void | [
"Populate",
"the",
"controller",
"s",
"protected",
"properties"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L180-L218 |
30,637 | BKWLD/decoy | classes/Controllers/Base.php | Base.title | public function title($controller_name = null)
{
// For when this is invoked as a getter for $this->title
if (!$controller_name) {
return $this->title;
}
// Do the de-studlying
preg_match_all('#[a-z]+|[A-Z][a-z]*#', $controller_name, $matches);
return implode(" ", $matches[0]);
} | php | public function title($controller_name = null)
{
// For when this is invoked as a getter for $this->title
if (!$controller_name) {
return $this->title;
}
// Do the de-studlying
preg_match_all('#[a-z]+|[A-Z][a-z]*#', $controller_name, $matches);
return implode(" ", $matches[0]);
} | [
"public",
"function",
"title",
"(",
"$",
"controller_name",
"=",
"null",
")",
"{",
"// For when this is invoked as a getter for $this->title",
"if",
"(",
"!",
"$",
"controller_name",
")",
"{",
"return",
"$",
"this",
"->",
"title",
";",
"}",
"// Do the de-studlying",
"preg_match_all",
"(",
"'#[a-z]+|[A-Z][a-z]*#'",
",",
"$",
"controller_name",
",",
"$",
"matches",
")",
";",
"return",
"implode",
"(",
"\" \"",
",",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"}"
] | Get the title for the controller based on the controller name. Basically,
it's a de-studdly-er
@param string $controller_name ex: 'Admins' or 'CarLovers'
@return string ex: 'Admins' or 'Car Lovers' | [
"Get",
"the",
"title",
"for",
"the",
"controller",
"based",
"on",
"the",
"controller",
"name",
".",
"Basically",
"it",
"s",
"a",
"de",
"-",
"studdly",
"-",
"er"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L247-L258 |
30,638 | BKWLD/decoy | classes/Controllers/Base.php | Base.detailPath | public function detailPath($class)
{
// Remove Decoy from the class
$path = str_replace('Bkwld\Decoy\Controllers\\', '', $class, $is_decoy);
// Remove the App controller prefix
$path = str_replace('App\Http\Controllers\\', '', $path);
// Break up all the remainder of the class and de-study them (which is what
// title() does)
$parts = explode('\\', $path);
foreach ($parts as &$part) {
$part = str_replace(' ', '_', strtolower($this->title($part)));
}
$path = implode('.', $parts);
// If the controller is part of Decoy, add it to the path
if ($is_decoy) {
$path = 'decoy::'.$path;
}
// Done
return $path.'.edit';
} | php | public function detailPath($class)
{
// Remove Decoy from the class
$path = str_replace('Bkwld\Decoy\Controllers\\', '', $class, $is_decoy);
// Remove the App controller prefix
$path = str_replace('App\Http\Controllers\\', '', $path);
// Break up all the remainder of the class and de-study them (which is what
// title() does)
$parts = explode('\\', $path);
foreach ($parts as &$part) {
$part = str_replace(' ', '_', strtolower($this->title($part)));
}
$path = implode('.', $parts);
// If the controller is part of Decoy, add it to the path
if ($is_decoy) {
$path = 'decoy::'.$path;
}
// Done
return $path.'.edit';
} | [
"public",
"function",
"detailPath",
"(",
"$",
"class",
")",
"{",
"// Remove Decoy from the class",
"$",
"path",
"=",
"str_replace",
"(",
"'Bkwld\\Decoy\\Controllers\\\\'",
",",
"''",
",",
"$",
"class",
",",
"$",
"is_decoy",
")",
";",
"// Remove the App controller prefix",
"$",
"path",
"=",
"str_replace",
"(",
"'App\\Http\\Controllers\\\\'",
",",
"''",
",",
"$",
"path",
")",
";",
"// Break up all the remainder of the class and de-study them (which is what",
"// title() does)",
"$",
"parts",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"&",
"$",
"part",
")",
"{",
"$",
"part",
"=",
"str_replace",
"(",
"' '",
",",
"'_'",
",",
"strtolower",
"(",
"$",
"this",
"->",
"title",
"(",
"$",
"part",
")",
")",
")",
";",
"}",
"$",
"path",
"=",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
";",
"// If the controller is part of Decoy, add it to the path",
"if",
"(",
"$",
"is_decoy",
")",
"{",
"$",
"path",
"=",
"'decoy::'",
".",
"$",
"path",
";",
"}",
"// Done",
"return",
"$",
"path",
".",
"'.edit'",
";",
"}"
] | Get the directory for the detail views. It's based off the controller name.
This is basically a conversion to snake case from studyly case
@param string $class ex: 'Admin\NewsController'
@return string ex: admins.edit or car_lovers.edit | [
"Get",
"the",
"directory",
"for",
"the",
"detail",
"views",
".",
"It",
"s",
"based",
"off",
"the",
"controller",
"name",
".",
"This",
"is",
"basically",
"a",
"conversion",
"to",
"snake",
"case",
"from",
"studyly",
"case"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L311-L336 |
30,639 | BKWLD/decoy | classes/Controllers/Base.php | Base.parent | public function parent($parent)
{
// Save out the passed reference
$this->parent = $parent;
// Save out sub properties that I hope to deprecate
$this->parent_model = get_class($this->parent);
$this->parent_controller = Decoy::controllerForModel($this->parent_model);
// Figure out what the relationship function to the child (this controller's
// model) on the parent model . It will be the plural version of this
// model's name.
$this->parent_to_self = Decoy::hasManyName($this->model);
// If the parent is the same as this controller, assume that it's a
// many-to-many-to-self relationship. Thus, expect a relationship method to
// be defined on the model called "RELATIONSHIPAsChild". I.e. "postsAsChild"
if ($this->parent_controller == $this->controller && method_exists($this->model, $this->parent_to_self.'AsChild')) {
$this->self_to_parent = $this->parent_to_self.'AsChild';
// If the parent relationship is a polymorphic one-many, then the
// relationship function on the child model will be the model name plus
// "able". For instance, the Link model would have it's relationship to
// parent called "linkable".
} elseif (is_a($this->parentRelation(), 'Illuminate\Database\Eloquent\Relations\MorphMany')) {
$this->self_to_parent = Decoy::belongsToName($this->model).'able';
// Save out to self to parent relationship. It will be singular if the
// relationship is a many to many.
} else {
$this->self_to_parent = $this->isChildInManyToMany()?
Decoy::hasManyName($this->parent_model):
Decoy::belongsToName($this->parent_model);
}
// Make chainable
return $this;
} | php | public function parent($parent)
{
// Save out the passed reference
$this->parent = $parent;
// Save out sub properties that I hope to deprecate
$this->parent_model = get_class($this->parent);
$this->parent_controller = Decoy::controllerForModel($this->parent_model);
// Figure out what the relationship function to the child (this controller's
// model) on the parent model . It will be the plural version of this
// model's name.
$this->parent_to_self = Decoy::hasManyName($this->model);
// If the parent is the same as this controller, assume that it's a
// many-to-many-to-self relationship. Thus, expect a relationship method to
// be defined on the model called "RELATIONSHIPAsChild". I.e. "postsAsChild"
if ($this->parent_controller == $this->controller && method_exists($this->model, $this->parent_to_self.'AsChild')) {
$this->self_to_parent = $this->parent_to_self.'AsChild';
// If the parent relationship is a polymorphic one-many, then the
// relationship function on the child model will be the model name plus
// "able". For instance, the Link model would have it's relationship to
// parent called "linkable".
} elseif (is_a($this->parentRelation(), 'Illuminate\Database\Eloquent\Relations\MorphMany')) {
$this->self_to_parent = Decoy::belongsToName($this->model).'able';
// Save out to self to parent relationship. It will be singular if the
// relationship is a many to many.
} else {
$this->self_to_parent = $this->isChildInManyToMany()?
Decoy::hasManyName($this->parent_model):
Decoy::belongsToName($this->parent_model);
}
// Make chainable
return $this;
} | [
"public",
"function",
"parent",
"(",
"$",
"parent",
")",
"{",
"// Save out the passed reference",
"$",
"this",
"->",
"parent",
"=",
"$",
"parent",
";",
"// Save out sub properties that I hope to deprecate",
"$",
"this",
"->",
"parent_model",
"=",
"get_class",
"(",
"$",
"this",
"->",
"parent",
")",
";",
"$",
"this",
"->",
"parent_controller",
"=",
"Decoy",
"::",
"controllerForModel",
"(",
"$",
"this",
"->",
"parent_model",
")",
";",
"// Figure out what the relationship function to the child (this controller's",
"// model) on the parent model . It will be the plural version of this",
"// model's name.",
"$",
"this",
"->",
"parent_to_self",
"=",
"Decoy",
"::",
"hasManyName",
"(",
"$",
"this",
"->",
"model",
")",
";",
"// If the parent is the same as this controller, assume that it's a",
"// many-to-many-to-self relationship. Thus, expect a relationship method to",
"// be defined on the model called \"RELATIONSHIPAsChild\". I.e. \"postsAsChild\"",
"if",
"(",
"$",
"this",
"->",
"parent_controller",
"==",
"$",
"this",
"->",
"controller",
"&&",
"method_exists",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"parent_to_self",
".",
"'AsChild'",
")",
")",
"{",
"$",
"this",
"->",
"self_to_parent",
"=",
"$",
"this",
"->",
"parent_to_self",
".",
"'AsChild'",
";",
"// If the parent relationship is a polymorphic one-many, then the",
"// relationship function on the child model will be the model name plus",
"// \"able\". For instance, the Link model would have it's relationship to",
"// parent called \"linkable\".",
"}",
"elseif",
"(",
"is_a",
"(",
"$",
"this",
"->",
"parentRelation",
"(",
")",
",",
"'Illuminate\\Database\\Eloquent\\Relations\\MorphMany'",
")",
")",
"{",
"$",
"this",
"->",
"self_to_parent",
"=",
"Decoy",
"::",
"belongsToName",
"(",
"$",
"this",
"->",
"model",
")",
".",
"'able'",
";",
"// Save out to self to parent relationship. It will be singular if the",
"// relationship is a many to many.",
"}",
"else",
"{",
"$",
"this",
"->",
"self_to_parent",
"=",
"$",
"this",
"->",
"isChildInManyToMany",
"(",
")",
"?",
"Decoy",
"::",
"hasManyName",
"(",
"$",
"this",
"->",
"parent_model",
")",
":",
"Decoy",
"::",
"belongsToName",
"(",
"$",
"this",
"->",
"parent_model",
")",
";",
"}",
"// Make chainable",
"return",
"$",
"this",
";",
"}"
] | Give this controller a parent model instance. For instance, this makes the
index view a listing of just the children of the parent.
@param Illuminate\Database\Eloquent\Model $parent
@return $this | [
"Give",
"this",
"controller",
"a",
"parent",
"model",
"instance",
".",
"For",
"instance",
"this",
"makes",
"the",
"index",
"view",
"a",
"listing",
"of",
"just",
"the",
"children",
"of",
"the",
"parent",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L360-L397 |
30,640 | BKWLD/decoy | classes/Controllers/Base.php | Base.index | public function index()
{
// Look for overriden views
$this->overrideViews();
// Get models to show
$results = $this->makeIndexQuery()->paginate($this->perPage());
// Render the view using the `listing` builder
$listing = Listing::createFromController($this, $results);
if ($this->parent) {
$listing->parent($this->parent);
// The layout header may have a many to many autocomplete
$this->layout->with($this->autocompleteViewVars());
}
// Render view
return $this->populateView($listing);
} | php | public function index()
{
// Look for overriden views
$this->overrideViews();
// Get models to show
$results = $this->makeIndexQuery()->paginate($this->perPage());
// Render the view using the `listing` builder
$listing = Listing::createFromController($this, $results);
if ($this->parent) {
$listing->parent($this->parent);
// The layout header may have a many to many autocomplete
$this->layout->with($this->autocompleteViewVars());
}
// Render view
return $this->populateView($listing);
} | [
"public",
"function",
"index",
"(",
")",
"{",
"// Look for overriden views",
"$",
"this",
"->",
"overrideViews",
"(",
")",
";",
"// Get models to show",
"$",
"results",
"=",
"$",
"this",
"->",
"makeIndexQuery",
"(",
")",
"->",
"paginate",
"(",
"$",
"this",
"->",
"perPage",
"(",
")",
")",
";",
"// Render the view using the `listing` builder",
"$",
"listing",
"=",
"Listing",
"::",
"createFromController",
"(",
"$",
"this",
",",
"$",
"results",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parent",
")",
"{",
"$",
"listing",
"->",
"parent",
"(",
"$",
"this",
"->",
"parent",
")",
";",
"// The layout header may have a many to many autocomplete",
"$",
"this",
"->",
"layout",
"->",
"with",
"(",
"$",
"this",
"->",
"autocompleteViewVars",
"(",
")",
")",
";",
"}",
"// Render view",
"return",
"$",
"this",
"->",
"populateView",
"(",
"$",
"listing",
")",
";",
"}"
] | Show an index, listing page. Sets view via the layout.
@return Illuminate\Contracts\View\Factory | [
"Show",
"an",
"index",
"listing",
"page",
".",
"Sets",
"view",
"via",
"the",
"layout",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L440-L459 |
30,641 | BKWLD/decoy | classes/Controllers/Base.php | Base.create | public function create()
{
// Look for overriden views
$this->overrideViews();
// Pass validation through
Former::withRules($this->getRules());
// Initialize localization
with($localize = new Localize)
->model($this->model)
->title(Str::singular($this->title));
// Make the sidebar
$sidebar = new Sidebar;
if (!$localize->hidden()) {
$sidebar->addToEnd($localize);
}
// Render view
return $this->populateView($this->show_view, [
'item' => null,
'localize' => $localize,
'sidebar' => $sidebar,
'parent_id' => $this->parent ? $this->parent->getKey() : null,
]);
} | php | public function create()
{
// Look for overriden views
$this->overrideViews();
// Pass validation through
Former::withRules($this->getRules());
// Initialize localization
with($localize = new Localize)
->model($this->model)
->title(Str::singular($this->title));
// Make the sidebar
$sidebar = new Sidebar;
if (!$localize->hidden()) {
$sidebar->addToEnd($localize);
}
// Render view
return $this->populateView($this->show_view, [
'item' => null,
'localize' => $localize,
'sidebar' => $sidebar,
'parent_id' => $this->parent ? $this->parent->getKey() : null,
]);
} | [
"public",
"function",
"create",
"(",
")",
"{",
"// Look for overriden views",
"$",
"this",
"->",
"overrideViews",
"(",
")",
";",
"// Pass validation through",
"Former",
"::",
"withRules",
"(",
"$",
"this",
"->",
"getRules",
"(",
")",
")",
";",
"// Initialize localization",
"with",
"(",
"$",
"localize",
"=",
"new",
"Localize",
")",
"->",
"model",
"(",
"$",
"this",
"->",
"model",
")",
"->",
"title",
"(",
"Str",
"::",
"singular",
"(",
"$",
"this",
"->",
"title",
")",
")",
";",
"// Make the sidebar",
"$",
"sidebar",
"=",
"new",
"Sidebar",
";",
"if",
"(",
"!",
"$",
"localize",
"->",
"hidden",
"(",
")",
")",
"{",
"$",
"sidebar",
"->",
"addToEnd",
"(",
"$",
"localize",
")",
";",
"}",
"// Render view",
"return",
"$",
"this",
"->",
"populateView",
"(",
"$",
"this",
"->",
"show_view",
",",
"[",
"'item'",
"=>",
"null",
",",
"'localize'",
"=>",
"$",
"localize",
",",
"'sidebar'",
"=>",
"$",
"sidebar",
",",
"'parent_id'",
"=>",
"$",
"this",
"->",
"parent",
"?",
"$",
"this",
"->",
"parent",
"->",
"getKey",
"(",
")",
":",
"null",
",",
"]",
")",
";",
"}"
] | Show the create form. Sets view via the layout.
@return Illuminate\Contracts\View\Factory | [
"Show",
"the",
"create",
"form",
".",
"Sets",
"view",
"via",
"the",
"layout",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L466-L492 |
30,642 | BKWLD/decoy | classes/Controllers/Base.php | Base.store | public function store()
{
// Create a new object
$item = new $this->model;
// Remove nested model data from input and prepare to insert on save
$input = (new NestedModels)->relateTo($item);
// Hydrate the object
$item->fill($input);
// Validate and save.
$this->validate($item);
if ($this->parent) {
$this->parent->{$this->parent_to_self}()->save($item);
} else {
$item->save();
}
// Redirect to edit view
if (Request::ajax()) {
return Response::json(['id' => $item->id]);
} else {
return Redirect::to(DecoyURL::relative('edit', $item->id))
->with('success', $this->successMessage($item, 'created'));
}
} | php | public function store()
{
// Create a new object
$item = new $this->model;
// Remove nested model data from input and prepare to insert on save
$input = (new NestedModels)->relateTo($item);
// Hydrate the object
$item->fill($input);
// Validate and save.
$this->validate($item);
if ($this->parent) {
$this->parent->{$this->parent_to_self}()->save($item);
} else {
$item->save();
}
// Redirect to edit view
if (Request::ajax()) {
return Response::json(['id' => $item->id]);
} else {
return Redirect::to(DecoyURL::relative('edit', $item->id))
->with('success', $this->successMessage($item, 'created'));
}
} | [
"public",
"function",
"store",
"(",
")",
"{",
"// Create a new object",
"$",
"item",
"=",
"new",
"$",
"this",
"->",
"model",
";",
"// Remove nested model data from input and prepare to insert on save",
"$",
"input",
"=",
"(",
"new",
"NestedModels",
")",
"->",
"relateTo",
"(",
"$",
"item",
")",
";",
"// Hydrate the object",
"$",
"item",
"->",
"fill",
"(",
"$",
"input",
")",
";",
"// Validate and save.",
"$",
"this",
"->",
"validate",
"(",
"$",
"item",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parent",
")",
"{",
"$",
"this",
"->",
"parent",
"->",
"{",
"$",
"this",
"->",
"parent_to_self",
"}",
"(",
")",
"->",
"save",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"item",
"->",
"save",
"(",
")",
";",
"}",
"// Redirect to edit view",
"if",
"(",
"Request",
"::",
"ajax",
"(",
")",
")",
"{",
"return",
"Response",
"::",
"json",
"(",
"[",
"'id'",
"=>",
"$",
"item",
"->",
"id",
"]",
")",
";",
"}",
"else",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"DecoyURL",
"::",
"relative",
"(",
"'edit'",
",",
"$",
"item",
"->",
"id",
")",
")",
"->",
"with",
"(",
"'success'",
",",
"$",
"this",
"->",
"successMessage",
"(",
"$",
"item",
",",
"'created'",
")",
")",
";",
"}",
"}"
] | Store a new record
@return Symfony\Component\HttpFoundation\Response Redirect to edit view | [
"Store",
"a",
"new",
"record"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L499-L525 |
30,643 | BKWLD/decoy | classes/Controllers/Base.php | Base.edit | public function edit($id)
{
// Get the model instance
$item = $this->findOrFail($id);
// Respond to AJAX requests for a single item with JSON
if (Request::ajax()) {
return Response::json($item);
}
// Look for overriden views
$this->overrideViews();
// Populate form
Former::populate($item);
Former::withRules($this->getRules());
// Initialize localization
with($localize = new Localize)
->item($item)
->title(Str::singular($this->title));
// Make the sidebar
$sidebar = new Sidebar($item);
if (!$localize->hidden()) {
$sidebar->addToEnd($localize);
}
// Render view
return $this->populateView($this->show_view, [
'item' => $item,
'localize' => $localize,
'sidebar' => $sidebar,
'parent_id' => $this->parent ? $this->parent->getKey() : null,
]);
} | php | public function edit($id)
{
// Get the model instance
$item = $this->findOrFail($id);
// Respond to AJAX requests for a single item with JSON
if (Request::ajax()) {
return Response::json($item);
}
// Look for overriden views
$this->overrideViews();
// Populate form
Former::populate($item);
Former::withRules($this->getRules());
// Initialize localization
with($localize = new Localize)
->item($item)
->title(Str::singular($this->title));
// Make the sidebar
$sidebar = new Sidebar($item);
if (!$localize->hidden()) {
$sidebar->addToEnd($localize);
}
// Render view
return $this->populateView($this->show_view, [
'item' => $item,
'localize' => $localize,
'sidebar' => $sidebar,
'parent_id' => $this->parent ? $this->parent->getKey() : null,
]);
} | [
"public",
"function",
"edit",
"(",
"$",
"id",
")",
"{",
"// Get the model instance",
"$",
"item",
"=",
"$",
"this",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"// Respond to AJAX requests for a single item with JSON",
"if",
"(",
"Request",
"::",
"ajax",
"(",
")",
")",
"{",
"return",
"Response",
"::",
"json",
"(",
"$",
"item",
")",
";",
"}",
"// Look for overriden views",
"$",
"this",
"->",
"overrideViews",
"(",
")",
";",
"// Populate form",
"Former",
"::",
"populate",
"(",
"$",
"item",
")",
";",
"Former",
"::",
"withRules",
"(",
"$",
"this",
"->",
"getRules",
"(",
")",
")",
";",
"// Initialize localization",
"with",
"(",
"$",
"localize",
"=",
"new",
"Localize",
")",
"->",
"item",
"(",
"$",
"item",
")",
"->",
"title",
"(",
"Str",
"::",
"singular",
"(",
"$",
"this",
"->",
"title",
")",
")",
";",
"// Make the sidebar",
"$",
"sidebar",
"=",
"new",
"Sidebar",
"(",
"$",
"item",
")",
";",
"if",
"(",
"!",
"$",
"localize",
"->",
"hidden",
"(",
")",
")",
"{",
"$",
"sidebar",
"->",
"addToEnd",
"(",
"$",
"localize",
")",
";",
"}",
"// Render view",
"return",
"$",
"this",
"->",
"populateView",
"(",
"$",
"this",
"->",
"show_view",
",",
"[",
"'item'",
"=>",
"$",
"item",
",",
"'localize'",
"=>",
"$",
"localize",
",",
"'sidebar'",
"=>",
"$",
"sidebar",
",",
"'parent_id'",
"=>",
"$",
"this",
"->",
"parent",
"?",
"$",
"this",
"->",
"parent",
"->",
"getKey",
"(",
")",
":",
"null",
",",
"]",
")",
";",
"}"
] | Show the edit form. Sets view via the layout.
@param int $id Model key
@return Illuminate\Contracts\View\Factory | [
"Show",
"the",
"edit",
"form",
".",
"Sets",
"view",
"via",
"the",
"layout",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L533-L568 |
30,644 | BKWLD/decoy | classes/Controllers/Base.php | Base.destroy | public function destroy($id)
{
// Find the item
$item = $this->findOrFail($id);
// Delete row (this should trigger file attachment deletes as well)
$item->delete();
// As long as not an ajax request, go back to the parent directory of the referrer
if (Request::ajax()) {
return Response::json();
} else {
return Redirect::to(DecoyURL::relative('index'))
->with('success', $this->successMessage($item, 'deleted'));
}
} | php | public function destroy($id)
{
// Find the item
$item = $this->findOrFail($id);
// Delete row (this should trigger file attachment deletes as well)
$item->delete();
// As long as not an ajax request, go back to the parent directory of the referrer
if (Request::ajax()) {
return Response::json();
} else {
return Redirect::to(DecoyURL::relative('index'))
->with('success', $this->successMessage($item, 'deleted'));
}
} | [
"public",
"function",
"destroy",
"(",
"$",
"id",
")",
"{",
"// Find the item",
"$",
"item",
"=",
"$",
"this",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"// Delete row (this should trigger file attachment deletes as well)",
"$",
"item",
"->",
"delete",
"(",
")",
";",
"// As long as not an ajax request, go back to the parent directory of the referrer",
"if",
"(",
"Request",
"::",
"ajax",
"(",
")",
")",
"{",
"return",
"Response",
"::",
"json",
"(",
")",
";",
"}",
"else",
"{",
"return",
"Redirect",
"::",
"to",
"(",
"DecoyURL",
"::",
"relative",
"(",
"'index'",
")",
")",
"->",
"with",
"(",
"'success'",
",",
"$",
"this",
"->",
"successMessage",
"(",
"$",
"item",
",",
"'deleted'",
")",
")",
";",
"}",
"}"
] | Destroy a record
@param int $id Model key
@return Symfony\Component\HttpFoundation\Response Redirect to listing | [
"Destroy",
"a",
"record"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L619-L634 |
30,645 | BKWLD/decoy | classes/Controllers/Base.php | Base.duplicate | public function duplicate($id)
{
// Find the source item
$src = $this->findOrFail($id);
if (empty($src->cloneable)) {
return App::abort(404);
}
// Duplicate using Bkwld\Cloner
$new = $src->duplicate();
// Don't make duplicates public
if (array_key_exists('public', $new->getAttributes())) {
$this->public = 0;
}
// If there is a name or title field, append " copy" to it. Use "original"
// to avoid mutators.
if ($name = $new->getOriginal('name')) {
$new->setAttribute('name', $name.' copy');
} elseif ($title = $new->getOriginal('title')) {
$new->setAttribute('title', $title.' copy');
}
// Set localization options on new instance
if ($locale = request('locale')) {
$new->locale = $locale;
if (isset($src->locale_group)) {
$new->locale_group = $src->locale_group;
}
}
// Save any changes that were made
$new->save();
// Save the new record and redirect to its edit view
return Redirect::to(DecoyURL::relative('edit', $new->getKey()))
->with('success', $this->successMessage($src, 'duplicated'));
} | php | public function duplicate($id)
{
// Find the source item
$src = $this->findOrFail($id);
if (empty($src->cloneable)) {
return App::abort(404);
}
// Duplicate using Bkwld\Cloner
$new = $src->duplicate();
// Don't make duplicates public
if (array_key_exists('public', $new->getAttributes())) {
$this->public = 0;
}
// If there is a name or title field, append " copy" to it. Use "original"
// to avoid mutators.
if ($name = $new->getOriginal('name')) {
$new->setAttribute('name', $name.' copy');
} elseif ($title = $new->getOriginal('title')) {
$new->setAttribute('title', $title.' copy');
}
// Set localization options on new instance
if ($locale = request('locale')) {
$new->locale = $locale;
if (isset($src->locale_group)) {
$new->locale_group = $src->locale_group;
}
}
// Save any changes that were made
$new->save();
// Save the new record and redirect to its edit view
return Redirect::to(DecoyURL::relative('edit', $new->getKey()))
->with('success', $this->successMessage($src, 'duplicated'));
} | [
"public",
"function",
"duplicate",
"(",
"$",
"id",
")",
"{",
"// Find the source item",
"$",
"src",
"=",
"$",
"this",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"src",
"->",
"cloneable",
")",
")",
"{",
"return",
"App",
"::",
"abort",
"(",
"404",
")",
";",
"}",
"// Duplicate using Bkwld\\Cloner",
"$",
"new",
"=",
"$",
"src",
"->",
"duplicate",
"(",
")",
";",
"// Don't make duplicates public",
"if",
"(",
"array_key_exists",
"(",
"'public'",
",",
"$",
"new",
"->",
"getAttributes",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"public",
"=",
"0",
";",
"}",
"// If there is a name or title field, append \" copy\" to it. Use \"original\"",
"// to avoid mutators.",
"if",
"(",
"$",
"name",
"=",
"$",
"new",
"->",
"getOriginal",
"(",
"'name'",
")",
")",
"{",
"$",
"new",
"->",
"setAttribute",
"(",
"'name'",
",",
"$",
"name",
".",
"' copy'",
")",
";",
"}",
"elseif",
"(",
"$",
"title",
"=",
"$",
"new",
"->",
"getOriginal",
"(",
"'title'",
")",
")",
"{",
"$",
"new",
"->",
"setAttribute",
"(",
"'title'",
",",
"$",
"title",
".",
"' copy'",
")",
";",
"}",
"// Set localization options on new instance",
"if",
"(",
"$",
"locale",
"=",
"request",
"(",
"'locale'",
")",
")",
"{",
"$",
"new",
"->",
"locale",
"=",
"$",
"locale",
";",
"if",
"(",
"isset",
"(",
"$",
"src",
"->",
"locale_group",
")",
")",
"{",
"$",
"new",
"->",
"locale_group",
"=",
"$",
"src",
"->",
"locale_group",
";",
"}",
"}",
"// Save any changes that were made",
"$",
"new",
"->",
"save",
"(",
")",
";",
"// Save the new record and redirect to its edit view",
"return",
"Redirect",
"::",
"to",
"(",
"DecoyURL",
"::",
"relative",
"(",
"'edit'",
",",
"$",
"new",
"->",
"getKey",
"(",
")",
")",
")",
"->",
"with",
"(",
"'success'",
",",
"$",
"this",
"->",
"successMessage",
"(",
"$",
"src",
",",
"'duplicated'",
")",
")",
";",
"}"
] | Duplicate a record
@param int $id Model key
@return Symfony\Component\HttpFoundation\Response Redirect to new record | [
"Duplicate",
"a",
"record"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L646-L684 |
30,646 | BKWLD/decoy | classes/Controllers/Base.php | Base.autocomplete | public function autocomplete()
{
// Do nothing if the query is too short
if (strlen(request('query')) < 1) {
return Response::json();
}
// Get an instance so the title attributes can be found. If none are found,
// then there are no results, so bounce
if (!$model = call_user_func([$this->model, 'first'])) {
return Response::json($this->formatAutocompleteResponse([]));
}
// Get data matching the query
$query = call_user_func([$this->model, 'titleContains'], request('query'))
->ordered()
->take(15); // Note, this is also enforced in the autocomplete.js
// Don't return any rows already attached to the parent. So make sure the
// id is not already in the pivot table for the parent
if ($this->isChildInManyToMany()) {
// See if there is an exact match on what's been entered. This is useful
// for many to manys with tags because we want to know if the reason that
// autocomplete returns no results on an exact match that is already
// attached is because it already exists. Otherwise, it would allow the
// user to create the tag
if ($this->parentRelation()
->titleContains(request('query'), true)
->count()) {
return Response::json(['exists' => true]);
}
// Get the ids of already attached rows through the relationship function.
// There are ways to do just in SQL but then we lose the ability for the
// relationship function to apply conditions, like is done in polymoprhic
// relationships.
$siblings = $this->parentRelation()->get();
if (count($siblings)) {
$sibling_ids = [];
foreach ($siblings as $sibling) {
$sibling_ids[] = $sibling->id;
}
// Add condition to query
$model = new $this->model;
$query = $query->whereNotIn($model->getQualifiedKeyName(), $sibling_ids);
}
}
// Return result
return Response::json($this->formatAutocompleteResponse($query->get()));
} | php | public function autocomplete()
{
// Do nothing if the query is too short
if (strlen(request('query')) < 1) {
return Response::json();
}
// Get an instance so the title attributes can be found. If none are found,
// then there are no results, so bounce
if (!$model = call_user_func([$this->model, 'first'])) {
return Response::json($this->formatAutocompleteResponse([]));
}
// Get data matching the query
$query = call_user_func([$this->model, 'titleContains'], request('query'))
->ordered()
->take(15); // Note, this is also enforced in the autocomplete.js
// Don't return any rows already attached to the parent. So make sure the
// id is not already in the pivot table for the parent
if ($this->isChildInManyToMany()) {
// See if there is an exact match on what's been entered. This is useful
// for many to manys with tags because we want to know if the reason that
// autocomplete returns no results on an exact match that is already
// attached is because it already exists. Otherwise, it would allow the
// user to create the tag
if ($this->parentRelation()
->titleContains(request('query'), true)
->count()) {
return Response::json(['exists' => true]);
}
// Get the ids of already attached rows through the relationship function.
// There are ways to do just in SQL but then we lose the ability for the
// relationship function to apply conditions, like is done in polymoprhic
// relationships.
$siblings = $this->parentRelation()->get();
if (count($siblings)) {
$sibling_ids = [];
foreach ($siblings as $sibling) {
$sibling_ids[] = $sibling->id;
}
// Add condition to query
$model = new $this->model;
$query = $query->whereNotIn($model->getQualifiedKeyName(), $sibling_ids);
}
}
// Return result
return Response::json($this->formatAutocompleteResponse($query->get()));
} | [
"public",
"function",
"autocomplete",
"(",
")",
"{",
"// Do nothing if the query is too short",
"if",
"(",
"strlen",
"(",
"request",
"(",
"'query'",
")",
")",
"<",
"1",
")",
"{",
"return",
"Response",
"::",
"json",
"(",
")",
";",
"}",
"// Get an instance so the title attributes can be found. If none are found,",
"// then there are no results, so bounce",
"if",
"(",
"!",
"$",
"model",
"=",
"call_user_func",
"(",
"[",
"$",
"this",
"->",
"model",
",",
"'first'",
"]",
")",
")",
"{",
"return",
"Response",
"::",
"json",
"(",
"$",
"this",
"->",
"formatAutocompleteResponse",
"(",
"[",
"]",
")",
")",
";",
"}",
"// Get data matching the query",
"$",
"query",
"=",
"call_user_func",
"(",
"[",
"$",
"this",
"->",
"model",
",",
"'titleContains'",
"]",
",",
"request",
"(",
"'query'",
")",
")",
"->",
"ordered",
"(",
")",
"->",
"take",
"(",
"15",
")",
";",
"// Note, this is also enforced in the autocomplete.js",
"// Don't return any rows already attached to the parent. So make sure the",
"// id is not already in the pivot table for the parent",
"if",
"(",
"$",
"this",
"->",
"isChildInManyToMany",
"(",
")",
")",
"{",
"// See if there is an exact match on what's been entered. This is useful",
"// for many to manys with tags because we want to know if the reason that",
"// autocomplete returns no results on an exact match that is already",
"// attached is because it already exists. Otherwise, it would allow the",
"// user to create the tag",
"if",
"(",
"$",
"this",
"->",
"parentRelation",
"(",
")",
"->",
"titleContains",
"(",
"request",
"(",
"'query'",
")",
",",
"true",
")",
"->",
"count",
"(",
")",
")",
"{",
"return",
"Response",
"::",
"json",
"(",
"[",
"'exists'",
"=>",
"true",
"]",
")",
";",
"}",
"// Get the ids of already attached rows through the relationship function.",
"// There are ways to do just in SQL but then we lose the ability for the",
"// relationship function to apply conditions, like is done in polymoprhic",
"// relationships.",
"$",
"siblings",
"=",
"$",
"this",
"->",
"parentRelation",
"(",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"siblings",
")",
")",
"{",
"$",
"sibling_ids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"siblings",
"as",
"$",
"sibling",
")",
"{",
"$",
"sibling_ids",
"[",
"]",
"=",
"$",
"sibling",
"->",
"id",
";",
"}",
"// Add condition to query",
"$",
"model",
"=",
"new",
"$",
"this",
"->",
"model",
";",
"$",
"query",
"=",
"$",
"query",
"->",
"whereNotIn",
"(",
"$",
"model",
"->",
"getQualifiedKeyName",
"(",
")",
",",
"$",
"sibling_ids",
")",
";",
"}",
"}",
"// Return result",
"return",
"Response",
"::",
"json",
"(",
"$",
"this",
"->",
"formatAutocompleteResponse",
"(",
"$",
"query",
"->",
"get",
"(",
")",
")",
")",
";",
"}"
] | List as JSON for autocomplete widgets
@return Illuminate\Http\Response JSON | [
"List",
"as",
"JSON",
"for",
"autocomplete",
"widgets"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L695-L747 |
30,647 | BKWLD/decoy | classes/Controllers/Base.php | Base.autocompleteViewVars | public function autocompleteViewVars()
{
if (!$this->parent) {
return [];
}
$parent_controller = new $this->parent_controller;
return [
'parent_id' => $this->parent->getKey(),
'parent_controller' => $this->parent_controller,
'parent_controller_title' => $parent_controller->title(),
'parent_controller_description' => $parent_controller->description(),
'many_to_many' => $this->isChildInManyToMany(),
];
} | php | public function autocompleteViewVars()
{
if (!$this->parent) {
return [];
}
$parent_controller = new $this->parent_controller;
return [
'parent_id' => $this->parent->getKey(),
'parent_controller' => $this->parent_controller,
'parent_controller_title' => $parent_controller->title(),
'parent_controller_description' => $parent_controller->description(),
'many_to_many' => $this->isChildInManyToMany(),
];
} | [
"public",
"function",
"autocompleteViewVars",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parent",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"parent_controller",
"=",
"new",
"$",
"this",
"->",
"parent_controller",
";",
"return",
"[",
"'parent_id'",
"=>",
"$",
"this",
"->",
"parent",
"->",
"getKey",
"(",
")",
",",
"'parent_controller'",
"=>",
"$",
"this",
"->",
"parent_controller",
",",
"'parent_controller_title'",
"=>",
"$",
"parent_controller",
"->",
"title",
"(",
")",
",",
"'parent_controller_description'",
"=>",
"$",
"parent_controller",
"->",
"description",
"(",
")",
",",
"'many_to_many'",
"=>",
"$",
"this",
"->",
"isChildInManyToMany",
"(",
")",
",",
"]",
";",
"}"
] | Return key-val pairs needed for view partials related to many to many
autocompletes
@return array key-val pairs | [
"Return",
"key",
"-",
"val",
"pairs",
"needed",
"for",
"view",
"partials",
"related",
"to",
"many",
"to",
"many",
"autocompletes"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L755-L770 |
30,648 | BKWLD/decoy | classes/Controllers/Base.php | Base.attach | public function attach($id)
{
// Require there to be a parent id and a valid id for the resource
$item = $this->findOrFail($id);
// Do the attach
$item->fireDecoyEvent('attaching', [$item, $this->parent]);
$item->{$this->self_to_parent}()->attach($this->parent);
$item->fireDecoyEvent('attached', [$item, $this->parent]);
// Return the response
return Response::json();
} | php | public function attach($id)
{
// Require there to be a parent id and a valid id for the resource
$item = $this->findOrFail($id);
// Do the attach
$item->fireDecoyEvent('attaching', [$item, $this->parent]);
$item->{$this->self_to_parent}()->attach($this->parent);
$item->fireDecoyEvent('attached', [$item, $this->parent]);
// Return the response
return Response::json();
} | [
"public",
"function",
"attach",
"(",
"$",
"id",
")",
"{",
"// Require there to be a parent id and a valid id for the resource",
"$",
"item",
"=",
"$",
"this",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"// Do the attach",
"$",
"item",
"->",
"fireDecoyEvent",
"(",
"'attaching'",
",",
"[",
"$",
"item",
",",
"$",
"this",
"->",
"parent",
"]",
")",
";",
"$",
"item",
"->",
"{",
"$",
"this",
"->",
"self_to_parent",
"}",
"(",
")",
"->",
"attach",
"(",
"$",
"this",
"->",
"parent",
")",
";",
"$",
"item",
"->",
"fireDecoyEvent",
"(",
"'attached'",
",",
"[",
"$",
"item",
",",
"$",
"this",
"->",
"parent",
"]",
")",
";",
"// Return the response",
"return",
"Response",
"::",
"json",
"(",
")",
";",
"}"
] | Attach a model to a parent_id, like with a many to many style
autocomplete widget
@param int $id The id of the parent model
@return Illuminate\Http\Response JSON | [
"Attach",
"a",
"model",
"to",
"a",
"parent_id",
"like",
"with",
"a",
"many",
"to",
"many",
"style",
"autocomplete",
"widget"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L779-L791 |
30,649 | BKWLD/decoy | classes/Controllers/Base.php | Base.remove | public function remove($id)
{
// Support removing many ids at once
$ids = Request::has('ids') ? explode(',', request('ids')) : [$id];
// Get the model instances for each id, for the purpose of event firing
$items = array_map(function ($id) {
return $this->findOrFail($id);
}, $ids);
// Lookup up the parent model so we can bulk remove multiple of THIS model
foreach ($items as $item) {
$item->fireDecoyEvent('removing', [$item, $this->parent]);
}
$this->parentRelation()->detach($ids);
foreach ($items as $item) {
$item->fireDecoyEvent('removed', [$item, $this->parent]);
}
// Redirect. We can use back cause this is never called from a "show"
// page like get_delete is.
if (Request::ajax()) {
return Response::json();
}
return Redirect::back();
} | php | public function remove($id)
{
// Support removing many ids at once
$ids = Request::has('ids') ? explode(',', request('ids')) : [$id];
// Get the model instances for each id, for the purpose of event firing
$items = array_map(function ($id) {
return $this->findOrFail($id);
}, $ids);
// Lookup up the parent model so we can bulk remove multiple of THIS model
foreach ($items as $item) {
$item->fireDecoyEvent('removing', [$item, $this->parent]);
}
$this->parentRelation()->detach($ids);
foreach ($items as $item) {
$item->fireDecoyEvent('removed', [$item, $this->parent]);
}
// Redirect. We can use back cause this is never called from a "show"
// page like get_delete is.
if (Request::ajax()) {
return Response::json();
}
return Redirect::back();
} | [
"public",
"function",
"remove",
"(",
"$",
"id",
")",
"{",
"// Support removing many ids at once",
"$",
"ids",
"=",
"Request",
"::",
"has",
"(",
"'ids'",
")",
"?",
"explode",
"(",
"','",
",",
"request",
"(",
"'ids'",
")",
")",
":",
"[",
"$",
"id",
"]",
";",
"// Get the model instances for each id, for the purpose of event firing",
"$",
"items",
"=",
"array_map",
"(",
"function",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"this",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"}",
",",
"$",
"ids",
")",
";",
"// Lookup up the parent model so we can bulk remove multiple of THIS model",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"fireDecoyEvent",
"(",
"'removing'",
",",
"[",
"$",
"item",
",",
"$",
"this",
"->",
"parent",
"]",
")",
";",
"}",
"$",
"this",
"->",
"parentRelation",
"(",
")",
"->",
"detach",
"(",
"$",
"ids",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"fireDecoyEvent",
"(",
"'removed'",
",",
"[",
"$",
"item",
",",
"$",
"this",
"->",
"parent",
"]",
")",
";",
"}",
"// Redirect. We can use back cause this is never called from a \"show\"",
"// page like get_delete is.",
"if",
"(",
"Request",
"::",
"ajax",
"(",
")",
")",
"{",
"return",
"Response",
"::",
"json",
"(",
")",
";",
"}",
"return",
"Redirect",
"::",
"back",
"(",
")",
";",
"}"
] | Remove a relationship. Very similar to delete, except that we're
not actually deleting from the database
@param mixed $id One or many (commaa delimited) parent ids
@return Illuminate\Http\Response Either a JSON or Redirect response | [
"Remove",
"a",
"relationship",
".",
"Very",
"similar",
"to",
"delete",
"except",
"that",
"we",
"re",
"not",
"actually",
"deleting",
"from",
"the",
"database"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L799-L825 |
30,650 | BKWLD/decoy | classes/Controllers/Base.php | Base.makeIndexQuery | protected function makeIndexQuery()
{
// Open up the query. We can assume that Model has an ordered() function
// because it's defined on Decoy's Base_Model
$query = $this->parent ?
$this->parentRelation()->ordered() :
call_user_func([$this->model, 'ordered']);
// Allow trashed records
if ($this->withTrashed()) {
$query->withTrashed();
}
// Apply search
$search = new Search();
$query = $search->apply($query, $this->search());
return $query;
} | php | protected function makeIndexQuery()
{
// Open up the query. We can assume that Model has an ordered() function
// because it's defined on Decoy's Base_Model
$query = $this->parent ?
$this->parentRelation()->ordered() :
call_user_func([$this->model, 'ordered']);
// Allow trashed records
if ($this->withTrashed()) {
$query->withTrashed();
}
// Apply search
$search = new Search();
$query = $search->apply($query, $this->search());
return $query;
} | [
"protected",
"function",
"makeIndexQuery",
"(",
")",
"{",
"// Open up the query. We can assume that Model has an ordered() function",
"// because it's defined on Decoy's Base_Model",
"$",
"query",
"=",
"$",
"this",
"->",
"parent",
"?",
"$",
"this",
"->",
"parentRelation",
"(",
")",
"->",
"ordered",
"(",
")",
":",
"call_user_func",
"(",
"[",
"$",
"this",
"->",
"model",
",",
"'ordered'",
"]",
")",
";",
"// Allow trashed records",
"if",
"(",
"$",
"this",
"->",
"withTrashed",
"(",
")",
")",
"{",
"$",
"query",
"->",
"withTrashed",
"(",
")",
";",
"}",
"// Apply search",
"$",
"search",
"=",
"new",
"Search",
"(",
")",
";",
"$",
"query",
"=",
"$",
"search",
"->",
"apply",
"(",
"$",
"query",
",",
"$",
"this",
"->",
"search",
"(",
")",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Make the index query, including applying a search
@return \Illuminate\Database\Eloquent\Builder | [
"Make",
"the",
"index",
"query",
"including",
"applying",
"a",
"search"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L836-L853 |
30,651 | BKWLD/decoy | classes/Controllers/Base.php | Base.findOrFail | protected function findOrFail($id)
{
$model = $this->model;
if ($this->withTrashed()) {
return $model::withTrashed()->findOrFail($id);
} else {
return $model::findOrFail($id);
}
} | php | protected function findOrFail($id)
{
$model = $this->model;
if ($this->withTrashed()) {
return $model::withTrashed()->findOrFail($id);
} else {
return $model::findOrFail($id);
}
} | [
"protected",
"function",
"findOrFail",
"(",
"$",
"id",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
";",
"if",
"(",
"$",
"this",
"->",
"withTrashed",
"(",
")",
")",
"{",
"return",
"$",
"model",
"::",
"withTrashed",
"(",
")",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"}",
"else",
"{",
"return",
"$",
"model",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Helper for getting a model instance by ID
@param scalar $id
@return Eloquent\Model | [
"Helper",
"for",
"getting",
"a",
"model",
"instance",
"by",
"ID"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L861-L869 |
30,652 | BKWLD/decoy | classes/Controllers/Base.php | Base.validate | protected function validate($data, $rules = null, $messages = [])
{
// A request may be passed in when using Laravel traits, like how resetting
// passwords work. Get the input from it
if (is_a($data, \Illuminate\Http\Request::class)) {
$data = $data->input();
}
// Get validation rules from model
$model = null;
if (is_a($data, BaseModel::class)) {
$model = $data;
$data = $model->getAttributes();
if (empty($rules)) {
$rules = $model::$rules;
}
}
// If an AJAX update, don't require all fields to be present. Pass just the
// keys of the input to the array_only function to filter the rules list.
if (Request::ajax() && Request::getMethod() == 'PUT') {
$rules = array_only($rules, array_keys(request()->input()));
}
// Stop if no rules
if (empty($rules)) {
return;
}
// Build the validation instance and fire the intiating event.
if ($model) {
(new ModelValidator)->validate($model, $rules, $messages);
} else {
$messages = array_merge(BkwldLibraryValidator::$messages, $messages);
$validation = Validator::make($data, $rules, $messages);
if ($validation->fails()) {
throw new ValidationFail($validation);
}
}
} | php | protected function validate($data, $rules = null, $messages = [])
{
// A request may be passed in when using Laravel traits, like how resetting
// passwords work. Get the input from it
if (is_a($data, \Illuminate\Http\Request::class)) {
$data = $data->input();
}
// Get validation rules from model
$model = null;
if (is_a($data, BaseModel::class)) {
$model = $data;
$data = $model->getAttributes();
if (empty($rules)) {
$rules = $model::$rules;
}
}
// If an AJAX update, don't require all fields to be present. Pass just the
// keys of the input to the array_only function to filter the rules list.
if (Request::ajax() && Request::getMethod() == 'PUT') {
$rules = array_only($rules, array_keys(request()->input()));
}
// Stop if no rules
if (empty($rules)) {
return;
}
// Build the validation instance and fire the intiating event.
if ($model) {
(new ModelValidator)->validate($model, $rules, $messages);
} else {
$messages = array_merge(BkwldLibraryValidator::$messages, $messages);
$validation = Validator::make($data, $rules, $messages);
if ($validation->fails()) {
throw new ValidationFail($validation);
}
}
} | [
"protected",
"function",
"validate",
"(",
"$",
"data",
",",
"$",
"rules",
"=",
"null",
",",
"$",
"messages",
"=",
"[",
"]",
")",
"{",
"// A request may be passed in when using Laravel traits, like how resetting",
"// passwords work. Get the input from it",
"if",
"(",
"is_a",
"(",
"$",
"data",
",",
"\\",
"Illuminate",
"\\",
"Http",
"\\",
"Request",
"::",
"class",
")",
")",
"{",
"$",
"data",
"=",
"$",
"data",
"->",
"input",
"(",
")",
";",
"}",
"// Get validation rules from model",
"$",
"model",
"=",
"null",
";",
"if",
"(",
"is_a",
"(",
"$",
"data",
",",
"BaseModel",
"::",
"class",
")",
")",
"{",
"$",
"model",
"=",
"$",
"data",
";",
"$",
"data",
"=",
"$",
"model",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rules",
")",
")",
"{",
"$",
"rules",
"=",
"$",
"model",
"::",
"$",
"rules",
";",
"}",
"}",
"// If an AJAX update, don't require all fields to be present. Pass just the",
"// keys of the input to the array_only function to filter the rules list.",
"if",
"(",
"Request",
"::",
"ajax",
"(",
")",
"&&",
"Request",
"::",
"getMethod",
"(",
")",
"==",
"'PUT'",
")",
"{",
"$",
"rules",
"=",
"array_only",
"(",
"$",
"rules",
",",
"array_keys",
"(",
"request",
"(",
")",
"->",
"input",
"(",
")",
")",
")",
";",
"}",
"// Stop if no rules",
"if",
"(",
"empty",
"(",
"$",
"rules",
")",
")",
"{",
"return",
";",
"}",
"// Build the validation instance and fire the intiating event.",
"if",
"(",
"$",
"model",
")",
"{",
"(",
"new",
"ModelValidator",
")",
"->",
"validate",
"(",
"$",
"model",
",",
"$",
"rules",
",",
"$",
"messages",
")",
";",
"}",
"else",
"{",
"$",
"messages",
"=",
"array_merge",
"(",
"BkwldLibraryValidator",
"::",
"$",
"messages",
",",
"$",
"messages",
")",
";",
"$",
"validation",
"=",
"Validator",
"::",
"make",
"(",
"$",
"data",
",",
"$",
"rules",
",",
"$",
"messages",
")",
";",
"if",
"(",
"$",
"validation",
"->",
"fails",
"(",
")",
")",
"{",
"throw",
"new",
"ValidationFail",
"(",
"$",
"validation",
")",
";",
"}",
"}",
"}"
] | All actions validate in basically the same way. This is shared logic for that
@param BaseModel|Request|array $data
@param array $rules A Laravel rules array. If null, will be pulled from model
@param array $messages Special error messages
@return void
@throws ValidationFail | [
"All",
"actions",
"validate",
"in",
"basically",
"the",
"same",
"way",
".",
"This",
"is",
"shared",
"logic",
"for",
"that"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L893-L932 |
30,653 | BKWLD/decoy | classes/Controllers/Base.php | Base.formatAutocompleteResponse | public function formatAutocompleteResponse($results)
{
$output = [];
foreach ($results as $row) {
// Only keep the id and title fields
$item = new stdClass;
$item->id = $row->getKey();
$item->title = $row->getAdminTitleAttribute();
// Add properties for the columns mentioned in the list view within the
// 'columns' property of this row in the response. Use the same logic
// found in Decoy::renderListColumn();
$item->columns = [];
foreach ($this->columns() as $column) {
if (method_exists($row, $column)) {
$item->columns[$column] = call_user_func([$row, $column]);
} elseif (isset($row->$column)) {
if (is_a($row->$column, 'Carbon\Carbon')) {
$item->columns[$column] = $row->$column->format(FORMAT_DATE);
} else {
$item->columns[$column] = $row->$column;
}
} else {
$item->columns[$column] = null;
}
}
// Add the item to the output
$output[] = $item;
}
return $output;
} | php | public function formatAutocompleteResponse($results)
{
$output = [];
foreach ($results as $row) {
// Only keep the id and title fields
$item = new stdClass;
$item->id = $row->getKey();
$item->title = $row->getAdminTitleAttribute();
// Add properties for the columns mentioned in the list view within the
// 'columns' property of this row in the response. Use the same logic
// found in Decoy::renderListColumn();
$item->columns = [];
foreach ($this->columns() as $column) {
if (method_exists($row, $column)) {
$item->columns[$column] = call_user_func([$row, $column]);
} elseif (isset($row->$column)) {
if (is_a($row->$column, 'Carbon\Carbon')) {
$item->columns[$column] = $row->$column->format(FORMAT_DATE);
} else {
$item->columns[$column] = $row->$column;
}
} else {
$item->columns[$column] = null;
}
}
// Add the item to the output
$output[] = $item;
}
return $output;
} | [
"public",
"function",
"formatAutocompleteResponse",
"(",
"$",
"results",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"row",
")",
"{",
"// Only keep the id and title fields",
"$",
"item",
"=",
"new",
"stdClass",
";",
"$",
"item",
"->",
"id",
"=",
"$",
"row",
"->",
"getKey",
"(",
")",
";",
"$",
"item",
"->",
"title",
"=",
"$",
"row",
"->",
"getAdminTitleAttribute",
"(",
")",
";",
"// Add properties for the columns mentioned in the list view within the",
"// 'columns' property of this row in the response. Use the same logic",
"// found in Decoy::renderListColumn();",
"$",
"item",
"->",
"columns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"row",
",",
"$",
"column",
")",
")",
"{",
"$",
"item",
"->",
"columns",
"[",
"$",
"column",
"]",
"=",
"call_user_func",
"(",
"[",
"$",
"row",
",",
"$",
"column",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"row",
"->",
"$",
"column",
")",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"row",
"->",
"$",
"column",
",",
"'Carbon\\Carbon'",
")",
")",
"{",
"$",
"item",
"->",
"columns",
"[",
"$",
"column",
"]",
"=",
"$",
"row",
"->",
"$",
"column",
"->",
"format",
"(",
"FORMAT_DATE",
")",
";",
"}",
"else",
"{",
"$",
"item",
"->",
"columns",
"[",
"$",
"column",
"]",
"=",
"$",
"row",
"->",
"$",
"column",
";",
"}",
"}",
"else",
"{",
"$",
"item",
"->",
"columns",
"[",
"$",
"column",
"]",
"=",
"null",
";",
"}",
"}",
"// Add the item to the output",
"$",
"output",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Format the results of a query in the format needed for the autocomplete
responses
@param array $results
@return array | [
"Format",
"the",
"results",
"of",
"a",
"query",
"in",
"the",
"format",
"needed",
"for",
"the",
"autocomplete",
"responses"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L941-L974 |
30,654 | BKWLD/decoy | classes/Controllers/Base.php | Base.parentRelation | private function parentRelation()
{
if ($this->parent && method_exists($this->parent, $this->parent_to_self)) {
return $this->parent->{$this->parent_to_self}();
}
return false;
} | php | private function parentRelation()
{
if ($this->parent && method_exists($this->parent, $this->parent_to_self)) {
return $this->parent->{$this->parent_to_self}();
}
return false;
} | [
"private",
"function",
"parentRelation",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parent",
"&&",
"method_exists",
"(",
"$",
"this",
"->",
"parent",
",",
"$",
"this",
"->",
"parent_to_self",
")",
")",
"{",
"return",
"$",
"this",
"->",
"parent",
"->",
"{",
"$",
"this",
"->",
"parent_to_self",
"}",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Run the parent relationship function for the active model, returning the Relation
object. Returns false if none found.
@return Illuminate\Database\Eloquent\Relations\Relation | false | [
"Run",
"the",
"parent",
"relationship",
"function",
"for",
"the",
"active",
"model",
"returning",
"the",
"Relation",
"object",
".",
"Returns",
"false",
"if",
"none",
"found",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L993-L1000 |
30,655 | BKWLD/decoy | classes/Controllers/Base.php | Base.overrideViews | protected function overrideViews()
{
$dir = Str::snake($this->controllerName());
$path = base_path('resources/views/admin/').$dir;
app('view')->prependNamespace('decoy', $path);
} | php | protected function overrideViews()
{
$dir = Str::snake($this->controllerName());
$path = base_path('resources/views/admin/').$dir;
app('view')->prependNamespace('decoy', $path);
} | [
"protected",
"function",
"overrideViews",
"(",
")",
"{",
"$",
"dir",
"=",
"Str",
"::",
"snake",
"(",
"$",
"this",
"->",
"controllerName",
"(",
")",
")",
";",
"$",
"path",
"=",
"base_path",
"(",
"'resources/views/admin/'",
")",
".",
"$",
"dir",
";",
"app",
"(",
"'view'",
")",
"->",
"prependNamespace",
"(",
"'decoy'",
",",
"$",
"path",
")",
";",
"}"
] | Tell Laravel to look for view files within the app admin views so that,
on a controller-level basis, the app can customize elements of an admin
view through it's partials.
@return void | [
"Tell",
"Laravel",
"to",
"look",
"for",
"view",
"files",
"within",
"the",
"app",
"admin",
"views",
"so",
"that",
"on",
"a",
"controller",
"-",
"level",
"basis",
"the",
"app",
"can",
"customize",
"elements",
"of",
"an",
"admin",
"view",
"through",
"it",
"s",
"partials",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L1009-L1014 |
30,656 | BKWLD/decoy | classes/Controllers/Base.php | Base.populateView | protected function populateView($content, $vars = [])
{
// The view
if (is_string($content)) {
$this->layout->content = View::make($content);
} else {
$this->layout->content = $content;
}
// Set vars
$this->layout->title = $this->title();
$this->layout->description = $this->description();
View::share('controller', $this->controller);
// Make sure that the content is a Laravel view before applying vars.
// to it. In the case of the index view, `content` is a Fields\Listing
// instance, not a Laravel view
if (is_a($this->layout->content, 'Illuminate\View\View')) {
$this->layout->content->with($vars);
}
// Return the layout View
return $this->layout;
} | php | protected function populateView($content, $vars = [])
{
// The view
if (is_string($content)) {
$this->layout->content = View::make($content);
} else {
$this->layout->content = $content;
}
// Set vars
$this->layout->title = $this->title();
$this->layout->description = $this->description();
View::share('controller', $this->controller);
// Make sure that the content is a Laravel view before applying vars.
// to it. In the case of the index view, `content` is a Fields\Listing
// instance, not a Laravel view
if (is_a($this->layout->content, 'Illuminate\View\View')) {
$this->layout->content->with($vars);
}
// Return the layout View
return $this->layout;
} | [
"protected",
"function",
"populateView",
"(",
"$",
"content",
",",
"$",
"vars",
"=",
"[",
"]",
")",
"{",
"// The view",
"if",
"(",
"is_string",
"(",
"$",
"content",
")",
")",
"{",
"$",
"this",
"->",
"layout",
"->",
"content",
"=",
"View",
"::",
"make",
"(",
"$",
"content",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"layout",
"->",
"content",
"=",
"$",
"content",
";",
"}",
"// Set vars",
"$",
"this",
"->",
"layout",
"->",
"title",
"=",
"$",
"this",
"->",
"title",
"(",
")",
";",
"$",
"this",
"->",
"layout",
"->",
"description",
"=",
"$",
"this",
"->",
"description",
"(",
")",
";",
"View",
"::",
"share",
"(",
"'controller'",
",",
"$",
"this",
"->",
"controller",
")",
";",
"// Make sure that the content is a Laravel view before applying vars.",
"// to it. In the case of the index view, `content` is a Fields\\Listing",
"// instance, not a Laravel view",
"if",
"(",
"is_a",
"(",
"$",
"this",
"->",
"layout",
"->",
"content",
",",
"'Illuminate\\View\\View'",
")",
")",
"{",
"$",
"this",
"->",
"layout",
"->",
"content",
"->",
"with",
"(",
"$",
"vars",
")",
";",
"}",
"// Return the layout View",
"return",
"$",
"this",
"->",
"layout",
";",
"}"
] | Pass controller properties that are used by the layout and views through
to the view layer
@param mixed $content string view name or an HtmlObject / View object
@param array $vars Key value pairs passed to the content view
@return Illuminate\View\View | [
"Pass",
"controller",
"properties",
"that",
"are",
"used",
"by",
"the",
"layout",
"and",
"views",
"through",
"to",
"the",
"view",
"layer"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L1024-L1047 |
30,657 | BKWLD/decoy | classes/Controllers/Base.php | Base.successMessage | protected function successMessage($input = '', $verb = 'saved')
{
// Figure out the title and wrap it in quotes
$title = $input;
if (is_a($input, '\Bkwld\Decoy\Models\Base')) {
$title = $input->getAdminTitleAttribute();
}
if ($title && is_string($title)) {
$title = '"'.$title.'"';
}
// Render the message
$message = __('decoy::base.success_message', ['model' => Str::singular($this->title), 'title' => $title, 'verb' => __("decoy::base.verb.$verb")]);
// Add extra messaging for copies
if ($verb == 'duplicated') {
$url = preg_replace('#/duplicate#', '/edit', Request::url());
$message .= __('decoy::base.success_duplicated', ['url' => $url]);
}
// Add extra messaging if the creation was begun from the localize UI
if ($verb == 'duplicated' && is_a($input, '\Bkwld\Decoy\Models\Base') && !empty($input->locale)) {
$message .= __('decoy::base.success_localized', ['locale' => config('decoy.site.locales')[$input->locale]]);
}
// Return message
return $message;
} | php | protected function successMessage($input = '', $verb = 'saved')
{
// Figure out the title and wrap it in quotes
$title = $input;
if (is_a($input, '\Bkwld\Decoy\Models\Base')) {
$title = $input->getAdminTitleAttribute();
}
if ($title && is_string($title)) {
$title = '"'.$title.'"';
}
// Render the message
$message = __('decoy::base.success_message', ['model' => Str::singular($this->title), 'title' => $title, 'verb' => __("decoy::base.verb.$verb")]);
// Add extra messaging for copies
if ($verb == 'duplicated') {
$url = preg_replace('#/duplicate#', '/edit', Request::url());
$message .= __('decoy::base.success_duplicated', ['url' => $url]);
}
// Add extra messaging if the creation was begun from the localize UI
if ($verb == 'duplicated' && is_a($input, '\Bkwld\Decoy\Models\Base') && !empty($input->locale)) {
$message .= __('decoy::base.success_localized', ['locale' => config('decoy.site.locales')[$input->locale]]);
}
// Return message
return $message;
} | [
"protected",
"function",
"successMessage",
"(",
"$",
"input",
"=",
"''",
",",
"$",
"verb",
"=",
"'saved'",
")",
"{",
"// Figure out the title and wrap it in quotes",
"$",
"title",
"=",
"$",
"input",
";",
"if",
"(",
"is_a",
"(",
"$",
"input",
",",
"'\\Bkwld\\Decoy\\Models\\Base'",
")",
")",
"{",
"$",
"title",
"=",
"$",
"input",
"->",
"getAdminTitleAttribute",
"(",
")",
";",
"}",
"if",
"(",
"$",
"title",
"&&",
"is_string",
"(",
"$",
"title",
")",
")",
"{",
"$",
"title",
"=",
"'\"'",
".",
"$",
"title",
".",
"'\"'",
";",
"}",
"// Render the message",
"$",
"message",
"=",
"__",
"(",
"'decoy::base.success_message'",
",",
"[",
"'model'",
"=>",
"Str",
"::",
"singular",
"(",
"$",
"this",
"->",
"title",
")",
",",
"'title'",
"=>",
"$",
"title",
",",
"'verb'",
"=>",
"__",
"(",
"\"decoy::base.verb.$verb\"",
")",
"]",
")",
";",
"// Add extra messaging for copies",
"if",
"(",
"$",
"verb",
"==",
"'duplicated'",
")",
"{",
"$",
"url",
"=",
"preg_replace",
"(",
"'#/duplicate#'",
",",
"'/edit'",
",",
"Request",
"::",
"url",
"(",
")",
")",
";",
"$",
"message",
".=",
"__",
"(",
"'decoy::base.success_duplicated'",
",",
"[",
"'url'",
"=>",
"$",
"url",
"]",
")",
";",
"}",
"// Add extra messaging if the creation was begun from the localize UI",
"if",
"(",
"$",
"verb",
"==",
"'duplicated'",
"&&",
"is_a",
"(",
"$",
"input",
",",
"'\\Bkwld\\Decoy\\Models\\Base'",
")",
"&&",
"!",
"empty",
"(",
"$",
"input",
"->",
"locale",
")",
")",
"{",
"$",
"message",
".=",
"__",
"(",
"'decoy::base.success_localized'",
",",
"[",
"'locale'",
"=>",
"config",
"(",
"'decoy.site.locales'",
")",
"[",
"$",
"input",
"->",
"locale",
"]",
"]",
")",
";",
"}",
"// Return message",
"return",
"$",
"message",
";",
"}"
] | Creates a success message for CRUD commands
@param Bkwld\Decoy\Model\Base|string $title The model instance that is
being worked on or a string
containing the title
@param string $verb Default: 'saved'. Past tense CRUD verb (created, saved, etc)
@return string The CRUD success message string | [
"Creates",
"a",
"success",
"message",
"for",
"CRUD",
"commands"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Base.php#L1058-L1086 |
30,658 | BKWLD/decoy | classes/Models/Traits/CanSerializeTransform.php | CanSerializeTransform.runSerializeTransforms | public function runSerializeTransforms()
{
// If the class using this trait is a collection, replace the items in the
// collection with the transformed set
if (is_a($this, Collection::class)) {
$this->items = $this->runSerializeTransformsOnCollection($this);
// Otherwise, if the class is a model, act directly on it
} elseif (is_a($this, Model::class)) {
$this->runSerializeTransformsOnModel($this);
}
} | php | public function runSerializeTransforms()
{
// If the class using this trait is a collection, replace the items in the
// collection with the transformed set
if (is_a($this, Collection::class)) {
$this->items = $this->runSerializeTransformsOnCollection($this);
// Otherwise, if the class is a model, act directly on it
} elseif (is_a($this, Model::class)) {
$this->runSerializeTransformsOnModel($this);
}
} | [
"public",
"function",
"runSerializeTransforms",
"(",
")",
"{",
"// If the class using this trait is a collection, replace the items in the",
"// collection with the transformed set",
"if",
"(",
"is_a",
"(",
"$",
"this",
",",
"Collection",
"::",
"class",
")",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"$",
"this",
"->",
"runSerializeTransformsOnCollection",
"(",
"$",
"this",
")",
";",
"// Otherwise, if the class is a model, act directly on it",
"}",
"elseif",
"(",
"is_a",
"(",
"$",
"this",
",",
"Model",
"::",
"class",
")",
")",
"{",
"$",
"this",
"->",
"runSerializeTransformsOnModel",
"(",
"$",
"this",
")",
";",
"}",
"}"
] | Apply all registered transforms to the items in the collection. If a
transform returns falsey, that model will be removed from the collection
@return void | [
"Apply",
"all",
"registered",
"transforms",
"to",
"the",
"items",
"in",
"the",
"collection",
".",
"If",
"a",
"transform",
"returns",
"falsey",
"that",
"model",
"will",
"be",
"removed",
"from",
"the",
"collection"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/CanSerializeTransform.php#L72-L83 |
30,659 | BKWLD/decoy | classes/Models/Traits/CanSerializeTransform.php | CanSerializeTransform.runSerializeTransformsOnCollection | protected function runSerializeTransformsOnCollection(Collection $collection)
{
// Loop through the collection and transform each model
return $collection->map(function ($item) {
// If collection item isn't a model, don't do anything
if (!is_a($item, Model::class)) return $item;
// Serialize the model
return $this->runSerializeTransformsOnModel($item);
// Remove all the models whose transforms did not return a value. Then
// convert back to an array.
})->filter()->all();
} | php | protected function runSerializeTransformsOnCollection(Collection $collection)
{
// Loop through the collection and transform each model
return $collection->map(function ($item) {
// If collection item isn't a model, don't do anything
if (!is_a($item, Model::class)) return $item;
// Serialize the model
return $this->runSerializeTransformsOnModel($item);
// Remove all the models whose transforms did not return a value. Then
// convert back to an array.
})->filter()->all();
} | [
"protected",
"function",
"runSerializeTransformsOnCollection",
"(",
"Collection",
"$",
"collection",
")",
"{",
"// Loop through the collection and transform each model",
"return",
"$",
"collection",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"// If collection item isn't a model, don't do anything",
"if",
"(",
"!",
"is_a",
"(",
"$",
"item",
",",
"Model",
"::",
"class",
")",
")",
"return",
"$",
"item",
";",
"// Serialize the model",
"return",
"$",
"this",
"->",
"runSerializeTransformsOnModel",
"(",
"$",
"item",
")",
";",
"// Remove all the models whose transforms did not return a value. Then",
"// convert back to an array.",
"}",
")",
"->",
"filter",
"(",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Run transforms on every model in a collection
@return Collection | [
"Run",
"transforms",
"on",
"every",
"model",
"in",
"a",
"collection"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/CanSerializeTransform.php#L90-L104 |
30,660 | BKWLD/decoy | classes/Models/Traits/CanSerializeTransform.php | CanSerializeTransform.runSerializeTransformsOnModel | protected function runSerializeTransformsOnModel(Model $model)
{
// Loop through all the transform functions
foreach ($this->serialize_transforms as $transform) {
// Call the transform and if nothing is retuned, return nothing. This will
// be used by runSerializeTransformsOnCollection() to filter out models.
if (!$model = call_user_func($transform, $model)) {
return;
}
}
// Return the transformed model
return $model;
} | php | protected function runSerializeTransformsOnModel(Model $model)
{
// Loop through all the transform functions
foreach ($this->serialize_transforms as $transform) {
// Call the transform and if nothing is retuned, return nothing. This will
// be used by runSerializeTransformsOnCollection() to filter out models.
if (!$model = call_user_func($transform, $model)) {
return;
}
}
// Return the transformed model
return $model;
} | [
"protected",
"function",
"runSerializeTransformsOnModel",
"(",
"Model",
"$",
"model",
")",
"{",
"// Loop through all the transform functions",
"foreach",
"(",
"$",
"this",
"->",
"serialize_transforms",
"as",
"$",
"transform",
")",
"{",
"// Call the transform and if nothing is retuned, return nothing. This will",
"// be used by runSerializeTransformsOnCollection() to filter out models.",
"if",
"(",
"!",
"$",
"model",
"=",
"call_user_func",
"(",
"$",
"transform",
",",
"$",
"model",
")",
")",
"{",
"return",
";",
"}",
"}",
"// Return the transformed model",
"return",
"$",
"model",
";",
"}"
] | Run transforms on a single model
@param Model $model
@return Model|void | [
"Run",
"transforms",
"on",
"a",
"single",
"model"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/CanSerializeTransform.php#L112-L126 |
30,661 | BKWLD/decoy | classes/Fields/Traits/CaptureLabel.php | CaptureLabel.label | public function label($text, $attributes = [])
{
$this->label_text = $text;
return parent::label($text, $attributes);
} | php | public function label($text, $attributes = [])
{
$this->label_text = $text;
return parent::label($text, $attributes);
} | [
"public",
"function",
"label",
"(",
"$",
"text",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"label_text",
"=",
"$",
"text",
";",
"return",
"parent",
"::",
"label",
"(",
"$",
"text",
",",
"$",
"attributes",
")",
";",
"}"
] | Override the parent label so we can use the raw text of the label
@param string $text A label
@param array $attributes The label's attributes
@return Field A field | [
"Override",
"the",
"parent",
"label",
"so",
"we",
"can",
"use",
"the",
"raw",
"text",
"of",
"the",
"label"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Traits/CaptureLabel.php#L25-L30 |
30,662 | BKWLD/decoy | classes/Controllers/ForgotPassword.php | ForgotPassword.showLinkRequestForm | public function showLinkRequestForm()
{
// Pass validation rules
Former::withRules([
'email' => 'required|email',
]);
// Set the breadcrumbs
app('decoy.breadcrumbs')->set([
route('decoy::account@login') => 'Login',
url()->current() => 'Forgot Password',
]);
// Show the page
$this->title = 'Forgot Password';
$this->description = 'You know the drill.';
return $this->populateView('decoy::account.forgot');
} | php | public function showLinkRequestForm()
{
// Pass validation rules
Former::withRules([
'email' => 'required|email',
]);
// Set the breadcrumbs
app('decoy.breadcrumbs')->set([
route('decoy::account@login') => 'Login',
url()->current() => 'Forgot Password',
]);
// Show the page
$this->title = 'Forgot Password';
$this->description = 'You know the drill.';
return $this->populateView('decoy::account.forgot');
} | [
"public",
"function",
"showLinkRequestForm",
"(",
")",
"{",
"// Pass validation rules",
"Former",
"::",
"withRules",
"(",
"[",
"'email'",
"=>",
"'required|email'",
",",
"]",
")",
";",
"// Set the breadcrumbs",
"app",
"(",
"'decoy.breadcrumbs'",
")",
"->",
"set",
"(",
"[",
"route",
"(",
"'decoy::account@login'",
")",
"=>",
"'Login'",
",",
"url",
"(",
")",
"->",
"current",
"(",
")",
"=>",
"'Forgot Password'",
",",
"]",
")",
";",
"// Show the page",
"$",
"this",
"->",
"title",
"=",
"'Forgot Password'",
";",
"$",
"this",
"->",
"description",
"=",
"'You know the drill.'",
";",
"return",
"$",
"this",
"->",
"populateView",
"(",
"'decoy::account.forgot'",
")",
";",
"}"
] | Display the form to request a password reset link.
@return \Illuminate\Http\Response | [
"Display",
"the",
"form",
"to",
"request",
"a",
"password",
"reset",
"link",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/ForgotPassword.php#L23-L41 |
30,663 | BKWLD/decoy | classes/Fields/Checklist.php | Checklist.from | public function from(array $options)
{
// Makes the options passed in override anything from the populator.
$this->grouped = true;
// Produce Former-style checkbox options
$options = FormerUtils::checkboxArray($this->name, $options);
$this->checkboxes($options);
// Make chainable
return $this;
} | php | public function from(array $options)
{
// Makes the options passed in override anything from the populator.
$this->grouped = true;
// Produce Former-style checkbox options
$options = FormerUtils::checkboxArray($this->name, $options);
$this->checkboxes($options);
// Make chainable
return $this;
} | [
"public",
"function",
"from",
"(",
"array",
"$",
"options",
")",
"{",
"// Makes the options passed in override anything from the populator.",
"$",
"this",
"->",
"grouped",
"=",
"true",
";",
"// Produce Former-style checkbox options",
"$",
"options",
"=",
"FormerUtils",
"::",
"checkboxArray",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"checkboxes",
"(",
"$",
"options",
")",
";",
"// Make chainable",
"return",
"$",
"this",
";",
"}"
] | Accept checkbox configuration from an associative array
@param array $options
@return $this | [
"Accept",
"checkbox",
"configuration",
"from",
"an",
"associative",
"array"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Checklist.php#L40-L51 |
30,664 | BKWLD/decoy | classes/Controllers/Elements.php | Elements.index | public function index($locale = null, $tab = null)
{
// If there are no locales, treat the first argument as the tab
if (!($locales = Config::get('decoy.site.locales')) || empty($locales)) {
$tab = $locale;
$locale = null;
// Otherwise, set a default locale if none was specified
} elseif (!$locale) {
$locale = Decoy::defaultLocale();
}
// Get all the elements for the current locale
$elements = app('decoy.elements')->localize($locale)->hydrate(true);
// If the user has customized permissions, filter the elements to only the
// allowed pages of elements.
if ($permissions = app('decoy.user')->getPermissionsAttribute()) {
$elements->onlyPages($permissions->elements);
}
// If handling a deep link to a tab, verify that the passed tab
// slug is a real key in the data. Else 404.
if ($tab && !in_array($tab, $elements->pluck('page_label')
->map(function ($title) {
return Str::slug($title);
})
->all())) {
App::abort(404);
}
// Populate form
Former::withRules($elements->rules());
Former::populate($elements->populate());
// Convert the collection to models for simpler manipulation
$elements = $elements->asModels();
// Set the breadcrumbs NOT include the locale/tab
app('decoy.breadcrumbs')->set([
route('decoy::elements') => $this->title,
]);
// Render the view
return $this->populateView('decoy::elements.index', [
'elements' => $elements,
'locale' => $locale,
'tab' => $tab,
]);
} | php | public function index($locale = null, $tab = null)
{
// If there are no locales, treat the first argument as the tab
if (!($locales = Config::get('decoy.site.locales')) || empty($locales)) {
$tab = $locale;
$locale = null;
// Otherwise, set a default locale if none was specified
} elseif (!$locale) {
$locale = Decoy::defaultLocale();
}
// Get all the elements for the current locale
$elements = app('decoy.elements')->localize($locale)->hydrate(true);
// If the user has customized permissions, filter the elements to only the
// allowed pages of elements.
if ($permissions = app('decoy.user')->getPermissionsAttribute()) {
$elements->onlyPages($permissions->elements);
}
// If handling a deep link to a tab, verify that the passed tab
// slug is a real key in the data. Else 404.
if ($tab && !in_array($tab, $elements->pluck('page_label')
->map(function ($title) {
return Str::slug($title);
})
->all())) {
App::abort(404);
}
// Populate form
Former::withRules($elements->rules());
Former::populate($elements->populate());
// Convert the collection to models for simpler manipulation
$elements = $elements->asModels();
// Set the breadcrumbs NOT include the locale/tab
app('decoy.breadcrumbs')->set([
route('decoy::elements') => $this->title,
]);
// Render the view
return $this->populateView('decoy::elements.index', [
'elements' => $elements,
'locale' => $locale,
'tab' => $tab,
]);
} | [
"public",
"function",
"index",
"(",
"$",
"locale",
"=",
"null",
",",
"$",
"tab",
"=",
"null",
")",
"{",
"// If there are no locales, treat the first argument as the tab",
"if",
"(",
"!",
"(",
"$",
"locales",
"=",
"Config",
"::",
"get",
"(",
"'decoy.site.locales'",
")",
")",
"||",
"empty",
"(",
"$",
"locales",
")",
")",
"{",
"$",
"tab",
"=",
"$",
"locale",
";",
"$",
"locale",
"=",
"null",
";",
"// Otherwise, set a default locale if none was specified",
"}",
"elseif",
"(",
"!",
"$",
"locale",
")",
"{",
"$",
"locale",
"=",
"Decoy",
"::",
"defaultLocale",
"(",
")",
";",
"}",
"// Get all the elements for the current locale",
"$",
"elements",
"=",
"app",
"(",
"'decoy.elements'",
")",
"->",
"localize",
"(",
"$",
"locale",
")",
"->",
"hydrate",
"(",
"true",
")",
";",
"// If the user has customized permissions, filter the elements to only the",
"// allowed pages of elements.",
"if",
"(",
"$",
"permissions",
"=",
"app",
"(",
"'decoy.user'",
")",
"->",
"getPermissionsAttribute",
"(",
")",
")",
"{",
"$",
"elements",
"->",
"onlyPages",
"(",
"$",
"permissions",
"->",
"elements",
")",
";",
"}",
"// If handling a deep link to a tab, verify that the passed tab",
"// slug is a real key in the data. Else 404.",
"if",
"(",
"$",
"tab",
"&&",
"!",
"in_array",
"(",
"$",
"tab",
",",
"$",
"elements",
"->",
"pluck",
"(",
"'page_label'",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"title",
")",
"{",
"return",
"Str",
"::",
"slug",
"(",
"$",
"title",
")",
";",
"}",
")",
"->",
"all",
"(",
")",
")",
")",
"{",
"App",
"::",
"abort",
"(",
"404",
")",
";",
"}",
"// Populate form",
"Former",
"::",
"withRules",
"(",
"$",
"elements",
"->",
"rules",
"(",
")",
")",
";",
"Former",
"::",
"populate",
"(",
"$",
"elements",
"->",
"populate",
"(",
")",
")",
";",
"// Convert the collection to models for simpler manipulation",
"$",
"elements",
"=",
"$",
"elements",
"->",
"asModels",
"(",
")",
";",
"// Set the breadcrumbs NOT include the locale/tab",
"app",
"(",
"'decoy.breadcrumbs'",
")",
"->",
"set",
"(",
"[",
"route",
"(",
"'decoy::elements'",
")",
"=>",
"$",
"this",
"->",
"title",
",",
"]",
")",
";",
"// Render the view",
"return",
"$",
"this",
"->",
"populateView",
"(",
"'decoy::elements.index'",
",",
"[",
"'elements'",
"=>",
"$",
"elements",
",",
"'locale'",
"=>",
"$",
"locale",
",",
"'tab'",
"=>",
"$",
"tab",
",",
"]",
")",
";",
"}"
] | All elements view
@param string $locale The locale to load from the DB
@param string $tab A deep link to a specific tab. Will get processed by JS
@return Illuminate\Http\Response | [
"All",
"elements",
"view"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Elements.php#L42-L91 |
30,665 | BKWLD/decoy | classes/Controllers/Elements.php | Elements.renderField | public static function renderField($el, $key = null)
{
if (!$key) {
$key = $el->inputName();
}
$id = str_replace('|', '-', $key);
switch ($el->type) {
case 'text':
return Former::text($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'textarea':
return Former::textarea($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'wysiwyg':
return Former::wysiwyg($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'image':
return Former::image($key, $el->label)
->forElement($el)
->id($id);
case 'file':
return Former::upload($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'boolean':
return Former::checkbox($key, false)
->checkboxes([
"<b>{$el->label}</b>" => [
'name' => $key,
'value' => 1,
],
])
->blockHelp($el->help)
->id($id)
->push();
case 'select':
return Former::select($key, $el->label)
->options($el->options)
->blockHelp($el->help)
->id($id);
case 'radios':
return Former::radiolist($key, $el->label)
->from($el->options)
->blockHelp($el->help)
->id($id);
case 'checkboxes':
return Former::checklist($key, $el->label)
->from($el->options)
->blockHelp($el->help)
->id($id);
case 'video-encoder':
return Former::videoEncoder($key, $el->label)
->blockHelp($el->help)
->model($el)
->preset($el->preset)
->id($id);
case 'model':
return Former::belongsTo($key, $el->label)
->parent($el->class)
->blockHelp($el->help)
->id($id);
}
} | php | public static function renderField($el, $key = null)
{
if (!$key) {
$key = $el->inputName();
}
$id = str_replace('|', '-', $key);
switch ($el->type) {
case 'text':
return Former::text($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'textarea':
return Former::textarea($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'wysiwyg':
return Former::wysiwyg($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'image':
return Former::image($key, $el->label)
->forElement($el)
->id($id);
case 'file':
return Former::upload($key, $el->label)
->blockHelp($el->help)
->id($id);
case 'boolean':
return Former::checkbox($key, false)
->checkboxes([
"<b>{$el->label}</b>" => [
'name' => $key,
'value' => 1,
],
])
->blockHelp($el->help)
->id($id)
->push();
case 'select':
return Former::select($key, $el->label)
->options($el->options)
->blockHelp($el->help)
->id($id);
case 'radios':
return Former::radiolist($key, $el->label)
->from($el->options)
->blockHelp($el->help)
->id($id);
case 'checkboxes':
return Former::checklist($key, $el->label)
->from($el->options)
->blockHelp($el->help)
->id($id);
case 'video-encoder':
return Former::videoEncoder($key, $el->label)
->blockHelp($el->help)
->model($el)
->preset($el->preset)
->id($id);
case 'model':
return Former::belongsTo($key, $el->label)
->parent($el->class)
->blockHelp($el->help)
->id($id);
}
} | [
"public",
"static",
"function",
"renderField",
"(",
"$",
"el",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"$",
"el",
"->",
"inputName",
"(",
")",
";",
"}",
"$",
"id",
"=",
"str_replace",
"(",
"'|'",
",",
"'-'",
",",
"$",
"key",
")",
";",
"switch",
"(",
"$",
"el",
"->",
"type",
")",
"{",
"case",
"'text'",
":",
"return",
"Former",
"::",
"text",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'textarea'",
":",
"return",
"Former",
"::",
"textarea",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'wysiwyg'",
":",
"return",
"Former",
"::",
"wysiwyg",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'image'",
":",
"return",
"Former",
"::",
"image",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"forElement",
"(",
"$",
"el",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'file'",
":",
"return",
"Former",
"::",
"upload",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'boolean'",
":",
"return",
"Former",
"::",
"checkbox",
"(",
"$",
"key",
",",
"false",
")",
"->",
"checkboxes",
"(",
"[",
"\"<b>{$el->label}</b>\"",
"=>",
"[",
"'name'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"1",
",",
"]",
",",
"]",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
"->",
"push",
"(",
")",
";",
"case",
"'select'",
":",
"return",
"Former",
"::",
"select",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"options",
"(",
"$",
"el",
"->",
"options",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'radios'",
":",
"return",
"Former",
"::",
"radiolist",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"from",
"(",
"$",
"el",
"->",
"options",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'checkboxes'",
":",
"return",
"Former",
"::",
"checklist",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"from",
"(",
"$",
"el",
"->",
"options",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'video-encoder'",
":",
"return",
"Former",
"::",
"videoEncoder",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"model",
"(",
"$",
"el",
")",
"->",
"preset",
"(",
"$",
"el",
"->",
"preset",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"case",
"'model'",
":",
"return",
"Former",
"::",
"belongsTo",
"(",
"$",
"key",
",",
"$",
"el",
"->",
"label",
")",
"->",
"parent",
"(",
"$",
"el",
"->",
"class",
")",
"->",
"blockHelp",
"(",
"$",
"el",
"->",
"help",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | A helper function for rendering the list of fields
@param Bkwld\Decoy\Models\Element $el
@param string $key
@return Former\Traits\Object | [
"A",
"helper",
"function",
"for",
"rendering",
"the",
"list",
"of",
"fields"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Elements.php#L100-L177 |
30,666 | BKWLD/decoy | classes/Controllers/Elements.php | Elements.store | public function store($locale = null)
{
// Get the default locale
if (!$locale) {
$locale = Decoy::defaultLocale();
}
// Hydrate the elements collection
$elements = app('decoy.elements')
->localize($locale)
->hydrate(true);
// If the user has customized permissions, filter the elements to only the
// allowed pages of elements.
if ($permissions = app('decoy.user')->getPermissionsAttribute()) {
$elements->onlyPages($permissions->elements);
}
// Get all the input such that empty file fields are removed from the input.
$input = Decoy::filteredInput();
// Validate the input
$validator = Validator::make($input, $elements->rules());
if ($validator->fails()) {
throw new ValidationFail($validator);
}
// Merge the input into the elements and save them. Key must be converted back
// from the | delimited format necessitated by PHP
$elements->asModels()->each(function (Element $el) use ($elements, $input) {
// Inform the model as to whether the model already exists in the db.
if ($el->exists = $elements->keyUpdated($el->key)) {
$el->syncOriginal();
}
// Handle images differently, since they get saved in the Images table
if ($el->type == 'image') {
return $this->storeImage($el, $input);
}
// Empty file fields will have no key as a result of the above filtering
$key = $el->inputName();
if (!array_key_exists($key, $input)) {
// If no new video was uploaded but the preset was changed, re-encode
if ($el->type == 'video-encoder' && $el->hasDirtyPreset('value')) {
$el->encode('value', $el->encodingPresetInputVal('value'));
}
return;
}
$value = $input[$key];
// If value is an array, like it would be for the "checkboxes" type, make
// it a comma delimited string
if (is_array($value)) {
$value = implode(',', $value);
}
// We're removing the carriage returns because YAML won't include them and
// all multiline YAML config values were incorrectly being returned as
// dirty.
$value = str_replace("\r", '', $value);
// Check if the model is dirty, manually. Laravel's performInsert()
// doesn't do this, thus we must check ourselves.
if ($value == $el->value) {
return;
}
// If type is a video encoder and the value is empty, delete the row to
// force the encoding row to also delete. This is possible because
// videos cannot have a YAML set default value.
if (!$value && $el->type == 'video-encoder') {
return $el->delete();
}
// Save it
$el->value = Request::hasFile($key) ?
app('upchuck.storage')->moveUpload(Request::file($key)) :
$value;
$el->save();
});
// Clear the cache
$elements->clearCache();
// Redirect back to index
return Redirect::to(URL::current())->with('success',
__('decoy::elements.successfully_saved'));
} | php | public function store($locale = null)
{
// Get the default locale
if (!$locale) {
$locale = Decoy::defaultLocale();
}
// Hydrate the elements collection
$elements = app('decoy.elements')
->localize($locale)
->hydrate(true);
// If the user has customized permissions, filter the elements to only the
// allowed pages of elements.
if ($permissions = app('decoy.user')->getPermissionsAttribute()) {
$elements->onlyPages($permissions->elements);
}
// Get all the input such that empty file fields are removed from the input.
$input = Decoy::filteredInput();
// Validate the input
$validator = Validator::make($input, $elements->rules());
if ($validator->fails()) {
throw new ValidationFail($validator);
}
// Merge the input into the elements and save them. Key must be converted back
// from the | delimited format necessitated by PHP
$elements->asModels()->each(function (Element $el) use ($elements, $input) {
// Inform the model as to whether the model already exists in the db.
if ($el->exists = $elements->keyUpdated($el->key)) {
$el->syncOriginal();
}
// Handle images differently, since they get saved in the Images table
if ($el->type == 'image') {
return $this->storeImage($el, $input);
}
// Empty file fields will have no key as a result of the above filtering
$key = $el->inputName();
if (!array_key_exists($key, $input)) {
// If no new video was uploaded but the preset was changed, re-encode
if ($el->type == 'video-encoder' && $el->hasDirtyPreset('value')) {
$el->encode('value', $el->encodingPresetInputVal('value'));
}
return;
}
$value = $input[$key];
// If value is an array, like it would be for the "checkboxes" type, make
// it a comma delimited string
if (is_array($value)) {
$value = implode(',', $value);
}
// We're removing the carriage returns because YAML won't include them and
// all multiline YAML config values were incorrectly being returned as
// dirty.
$value = str_replace("\r", '', $value);
// Check if the model is dirty, manually. Laravel's performInsert()
// doesn't do this, thus we must check ourselves.
if ($value == $el->value) {
return;
}
// If type is a video encoder and the value is empty, delete the row to
// force the encoding row to also delete. This is possible because
// videos cannot have a YAML set default value.
if (!$value && $el->type == 'video-encoder') {
return $el->delete();
}
// Save it
$el->value = Request::hasFile($key) ?
app('upchuck.storage')->moveUpload(Request::file($key)) :
$value;
$el->save();
});
// Clear the cache
$elements->clearCache();
// Redirect back to index
return Redirect::to(URL::current())->with('success',
__('decoy::elements.successfully_saved'));
} | [
"public",
"function",
"store",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"// Get the default locale",
"if",
"(",
"!",
"$",
"locale",
")",
"{",
"$",
"locale",
"=",
"Decoy",
"::",
"defaultLocale",
"(",
")",
";",
"}",
"// Hydrate the elements collection",
"$",
"elements",
"=",
"app",
"(",
"'decoy.elements'",
")",
"->",
"localize",
"(",
"$",
"locale",
")",
"->",
"hydrate",
"(",
"true",
")",
";",
"// If the user has customized permissions, filter the elements to only the",
"// allowed pages of elements.",
"if",
"(",
"$",
"permissions",
"=",
"app",
"(",
"'decoy.user'",
")",
"->",
"getPermissionsAttribute",
"(",
")",
")",
"{",
"$",
"elements",
"->",
"onlyPages",
"(",
"$",
"permissions",
"->",
"elements",
")",
";",
"}",
"// Get all the input such that empty file fields are removed from the input.",
"$",
"input",
"=",
"Decoy",
"::",
"filteredInput",
"(",
")",
";",
"// Validate the input",
"$",
"validator",
"=",
"Validator",
"::",
"make",
"(",
"$",
"input",
",",
"$",
"elements",
"->",
"rules",
"(",
")",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"throw",
"new",
"ValidationFail",
"(",
"$",
"validator",
")",
";",
"}",
"// Merge the input into the elements and save them. Key must be converted back",
"// from the | delimited format necessitated by PHP",
"$",
"elements",
"->",
"asModels",
"(",
")",
"->",
"each",
"(",
"function",
"(",
"Element",
"$",
"el",
")",
"use",
"(",
"$",
"elements",
",",
"$",
"input",
")",
"{",
"// Inform the model as to whether the model already exists in the db.",
"if",
"(",
"$",
"el",
"->",
"exists",
"=",
"$",
"elements",
"->",
"keyUpdated",
"(",
"$",
"el",
"->",
"key",
")",
")",
"{",
"$",
"el",
"->",
"syncOriginal",
"(",
")",
";",
"}",
"// Handle images differently, since they get saved in the Images table",
"if",
"(",
"$",
"el",
"->",
"type",
"==",
"'image'",
")",
"{",
"return",
"$",
"this",
"->",
"storeImage",
"(",
"$",
"el",
",",
"$",
"input",
")",
";",
"}",
"// Empty file fields will have no key as a result of the above filtering",
"$",
"key",
"=",
"$",
"el",
"->",
"inputName",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"input",
")",
")",
"{",
"// If no new video was uploaded but the preset was changed, re-encode",
"if",
"(",
"$",
"el",
"->",
"type",
"==",
"'video-encoder'",
"&&",
"$",
"el",
"->",
"hasDirtyPreset",
"(",
"'value'",
")",
")",
"{",
"$",
"el",
"->",
"encode",
"(",
"'value'",
",",
"$",
"el",
"->",
"encodingPresetInputVal",
"(",
"'value'",
")",
")",
";",
"}",
"return",
";",
"}",
"$",
"value",
"=",
"$",
"input",
"[",
"$",
"key",
"]",
";",
"// If value is an array, like it would be for the \"checkboxes\" type, make",
"// it a comma delimited string",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"','",
",",
"$",
"value",
")",
";",
"}",
"// We're removing the carriage returns because YAML won't include them and",
"// all multiline YAML config values were incorrectly being returned as",
"// dirty.",
"$",
"value",
"=",
"str_replace",
"(",
"\"\\r\"",
",",
"''",
",",
"$",
"value",
")",
";",
"// Check if the model is dirty, manually. Laravel's performInsert()",
"// doesn't do this, thus we must check ourselves.",
"if",
"(",
"$",
"value",
"==",
"$",
"el",
"->",
"value",
")",
"{",
"return",
";",
"}",
"// If type is a video encoder and the value is empty, delete the row to",
"// force the encoding row to also delete. This is possible because",
"// videos cannot have a YAML set default value.",
"if",
"(",
"!",
"$",
"value",
"&&",
"$",
"el",
"->",
"type",
"==",
"'video-encoder'",
")",
"{",
"return",
"$",
"el",
"->",
"delete",
"(",
")",
";",
"}",
"// Save it",
"$",
"el",
"->",
"value",
"=",
"Request",
"::",
"hasFile",
"(",
"$",
"key",
")",
"?",
"app",
"(",
"'upchuck.storage'",
")",
"->",
"moveUpload",
"(",
"Request",
"::",
"file",
"(",
"$",
"key",
")",
")",
":",
"$",
"value",
";",
"$",
"el",
"->",
"save",
"(",
")",
";",
"}",
")",
";",
"// Clear the cache",
"$",
"elements",
"->",
"clearCache",
"(",
")",
";",
"// Redirect back to index",
"return",
"Redirect",
"::",
"to",
"(",
"URL",
"::",
"current",
"(",
")",
")",
"->",
"with",
"(",
"'success'",
",",
"__",
"(",
"'decoy::elements.successfully_saved'",
")",
")",
";",
"}"
] | Handle form post
@param string $locale The locale to assign to it
@return Illuminate\Http\Response | [
"Handle",
"form",
"post"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Elements.php#L185-L276 |
30,667 | BKWLD/decoy | classes/Controllers/Elements.php | Elements.storeImage | protected function storeImage(Element $el, $input)
{
// Do nothing if no images
if (!is_array($input['images'])) {
return;
}
// Check for the image in the input. If isn't found, make no changes.
$name = $el->inputName();
if (!$data = array_first($input['images'],
function ($data, $id) use ($name) {
return $data['name'] == $name;
})) {
return;
}
// Update an existing image
if ($image = $el->images->first()) {
$image->fill($data)->save();
// Or create a new image, if file data was supplied
} elseif (!empty($data['file'])) {
$el->value = null;
$el->save();
$image = new Image($data);
$el->images()->save($image);
// Othweise, nothing to do
} else {
return;
}
// Update the element with the path to the image
$el->value = $image->file;
$el->save();
} | php | protected function storeImage(Element $el, $input)
{
// Do nothing if no images
if (!is_array($input['images'])) {
return;
}
// Check for the image in the input. If isn't found, make no changes.
$name = $el->inputName();
if (!$data = array_first($input['images'],
function ($data, $id) use ($name) {
return $data['name'] == $name;
})) {
return;
}
// Update an existing image
if ($image = $el->images->first()) {
$image->fill($data)->save();
// Or create a new image, if file data was supplied
} elseif (!empty($data['file'])) {
$el->value = null;
$el->save();
$image = new Image($data);
$el->images()->save($image);
// Othweise, nothing to do
} else {
return;
}
// Update the element with the path to the image
$el->value = $image->file;
$el->save();
} | [
"protected",
"function",
"storeImage",
"(",
"Element",
"$",
"el",
",",
"$",
"input",
")",
"{",
"// Do nothing if no images",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
"[",
"'images'",
"]",
")",
")",
"{",
"return",
";",
"}",
"// Check for the image in the input. If isn't found, make no changes.",
"$",
"name",
"=",
"$",
"el",
"->",
"inputName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"data",
"=",
"array_first",
"(",
"$",
"input",
"[",
"'images'",
"]",
",",
"function",
"(",
"$",
"data",
",",
"$",
"id",
")",
"use",
"(",
"$",
"name",
")",
"{",
"return",
"$",
"data",
"[",
"'name'",
"]",
"==",
"$",
"name",
";",
"}",
")",
")",
"{",
"return",
";",
"}",
"// Update an existing image",
"if",
"(",
"$",
"image",
"=",
"$",
"el",
"->",
"images",
"->",
"first",
"(",
")",
")",
"{",
"$",
"image",
"->",
"fill",
"(",
"$",
"data",
")",
"->",
"save",
"(",
")",
";",
"// Or create a new image, if file data was supplied",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"el",
"->",
"value",
"=",
"null",
";",
"$",
"el",
"->",
"save",
"(",
")",
";",
"$",
"image",
"=",
"new",
"Image",
"(",
"$",
"data",
")",
";",
"$",
"el",
"->",
"images",
"(",
")",
"->",
"save",
"(",
"$",
"image",
")",
";",
"// Othweise, nothing to do",
"}",
"else",
"{",
"return",
";",
"}",
"// Update the element with the path to the image",
"$",
"el",
"->",
"value",
"=",
"$",
"image",
"->",
"file",
";",
"$",
"el",
"->",
"save",
"(",
")",
";",
"}"
] | Handle storage of image Element types
@param Element $el
@param array $input
@return void | [
"Handle",
"storage",
"of",
"image",
"Element",
"types"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Elements.php#L285-L320 |
30,668 | BKWLD/decoy | classes/Controllers/Elements.php | Elements.field | public function field($key)
{
return View::make('decoy::layouts.blank')
->nest('content', 'decoy::elements.field', [
'element' => app('decoy.elements')
->localize(Decoy::locale())
->hydrate(true)
->get($key),
]);
} | php | public function field($key)
{
return View::make('decoy::layouts.blank')
->nest('content', 'decoy::elements.field', [
'element' => app('decoy.elements')
->localize(Decoy::locale())
->hydrate(true)
->get($key),
]);
} | [
"public",
"function",
"field",
"(",
"$",
"key",
")",
"{",
"return",
"View",
"::",
"make",
"(",
"'decoy::layouts.blank'",
")",
"->",
"nest",
"(",
"'content'",
",",
"'decoy::elements.field'",
",",
"[",
"'element'",
"=>",
"app",
"(",
"'decoy.elements'",
")",
"->",
"localize",
"(",
"Decoy",
"::",
"locale",
"(",
")",
")",
"->",
"hydrate",
"(",
"true",
")",
"->",
"get",
"(",
"$",
"key",
")",
",",
"]",
")",
";",
"}"
] | Show the field editor form that will appear in an iframe on
the frontend
@param string $key A full Element key
@return Illuminate\Http\Response | [
"Show",
"the",
"field",
"editor",
"form",
"that",
"will",
"appear",
"in",
"an",
"iframe",
"on",
"the",
"frontend"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Elements.php#L329-L338 |
30,669 | BKWLD/decoy | classes/Controllers/Elements.php | Elements.fieldUpdate | public function fieldUpdate($key)
{
$elements = app('decoy.elements')->localize(Decoy::locale());
// If the value has changed, update or an insert a record in the database.
$el = Decoy::el($key);
$value = request('value');
if ($value != $el->value || Request::hasFile('value')) {
// Making use of the model's exists property to trigger Laravel's
// internal logic.
$el->exists = $elements->keyUpdated($el->key);
// Save it. Files will be automatically attached via model callbacks
$el->value = $value;
$el->locale = Decoy::locale();
$el->save();
// Clear the cache
$elements->clearCache();
}
// Return the layout with JUST a script variable with the element value
// after saving. Thus, post any saving callback operations.
return View::make('decoy::layouts.blank', [
'content' => "<div id='response' data-key='{$key}'>{$el}</div>"
]);
} | php | public function fieldUpdate($key)
{
$elements = app('decoy.elements')->localize(Decoy::locale());
// If the value has changed, update or an insert a record in the database.
$el = Decoy::el($key);
$value = request('value');
if ($value != $el->value || Request::hasFile('value')) {
// Making use of the model's exists property to trigger Laravel's
// internal logic.
$el->exists = $elements->keyUpdated($el->key);
// Save it. Files will be automatically attached via model callbacks
$el->value = $value;
$el->locale = Decoy::locale();
$el->save();
// Clear the cache
$elements->clearCache();
}
// Return the layout with JUST a script variable with the element value
// after saving. Thus, post any saving callback operations.
return View::make('decoy::layouts.blank', [
'content' => "<div id='response' data-key='{$key}'>{$el}</div>"
]);
} | [
"public",
"function",
"fieldUpdate",
"(",
"$",
"key",
")",
"{",
"$",
"elements",
"=",
"app",
"(",
"'decoy.elements'",
")",
"->",
"localize",
"(",
"Decoy",
"::",
"locale",
"(",
")",
")",
";",
"// If the value has changed, update or an insert a record in the database.",
"$",
"el",
"=",
"Decoy",
"::",
"el",
"(",
"$",
"key",
")",
";",
"$",
"value",
"=",
"request",
"(",
"'value'",
")",
";",
"if",
"(",
"$",
"value",
"!=",
"$",
"el",
"->",
"value",
"||",
"Request",
"::",
"hasFile",
"(",
"'value'",
")",
")",
"{",
"// Making use of the model's exists property to trigger Laravel's",
"// internal logic.",
"$",
"el",
"->",
"exists",
"=",
"$",
"elements",
"->",
"keyUpdated",
"(",
"$",
"el",
"->",
"key",
")",
";",
"// Save it. Files will be automatically attached via model callbacks",
"$",
"el",
"->",
"value",
"=",
"$",
"value",
";",
"$",
"el",
"->",
"locale",
"=",
"Decoy",
"::",
"locale",
"(",
")",
";",
"$",
"el",
"->",
"save",
"(",
")",
";",
"// Clear the cache",
"$",
"elements",
"->",
"clearCache",
"(",
")",
";",
"}",
"// Return the layout with JUST a script variable with the element value",
"// after saving. Thus, post any saving callback operations.",
"return",
"View",
"::",
"make",
"(",
"'decoy::layouts.blank'",
",",
"[",
"'content'",
"=>",
"\"<div id='response' data-key='{$key}'>{$el}</div>\"",
"]",
")",
";",
"}"
] | Update a single field because of a frontend Element editor
iframe post
@param string $key A full Element key
@return Illuminate\Http\Response | [
"Update",
"a",
"single",
"field",
"because",
"of",
"a",
"frontend",
"Element",
"editor",
"iframe",
"post"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Elements.php#L347-L374 |
30,670 | BKWLD/decoy | classes/Controllers/Elements.php | Elements.getPermissionOptions | public function getPermissionOptions()
{
// Get all the grouped elements
$elements = app('decoy.elements')
->localize(Decoy::locale())
->hydrate(true)
->asModels()
->sortBy('page_label')
->groupBy('page_label');
// Map to the expected permisions forat
$out = [];
foreach ($elements as $page_label => $fields) {
$out[Str::slug($page_label)] = [$page_label, $fields[0]->page_help];
}
return $out;
} | php | public function getPermissionOptions()
{
// Get all the grouped elements
$elements = app('decoy.elements')
->localize(Decoy::locale())
->hydrate(true)
->asModels()
->sortBy('page_label')
->groupBy('page_label');
// Map to the expected permisions forat
$out = [];
foreach ($elements as $page_label => $fields) {
$out[Str::slug($page_label)] = [$page_label, $fields[0]->page_help];
}
return $out;
} | [
"public",
"function",
"getPermissionOptions",
"(",
")",
"{",
"// Get all the grouped elements",
"$",
"elements",
"=",
"app",
"(",
"'decoy.elements'",
")",
"->",
"localize",
"(",
"Decoy",
"::",
"locale",
"(",
")",
")",
"->",
"hydrate",
"(",
"true",
")",
"->",
"asModels",
"(",
")",
"->",
"sortBy",
"(",
"'page_label'",
")",
"->",
"groupBy",
"(",
"'page_label'",
")",
";",
"// Map to the expected permisions forat",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"page_label",
"=>",
"$",
"fields",
")",
"{",
"$",
"out",
"[",
"Str",
"::",
"slug",
"(",
"$",
"page_label",
")",
"]",
"=",
"[",
"$",
"page_label",
",",
"$",
"fields",
"[",
"0",
"]",
"->",
"page_help",
"]",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | The permissions options are a list of all the tabs
@return array | [
"The",
"permissions",
"options",
"are",
"a",
"list",
"of",
"all",
"the",
"tabs"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Elements.php#L381-L398 |
30,671 | BKWLD/decoy | classes/Helpers.php | Helpers.title | public function title()
{
// If no title has been set, try to figure it out based on breadcrumbs
$title = View::yieldContent('title');
if (empty($title)) {
$title = app('decoy.breadcrumbs')->title();
}
// Set the title
$site = $this->site();
return '<title>' . ($title ? "$title | $site" : $site) . '</title>';
} | php | public function title()
{
// If no title has been set, try to figure it out based on breadcrumbs
$title = View::yieldContent('title');
if (empty($title)) {
$title = app('decoy.breadcrumbs')->title();
}
// Set the title
$site = $this->site();
return '<title>' . ($title ? "$title | $site" : $site) . '</title>';
} | [
"public",
"function",
"title",
"(",
")",
"{",
"// If no title has been set, try to figure it out based on breadcrumbs",
"$",
"title",
"=",
"View",
"::",
"yieldContent",
"(",
"'title'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"title",
")",
")",
"{",
"$",
"title",
"=",
"app",
"(",
"'decoy.breadcrumbs'",
")",
"->",
"title",
"(",
")",
";",
"}",
"// Set the title",
"$",
"site",
"=",
"$",
"this",
"->",
"site",
"(",
")",
";",
"return",
"'<title>'",
".",
"(",
"$",
"title",
"?",
"\"$title | $site\"",
":",
"$",
"site",
")",
".",
"'</title>'",
";",
"}"
] | Generate title tags based on section content
@return string | [
"Generate",
"title",
"tags",
"based",
"on",
"section",
"content"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L32-L44 |
30,672 | BKWLD/decoy | classes/Helpers.php | Helpers.site | public function site()
{
$site = Config::get('decoy.site.name');
if (is_callable($site)) {
$site = call_user_func($site);
}
return $site;
} | php | public function site()
{
$site = Config::get('decoy.site.name');
if (is_callable($site)) {
$site = call_user_func($site);
}
return $site;
} | [
"public",
"function",
"site",
"(",
")",
"{",
"$",
"site",
"=",
"Config",
"::",
"get",
"(",
"'decoy.site.name'",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"site",
")",
")",
"{",
"$",
"site",
"=",
"call_user_func",
"(",
"$",
"site",
")",
";",
"}",
"return",
"$",
"site",
";",
"}"
] | Get the site name
@return string | [
"Get",
"the",
"site",
"name"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L51-L59 |
30,673 | BKWLD/decoy | classes/Helpers.php | Helpers.bodyClass | public function bodyClass()
{
$path = Request::path();
$classes = [];
// Special condition for the elements
if (strpos($path, '/elements/field/') !== false) {
return 'elements field';
}
// Special condition for the reset page, which passes the token in as part of the route
if (strpos($path, '/reset/') !== false) {
return 'login reset';
}
// Tab-sidebar views support deep links that would normally affect the
// class of the page.
if (strpos($path, '/elements/') !== false) {
return 'elements index';
}
// Get the controller and action from the URL
preg_match('#/([a-z-]+)(?:/\d+)?(?:/(create|edit))?$#i', $path, $matches);
$controller = empty($matches[1]) ? 'login' : $matches[1];
$action = empty($matches[2]) ? 'index' : $matches[2];
array_push($classes, $controller, $action);
// Add the admin roles
if ($admin = app('decoy.user')) {
$classes[] = 'role-'.$admin->role;
}
// Return the list of classes
return implode(' ', $classes);
} | php | public function bodyClass()
{
$path = Request::path();
$classes = [];
// Special condition for the elements
if (strpos($path, '/elements/field/') !== false) {
return 'elements field';
}
// Special condition for the reset page, which passes the token in as part of the route
if (strpos($path, '/reset/') !== false) {
return 'login reset';
}
// Tab-sidebar views support deep links that would normally affect the
// class of the page.
if (strpos($path, '/elements/') !== false) {
return 'elements index';
}
// Get the controller and action from the URL
preg_match('#/([a-z-]+)(?:/\d+)?(?:/(create|edit))?$#i', $path, $matches);
$controller = empty($matches[1]) ? 'login' : $matches[1];
$action = empty($matches[2]) ? 'index' : $matches[2];
array_push($classes, $controller, $action);
// Add the admin roles
if ($admin = app('decoy.user')) {
$classes[] = 'role-'.$admin->role;
}
// Return the list of classes
return implode(' ', $classes);
} | [
"public",
"function",
"bodyClass",
"(",
")",
"{",
"$",
"path",
"=",
"Request",
"::",
"path",
"(",
")",
";",
"$",
"classes",
"=",
"[",
"]",
";",
"// Special condition for the elements",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'/elements/field/'",
")",
"!==",
"false",
")",
"{",
"return",
"'elements field'",
";",
"}",
"// Special condition for the reset page, which passes the token in as part of the route",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'/reset/'",
")",
"!==",
"false",
")",
"{",
"return",
"'login reset'",
";",
"}",
"// Tab-sidebar views support deep links that would normally affect the",
"// class of the page.",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'/elements/'",
")",
"!==",
"false",
")",
"{",
"return",
"'elements index'",
";",
"}",
"// Get the controller and action from the URL",
"preg_match",
"(",
"'#/([a-z-]+)(?:/\\d+)?(?:/(create|edit))?$#i'",
",",
"$",
"path",
",",
"$",
"matches",
")",
";",
"$",
"controller",
"=",
"empty",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"?",
"'login'",
":",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"action",
"=",
"empty",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"?",
"'index'",
":",
"$",
"matches",
"[",
"2",
"]",
";",
"array_push",
"(",
"$",
"classes",
",",
"$",
"controller",
",",
"$",
"action",
")",
";",
"// Add the admin roles",
"if",
"(",
"$",
"admin",
"=",
"app",
"(",
"'decoy.user'",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'role-'",
".",
"$",
"admin",
"->",
"role",
";",
"}",
"// Return the list of classes",
"return",
"implode",
"(",
"' '",
",",
"$",
"classes",
")",
";",
"}"
] | Add the controller and action as CSS classes on the body tag | [
"Add",
"the",
"controller",
"and",
"action",
"as",
"CSS",
"classes",
"on",
"the",
"body",
"tag"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L64-L98 |
30,674 | BKWLD/decoy | classes/Helpers.php | Helpers.els | public function els($prefix, $crops = [])
{
return app('decoy.elements')
->localize($this->locale())
->getMany($prefix, $crops);
} | php | public function els($prefix, $crops = [])
{
return app('decoy.elements')
->localize($this->locale())
->getMany($prefix, $crops);
} | [
"public",
"function",
"els",
"(",
"$",
"prefix",
",",
"$",
"crops",
"=",
"[",
"]",
")",
"{",
"return",
"app",
"(",
"'decoy.elements'",
")",
"->",
"localize",
"(",
"$",
"this",
"->",
"locale",
"(",
")",
")",
"->",
"getMany",
"(",
"$",
"prefix",
",",
"$",
"crops",
")",
";",
"}"
] | Return a number of Element values at once in an associative array
@param string $prefix Any leading part of a key
@param array $crops Assoc array with Element partial keys for ITS keys
and values as an arary of crop()-style arguments
@return array | [
"Return",
"a",
"number",
"of",
"Element",
"values",
"at",
"once",
"in",
"an",
"associative",
"array"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L221-L226 |
30,675 | BKWLD/decoy | classes/Helpers.php | Helpers.defaultLocale | public function defaultLocale()
{
if (($locales = Config::get('decoy.site.locales'))
&& is_array($locales)) {
reset($locales);
return key($locales);
}
} | php | public function defaultLocale()
{
if (($locales = Config::get('decoy.site.locales'))
&& is_array($locales)) {
reset($locales);
return key($locales);
}
} | [
"public",
"function",
"defaultLocale",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"locales",
"=",
"Config",
"::",
"get",
"(",
"'decoy.site.locales'",
")",
")",
"&&",
"is_array",
"(",
"$",
"locales",
")",
")",
"{",
"reset",
"(",
"$",
"locales",
")",
";",
"return",
"key",
"(",
"$",
"locales",
")",
";",
"}",
"}"
] | Get the default locale, aka, the first locales array key
@return string | [
"Get",
"the",
"default",
"locale",
"aka",
"the",
"first",
"locales",
"array",
"key"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L304-L312 |
30,676 | BKWLD/decoy | classes/Helpers.php | Helpers.modelForController | public function modelForController($controller)
{
// Swap out the namespace if decoy
$model = str_replace('Bkwld\Decoy\Controllers',
'Bkwld\Decoy\Models',
$controller,
$is_decoy);
// Replace non-decoy controller's with the standard model namespace
if (!$is_decoy) {
$namespace = ucfirst(Config::get('decoy.core.dir'));
$model = str_replace('App\Http\Controllers\\'.$namespace.'\\', 'App\\', $model);
}
// Make it singular
$offset = strrpos($model, '\\') + 1;
return substr($model, 0, $offset).Str::singular(substr($model, $offset));
} | php | public function modelForController($controller)
{
// Swap out the namespace if decoy
$model = str_replace('Bkwld\Decoy\Controllers',
'Bkwld\Decoy\Models',
$controller,
$is_decoy);
// Replace non-decoy controller's with the standard model namespace
if (!$is_decoy) {
$namespace = ucfirst(Config::get('decoy.core.dir'));
$model = str_replace('App\Http\Controllers\\'.$namespace.'\\', 'App\\', $model);
}
// Make it singular
$offset = strrpos($model, '\\') + 1;
return substr($model, 0, $offset).Str::singular(substr($model, $offset));
} | [
"public",
"function",
"modelForController",
"(",
"$",
"controller",
")",
"{",
"// Swap out the namespace if decoy",
"$",
"model",
"=",
"str_replace",
"(",
"'Bkwld\\Decoy\\Controllers'",
",",
"'Bkwld\\Decoy\\Models'",
",",
"$",
"controller",
",",
"$",
"is_decoy",
")",
";",
"// Replace non-decoy controller's with the standard model namespace",
"if",
"(",
"!",
"$",
"is_decoy",
")",
"{",
"$",
"namespace",
"=",
"ucfirst",
"(",
"Config",
"::",
"get",
"(",
"'decoy.core.dir'",
")",
")",
";",
"$",
"model",
"=",
"str_replace",
"(",
"'App\\Http\\Controllers\\\\'",
".",
"$",
"namespace",
".",
"'\\\\'",
",",
"'App\\\\'",
",",
"$",
"model",
")",
";",
"}",
"// Make it singular",
"$",
"offset",
"=",
"strrpos",
"(",
"$",
"model",
",",
"'\\\\'",
")",
"+",
"1",
";",
"return",
"substr",
"(",
"$",
"model",
",",
"0",
",",
"$",
"offset",
")",
".",
"Str",
"::",
"singular",
"(",
"substr",
"(",
"$",
"model",
",",
"$",
"offset",
")",
")",
";",
"}"
] | Get the model class string from a controller class string
@param string $controller ex: "App\Http\Controllers\Admin\People"
@return string ex: "App\Person" | [
"Get",
"the",
"model",
"class",
"string",
"from",
"a",
"controller",
"class",
"string"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L320-L338 |
30,677 | BKWLD/decoy | classes/Helpers.php | Helpers.controllerForModel | public function controllerForModel($model)
{
// Swap out the namespace if decoy
$controller = str_replace('Bkwld\Decoy\Models', 'Bkwld\Decoy\Controllers', $model, $is_decoy);
// Replace non-decoy controller's with the standard model namespace
if (!$is_decoy) {
$namespace = ucfirst(Config::get('decoy.core.dir'));
$controller = str_replace('App\\', 'App\Http\Controllers\\'.$namespace.'\\', $controller);
}
// Make it plural
$offset = strrpos($controller, '\\') + 1;
return substr($controller, 0, $offset).Str::plural(substr($controller, $offset));
} | php | public function controllerForModel($model)
{
// Swap out the namespace if decoy
$controller = str_replace('Bkwld\Decoy\Models', 'Bkwld\Decoy\Controllers', $model, $is_decoy);
// Replace non-decoy controller's with the standard model namespace
if (!$is_decoy) {
$namespace = ucfirst(Config::get('decoy.core.dir'));
$controller = str_replace('App\\', 'App\Http\Controllers\\'.$namespace.'\\', $controller);
}
// Make it plural
$offset = strrpos($controller, '\\') + 1;
return substr($controller, 0, $offset).Str::plural(substr($controller, $offset));
} | [
"public",
"function",
"controllerForModel",
"(",
"$",
"model",
")",
"{",
"// Swap out the namespace if decoy",
"$",
"controller",
"=",
"str_replace",
"(",
"'Bkwld\\Decoy\\Models'",
",",
"'Bkwld\\Decoy\\Controllers'",
",",
"$",
"model",
",",
"$",
"is_decoy",
")",
";",
"// Replace non-decoy controller's with the standard model namespace",
"if",
"(",
"!",
"$",
"is_decoy",
")",
"{",
"$",
"namespace",
"=",
"ucfirst",
"(",
"Config",
"::",
"get",
"(",
"'decoy.core.dir'",
")",
")",
";",
"$",
"controller",
"=",
"str_replace",
"(",
"'App\\\\'",
",",
"'App\\Http\\Controllers\\\\'",
".",
"$",
"namespace",
".",
"'\\\\'",
",",
"$",
"controller",
")",
";",
"}",
"// Make it plural",
"$",
"offset",
"=",
"strrpos",
"(",
"$",
"controller",
",",
"'\\\\'",
")",
"+",
"1",
";",
"return",
"substr",
"(",
"$",
"controller",
",",
"0",
",",
"$",
"offset",
")",
".",
"Str",
"::",
"plural",
"(",
"substr",
"(",
"$",
"controller",
",",
"$",
"offset",
")",
")",
";",
"}"
] | Get the controller class string from a model class string
@param string $controller ex: "App\Person"
@return string ex: "App\Http\Controllers\Admin\People" | [
"Get",
"the",
"controller",
"class",
"string",
"from",
"a",
"model",
"class",
"string"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L346-L360 |
30,678 | BKWLD/decoy | classes/Helpers.php | Helpers.filteredInput | public function filteredInput()
{
$files = $this->arrayFilterRecursive(Request::file());
$input = array_replace_recursive(Request::input(), $files);
return Library\Utils\Collection::nullEmpties($input);
} | php | public function filteredInput()
{
$files = $this->arrayFilterRecursive(Request::file());
$input = array_replace_recursive(Request::input(), $files);
return Library\Utils\Collection::nullEmpties($input);
} | [
"public",
"function",
"filteredInput",
"(",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"arrayFilterRecursive",
"(",
"Request",
"::",
"file",
"(",
")",
")",
";",
"$",
"input",
"=",
"array_replace_recursive",
"(",
"Request",
"::",
"input",
"(",
")",
",",
"$",
"files",
")",
";",
"return",
"Library",
"\\",
"Utils",
"\\",
"Collection",
"::",
"nullEmpties",
"(",
"$",
"input",
")",
";",
"}"
] | Get all input but filter out empty file fields. This prevents empty file
fields from overriding existing files on a model. Using this assumes that
we are filling a model and then validating the model attributes.
@return array | [
"Get",
"all",
"input",
"but",
"filter",
"out",
"empty",
"file",
"fields",
".",
"This",
"prevents",
"empty",
"file",
"fields",
"from",
"overriding",
"existing",
"files",
"on",
"a",
"model",
".",
"Using",
"this",
"assumes",
"that",
"we",
"are",
"filling",
"a",
"model",
"and",
"then",
"validating",
"the",
"model",
"attributes",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Helpers.php#L393-L399 |
30,679 | BKWLD/decoy | classes/Observers/ModelCallbacks.php | ModelCallbacks.handle | public function handle($event, $payload)
{
list($model) = $payload;
// Get the action from the event name
preg_match('#\.(\w+)#', $event, $matches);
$action = $matches[1];
// If there is matching callback method on the model, call it, passing
// any additional event arguments to it
$method = 'on'.Str::studly($action);
if (method_exists($model, $method)) {
return call_user_func_array([$model, $method], array_slice($payload, 1));
}
} | php | public function handle($event, $payload)
{
list($model) = $payload;
// Get the action from the event name
preg_match('#\.(\w+)#', $event, $matches);
$action = $matches[1];
// If there is matching callback method on the model, call it, passing
// any additional event arguments to it
$method = 'on'.Str::studly($action);
if (method_exists($model, $method)) {
return call_user_func_array([$model, $method], array_slice($payload, 1));
}
} | [
"public",
"function",
"handle",
"(",
"$",
"event",
",",
"$",
"payload",
")",
"{",
"list",
"(",
"$",
"model",
")",
"=",
"$",
"payload",
";",
"// Get the action from the event name",
"preg_match",
"(",
"'#\\.(\\w+)#'",
",",
"$",
"event",
",",
"$",
"matches",
")",
";",
"$",
"action",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"// If there is matching callback method on the model, call it, passing",
"// any additional event arguments to it",
"$",
"method",
"=",
"'on'",
".",
"Str",
"::",
"studly",
"(",
"$",
"action",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"model",
",",
"$",
"method",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"[",
"$",
"model",
",",
"$",
"method",
"]",
",",
"array_slice",
"(",
"$",
"payload",
",",
"1",
")",
")",
";",
"}",
"}"
] | Handle all model events, both Eloquent and Decoy
@param string $event
@param array $payload Contains:
- Bkwld\Decoy\Models\Base $model
@return void | [
"Handle",
"all",
"model",
"events",
"both",
"Eloquent",
"and",
"Decoy"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/ModelCallbacks.php#L22-L36 |
30,680 | BKWLD/decoy | classes/Models/Element.php | Element.setAttribute | public function setAttribute($key, $value)
{
if ($key == 'type') {
switch ($value) {
case 'image': self::$rules['value'] = 'image';
break;
case 'file': self::$rules['value'] = 'file';
break;
case 'video-encoder': self::$rules['value'] = 'video';
break;
}
}
// Continue
return parent::setAttribute($key, $value);
} | php | public function setAttribute($key, $value)
{
if ($key == 'type') {
switch ($value) {
case 'image': self::$rules['value'] = 'image';
break;
case 'file': self::$rules['value'] = 'file';
break;
case 'video-encoder': self::$rules['value'] = 'video';
break;
}
}
// Continue
return parent::setAttribute($key, $value);
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"'type'",
")",
"{",
"switch",
"(",
"$",
"value",
")",
"{",
"case",
"'image'",
":",
"self",
"::",
"$",
"rules",
"[",
"'value'",
"]",
"=",
"'image'",
";",
"break",
";",
"case",
"'file'",
":",
"self",
"::",
"$",
"rules",
"[",
"'value'",
"]",
"=",
"'file'",
";",
"break",
";",
"case",
"'video-encoder'",
":",
"self",
"::",
"$",
"rules",
"[",
"'value'",
"]",
"=",
"'video'",
";",
"break",
";",
"}",
"}",
"// Continue",
"return",
"parent",
"::",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Subclass setAttribute so that we can automatically set validation
rules based on the Element type
@param string $key
@param mixed $value
@return void | [
"Subclass",
"setAttribute",
"so",
"that",
"we",
"can",
"automatically",
"set",
"validation",
"rules",
"based",
"on",
"the",
"Element",
"type"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Element.php#L103-L118 |
30,681 | BKWLD/decoy | classes/Models/Element.php | Element.value | public function value()
{
// Must return a string
if (empty($this->value)) {
return '';
}
// Different outputs depending on type
switch ($this->type) {
case 'boolean': return !empty($this->value);
case 'image': return $this->img()->url;
case 'textarea': return nl2br($this->value);
case 'wysiwyg': return Str::startsWith($this->value, '<') ? $this->value : "<p>{$this->value}</p>";
case 'checkboxes': return explode(',', $this->value);
case 'video-encoder': return $this->encoding('value')->tag;
case 'model': return $this->relatedModel();
default: return $this->value;
}
} | php | public function value()
{
// Must return a string
if (empty($this->value)) {
return '';
}
// Different outputs depending on type
switch ($this->type) {
case 'boolean': return !empty($this->value);
case 'image': return $this->img()->url;
case 'textarea': return nl2br($this->value);
case 'wysiwyg': return Str::startsWith($this->value, '<') ? $this->value : "<p>{$this->value}</p>";
case 'checkboxes': return explode(',', $this->value);
case 'video-encoder': return $this->encoding('value')->tag;
case 'model': return $this->relatedModel();
default: return $this->value;
}
} | [
"public",
"function",
"value",
"(",
")",
"{",
"// Must return a string",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Different outputs depending on type",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"'boolean'",
":",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"value",
")",
";",
"case",
"'image'",
":",
"return",
"$",
"this",
"->",
"img",
"(",
")",
"->",
"url",
";",
"case",
"'textarea'",
":",
"return",
"nl2br",
"(",
"$",
"this",
"->",
"value",
")",
";",
"case",
"'wysiwyg'",
":",
"return",
"Str",
"::",
"startsWith",
"(",
"$",
"this",
"->",
"value",
",",
"'<'",
")",
"?",
"$",
"this",
"->",
"value",
":",
"\"<p>{$this->value}</p>\"",
";",
"case",
"'checkboxes'",
":",
"return",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"value",
")",
";",
"case",
"'video-encoder'",
":",
"return",
"$",
"this",
"->",
"encoding",
"(",
"'value'",
")",
"->",
"tag",
";",
"case",
"'model'",
":",
"return",
"$",
"this",
"->",
"relatedModel",
"(",
")",
";",
"default",
":",
"return",
"$",
"this",
"->",
"value",
";",
"}",
"}"
] | Format the value before returning it based on the type
@return mixed Stringable | [
"Format",
"the",
"value",
"before",
"returning",
"it",
"based",
"on",
"the",
"type"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Element.php#L125-L144 |
30,682 | BKWLD/decoy | classes/Models/Element.php | Element.relatedModel | protected function relatedModel()
{
$yaml = app('decoy.elements')->getConfig();
$model = array_get($yaml, $this->key.'.class')
?: array_get($yaml, $this->key.',model.class');
return $model::find($this->value);
} | php | protected function relatedModel()
{
$yaml = app('decoy.elements')->getConfig();
$model = array_get($yaml, $this->key.'.class')
?: array_get($yaml, $this->key.',model.class');
return $model::find($this->value);
} | [
"protected",
"function",
"relatedModel",
"(",
")",
"{",
"$",
"yaml",
"=",
"app",
"(",
"'decoy.elements'",
")",
"->",
"getConfig",
"(",
")",
";",
"$",
"model",
"=",
"array_get",
"(",
"$",
"yaml",
",",
"$",
"this",
"->",
"key",
".",
"'.class'",
")",
"?",
":",
"array_get",
"(",
"$",
"yaml",
",",
"$",
"this",
"->",
"key",
".",
"',model.class'",
")",
";",
"return",
"$",
"model",
"::",
"find",
"(",
"$",
"this",
"->",
"value",
")",
";",
"}"
] | Get the model referenced in a "model" field
@return Model | [
"Get",
"the",
"model",
"referenced",
"in",
"a",
"model",
"field"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Element.php#L151-L158 |
30,683 | BKWLD/decoy | classes/Models/Element.php | Element.img | public function img()
{
// Check for an existing Image relation
if (($image = $this->parentImg($this->inputName()))
&& $image->exists) {
// If the Image represents a default image, but doesn't match the current
// item from the config, trash the current one and build the new default
// image.
if ($replacement = $this->getReplacementImage($image)) {
return $replacement;
}
// Return the found image
return $image;
}
// Else return a default image
return $this->defaultImage();
} | php | public function img()
{
// Check for an existing Image relation
if (($image = $this->parentImg($this->inputName()))
&& $image->exists) {
// If the Image represents a default image, but doesn't match the current
// item from the config, trash the current one and build the new default
// image.
if ($replacement = $this->getReplacementImage($image)) {
return $replacement;
}
// Return the found image
return $image;
}
// Else return a default image
return $this->defaultImage();
} | [
"public",
"function",
"img",
"(",
")",
"{",
"// Check for an existing Image relation",
"if",
"(",
"(",
"$",
"image",
"=",
"$",
"this",
"->",
"parentImg",
"(",
"$",
"this",
"->",
"inputName",
"(",
")",
")",
")",
"&&",
"$",
"image",
"->",
"exists",
")",
"{",
"// If the Image represents a default image, but doesn't match the current",
"// item from the config, trash the current one and build the new default",
"// image.",
"if",
"(",
"$",
"replacement",
"=",
"$",
"this",
"->",
"getReplacementImage",
"(",
"$",
"image",
")",
")",
"{",
"return",
"$",
"replacement",
";",
"}",
"// Return the found image",
"return",
"$",
"image",
";",
"}",
"// Else return a default image",
"return",
"$",
"this",
"->",
"defaultImage",
"(",
")",
";",
"}"
] | Look for default iamges using a named key. It was a lot simpler in the
integeration with the Elements admin UI to store the input name in the
"name" attribute
@return Image | [
"Look",
"for",
"default",
"iamges",
"using",
"a",
"named",
"key",
".",
"It",
"was",
"a",
"lot",
"simpler",
"in",
"the",
"integeration",
"with",
"the",
"Elements",
"admin",
"UI",
"to",
"store",
"the",
"input",
"name",
"in",
"the",
"name",
"attribute"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Element.php#L189-L208 |
30,684 | BKWLD/decoy | classes/Models/Element.php | Element.getReplacementImage | protected function getReplacementImage(Image $image)
{
// Check that the image is in the elements dir, which means it's
// a default image
if (!strpos($image->file, '/elements/')) {
return;
}
// Get the current file value form the YAML. Need to check for the
// shorthand with the type suffix as well.
$yaml = app('decoy.elements')->assocConfig();
$replacement = $yaml[$this->key]['value'];
// Check if the filenames are the same
if (pathinfo($image->file, PATHINFO_BASENAME)
== pathinfo($replacement, PATHINFO_BASENAME)) {
return;
}
// Since the filenames are not the same, remove the old image and generate
// a new one
$image->delete();
$this->exists = true; // It actually does exist if there was an Image
$this->value = $replacement;
return $this->defaultImage();
} | php | protected function getReplacementImage(Image $image)
{
// Check that the image is in the elements dir, which means it's
// a default image
if (!strpos($image->file, '/elements/')) {
return;
}
// Get the current file value form the YAML. Need to check for the
// shorthand with the type suffix as well.
$yaml = app('decoy.elements')->assocConfig();
$replacement = $yaml[$this->key]['value'];
// Check if the filenames are the same
if (pathinfo($image->file, PATHINFO_BASENAME)
== pathinfo($replacement, PATHINFO_BASENAME)) {
return;
}
// Since the filenames are not the same, remove the old image and generate
// a new one
$image->delete();
$this->exists = true; // It actually does exist if there was an Image
$this->value = $replacement;
return $this->defaultImage();
} | [
"protected",
"function",
"getReplacementImage",
"(",
"Image",
"$",
"image",
")",
"{",
"// Check that the image is in the elements dir, which means it's",
"// a default image",
"if",
"(",
"!",
"strpos",
"(",
"$",
"image",
"->",
"file",
",",
"'/elements/'",
")",
")",
"{",
"return",
";",
"}",
"// Get the current file value form the YAML. Need to check for the",
"// shorthand with the type suffix as well.",
"$",
"yaml",
"=",
"app",
"(",
"'decoy.elements'",
")",
"->",
"assocConfig",
"(",
")",
";",
"$",
"replacement",
"=",
"$",
"yaml",
"[",
"$",
"this",
"->",
"key",
"]",
"[",
"'value'",
"]",
";",
"// Check if the filenames are the same",
"if",
"(",
"pathinfo",
"(",
"$",
"image",
"->",
"file",
",",
"PATHINFO_BASENAME",
")",
"==",
"pathinfo",
"(",
"$",
"replacement",
",",
"PATHINFO_BASENAME",
")",
")",
"{",
"return",
";",
"}",
"// Since the filenames are not the same, remove the old image and generate",
"// a new one",
"$",
"image",
"->",
"delete",
"(",
")",
";",
"$",
"this",
"->",
"exists",
"=",
"true",
";",
"// It actually does exist if there was an Image",
"$",
"this",
"->",
"value",
"=",
"$",
"replacement",
";",
"return",
"$",
"this",
"->",
"defaultImage",
"(",
")",
";",
"}"
] | Check if the Image represents a default image but is out of date
@param Image $image
@return Image|void | [
"Check",
"if",
"the",
"Image",
"represents",
"a",
"default",
"image",
"but",
"is",
"out",
"of",
"date"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Element.php#L216-L242 |
30,685 | BKWLD/decoy | classes/Models/Element.php | Element.defaultImage | public function defaultImage()
{
// Return an empty Image object if no default value
if (empty($this->value)) {
return new Image;
}
// All src images must live in the /img (relative) directory
if (!Str::is('/img/*', $this->value)) {
$msg = 'Element images must be stored in public/img: '.$this->value;
throw new Exception($msg);
}
// Check if the image already exists in the uploads directory
$src = $this->value;
$src_abs = public_path($src);
$path = str_replace('/img/', '/elements/', $src);
if (!app('upchuck.disk')->has($path)) {
// Copy it to the disk
$stream = fopen($src_abs, 'r+');
app('upchuck.disk')->writeStream($path, $stream);
fclose($stream);
}
// Wrap the touching of the element and images table in a transaction
// so that the element isn't updated if the images write fails
DB::beginTransaction();
// Update or create this Element instance
$this->value = app('upchuck')->url($path);
$this->save();
// Create and return new Image instance. The Image::populateFileMeta()
// requires an UploadedFile, so we need to do it manually here.
$size = getimagesize($src_abs);
$image = new Image([
'file' => $this->value,
'name' => $this->inputName(),
'file_type' => pathinfo($src_abs, PATHINFO_EXTENSION),
'file_size' => filesize($src_abs),
'width' => $size[0],
'height' => $size[1],
]);
$this->images()->save($image);
DB::commit();
// Clear cached image relations
unset($this->relations['images']);
// Return the image
return $image;
} | php | public function defaultImage()
{
// Return an empty Image object if no default value
if (empty($this->value)) {
return new Image;
}
// All src images must live in the /img (relative) directory
if (!Str::is('/img/*', $this->value)) {
$msg = 'Element images must be stored in public/img: '.$this->value;
throw new Exception($msg);
}
// Check if the image already exists in the uploads directory
$src = $this->value;
$src_abs = public_path($src);
$path = str_replace('/img/', '/elements/', $src);
if (!app('upchuck.disk')->has($path)) {
// Copy it to the disk
$stream = fopen($src_abs, 'r+');
app('upchuck.disk')->writeStream($path, $stream);
fclose($stream);
}
// Wrap the touching of the element and images table in a transaction
// so that the element isn't updated if the images write fails
DB::beginTransaction();
// Update or create this Element instance
$this->value = app('upchuck')->url($path);
$this->save();
// Create and return new Image instance. The Image::populateFileMeta()
// requires an UploadedFile, so we need to do it manually here.
$size = getimagesize($src_abs);
$image = new Image([
'file' => $this->value,
'name' => $this->inputName(),
'file_type' => pathinfo($src_abs, PATHINFO_EXTENSION),
'file_size' => filesize($src_abs),
'width' => $size[0],
'height' => $size[1],
]);
$this->images()->save($image);
DB::commit();
// Clear cached image relations
unset($this->relations['images']);
// Return the image
return $image;
} | [
"public",
"function",
"defaultImage",
"(",
")",
"{",
"// Return an empty Image object if no default value",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"new",
"Image",
";",
"}",
"// All src images must live in the /img (relative) directory",
"if",
"(",
"!",
"Str",
"::",
"is",
"(",
"'/img/*'",
",",
"$",
"this",
"->",
"value",
")",
")",
"{",
"$",
"msg",
"=",
"'Element images must be stored in public/img: '",
".",
"$",
"this",
"->",
"value",
";",
"throw",
"new",
"Exception",
"(",
"$",
"msg",
")",
";",
"}",
"// Check if the image already exists in the uploads directory",
"$",
"src",
"=",
"$",
"this",
"->",
"value",
";",
"$",
"src_abs",
"=",
"public_path",
"(",
"$",
"src",
")",
";",
"$",
"path",
"=",
"str_replace",
"(",
"'/img/'",
",",
"'/elements/'",
",",
"$",
"src",
")",
";",
"if",
"(",
"!",
"app",
"(",
"'upchuck.disk'",
")",
"->",
"has",
"(",
"$",
"path",
")",
")",
"{",
"// Copy it to the disk",
"$",
"stream",
"=",
"fopen",
"(",
"$",
"src_abs",
",",
"'r+'",
")",
";",
"app",
"(",
"'upchuck.disk'",
")",
"->",
"writeStream",
"(",
"$",
"path",
",",
"$",
"stream",
")",
";",
"fclose",
"(",
"$",
"stream",
")",
";",
"}",
"// Wrap the touching of the element and images table in a transaction",
"// so that the element isn't updated if the images write fails",
"DB",
"::",
"beginTransaction",
"(",
")",
";",
"// Update or create this Element instance",
"$",
"this",
"->",
"value",
"=",
"app",
"(",
"'upchuck'",
")",
"->",
"url",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"// Create and return new Image instance. The Image::populateFileMeta()",
"// requires an UploadedFile, so we need to do it manually here.",
"$",
"size",
"=",
"getimagesize",
"(",
"$",
"src_abs",
")",
";",
"$",
"image",
"=",
"new",
"Image",
"(",
"[",
"'file'",
"=>",
"$",
"this",
"->",
"value",
",",
"'name'",
"=>",
"$",
"this",
"->",
"inputName",
"(",
")",
",",
"'file_type'",
"=>",
"pathinfo",
"(",
"$",
"src_abs",
",",
"PATHINFO_EXTENSION",
")",
",",
"'file_size'",
"=>",
"filesize",
"(",
"$",
"src_abs",
")",
",",
"'width'",
"=>",
"$",
"size",
"[",
"0",
"]",
",",
"'height'",
"=>",
"$",
"size",
"[",
"1",
"]",
",",
"]",
")",
";",
"$",
"this",
"->",
"images",
"(",
")",
"->",
"save",
"(",
"$",
"image",
")",
";",
"DB",
"::",
"commit",
"(",
")",
";",
"// Clear cached image relations",
"unset",
"(",
"$",
"this",
"->",
"relations",
"[",
"'images'",
"]",
")",
";",
"// Return the image",
"return",
"$",
"image",
";",
"}"
] | Check if the value looks like an image. If it does, copy it to the uploads
dir so Croppa can work on it and return the modified path
@return Image | [
"Check",
"if",
"the",
"value",
"looks",
"like",
"an",
"image",
".",
"If",
"it",
"does",
"copy",
"it",
"to",
"the",
"uploads",
"dir",
"so",
"Croppa",
"can",
"work",
"on",
"it",
"and",
"return",
"the",
"modified",
"path"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Element.php#L250-L302 |
30,686 | BKWLD/decoy | classes/Collections/Elements.php | Elements.asModels | public function asModels()
{
$this->hydrate();
return new ModelCollection(array_map(function ($element, $key) {
// Add the key as an attribute
return new $this->model(array_merge($element, ['key' => $key]));
}, $this->all(), array_keys($this->items)));
} | php | public function asModels()
{
$this->hydrate();
return new ModelCollection(array_map(function ($element, $key) {
// Add the key as an attribute
return new $this->model(array_merge($element, ['key' => $key]));
}, $this->all(), array_keys($this->items)));
} | [
"public",
"function",
"asModels",
"(",
")",
"{",
"$",
"this",
"->",
"hydrate",
"(",
")",
";",
"return",
"new",
"ModelCollection",
"(",
"array_map",
"(",
"function",
"(",
"$",
"element",
",",
"$",
"key",
")",
"{",
"// Add the key as an attribute",
"return",
"new",
"$",
"this",
"->",
"model",
"(",
"array_merge",
"(",
"$",
"element",
",",
"[",
"'key'",
"=>",
"$",
"key",
"]",
")",
")",
";",
"}",
",",
"$",
"this",
"->",
"all",
"(",
")",
",",
"array_keys",
"(",
"$",
"this",
"->",
"items",
")",
")",
")",
";",
"}"
] | Map the items into a collection of Element instances
@return Bkwld\Decoy\Collections\Elements | [
"Map",
"the",
"items",
"into",
"a",
"collection",
"of",
"Element",
"instances"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L71-L80 |
30,687 | BKWLD/decoy | classes/Collections/Elements.php | Elements.get | public function get($key, $default = null)
{
$this->hydrate();
// Create an Element instance using the data for the key
if ($this->has($key)) {
return new $this->model(array_merge($this->items[$key], ['key' => $key]));
}
// If the key doesn't exist but a default was passed in, return it
if ($default) {
return $default;
}
// if the key doesn't exist, but running locally, throw an exception
if (App::isLocal()) {
throw new Exception("Element key '{$key}' is not declared in elements.yaml.");
}
// Otherwise, like if key doesn't exist and running on production,
// return an empty Element, whose ->toString() will return an empty string.
Log::error("Element key '{$key}' is not declared in elements.yaml.");
return new $this->model();
} | php | public function get($key, $default = null)
{
$this->hydrate();
// Create an Element instance using the data for the key
if ($this->has($key)) {
return new $this->model(array_merge($this->items[$key], ['key' => $key]));
}
// If the key doesn't exist but a default was passed in, return it
if ($default) {
return $default;
}
// if the key doesn't exist, but running locally, throw an exception
if (App::isLocal()) {
throw new Exception("Element key '{$key}' is not declared in elements.yaml.");
}
// Otherwise, like if key doesn't exist and running on production,
// return an empty Element, whose ->toString() will return an empty string.
Log::error("Element key '{$key}' is not declared in elements.yaml.");
return new $this->model();
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"hydrate",
"(",
")",
";",
"// Create an Element instance using the data for the key",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"new",
"$",
"this",
"->",
"model",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
",",
"[",
"'key'",
"=>",
"$",
"key",
"]",
")",
")",
";",
"}",
"// If the key doesn't exist but a default was passed in, return it",
"if",
"(",
"$",
"default",
")",
"{",
"return",
"$",
"default",
";",
"}",
"// if the key doesn't exist, but running locally, throw an exception",
"if",
"(",
"App",
"::",
"isLocal",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Element key '{$key}' is not declared in elements.yaml.\"",
")",
";",
"}",
"// Otherwise, like if key doesn't exist and running on production,",
"// return an empty Element, whose ->toString() will return an empty string.",
"Log",
"::",
"error",
"(",
"\"Element key '{$key}' is not declared in elements.yaml.\"",
")",
";",
"return",
"new",
"$",
"this",
"->",
"model",
"(",
")",
";",
"}"
] | Get an element given it's key
@param string $key
@return Bkwld\Decoy\Models\Element | [
"Get",
"an",
"element",
"given",
"it",
"s",
"key"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L88-L111 |
30,688 | BKWLD/decoy | classes/Collections/Elements.php | Elements.getMany | public function getMany($prefix, $crops = [])
{
// Get all of the elements matching the prefix with dot-notated keys
$dotted = $this
->hydrate()
->filter(function($val, $key) use ($prefix) {
return starts_with($key, $prefix);
// Loop through all matching elements
})->map(function($val, $key) use ($prefix, $crops) {
// Resolve the key using the Element helper so that we get an
// actual Element model instance.
$el = $this->get($key);
$value = $el->value();
// Check if the element key is in the $crops config. If so,
// return the croopped image instructions.
$crop_key = substr($key, strlen($prefix) + 1);
if (isset($crops[$crop_key])) {
// Handle models returned from BelongsTo fields
if (is_a($value, Base::class)) {
$func = [$value, 'withDefaultImage'];
return call_user_func_array($func, $crops[$crop_key]);
}
// Otherwise, use the crop helper on the Element model
return call_user_func_array([$el, 'crop'], $crops[$crop_key]);
}
// If no crops were defined, return the value
return (string) $value;
// Convert the collection to an array
})->all();
// Make a multidimensionsl array from the dots, stripping the prefix
// from the keys. Then return it.
$multi = [];
$len = strlen($prefix);
foreach($dotted as $key => $val) {
array_set($multi, trim(substr($key, $len), '.'), $val);
}
return $multi;
} | php | public function getMany($prefix, $crops = [])
{
// Get all of the elements matching the prefix with dot-notated keys
$dotted = $this
->hydrate()
->filter(function($val, $key) use ($prefix) {
return starts_with($key, $prefix);
// Loop through all matching elements
})->map(function($val, $key) use ($prefix, $crops) {
// Resolve the key using the Element helper so that we get an
// actual Element model instance.
$el = $this->get($key);
$value = $el->value();
// Check if the element key is in the $crops config. If so,
// return the croopped image instructions.
$crop_key = substr($key, strlen($prefix) + 1);
if (isset($crops[$crop_key])) {
// Handle models returned from BelongsTo fields
if (is_a($value, Base::class)) {
$func = [$value, 'withDefaultImage'];
return call_user_func_array($func, $crops[$crop_key]);
}
// Otherwise, use the crop helper on the Element model
return call_user_func_array([$el, 'crop'], $crops[$crop_key]);
}
// If no crops were defined, return the value
return (string) $value;
// Convert the collection to an array
})->all();
// Make a multidimensionsl array from the dots, stripping the prefix
// from the keys. Then return it.
$multi = [];
$len = strlen($prefix);
foreach($dotted as $key => $val) {
array_set($multi, trim(substr($key, $len), '.'), $val);
}
return $multi;
} | [
"public",
"function",
"getMany",
"(",
"$",
"prefix",
",",
"$",
"crops",
"=",
"[",
"]",
")",
"{",
"// Get all of the elements matching the prefix with dot-notated keys",
"$",
"dotted",
"=",
"$",
"this",
"->",
"hydrate",
"(",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"val",
",",
"$",
"key",
")",
"use",
"(",
"$",
"prefix",
")",
"{",
"return",
"starts_with",
"(",
"$",
"key",
",",
"$",
"prefix",
")",
";",
"// Loop through all matching elements",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"val",
",",
"$",
"key",
")",
"use",
"(",
"$",
"prefix",
",",
"$",
"crops",
")",
"{",
"// Resolve the key using the Element helper so that we get an",
"// actual Element model instance.",
"$",
"el",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"$",
"value",
"=",
"$",
"el",
"->",
"value",
"(",
")",
";",
"// Check if the element key is in the $crops config. If so,",
"// return the croopped image instructions.",
"$",
"crop_key",
"=",
"substr",
"(",
"$",
"key",
",",
"strlen",
"(",
"$",
"prefix",
")",
"+",
"1",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"crops",
"[",
"$",
"crop_key",
"]",
")",
")",
"{",
"// Handle models returned from BelongsTo fields",
"if",
"(",
"is_a",
"(",
"$",
"value",
",",
"Base",
"::",
"class",
")",
")",
"{",
"$",
"func",
"=",
"[",
"$",
"value",
",",
"'withDefaultImage'",
"]",
";",
"return",
"call_user_func_array",
"(",
"$",
"func",
",",
"$",
"crops",
"[",
"$",
"crop_key",
"]",
")",
";",
"}",
"// Otherwise, use the crop helper on the Element model",
"return",
"call_user_func_array",
"(",
"[",
"$",
"el",
",",
"'crop'",
"]",
",",
"$",
"crops",
"[",
"$",
"crop_key",
"]",
")",
";",
"}",
"// If no crops were defined, return the value",
"return",
"(",
"string",
")",
"$",
"value",
";",
"// Convert the collection to an array",
"}",
")",
"->",
"all",
"(",
")",
";",
"// Make a multidimensionsl array from the dots, stripping the prefix",
"// from the keys. Then return it.",
"$",
"multi",
"=",
"[",
"]",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"prefix",
")",
";",
"foreach",
"(",
"$",
"dotted",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"array_set",
"(",
"$",
"multi",
",",
"trim",
"(",
"substr",
"(",
"$",
"key",
",",
"$",
"len",
")",
",",
"'.'",
")",
",",
"$",
"val",
")",
";",
"}",
"return",
"$",
"multi",
";",
"}"
] | Get a number of elements at once by passing in a first or second level
depth key. Like just `'homepage.marquee'`
@param string $prefix Any leading part of a key
@param array $crops Assoc array with Element partial keys for ITS keys
and values as an arary of crop()-style arguments
@return array | [
"Get",
"a",
"number",
"of",
"elements",
"at",
"once",
"by",
"passing",
"in",
"a",
"first",
"or",
"second",
"level",
"depth",
"key",
".",
"Like",
"just",
"homepage",
".",
"marquee"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L122-L167 |
30,689 | BKWLD/decoy | classes/Collections/Elements.php | Elements.mergeSources | protected function mergeSources()
{
$assoc = $this->assocConfig();
return array_replace_recursive($assoc,
// Get only the databse records whose keys are present in the YAML. This removes
// entries that may be from older YAML configs.
array_intersect_key($this->assocAdminChoices(), $assoc)
);
} | php | protected function mergeSources()
{
$assoc = $this->assocConfig();
return array_replace_recursive($assoc,
// Get only the databse records whose keys are present in the YAML. This removes
// entries that may be from older YAML configs.
array_intersect_key($this->assocAdminChoices(), $assoc)
);
} | [
"protected",
"function",
"mergeSources",
"(",
")",
"{",
"$",
"assoc",
"=",
"$",
"this",
"->",
"assocConfig",
"(",
")",
";",
"return",
"array_replace_recursive",
"(",
"$",
"assoc",
",",
"// Get only the databse records whose keys are present in the YAML. This removes",
"// entries that may be from older YAML configs.",
"array_intersect_key",
"(",
"$",
"this",
"->",
"assocAdminChoices",
"(",
")",
",",
"$",
"assoc",
")",
")",
";",
"}"
] | Merge database records and config file into a single, flat associative array.
@return void | [
"Merge",
"database",
"records",
"and",
"config",
"file",
"into",
"a",
"single",
"flat",
"associative",
"array",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L280-L290 |
30,690 | BKWLD/decoy | classes/Collections/Elements.php | Elements.assocConfig | public function assocConfig($include_extra = false)
{
// Load the config data if it isn't already
if (!$this->config) {
$this->loadConfig();
}
// Loop through the YAML config and make flattened keys. The ternary
// operators in here allow a shorthand version of the YAML config as
// described in the docs.
$config = [];
foreach ($this->config as $page => $page_data) {
foreach (isset($page_data['sections']) ? $page_data['sections'] : $page_data as $section => $section_data) {
foreach (isset($section_data['fields']) ? $section_data['fields'] : $section_data as $field => $field_data) {
// Determine the type of field
$field_parts = explode(',', $field);
$field = $field_parts[0];
if (count($field_parts) == 2) {
$type = $field_parts[1];
} // If concatted onto the field name
elseif (is_array($field_data) && isset($field_data['type'])) {
$type = $field_data['type'];
} // Explicitly set
else {
$type = 'text';
} // Default type
// Determine the value
if (is_array($field_data) && array_key_exists('value', $field_data)) {
$value = $field_data['value'];
} elseif (is_scalar($field_data)) {
$value = $field_data;
} // String, boolean, int, etc
else {
$value = null;
}
// Build the value array
$el = ['type' => $type, 'value' => $value];
if ($this->has_extra || $include_extra) {
$this->mergeExtra($el, $field, $field_data);
$this->mergeExtra($el, $section, $section_data, 'section_');
$this->mergeExtra($el, $page, $page_data, 'page_');
$el['rules'] = isset($field_data['rules']) ? $field_data['rules'] : null;
}
// Add the config
$config["{$page}.{$section}.{$field}"] = $el;
}
}
}
// Return the flattened config
return $config;
} | php | public function assocConfig($include_extra = false)
{
// Load the config data if it isn't already
if (!$this->config) {
$this->loadConfig();
}
// Loop through the YAML config and make flattened keys. The ternary
// operators in here allow a shorthand version of the YAML config as
// described in the docs.
$config = [];
foreach ($this->config as $page => $page_data) {
foreach (isset($page_data['sections']) ? $page_data['sections'] : $page_data as $section => $section_data) {
foreach (isset($section_data['fields']) ? $section_data['fields'] : $section_data as $field => $field_data) {
// Determine the type of field
$field_parts = explode(',', $field);
$field = $field_parts[0];
if (count($field_parts) == 2) {
$type = $field_parts[1];
} // If concatted onto the field name
elseif (is_array($field_data) && isset($field_data['type'])) {
$type = $field_data['type'];
} // Explicitly set
else {
$type = 'text';
} // Default type
// Determine the value
if (is_array($field_data) && array_key_exists('value', $field_data)) {
$value = $field_data['value'];
} elseif (is_scalar($field_data)) {
$value = $field_data;
} // String, boolean, int, etc
else {
$value = null;
}
// Build the value array
$el = ['type' => $type, 'value' => $value];
if ($this->has_extra || $include_extra) {
$this->mergeExtra($el, $field, $field_data);
$this->mergeExtra($el, $section, $section_data, 'section_');
$this->mergeExtra($el, $page, $page_data, 'page_');
$el['rules'] = isset($field_data['rules']) ? $field_data['rules'] : null;
}
// Add the config
$config["{$page}.{$section}.{$field}"] = $el;
}
}
}
// Return the flattened config
return $config;
} | [
"public",
"function",
"assocConfig",
"(",
"$",
"include_extra",
"=",
"false",
")",
"{",
"// Load the config data if it isn't already",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
")",
"{",
"$",
"this",
"->",
"loadConfig",
"(",
")",
";",
"}",
"// Loop through the YAML config and make flattened keys. The ternary",
"// operators in here allow a shorthand version of the YAML config as",
"// described in the docs.",
"$",
"config",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"config",
"as",
"$",
"page",
"=>",
"$",
"page_data",
")",
"{",
"foreach",
"(",
"isset",
"(",
"$",
"page_data",
"[",
"'sections'",
"]",
")",
"?",
"$",
"page_data",
"[",
"'sections'",
"]",
":",
"$",
"page_data",
"as",
"$",
"section",
"=>",
"$",
"section_data",
")",
"{",
"foreach",
"(",
"isset",
"(",
"$",
"section_data",
"[",
"'fields'",
"]",
")",
"?",
"$",
"section_data",
"[",
"'fields'",
"]",
":",
"$",
"section_data",
"as",
"$",
"field",
"=>",
"$",
"field_data",
")",
"{",
"// Determine the type of field",
"$",
"field_parts",
"=",
"explode",
"(",
"','",
",",
"$",
"field",
")",
";",
"$",
"field",
"=",
"$",
"field_parts",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"field_parts",
")",
"==",
"2",
")",
"{",
"$",
"type",
"=",
"$",
"field_parts",
"[",
"1",
"]",
";",
"}",
"// If concatted onto the field name",
"elseif",
"(",
"is_array",
"(",
"$",
"field_data",
")",
"&&",
"isset",
"(",
"$",
"field_data",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"field_data",
"[",
"'type'",
"]",
";",
"}",
"// Explicitly set",
"else",
"{",
"$",
"type",
"=",
"'text'",
";",
"}",
"// Default type",
"// Determine the value",
"if",
"(",
"is_array",
"(",
"$",
"field_data",
")",
"&&",
"array_key_exists",
"(",
"'value'",
",",
"$",
"field_data",
")",
")",
"{",
"$",
"value",
"=",
"$",
"field_data",
"[",
"'value'",
"]",
";",
"}",
"elseif",
"(",
"is_scalar",
"(",
"$",
"field_data",
")",
")",
"{",
"$",
"value",
"=",
"$",
"field_data",
";",
"}",
"// String, boolean, int, etc",
"else",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"// Build the value array",
"$",
"el",
"=",
"[",
"'type'",
"=>",
"$",
"type",
",",
"'value'",
"=>",
"$",
"value",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"has_extra",
"||",
"$",
"include_extra",
")",
"{",
"$",
"this",
"->",
"mergeExtra",
"(",
"$",
"el",
",",
"$",
"field",
",",
"$",
"field_data",
")",
";",
"$",
"this",
"->",
"mergeExtra",
"(",
"$",
"el",
",",
"$",
"section",
",",
"$",
"section_data",
",",
"'section_'",
")",
";",
"$",
"this",
"->",
"mergeExtra",
"(",
"$",
"el",
",",
"$",
"page",
",",
"$",
"page_data",
",",
"'page_'",
")",
";",
"$",
"el",
"[",
"'rules'",
"]",
"=",
"isset",
"(",
"$",
"field_data",
"[",
"'rules'",
"]",
")",
"?",
"$",
"field_data",
"[",
"'rules'",
"]",
":",
"null",
";",
"}",
"// Add the config",
"$",
"config",
"[",
"\"{$page}.{$section}.{$field}\"",
"]",
"=",
"$",
"el",
";",
"}",
"}",
"}",
"// Return the flattened config",
"return",
"$",
"config",
";",
"}"
] | Massage the YAML config file into a single, flat associative array
@param boolean $include_extra Include attibutes that are only needed by Admin UIs
@return array | [
"Massage",
"the",
"YAML",
"config",
"file",
"into",
"a",
"single",
"flat",
"associative",
"array"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L298-L353 |
30,691 | BKWLD/decoy | classes/Collections/Elements.php | Elements.mergeExtra | protected function mergeExtra(&$el, $key, $data, $prefix = null)
{
// Don't add extra if this in the 1st or 2nd depth (which means there is a prefix)
// and there is no node for the children. This prevents a FIELD named "label" to be
// treated as the the label for it's section.
$skip = $prefix && empty($data['sections']) && empty($data['fields']);
// Fields
if (isset($data['label']) && $data['label'] === false) {
$el[$prefix.'label'] = false;
} else {
$el[$prefix.'label'] = empty($data['label']) || $skip ? Utils\Text::titleFromKey($key) : $data['label'];
}
$el[$prefix.'help'] = empty($data['help']) || $skip ? null : $data['help'];
// Used by radio, select, and checkboxes types
$el[$prefix.'options'] = empty($data['options']) || $skip ? null : $data['options'];
// Used by belongs to but maybe others in the future
$el[$prefix.'class'] = empty($data['class']) || $skip ? null : $data['class'];
// Used by videoEncoder
$el[$prefix.'preset'] = empty($data['preset']) || $skip ? null : $data['preset'];
} | php | protected function mergeExtra(&$el, $key, $data, $prefix = null)
{
// Don't add extra if this in the 1st or 2nd depth (which means there is a prefix)
// and there is no node for the children. This prevents a FIELD named "label" to be
// treated as the the label for it's section.
$skip = $prefix && empty($data['sections']) && empty($data['fields']);
// Fields
if (isset($data['label']) && $data['label'] === false) {
$el[$prefix.'label'] = false;
} else {
$el[$prefix.'label'] = empty($data['label']) || $skip ? Utils\Text::titleFromKey($key) : $data['label'];
}
$el[$prefix.'help'] = empty($data['help']) || $skip ? null : $data['help'];
// Used by radio, select, and checkboxes types
$el[$prefix.'options'] = empty($data['options']) || $skip ? null : $data['options'];
// Used by belongs to but maybe others in the future
$el[$prefix.'class'] = empty($data['class']) || $skip ? null : $data['class'];
// Used by videoEncoder
$el[$prefix.'preset'] = empty($data['preset']) || $skip ? null : $data['preset'];
} | [
"protected",
"function",
"mergeExtra",
"(",
"&",
"$",
"el",
",",
"$",
"key",
",",
"$",
"data",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"// Don't add extra if this in the 1st or 2nd depth (which means there is a prefix)",
"// and there is no node for the children. This prevents a FIELD named \"label\" to be",
"// treated as the the label for it's section.",
"$",
"skip",
"=",
"$",
"prefix",
"&&",
"empty",
"(",
"$",
"data",
"[",
"'sections'",
"]",
")",
"&&",
"empty",
"(",
"$",
"data",
"[",
"'fields'",
"]",
")",
";",
"// Fields",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'label'",
"]",
")",
"&&",
"$",
"data",
"[",
"'label'",
"]",
"===",
"false",
")",
"{",
"$",
"el",
"[",
"$",
"prefix",
".",
"'label'",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"el",
"[",
"$",
"prefix",
".",
"'label'",
"]",
"=",
"empty",
"(",
"$",
"data",
"[",
"'label'",
"]",
")",
"||",
"$",
"skip",
"?",
"Utils",
"\\",
"Text",
"::",
"titleFromKey",
"(",
"$",
"key",
")",
":",
"$",
"data",
"[",
"'label'",
"]",
";",
"}",
"$",
"el",
"[",
"$",
"prefix",
".",
"'help'",
"]",
"=",
"empty",
"(",
"$",
"data",
"[",
"'help'",
"]",
")",
"||",
"$",
"skip",
"?",
"null",
":",
"$",
"data",
"[",
"'help'",
"]",
";",
"// Used by radio, select, and checkboxes types",
"$",
"el",
"[",
"$",
"prefix",
".",
"'options'",
"]",
"=",
"empty",
"(",
"$",
"data",
"[",
"'options'",
"]",
")",
"||",
"$",
"skip",
"?",
"null",
":",
"$",
"data",
"[",
"'options'",
"]",
";",
"// Used by belongs to but maybe others in the future",
"$",
"el",
"[",
"$",
"prefix",
".",
"'class'",
"]",
"=",
"empty",
"(",
"$",
"data",
"[",
"'class'",
"]",
")",
"||",
"$",
"skip",
"?",
"null",
":",
"$",
"data",
"[",
"'class'",
"]",
";",
"// Used by videoEncoder",
"$",
"el",
"[",
"$",
"prefix",
".",
"'preset'",
"]",
"=",
"empty",
"(",
"$",
"data",
"[",
"'preset'",
"]",
")",
"||",
"$",
"skip",
"?",
"null",
":",
"$",
"data",
"[",
"'preset'",
"]",
";",
"}"
] | Add label and help to the element data for one of the levels
@param array $el The element data that is being merged into, passed by reference
@param mixed $data The data for a level in the Elements YAML config
@param string $prefix A prefix to append to the beginning of the key being set on $el | [
"Add",
"label",
"and",
"help",
"to",
"the",
"element",
"data",
"for",
"one",
"of",
"the",
"levels"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L362-L385 |
30,692 | BKWLD/decoy | classes/Collections/Elements.php | Elements.assocAdminChoices | protected function assocAdminChoices()
{
// Build the query
$query = call_user_func([$this->model, 'query']);
if ($this->locale) {
$query->localize($this->locale);
}
// Convert models to simple array
$elements = array_map(function (Element $element) {
// Don't need the key as an attribute because of the dictionary conversion
$ar = array_except($element->toArray(), ['key']);
// Restore relationships
$ar['images'] = $element->images;
return $ar;
// .. from a dictionary of ALL elements for the locale
}, $query->get()->getDictionary());
// Store the keys of all these elements so we can keep track of which
// Elements "exist"
$this->updated_items = array_keys($elements);
// Return the elements
return $elements;
} | php | protected function assocAdminChoices()
{
// Build the query
$query = call_user_func([$this->model, 'query']);
if ($this->locale) {
$query->localize($this->locale);
}
// Convert models to simple array
$elements = array_map(function (Element $element) {
// Don't need the key as an attribute because of the dictionary conversion
$ar = array_except($element->toArray(), ['key']);
// Restore relationships
$ar['images'] = $element->images;
return $ar;
// .. from a dictionary of ALL elements for the locale
}, $query->get()->getDictionary());
// Store the keys of all these elements so we can keep track of which
// Elements "exist"
$this->updated_items = array_keys($elements);
// Return the elements
return $elements;
} | [
"protected",
"function",
"assocAdminChoices",
"(",
")",
"{",
"// Build the query",
"$",
"query",
"=",
"call_user_func",
"(",
"[",
"$",
"this",
"->",
"model",
",",
"'query'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"locale",
")",
"{",
"$",
"query",
"->",
"localize",
"(",
"$",
"this",
"->",
"locale",
")",
";",
"}",
"// Convert models to simple array",
"$",
"elements",
"=",
"array_map",
"(",
"function",
"(",
"Element",
"$",
"element",
")",
"{",
"// Don't need the key as an attribute because of the dictionary conversion",
"$",
"ar",
"=",
"array_except",
"(",
"$",
"element",
"->",
"toArray",
"(",
")",
",",
"[",
"'key'",
"]",
")",
";",
"// Restore relationships",
"$",
"ar",
"[",
"'images'",
"]",
"=",
"$",
"element",
"->",
"images",
";",
"return",
"$",
"ar",
";",
"// .. from a dictionary of ALL elements for the locale",
"}",
",",
"$",
"query",
"->",
"get",
"(",
")",
"->",
"getDictionary",
"(",
")",
")",
";",
"// Store the keys of all these elements so we can keep track of which",
"// Elements \"exist\"",
"$",
"this",
"->",
"updated_items",
"=",
"array_keys",
"(",
"$",
"elements",
")",
";",
"// Return the elements",
"return",
"$",
"elements",
";",
"}"
] | Get admin overrides to Elements from the databse
@return array | [
"Get",
"admin",
"overrides",
"to",
"Elements",
"from",
"the",
"databse"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L392-L420 |
30,693 | BKWLD/decoy | classes/Collections/Elements.php | Elements.loadConfig | protected function loadConfig()
{
// Start with empty config
$this->config = [];
// Build a lit of all the paths
$dir = config_path('decoy').'/';
$files = [];
if (is_readable($dir.'elements.yaml')) {
$files[] = $dir.'elements.yaml';
}
if (is_dir($dir.'elements')) {
$files = array_merge($files, glob($dir.'elements/*.yaml'));
}
if (!count($files)) {
return;
}
// Loop though config files and merge them together
foreach ($files as $file) {
// If an array found ...
if (($config = Yaml::parse(file_get_contents($file)))
&& is_array($config)) {
// Merge it in
$this->config = array_replace_recursive($this->config, $config);
}
}
} | php | protected function loadConfig()
{
// Start with empty config
$this->config = [];
// Build a lit of all the paths
$dir = config_path('decoy').'/';
$files = [];
if (is_readable($dir.'elements.yaml')) {
$files[] = $dir.'elements.yaml';
}
if (is_dir($dir.'elements')) {
$files = array_merge($files, glob($dir.'elements/*.yaml'));
}
if (!count($files)) {
return;
}
// Loop though config files and merge them together
foreach ($files as $file) {
// If an array found ...
if (($config = Yaml::parse(file_get_contents($file)))
&& is_array($config)) {
// Merge it in
$this->config = array_replace_recursive($this->config, $config);
}
}
} | [
"protected",
"function",
"loadConfig",
"(",
")",
"{",
"// Start with empty config",
"$",
"this",
"->",
"config",
"=",
"[",
"]",
";",
"// Build a lit of all the paths",
"$",
"dir",
"=",
"config_path",
"(",
"'decoy'",
")",
".",
"'/'",
";",
"$",
"files",
"=",
"[",
"]",
";",
"if",
"(",
"is_readable",
"(",
"$",
"dir",
".",
"'elements.yaml'",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"dir",
".",
"'elements.yaml'",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
".",
"'elements'",
")",
")",
"{",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"glob",
"(",
"$",
"dir",
".",
"'elements/*.yaml'",
")",
")",
";",
"}",
"if",
"(",
"!",
"count",
"(",
"$",
"files",
")",
")",
"{",
"return",
";",
"}",
"// Loop though config files and merge them together",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"// If an array found ...",
"if",
"(",
"(",
"$",
"config",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
")",
"&&",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"// Merge it in",
"$",
"this",
"->",
"config",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"config",
")",
";",
"}",
"}",
"}"
] | Load the config file and store it internally
@return void | [
"Load",
"the",
"config",
"file",
"and",
"store",
"it",
"internally"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L441-L470 |
30,694 | BKWLD/decoy | classes/Collections/Elements.php | Elements.keyUpdated | public function keyUpdated($key)
{
if ($this->updated_items === null) {
$this->assocAdminChoices();
}
return in_array($key, $this->updated_items);
} | php | public function keyUpdated($key)
{
if ($this->updated_items === null) {
$this->assocAdminChoices();
}
return in_array($key, $this->updated_items);
} | [
"public",
"function",
"keyUpdated",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"updated_items",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"assocAdminChoices",
"(",
")",
";",
"}",
"return",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"updated_items",
")",
";",
"}"
] | Check if a key has been stored in the database
@param string $key The key of an element
@return boolean | [
"Check",
"if",
"a",
"key",
"has",
"been",
"stored",
"in",
"the",
"database"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L478-L485 |
30,695 | BKWLD/decoy | classes/Collections/Elements.php | Elements.onlyPages | public function onlyPages($pages)
{
$this->items = array_filter($this->items, function ($element) use ($pages) {
return in_array(Str::slug($element['page_label']), $pages);
});
return $this;
} | php | public function onlyPages($pages)
{
$this->items = array_filter($this->items, function ($element) use ($pages) {
return in_array(Str::slug($element['page_label']), $pages);
});
return $this;
} | [
"public",
"function",
"onlyPages",
"(",
"$",
"pages",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"items",
",",
"function",
"(",
"$",
"element",
")",
"use",
"(",
"$",
"pages",
")",
"{",
"return",
"in_array",
"(",
"Str",
"::",
"slug",
"(",
"$",
"element",
"[",
"'page_label'",
"]",
")",
",",
"$",
"pages",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Filter the elements to only those allowed in the provided pages
@param array $pages
@return $this | [
"Filter",
"the",
"elements",
"to",
"only",
"those",
"allowed",
"in",
"the",
"provided",
"pages"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L493-L500 |
30,696 | BKWLD/decoy | classes/Collections/Elements.php | Elements.rules | public function rules()
{
$rules = [];
foreach ($this->assocConfig(true) as $key => $data) {
if (empty($data['rules'])) {
continue;
}
$rules[str_replace('.', '|', $key)] = $data['rules'];
}
return $rules;
} | php | public function rules()
{
$rules = [];
foreach ($this->assocConfig(true) as $key => $data) {
if (empty($data['rules'])) {
continue;
}
$rules[str_replace('.', '|', $key)] = $data['rules'];
}
return $rules;
} | [
"public",
"function",
"rules",
"(",
")",
"{",
"$",
"rules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"assocConfig",
"(",
"true",
")",
"as",
"$",
"key",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"'rules'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"rules",
"[",
"str_replace",
"(",
"'.'",
",",
"'|'",
",",
"$",
"key",
")",
"]",
"=",
"$",
"data",
"[",
"'rules'",
"]",
";",
"}",
"return",
"$",
"rules",
";",
"}"
] | Return the validation rules for the items. Convert the keys to the
expected input style
@return array An array of validation rules, keyed to element keys | [
"Return",
"the",
"validation",
"rules",
"for",
"the",
"items",
".",
"Convert",
"the",
"keys",
"to",
"the",
"expected",
"input",
"style"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L508-L519 |
30,697 | BKWLD/decoy | classes/Collections/Elements.php | Elements.populate | public function populate()
{
return array_combine(array_map(function ($key) {
return str_replace('.', '|', $key);
}, $this->keys()->all()), $this->pluck('value')->all());
} | php | public function populate()
{
return array_combine(array_map(function ($key) {
return str_replace('.', '|', $key);
}, $this->keys()->all()), $this->pluck('value')->all());
} | [
"public",
"function",
"populate",
"(",
")",
"{",
"return",
"array_combine",
"(",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"{",
"return",
"str_replace",
"(",
"'.'",
",",
"'|'",
",",
"$",
"key",
")",
";",
"}",
",",
"$",
"this",
"->",
"keys",
"(",
")",
"->",
"all",
"(",
")",
")",
",",
"$",
"this",
"->",
"pluck",
"(",
"'value'",
")",
"->",
"all",
"(",
")",
")",
";",
"}"
] | Return key-value pairs for use by former to populate the fields. The
keys must be converted to the Input safe variant.
@return array | [
"Return",
"key",
"-",
"value",
"pairs",
"for",
"use",
"by",
"former",
"to",
"populate",
"the",
"fields",
".",
"The",
"keys",
"must",
"be",
"converted",
"to",
"the",
"Input",
"safe",
"variant",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Collections/Elements.php#L527-L532 |
30,698 | BKWLD/decoy | classes/Fields/Upload.php | Upload.render | public function render()
{
// A file has already been uploaded
if ($this->value) {
// If it's required, show the icon but don't enforce it. There is already
// a file uploaded after all
if ($this->isRequired()) {
$this->setAttribute('required', null);
}
}
// Continue execution
return parent::render();
} | php | public function render()
{
// A file has already been uploaded
if ($this->value) {
// If it's required, show the icon but don't enforce it. There is already
// a file uploaded after all
if ($this->isRequired()) {
$this->setAttribute('required', null);
}
}
// Continue execution
return parent::render();
} | [
"public",
"function",
"render",
"(",
")",
"{",
"// A file has already been uploaded",
"if",
"(",
"$",
"this",
"->",
"value",
")",
"{",
"// If it's required, show the icon but don't enforce it. There is already",
"// a file uploaded after all",
"if",
"(",
"$",
"this",
"->",
"isRequired",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"'required'",
",",
"null",
")",
";",
"}",
"}",
"// Continue execution",
"return",
"parent",
"::",
"render",
"(",
")",
";",
"}"
] | Prints out the current file upload field.
@return string An input tag | [
"Prints",
"out",
"the",
"current",
"file",
"upload",
"field",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Upload.php#L57-L71 |
30,699 | BKWLD/decoy | classes/Observers/ManyToManyChecklist.php | ManyToManyChecklist.handle | public function handle($event, $payload)
{
list($model) = $payload;
// Check for matching input elements
foreach (Request::input() as $key => $val) {
if (preg_match('#^'.self::PREFIX.'(.+)#', $key, $matches)) {
$this->updateRelationship($model, $matches[1]);
}
}
} | php | public function handle($event, $payload)
{
list($model) = $payload;
// Check for matching input elements
foreach (Request::input() as $key => $val) {
if (preg_match('#^'.self::PREFIX.'(.+)#', $key, $matches)) {
$this->updateRelationship($model, $matches[1]);
}
}
} | [
"public",
"function",
"handle",
"(",
"$",
"event",
",",
"$",
"payload",
")",
"{",
"list",
"(",
"$",
"model",
")",
"=",
"$",
"payload",
";",
"// Check for matching input elements",
"foreach",
"(",
"Request",
"::",
"input",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#^'",
".",
"self",
"::",
"PREFIX",
".",
"'(.+)#'",
",",
"$",
"key",
",",
"$",
"matches",
")",
")",
"{",
"$",
"this",
"->",
"updateRelationship",
"(",
"$",
"model",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}"
] | Take input from a Many to Many Checklist and commit it to the db. Called
on model saved.
@param string $event
@param array $payload Contains:
- Bkwld\Decoy\Models\Base $model
@return void | [
"Take",
"input",
"from",
"a",
"Many",
"to",
"Many",
"Checklist",
"and",
"commit",
"it",
"to",
"the",
"db",
".",
"Called",
"on",
"model",
"saved",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/ManyToManyChecklist.php#L28-L38 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.