repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
BKWLD/decoy | classes/Controllers/Traits/Exportable.php | Exportable.makeCsvFileTitle | protected function makeCsvFileTitle()
{
return vsprintf('%s %s as of %s at %s.csv', [
Decoy::site(),
$this->title(),
Carbon::now()->format('n.j.y'),
Carbon::now()->format('g:i A'),
]);
} | php | protected function makeCsvFileTitle()
{
return vsprintf('%s %s as of %s at %s.csv', [
Decoy::site(),
$this->title(),
Carbon::now()->format('n.j.y'),
Carbon::now()->format('g:i A'),
]);
} | [
"protected",
"function",
"makeCsvFileTitle",
"(",
")",
"{",
"return",
"vsprintf",
"(",
"'%s %s as of %s at %s.csv'",
",",
"[",
"Decoy",
"::",
"site",
"(",
")",
",",
"$",
"this",
"->",
"title",
"(",
")",
",",
"Carbon",
"::",
"now",
"(",
")",
"->",
"format... | Make the title of the CSV
@return string | [
"Make",
"the",
"title",
"of",
"the",
"CSV"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Traits/Exportable.php#L86-L94 | train |
BKWLD/decoy | classes/Observers/Encoding.php | Encoding.onSaving | public function onSaving($event, $payload)
{
list($model) = $payload;
if (!$this->isEncodable($model)) {
return;
}
foreach ($model->getDirtyEncodableAttributes() as $attribute) {
// If the attribute has a value, encode the attribute
if ($model->getAttribute($attribute)) {
$model->encodeOnSave($attribute);
}
// Otherwise delete encoding references
elseif ($encoding = $model->encoding($attribute)) {
$encoding->delete();
}
}
} | php | public function onSaving($event, $payload)
{
list($model) = $payload;
if (!$this->isEncodable($model)) {
return;
}
foreach ($model->getDirtyEncodableAttributes() as $attribute) {
// If the attribute has a value, encode the attribute
if ($model->getAttribute($attribute)) {
$model->encodeOnSave($attribute);
}
// Otherwise delete encoding references
elseif ($encoding = $model->encoding($attribute)) {
$encoding->delete();
}
}
} | [
"public",
"function",
"onSaving",
"(",
"$",
"event",
",",
"$",
"payload",
")",
"{",
"list",
"(",
"$",
"model",
")",
"=",
"$",
"payload",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isEncodable",
"(",
"$",
"model",
")",
")",
"{",
"return",
";",
"}",
... | Start a new encode if a new encodable file was uploaded
@param string $event
@param array $payload Contains:
- Bkwld\Decoy\Models\Base $model
@return void | [
"Start",
"a",
"new",
"encode",
"if",
"a",
"new",
"encodable",
"file",
"was",
"uploaded"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/Encoding.php#L18-L38 | train |
BKWLD/decoy | classes/Observers/Encoding.php | Encoding.isEncodable | public function isEncodable($model)
{
if (!method_exists($model, 'getDirtyEncodableAttributes')) {
return false;
}
if (is_a($model, 'Bkwld\Decoy\Models\Element') && $model->getAttribute('type') != 'video-encoder') {
return false;
}
return true;
} | php | public function isEncodable($model)
{
if (!method_exists($model, 'getDirtyEncodableAttributes')) {
return false;
}
if (is_a($model, 'Bkwld\Decoy\Models\Element') && $model->getAttribute('type') != 'video-encoder') {
return false;
}
return true;
} | [
"public",
"function",
"isEncodable",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"model",
",",
"'getDirtyEncodableAttributes'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_a",
"(",
"$",
"model",
",",
"'Bkwld\\De... | Check if a model should be encoded
@param Bkwld\Decoy\Models\Base $model
@return boolean | [
"Check",
"if",
"a",
"model",
"should",
"be",
"encoded"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/Encoding.php#L62-L73 | train |
BKWLD/decoy | classes/Observers/Localize.php | Localize.handle | public function handle($event, $payload)
{
list($model) = $payload;
if (!empty($model->locale)
&& empty($model->locale_group)
&& !is_a($model, Element::class) // Elements don't have groups
&& ($locales = Config::get('decoy.site.locales'))
&& count($locales) > 1) {
$model->setAttribute('locale_group', Str::random());
}
} | php | public function handle($event, $payload)
{
list($model) = $payload;
if (!empty($model->locale)
&& empty($model->locale_group)
&& !is_a($model, Element::class) // Elements don't have groups
&& ($locales = Config::get('decoy.site.locales'))
&& count($locales) > 1) {
$model->setAttribute('locale_group', Str::random());
}
} | [
"public",
"function",
"handle",
"(",
"$",
"event",
",",
"$",
"payload",
")",
"{",
"list",
"(",
"$",
"model",
")",
"=",
"$",
"payload",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"model",
"->",
"locale",
")",
"&&",
"empty",
"(",
"$",
"model",
"->",
... | Called on model saving
@param string $event
@param array $payload Contains:
- Bkwld\Decoy\Models\Base $model
@return void | [
"Called",
"on",
"model",
"saving"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/Localize.php#L23-L34 | train |
BKWLD/decoy | classes/Middleware/Auth.php | Auth.dectectFromExplicitRoute | protected function dectectFromExplicitRoute()
{
// Get the action
$action = Route::current()->getActionName();
if ($action == 'Closure') {
throw new \Exception('decoy.auth requires routing to controllers.');
}
// Get parse the `uses` from the route definition
preg_match('#(.+)@(.+)#', Route::current()->getActionName(), $matches);
$controller = $matches[1];
$action = $matches[2];
// Further mapping of the action
$action = $this->mapActionToPermission($action);
// Return the detected action and controller
return [$action, $controller];
} | php | protected function dectectFromExplicitRoute()
{
// Get the action
$action = Route::current()->getActionName();
if ($action == 'Closure') {
throw new \Exception('decoy.auth requires routing to controllers.');
}
// Get parse the `uses` from the route definition
preg_match('#(.+)@(.+)#', Route::current()->getActionName(), $matches);
$controller = $matches[1];
$action = $matches[2];
// Further mapping of the action
$action = $this->mapActionToPermission($action);
// Return the detected action and controller
return [$action, $controller];
} | [
"protected",
"function",
"dectectFromExplicitRoute",
"(",
")",
"{",
"// Get the action",
"$",
"action",
"=",
"Route",
"::",
"current",
"(",
")",
"->",
"getActionName",
"(",
")",
";",
"if",
"(",
"$",
"action",
"==",
"'Closure'",
")",
"{",
"throw",
"new",
"\... | Get the action and controller from an explicilty defined route
@return array action,controller
@throws Exception | [
"Get",
"the",
"action",
"and",
"controller",
"from",
"an",
"explicilty",
"defined",
"route"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Auth.php#L57-L75 | train |
BKWLD/decoy | classes/Middleware/Auth.php | Auth.dectectFromWildcardRouter | protected function dectectFromWildcardRouter()
{
$wildcard = App::make('decoy.wildcard');
// Attach / detach are ACL-ed by the parent controller. It's the one being
// touched,
$action = $wildcard->detectAction();
if (in_array($action, ['attach', 'remove'])) {
$controller = request('parent_controller');
$action = 'update';
// Otherwise, use the controller from the route
} else {
$controller = $wildcard->detectControllerName();
}
// Further mapping of the action
$action = $this->mapActionToPermission($action);
// Return the detected action and controller
return [$action, $controller];
} | php | protected function dectectFromWildcardRouter()
{
$wildcard = App::make('decoy.wildcard');
// Attach / detach are ACL-ed by the parent controller. It's the one being
// touched,
$action = $wildcard->detectAction();
if (in_array($action, ['attach', 'remove'])) {
$controller = request('parent_controller');
$action = 'update';
// Otherwise, use the controller from the route
} else {
$controller = $wildcard->detectControllerName();
}
// Further mapping of the action
$action = $this->mapActionToPermission($action);
// Return the detected action and controller
return [$action, $controller];
} | [
"protected",
"function",
"dectectFromWildcardRouter",
"(",
")",
"{",
"$",
"wildcard",
"=",
"App",
"::",
"make",
"(",
"'decoy.wildcard'",
")",
";",
"// Attach / detach are ACL-ed by the parent controller. It's the one being",
"// touched,",
"$",
"action",
"=",
"$",
"wildc... | Get the action and controller from the wildcard router
@return array action,controller | [
"Get",
"the",
"action",
"and",
"controller",
"from",
"the",
"wildcard",
"router"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Auth.php#L82-L103 | train |
BKWLD/decoy | classes/Models/Admin.php | Admin.onValidating | public function onValidating($validation)
{
// Only apply mods when editing an existing record
if (!$this->exists) {
return;
}
$rules = self::$rules;
// Make password optional
$rules = array_except($rules, 'password');
// Ignore the current record when validating email
$rules['email'] .= ','.$this->id;
// Update rules
$validation->setRules($rules);
} | php | public function onValidating($validation)
{
// Only apply mods when editing an existing record
if (!$this->exists) {
return;
}
$rules = self::$rules;
// Make password optional
$rules = array_except($rules, 'password');
// Ignore the current record when validating email
$rules['email'] .= ','.$this->id;
// Update rules
$validation->setRules($rules);
} | [
"public",
"function",
"onValidating",
"(",
"$",
"validation",
")",
"{",
"// Only apply mods when editing an existing record",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
")",
"{",
"return",
";",
"}",
"$",
"rules",
"=",
"self",
"::",
"$",
"rules",
";",
"// M... | Tweak some validation rules
@param Illuminate\Validation\Validator $validation | [
"Tweak",
"some",
"validation",
"rules"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L84-L101 | train |
BKWLD/decoy | classes/Models/Admin.php | Admin.onCreating | public function onCreating()
{
// Send out email
if (Request::has('_send_email')) {
$this->sendCreateEmail();
}
// Make them active
$this->active = 1;
// If the current user can't grant permissions, make the new admin
// have the same role as themselves. Admins created from the CLI (like as
// part of a migration) won't be logged in.
if (($admin = app('decoy.user'))
&& !app('decoy.user')->can('grant', 'admins')) {
$this->role = $admin->role;
// Otherwise, give the admin a default role if none was defined
} elseif (empty($this->role)) {
$this->role = 'admin';
}
} | php | public function onCreating()
{
// Send out email
if (Request::has('_send_email')) {
$this->sendCreateEmail();
}
// Make them active
$this->active = 1;
// If the current user can't grant permissions, make the new admin
// have the same role as themselves. Admins created from the CLI (like as
// part of a migration) won't be logged in.
if (($admin = app('decoy.user'))
&& !app('decoy.user')->can('grant', 'admins')) {
$this->role = $admin->role;
// Otherwise, give the admin a default role if none was defined
} elseif (empty($this->role)) {
$this->role = 'admin';
}
} | [
"public",
"function",
"onCreating",
"(",
")",
"{",
"// Send out email",
"if",
"(",
"Request",
"::",
"has",
"(",
"'_send_email'",
")",
")",
"{",
"$",
"this",
"->",
"sendCreateEmail",
"(",
")",
";",
"}",
"// Make them active",
"$",
"this",
"->",
"active",
"=... | New admin callbacks
@return void | [
"New",
"admin",
"callbacks"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L108-L129 | train |
BKWLD/decoy | classes/Models/Admin.php | Admin.onSaving | public function onSaving()
{
// If the password is changing, hash it
if ($this->isDirty('password')) {
$this->password = bcrypt($this->password);
}
// Save or clear permission choices if the form had a "custom permissions"
// pushed checkbox
if (Request::exists('_custom_permissions')) {
$this->permissions = request('_custom_permissions') ?
json_encode(request('_permission')) : null;
}
} | php | public function onSaving()
{
// If the password is changing, hash it
if ($this->isDirty('password')) {
$this->password = bcrypt($this->password);
}
// Save or clear permission choices if the form had a "custom permissions"
// pushed checkbox
if (Request::exists('_custom_permissions')) {
$this->permissions = request('_custom_permissions') ?
json_encode(request('_permission')) : null;
}
} | [
"public",
"function",
"onSaving",
"(",
")",
"{",
"// If the password is changing, hash it",
"if",
"(",
"$",
"this",
"->",
"isDirty",
"(",
"'password'",
")",
")",
"{",
"$",
"this",
"->",
"password",
"=",
"bcrypt",
"(",
"$",
"this",
"->",
"password",
")",
";... | Callbacks regardless of new or old
@return void | [
"Callbacks",
"regardless",
"of",
"new",
"or",
"old"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L148-L161 | train |
BKWLD/decoy | classes/Models/Admin.php | Admin.sendUpdateEmail | public function sendUpdateEmail()
{
// Prepare data for mail
$admin = app('decoy.user');
$email = [
'editor_first_name' => $admin->first_name,
'editor_last_name' => $admin->last_name,
'first_name' =>request('first_name'),
'last_name' =>request('last_name'),
'email' => request('email'),
'password' =>request('password'),
'url' => Request::root().'/'.Config::get('decoy.core.dir'),
'root' => Request::root(),
];
// Send the email
Mail::send('decoy::emails.update', $email, function ($m) use ($email) {
$m->to($email['email'], $email['first_name'].' '.$email['last_name']);
$m->subject('Your '.Decoy::site().' admin account info has been updated');
});
} | php | public function sendUpdateEmail()
{
// Prepare data for mail
$admin = app('decoy.user');
$email = [
'editor_first_name' => $admin->first_name,
'editor_last_name' => $admin->last_name,
'first_name' =>request('first_name'),
'last_name' =>request('last_name'),
'email' => request('email'),
'password' =>request('password'),
'url' => Request::root().'/'.Config::get('decoy.core.dir'),
'root' => Request::root(),
];
// Send the email
Mail::send('decoy::emails.update', $email, function ($m) use ($email) {
$m->to($email['email'], $email['first_name'].' '.$email['last_name']);
$m->subject('Your '.Decoy::site().' admin account info has been updated');
});
} | [
"public",
"function",
"sendUpdateEmail",
"(",
")",
"{",
"// Prepare data for mail",
"$",
"admin",
"=",
"app",
"(",
"'decoy.user'",
")",
";",
"$",
"email",
"=",
"[",
"'editor_first_name'",
"=>",
"$",
"admin",
"->",
"first_name",
",",
"'editor_last_name'",
"=>",
... | Send update email
@return void | [
"Send",
"update",
"email"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L193-L213 | train |
BKWLD/decoy | classes/Models/Admin.php | Admin.shouldLogChange | public function shouldLogChange($action)
{
if ($action != 'deleted'
&& count($this->getDirty()) == 1
&& $this->isDirty('remember_token')) {
return false;
}
return parent::shouldLogChange($action);
} | php | public function shouldLogChange($action)
{
if ($action != 'deleted'
&& count($this->getDirty()) == 1
&& $this->isDirty('remember_token')) {
return false;
}
return parent::shouldLogChange($action);
} | [
"public",
"function",
"shouldLogChange",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"action",
"!=",
"'deleted'",
"&&",
"count",
"(",
"$",
"this",
"->",
"getDirty",
"(",
")",
")",
"==",
"1",
"&&",
"$",
"this",
"->",
"isDirty",
"(",
"'remember_token'"... | Don't log if admin is logging in and out
@param string $action
@return boolean | [
"Don",
"t",
"log",
"if",
"admin",
"is",
"logging",
"in",
"and",
"out"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L259-L267 | train |
BKWLD/decoy | classes/Models/Admin.php | Admin.getAdminStatusAttribute | public function getAdminStatusAttribute()
{
$html ='';
// Add the role
if (($roles = static::getRoleTitles()) && count($roles)) {
$html .= '<span class="label label-primary">'.$roles[$this->role].'</span>';
}
// If row is you
if ($this->id == app('decoy.user')->id) {
$html .= '<span class="label label-info">' . __('decoy::admins.standard_list.you') . '</span>';
}
// If row is disabled
if ($this->disabled()) {
$html .= '<a href="' . URL::to(DecoyURL::relative('enable', $this->id)) . '" class="label label-warning
js-tooltip" title="' . __('decoy::admins.standard_list.click') . '">' .
__('decoy::admins.standard_list.disabled') . '</a>';
}
// Return HTML
return $html;
} | php | public function getAdminStatusAttribute()
{
$html ='';
// Add the role
if (($roles = static::getRoleTitles()) && count($roles)) {
$html .= '<span class="label label-primary">'.$roles[$this->role].'</span>';
}
// If row is you
if ($this->id == app('decoy.user')->id) {
$html .= '<span class="label label-info">' . __('decoy::admins.standard_list.you') . '</span>';
}
// If row is disabled
if ($this->disabled()) {
$html .= '<a href="' . URL::to(DecoyURL::relative('enable', $this->id)) . '" class="label label-warning
js-tooltip" title="' . __('decoy::admins.standard_list.click') . '">' .
__('decoy::admins.standard_list.disabled') . '</a>';
}
// Return HTML
return $html;
} | [
"public",
"function",
"getAdminStatusAttribute",
"(",
")",
"{",
"$",
"html",
"=",
"''",
";",
"// Add the role",
"if",
"(",
"(",
"$",
"roles",
"=",
"static",
"::",
"getRoleTitles",
"(",
")",
")",
"&&",
"count",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"... | Show a badge if the user is the currently logged in
@return string | [
"Show",
"a",
"badge",
"if",
"the",
"user",
"is",
"the",
"currently",
"logged",
"in"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L319-L342 | train |
BKWLD/decoy | classes/Models/Admin.php | Admin.getPermissionOptions | public static function getPermissionOptions($admin = null)
{
// Get all the app controllers
$controllers = array_map(function($path) {
return 'App\Http\Controllers\Admin\\'.basename($path, '.php');
}, glob(app_path('/Http/Controllers/Admin/*.php')));
// Add some Decoy controllers
$controllers[] = 'Bkwld\Decoy\Controllers\Admins';
$controllers[] = 'Bkwld\Decoy\Controllers\Changes';
$controllers[] = 'Bkwld\Decoy\Controllers\Elements';
$controllers[] = 'Bkwld\Decoy\Controllers\RedirectRules';
// Alphabetize the controller classes
usort($controllers, function ($a, $b) {
return substr($a, strrpos($a, '\\') + 1) > substr($b, strrpos($b, '\\') + 1);
});
// Convert the list of controller classes into the shorthand strings used
// by Decoy Auth as well as english name and desciption
return array_map(function ($class) use ($admin) {
$obj = new $class;
$permissions = $obj->getPermissionOptions();
if (!is_array($permissions)) {
$permissions = [];
}
// Build the controller-level node
return (object) [
// Add controller information
'slug' => DecoyURL::slugController($class),
'title' => $obj->title(),
'description' => $obj->description(),
// Add permission options for the controller
'permissions' => array_map(function ($value, $action) use ($class, $admin) {
$roles = array_keys(Config::get('decoy.site.roles'));
return (object) [
'slug' => $action,
'title' => is_array($value) ? $value[0] : Text::titleFromKey($action),
'description' => is_array($value) ? $value[1] : $value,
// Set the initial checked state based on the admin's permissions, if
// one is set. Or based on the first role.
'checked' => $admin ?
$admin->can($action, $class) :
with(new Admin(['role' => $roles[0]]))->can($action, $class),
// Filter the list of roles to just the roles that allow the
// permission currently being iterated through
'roles' => array_filter($roles, function ($role) use ($action, $class) {
return with(new Admin(['role' => $role]))->can($action, $class);
}),
];
}, $permissions, array_keys($permissions)),
];
}, $controllers);
} | php | public static function getPermissionOptions($admin = null)
{
// Get all the app controllers
$controllers = array_map(function($path) {
return 'App\Http\Controllers\Admin\\'.basename($path, '.php');
}, glob(app_path('/Http/Controllers/Admin/*.php')));
// Add some Decoy controllers
$controllers[] = 'Bkwld\Decoy\Controllers\Admins';
$controllers[] = 'Bkwld\Decoy\Controllers\Changes';
$controllers[] = 'Bkwld\Decoy\Controllers\Elements';
$controllers[] = 'Bkwld\Decoy\Controllers\RedirectRules';
// Alphabetize the controller classes
usort($controllers, function ($a, $b) {
return substr($a, strrpos($a, '\\') + 1) > substr($b, strrpos($b, '\\') + 1);
});
// Convert the list of controller classes into the shorthand strings used
// by Decoy Auth as well as english name and desciption
return array_map(function ($class) use ($admin) {
$obj = new $class;
$permissions = $obj->getPermissionOptions();
if (!is_array($permissions)) {
$permissions = [];
}
// Build the controller-level node
return (object) [
// Add controller information
'slug' => DecoyURL::slugController($class),
'title' => $obj->title(),
'description' => $obj->description(),
// Add permission options for the controller
'permissions' => array_map(function ($value, $action) use ($class, $admin) {
$roles = array_keys(Config::get('decoy.site.roles'));
return (object) [
'slug' => $action,
'title' => is_array($value) ? $value[0] : Text::titleFromKey($action),
'description' => is_array($value) ? $value[1] : $value,
// Set the initial checked state based on the admin's permissions, if
// one is set. Or based on the first role.
'checked' => $admin ?
$admin->can($action, $class) :
with(new Admin(['role' => $roles[0]]))->can($action, $class),
// Filter the list of roles to just the roles that allow the
// permission currently being iterated through
'roles' => array_filter($roles, function ($role) use ($action, $class) {
return with(new Admin(['role' => $role]))->can($action, $class);
}),
];
}, $permissions, array_keys($permissions)),
];
}, $controllers);
} | [
"public",
"static",
"function",
"getPermissionOptions",
"(",
"$",
"admin",
"=",
"null",
")",
"{",
"// Get all the app controllers",
"$",
"controllers",
"=",
"array_map",
"(",
"function",
"(",
"$",
"path",
")",
"{",
"return",
"'App\\Http\\Controllers\\Admin\\\\'",
".... | Get the list of all permissions
@param Admin|null $admin
@return array | [
"Get",
"the",
"list",
"of",
"all",
"permissions"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Admin.php#L391-L451 | train |
BKWLD/decoy | classes/Models/Traits/SerializeWithImages.php | SerializeWithImages.withDefaultImage | public function withDefaultImage(
$width = null,
$height = null,
$options = null)
{
$this->withRenamedImage(null, null, $width, $height, $options);
return $this;
} | php | public function withDefaultImage(
$width = null,
$height = null,
$options = null)
{
$this->withRenamedImage(null, null, $width, $height, $options);
return $this;
} | [
"public",
"function",
"withDefaultImage",
"(",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"withRenamedImage",
"(",
"null",
",",
"null",
",",
"$",
"width",
",",
"$",
"heig... | Convenience method for adding the default, null, named image crop
@param integer $width
@param integer $height
@param array $options
@return $this | [
"Convenience",
"method",
"for",
"adding",
"the",
"default",
"null",
"named",
"image",
"crop"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L24-L32 | train |
BKWLD/decoy | classes/Models/Traits/SerializeWithImages.php | SerializeWithImages.withImage | public function withImage(
$name = null,
$width = null,
$height = null,
$options = null)
{
$this->withRenamedImage($name, $name, $width, $height, $options);
return $this;
} | php | public function withImage(
$name = null,
$width = null,
$height = null,
$options = null)
{
$this->withRenamedImage($name, $name, $width, $height, $options);
return $this;
} | [
"public",
"function",
"withImage",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"withRenamedImage",
"(",
"$",
"name",
",",
"$",
"name"... | Convenience method for specifying the name of the image to add
@param string $name
@param integer $width
@param integer $height
@param array $options
@return $this | [
"Convenience",
"method",
"for",
"specifying",
"the",
"name",
"of",
"the",
"image",
"to",
"add"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L43-L52 | train |
BKWLD/decoy | classes/Models/Traits/SerializeWithImages.php | SerializeWithImages.withRenamedImage | public function withRenamedImage(
$name = null,
$property = null,
$width = null,
$height = null,
$options = null)
{
// The json needs a property name
if (empty($property)) {
$property = 'default';
}
// Add a transform that adds and whitelisted the attribute as named
$this->serializeTransform(function (Model $model) use (
$name, $property, $width, $height, $options) {
// Make sure that the model uses the HasImages trait
if (!method_exists($model, 'img')) {
throw new Exception(get_class($model).' needs HasImages trait');
}
// Prepare for future applying
$transforming_model = $model;
$models = [$model];
// If the name contains a period, treat it as dot notation to get at an
// image on a related model
if (strpos($name, '.') > -1) {
$relations = explode('.', $name);
// If the name and property are identical, use just the image name for
// the property.
if ($name == $property) {
$name = $property = array_pop($relations);
} else {
$name = array_pop($relations);
}
// If the name is "default", look for it with a NULL name
if ($name == 'default') {
$name = null;
}
// Step through the relationship chain until we have an array of all
// of the children models.
foreach ($relations as $relation) {
$models = $this->getRelatedModelsWithImages($models, $relation);
}
}
// For each model that shoudl be touched, append the named image to it's
// `imgs` attribute, keyed by $proprety
foreach ($models as $model) {
$image = $model->img($name)->crop($width, $height, $options);
$model->appendToImgs($image, $property);
}
// Return the model being transformed
return $transforming_model;
});
// Support chaining
return $this;
} | php | public function withRenamedImage(
$name = null,
$property = null,
$width = null,
$height = null,
$options = null)
{
// The json needs a property name
if (empty($property)) {
$property = 'default';
}
// Add a transform that adds and whitelisted the attribute as named
$this->serializeTransform(function (Model $model) use (
$name, $property, $width, $height, $options) {
// Make sure that the model uses the HasImages trait
if (!method_exists($model, 'img')) {
throw new Exception(get_class($model).' needs HasImages trait');
}
// Prepare for future applying
$transforming_model = $model;
$models = [$model];
// If the name contains a period, treat it as dot notation to get at an
// image on a related model
if (strpos($name, '.') > -1) {
$relations = explode('.', $name);
// If the name and property are identical, use just the image name for
// the property.
if ($name == $property) {
$name = $property = array_pop($relations);
} else {
$name = array_pop($relations);
}
// If the name is "default", look for it with a NULL name
if ($name == 'default') {
$name = null;
}
// Step through the relationship chain until we have an array of all
// of the children models.
foreach ($relations as $relation) {
$models = $this->getRelatedModelsWithImages($models, $relation);
}
}
// For each model that shoudl be touched, append the named image to it's
// `imgs` attribute, keyed by $proprety
foreach ($models as $model) {
$image = $model->img($name)->crop($width, $height, $options);
$model->appendToImgs($image, $property);
}
// Return the model being transformed
return $transforming_model;
});
// Support chaining
return $this;
} | [
"public",
"function",
"withRenamedImage",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"property",
"=",
"null",
",",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"// The json needs a property name",
... | Add an Image instance with the provided crop in instructions to every
item in the collection.
@param string $name The `name` attribute to look for in Images
@param string $property The property name to use in the JSON output
@param integer $width
@param integer $height
@param array $options
@return $this
@throws Exception | [
"Add",
"an",
"Image",
"instance",
"with",
"the",
"provided",
"crop",
"in",
"instructions",
"to",
"every",
"item",
"in",
"the",
"collection",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L67-L130 | train |
BKWLD/decoy | classes/Models/Traits/SerializeWithImages.php | SerializeWithImages.getRelatedModelsWithImages | protected function getRelatedModelsWithImages($parents, $relation)
{
$models = [];
foreach ($parents as $parent) {
// Get the related object
$related = $parent->$relation;
// The related object is a model (like in a belongsTo setup), add it to
// the array
if (is_a($related, Model::class)) {
$models[] = $related;
}
// Otherwise, if the relation returns a collection (like a hasMany), add
// all the related models to the growing array.
elseif (is_a($related, Collection::class)) {
$models = array_merge($models, $related->all());
}
}
return $models;
} | php | protected function getRelatedModelsWithImages($parents, $relation)
{
$models = [];
foreach ($parents as $parent) {
// Get the related object
$related = $parent->$relation;
// The related object is a model (like in a belongsTo setup), add it to
// the array
if (is_a($related, Model::class)) {
$models[] = $related;
}
// Otherwise, if the relation returns a collection (like a hasMany), add
// all the related models to the growing array.
elseif (is_a($related, Collection::class)) {
$models = array_merge($models, $related->all());
}
}
return $models;
} | [
"protected",
"function",
"getRelatedModelsWithImages",
"(",
"$",
"parents",
",",
"$",
"relation",
")",
"{",
"$",
"models",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parents",
"as",
"$",
"parent",
")",
"{",
"// Get the related object",
"$",
"related",
"=",
... | Take an array of parent models and return a new array of the children of
all parents in one array
@param array $parents Array of eloquent models
@param string $relation Relation name
@return array | [
"Take",
"an",
"array",
"of",
"parent",
"models",
"and",
"return",
"a",
"new",
"array",
"of",
"the",
"children",
"of",
"all",
"parents",
"in",
"one",
"array"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/SerializeWithImages.php#L140-L162 | train |
BKWLD/decoy | classes/Models/Change.php | Change.log | public static function log(Model $model, $action, Admin $admin = null)
{
// Create a new change instance
if (static::shouldWriteChange($model, $action)) {
$changed = static::getChanged($model, $action);
$change = static::createLog($model, $action, $admin, $changed);
}
// Log published / unpblished changes
static::logPublishingChange($model, $action, $admin);
// If the action was a deletion, mark all of the records for this model as
// deleted
if ($action == 'deleted') {
DB::table('changes')
->where('model', get_class($model))
->where('key', $model->getKey())
->update(['deleted' => 1]);
}
// Return the changed instance
if (isset($change)) {
return $change;
}
} | php | public static function log(Model $model, $action, Admin $admin = null)
{
// Create a new change instance
if (static::shouldWriteChange($model, $action)) {
$changed = static::getChanged($model, $action);
$change = static::createLog($model, $action, $admin, $changed);
}
// Log published / unpblished changes
static::logPublishingChange($model, $action, $admin);
// If the action was a deletion, mark all of the records for this model as
// deleted
if ($action == 'deleted') {
DB::table('changes')
->where('model', get_class($model))
->where('key', $model->getKey())
->update(['deleted' => 1]);
}
// Return the changed instance
if (isset($change)) {
return $change;
}
} | [
"public",
"static",
"function",
"log",
"(",
"Model",
"$",
"model",
",",
"$",
"action",
",",
"Admin",
"$",
"admin",
"=",
"null",
")",
"{",
"// Create a new change instance",
"if",
"(",
"static",
"::",
"shouldWriteChange",
"(",
"$",
"model",
",",
"$",
"actio... | A convenience method for saving a change instance
@param Model $model The model being touched
@param string $action Generally a CRUD verb: "created", "updated", "deleted"
@param Admin $admin The admin acting on the record
@return static|void | [
"A",
"convenience",
"method",
"for",
"saving",
"a",
"change",
"instance"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L96-L120 | train |
BKWLD/decoy | classes/Models/Change.php | Change.shouldWriteChange | static private function shouldWriteChange(Model $model, $action)
{
if (in_array($action, ['created', 'deleted'])) return true;
$changed_attributes = array_keys($model->getDirty());
$ignored = ['updated_at', 'public'];
$loggable = array_diff($changed_attributes, $ignored);
return count($loggable) > 0;
} | php | static private function shouldWriteChange(Model $model, $action)
{
if (in_array($action, ['created', 'deleted'])) return true;
$changed_attributes = array_keys($model->getDirty());
$ignored = ['updated_at', 'public'];
$loggable = array_diff($changed_attributes, $ignored);
return count($loggable) > 0;
} | [
"static",
"private",
"function",
"shouldWriteChange",
"(",
"Model",
"$",
"model",
",",
"$",
"action",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"action",
",",
"[",
"'created'",
",",
"'deleted'",
"]",
")",
")",
"return",
"true",
";",
"$",
"changed_attrib... | Don't log changes when the only thing that changed was the published
state or updated timestamp. We check if there are any attributes
besides these that changed.
@param Model $model The model being touched
@param string $action
@return boolean | [
"Don",
"t",
"log",
"changes",
"when",
"the",
"only",
"thing",
"that",
"changed",
"was",
"the",
"published",
"state",
"or",
"updated",
"timestamp",
".",
"We",
"check",
"if",
"there",
"are",
"any",
"attributes",
"besides",
"these",
"that",
"changed",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L131-L138 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getChanged | static private function getChanged(Model $model, $action)
{
$changed = $model->getDirty();
if ($action == 'deleted' || empty($changed)) {
$changed = null;
}
return $changed;
} | php | static private function getChanged(Model $model, $action)
{
$changed = $model->getDirty();
if ($action == 'deleted' || empty($changed)) {
$changed = null;
}
return $changed;
} | [
"static",
"private",
"function",
"getChanged",
"(",
"Model",
"$",
"model",
",",
"$",
"action",
")",
"{",
"$",
"changed",
"=",
"$",
"model",
"->",
"getDirty",
"(",
")",
";",
"if",
"(",
"$",
"action",
"==",
"'deleted'",
"||",
"empty",
"(",
"$",
"change... | Get the changes attributes
@param Model $model The model being touched
@param string $action
@return array|null | [
"Get",
"the",
"changes",
"attributes"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L147-L154 | train |
BKWLD/decoy | classes/Models/Change.php | Change.createLog | static protected function createLog(
Model $model,
$action,
Admin $admin = null,
$changed = null)
{
return static::create([
'model' => get_class($model),
'key' => $model->getKey(),
'action' => $action,
'title' => static::getModelTitle($model),
'changed' => $changed,
'admin_id' => static::getAdminId($admin),
]);
} | php | static protected function createLog(
Model $model,
$action,
Admin $admin = null,
$changed = null)
{
return static::create([
'model' => get_class($model),
'key' => $model->getKey(),
'action' => $action,
'title' => static::getModelTitle($model),
'changed' => $changed,
'admin_id' => static::getAdminId($admin),
]);
} | [
"static",
"protected",
"function",
"createLog",
"(",
"Model",
"$",
"model",
",",
"$",
"action",
",",
"Admin",
"$",
"admin",
"=",
"null",
",",
"$",
"changed",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"[",
"'model'",
"=>",
"get_cla... | Create a change entry
@param Model $model Th
@param string $action
@param Admin $admin | [
"Create",
"a",
"change",
"entry"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L163-L177 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getAdminId | static protected function getAdminId(Admin $admin = null)
{
if (!$admin) {
$admin = app('decoy.user');
}
return $admin ? $admin->getKey() : null;
} | php | static protected function getAdminId(Admin $admin = null)
{
if (!$admin) {
$admin = app('decoy.user');
}
return $admin ? $admin->getKey() : null;
} | [
"static",
"protected",
"function",
"getAdminId",
"(",
"Admin",
"$",
"admin",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"admin",
")",
"{",
"$",
"admin",
"=",
"app",
"(",
"'decoy.user'",
")",
";",
"}",
"return",
"$",
"admin",
"?",
"$",
"admin",
"->... | Get the admin id
@param Admin $admin
@return integer | [
"Get",
"the",
"admin",
"id"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L197-L203 | train |
BKWLD/decoy | classes/Models/Change.php | Change.logPublishingChange | static public function logPublishingChange(
Model $model,
$action,
Admin $admin = null)
{
if ($model->isDirty('public')) {
if ($model->public) {
static::createLog($model, 'published', $admin);
} else if (!$model->public && $action != 'created') {
static::createLog($model, 'unpublished', $admin);
}
}
} | php | static public function logPublishingChange(
Model $model,
$action,
Admin $admin = null)
{
if ($model->isDirty('public')) {
if ($model->public) {
static::createLog($model, 'published', $admin);
} else if (!$model->public && $action != 'created') {
static::createLog($model, 'unpublished', $admin);
}
}
} | [
"static",
"public",
"function",
"logPublishingChange",
"(",
"Model",
"$",
"model",
",",
"$",
"action",
",",
"Admin",
"$",
"admin",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"isDirty",
"(",
"'public'",
")",
")",
"{",
"if",
"(",
"$",
"model... | Log changes to publishing state. The initial publish should be logged
but not an initil unpublished state.
@param Model $model
@param string $action
@param Admin $admin
@return void | [
"Log",
"changes",
"to",
"publishing",
"state",
".",
"The",
"initial",
"publish",
"should",
"be",
"logged",
"but",
"not",
"an",
"initil",
"unpublished",
"state",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L214-L226 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getAdminTitleHtmlAttribute | public function getAdminTitleHtmlAttribute()
{
return __('decoy::changes.admin_title', [
'admin' => $this->getAdminLinkAttribute(),
'action' => $this->getActionLabelAttribute(),
'model' => $this->getModelNameHtmlAttribute(),
'model_title' => $this->getLinkedTitleAttribute(),
'date' => $this->getDateAttribute()
]);
} | php | public function getAdminTitleHtmlAttribute()
{
return __('decoy::changes.admin_title', [
'admin' => $this->getAdminLinkAttribute(),
'action' => $this->getActionLabelAttribute(),
'model' => $this->getModelNameHtmlAttribute(),
'model_title' => $this->getLinkedTitleAttribute(),
'date' => $this->getDateAttribute()
]);
} | [
"public",
"function",
"getAdminTitleHtmlAttribute",
"(",
")",
"{",
"return",
"__",
"(",
"'decoy::changes.admin_title'",
",",
"[",
"'admin'",
"=>",
"$",
"this",
"->",
"getAdminLinkAttribute",
"(",
")",
",",
"'action'",
"=>",
"$",
"this",
"->",
"getActionLabelAttrib... | Format the the activity like a sentence
@return string HTML | [
"Format",
"the",
"the",
"activity",
"like",
"a",
"sentence"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L257-L266 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getAdminLinkAttribute | public function getAdminLinkAttribute()
{
if ($this->admin_id) {
return sprintf('<a href="%s">%s</a>',
$this->filterUrl(['admin_id' => $this->admin_id]),
$this->admin->getAdminTitleHtmlAttribute());
} else {
return 'Someone';
}
} | php | public function getAdminLinkAttribute()
{
if ($this->admin_id) {
return sprintf('<a href="%s">%s</a>',
$this->filterUrl(['admin_id' => $this->admin_id]),
$this->admin->getAdminTitleHtmlAttribute());
} else {
return 'Someone';
}
} | [
"public",
"function",
"getAdminLinkAttribute",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"admin_id",
")",
"{",
"return",
"sprintf",
"(",
"'<a href=\"%s\">%s</a>'",
",",
"$",
"this",
"->",
"filterUrl",
"(",
"[",
"'admin_id'",
"=>",
"$",
"this",
"->",
"ad... | Get the admin name and link
@return string HTML | [
"Get",
"the",
"admin",
"name",
"and",
"link"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L273-L282 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getActionLabelAttribute | public function getActionLabelAttribute()
{
$map = [
'created' => 'success',
'updated' => 'warning',
'deleted' => 'danger',
'published' => 'info',
'unpublished' => 'default',
];
return sprintf('<a href="%s" class="label label-%s">%s</a>',
$this->filterUrl(['action' => $this->action]),
isset($map[$this->action]) ? $map[$this->action] : 'info',
__("decoy::changes.actions.$this->action"));
} | php | public function getActionLabelAttribute()
{
$map = [
'created' => 'success',
'updated' => 'warning',
'deleted' => 'danger',
'published' => 'info',
'unpublished' => 'default',
];
return sprintf('<a href="%s" class="label label-%s">%s</a>',
$this->filterUrl(['action' => $this->action]),
isset($map[$this->action]) ? $map[$this->action] : 'info',
__("decoy::changes.actions.$this->action"));
} | [
"public",
"function",
"getActionLabelAttribute",
"(",
")",
"{",
"$",
"map",
"=",
"[",
"'created'",
"=>",
"'success'",
",",
"'updated'",
"=>",
"'warning'",
",",
"'deleted'",
"=>",
"'danger'",
",",
"'published'",
"=>",
"'info'",
",",
"'unpublished'",
"=>",
"'def... | Format the activity as a colored label
@return string HTML | [
"Format",
"the",
"activity",
"as",
"a",
"colored",
"label"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L289-L303 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getModelNameHtmlAttribute | public function getModelNameHtmlAttribute()
{
$class = Decoy::controllerForModel($this->model);
// There is not a controller for the model
if (!$class || !class_exists($class)) {
return sprintf('<b><a href="%s">%s</a></b>',
$this->filterUrl(['model' => $this->model]),
preg_replace('#(?<!\ )[A-Z]#', ' $0', $this->model));
}
// There is a corresponding controller class
$controller = new $class;
return sprintf('<b class="js-tooltip" title="%s"><a href="%s">%s</a></b>',
htmlentities($controller->description()),
$this->filterUrl(['model' => $this->model]),
Str::singular($controller->title()));
} | php | public function getModelNameHtmlAttribute()
{
$class = Decoy::controllerForModel($this->model);
// There is not a controller for the model
if (!$class || !class_exists($class)) {
return sprintf('<b><a href="%s">%s</a></b>',
$this->filterUrl(['model' => $this->model]),
preg_replace('#(?<!\ )[A-Z]#', ' $0', $this->model));
}
// There is a corresponding controller class
$controller = new $class;
return sprintf('<b class="js-tooltip" title="%s"><a href="%s">%s</a></b>',
htmlentities($controller->description()),
$this->filterUrl(['model' => $this->model]),
Str::singular($controller->title()));
} | [
"public",
"function",
"getModelNameHtmlAttribute",
"(",
")",
"{",
"$",
"class",
"=",
"Decoy",
"::",
"controllerForModel",
"(",
"$",
"this",
"->",
"model",
")",
";",
"// There is not a controller for the model",
"if",
"(",
"!",
"$",
"class",
"||",
"!",
"class_exi... | Format the model name by translating it through the controllers's defined
title
@return string HTML | [
"Format",
"the",
"model",
"name",
"by",
"translating",
"it",
"through",
"the",
"controllers",
"s",
"defined",
"title"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L311-L328 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getLinkedTitleAttribute | public function getLinkedTitleAttribute()
{
if (!$this->title) return;
return sprintf('<a href="%s">"%s"</a>',
$this->filterUrl(['model' => $this->model, 'key' => $this->key]),
$this->title);
} | php | public function getLinkedTitleAttribute()
{
if (!$this->title) return;
return sprintf('<a href="%s">"%s"</a>',
$this->filterUrl(['model' => $this->model, 'key' => $this->key]),
$this->title);
} | [
"public",
"function",
"getLinkedTitleAttribute",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"title",
")",
"return",
";",
"return",
"sprintf",
"(",
"'<a href=\"%s\">\"%s\"</a>'",
",",
"$",
"this",
"->",
"filterUrl",
"(",
"[",
"'model'",
"=>",
"$",
"t... | Get the title of the model. Perhaps in the future there will be more smarts
here, like generating a link to the edit view
@return string HTML | [
"Get",
"the",
"title",
"of",
"the",
"model",
".",
"Perhaps",
"in",
"the",
"future",
"there",
"will",
"be",
"more",
"smarts",
"here",
"like",
"generating",
"a",
"link",
"to",
"the",
"edit",
"view"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L336-L342 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getDateAttribute | public function getDateAttribute()
{
\Carbon\Carbon::setLocale(Decoy::locale());
return sprintf('<a href="%s" class="js-tooltip" title="%s">%s</a>',
$this->filterUrl(['created_at' => $this->created_at->format('m/d/Y')]),
$this->getHumanDateAttribute(),
$this->created_at->diffForHumans());
} | php | public function getDateAttribute()
{
\Carbon\Carbon::setLocale(Decoy::locale());
return sprintf('<a href="%s" class="js-tooltip" title="%s">%s</a>',
$this->filterUrl(['created_at' => $this->created_at->format('m/d/Y')]),
$this->getHumanDateAttribute(),
$this->created_at->diffForHumans());
} | [
"public",
"function",
"getDateAttribute",
"(",
")",
"{",
"\\",
"Carbon",
"\\",
"Carbon",
"::",
"setLocale",
"(",
"Decoy",
"::",
"locale",
"(",
")",
")",
";",
"return",
"sprintf",
"(",
"'<a href=\"%s\" class=\"js-tooltip\" title=\"%s\">%s</a>'",
",",
"$",
"this",
... | Get the date of the change
@return string HTML | [
"Get",
"the",
"date",
"of",
"the",
"change"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L349-L356 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getFilterActionAttribute | public function getFilterActionAttribute()
{
return sprintf('<a href="%s"
class="glyphicon glyphicon-filter js-tooltip"
title="' . __('decoy::changes.standard_list.filter') . '"
data-placement="left"></a>',
$this->filterUrl(['model' => $this->model, 'key' => $this->key]),
strip_tags($this->getModelNameHtmlAttribute()));
} | php | public function getFilterActionAttribute()
{
return sprintf('<a href="%s"
class="glyphicon glyphicon-filter js-tooltip"
title="' . __('decoy::changes.standard_list.filter') . '"
data-placement="left"></a>',
$this->filterUrl(['model' => $this->model, 'key' => $this->key]),
strip_tags($this->getModelNameHtmlAttribute()));
} | [
"public",
"function",
"getFilterActionAttribute",
"(",
")",
"{",
"return",
"sprintf",
"(",
"'<a href=\"%s\"\n class=\"glyphicon glyphicon-filter js-tooltip\"\n title=\"'",
".",
"__",
"(",
"'decoy::changes.standard_list.filter'",
")",
".",
"'\"\n data-... | Make the preview filter icon
@return string | [
"Make",
"the",
"preview",
"filter",
"icon"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L388-L396 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getChangesActionAttribute | public function getChangesActionAttribute()
{
// If there are changes, add the modal button
if ($this->changed) {
return sprintf('<a href="%s"
class="glyphicon glyphicon-export js-tooltip changes-modal-link"
title="%s" data-placement="left"></a>',
DecoyURL::action('changes@edit', $this->id),
__('decoy::changes.standard_list.view'));
}
// Else, show a disabled button
else {
return sprintf('<span
class="glyphicon glyphicon-export js-tooltip"
title="%s" data-placement="left"></span>', __('decoy::changes.standard_list.no_changed'));
}
} | php | public function getChangesActionAttribute()
{
// If there are changes, add the modal button
if ($this->changed) {
return sprintf('<a href="%s"
class="glyphicon glyphicon-export js-tooltip changes-modal-link"
title="%s" data-placement="left"></a>',
DecoyURL::action('changes@edit', $this->id),
__('decoy::changes.standard_list.view'));
}
// Else, show a disabled button
else {
return sprintf('<span
class="glyphicon glyphicon-export js-tooltip"
title="%s" data-placement="left"></span>', __('decoy::changes.standard_list.no_changed'));
}
} | [
"public",
"function",
"getChangesActionAttribute",
"(",
")",
"{",
"// If there are changes, add the modal button",
"if",
"(",
"$",
"this",
"->",
"changed",
")",
"{",
"return",
"sprintf",
"(",
"'<a href=\"%s\"\n class=\"glyphicon glyphicon-export js-tooltip changes-... | Make the changes icon
@return string | [
"Make",
"the",
"changes",
"icon"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L413-L430 | train |
BKWLD/decoy | classes/Models/Change.php | Change.getPreviewActionAttribute | public function getPreviewActionAttribute()
{
if ($this->changedModel
&& $this->changedModel->uri
&& $this->action != 'deleted') {
return sprintf('<a href="%s" target="_blank"
class="glyphicon glyphicon-bookmark js-tooltip"
title="%s" data-placement="left"></a>',
$this->preview_url,
__('decoy::changes.standard_list.preview'));
} else {
return '<span class="glyphicon glyphicon-bookmark disabled"></span>';
}
} | php | public function getPreviewActionAttribute()
{
if ($this->changedModel
&& $this->changedModel->uri
&& $this->action != 'deleted') {
return sprintf('<a href="%s" target="_blank"
class="glyphicon glyphicon-bookmark js-tooltip"
title="%s" data-placement="left"></a>',
$this->preview_url,
__('decoy::changes.standard_list.preview'));
} else {
return '<span class="glyphicon glyphicon-bookmark disabled"></span>';
}
} | [
"public",
"function",
"getPreviewActionAttribute",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"changedModel",
"&&",
"$",
"this",
"->",
"changedModel",
"->",
"uri",
"&&",
"$",
"this",
"->",
"action",
"!=",
"'deleted'",
")",
"{",
"return",
"sprintf",
"(",
... | Make link to preview a version as long as the model has a URI and the
action wasn't a delete action.
@return string | [
"Make",
"link",
"to",
"preview",
"a",
"version",
"as",
"long",
"as",
"the",
"model",
"has",
"a",
"URI",
"and",
"the",
"action",
"wasn",
"t",
"a",
"delete",
"action",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L438-L451 | train |
BKWLD/decoy | classes/Models/Change.php | Change.attributesForModal | public function attributesForModal()
{
// Remove some specific attributes. Leaving empties in there so the updating
// of values to NULL is displayed.
$attributes = array_except($this->changed, [
'id', 'updated_at', 'created_at', 'password', 'remember_token',
]);
// Make more readable titles
$out = [];
foreach ($attributes as $key => $val) {
$out[Text::titleFromKey($key)] = $val;
}
return $out;
} | php | public function attributesForModal()
{
// Remove some specific attributes. Leaving empties in there so the updating
// of values to NULL is displayed.
$attributes = array_except($this->changed, [
'id', 'updated_at', 'created_at', 'password', 'remember_token',
]);
// Make more readable titles
$out = [];
foreach ($attributes as $key => $val) {
$out[Text::titleFromKey($key)] = $val;
}
return $out;
} | [
"public",
"function",
"attributesForModal",
"(",
")",
"{",
"// Remove some specific attributes. Leaving empties in there so the updating",
"// of values to NULL is displayed.",
"$",
"attributes",
"=",
"array_except",
"(",
"$",
"this",
"->",
"changed",
",",
"[",
"'id'",
",",
... | Get just the attributes that should be displayed in the admin modal.
@return array | [
"Get",
"just",
"the",
"attributes",
"that",
"should",
"be",
"displayed",
"in",
"the",
"admin",
"modal",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Change.php#L472-L487 | train |
BKWLD/decoy | classes/Models/Traits/HasImages.php | HasImages.croppedImages | public function croppedImages($width = null, $height = null, $options = null)
{
return array_combine(
// Keys
$this->images->map(function ($image) {
return $image->name ?: 'default';
})->toArray(),
// Values
$this->images->map(function ($image) use ($width, $height, $options) {
return $image->crop($width, $height, $options)->url;
})->toArray()
);
} | php | public function croppedImages($width = null, $height = null, $options = null)
{
return array_combine(
// Keys
$this->images->map(function ($image) {
return $image->name ?: 'default';
})->toArray(),
// Values
$this->images->map(function ($image) use ($width, $height, $options) {
return $image->crop($width, $height, $options)->url;
})->toArray()
);
} | [
"public",
"function",
"croppedImages",
"(",
"$",
"width",
"=",
"null",
",",
"$",
"height",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"return",
"array_combine",
"(",
"// Keys",
"$",
"this",
"->",
"images",
"->",
"map",
"(",
"function",
"(... | Return an array of all images associated with the model, keyed by their
name, while optionally applying a crop to them | [
"Return",
"an",
"array",
"of",
"all",
"images",
"associated",
"with",
"the",
"model",
"keyed",
"by",
"their",
"name",
"while",
"optionally",
"applying",
"a",
"crop",
"to",
"them"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/HasImages.php#L92-L106 | train |
BKWLD/decoy | classes/Models/Traits/HasImages.php | HasImages.appendToImgs | public function appendToImgs(Image $image, $property)
{
// Create or fetch the container for all images on the model. The
// container could not be "images" because that is used by the
// relationship function and leads to trouble.
if (!$this->getAttribute('imgs')) {
$imgs = [];
$this->addVisible('imgs');
} else {
$imgs = $this->getAttribute('imgs');
}
// Add the image to the container and set it. Then return the model. It
// must be explicitly converted to an array because Laravel won't
// automatically do it during collection serialization. Another, more
// complicated approach could have been to use the Decoy Base model to add
// a cast type of "model" and then call toArray() on it when casting the
// attribute.
$imgs[$property] = $image->toArray();
$this->setAttribute('imgs', $imgs);
return $this;
} | php | public function appendToImgs(Image $image, $property)
{
// Create or fetch the container for all images on the model. The
// container could not be "images" because that is used by the
// relationship function and leads to trouble.
if (!$this->getAttribute('imgs')) {
$imgs = [];
$this->addVisible('imgs');
} else {
$imgs = $this->getAttribute('imgs');
}
// Add the image to the container and set it. Then return the model. It
// must be explicitly converted to an array because Laravel won't
// automatically do it during collection serialization. Another, more
// complicated approach could have been to use the Decoy Base model to add
// a cast type of "model" and then call toArray() on it when casting the
// attribute.
$imgs[$property] = $image->toArray();
$this->setAttribute('imgs', $imgs);
return $this;
} | [
"public",
"function",
"appendToImgs",
"(",
"Image",
"$",
"image",
",",
"$",
"property",
")",
"{",
"// Create or fetch the container for all images on the model. The",
"// container could not be \"images\" because that is used by the",
"// relationship function and leads to trouble.",
"... | Add an Image to the `imgs` attribute of the model for the purpose of
exposing it when serialized.
@param Image $image
@param string $property
@return $this | [
"Add",
"an",
"Image",
"to",
"the",
"imgs",
"attribute",
"of",
"the",
"model",
"for",
"the",
"purpose",
"of",
"exposing",
"it",
"when",
"serialized",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/HasImages.php#L116-L138 | train |
BKWLD/decoy | classes/Routing/Router.php | Router.registerAll | public function registerAll()
{
// Public routes
Route::group([
'prefix' => $this->dir,
'middleware' => 'decoy.public',
], function () {
$this->registerLogin();
$this->registerResetPassword();
});
// Routes that don't require auth or CSRF
Route::group([
'prefix' => $this->dir,
'middleware' => 'decoy.endpoint',
], function () {
$this->registerExternalEndpoints();
});
// Protected, admin routes
Route::group([
'prefix' => $this->dir,
'middleware' => 'decoy.protected',
], function () {
$this->registerAdmins();
$this->registerCommands();
$this->registerElements();
$this->registerEncode();
$this->registerRedactor();
$this->registerWorkers();
$this->registerWildcard(); // Must be last
});
} | php | public function registerAll()
{
// Public routes
Route::group([
'prefix' => $this->dir,
'middleware' => 'decoy.public',
], function () {
$this->registerLogin();
$this->registerResetPassword();
});
// Routes that don't require auth or CSRF
Route::group([
'prefix' => $this->dir,
'middleware' => 'decoy.endpoint',
], function () {
$this->registerExternalEndpoints();
});
// Protected, admin routes
Route::group([
'prefix' => $this->dir,
'middleware' => 'decoy.protected',
], function () {
$this->registerAdmins();
$this->registerCommands();
$this->registerElements();
$this->registerEncode();
$this->registerRedactor();
$this->registerWorkers();
$this->registerWildcard(); // Must be last
});
} | [
"public",
"function",
"registerAll",
"(",
")",
"{",
"// Public routes",
"Route",
"::",
"group",
"(",
"[",
"'prefix'",
"=>",
"$",
"this",
"->",
"dir",
",",
"'middleware'",
"=>",
"'decoy.public'",
",",
"]",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->"... | Register all routes
@return void | [
"Register",
"all",
"routes"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Router.php#L43-L75 | train |
BKWLD/decoy | classes/Routing/Router.php | Router.registerWildcard | public function registerWildcard()
{
// Setup a wildcarded catch all route
Route::any('{path}', ['as' => 'decoy::wildcard', function ($path) {
// Remember the detected route
App::make('events')->listen('wildcard.detection', function ($controller, $action) {
$this->action($controller.'@'.$action);
});
// Do the detection
$router = App::make('decoy.wildcard');
$response = $router->detectAndExecute();
if (is_a($response, 'Symfony\Component\HttpFoundation\Response')
|| is_a($response, 'Illuminate\View\View')) { // Possible when layout is involved
return $response;
} else {
App::abort(404);
}
}])->where('path', '.*');
} | php | public function registerWildcard()
{
// Setup a wildcarded catch all route
Route::any('{path}', ['as' => 'decoy::wildcard', function ($path) {
// Remember the detected route
App::make('events')->listen('wildcard.detection', function ($controller, $action) {
$this->action($controller.'@'.$action);
});
// Do the detection
$router = App::make('decoy.wildcard');
$response = $router->detectAndExecute();
if (is_a($response, 'Symfony\Component\HttpFoundation\Response')
|| is_a($response, 'Illuminate\View\View')) { // Possible when layout is involved
return $response;
} else {
App::abort(404);
}
}])->where('path', '.*');
} | [
"public",
"function",
"registerWildcard",
"(",
")",
"{",
"// Setup a wildcarded catch all route",
"Route",
"::",
"any",
"(",
"'{path}'",
",",
"[",
"'as'",
"=>",
"'decoy::wildcard'",
",",
"function",
"(",
"$",
"path",
")",
"{",
"// Remember the detected route",
"App"... | Setup wilcard routing
@return void | [
"Setup",
"wilcard",
"routing"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Router.php#L129-L149 | train |
BKWLD/decoy | classes/Routing/Router.php | Router.action | public function action($name = null)
{
if ($name) {
$this->action = $name;
}
if ($this->action) {
return $this->action;
}
// Wildcard
return Route::currentRouteAction();
} | php | public function action($name = null)
{
if ($name) {
$this->action = $name;
}
if ($this->action) {
return $this->action;
}
// Wildcard
return Route::currentRouteAction();
} | [
"public",
"function",
"action",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"action",
"=",
"$",
"name",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"action",
")",
"{",
"return",
"$",
"this",
"->",
... | Set and get the action for this request
@return string '\Bkwld\Decoy\Controllers\Account@forgot' | [
"Set",
"and",
"get",
"the",
"action",
"for",
"this",
"request"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Routing/Router.php#L275-L287 | train |
BKWLD/decoy | classes/Input/Position.php | Position.has | public function has()
{
if (!Request::has('position')) {
return false;
}
if (isset($this->item->position)) {
return true;
}
if (!empty($this->pivot) && isset($this->pivot->position)) {
return true;
}
return false;
} | php | public function has()
{
if (!Request::has('position')) {
return false;
}
if (isset($this->item->position)) {
return true;
}
if (!empty($this->pivot) && isset($this->pivot->position)) {
return true;
}
return false;
} | [
"public",
"function",
"has",
"(",
")",
"{",
"if",
"(",
"!",
"Request",
"::",
"has",
"(",
"'position'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"item",
"->",
"position",
")",
")",
"{",
"return",
"tru... | Check if we have all dependencies for an position change | [
"Check",
"if",
"we",
"have",
"all",
"dependencies",
"for",
"an",
"position",
"change"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Position.php#L36-L51 | train |
BKWLD/decoy | classes/Input/Position.php | Position.fill | public function fill()
{
// Write the position value to the pivot table
if (isset($this->pivot->position)) {
$this->pivot->position = request('position');
$this->pivot->save();
// Write position value to the item
} elseif (isset($this->item->position)) {
// Visiblity may be set at the same time and would be ignored otherwise
if (Request::has('public')) {
$this->item->public = request('public');
}
// Do position
$this->item->position = request('position');
}
} | php | public function fill()
{
// Write the position value to the pivot table
if (isset($this->pivot->position)) {
$this->pivot->position = request('position');
$this->pivot->save();
// Write position value to the item
} elseif (isset($this->item->position)) {
// Visiblity may be set at the same time and would be ignored otherwise
if (Request::has('public')) {
$this->item->public = request('public');
}
// Do position
$this->item->position = request('position');
}
} | [
"public",
"function",
"fill",
"(",
")",
"{",
"// Write the position value to the pivot table",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"pivot",
"->",
"position",
")",
")",
"{",
"$",
"this",
"->",
"pivot",
"->",
"position",
"=",
"request",
"(",
"'position... | Set new position | [
"Set",
"new",
"position"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Position.php#L56-L74 | train |
BKWLD/decoy | classes/Fields/Traits/CaptureHelp.php | CaptureHelp.help | public function help($help, $attributes = [])
{
$this->help = $help;
return parent::help($help, $attributes);
} | php | public function help($help, $attributes = [])
{
$this->help = $help;
return parent::help($help, $attributes);
} | [
"public",
"function",
"help",
"(",
"$",
"help",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"help",
"=",
"$",
"help",
";",
"return",
"parent",
"::",
"help",
"(",
"$",
"help",
",",
"$",
"attributes",
")",
";",
"}"
] | Store the help locally
@param string $help The help text
@param array $attributes Facultative attributes
@return $this | [
"Store",
"the",
"help",
"locally"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Traits/CaptureHelp.php#L32-L37 | train |
BKWLD/decoy | classes/Fields/Traits/CaptureHelp.php | CaptureHelp.blockhelp | public function blockhelp($help, $attributes = [])
{
$this->blockhelp = $help;
return parent::help($help, $attributes);
} | php | public function blockhelp($help, $attributes = [])
{
$this->blockhelp = $help;
return parent::help($help, $attributes);
} | [
"public",
"function",
"blockhelp",
"(",
"$",
"help",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"blockhelp",
"=",
"$",
"help",
";",
"return",
"parent",
"::",
"help",
"(",
"$",
"help",
",",
"$",
"attributes",
")",
";",
"}"
] | Store the block help locally
@param string $help The help text
@param array $attributes Facultative attributes
@return $this | [
"Store",
"the",
"block",
"help",
"locally"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Traits/CaptureHelp.php#L46-L51 | train |
BKWLD/decoy | classes/Middleware/Guest.php | Guest.getHome | public function getHome()
{
// Vars
$config = config('decoy.site.post_login_redirect');
$auth = app('decoy.user');
// Make the config optional
if ($config) {
// Support the config being a colsure
if (is_callable($config)) {
$config = call_user_func($config);
}
// Make sure the user has permission before redirecting
if ($auth->can('read', $config)) {
return $config;
}
}
// If the user doesn't have permission, iterate through the navigation
// options until one is permissible
foreach ($this->getNavUrls() as $url) {
if ($auth->can('read', $url)) {
return $url;
}
}
// Default to their account page, which all can access
return $auth->getUserUrl();
} | php | public function getHome()
{
// Vars
$config = config('decoy.site.post_login_redirect');
$auth = app('decoy.user');
// Make the config optional
if ($config) {
// Support the config being a colsure
if (is_callable($config)) {
$config = call_user_func($config);
}
// Make sure the user has permission before redirecting
if ($auth->can('read', $config)) {
return $config;
}
}
// If the user doesn't have permission, iterate through the navigation
// options until one is permissible
foreach ($this->getNavUrls() as $url) {
if ($auth->can('read', $url)) {
return $url;
}
}
// Default to their account page, which all can access
return $auth->getUserUrl();
} | [
"public",
"function",
"getHome",
"(",
")",
"{",
"// Vars",
"$",
"config",
"=",
"config",
"(",
"'decoy.site.post_login_redirect'",
")",
";",
"$",
"auth",
"=",
"app",
"(",
"'decoy.user'",
")",
";",
"// Make the config optional",
"if",
"(",
"$",
"config",
")",
... | Determine what the dashboard URL should be, where the user is redirected
after login.
@return string | [
"Determine",
"what",
"the",
"dashboard",
"URL",
"should",
"be",
"where",
"the",
"user",
"is",
"redirected",
"after",
"login",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Guest.php#L37-L67 | train |
BKWLD/decoy | classes/Middleware/Guest.php | Guest.getNavUrls | public function getNavUrls($nav = null)
{
// If no nav passed, as it would be for a sub navs, get the configed nav
if (empty($nav)) {
$nav = config('decoy.site.nav');
}
// Allow for the nav to be acallable
if (is_callable($nav)) {
$nav = call_user_func($nav);
}
// Loop through the nav
$flat = [];
foreach ($nav as $val) {
if (is_array($val)) {
$flat = array_merge($flat, $this->getNavUrls($val));
} else {
$flat[] = $val;
}
}
return $flat;
} | php | public function getNavUrls($nav = null)
{
// If no nav passed, as it would be for a sub navs, get the configed nav
if (empty($nav)) {
$nav = config('decoy.site.nav');
}
// Allow for the nav to be acallable
if (is_callable($nav)) {
$nav = call_user_func($nav);
}
// Loop through the nav
$flat = [];
foreach ($nav as $val) {
if (is_array($val)) {
$flat = array_merge($flat, $this->getNavUrls($val));
} else {
$flat[] = $val;
}
}
return $flat;
} | [
"public",
"function",
"getNavUrls",
"(",
"$",
"nav",
"=",
"null",
")",
"{",
"// If no nav passed, as it would be for a sub navs, get the configed nav",
"if",
"(",
"empty",
"(",
"$",
"nav",
")",
")",
"{",
"$",
"nav",
"=",
"config",
"(",
"'decoy.site.nav'",
")",
"... | Return a flat list of all the URLs in the nav. This doesn't include ones
automatically added by Decoy
@param array $nav
@return array | [
"Return",
"a",
"flat",
"list",
"of",
"all",
"the",
"URLs",
"in",
"the",
"nav",
".",
"This",
"doesn",
"t",
"include",
"ones",
"automatically",
"added",
"by",
"Decoy"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Middleware/Guest.php#L76-L99 | train |
BKWLD/decoy | classes/Fields/VideoEncoder.php | VideoEncoder.wrapAndRender | public function wrapAndRender()
{
// Check if the model has encodings
if (($item = $this->getModel()) && method_exists($item, 'encodings')) {
// If so, get it's encoding model instance
$this->encoding = $item->encodings()
->where('encodable_attribute', $this->model_attribute)
->first();
// Add the data attributes for JS view
if ($this->encoding) {
$this->group->data_encode($this->encoding->id);
}
}
// Continue rendering
return parent::wrapAndRender();
} | php | public function wrapAndRender()
{
// Check if the model has encodings
if (($item = $this->getModel()) && method_exists($item, 'encodings')) {
// If so, get it's encoding model instance
$this->encoding = $item->encodings()
->where('encodable_attribute', $this->model_attribute)
->first();
// Add the data attributes for JS view
if ($this->encoding) {
$this->group->data_encode($this->encoding->id);
}
}
// Continue rendering
return parent::wrapAndRender();
} | [
"public",
"function",
"wrapAndRender",
"(",
")",
"{",
"// Check if the model has encodings",
"if",
"(",
"(",
"$",
"item",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
"&&",
"method_exists",
"(",
"$",
"item",
",",
"'encodings'",
")",
")",
"{",
"// If ... | Prints out the field, wrapped in its group.
@return string | [
"Prints",
"out",
"the",
"field",
"wrapped",
"in",
"its",
"group",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L101-L119 | train |
BKWLD/decoy | classes/Fields/VideoEncoder.php | VideoEncoder.renderPresets | protected function renderPresets()
{
// Create the dropdown menu options
$config = config('decoy.encode.presets');
$presets = array_keys($config);
$dropdown = implode('', array_map(function ($config, $preset) {
return '<li>
<a href="#" data-val="'.$preset.'">
'.$config['title'].'
</a>
</li>';
}, $config, $presets));
// Make the hidden field
$hidden = '<input type="hidden"
name="_preset['.$this->name.']"
value="'.$this->presetValue().'">';
// Renturn the total markup
return '<div class="input-group-btn js-tooltip"
title="<b>Encoding quality.</b><br>Change to re-encode videos.">
'.$hidden.'
<button type="button"
class="btn btn-default dropdown-toggle"
data-toggle="dropdown" >
<span class="selected">Presets</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right presets">
'.$dropdown.'
</ul>
</div>';
} | php | protected function renderPresets()
{
// Create the dropdown menu options
$config = config('decoy.encode.presets');
$presets = array_keys($config);
$dropdown = implode('', array_map(function ($config, $preset) {
return '<li>
<a href="#" data-val="'.$preset.'">
'.$config['title'].'
</a>
</li>';
}, $config, $presets));
// Make the hidden field
$hidden = '<input type="hidden"
name="_preset['.$this->name.']"
value="'.$this->presetValue().'">';
// Renturn the total markup
return '<div class="input-group-btn js-tooltip"
title="<b>Encoding quality.</b><br>Change to re-encode videos.">
'.$hidden.'
<button type="button"
class="btn btn-default dropdown-toggle"
data-toggle="dropdown" >
<span class="selected">Presets</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right presets">
'.$dropdown.'
</ul>
</div>';
} | [
"protected",
"function",
"renderPresets",
"(",
")",
"{",
"// Create the dropdown menu options",
"$",
"config",
"=",
"config",
"(",
"'decoy.encode.presets'",
")",
";",
"$",
"presets",
"=",
"array_keys",
"(",
"$",
"config",
")",
";",
"$",
"dropdown",
"=",
"implode... | Render the presets select menu
@return string | [
"Render",
"the",
"presets",
"select",
"menu"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L126-L158 | train |
BKWLD/decoy | classes/Fields/VideoEncoder.php | VideoEncoder.presetValue | protected function presetValue()
{
if ($this->encoding) {
return $this->encoding->preset;
}
if ($this->preset) {
return $this->preset;
}
return array_keys(config('decoy.encode.presets'))[0];
} | php | protected function presetValue()
{
if ($this->encoding) {
return $this->encoding->preset;
}
if ($this->preset) {
return $this->preset;
}
return array_keys(config('decoy.encode.presets'))[0];
} | [
"protected",
"function",
"presetValue",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"encoding",
")",
"{",
"return",
"$",
"this",
"->",
"encoding",
"->",
"preset",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"preset",
")",
"{",
"return",
"$",
"this",
"... | Get the preset value
@return string | [
"Get",
"the",
"preset",
"value"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L165-L176 | train |
BKWLD/decoy | classes/Fields/VideoEncoder.php | VideoEncoder.renderIndestructibleReview | protected function renderIndestructibleReview()
{
if ($this->encoding && $this->encoding->status == 'complete') {
return $this->renderPlayerOrStatus();
}
return $this->renderPlayerOrStatus().parent::renderIndestructibleReview();
} | php | protected function renderIndestructibleReview()
{
if ($this->encoding && $this->encoding->status == 'complete') {
return $this->renderPlayerOrStatus();
}
return $this->renderPlayerOrStatus().parent::renderIndestructibleReview();
} | [
"protected",
"function",
"renderIndestructibleReview",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"encoding",
"&&",
"$",
"this",
"->",
"encoding",
"->",
"status",
"==",
"'complete'",
")",
"{",
"return",
"$",
"this",
"->",
"renderPlayerOrStatus",
"(",
")",
... | Should only the video player with no checkbox
@return string HTML | [
"Should",
"only",
"the",
"video",
"player",
"with",
"no",
"checkbox"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L193-L200 | train |
BKWLD/decoy | classes/Fields/VideoEncoder.php | VideoEncoder.renderPlayerOrStatus | protected function renderPlayerOrStatus()
{
if (!$this->encoding) {
return $this->renderError('No encoding instance found.');
}
switch ($this->encoding->status) {
case 'complete':
return $this->renderPlayer();
case 'error':
return $this->renderError($this->encoding->message);
case 'cancelled':
return $this->renderError('The encoding job was manually cancelled');
case 'pending':
return $this->renderProgress('');
case 'queued':
return $this->renderProgress($this->encoding->status);
case 'processing':
return $this->renderProgress($this->encoding->status);
}
} | php | protected function renderPlayerOrStatus()
{
if (!$this->encoding) {
return $this->renderError('No encoding instance found.');
}
switch ($this->encoding->status) {
case 'complete':
return $this->renderPlayer();
case 'error':
return $this->renderError($this->encoding->message);
case 'cancelled':
return $this->renderError('The encoding job was manually cancelled');
case 'pending':
return $this->renderProgress('');
case 'queued':
return $this->renderProgress($this->encoding->status);
case 'processing':
return $this->renderProgress($this->encoding->status);
}
} | [
"protected",
"function",
"renderPlayerOrStatus",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"encoding",
")",
"{",
"return",
"$",
"this",
"->",
"renderError",
"(",
"'No encoding instance found.'",
")",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"enc... | Render the player if the encoding is complete. Otherwise, show progress
@return string HTML | [
"Render",
"the",
"player",
"if",
"the",
"encoding",
"is",
"complete",
".",
"Otherwise",
"show",
"progress"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/VideoEncoder.php#L207-L233 | train |
BKWLD/decoy | classes/Controllers/Workers.php | Workers.tail | public function tail($worker)
{
// Form the path to the file
$file = Model::logPath(urldecode($worker));
if (!file_exists($file)) {
throw new Exception('Log not found: '.$file);
}
$size = 1024 * 100; // in bytes to get
// Read from the end of the file
clearstatcache();
$fp = fopen($file, 'r');
fseek($fp, -$size, SEEK_END);
$contents = explode("\n", fread($fp, $size));
fclose($fp);
// Reverse the contents and return
$contents = array_reverse($contents);
if (empty($contents[0])) {
array_shift($contents);
}
die(implode("\n", $contents));
} | php | public function tail($worker)
{
// Form the path to the file
$file = Model::logPath(urldecode($worker));
if (!file_exists($file)) {
throw new Exception('Log not found: '.$file);
}
$size = 1024 * 100; // in bytes to get
// Read from the end of the file
clearstatcache();
$fp = fopen($file, 'r');
fseek($fp, -$size, SEEK_END);
$contents = explode("\n", fread($fp, $size));
fclose($fp);
// Reverse the contents and return
$contents = array_reverse($contents);
if (empty($contents[0])) {
array_shift($contents);
}
die(implode("\n", $contents));
} | [
"public",
"function",
"tail",
"(",
"$",
"worker",
")",
"{",
"// Form the path to the file",
"$",
"file",
"=",
"Model",
"::",
"logPath",
"(",
"urldecode",
"(",
"$",
"worker",
")",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",... | Ajax service that tails the log file for the selected worker
@param $worker | [
"Ajax",
"service",
"that",
"tails",
"the",
"log",
"file",
"for",
"the",
"selected",
"worker"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Controllers/Workers.php#L34-L56 | train |
BKWLD/decoy | classes/Auth/Policy.php | Policy.check | public function check(Admin $admin, $action, $controller)
{
// Convert controller instance to its string name
if (is_object($controller)) {
$controller = get_class($controller);
}
// Get the slug version of the controller. Test if a URL was passed first
// and, if not, treat it like a full controller name. URLs are used in the
// nav. Also, an already slugified controller name will work fine too.
$pattern = '#/'.Config::get('decoy.core.dir').'/([^/]+)#';
if (preg_match($pattern, $controller, $matches)) {
$controller = $matches[1];
} else {
$controller = DecoyURL::slugController($controller);
}
// Allow all admins to upload to redactor
if ($controller == 'redactor') {
return true;
}
// Always allow an admin to edit themselves for changing password. Other
// features will be disabled from the view file.
if ($controller == 'admins'
&& ($action == 'read'
|| ($action == 'update' && Request::segment(3) == $admin->id))) {
return true;
}
// Don't allow creation on Decoy controlers that don't allow it
if ($action == 'create' && in_array($controller, [
'commands', 'changes', 'elements', 'workers',
])) {
return false;
}
// Always let developers access workers and commands
if (in_array($controller, ['workers', 'commands']) && $admin->isDeveloper()) {
return true;
}
// If the admin has permissions, test if they have access to the action using
// the array of permitted actions.
if ($permissions = $admin->getPermissionsAttribute()) {
// Check that the controller was defined in the permissions
if (!isset($permissions->$controller)
|| !is_array($permissions->$controller)) {
return false;
}
// When interacting with elements, allow as long as there is at least one
// page they have access to. Rely on the elements controller to enforce
// additional restrictions.
if ($controller == 'elements' && in_array($action, ['read', 'create'])) {
return count($permissions->elements) > 0;
}
// Default behavior checks that the action was checked in the permissions
// UI for the controller.
return in_array($action, $permissions->$controller);
}
// If there are "can" rules, then apply them as a whitelist. Only those
// actions are allowed.
$can = Config::get('decoy.site.permissions.'.$admin->role.'.can');
if (is_callable($can)) {
$can = call_user_func($can, $action, $controller);
}
if (is_array($can) &&
!in_array($action.'.'.$controller, $can) &&
!in_array('manage.'.$controller, $can)) {
return false;
}
// If the action is listed as "can't" then immediately deny. Also check for
// "manage" which means they can't do ANYTHING
$cant = Config::get('decoy.site.permissions.'.$admin->role.'.cant');
if (is_callable($cant)) {
$cant = call_user_func($cant, $action, $controller);
}
if (is_array($cant) && (
in_array($action.'.'.$controller, $cant) ||
in_array('manage.'.$controller, $cant))) {
return false;
}
// I guess we're good to go
return true;
} | php | public function check(Admin $admin, $action, $controller)
{
// Convert controller instance to its string name
if (is_object($controller)) {
$controller = get_class($controller);
}
// Get the slug version of the controller. Test if a URL was passed first
// and, if not, treat it like a full controller name. URLs are used in the
// nav. Also, an already slugified controller name will work fine too.
$pattern = '#/'.Config::get('decoy.core.dir').'/([^/]+)#';
if (preg_match($pattern, $controller, $matches)) {
$controller = $matches[1];
} else {
$controller = DecoyURL::slugController($controller);
}
// Allow all admins to upload to redactor
if ($controller == 'redactor') {
return true;
}
// Always allow an admin to edit themselves for changing password. Other
// features will be disabled from the view file.
if ($controller == 'admins'
&& ($action == 'read'
|| ($action == 'update' && Request::segment(3) == $admin->id))) {
return true;
}
// Don't allow creation on Decoy controlers that don't allow it
if ($action == 'create' && in_array($controller, [
'commands', 'changes', 'elements', 'workers',
])) {
return false;
}
// Always let developers access workers and commands
if (in_array($controller, ['workers', 'commands']) && $admin->isDeveloper()) {
return true;
}
// If the admin has permissions, test if they have access to the action using
// the array of permitted actions.
if ($permissions = $admin->getPermissionsAttribute()) {
// Check that the controller was defined in the permissions
if (!isset($permissions->$controller)
|| !is_array($permissions->$controller)) {
return false;
}
// When interacting with elements, allow as long as there is at least one
// page they have access to. Rely on the elements controller to enforce
// additional restrictions.
if ($controller == 'elements' && in_array($action, ['read', 'create'])) {
return count($permissions->elements) > 0;
}
// Default behavior checks that the action was checked in the permissions
// UI for the controller.
return in_array($action, $permissions->$controller);
}
// If there are "can" rules, then apply them as a whitelist. Only those
// actions are allowed.
$can = Config::get('decoy.site.permissions.'.$admin->role.'.can');
if (is_callable($can)) {
$can = call_user_func($can, $action, $controller);
}
if (is_array($can) &&
!in_array($action.'.'.$controller, $can) &&
!in_array('manage.'.$controller, $can)) {
return false;
}
// If the action is listed as "can't" then immediately deny. Also check for
// "manage" which means they can't do ANYTHING
$cant = Config::get('decoy.site.permissions.'.$admin->role.'.cant');
if (is_callable($cant)) {
$cant = call_user_func($cant, $action, $controller);
}
if (is_array($cant) && (
in_array($action.'.'.$controller, $cant) ||
in_array('manage.'.$controller, $cant))) {
return false;
}
// I guess we're good to go
return true;
} | [
"public",
"function",
"check",
"(",
"Admin",
"$",
"admin",
",",
"$",
"action",
",",
"$",
"controller",
")",
"{",
"// Convert controller instance to its string name",
"if",
"(",
"is_object",
"(",
"$",
"controller",
")",
")",
"{",
"$",
"controller",
"=",
"get_cl... | Check an Admin model against an action performed on a controller against
permissions from the config.
@param Admin $admin
@param string $action The verb we're checking. Examples:
- create
- read
- update
- destroy
- manage
- publish
@param string $controller
- controller instance
- controller name (Admin\ArticlesController)
- URL (/admin/articles)
- slug (articles)
@return boolean | [
"Check",
"an",
"Admin",
"model",
"against",
"an",
"action",
"performed",
"on",
"a",
"controller",
"against",
"permissions",
"from",
"the",
"config",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Auth/Policy.php#L34-L124 | train |
BKWLD/decoy | classes/Models/Base.php | Base.hasGetMutator | public function hasGetMutator($key)
{
if (!Decoy::handling()
|| !array_key_exists($key, $this->attributes)
|| in_array($key, $this->admin_mutators)) {
return parent::hasGetMutator($key);
}
} | php | public function hasGetMutator($key)
{
if (!Decoy::handling()
|| !array_key_exists($key, $this->attributes)
|| in_array($key, $this->admin_mutators)) {
return parent::hasGetMutator($key);
}
} | [
"public",
"function",
"hasGetMutator",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"Decoy",
"::",
"handling",
"(",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"attributes",
")",
"||",
"in_array",
"(",
"$",
"key",
",",
... | Disable mutators unless the active request isn't for the admin, the key
doesn't reference a true database-backed attribute, or the key was
expressly whitelisted in the admin_mutators property.
@param string $key
@return mixed | [
"Disable",
"mutators",
"unless",
"the",
"active",
"request",
"isn",
"t",
"for",
"the",
"admin",
"the",
"key",
"doesn",
"t",
"reference",
"a",
"true",
"database",
"-",
"backed",
"attribute",
"or",
"the",
"key",
"was",
"expressly",
"whitelisted",
"in",
"the",
... | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L124-L131 | train |
BKWLD/decoy | classes/Models/Base.php | Base.getAdminThumbAttribute | public function getAdminThumbAttribute($width = 40, $height = 40)
{
// Check if there are images for the model
if (!method_exists($this, 'images')) {
return;
}
$images = $this->images;
if ($images->isEmpty()) {
return;
}
// Get null-named (default) images first
return $images->sortBy('name')->first()->crop($width, $height)->url;
} | php | public function getAdminThumbAttribute($width = 40, $height = 40)
{
// Check if there are images for the model
if (!method_exists($this, 'images')) {
return;
}
$images = $this->images;
if ($images->isEmpty()) {
return;
}
// Get null-named (default) images first
return $images->sortBy('name')->first()->crop($width, $height)->url;
} | [
"public",
"function",
"getAdminThumbAttribute",
"(",
"$",
"width",
"=",
"40",
",",
"$",
"height",
"=",
"40",
")",
"{",
"// Check if there are images for the model",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"'images'",
")",
")",
"{",
"return",
... | The URL for the thumbnail
@return string URL | [
"The",
"URL",
"for",
"the",
"thumbnail"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L290-L305 | train |
BKWLD/decoy | classes/Models/Base.php | Base.getFileAttributesAttribute | public function getFileAttributesAttribute()
{
// Get all the file validation rule keys
$attributes = array_keys(array_filter(static::$rules, function ($rules) {
return preg_match('#file|image|mimes|video|dimensions#i', $rules);
}));
// Get all the model attributes from upchuck
if (method_exists($this, 'getUploadMap')) {
$attributes = array_unique(array_merge($attributes,
array_values($this->getUploadMap())));
}
// Return array of attributes
return $attributes;
} | php | public function getFileAttributesAttribute()
{
// Get all the file validation rule keys
$attributes = array_keys(array_filter(static::$rules, function ($rules) {
return preg_match('#file|image|mimes|video|dimensions#i', $rules);
}));
// Get all the model attributes from upchuck
if (method_exists($this, 'getUploadMap')) {
$attributes = array_unique(array_merge($attributes,
array_values($this->getUploadMap())));
}
// Return array of attributes
return $attributes;
} | [
"public",
"function",
"getFileAttributesAttribute",
"(",
")",
"{",
"// Get all the file validation rule keys",
"$",
"attributes",
"=",
"array_keys",
"(",
"array_filter",
"(",
"static",
"::",
"$",
"rules",
",",
"function",
"(",
"$",
"rules",
")",
"{",
"return",
"pr... | Get all file fields by looking at Upchuck config and validation rules
@return array The keys of all the attributes that store file references | [
"Get",
"all",
"file",
"fields",
"by",
"looking",
"at",
"Upchuck",
"config",
"and",
"validation",
"rules"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L329-L345 | train |
BKWLD/decoy | classes/Models/Base.php | Base.getAdminRowClassAttribute | public function getAdminRowClassAttribute() {
$classes = [];
// Add a visbility classs
if ($this->public) {
$classes[] = 'is-public';
}
// Add a soft-deleted class
if (method_exists($this, 'trashed') && $this->trashed()) {
$classes[] = 'is-trashed';
}
// Return all classes
return implode(' ', $classes);
} | php | public function getAdminRowClassAttribute() {
$classes = [];
// Add a visbility classs
if ($this->public) {
$classes[] = 'is-public';
}
// Add a soft-deleted class
if (method_exists($this, 'trashed') && $this->trashed()) {
$classes[] = 'is-trashed';
}
// Return all classes
return implode(' ', $classes);
} | [
"public",
"function",
"getAdminRowClassAttribute",
"(",
")",
"{",
"$",
"classes",
"=",
"[",
"]",
";",
"// Add a visbility classs",
"if",
"(",
"$",
"this",
"->",
"public",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'is-public'",
";",
"}",
"// Add a soft-delete... | Automatically add classes to rows in listing tables in the admin
@return string | [
"Automatically",
"add",
"classes",
"to",
"rows",
"in",
"listing",
"tables",
"in",
"the",
"admin"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L367-L382 | train |
BKWLD/decoy | classes/Models/Base.php | Base.getAttributesForLocalizationComparisonAttribute | public function getAttributesForLocalizationComparisonAttribute()
{
$attributes = $this->getAttributes();
if (method_exists($this, 'croppedImages')) {
$attributes['images'] = $this->croppedImages(300);
}
return $attributes;
} | php | public function getAttributesForLocalizationComparisonAttribute()
{
$attributes = $this->getAttributes();
if (method_exists($this, 'croppedImages')) {
$attributes['images'] = $this->croppedImages(300);
}
return $attributes;
} | [
"public",
"function",
"getAttributesForLocalizationComparisonAttribute",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'croppedImages'",
")",
")",
"{",
"$",
"attrib... | Expose model attributes for comparison by the localization sidebar
@return array | [
"Expose",
"model",
"attributes",
"for",
"comparison",
"by",
"the",
"localization",
"sidebar"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L389-L396 | train |
BKWLD/decoy | classes/Models/Base.php | Base.makeAdminActions | public function makeAdminActions($data)
{
$actions = [];
if ($html = $this->makeVisibilityAction($data)) {
$actions['visibility'] = $html;
}
if ($html = $this->makeEditAction($data)) {
$actions['edit'] = $html;
}
if ($html = $this->makeViewAction($data)) {
$actions['view'] = $html;
}
if ($html = $this->makeDeleteAction($data)) {
$actions['delete'] = $html;
}
return $actions;
} | php | public function makeAdminActions($data)
{
$actions = [];
if ($html = $this->makeVisibilityAction($data)) {
$actions['visibility'] = $html;
}
if ($html = $this->makeEditAction($data)) {
$actions['edit'] = $html;
}
if ($html = $this->makeViewAction($data)) {
$actions['view'] = $html;
}
if ($html = $this->makeDeleteAction($data)) {
$actions['delete'] = $html;
}
return $actions;
} | [
"public",
"function",
"makeAdminActions",
"(",
"$",
"data",
")",
"{",
"$",
"actions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"html",
"=",
"$",
"this",
"->",
"makeVisibilityAction",
"(",
"$",
"data",
")",
")",
"{",
"$",
"actions",
"[",
"'visibility'",
"]... | Make the markup for the actions column of the admin listing view. The
indivudal actions are stored in an array that is iterted through in the
view
@param array $data The data passed to a listing view
@return array | [
"Make",
"the",
"markup",
"for",
"the",
"actions",
"column",
"of",
"the",
"admin",
"listing",
"view",
".",
"The",
"indivudal",
"actions",
"are",
"stored",
"in",
"an",
"array",
"that",
"is",
"iterted",
"through",
"in",
"the",
"view"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L410-L431 | train |
BKWLD/decoy | classes/Models/Base.php | Base.makeVisibilityAction | protected function makeVisibilityAction($data)
{
extract($data);
// Check if this model supports editing the visibility
if ($many_to_many
|| !app('decoy.user')->can('publish', $controller)
|| !array_key_exists('public', $this->attributes)) {
return;
}
// Create the markup
$public = $this->getAttribute('public');
return sprintf('<a class="visibility js-tooltip" data-placement="left" title="%s">
<span class="glyphicon glyphicon-eye-%s"></span>
</a>',
$public ? __('decoy::base.standard_list.private') : __('decoy::base.standard_list.publish'),
$public ? 'open' : 'close'
);
} | php | protected function makeVisibilityAction($data)
{
extract($data);
// Check if this model supports editing the visibility
if ($many_to_many
|| !app('decoy.user')->can('publish', $controller)
|| !array_key_exists('public', $this->attributes)) {
return;
}
// Create the markup
$public = $this->getAttribute('public');
return sprintf('<a class="visibility js-tooltip" data-placement="left" title="%s">
<span class="glyphicon glyphicon-eye-%s"></span>
</a>',
$public ? __('decoy::base.standard_list.private') : __('decoy::base.standard_list.publish'),
$public ? 'open' : 'close'
);
} | [
"protected",
"function",
"makeVisibilityAction",
"(",
"$",
"data",
")",
"{",
"extract",
"(",
"$",
"data",
")",
";",
"// Check if this model supports editing the visibility",
"if",
"(",
"$",
"many_to_many",
"||",
"!",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
... | Make the visibility state action
@param array $data The data passed to a listing view
@return string | [
"Make",
"the",
"visibility",
"state",
"action"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L439-L458 | train |
BKWLD/decoy | classes/Models/Base.php | Base.makeEditAction | protected function makeEditAction($data)
{
extract($data);
// Make markup
$editable = app('decoy.user')->can('update', $controller);
return sprintf('<a href="%s" class="action-edit js-tooltip"
data-placement="left" title="%s">
<span class="glyphicon glyphicon-%s"></span>
</a>',
$this->getAdminEditUri($controller, $many_to_many), // URL
$editable ? // Label
__('decoy::base.action.edit') :
__('decoy::base.action.read') ,
$editable ? 'pencil' : 'zoom-in' // Icon
);
} | php | protected function makeEditAction($data)
{
extract($data);
// Make markup
$editable = app('decoy.user')->can('update', $controller);
return sprintf('<a href="%s" class="action-edit js-tooltip"
data-placement="left" title="%s">
<span class="glyphicon glyphicon-%s"></span>
</a>',
$this->getAdminEditUri($controller, $many_to_many), // URL
$editable ? // Label
__('decoy::base.action.edit') :
__('decoy::base.action.read') ,
$editable ? 'pencil' : 'zoom-in' // Icon
);
} | [
"protected",
"function",
"makeEditAction",
"(",
"$",
"data",
")",
"{",
"extract",
"(",
"$",
"data",
")",
";",
"// Make markup",
"$",
"editable",
"=",
"app",
"(",
"'decoy.user'",
")",
"->",
"can",
"(",
"'update'",
",",
"$",
"controller",
")",
";",
"return... | Make the edit or view action.
@param array $data The data passed to a listing view
@return string | [
"Make",
"the",
"edit",
"or",
"view",
"action",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L466-L482 | train |
BKWLD/decoy | classes/Models/Base.php | Base.getAdminEditUri | public function getAdminEditUri($controller, $many_to_many = false)
{
if ($many_to_many) {
return URL::to(DecoyURL::action($controller.'@edit', $this->getKey()));
}
return URL::to(DecoyURL::relative('edit', $this->getKey(), $controller));
} | php | public function getAdminEditUri($controller, $many_to_many = false)
{
if ($many_to_many) {
return URL::to(DecoyURL::action($controller.'@edit', $this->getKey()));
}
return URL::to(DecoyURL::relative('edit', $this->getKey(), $controller));
} | [
"public",
"function",
"getAdminEditUri",
"(",
"$",
"controller",
",",
"$",
"many_to_many",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"many_to_many",
")",
"{",
"return",
"URL",
"::",
"to",
"(",
"DecoyURL",
"::",
"action",
"(",
"$",
"controller",
".",
"'@edi... | Get the admin edit URL assuming you know the controller and whether it's
being listed as a many to many
@param string $controller ex: Admin\ArticlesController
@param boolean $many_to_many
@return string | [
"Get",
"the",
"admin",
"edit",
"URL",
"assuming",
"you",
"know",
"the",
"controller",
"and",
"whether",
"it",
"s",
"being",
"listed",
"as",
"a",
"many",
"to",
"many"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L492-L499 | train |
BKWLD/decoy | classes/Models/Base.php | Base.makeDeleteAction | protected function makeDeleteAction($data)
{
extract($data);
// Check if this model can be deleted. This mirrors code found in the table
// partial for generating the edit link on the title
if (!(app('decoy.user')->can('destroy', $controller)
|| ($many_to_many && app('decoy.user')->can('update', $parent_controller)))) {
return;
}
// If soft deleted, show a disabled icon
if (method_exists($this, 'trashed') && $this->trashed()) {
return '<span class="glyphicon glyphicon-trash"></span>';
}
// Make the label
$label = $many_to_many ?
__('decoy::base.action.remove') :
$with_trashed ?
__('decoy::base.action.soft_delete') :
__('decoy::base.action.delete') ;
// Return markup
return sprintf('<a class="%s js-tooltip" data-placement="left" title="%s">
<span class="glyphicon glyphicon-%s"></span>
</a>',
$many_to_many ? 'remove-now' : 'delete-now',
$label,
$many_to_many ? 'remove' : 'trash'
);
} | php | protected function makeDeleteAction($data)
{
extract($data);
// Check if this model can be deleted. This mirrors code found in the table
// partial for generating the edit link on the title
if (!(app('decoy.user')->can('destroy', $controller)
|| ($many_to_many && app('decoy.user')->can('update', $parent_controller)))) {
return;
}
// If soft deleted, show a disabled icon
if (method_exists($this, 'trashed') && $this->trashed()) {
return '<span class="glyphicon glyphicon-trash"></span>';
}
// Make the label
$label = $many_to_many ?
__('decoy::base.action.remove') :
$with_trashed ?
__('decoy::base.action.soft_delete') :
__('decoy::base.action.delete') ;
// Return markup
return sprintf('<a class="%s js-tooltip" data-placement="left" title="%s">
<span class="glyphicon glyphicon-%s"></span>
</a>',
$many_to_many ? 'remove-now' : 'delete-now',
$label,
$many_to_many ? 'remove' : 'trash'
);
} | [
"protected",
"function",
"makeDeleteAction",
"(",
"$",
"data",
")",
"{",
"extract",
"(",
"$",
"data",
")",
";",
"// Check if this model can be deleted. This mirrors code found in the table",
"// partial for generating the edit link on the title",
"if",
"(",
"!",
"(",
"app",... | Make the delete action
@param array $data The data passed to a listing view
@return string | [
"Make",
"the",
"delete",
"action"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L525-L556 | train |
BKWLD/decoy | classes/Models/Base.php | Base.scopePositioned | public function scopePositioned($query)
{
$query->orderBy($this->getTable().'.position', 'asc');
if ($this->usesTimestamps()) {
$query->orderBy($this->getTable().'.created_at', 'desc');
}
return $query;
} | php | public function scopePositioned($query)
{
$query->orderBy($this->getTable().'.position', 'asc');
if ($this->usesTimestamps()) {
$query->orderBy($this->getTable().'.created_at', 'desc');
}
return $query;
} | [
"public",
"function",
"scopePositioned",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"orderBy",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"'.position'",
",",
"'asc'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"usesTimestamps",
"(",
")",
"... | Order a table that has a position value
@param Illuminate\Database\Query\Builder $query
@return Illuminate\Database\Query\Builder | [
"Order",
"a",
"table",
"that",
"has",
"a",
"position",
"value"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L666-L673 | train |
BKWLD/decoy | classes/Models/Base.php | Base.scopeRandomize | public function scopeRandomize($query, $seed = false)
{
if ($seed === true) {
$seed = Session::getId();
}
if ($seed) {
return $query->orderBy(DB::raw('RAND("'.$seed.'")'));
}
return $query->orderBy(DB::raw('RAND()'));
} | php | public function scopeRandomize($query, $seed = false)
{
if ($seed === true) {
$seed = Session::getId();
}
if ($seed) {
return $query->orderBy(DB::raw('RAND("'.$seed.'")'));
}
return $query->orderBy(DB::raw('RAND()'));
} | [
"public",
"function",
"scopeRandomize",
"(",
"$",
"query",
",",
"$",
"seed",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"seed",
"===",
"true",
")",
"{",
"$",
"seed",
"=",
"Session",
"::",
"getId",
"(",
")",
";",
"}",
"if",
"(",
"$",
"seed",
")",
"... | Randomize the results in the DB. This shouldn't be used for large datasets
cause it's not very performant
@param Illuminate\Database\Query\Builder $query
@param mixed $seed Providing a seed keeps the order the same on subsequent queries
@return Illuminate\Database\Query\Builder | [
"Randomize",
"the",
"results",
"in",
"the",
"DB",
".",
"This",
"shouldn",
"t",
"be",
"used",
"for",
"large",
"datasets",
"cause",
"it",
"s",
"not",
"very",
"performant"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L694-L705 | train |
BKWLD/decoy | classes/Models/Base.php | Base.scopeOtherLocalizations | public function scopeOtherLocalizations($query)
{
return $query->where('locale_group', $this->locale_group)
->where($this->getKeyName(), '!=', $this->getKey());
} | php | public function scopeOtherLocalizations($query)
{
return $query->where('locale_group', $this->locale_group)
->where($this->getKeyName(), '!=', $this->getKey());
} | [
"public",
"function",
"scopeOtherLocalizations",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"'locale_group'",
",",
"$",
"this",
"->",
"locale_group",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"getKeyName",
"(",
")",
",",
"... | Get localized siblings of this model
@param Illuminate\Database\Query\Builder $query
@return Illuminate\Database\Query\Builder | [
"Get",
"localized",
"siblings",
"of",
"this",
"model"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L725-L729 | train |
BKWLD/decoy | classes/Models/Base.php | Base.findBySlugOrFail | public static function findBySlugOrFail($slug, array $columns = ['*'])
{
// Model not found, throw exception
if (!$item = static::findBySlug($slug)) {
throw (new ModelNotFoundException)->setModel(get_called_class());
}
// Return the model if visible
$item->enforceVisibility();
return $item;
} | php | public static function findBySlugOrFail($slug, array $columns = ['*'])
{
// Model not found, throw exception
if (!$item = static::findBySlug($slug)) {
throw (new ModelNotFoundException)->setModel(get_called_class());
}
// Return the model if visible
$item->enforceVisibility();
return $item;
} | [
"public",
"static",
"function",
"findBySlugOrFail",
"(",
"$",
"slug",
",",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"// Model not found, throw exception",
"if",
"(",
"!",
"$",
"item",
"=",
"static",
"::",
"findBySlug",
"(",
"$",
"slug",
")"... | Find by the slug and fail if missing. Invokes methods from the
Sluggable trait.
@param string $string
@param array $columns
@return Illuminate\Database\Eloquent\Model
@throws Illuminate\Database\Eloquent\ModelNotFoundException | [
"Find",
"by",
"the",
"slug",
"and",
"fail",
"if",
"missing",
".",
"Invokes",
"methods",
"from",
"the",
"Sluggable",
"trait",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L741-L752 | train |
BKWLD/decoy | classes/Models/Base.php | Base.fireDecoyEvent | public function fireDecoyEvent($event, $args = null)
{
$event = "decoy::model.{$event}: ".get_class($this);
return Event::fire($event, $args);
} | php | public function fireDecoyEvent($event, $args = null)
{
$event = "decoy::model.{$event}: ".get_class($this);
return Event::fire($event, $args);
} | [
"public",
"function",
"fireDecoyEvent",
"(",
"$",
"event",
",",
"$",
"args",
"=",
"null",
")",
"{",
"$",
"event",
"=",
"\"decoy::model.{$event}: \"",
".",
"get_class",
"(",
"$",
"this",
")",
";",
"return",
"Event",
"::",
"fire",
"(",
"$",
"event",
",",
... | Fire an Decoy model event.
@param $string event The name of this event
@param $array args An array of params that will be passed to the handler
@return object | [
"Fire",
"an",
"Decoy",
"model",
"event",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L779-L784 | train |
BKWLD/decoy | classes/Models/Base.php | Base.titleAttributes | public function titleAttributes()
{
// Convert to an array so I can test for the presence of values. As an
// object, it would throw exceptions
$row = $this->getAttributes();
// Name before title to cover the case of people with job titles
if (isset($row['name'])) {
return ['name'];
}
// Search full names if people-type fields
if (isset($row['first_name']) && isset($row['last_name'])) {
return ['first_name', 'last_name'];
}
// Standard location for the title
if (isset($row['title'])) {
return ['title'];
}
// Default to no searchable attributes
return [];
} | php | public function titleAttributes()
{
// Convert to an array so I can test for the presence of values. As an
// object, it would throw exceptions
$row = $this->getAttributes();
// Name before title to cover the case of people with job titles
if (isset($row['name'])) {
return ['name'];
}
// Search full names if people-type fields
if (isset($row['first_name']) && isset($row['last_name'])) {
return ['first_name', 'last_name'];
}
// Standard location for the title
if (isset($row['title'])) {
return ['title'];
}
// Default to no searchable attributes
return [];
} | [
"public",
"function",
"titleAttributes",
"(",
")",
"{",
"// Convert to an array so I can test for the presence of values. As an",
"// object, it would throw exceptions",
"$",
"row",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"// Name before title to cover the case of... | Deduce the source for the title of the model
@return array | [
"Deduce",
"the",
"source",
"for",
"the",
"title",
"of",
"the",
"model"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Base.php#L791-L814 | train |
BKWLD/decoy | classes/Input/Sidebar.php | Sidebar.render | public function render()
{
// Massage the response from base controller subclassings of sidebar
$items = array_map(function ($item) {
// If a listing instance, apply defaults common to all sidebar instances
if (is_a($item, 'Bkwld\Decoy\Fields\Listing')) {
return $item->layout('sidebar')->parent($this->parent)->__toString();
}
// Anything else will be converted to a string in the next step
return $item;
}, array_merge($this->items, $this->ending_items));
// Combine all listing items into a single string and return
return array_reduce($items, function ($carry, $item) {
return $carry.$item;
}, '');
} | php | public function render()
{
// Massage the response from base controller subclassings of sidebar
$items = array_map(function ($item) {
// If a listing instance, apply defaults common to all sidebar instances
if (is_a($item, 'Bkwld\Decoy\Fields\Listing')) {
return $item->layout('sidebar')->parent($this->parent)->__toString();
}
// Anything else will be converted to a string in the next step
return $item;
}, array_merge($this->items, $this->ending_items));
// Combine all listing items into a single string and return
return array_reduce($items, function ($carry, $item) {
return $carry.$item;
}, '');
} | [
"public",
"function",
"render",
"(",
")",
"{",
"// Massage the response from base controller subclassings of sidebar",
"$",
"items",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"// If a listing instance, apply defaults common to all sidebar instances",
"if",
... | Render an array of listing objects to an HTML string
@return string HTML | [
"Render",
"an",
"array",
"of",
"listing",
"objects",
"to",
"an",
"HTML",
"string"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/Sidebar.php#L85-L103 | train |
BKWLD/decoy | classes/Fields/Former/MethodDispatcher.php | MethodDispatcher.getClassFromMethod | protected function getClassFromMethod($method)
{
// Look for a studly class
$class = Str::singular(Str::studly($method));
foreach ($this->repositories as $repository) {
if (class_exists($repository.$class)) {
return $repository.$class;
}
}
// Resume normal functioning
return parent::getClassFromMethod($method);
} | php | protected function getClassFromMethod($method)
{
// Look for a studly class
$class = Str::singular(Str::studly($method));
foreach ($this->repositories as $repository) {
if (class_exists($repository.$class)) {
return $repository.$class;
}
}
// Resume normal functioning
return parent::getClassFromMethod($method);
} | [
"protected",
"function",
"getClassFromMethod",
"(",
"$",
"method",
")",
"{",
"// Look for a studly class",
"$",
"class",
"=",
"Str",
"::",
"singular",
"(",
"Str",
"::",
"studly",
"(",
"$",
"method",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"reposi... | Override the parent so that study class names are respected on
case sensitive file systems.
@param string $method The field created
@return string The correct class | [
"Override",
"the",
"parent",
"so",
"that",
"study",
"class",
"names",
"are",
"respected",
"on",
"case",
"sensitive",
"file",
"systems",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Former/MethodDispatcher.php#L20-L33 | train |
BKWLD/decoy | classes/Fields/Datetime.php | Datetime.value | public function value($value)
{
// Set the value using parent, so that if there is already one specified
// from populate or POST
parent::value($value);
// Set the value of the subfields
$this->date->value($value);
$this->time->value($value);
// Chainable
return $this;
} | php | public function value($value)
{
// Set the value using parent, so that if there is already one specified
// from populate or POST
parent::value($value);
// Set the value of the subfields
$this->date->value($value);
$this->time->value($value);
// Chainable
return $this;
} | [
"public",
"function",
"value",
"(",
"$",
"value",
")",
"{",
"// Set the value using parent, so that if there is already one specified",
"// from populate or POST",
"parent",
"::",
"value",
"(",
"$",
"value",
")",
";",
"// Set the value of the subfields",
"$",
"this",
"->",
... | Massage inputted string values into dates
@param string $value A new value
@return $this | [
"Massage",
"inputted",
"string",
"values",
"into",
"dates"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/Datetime.php#L67-L79 | train |
BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.encoding | public function encoding($attribute = 'video')
{
$encodings = $this->encodings;
if (!is_a($encodings, Collection::class)) {
$encodings = Encoding::hydrate($encodings);
}
return $encodings->first(function ($i, $encoding) use ($attribute) {
return data_get($encoding, 'encodable_attribute') == $attribute;
});
} | php | public function encoding($attribute = 'video')
{
$encodings = $this->encodings;
if (!is_a($encodings, Collection::class)) {
$encodings = Encoding::hydrate($encodings);
}
return $encodings->first(function ($i, $encoding) use ($attribute) {
return data_get($encoding, 'encodable_attribute') == $attribute;
});
} | [
"public",
"function",
"encoding",
"(",
"$",
"attribute",
"=",
"'video'",
")",
"{",
"$",
"encodings",
"=",
"$",
"this",
"->",
"encodings",
";",
"if",
"(",
"!",
"is_a",
"(",
"$",
"encodings",
",",
"Collection",
"::",
"class",
")",
")",
"{",
"$",
"encod... | Find the encoding for a given database field
@param string $attribute
@return Encoding|false | [
"Find",
"the",
"encoding",
"for",
"a",
"given",
"database",
"field"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L52-L62 | train |
BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.getDirtyEncodableAttributes | public function getDirtyEncodableAttributes()
{
if (empty($this->encodable_attributes)) {
return [];
}
return array_filter($this->encodable_attributes, function ($attribute) {
// The file has changed
if ($this->isDirty($attribute)) {
return true;
}
// The encoding preset is changing
return $this->hasDirtyPreset($attribute);
});
} | php | public function getDirtyEncodableAttributes()
{
if (empty($this->encodable_attributes)) {
return [];
}
return array_filter($this->encodable_attributes, function ($attribute) {
// The file has changed
if ($this->isDirty($attribute)) {
return true;
}
// The encoding preset is changing
return $this->hasDirtyPreset($attribute);
});
} | [
"public",
"function",
"getDirtyEncodableAttributes",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"encodable_attributes",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"encodable_attributes",
","... | Get all the attributes on a model who support video encodes and are dirty.
An encode is considered dirty if a file is uploaded, replaced, marked for
deletion OR if it's preset has changed.
@return array | [
"Get",
"all",
"the",
"attributes",
"on",
"a",
"model",
"who",
"support",
"video",
"encodes",
"and",
"are",
"dirty",
".",
"An",
"encode",
"is",
"considered",
"dirty",
"if",
"a",
"file",
"is",
"uploaded",
"replaced",
"marked",
"for",
"deletion",
"OR",
"if",
... | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L71-L87 | train |
BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.hasDirtyPreset | public function hasDirtyPreset($attribute)
{
// Require a previous encoding instance
return ($encoding = $this->encoding($attribute))
// Make sure the input actually contains a preset. It won't in cases like
// the AJAX PUT during listing drag and drop sorting or visibility toggle
&& ($preset_key = $this->encodingPresetInputKey($attribute))
&& request()->exists($preset_key)
// Check if the preset has changed
&& request($preset_key) != $encoding->preset;
} | php | public function hasDirtyPreset($attribute)
{
// Require a previous encoding instance
return ($encoding = $this->encoding($attribute))
// Make sure the input actually contains a preset. It won't in cases like
// the AJAX PUT during listing drag and drop sorting or visibility toggle
&& ($preset_key = $this->encodingPresetInputKey($attribute))
&& request()->exists($preset_key)
// Check if the preset has changed
&& request($preset_key) != $encoding->preset;
} | [
"public",
"function",
"hasDirtyPreset",
"(",
"$",
"attribute",
")",
"{",
"// Require a previous encoding instance",
"return",
"(",
"$",
"encoding",
"=",
"$",
"this",
"->",
"encoding",
"(",
"$",
"attribute",
")",
")",
"// Make sure the input actually contains a preset. ... | Check if the preset choice is dirty
@param string $attribute
@return boolean | [
"Check",
"if",
"the",
"preset",
"choice",
"is",
"dirty"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L95-L108 | train |
BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.adminColEncodeStatus | public function adminColEncodeStatus()
{
if (!$encode = $this->encoding()) {
return '<span class="label">Pending</span>';
}
switch ($encode->status) {
case 'pending':
return '<span class="label">'.ucfirst($encode->status).'</span>';
case 'error':
case 'cancelled':
return '<span class="label label-important">'.ucfirst($encode->status).'</span>';
case 'queued':
case 'processing':
return '<span class="label label-info">'.ucfirst($encode->status).'</span>';
case 'complete':
return '<span class="label label-success">'.ucfirst($encode->status).'</span>';
}
} | php | public function adminColEncodeStatus()
{
if (!$encode = $this->encoding()) {
return '<span class="label">Pending</span>';
}
switch ($encode->status) {
case 'pending':
return '<span class="label">'.ucfirst($encode->status).'</span>';
case 'error':
case 'cancelled':
return '<span class="label label-important">'.ucfirst($encode->status).'</span>';
case 'queued':
case 'processing':
return '<span class="label label-info">'.ucfirst($encode->status).'</span>';
case 'complete':
return '<span class="label label-success">'.ucfirst($encode->status).'</span>';
}
} | [
"public",
"function",
"adminColEncodeStatus",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"encode",
"=",
"$",
"this",
"->",
"encoding",
"(",
")",
")",
"{",
"return",
"'<span class=\"label\">Pending</span>'",
";",
"}",
"switch",
"(",
"$",
"encode",
"->",
"status",
... | A utitliy function to create status badges for Decoy listings
@return string HTML | [
"A",
"utitliy",
"function",
"to",
"create",
"status",
"badges",
"for",
"Decoy",
"listings"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L140-L160 | train |
BKWLD/decoy | classes/Models/Traits/Encodable.php | Encodable.encode | public function encode($attribute, $preset)
{
$encoding = new Encoding([
'encodable_attribute' => $attribute,
'preset' => $preset,
]);
$this->encodings()->save($encoding);
return $encoding;
} | php | public function encode($attribute, $preset)
{
$encoding = new Encoding([
'encodable_attribute' => $attribute,
'preset' => $preset,
]);
$this->encodings()->save($encoding);
return $encoding;
} | [
"public",
"function",
"encode",
"(",
"$",
"attribute",
",",
"$",
"preset",
")",
"{",
"$",
"encoding",
"=",
"new",
"Encoding",
"(",
"[",
"'encodable_attribute'",
"=>",
"$",
"attribute",
",",
"'preset'",
"=>",
"$",
"preset",
",",
"]",
")",
";",
"$",
"thi... | Delete any existing encoding for the attribute and then encode from the
source. The deleting happens automatically onCreating.
@param string $attribute The attribute on the model to use as source
@param string $preset The output config key
@return Encoding The new output instance | [
"Delete",
"any",
"existing",
"encoding",
"for",
"the",
"attribute",
"and",
"then",
"encode",
"from",
"the",
"source",
".",
"The",
"deleting",
"happens",
"automatically",
"onCreating",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Traits/Encodable.php#L208-L218 | train |
BKWLD/decoy | classes/Fields/BelongsTo.php | BelongsTo.wrapAndRender | public function wrapAndRender()
{
// Apend the edit button
$this->appendEditButton();
// Add control group attributes
$this->addGroupClass('belongs-to');
$this->group->setAttribute('data-js-view', 'belongs-to');
if ($this->route) {
$this->group->setAttribute('data-controller-route', $this->route);
}
// Continue doing normal wrapping
return parent::wrapAndRender();
} | php | public function wrapAndRender()
{
// Apend the edit button
$this->appendEditButton();
// Add control group attributes
$this->addGroupClass('belongs-to');
$this->group->setAttribute('data-js-view', 'belongs-to');
if ($this->route) {
$this->group->setAttribute('data-controller-route', $this->route);
}
// Continue doing normal wrapping
return parent::wrapAndRender();
} | [
"public",
"function",
"wrapAndRender",
"(",
")",
"{",
"// Apend the edit button",
"$",
"this",
"->",
"appendEditButton",
"(",
")",
";",
"// Add control group attributes",
"$",
"this",
"->",
"addGroupClass",
"(",
"'belongs-to'",
")",
";",
"$",
"this",
"->",
"group"... | Prints out the field, wrapped in its group. This is the opportunity
to tack additional stuff onto the control group
@return string | [
"Prints",
"out",
"the",
"field",
"wrapped",
"in",
"its",
"group",
".",
"This",
"is",
"the",
"opportunity",
"to",
"tack",
"additional",
"stuff",
"onto",
"the",
"control",
"group"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/BelongsTo.php#L128-L142 | train |
BKWLD/decoy | classes/Fields/BelongsTo.php | BelongsTo.parentModel | public function parentModel()
{
if ($this->value
&& ($relation = $this->guessRelation())
&& ($model = $this->getModel())
&& method_exists($model, $relation)) {
return $model->$relation;
}
} | php | public function parentModel()
{
if ($this->value
&& ($relation = $this->guessRelation())
&& ($model = $this->getModel())
&& method_exists($model, $relation)) {
return $model->$relation;
}
} | [
"public",
"function",
"parentModel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"value",
"&&",
"(",
"$",
"relation",
"=",
"$",
"this",
"->",
"guessRelation",
"(",
")",
")",
"&&",
"(",
"$",
"model",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
... | Get the parent record of the form instance
@return Illuminate\Database\Eloquent\Model | [
"Get",
"the",
"parent",
"record",
"of",
"the",
"form",
"instance"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/BelongsTo.php#L197-L205 | train |
BKWLD/decoy | classes/Fields/BelongsTo.php | BelongsTo.guessRelation | protected function guessRelation()
{
if ($this->relation) {
return $this->relation;
}
return Str::camel(str_replace('_id', '', $this->name));
} | php | protected function guessRelation()
{
if ($this->relation) {
return $this->relation;
}
return Str::camel(str_replace('_id', '', $this->name));
} | [
"protected",
"function",
"guessRelation",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"relation",
")",
"{",
"return",
"$",
"this",
"->",
"relation",
";",
"}",
"return",
"Str",
"::",
"camel",
"(",
"str_replace",
"(",
"'_id'",
",",
"''",
",",
"$",
"th... | Guess at the relationship name by removing id from the name and camel casing
@return string | [
"Guess",
"at",
"the",
"relationship",
"name",
"by",
"removing",
"id",
"from",
"the",
"name",
"and",
"camel",
"casing"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/BelongsTo.php#L212-L219 | train |
BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.relateTo | public function relateTo($model)
{
// Vars
$relation_attributes = [];
$input = Decoy::filteredInput();
// Loop through the input, looking for relationships
foreach ($input as $name => $data) {
if (!$relation = $this->makeRelation($model, $name, $data)) {
continue;
}
$relation_attributes[] = $name;
// Write child data when the model is saved. Because of how the saved
// listener works, we need to explicitly make sure the saved model is
// the one whose data we're parsing.
$model::saved(function ($saved_model) use ($model, $relation, $name, $data) {
if ($model != $saved_model) {
return;
}
$this->writeOnSaved($relation, $name, $data);
});
}
// Returning all input without the related attribtues
return array_except($input, $relation_attributes);
} | php | public function relateTo($model)
{
// Vars
$relation_attributes = [];
$input = Decoy::filteredInput();
// Loop through the input, looking for relationships
foreach ($input as $name => $data) {
if (!$relation = $this->makeRelation($model, $name, $data)) {
continue;
}
$relation_attributes[] = $name;
// Write child data when the model is saved. Because of how the saved
// listener works, we need to explicitly make sure the saved model is
// the one whose data we're parsing.
$model::saved(function ($saved_model) use ($model, $relation, $name, $data) {
if ($model != $saved_model) {
return;
}
$this->writeOnSaved($relation, $name, $data);
});
}
// Returning all input without the related attribtues
return array_except($input, $relation_attributes);
} | [
"public",
"function",
"relateTo",
"(",
"$",
"model",
")",
"{",
"// Vars",
"$",
"relation_attributes",
"=",
"[",
"]",
";",
"$",
"input",
"=",
"Decoy",
"::",
"filteredInput",
"(",
")",
";",
"// Loop through the input, looking for relationships",
"foreach",
"(",
"$... | Check the input for related models data. Remove it from the input if it
exists. And then listen for the model to be saved and write the related
models.
@param Eloquent\Model $model
@return array The input with attributes that were relations removed | [
"Check",
"the",
"input",
"for",
"related",
"models",
"data",
".",
"Remove",
"it",
"from",
"the",
"input",
"if",
"it",
"exists",
".",
"And",
"then",
"listen",
"for",
"the",
"model",
"to",
"be",
"saved",
"and",
"write",
"the",
"related",
"models",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L29-L55 | train |
BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.makeRelation | protected function makeRelation($model, $name, $data)
{
// The data must be an array and must contain arrays
if (!is_array($data)
|| empty($data)
|| count(array_filter($data, function ($child) {
return !is_array($child);
}))) {
return false;
}
// The input name should be a function defined on the model.
if (!method_exists($model, $name)) {
return false;
}
// Check if the running the function actually returns a relationship
$relation = $model->$name();
if (!is_a($relation, Relation::class)) {
return false;
}
// Return the relationship object
return $relation;
} | php | protected function makeRelation($model, $name, $data)
{
// The data must be an array and must contain arrays
if (!is_array($data)
|| empty($data)
|| count(array_filter($data, function ($child) {
return !is_array($child);
}))) {
return false;
}
// The input name should be a function defined on the model.
if (!method_exists($model, $name)) {
return false;
}
// Check if the running the function actually returns a relationship
$relation = $model->$name();
if (!is_a($relation, Relation::class)) {
return false;
}
// Return the relationship object
return $relation;
} | [
"protected",
"function",
"makeRelation",
"(",
"$",
"model",
",",
"$",
"name",
",",
"$",
"data",
")",
"{",
"// The data must be an array and must contain arrays",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"||",
"empty",
"(",
"$",
"data",
")",
"||",
... | Check if the input is a relation and, if it is, return the relationship
object
@param Model $model
@param string $name The input name, like from <input name="$name">, which
is also the naem of the relationship function.
@param mixed $data
@return false|Relation | [
"Check",
"if",
"the",
"input",
"is",
"a",
"relation",
"and",
"if",
"it",
"is",
"return",
"the",
"relationship",
"object"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L67-L91 | train |
BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.storeChild | protected function storeChild($relation, $input, $prefix)
{
$child = $relation->getRelated()->newInstance();
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$relation->save($child);
} | php | protected function storeChild($relation, $input, $prefix)
{
$child = $relation->getRelated()->newInstance();
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$relation->save($child);
} | [
"protected",
"function",
"storeChild",
"(",
"$",
"relation",
",",
"$",
"input",
",",
"$",
"prefix",
")",
"{",
"$",
"child",
"=",
"$",
"relation",
"->",
"getRelated",
"(",
")",
"->",
"newInstance",
"(",
")",
";",
"$",
"child",
"->",
"fill",
"(",
"$",
... | Create a new child record
@param Relation $relation
@param array $input The data for the nested model
@param string $prefix The input name prefix, for validation
@return void | [
"Create",
"a",
"new",
"child",
"record"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L124-L131 | train |
BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.updateChild | protected function updateChild($relation, $id, $input, $prefix)
{
$child = $relation->getRelated()->findOrFail($id);
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$child->save();
} | php | protected function updateChild($relation, $id, $input, $prefix)
{
$child = $relation->getRelated()->findOrFail($id);
$child->fill($input);
$rules = $this->getRules($relation, $input);
(new ModelValidator)->validateAndPrefixErrors($prefix, $child, $rules);
$child->save();
} | [
"protected",
"function",
"updateChild",
"(",
"$",
"relation",
",",
"$",
"id",
",",
"$",
"input",
",",
"$",
"prefix",
")",
"{",
"$",
"child",
"=",
"$",
"relation",
"->",
"getRelated",
"(",
")",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"chi... | Update an existing child record
@param Relation $relation
@param integer $id
@param array $input The data for the nested model
@param string $prefix The input name prefix, for validation
@return void | [
"Update",
"an",
"existing",
"child",
"record"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L142-L149 | train |
BKWLD/decoy | classes/Input/NestedModels.php | NestedModels.getRules | public function getRules($relation, $input)
{
$child = $relation->getRelated();
// If nested is not an Image, don't do anything special. This will result
// in the default validation behavior which gets the rules off of the child.
if (!is_a($child, Image::class)) {
return;
}
// Check for image rules on the parent
$parent = $relation->getParent();
$rules_key = 'images.' . ($input['name'] ?: 'default');
if (!array_key_exists($rules_key, $parent::$rules)) {
return;
}
// Return the parent rules concatenated on the default rules for an Image
// (those are essentially hardcoded here but I don't expect them to change)
return [
'file' => 'image|' . $parent::$rules[$rules_key],
];
} | php | public function getRules($relation, $input)
{
$child = $relation->getRelated();
// If nested is not an Image, don't do anything special. This will result
// in the default validation behavior which gets the rules off of the child.
if (!is_a($child, Image::class)) {
return;
}
// Check for image rules on the parent
$parent = $relation->getParent();
$rules_key = 'images.' . ($input['name'] ?: 'default');
if (!array_key_exists($rules_key, $parent::$rules)) {
return;
}
// Return the parent rules concatenated on the default rules for an Image
// (those are essentially hardcoded here but I don't expect them to change)
return [
'file' => 'image|' . $parent::$rules[$rules_key],
];
} | [
"public",
"function",
"getRules",
"(",
"$",
"relation",
",",
"$",
"input",
")",
"{",
"$",
"child",
"=",
"$",
"relation",
"->",
"getRelated",
"(",
")",
";",
"// If nested is not an Image, don't do anything special. This will result",
"// in the default validation behavior... | Get the validation rules. They are generally on the child except for
in the special case of Images
@param Relation $relation
@param array $input The data for the nested model
@return array | [
"Get",
"the",
"validation",
"rules",
".",
"They",
"are",
"generally",
"on",
"the",
"child",
"except",
"for",
"in",
"the",
"special",
"case",
"of",
"Images"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Input/NestedModels.php#L159-L181 | train |
BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.getRelations | public function getRelations()
{
$class = ucfirst('App\\'.ucfirst(Str::singular($this->name)));
$query = call_user_func([$class, 'ordered']);
if ($this->scope) {
call_user_func($this->scope, $query);
}
return $query->get();
} | php | public function getRelations()
{
$class = ucfirst('App\\'.ucfirst(Str::singular($this->name)));
$query = call_user_func([$class, 'ordered']);
if ($this->scope) {
call_user_func($this->scope, $query);
}
return $query->get();
} | [
"public",
"function",
"getRelations",
"(",
")",
"{",
"$",
"class",
"=",
"ucfirst",
"(",
"'App\\\\'",
".",
"ucfirst",
"(",
"Str",
"::",
"singular",
"(",
"$",
"this",
"->",
"name",
")",
")",
")",
";",
"$",
"query",
"=",
"call_user_func",
"(",
"[",
"$",... | Get all the options in the related table. Each will become a checkbox.
@return Illuminate\Database\Eloquent\Collection | [
"Get",
"all",
"the",
"options",
"in",
"the",
"related",
"table",
".",
"Each",
"will",
"become",
"a",
"checkbox",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L104-L114 | train |
BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.generateBox | protected function generateBox($row)
{
return [
'name' => $this->boxName(),
'value' => $row->getKey(),
'checked' => ($children = $this->children())
&& $children->contains($row->getKey()),
// Former is giving these a class of "form-control" which isn't correct
'class' => false,
// Add the model instance so the decorator can use it
'model' => $row,
];
} | php | protected function generateBox($row)
{
return [
'name' => $this->boxName(),
'value' => $row->getKey(),
'checked' => ($children = $this->children())
&& $children->contains($row->getKey()),
// Former is giving these a class of "form-control" which isn't correct
'class' => false,
// Add the model instance so the decorator can use it
'model' => $row,
];
} | [
"protected",
"function",
"generateBox",
"(",
"$",
"row",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"boxName",
"(",
")",
",",
"'value'",
"=>",
"$",
"row",
"->",
"getKey",
"(",
")",
",",
"'checked'",
"=>",
"(",
"$",
"children",
"=",
... | Take a model instance and generate a checkbox for it
@param Illuminate\Database\Eloquent\Model $row
@return array Configuration that is used by Former for a checkbox | [
"Take",
"a",
"model",
"instance",
"and",
"generate",
"a",
"checkbox",
"for",
"it"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L133-L147 | train |
BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.generateBoxLabel | protected function generateBoxLabel($row)
{
// Generate the title
$html = '<span class="title">'.$row->getAdminTitleHtmlAttribute().'</span>';
// Add link to edit
$url = '/'.Config::get('decoy.core.dir').'/'.Str::snake($this->name, '-')
.'/'.$row->getKey().'/edit';
if (app('decoy.user')->can('update', $url)) {
$html .= '<a href="'.$url.'"><span class="glyphicon glyphicon-pencil edit"></span></a>';
}
// The str_replace fixes Former's auto conversion of underscores into spaces.
$html = str_replace('_', '_', $html);
return $html;
} | php | protected function generateBoxLabel($row)
{
// Generate the title
$html = '<span class="title">'.$row->getAdminTitleHtmlAttribute().'</span>';
// Add link to edit
$url = '/'.Config::get('decoy.core.dir').'/'.Str::snake($this->name, '-')
.'/'.$row->getKey().'/edit';
if (app('decoy.user')->can('update', $url)) {
$html .= '<a href="'.$url.'"><span class="glyphicon glyphicon-pencil edit"></span></a>';
}
// The str_replace fixes Former's auto conversion of underscores into spaces.
$html = str_replace('_', '_', $html);
return $html;
} | [
"protected",
"function",
"generateBoxLabel",
"(",
"$",
"row",
")",
"{",
"// Generate the title",
"$",
"html",
"=",
"'<span class=\"title\">'",
".",
"$",
"row",
"->",
"getAdminTitleHtmlAttribute",
"(",
")",
".",
"'</span>'",
";",
"// Add link to edit",
"$",
"url",
... | Create the HTML label for a checkbox
@param Illuminate\Database\Eloquent\Model $row
@return string HTML | [
"Create",
"the",
"HTML",
"label",
"for",
"a",
"checkbox"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L155-L171 | train |
BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.children | protected function children()
{
if (($item = $this->getModel()) && method_exists($item, $this->name)) {
return $item->{$this->name};
}
} | php | protected function children()
{
if (($item = $this->getModel()) && method_exists($item, $this->name)) {
return $item->{$this->name};
}
} | [
"protected",
"function",
"children",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"item",
"=",
"$",
"this",
"->",
"getModel",
"(",
")",
")",
"&&",
"method_exists",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"name",
")",
")",
"{",
"return",
"$",
"item",
"->... | Get a collection of all the children that are already associated with the parent
@return Illuminate\Database\Eloquent\Collection | [
"Get",
"a",
"collection",
"of",
"all",
"the",
"children",
"that",
"are",
"already",
"associated",
"with",
"the",
"parent"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L178-L183 | train |
BKWLD/decoy | classes/Fields/ManyToManyChecklist.php | ManyToManyChecklist.createCheckable | protected function createCheckable($item, $fallbackValue = 1)
{
// Get the model reference out of the item and remove it before it's
// rendered. Otherwise it gets created as a data atrribute
$model = $item['attributes']['model'];
unset($item['attributes']['model']);
// Render the checkbox as per normal
$html = parent::createCheckable($item, $fallbackValue);
// Mutate a checkable using user defined
if ($this->decorator) {
$html = call_user_func($this->decorator, $html, $model);
}
// Return html
return $html;
} | php | protected function createCheckable($item, $fallbackValue = 1)
{
// Get the model reference out of the item and remove it before it's
// rendered. Otherwise it gets created as a data atrribute
$model = $item['attributes']['model'];
unset($item['attributes']['model']);
// Render the checkbox as per normal
$html = parent::createCheckable($item, $fallbackValue);
// Mutate a checkable using user defined
if ($this->decorator) {
$html = call_user_func($this->decorator, $html, $model);
}
// Return html
return $html;
} | [
"protected",
"function",
"createCheckable",
"(",
"$",
"item",
",",
"$",
"fallbackValue",
"=",
"1",
")",
"{",
"// Get the model reference out of the item and remove it before it's",
"// rendered. Otherwise it gets created as a data atrribute",
"$",
"model",
"=",
"$",
"item",
... | Renders a checkable. This overrides the Former subclass so we can decorate
each individual `.checkbox`div.
@param string|array $item A checkable item
@param integer $fallbackValue A fallback value if none is set
@return string | [
"Renders",
"a",
"checkable",
".",
"This",
"overrides",
"the",
"Former",
"subclass",
"so",
"we",
"can",
"decorate",
"each",
"individual",
".",
"checkbox",
"div",
"."
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Fields/ManyToManyChecklist.php#L194-L211 | train |
BKWLD/decoy | classes/Observers/ValidateExistingFiles.php | ValidateExistingFiles.onValidating | public function onValidating($event, $payload)
{
// Destructure payload
list($model, $validation) = $payload;
// Only act on locally hosted files
if (config('upchuck.disk.driver') != 'local') {
return;
}
// Get all the file related rules
// https://regex101.com/r/oP4kD2/1
$rules = array_filter($validation->getRules(), function ($rules) {
foreach ($rules as $rule) {
if (preg_match('#^(image|file|video|mimes|dimensions)#', $rule)) {
return true;
}
}
});
// For each of the file rules, if the input has a value, make a file
// instance for it if it's a local path.
$data = $validation->getData();
foreach (array_keys($rules) as $attribute) {
$value = array_get($data, $attribute);
// Skip if the attribute isn't in the input. It may not be for
// images or other nested models. Their validation should get
// triggered later through NestedModels behavior.
if (!array_has($data, $attribute)) {
continue;
// Skip if a file was uploaded for this attribtue
} else if (is_a($value, File::class)) {
continue;
// If the value is empty, because the user is deleting the file
// instance, set it to an empty string instead of the default
// (null). Null requires `nullable` validation rules to be set
// and I don't want to require that.
} else if (!$value) {
array_set($data, $attribute, '');
// Create the file instance and clear the data instance
} else {
array_set($data, $attribute, $this->makeFileFromPath($value));
}
}
// Replace the files and data with the updated set. `setData()` expects
// the data to contain files in it. But `getData()` strips out the
// files. Thus, they need to be merged back in before being set.
$validation->setData(array_merge($data));
} | php | public function onValidating($event, $payload)
{
// Destructure payload
list($model, $validation) = $payload;
// Only act on locally hosted files
if (config('upchuck.disk.driver') != 'local') {
return;
}
// Get all the file related rules
// https://regex101.com/r/oP4kD2/1
$rules = array_filter($validation->getRules(), function ($rules) {
foreach ($rules as $rule) {
if (preg_match('#^(image|file|video|mimes|dimensions)#', $rule)) {
return true;
}
}
});
// For each of the file rules, if the input has a value, make a file
// instance for it if it's a local path.
$data = $validation->getData();
foreach (array_keys($rules) as $attribute) {
$value = array_get($data, $attribute);
// Skip if the attribute isn't in the input. It may not be for
// images or other nested models. Their validation should get
// triggered later through NestedModels behavior.
if (!array_has($data, $attribute)) {
continue;
// Skip if a file was uploaded for this attribtue
} else if (is_a($value, File::class)) {
continue;
// If the value is empty, because the user is deleting the file
// instance, set it to an empty string instead of the default
// (null). Null requires `nullable` validation rules to be set
// and I don't want to require that.
} else if (!$value) {
array_set($data, $attribute, '');
// Create the file instance and clear the data instance
} else {
array_set($data, $attribute, $this->makeFileFromPath($value));
}
}
// Replace the files and data with the updated set. `setData()` expects
// the data to contain files in it. But `getData()` strips out the
// files. Thus, they need to be merged back in before being set.
$validation->setData(array_merge($data));
} | [
"public",
"function",
"onValidating",
"(",
"$",
"event",
",",
"$",
"payload",
")",
"{",
"// Destructure payload",
"list",
"(",
"$",
"model",
",",
"$",
"validation",
")",
"=",
"$",
"payload",
";",
"// Only act on locally hosted files",
"if",
"(",
"config",
"(",... | Massage validation handling
@param string $event
@param array $payload Contains:
- Bkwld\Decoy\Models\Base
- Illuminate\Validation\Validator
@return void | [
"Massage",
"validation",
"handling"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/ValidateExistingFiles.php#L25-L78 | train |
BKWLD/decoy | classes/Observers/ValidateExistingFiles.php | ValidateExistingFiles.makeFileFromPath | public function makeFileFromPath($path)
{
$upchuck_path = app('upchuck')->path($path);
$absolute_path = config('upchuck.disk.path').'/'.$upchuck_path;
return new UploadedFile(
$absolute_path, basename($absolute_path),
null, null, // Default mime and error
true); // Enable test mode so local file will be pass as uploaded
} | php | public function makeFileFromPath($path)
{
$upchuck_path = app('upchuck')->path($path);
$absolute_path = config('upchuck.disk.path').'/'.$upchuck_path;
return new UploadedFile(
$absolute_path, basename($absolute_path),
null, null, // Default mime and error
true); // Enable test mode so local file will be pass as uploaded
} | [
"public",
"function",
"makeFileFromPath",
"(",
"$",
"path",
")",
"{",
"$",
"upchuck_path",
"=",
"app",
"(",
"'upchuck'",
")",
"->",
"path",
"(",
"$",
"path",
")",
";",
"$",
"absolute_path",
"=",
"config",
"(",
"'upchuck.disk.path'",
")",
".",
"'/'",
".",... | Make an UploadedFile instance using Upchuck from the string input value
@param string $path
@return UploadedFile | [
"Make",
"an",
"UploadedFile",
"instance",
"using",
"Upchuck",
"from",
"the",
"string",
"input",
"value"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Observers/ValidateExistingFiles.php#L86-L94 | train |
BKWLD/decoy | classes/Models/Worker.php | Worker.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->option('worker')) {
return $this->worker();
}
if ($this->option('cron')) {
return $this->cron();
}
if ($this->option('heartbeat')) {
return $this->heartbeat();
}
return parent::execute($input, $output);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->option('worker')) {
return $this->worker();
}
if ($this->option('cron')) {
return $this->cron();
}
if ($this->option('heartbeat')) {
return $this->heartbeat();
}
return parent::execute($input, $output);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'worker'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"worker",
"(",
")",
";",
"}",... | Tap into the Laravel method that invokes the fire command to check for and
act on options | [
"Tap",
"into",
"the",
"Laravel",
"method",
"that",
"invokes",
"the",
"fire",
"command",
"to",
"check",
"for",
"and",
"act",
"on",
"options"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L63-L78 | train |
BKWLD/decoy | classes/Models/Worker.php | Worker.heartbeat | protected function heartbeat()
{
// Update the heartbeat
$last = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($last->interval)) {
$interval = 'calculating';
} else {
$interval = time() - $last->time;
}
Cache::forever($this->HEARTBEAT_CRON_KEY, (object) [
'time' => time(),
'interval' => $interval,
]);
// The worker has died
if (!$this->isRunning()) {
// Log an error that the worker stopped
$this->addLogging();
$this->error('The '.$this->name.' worker has stopped');
// Do work (since the worker has stopped)
$this->fire();
// The worker appears to be fine
} else {
$this->info('The '.$this->name.' worker is running');
}
} | php | protected function heartbeat()
{
// Update the heartbeat
$last = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($last->interval)) {
$interval = 'calculating';
} else {
$interval = time() - $last->time;
}
Cache::forever($this->HEARTBEAT_CRON_KEY, (object) [
'time' => time(),
'interval' => $interval,
]);
// The worker has died
if (!$this->isRunning()) {
// Log an error that the worker stopped
$this->addLogging();
$this->error('The '.$this->name.' worker has stopped');
// Do work (since the worker has stopped)
$this->fire();
// The worker appears to be fine
} else {
$this->info('The '.$this->name.' worker is running');
}
} | [
"protected",
"function",
"heartbeat",
"(",
")",
"{",
"// Update the heartbeat",
"$",
"last",
"=",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"HEARTBEAT_CRON_KEY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"last",
"->",
"interval",
")",
")",
"{",
"$",
... | This heartbeat function is called by cron to verify that the worker is still running | [
"This",
"heartbeat",
"function",
"is",
"called",
"by",
"cron",
"to",
"verify",
"that",
"the",
"worker",
"is",
"still",
"running"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L124-L153 | train |
BKWLD/decoy | classes/Models/Worker.php | Worker.log | public function log($level, $message, $context = [])
{
// This will be empty when output messages are triggered by the command
// when it's NOT called by a worker option
if (empty($this->logger)) {
return;
}
// Call the logger's level specific methods
$method = 'add'.ucfirst($level);
$this->logger->$method($message, $context);
} | php | public function log($level, $message, $context = [])
{
// This will be empty when output messages are triggered by the command
// when it's NOT called by a worker option
if (empty($this->logger)) {
return;
}
// Call the logger's level specific methods
$method = 'add'.ucfirst($level);
$this->logger->$method($message, $context);
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"// This will be empty when output messages are triggered by the command",
"// when it's NOT called by a worker option",
"if",
"(",
"empty",
"(",
"$",
"t... | Write Command output types to the log
@param $level
@param $message
@param array $context | [
"Write",
"Command",
"output",
"types",
"to",
"the",
"log"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L188-L199 | train |
BKWLD/decoy | classes/Models/Worker.php | Worker.all | public static function all()
{
$output = array();
$namespaced = Command::allCustom();
foreach ($namespaced as $namespace => $commands) {
foreach ($commands as $title => $command) {
if (is_a($command, 'Bkwld\Decoy\Models\Worker')) {
$output[] = $command;
}
}
}
return $output;
} | php | public static function all()
{
$output = array();
$namespaced = Command::allCustom();
foreach ($namespaced as $namespace => $commands) {
foreach ($commands as $title => $command) {
if (is_a($command, 'Bkwld\Decoy\Models\Worker')) {
$output[] = $command;
}
}
}
return $output;
} | [
"public",
"static",
"function",
"all",
"(",
")",
"{",
"$",
"output",
"=",
"array",
"(",
")",
";",
"$",
"namespaced",
"=",
"Command",
"::",
"allCustom",
"(",
")",
";",
"foreach",
"(",
"$",
"namespaced",
"as",
"$",
"namespace",
"=>",
"$",
"commands",
"... | Get all the tasks that have workers | [
"Get",
"all",
"the",
"tasks",
"that",
"have",
"workers"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L227-L240 | train |
BKWLD/decoy | classes/Models/Worker.php | Worker.lastHeartbeatCheck | public function lastHeartbeatCheck()
{
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check->time);
} | php | public function lastHeartbeatCheck()
{
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check->time);
} | [
"public",
"function",
"lastHeartbeatCheck",
"(",
")",
"{",
"$",
"check",
"=",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"HEARTBEAT_CRON_KEY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"check",
")",
")",
"{",
"return",
"'never'",
";",
"}",
"return",
... | Last time the heartbeat was checked | [
"Last",
"time",
"the",
"heartbeat",
"was",
"checked"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L253-L261 | train |
BKWLD/decoy | classes/Models/Worker.php | Worker.lastHeartbeat | public function lastHeartbeat()
{
$check = Cache::get($this->HEARTBEAT_WORKER_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check);
} | php | public function lastHeartbeat()
{
$check = Cache::get($this->HEARTBEAT_WORKER_KEY);
if (empty($check)) {
return 'never';
}
return date(Library\Utils\Constants::COMMON_DATETIME.' T', $check);
} | [
"public",
"function",
"lastHeartbeat",
"(",
")",
"{",
"$",
"check",
"=",
"Cache",
"::",
"get",
"(",
"$",
"this",
"->",
"HEARTBEAT_WORKER_KEY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"check",
")",
")",
"{",
"return",
"'never'",
";",
"}",
"return",
"d... | The last time the worker ran | [
"The",
"last",
"time",
"the",
"worker",
"ran"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L266-L274 | train |
BKWLD/decoy | classes/Models/Worker.php | Worker.currentInterval | public function currentInterval($format = null)
{
// Relative time formatting
$abbreviated = [
'pluraling' => false,
'spacing' => false,
'labels' => ['now', 's', 'm', 'h', 'd', 'm', 'y'],
];
// Figure stuff out
if ($this->isRunning()) {
$interval = $this->WORKER_SLEEP_SECS;
} else {
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
$interval = 'uncertain';
} else {
$interval = $check->interval;
}
}
// Format it
if (!is_numeric($interval)) {
return $interval;
}
switch ($format) {
case 'raw':
return $interval;
case 'abbreviated':
return Library\Utils\Text::timeElapsed(time() - $interval, $abbreviated);
default:
return Library\Utils\Text::timeElapsed(time() - $interval);
}
} | php | public function currentInterval($format = null)
{
// Relative time formatting
$abbreviated = [
'pluraling' => false,
'spacing' => false,
'labels' => ['now', 's', 'm', 'h', 'd', 'm', 'y'],
];
// Figure stuff out
if ($this->isRunning()) {
$interval = $this->WORKER_SLEEP_SECS;
} else {
$check = Cache::get($this->HEARTBEAT_CRON_KEY);
if (empty($check)) {
$interval = 'uncertain';
} else {
$interval = $check->interval;
}
}
// Format it
if (!is_numeric($interval)) {
return $interval;
}
switch ($format) {
case 'raw':
return $interval;
case 'abbreviated':
return Library\Utils\Text::timeElapsed(time() - $interval, $abbreviated);
default:
return Library\Utils\Text::timeElapsed(time() - $interval);
}
} | [
"public",
"function",
"currentInterval",
"(",
"$",
"format",
"=",
"null",
")",
"{",
"// Relative time formatting",
"$",
"abbreviated",
"=",
"[",
"'pluraling'",
"=>",
"false",
",",
"'spacing'",
"=>",
"false",
",",
"'labels'",
"=>",
"[",
"'now'",
",",
"'s'",
"... | The current interval that heartbeats are running at | [
"The",
"current",
"interval",
"that",
"heartbeats",
"are",
"running",
"at"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Models/Worker.php#L279-L315 | train |
BKWLD/decoy | classes/Layout/Nav.php | Nav.generate | public function generate()
{
// Get the navigation pages from the config
$pages = Config::get('decoy.site.nav');
if (is_callable($pages)) {
$pages = call_user_func($pages);
}
// Loop through the list of pages and massage
$massaged = [];
foreach ($pages as $key => $val) {
// If val is an array, make a drop down menu
if (is_array($val)) {
// Create a new page instance that represents the dropdown menu
$page = ['active' => false];
$page = array_merge($page, $this->makeIcon($key));
$page['children'] = [];
// Loop through children (we only support one level deep) and
// add each as a child
foreach ($val as $child_key => $child_val) {
$page['children'][] = $this->makePage($child_key, $child_val);
}
// See if any of the children are active and set the pulldown to active
foreach ($page['children'] as $child) {
if (!empty($child->active)) {
$page['active'] = true;
break;
}
}
// Add the pulldown to the list of pages
$massaged[] = (object) $page;
// The page is a simple (non pulldown) link
} else {
$massaged[] = $this->makePage($key, $val);
}
}
// Pass along the navigation data
return $massaged;
} | php | public function generate()
{
// Get the navigation pages from the config
$pages = Config::get('decoy.site.nav');
if (is_callable($pages)) {
$pages = call_user_func($pages);
}
// Loop through the list of pages and massage
$massaged = [];
foreach ($pages as $key => $val) {
// If val is an array, make a drop down menu
if (is_array($val)) {
// Create a new page instance that represents the dropdown menu
$page = ['active' => false];
$page = array_merge($page, $this->makeIcon($key));
$page['children'] = [];
// Loop through children (we only support one level deep) and
// add each as a child
foreach ($val as $child_key => $child_val) {
$page['children'][] = $this->makePage($child_key, $child_val);
}
// See if any of the children are active and set the pulldown to active
foreach ($page['children'] as $child) {
if (!empty($child->active)) {
$page['active'] = true;
break;
}
}
// Add the pulldown to the list of pages
$massaged[] = (object) $page;
// The page is a simple (non pulldown) link
} else {
$massaged[] = $this->makePage($key, $val);
}
}
// Pass along the navigation data
return $massaged;
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"// Get the navigation pages from the config",
"$",
"pages",
"=",
"Config",
"::",
"get",
"(",
"'decoy.site.nav'",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"pages",
")",
")",
"{",
"$",
"pages",
"=",
"call_... | Generate the nav config
@return array | [
"Generate",
"the",
"nav",
"config"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Nav.php#L18-L63 | train |
BKWLD/decoy | classes/Layout/Nav.php | Nav.makeIcon | protected function makeIcon($label_and_icon)
{
$parts = explode(',', $label_and_icon);
if (count($parts) == 2) {
return ['label' => $parts[0], 'icon' => $parts[1]];
}
return ['label' => $parts[0], 'icon' => 'default'];
} | php | protected function makeIcon($label_and_icon)
{
$parts = explode(',', $label_and_icon);
if (count($parts) == 2) {
return ['label' => $parts[0], 'icon' => $parts[1]];
}
return ['label' => $parts[0], 'icon' => 'default'];
} | [
"protected",
"function",
"makeIcon",
"(",
"$",
"label_and_icon",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"label_and_icon",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"==",
"2",
")",
"{",
"return",
"[",
"'label'",
"=>"... | Break the icon out of the label, returning an arary of label and icon | [
"Break",
"the",
"icon",
"out",
"of",
"the",
"label",
"returning",
"an",
"arary",
"of",
"label",
"and",
"icon"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Nav.php#L68-L76 | train |
BKWLD/decoy | classes/Layout/Nav.php | Nav.makePage | protected function makePage($key, $val)
{
// Check if it's a divider
if ($val === '-') {
return (object) ['divider' => true];
}
// Create a new page
$page = ['url' => $val, 'divider' => false];
$page = array_merge($page, $this->makeIcon($key));
// Check if this item is the currently selected one
$page['active'] = false;
if (strpos(URL::current(), parse_url($page['url'], PHP_URL_PATH))) {
$page['active'] = true;
}
// Return the new page
return (object) $page;
} | php | protected function makePage($key, $val)
{
// Check if it's a divider
if ($val === '-') {
return (object) ['divider' => true];
}
// Create a new page
$page = ['url' => $val, 'divider' => false];
$page = array_merge($page, $this->makeIcon($key));
// Check if this item is the currently selected one
$page['active'] = false;
if (strpos(URL::current(), parse_url($page['url'], PHP_URL_PATH))) {
$page['active'] = true;
}
// Return the new page
return (object) $page;
} | [
"protected",
"function",
"makePage",
"(",
"$",
"key",
",",
"$",
"val",
")",
"{",
"// Check if it's a divider",
"if",
"(",
"$",
"val",
"===",
"'-'",
")",
"{",
"return",
"(",
"object",
")",
"[",
"'divider'",
"=>",
"true",
"]",
";",
"}",
"// Create a new pa... | Make a page object
@return object | [
"Make",
"a",
"page",
"object"
] | 7a4acfa8e00cdca7ef4d82672a6547bae61f8e73 | https://github.com/BKWLD/decoy/blob/7a4acfa8e00cdca7ef4d82672a6547bae61f8e73/classes/Layout/Nav.php#L83-L102 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.