repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
summerblue/administrator
src/Frozennode/Administrator/Config/Settings/Config.php
Config.fetchData
public function fetchData(array $fields) { //set up the blank data $data = array(); foreach ($fields as $name => $field) { $data[$name] = null; } //populate the data from the file $this->setDataModel($this->populateData($data)); }
php
public function fetchData(array $fields) { //set up the blank data $data = array(); foreach ($fields as $name => $field) { $data[$name] = null; } //populate the data from the file $this->setDataModel($this->populateData($data)); }
[ "public", "function", "fetchData", "(", "array", "$", "fields", ")", "{", "//set up the blank data", "$", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "name", "=>", "$", "field", ")", "{", "$", "data", "[", "$", "nam...
Fetches the data for this settings config and stores it in the data property. @param array $fields
[ "Fetches", "the", "data", "for", "this", "settings", "config", "and", "stores", "it", "in", "the", "data", "property", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Settings/Config.php#L90-L101
summerblue/administrator
src/Frozennode/Administrator/Config/Settings/Config.php
Config.populateData
public function populateData(array $data) { //attempt to make the storage path if it doesn't already exist $path = $this->getStoragePath(); if (!is_dir($path)) { mkdir($path); } //try to fetch the JSON file $file = $path.$this->getOption('name').'.json'; if (file_exists($file)) { $json = file_get_contents($file); $saveData = json_decode($json); //run through the saveData and update the associated fields that we populated from the edit fields foreach ($saveData as $field => $value) { if (array_key_exists($field, $data)) { $data[$field] = $value; } } } return $data; }
php
public function populateData(array $data) { //attempt to make the storage path if it doesn't already exist $path = $this->getStoragePath(); if (!is_dir($path)) { mkdir($path); } //try to fetch the JSON file $file = $path.$this->getOption('name').'.json'; if (file_exists($file)) { $json = file_get_contents($file); $saveData = json_decode($json); //run through the saveData and update the associated fields that we populated from the edit fields foreach ($saveData as $field => $value) { if (array_key_exists($field, $data)) { $data[$field] = $value; } } } return $data; }
[ "public", "function", "populateData", "(", "array", "$", "data", ")", "{", "//attempt to make the storage path if it doesn't already exist", "$", "path", "=", "$", "this", "->", "getStoragePath", "(", ")", ";", "if", "(", "!", "is_dir", "(", "$", "path", ")", ...
Populates the data array if it can find the settings file. @param array $data @return array
[ "Populates", "the", "data", "array", "if", "it", "can", "find", "the", "settings", "file", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Settings/Config.php#L110-L135
summerblue/administrator
src/Frozennode/Administrator/Config/Settings/Config.php
Config.save
public function save(\Illuminate\Http\Request $input, array $fields) { $data = array(); $rules = $this->getOption('rules'); //iterate over the edit fields to only fetch the important items foreach ($fields as $name => $field) { if ($field->getOption('editable')) { $data[$name] = $input->get($name); //make sure the bool field is set correctly if ($field->getOption('type') === 'bool') { $data[$name] = $data[$name] === 'true' || $data[$name] === '1' ? 1 : 0; } } else { //unset uneditable fields rules unset($rules[$name]); } } //validate the model $validation = $this->validateData($data, $rules, $this->getOption('messages')); //if a string was kicked back, it's an error, so return it if (is_string($validation)) { return $validation; } //run the beforeSave function if provided $beforeSave = $this->runBeforeSave($data); //if a string was kicked back, it's an error, so return it if (is_string($beforeSave)) { return $beforeSave; } //Save the JSON data $this->putToJson($data); $this->setDataModel($data); return true; }
php
public function save(\Illuminate\Http\Request $input, array $fields) { $data = array(); $rules = $this->getOption('rules'); //iterate over the edit fields to only fetch the important items foreach ($fields as $name => $field) { if ($field->getOption('editable')) { $data[$name] = $input->get($name); //make sure the bool field is set correctly if ($field->getOption('type') === 'bool') { $data[$name] = $data[$name] === 'true' || $data[$name] === '1' ? 1 : 0; } } else { //unset uneditable fields rules unset($rules[$name]); } } //validate the model $validation = $this->validateData($data, $rules, $this->getOption('messages')); //if a string was kicked back, it's an error, so return it if (is_string($validation)) { return $validation; } //run the beforeSave function if provided $beforeSave = $this->runBeforeSave($data); //if a string was kicked back, it's an error, so return it if (is_string($beforeSave)) { return $beforeSave; } //Save the JSON data $this->putToJson($data); $this->setDataModel($data); return true; }
[ "public", "function", "save", "(", "\\", "Illuminate", "\\", "Http", "\\", "Request", "$", "input", ",", "array", "$", "fields", ")", "{", "$", "data", "=", "array", "(", ")", ";", "$", "rules", "=", "$", "this", "->", "getOption", "(", "'rules'", ...
Attempts to save a settings page. @param \Illuminate\Http\Request $input @param array $fields @return mixed //string if error, true if success
[ "Attempts", "to", "save", "a", "settings", "page", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Settings/Config.php#L145-L186
summerblue/administrator
src/Frozennode/Administrator/Config/Settings/Config.php
Config.runBeforeSave
public function runBeforeSave(array &$data) { $beforeSave = $this->getOption('before_save'); if (is_callable($beforeSave)) { $bs = $beforeSave($data); //if a string is returned, assume it's an error and kick it back if (is_string($bs)) { return $bs; } } return true; }
php
public function runBeforeSave(array &$data) { $beforeSave = $this->getOption('before_save'); if (is_callable($beforeSave)) { $bs = $beforeSave($data); //if a string is returned, assume it's an error and kick it back if (is_string($bs)) { return $bs; } } return true; }
[ "public", "function", "runBeforeSave", "(", "array", "&", "$", "data", ")", "{", "$", "beforeSave", "=", "$", "this", "->", "getOption", "(", "'before_save'", ")", ";", "if", "(", "is_callable", "(", "$", "beforeSave", ")", ")", "{", "$", "bs", "=", ...
Runs the before save method with the supplied data. @param array $data @param mixed
[ "Runs", "the", "before", "save", "method", "with", "the", "supplied", "data", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Settings/Config.php#L194-L208
summerblue/administrator
src/Frozennode/Administrator/Config/Settings/Config.php
Config.putToJson
public function putToJson($data) { $path = $this->getStoragePath(); //check if the storage path is writable if (!is_writable($path)) { throw new \InvalidArgumentException('The storage_path option in your '.$this->getOption('name').' settings config is not writable'); } file_put_contents($path.$this->getOption('name').'.json', json_encode($data)); }
php
public function putToJson($data) { $path = $this->getStoragePath(); //check if the storage path is writable if (!is_writable($path)) { throw new \InvalidArgumentException('The storage_path option in your '.$this->getOption('name').' settings config is not writable'); } file_put_contents($path.$this->getOption('name').'.json', json_encode($data)); }
[ "public", "function", "putToJson", "(", "$", "data", ")", "{", "$", "path", "=", "$", "this", "->", "getStoragePath", "(", ")", ";", "//check if the storage path is writable", "if", "(", "!", "is_writable", "(", "$", "path", ")", ")", "{", "throw", "new", ...
Puts the data contents into the json file. @param array $data
[ "Puts", "the", "data", "contents", "into", "the", "json", "file", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Settings/Config.php#L215-L225
summerblue/administrator
src/Frozennode/Administrator/Includes/Multup.php
Multup.open
public static function open($input, $rules, $path, $random = true) { return new self($input, $rules, $path, $random); }
php
public static function open($input, $rules, $path, $random = true) { return new self($input, $rules, $path, $random); }
[ "public", "static", "function", "open", "(", "$", "input", ",", "$", "rules", ",", "$", "path", ",", "$", "random", "=", "true", ")", "{", "return", "new", "self", "(", "$", "input", ",", "$", "rules", ",", "$", "path", ",", "$", "random", ")", ...
Static call, Laravel style. Returns a new Multup object, allowing for chainable calls. @param string $input name of the file to upload @param string $rules laravel style validation rules string @param string $path relative to /public/ to move the images if valid @param bool $random Whether or not to randomize the filename, the filename will be set to a 32 character string if true @return Multup
[ "Static", "call", "Laravel", "style", ".", "Returns", "a", "new", "Multup", "object", "allowing", "for", "chainable", "calls", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Includes/Multup.php#L100-L103
summerblue/administrator
src/Frozennode/Administrator/Includes/Multup.php
Multup.upload_image
private function upload_image() { /* validate the image */ $validation = Validator::make($this->image, array($this->input => $this->rules)); $errors = array(); $original_name = $this->image[$this->input]->getClientOriginalName(); $path = ''; $filename = ''; $resizes = ''; if ($validation->fails()) { /* use the messages object for the erros */ $errors = implode('. ', $validation->messages()->all()); } else { if ($this->random) { if (is_callable($this->random_cb)) { $filename = call_user_func($this->random_cb, $original_name); } else { $ext = File::extension($original_name); $filename = $this->generate_random_filename().'.'.$ext; } } else { $filename = $original_name; } /* upload the file */ $save = $this->image[$this->input]->move($this->path, $filename); //$save = Input::upload($this->input, $this->path, $filename); if ($save) { $path = $this->path.$filename; if (is_array($this->image_sizes)) { $resizer = new Resize(); $resizes = $resizer->create($save, $this->path, $filename, $this->image_sizes); } } else { $errors = 'Could not save image'; } } return compact('errors', 'path', 'filename', 'original_name', 'resizes'); }
php
private function upload_image() { /* validate the image */ $validation = Validator::make($this->image, array($this->input => $this->rules)); $errors = array(); $original_name = $this->image[$this->input]->getClientOriginalName(); $path = ''; $filename = ''; $resizes = ''; if ($validation->fails()) { /* use the messages object for the erros */ $errors = implode('. ', $validation->messages()->all()); } else { if ($this->random) { if (is_callable($this->random_cb)) { $filename = call_user_func($this->random_cb, $original_name); } else { $ext = File::extension($original_name); $filename = $this->generate_random_filename().'.'.$ext; } } else { $filename = $original_name; } /* upload the file */ $save = $this->image[$this->input]->move($this->path, $filename); //$save = Input::upload($this->input, $this->path, $filename); if ($save) { $path = $this->path.$filename; if (is_array($this->image_sizes)) { $resizer = new Resize(); $resizes = $resizer->create($save, $this->path, $filename, $this->image_sizes); } } else { $errors = 'Could not save image'; } } return compact('errors', 'path', 'filename', 'original_name', 'resizes'); }
[ "private", "function", "upload_image", "(", ")", "{", "/* validate the image */", "$", "validation", "=", "Validator", "::", "make", "(", "$", "this", "->", "image", ",", "array", "(", "$", "this", "->", "input", "=>", "$", "this", "->", "rules", ")", ")...
/* Upload the image
[ "/", "*", "Upload", "the", "image" ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Includes/Multup.php#L178-L221
summerblue/administrator
src/Frozennode/Administrator/Includes/Multup.php
Multup.after_upload
public function after_upload($cb, $args = '') { if (is_callable($cb)) { $this->upload_callback = $cb; $this->upload_callback_args = $args; } else { /* some sort of error... */ } return $this; }
php
public function after_upload($cb, $args = '') { if (is_callable($cb)) { $this->upload_callback = $cb; $this->upload_callback_args = $args; } else { /* some sort of error... */ } return $this; }
[ "public", "function", "after_upload", "(", "$", "cb", ",", "$", "args", "=", "''", ")", "{", "if", "(", "is_callable", "(", "$", "cb", ")", ")", "{", "$", "this", "->", "upload_callback", "=", "$", "cb", ";", "$", "this", "->", "upload_callback_args"...
/* Set the callback function to be called after each image is done uploading @var mixed anonymous function or string name of function
[ "/", "*", "Set", "the", "callback", "function", "to", "be", "called", "after", "each", "image", "is", "done", "uploading" ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Includes/Multup.php#L247-L257
summerblue/administrator
src/Frozennode/Administrator/Includes/Multup.php
Multup.post_upload_process
private function post_upload_process($args) { if (empty($args['errors'])) { /* add the saved image to the images array thing */ if (is_callable($this->upload_callback)) { if (!empty($this->upload_callback_args) && is_array($this->upload_callback_args)) { $args = array_merge($this->upload_callback_args, $args); } $args['callback_result'] = call_user_func($this->upload_callback, $args); } } return $args; }
php
private function post_upload_process($args) { if (empty($args['errors'])) { /* add the saved image to the images array thing */ if (is_callable($this->upload_callback)) { if (!empty($this->upload_callback_args) && is_array($this->upload_callback_args)) { $args = array_merge($this->upload_callback_args, $args); } $args['callback_result'] = call_user_func($this->upload_callback, $args); } } return $args; }
[ "private", "function", "post_upload_process", "(", "$", "args", ")", "{", "if", "(", "empty", "(", "$", "args", "[", "'errors'", "]", ")", ")", "{", "/* add the saved image to the images array thing */", "if", "(", "is_callable", "(", "$", "this", "->", "uploa...
/* Called after an image is successfully uploaded The function will append the vars to the images property If an after_upload function has been defined it will also append a variable to the array named callback_result @var array path resize ->this will be empty as the resize has not yet occurred filename -> the name of the successfully uploaded file @return void
[ "/", "*", "Called", "after", "an", "image", "is", "successfully", "uploaded", "The", "function", "will", "append", "the", "vars", "to", "the", "images", "property", "If", "an", "after_upload", "function", "has", "been", "defined", "it", "will", "also", "appe...
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Includes/Multup.php#L287-L302
summerblue/administrator
src/Frozennode/Administrator/Http/Middleware/ValidateModel.php
ValidateModel.handle
public function handle($request, Closure $next) { $modelName = $request->route()->parameter('model'); app()->singleton('itemconfig', function ($app) use ($modelName) { $configFactory = app('admin_config_factory'); return $configFactory->make($modelName, true); }); return $next($request); }
php
public function handle($request, Closure $next) { $modelName = $request->route()->parameter('model'); app()->singleton('itemconfig', function ($app) use ($modelName) { $configFactory = app('admin_config_factory'); return $configFactory->make($modelName, true); }); return $next($request); }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ")", "{", "$", "modelName", "=", "$", "request", "->", "route", "(", ")", "->", "parameter", "(", "'model'", ")", ";", "app", "(", ")", "->", "singleton", "(", "'itemco...
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Http/Middleware/ValidateModel.php#L17-L28
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.getRows
public function getRows(DB $db, $filters = null, $page = 1, $sort = null) { //prepare the query extract($this->prepareQuery($db, $page, $sort, $filters)); //run the count query $output = $this->performCountQuery($countQuery, $querySql, $queryBindings, $page); //now we need to limit and offset the rows in remembrance of our dear lost friend paginate() $query->take($this->rowsPerPage); $query->skip($this->rowsPerPage * ($output['page'] === 0 ? $output['page'] : $output['page'] - 1)); //parse the results $output['results'] = $this->parseResults($query->get()); return $output; }
php
public function getRows(DB $db, $filters = null, $page = 1, $sort = null) { //prepare the query extract($this->prepareQuery($db, $page, $sort, $filters)); //run the count query $output = $this->performCountQuery($countQuery, $querySql, $queryBindings, $page); //now we need to limit and offset the rows in remembrance of our dear lost friend paginate() $query->take($this->rowsPerPage); $query->skip($this->rowsPerPage * ($output['page'] === 0 ? $output['page'] : $output['page'] - 1)); //parse the results $output['results'] = $this->parseResults($query->get()); return $output; }
[ "public", "function", "getRows", "(", "DB", "$", "db", ",", "$", "filters", "=", "null", ",", "$", "page", "=", "1", ",", "$", "sort", "=", "null", ")", "{", "//prepare the query", "extract", "(", "$", "this", "->", "prepareQuery", "(", "$", "db", ...
Builds a results array (with results and pagination info). @param \Illuminate\Database\DatabaseManager $db @param array $filters @param int $page @param array $sort (with 'field' and 'direction' keys) @return array
[ "Builds", "a", "results", "array", "(", "with", "results", "and", "pagination", "info", ")", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L80-L96
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.prepareQuery
public function prepareQuery(DB $db, $page = 1, $sort = null, $filters = null) { //grab the model instance $model = $this->config->getDataModel(); //update the sort options $this->setSort($sort); $sort = $this->getSort(); //get things going by grouping the set $table = $model->getTable(); $keyName = $model->getKeyName(); $query = $model->groupBy($table.'.'.$keyName); //get the Illuminate\Database\Query\Builder instance and set up the count query $dbQuery = $query->getQuery(); $countQuery = $dbQuery->getConnection()->table($table)->groupBy($table.'.'.$keyName); //run the supplied query filter for both queries if it was provided $this->config->runQueryFilter($dbQuery); $this->config->runQueryFilter($countQuery); //set up initial array states for the selects $selects = array($table.'.*'); //set the filters $this->setFilters($filters, $dbQuery, $countQuery, $selects); //set the selects $dbQuery->select($selects); //determines if the sort should have the table prefixed to it $sortOnTable = true; //get the columns $columns = $this->columnFactory->getColumns(); //iterate over the columns to check if we need to join any values or add any extra columns foreach ($columns as $column) { //if this is a related column, we'll need to add some selects $column->filterQuery($selects); //if this is a related field or if (($column->getOption('is_related') || $column->getOption('select')) && $column->getOption('column_name') === $sort['field']) { $sortOnTable = false; } } //if the sort is on the model's table, prefix the table name to it if ($sortOnTable) { $sort['field'] = $table.'.'.$sort['field']; } //grab the query sql for later $querySql = $query->toSql(); //order the set by the model table's id $query->orderBy($sort['field'], $sort['direction']); //then retrieve the rows $query->getQuery()->select($selects); //only select distinct rows $query->distinct(); //load the query bindings $queryBindings = $query->getBindings(); return compact('query', 'querySql', 'queryBindings', 'countQuery', 'sort', 'selects'); }
php
public function prepareQuery(DB $db, $page = 1, $sort = null, $filters = null) { //grab the model instance $model = $this->config->getDataModel(); //update the sort options $this->setSort($sort); $sort = $this->getSort(); //get things going by grouping the set $table = $model->getTable(); $keyName = $model->getKeyName(); $query = $model->groupBy($table.'.'.$keyName); //get the Illuminate\Database\Query\Builder instance and set up the count query $dbQuery = $query->getQuery(); $countQuery = $dbQuery->getConnection()->table($table)->groupBy($table.'.'.$keyName); //run the supplied query filter for both queries if it was provided $this->config->runQueryFilter($dbQuery); $this->config->runQueryFilter($countQuery); //set up initial array states for the selects $selects = array($table.'.*'); //set the filters $this->setFilters($filters, $dbQuery, $countQuery, $selects); //set the selects $dbQuery->select($selects); //determines if the sort should have the table prefixed to it $sortOnTable = true; //get the columns $columns = $this->columnFactory->getColumns(); //iterate over the columns to check if we need to join any values or add any extra columns foreach ($columns as $column) { //if this is a related column, we'll need to add some selects $column->filterQuery($selects); //if this is a related field or if (($column->getOption('is_related') || $column->getOption('select')) && $column->getOption('column_name') === $sort['field']) { $sortOnTable = false; } } //if the sort is on the model's table, prefix the table name to it if ($sortOnTable) { $sort['field'] = $table.'.'.$sort['field']; } //grab the query sql for later $querySql = $query->toSql(); //order the set by the model table's id $query->orderBy($sort['field'], $sort['direction']); //then retrieve the rows $query->getQuery()->select($selects); //only select distinct rows $query->distinct(); //load the query bindings $queryBindings = $query->getBindings(); return compact('query', 'querySql', 'queryBindings', 'countQuery', 'sort', 'selects'); }
[ "public", "function", "prepareQuery", "(", "DB", "$", "db", ",", "$", "page", "=", "1", ",", "$", "sort", "=", "null", ",", "$", "filters", "=", "null", ")", "{", "//grab the model instance", "$", "model", "=", "$", "this", "->", "config", "->", "get...
Builds a results array (with results and pagination info). @param \Illuminate\Database\DatabaseManager $db @param int $page @param array $sort (with 'field' and 'direction' keys) @param array $filters @return array
[ "Builds", "a", "results", "array", "(", "with", "results", "and", "pagination", "info", ")", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L108-L177
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.performCountQuery
public function performCountQuery(QueryBuilder $countQuery, $querySql, $queryBindings, $page) { //grab the model instance $model = $this->config->getDataModel(); //then wrap the inner table and perform the count $sql = "SELECT COUNT({$model->getKeyName()}) AS aggregate FROM ({$querySql}) AS agg"; //then perform the count query $results = $countQuery->getConnection()->select($sql, $queryBindings); $numRows = is_array($results[0]) ? $results[0]['aggregate'] : $results[0]->aggregate; $page = (int) $page; $last = (int) ceil($numRows / $this->rowsPerPage); return array( //if the current page is greater than the last page, set the current page to the last page 'page' => $page > $last ? $last : $page, 'last' => $last, 'total' => $numRows, ); }
php
public function performCountQuery(QueryBuilder $countQuery, $querySql, $queryBindings, $page) { //grab the model instance $model = $this->config->getDataModel(); //then wrap the inner table and perform the count $sql = "SELECT COUNT({$model->getKeyName()}) AS aggregate FROM ({$querySql}) AS agg"; //then perform the count query $results = $countQuery->getConnection()->select($sql, $queryBindings); $numRows = is_array($results[0]) ? $results[0]['aggregate'] : $results[0]->aggregate; $page = (int) $page; $last = (int) ceil($numRows / $this->rowsPerPage); return array( //if the current page is greater than the last page, set the current page to the last page 'page' => $page > $last ? $last : $page, 'last' => $last, 'total' => $numRows, ); }
[ "public", "function", "performCountQuery", "(", "QueryBuilder", "$", "countQuery", ",", "$", "querySql", ",", "$", "queryBindings", ",", "$", "page", ")", "{", "//grab the model instance", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "...
Performs the count query and returns info about the pages. @param \Illuminate\Database\Query\Builder $countQuery @param string $querySql @param array $queryBindings @param int $page @return array
[ "Performs", "the", "count", "query", "and", "returns", "info", "about", "the", "pages", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L189-L209
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.setFilters
public function setFilters($filters, QueryBuilder &$query, QueryBuilder &$countQuery, &$selects) { //then we set the filters if ($filters && is_array($filters)) { foreach ($filters as $filter) { //get the field object $fieldObject = $this->fieldFactory->findFilter($filter['field_name']); //set the filter on the object $fieldObject->setFilter($filter); //filter the query objects, only pass in the selects the first time so they aren't added twice $fieldObject->filterQuery($query, $selects); $fieldObject->filterQuery($countQuery); } } }
php
public function setFilters($filters, QueryBuilder &$query, QueryBuilder &$countQuery, &$selects) { //then we set the filters if ($filters && is_array($filters)) { foreach ($filters as $filter) { //get the field object $fieldObject = $this->fieldFactory->findFilter($filter['field_name']); //set the filter on the object $fieldObject->setFilter($filter); //filter the query objects, only pass in the selects the first time so they aren't added twice $fieldObject->filterQuery($query, $selects); $fieldObject->filterQuery($countQuery); } } }
[ "public", "function", "setFilters", "(", "$", "filters", ",", "QueryBuilder", "&", "$", "query", ",", "QueryBuilder", "&", "$", "countQuery", ",", "&", "$", "selects", ")", "{", "//then we set the filters", "if", "(", "$", "filters", "&&", "is_array", "(", ...
Sets the query filters when getting the rows. @param mixed $filters @param \Illuminate\Database\Query\Builder $query @param \Illuminate\Database\Query\Builder $countQuery @param array $selects
[ "Sets", "the", "query", "filters", "when", "getting", "the", "rows", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L219-L235
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.parseResults
public function parseResults($rows) { $results = array(); //convert the resulting set into arrays foreach ($rows as $item) { //iterate over the included and related columns $arr = array(); $this->parseOnTableColumns($item, $arr); //then grab the computed, unsortable columns $this->parseComputedColumns($item, $arr); $results[] = $arr; } return $results; }
php
public function parseResults($rows) { $results = array(); //convert the resulting set into arrays foreach ($rows as $item) { //iterate over the included and related columns $arr = array(); $this->parseOnTableColumns($item, $arr); //then grab the computed, unsortable columns $this->parseComputedColumns($item, $arr); $results[] = $arr; } return $results; }
[ "public", "function", "parseResults", "(", "$", "rows", ")", "{", "$", "results", "=", "array", "(", ")", ";", "//convert the resulting set into arrays", "foreach", "(", "$", "rows", "as", "$", "item", ")", "{", "//iterate over the included and related columns", "...
Parses the results of a getRows query and converts it into a manageable array with the proper rendering. @param Collection $rows @return array
[ "Parses", "the", "results", "of", "a", "getRows", "query", "and", "converts", "it", "into", "a", "manageable", "array", "with", "the", "proper", "rendering", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L244-L262
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.parseOnTableColumns
public function parseOnTableColumns($item, array &$outputRow) { if (method_exists($item, 'presenter')) { $item = $item->presenter(); } $columns = $this->columnFactory->getColumns(); $includedColumns = $this->columnFactory->getIncludedColumns($this->fieldFactory->getEditFields()); $relatedColumns = $this->columnFactory->getRelatedColumns(); //loop over both the included and related columns foreach (array_merge($includedColumns, $relatedColumns) as $field => $col) { // $attributeValue = $item->getAttribute($field); $attributeValue = $item->$field; //if this column is in our objects array, render the output with the given value if (isset($columns[$field])) { $outputRow[$field] = array( 'raw' => $attributeValue, 'rendered' => $columns[$field]->renderOutput($attributeValue, $item), ); } //otherwise it's likely the primary key column which wasn't included (though it's needed for identification purposes) else { $outputRow[$field] = array( 'raw' => $attributeValue, 'rendered' => $attributeValue, ); } } }
php
public function parseOnTableColumns($item, array &$outputRow) { if (method_exists($item, 'presenter')) { $item = $item->presenter(); } $columns = $this->columnFactory->getColumns(); $includedColumns = $this->columnFactory->getIncludedColumns($this->fieldFactory->getEditFields()); $relatedColumns = $this->columnFactory->getRelatedColumns(); //loop over both the included and related columns foreach (array_merge($includedColumns, $relatedColumns) as $field => $col) { // $attributeValue = $item->getAttribute($field); $attributeValue = $item->$field; //if this column is in our objects array, render the output with the given value if (isset($columns[$field])) { $outputRow[$field] = array( 'raw' => $attributeValue, 'rendered' => $columns[$field]->renderOutput($attributeValue, $item), ); } //otherwise it's likely the primary key column which wasn't included (though it's needed for identification purposes) else { $outputRow[$field] = array( 'raw' => $attributeValue, 'rendered' => $attributeValue, ); } } }
[ "public", "function", "parseOnTableColumns", "(", "$", "item", ",", "array", "&", "$", "outputRow", ")", "{", "if", "(", "method_exists", "(", "$", "item", ",", "'presenter'", ")", ")", "{", "$", "item", "=", "$", "item", "->", "presenter", "(", ")", ...
Goes through all related columns and sets the proper values for this row. @param \Illuminate\Database\Eloquent\Model $item @param array $outputRow
[ "Goes", "through", "all", "related", "columns", "and", "sets", "the", "proper", "values", "for", "this", "row", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L270-L300
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.parseComputedColumns
public function parseComputedColumns($item, array &$outputRow) { $columns = $this->columnFactory->getColumns(); $computedColumns = $this->columnFactory->getComputedColumns(); //loop over the computed columns foreach ($computedColumns as $name => $column) { $outputRow[$name] = array( 'raw' => $item->{$name}, 'rendered' => $columns[$name]->renderOutput($item->{$name}, $item), ); } }
php
public function parseComputedColumns($item, array &$outputRow) { $columns = $this->columnFactory->getColumns(); $computedColumns = $this->columnFactory->getComputedColumns(); //loop over the computed columns foreach ($computedColumns as $name => $column) { $outputRow[$name] = array( 'raw' => $item->{$name}, 'rendered' => $columns[$name]->renderOutput($item->{$name}, $item), ); } }
[ "public", "function", "parseComputedColumns", "(", "$", "item", ",", "array", "&", "$", "outputRow", ")", "{", "$", "columns", "=", "$", "this", "->", "columnFactory", "->", "getColumns", "(", ")", ";", "$", "computedColumns", "=", "$", "this", "->", "co...
Goes through all computed columns and sets the proper values for this row. @param \Illuminate\Database\Eloquent\Model $item @param array $outputRow
[ "Goes", "through", "all", "computed", "columns", "and", "sets", "the", "proper", "values", "for", "this", "row", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L308-L320
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.setSort
public function setSort($sort = null) { $sort = $sort && is_array($sort) ? $sort : $this->config->getOption('sort'); //set the sort values $this->sort = array( 'field' => isset($sort['field']) ? $sort['field'] : $this->config->getDataModel()->getKeyName(), 'direction' => isset($sort['direction']) ? $sort['direction'] : 'desc', ); //if the sort direction isn't valid, set it to 'desc' if (!in_array($this->sort['direction'], array('asc', 'desc'))) { $this->sort['direction'] = 'desc'; } }
php
public function setSort($sort = null) { $sort = $sort && is_array($sort) ? $sort : $this->config->getOption('sort'); //set the sort values $this->sort = array( 'field' => isset($sort['field']) ? $sort['field'] : $this->config->getDataModel()->getKeyName(), 'direction' => isset($sort['direction']) ? $sort['direction'] : 'desc', ); //if the sort direction isn't valid, set it to 'desc' if (!in_array($this->sort['direction'], array('asc', 'desc'))) { $this->sort['direction'] = 'desc'; } }
[ "public", "function", "setSort", "(", "$", "sort", "=", "null", ")", "{", "$", "sort", "=", "$", "sort", "&&", "is_array", "(", "$", "sort", ")", "?", "$", "sort", ":", "$", "this", "->", "config", "->", "getOption", "(", "'sort'", ")", ";", "//s...
Sets up the sort options. @param array $sort
[ "Sets", "up", "the", "sort", "options", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L327-L341
summerblue/administrator
src/Frozennode/Administrator/DataTable/DataTable.php
DataTable.setRowsPerPage
public function setRowsPerPage(\Illuminate\Session\Store $session, $globalPerPage, $override = null) { if ($override) { $perPage = (int) $override; $session->put('administrator_'.$this->config->getOption('name').'_rows_per_page', $perPage); } $perPage = $session->get('administrator_'.$this->config->getOption('name').'_rows_per_page'); if (!$perPage) { $perPage = (int) $globalPerPage; } $this->rowsPerPage = $perPage; }
php
public function setRowsPerPage(\Illuminate\Session\Store $session, $globalPerPage, $override = null) { if ($override) { $perPage = (int) $override; $session->put('administrator_'.$this->config->getOption('name').'_rows_per_page', $perPage); } $perPage = $session->get('administrator_'.$this->config->getOption('name').'_rows_per_page'); if (!$perPage) { $perPage = (int) $globalPerPage; } $this->rowsPerPage = $perPage; }
[ "public", "function", "setRowsPerPage", "(", "\\", "Illuminate", "\\", "Session", "\\", "Store", "$", "session", ",", "$", "globalPerPage", ",", "$", "override", "=", "null", ")", "{", "if", "(", "$", "override", ")", "{", "$", "perPage", "=", "(", "in...
Set the number of rows per page for this data table. @param \Illuminate\Session\Store $session @param int $globalPerPage @param int $override //if provided, this will set the session's rows per page value
[ "Set", "the", "number", "of", "rows", "per", "page", "for", "this", "data", "table", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/DataTable.php#L360-L374
summerblue/administrator
src/Frozennode/Administrator/Validator.php
Validator.override
public function override($data, $rules) { $this->setData($data); $this->setRules($rules); $this->setCustomMessages($this->overrideCustomMessages); }
php
public function override($data, $rules) { $this->setData($data); $this->setRules($rules); $this->setCustomMessages($this->overrideCustomMessages); }
[ "public", "function", "override", "(", "$", "data", ",", "$", "rules", ")", "{", "$", "this", "->", "setData", "(", "$", "data", ")", ";", "$", "this", "->", "setRules", "(", "$", "rules", ")", ";", "$", "this", "->", "setCustomMessages", "(", "$",...
Overrides the rules and data. @param array $data @param array $rules
[ "Overrides", "the", "rules", "and", "data", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Validator.php#L50-L55
summerblue/administrator
src/Frozennode/Administrator/Validator.php
Validator.isJoined
public function isJoined($query, $table) { $tableFound = false; $query = is_a($query, 'Illuminate\Database\Query\Builder') ? $query : $query->getQuery(); if ($query->joins) { //iterate over the joins to see if the table is there foreach ($query->joins as $join) { if ($join->table === $table) { return true; } } } return false; }
php
public function isJoined($query, $table) { $tableFound = false; $query = is_a($query, 'Illuminate\Database\Query\Builder') ? $query : $query->getQuery(); if ($query->joins) { //iterate over the joins to see if the table is there foreach ($query->joins as $join) { if ($join->table === $table) { return true; } } } return false; }
[ "public", "function", "isJoined", "(", "$", "query", ",", "$", "table", ")", "{", "$", "tableFound", "=", "false", ";", "$", "query", "=", "is_a", "(", "$", "query", ",", "'Illuminate\\Database\\Query\\Builder'", ")", "?", "$", "query", ":", "$", "query"...
Checks if a table is already joined to a query object. @param Query $query @param string $table @return bool
[ "Checks", "if", "a", "table", "is", "already", "joined", "to", "a", "query", "object", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Validator.php#L105-L120
summerblue/administrator
src/Frozennode/Administrator/Validator.php
Validator.validateArrayWithAllOrNone
public function validateArrayWithAllOrNone($attribute, $value, $parameters) { $missing = 0; foreach ($parameters as $key) { if (!isset($value[$key])) { ++$missing; } } return $missing === count($parameters) || $missing === 0; }
php
public function validateArrayWithAllOrNone($attribute, $value, $parameters) { $missing = 0; foreach ($parameters as $key) { if (!isset($value[$key])) { ++$missing; } } return $missing === count($parameters) || $missing === 0; }
[ "public", "function", "validateArrayWithAllOrNone", "(", "$", "attribute", ",", "$", "value", ",", "$", "parameters", ")", "{", "$", "missing", "=", "0", ";", "foreach", "(", "$", "parameters", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", ...
Validates that an item is an array.
[ "Validates", "that", "an", "item", "is", "an", "array", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Validator.php#L141-L152
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getColumnObject
public function getColumnObject($options) { $class = $this->getColumnClassName($options); return new $class($this->validator, $this->config, $this->db, $options); }
php
public function getColumnObject($options) { $class = $this->getColumnClassName($options); return new $class($this->validator, $this->config, $this->db, $options); }
[ "public", "function", "getColumnObject", "(", "$", "options", ")", "{", "$", "class", "=", "$", "this", "->", "getColumnClassName", "(", "$", "options", ")", ";", "return", "new", "$", "class", "(", "$", "this", "->", "validator", ",", "$", "this", "->...
Creates the Column instance. @param array $options @return \Frozennode\Administrator\DataTable\Columns\Column
[ "Creates", "the", "Column", "instance", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L131-L136
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getColumns
public function getColumns() { //make sure we only run this once and then return the cached version if (empty($this->columns)) { foreach ($this->config->getOption('columns') as $name => $options) { //if only a string value was supplied, may sure to turn it into an array $object = $this->make($this->parseOptions($name, $options)); $this->columns[$object->getOption('column_name')] = $object; } } return $this->columns; }
php
public function getColumns() { //make sure we only run this once and then return the cached version if (empty($this->columns)) { foreach ($this->config->getOption('columns') as $name => $options) { //if only a string value was supplied, may sure to turn it into an array $object = $this->make($this->parseOptions($name, $options)); $this->columns[$object->getOption('column_name')] = $object; } } return $this->columns; }
[ "public", "function", "getColumns", "(", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "empty", "(", "$", "this", "->", "columns", ")", ")", "{", "foreach", "(", "$", "this", "->", "config", "->", "getOption", "(", ...
Gets the column objects. @return array
[ "Gets", "the", "column", "objects", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L200-L212
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getColumnOptions
public function getColumnOptions() { //make sure we only run this once and then return the cached version if (empty($this->columnOptions)) { foreach ($this->getColumns() as $column) { $this->columnOptions[] = $column->getOptions(); } } return $this->columnOptions; }
php
public function getColumnOptions() { //make sure we only run this once and then return the cached version if (empty($this->columnOptions)) { foreach ($this->getColumns() as $column) { $this->columnOptions[] = $column->getOptions(); } } return $this->columnOptions; }
[ "public", "function", "getColumnOptions", "(", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "empty", "(", "$", "this", "->", "columnOptions", ")", ")", "{", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", ...
Gets the column objects as an integer-indexed array. @return array
[ "Gets", "the", "column", "objects", "as", "an", "integer", "-", "indexed", "array", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L219-L229
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getIncludedColumns
public function getIncludedColumns(array $fields) { //make sure we only run this once and then return the cached version if (empty($this->includedColumns)) { $model = $this->config->getDataModel(); foreach ($this->getColumns() as $column) { if ($column->getOption('is_related')) { $this->includedColumns = array_merge($this->includedColumns, $column->getIncludedColumn()); } elseif (!$column->getOption('is_computed')) { $this->includedColumns[$column->getOption('column_name')] = $model->getTable().'.'.$column->getOption('column_name'); } } //make sure the table key is included if (!$this->validator->arrayGet($this->includedColumns, $model->getKeyName())) { $this->includedColumns[$model->getKeyName()] = $model->getTable().'.'.$model->getKeyName(); } //make sure any belongs_to fields that aren't on the columns list are included foreach ($fields as $field) { if (is_a($field, 'Frozennode\\Administrator\\Fields\\Relationships\\BelongsTo')) { $this->includedColumns[$field->getOption('foreign_key')] = $model->getTable().'.'.$field->getOption('foreign_key'); } } } return $this->includedColumns; }
php
public function getIncludedColumns(array $fields) { //make sure we only run this once and then return the cached version if (empty($this->includedColumns)) { $model = $this->config->getDataModel(); foreach ($this->getColumns() as $column) { if ($column->getOption('is_related')) { $this->includedColumns = array_merge($this->includedColumns, $column->getIncludedColumn()); } elseif (!$column->getOption('is_computed')) { $this->includedColumns[$column->getOption('column_name')] = $model->getTable().'.'.$column->getOption('column_name'); } } //make sure the table key is included if (!$this->validator->arrayGet($this->includedColumns, $model->getKeyName())) { $this->includedColumns[$model->getKeyName()] = $model->getTable().'.'.$model->getKeyName(); } //make sure any belongs_to fields that aren't on the columns list are included foreach ($fields as $field) { if (is_a($field, 'Frozennode\\Administrator\\Fields\\Relationships\\BelongsTo')) { $this->includedColumns[$field->getOption('foreign_key')] = $model->getTable().'.'.$field->getOption('foreign_key'); } } } return $this->includedColumns; }
[ "public", "function", "getIncludedColumns", "(", "array", "$", "fields", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "empty", "(", "$", "this", "->", "includedColumns", ")", ")", "{", "$", "model", "=", "$", "this", ...
Gets the columns that are on the model's table (i.e. not related or computed). @param array $fields @return array
[ "Gets", "the", "columns", "that", "are", "on", "the", "model", "s", "table", "(", "i", ".", "e", ".", "not", "related", "or", "computed", ")", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L238-L266
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getRelatedColumns
public function getRelatedColumns() { //make sure we only run this once and then return the cached version if (empty($this->relatedColumns)) { foreach ($this->getColumns() as $column) { if ($column->getOption('is_related')) { $this->relatedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->relatedColumns; }
php
public function getRelatedColumns() { //make sure we only run this once and then return the cached version if (empty($this->relatedColumns)) { foreach ($this->getColumns() as $column) { if ($column->getOption('is_related')) { $this->relatedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->relatedColumns; }
[ "public", "function", "getRelatedColumns", "(", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "empty", "(", "$", "this", "->", "relatedColumns", ")", ")", "{", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", ...
Gets the columns that are relationship columns. @return array
[ "Gets", "the", "columns", "that", "are", "relationship", "columns", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L273-L285
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Factory.php
Factory.getComputedColumns
public function getComputedColumns() { //make sure we only run this once and then return the cached version if (empty($this->computedColumns)) { foreach ($this->getColumns() as $column) { if (!$column->getOption('is_related') && $column->getOption('is_computed')) { $this->computedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->computedColumns; }
php
public function getComputedColumns() { //make sure we only run this once and then return the cached version if (empty($this->computedColumns)) { foreach ($this->getColumns() as $column) { if (!$column->getOption('is_related') && $column->getOption('is_computed')) { $this->computedColumns[$column->getOption('column_name')] = $column->getOption('column_name'); } } } return $this->computedColumns; }
[ "public", "function", "getComputedColumns", "(", ")", "{", "//make sure we only run this once and then return the cached version", "if", "(", "empty", "(", "$", "this", "->", "computedColumns", ")", ")", "{", "foreach", "(", "$", "this", "->", "getColumns", "(", ")"...
Gets the columns that are computed. @return array
[ "Gets", "the", "columns", "that", "are", "computed", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Factory.php#L292-L304
summerblue/administrator
src/Frozennode/Administrator/Fields/File.php
File.build
public function build() { parent::build(); //set the upload url depending on the type of config this is $url = $this->validator->getUrlInstance(); $route = $this->config->getType() === 'settings' ? 'admin_settings_file_upload' : 'admin_file_upload'; //set the upload url to the proper route $this->suppliedOptions['upload_url'] = $url->route($route, array($this->config->getOption('name'), $this->suppliedOptions['field_name'])); }
php
public function build() { parent::build(); //set the upload url depending on the type of config this is $url = $this->validator->getUrlInstance(); $route = $this->config->getType() === 'settings' ? 'admin_settings_file_upload' : 'admin_file_upload'; //set the upload url to the proper route $this->suppliedOptions['upload_url'] = $url->route($route, array($this->config->getOption('name'), $this->suppliedOptions['field_name'])); }
[ "public", "function", "build", "(", ")", "{", "parent", "::", "build", "(", ")", ";", "//set the upload url depending on the type of config this is", "$", "url", "=", "$", "this", "->", "validator", "->", "getUrlInstance", "(", ")", ";", "$", "route", "=", "$"...
Builds a few basic options
[ "Builds", "a", "few", "basic", "options" ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/File.php#L36-L46
summerblue/administrator
src/Frozennode/Administrator/Fields/File.php
File.doUpload
public function doUpload() { $mimes = $this->getOption('mimes') ? '|mimes:' . $this->getOption('mimes') : ''; //use the multup library to perform the upload $result = Multup::open('file', 'max:' . $this->getOption('size_limit') * 1000 . $mimes, $this->getOption('location'), $this->getOption('naming') === 'random') ->set_length($this->getOption('length')) ->upload(); return $result[0]; }
php
public function doUpload() { $mimes = $this->getOption('mimes') ? '|mimes:' . $this->getOption('mimes') : ''; //use the multup library to perform the upload $result = Multup::open('file', 'max:' . $this->getOption('size_limit') * 1000 . $mimes, $this->getOption('location'), $this->getOption('naming') === 'random') ->set_length($this->getOption('length')) ->upload(); return $result[0]; }
[ "public", "function", "doUpload", "(", ")", "{", "$", "mimes", "=", "$", "this", "->", "getOption", "(", "'mimes'", ")", "?", "'|mimes:'", ".", "$", "this", "->", "getOption", "(", "'mimes'", ")", ":", "''", ";", "//use the multup library to perform the uplo...
This static function is used to perform the actual upload and resizing using the Multup class @return array
[ "This", "static", "function", "is", "used", "to", "perform", "the", "actual", "upload", "and", "resizing", "using", "the", "Multup", "class" ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/File.php#L53-L64
summerblue/administrator
src/Frozennode/Administrator/Fields/Time.php
Time.filterQuery
public function filterQuery(QueryBuilder &$query, &$selects = null) { $model = $this->config->getDataModel(); //try to read the time for the min and max values, and if they check out, set the where if ($minValue = $this->getOption('min_value')) { $time = new DateTime($minValue); if ($time !== false) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '>=', $this->getDateString($time)); } } if ($maxValue = $this->getOption('max_value')) { $time = new DateTime($maxValue); if ($time !== false) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '<=', $this->getDateString($time)); } } }
php
public function filterQuery(QueryBuilder &$query, &$selects = null) { $model = $this->config->getDataModel(); //try to read the time for the min and max values, and if they check out, set the where if ($minValue = $this->getOption('min_value')) { $time = new DateTime($minValue); if ($time !== false) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '>=', $this->getDateString($time)); } } if ($maxValue = $this->getOption('max_value')) { $time = new DateTime($maxValue); if ($time !== false) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '<=', $this->getDateString($time)); } } }
[ "public", "function", "filterQuery", "(", "QueryBuilder", "&", "$", "query", ",", "&", "$", "selects", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "//try to read the time for the min and max value...
Filters a query object. @param \Illuminate\Database\Query\Builder $query @param array $selects
[ "Filters", "a", "query", "object", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Time.php#L37-L57
summerblue/administrator
src/Frozennode/Administrator/Fields/Time.php
Time.fillModel
public function fillModel(&$model, $input) { $time = false; $field_name = $this->getOption('field_name'); if (empty($input) && $field_name) { $model->{$field_name} = null; return; } elseif (!empty($input) && $input !== '0000-00-00') { $time = new DateTime($input); } //first we validate that it's a date/time if ($time !== false) { //fill the model with the correct date/time format $model->{$field_name} = $this->getDateString($time); } }
php
public function fillModel(&$model, $input) { $time = false; $field_name = $this->getOption('field_name'); if (empty($input) && $field_name) { $model->{$field_name} = null; return; } elseif (!empty($input) && $input !== '0000-00-00') { $time = new DateTime($input); } //first we validate that it's a date/time if ($time !== false) { //fill the model with the correct date/time format $model->{$field_name} = $this->getDateString($time); } }
[ "public", "function", "fillModel", "(", "&", "$", "model", ",", "$", "input", ")", "{", "$", "time", "=", "false", ";", "$", "field_name", "=", "$", "this", "->", "getOption", "(", "'field_name'", ")", ";", "if", "(", "empty", "(", "$", "input", ")...
Fill a model with input data. @param \Illuminate\Database\Eloquent\Model $model @param mixed $input @return array
[ "Fill", "a", "model", "with", "input", "data", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Time.php#L67-L85
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getModel
public function getModel($id = 0, array $fields, array $columns) { //if we're getting an existing model, we'll want to first get the edit fields without the relationships loaded $originalModel = $model = $this->getDataModel(); //get the model by id $model = $model->find($id); $model = $model ? $model : $originalModel; //if the model exists, load up the existing related items if ($model->exists) { $this->setExtraModelValues($fields, $model); } return $model; }
php
public function getModel($id = 0, array $fields, array $columns) { //if we're getting an existing model, we'll want to first get the edit fields without the relationships loaded $originalModel = $model = $this->getDataModel(); //get the model by id $model = $model->find($id); $model = $model ? $model : $originalModel; //if the model exists, load up the existing related items if ($model->exists) { $this->setExtraModelValues($fields, $model); } return $model; }
[ "public", "function", "getModel", "(", "$", "id", "=", "0", ",", "array", "$", "fields", ",", "array", "$", "columns", ")", "{", "//if we're getting an existing model, we'll want to first get the edit fields without the relationships loaded", "$", "originalModel", "=", "$...
Gets a model given an id. @param id $id @param array $fields @param array $columns @return \Illuminate\Database\Eloquent\Model
[ "Gets", "a", "model", "given", "an", "id", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L112-L127
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.setExtraModelValues
public function setExtraModelValues(array $fields, &$model) { //make sure the relationships are loaded foreach ($fields as $name => $field) { if ($field->getOption('relationship')) { $this->setModelRelationship($model, $field); } //if this is a setter field, unset it if ($field->getOption('setter')) { $model->__unset($name); } } }
php
public function setExtraModelValues(array $fields, &$model) { //make sure the relationships are loaded foreach ($fields as $name => $field) { if ($field->getOption('relationship')) { $this->setModelRelationship($model, $field); } //if this is a setter field, unset it if ($field->getOption('setter')) { $model->__unset($name); } } }
[ "public", "function", "setExtraModelValues", "(", "array", "$", "fields", ",", "&", "$", "model", ")", "{", "//make sure the relationships are loaded", "foreach", "(", "$", "fields", "as", "$", "name", "=>", "$", "field", ")", "{", "if", "(", "$", "field", ...
Fills a model with the data it needs before being sent back to the user. @param array $fields @param \Illuminate\Database\Eloquent\Model $model
[ "Fills", "a", "model", "with", "the", "data", "it", "needs", "before", "being", "sent", "back", "to", "the", "user", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L135-L148
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.setModelRelationship
public function setModelRelationship(&$model, Field $field) { //if this is a belongsToMany, we want to sort our initial values $relatedItems = $this->getModelRelatedItems($model, $field); $name = $field->getOption('field_name'); $multipleValues = $field->getOption('multiple_values'); $nameField = $field->getOption('name_field'); $autocomplete = $field->getOption('autocomplete'); $options = $field->getOption('options'); //get all existing values for this relationship if ($relatedItems) { //the array that holds all the ids of the currently-related items $relationsArray = array(); //the id-indexed array that holds all of the select option data for a relation. //this holds the currently-related items and all of the available options $autocompleteArray = array(); //iterate over the items foreach ($relatedItems as $item) { $keyName = $item->getKeyName(); //if this is a mutliple-value type (i.e. HasMany, BelongsToMany), make sure this is an array if ($multipleValues) { $relationsArray[] = $item->{$keyName}; } else { $model->setAttribute($name, $item->{$keyName}); } //if this is an autocomplete field, we'll need to provide an array of arrays with 'id' and 'text' indexes if ($autocomplete) { $autocompleteArray[$item->{$keyName}] = array('id' => $item->{$keyName}, 'text' => $item->{$nameField}); } } //if this is a BTM, set the relations array to the property that matches the relationship name if ($multipleValues) { $model->{$name} = $relationsArray; } //set the options attribute $model->setAttribute($name.'_options', $options); //unset the relationships so we only get back what we need $model->relationships = array(); //set the autocomplete array if ($autocomplete) { $model->setAttribute($name.'_autocomplete', $autocompleteArray); } } //if there are no values, then just set an empty array else { $model->{$name} = array(); } }
php
public function setModelRelationship(&$model, Field $field) { //if this is a belongsToMany, we want to sort our initial values $relatedItems = $this->getModelRelatedItems($model, $field); $name = $field->getOption('field_name'); $multipleValues = $field->getOption('multiple_values'); $nameField = $field->getOption('name_field'); $autocomplete = $field->getOption('autocomplete'); $options = $field->getOption('options'); //get all existing values for this relationship if ($relatedItems) { //the array that holds all the ids of the currently-related items $relationsArray = array(); //the id-indexed array that holds all of the select option data for a relation. //this holds the currently-related items and all of the available options $autocompleteArray = array(); //iterate over the items foreach ($relatedItems as $item) { $keyName = $item->getKeyName(); //if this is a mutliple-value type (i.e. HasMany, BelongsToMany), make sure this is an array if ($multipleValues) { $relationsArray[] = $item->{$keyName}; } else { $model->setAttribute($name, $item->{$keyName}); } //if this is an autocomplete field, we'll need to provide an array of arrays with 'id' and 'text' indexes if ($autocomplete) { $autocompleteArray[$item->{$keyName}] = array('id' => $item->{$keyName}, 'text' => $item->{$nameField}); } } //if this is a BTM, set the relations array to the property that matches the relationship name if ($multipleValues) { $model->{$name} = $relationsArray; } //set the options attribute $model->setAttribute($name.'_options', $options); //unset the relationships so we only get back what we need $model->relationships = array(); //set the autocomplete array if ($autocomplete) { $model->setAttribute($name.'_autocomplete', $autocompleteArray); } } //if there are no values, then just set an empty array else { $model->{$name} = array(); } }
[ "public", "function", "setModelRelationship", "(", "&", "$", "model", ",", "Field", "$", "field", ")", "{", "//if this is a belongsToMany, we want to sort our initial values", "$", "relatedItems", "=", "$", "this", "->", "getModelRelatedItems", "(", "$", "model", ",",...
Fills a model with the necessary relationship values for a field. @param \Illuminate\Database\Eloquent\Model $model @param \Frozennode\Administrator\Fields\Field $field
[ "Fills", "a", "model", "with", "the", "necessary", "relationship", "values", "for", "a", "field", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L156-L212
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getModelRelatedItems
public function getModelRelatedItems($model, Field $field) { $name = $field->getOption('field_name'); if ($field->getOption('multiple_values')) { //if a sort_field is provided, use it, otherwise sort by the name field if ($sortField = $field->getOption('sort_field')) { return $model->{$name}()->orderBy($sortField)->get(); } else { return $model->{$name}()->get(); } } else { return $model->{$name}()->get(); } }
php
public function getModelRelatedItems($model, Field $field) { $name = $field->getOption('field_name'); if ($field->getOption('multiple_values')) { //if a sort_field is provided, use it, otherwise sort by the name field if ($sortField = $field->getOption('sort_field')) { return $model->{$name}()->orderBy($sortField)->get(); } else { return $model->{$name}()->get(); } } else { return $model->{$name}()->get(); } }
[ "public", "function", "getModelRelatedItems", "(", "$", "model", ",", "Field", "$", "field", ")", "{", "$", "name", "=", "$", "field", "->", "getOption", "(", "'field_name'", ")", ";", "if", "(", "$", "field", "->", "getOption", "(", "'multiple_values'", ...
Fills a model with the necessary relationship values. @param \Illuminate\Database\Eloquent\Model $model @param \Frozennode\Administrator\Fields\Field $field @return \Illuminate\Database\Eloquent\Collection
[ "Fills", "a", "model", "with", "the", "necessary", "relationship", "values", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L222-L236
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.updateModel
public function updateModel($model, FieldFactory $fieldFactory, ActionFactory $actionFactory) { //set the data model to the active model $this->setDataModel($model->find($model->getKey())); //include the item link if one was supplied if ($link = $this->getModelLink()) { $model->setAttribute('admin_item_link', $link); } //set up the model with the edit fields new data $model->setAttribute('administrator_edit_fields', $fieldFactory->getEditFieldsArrays(true)); //set up the new actions data $model->setAttribute('administrator_actions', $actionFactory->getActionsOptions(true)); $model->setAttribute('administrator_action_permissions', $actionFactory->getActionPermissions(true)); return $model; }
php
public function updateModel($model, FieldFactory $fieldFactory, ActionFactory $actionFactory) { //set the data model to the active model $this->setDataModel($model->find($model->getKey())); //include the item link if one was supplied if ($link = $this->getModelLink()) { $model->setAttribute('admin_item_link', $link); } //set up the model with the edit fields new data $model->setAttribute('administrator_edit_fields', $fieldFactory->getEditFieldsArrays(true)); //set up the new actions data $model->setAttribute('administrator_actions', $actionFactory->getActionsOptions(true)); $model->setAttribute('administrator_action_permissions', $actionFactory->getActionPermissions(true)); return $model; }
[ "public", "function", "updateModel", "(", "$", "model", ",", "FieldFactory", "$", "fieldFactory", ",", "ActionFactory", "$", "actionFactory", ")", "{", "//set the data model to the active model", "$", "this", "->", "setDataModel", "(", "$", "model", "->", "find", ...
Updates a model with the latest permissions, links, and fields. @param \Illuminate\Database\Eloquent\Model $model @param \Frozennode\Administrator\Fields\Factory $fieldFactory @param \Frozennode\Administrator\Actions\Factory $actionFactory @return \Illuminate\Database\Eloquent\Model
[ "Updates", "a", "model", "with", "the", "latest", "permissions", "links", "and", "fields", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L247-L265
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.save
public function save(\Illuminate\Http\Request $input, array $fields, array $actionPermissions = null, $id = 0) { $model = $this->getDataModel()->find($id); //fetch the proper model so we don't have to deal with any extra attributes if (!$model) { $model = $this->getDataModel(); } //make sure the user has the proper permissions if ($model->exists) { if (!$actionPermissions['update']) { return 'You do not have permission to save this item'; } } elseif (!$actionPermissions['update'] || !$actionPermissions['create']) { return 'You do not have permission to create this item'; } //fill the model with our input $this->fillModel($model, $input, $fields); //validate the model $data = $model->exists ? $model->getDirty() : $model->getAttributes(); $validation_data = array_merge($data, $this->getRelationshipInputs($input, $fields)); $rules = $this->getModelValidationRules(); $rules = $model->exists ? array_intersect_key($rules, $validation_data) : $rules; $messages = $this->getModelValidationMessages(); $validation = $this->validateData($validation_data, $rules, $messages); //if a string was kicked back, it's an error, so return it if (is_string($validation)) { return $validation; } //save the model $model->save(); //save the relationships $this->saveRelationships($input, $model, $fields); //set/update the data model $this->setDataModel($model); return true; }
php
public function save(\Illuminate\Http\Request $input, array $fields, array $actionPermissions = null, $id = 0) { $model = $this->getDataModel()->find($id); //fetch the proper model so we don't have to deal with any extra attributes if (!$model) { $model = $this->getDataModel(); } //make sure the user has the proper permissions if ($model->exists) { if (!$actionPermissions['update']) { return 'You do not have permission to save this item'; } } elseif (!$actionPermissions['update'] || !$actionPermissions['create']) { return 'You do not have permission to create this item'; } //fill the model with our input $this->fillModel($model, $input, $fields); //validate the model $data = $model->exists ? $model->getDirty() : $model->getAttributes(); $validation_data = array_merge($data, $this->getRelationshipInputs($input, $fields)); $rules = $this->getModelValidationRules(); $rules = $model->exists ? array_intersect_key($rules, $validation_data) : $rules; $messages = $this->getModelValidationMessages(); $validation = $this->validateData($validation_data, $rules, $messages); //if a string was kicked back, it's an error, so return it if (is_string($validation)) { return $validation; } //save the model $model->save(); //save the relationships $this->saveRelationships($input, $model, $fields); //set/update the data model $this->setDataModel($model); return true; }
[ "public", "function", "save", "(", "\\", "Illuminate", "\\", "Http", "\\", "Request", "$", "input", ",", "array", "$", "fields", ",", "array", "$", "actionPermissions", "=", "null", ",", "$", "id", "=", "0", ")", "{", "$", "model", "=", "$", "this", ...
Saves the model. @param \Illuminate\Http\Request $input @param array $fields @param array $actionPermissions @param int $id @return mixed //string if error, true if success
[ "Saves", "the", "model", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L277-L321
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.fillModel
public function fillModel(&$model, \Illuminate\Http\Request $input, array $fields) { //run through the edit fields to see if we need to unset relationships or uneditable fields foreach ($fields as $name => $field) { if (!$field->getOption('external') && $field->getOption('editable')) { $field->fillModel($model, $input->get($name, null)); } //if this is an "external" field (i.e. it's not a column on this model's table) or uneditable, unset it elseif ($name !== $model->getKeyName()) { $model->__unset($name); } } //loop through the fields again to unset any setter fields foreach ($fields as $name => $field) { $type = $field->getOption('type'); if (($field->getOption('setter') && $type !== 'password') || ($type === 'password' && empty($model->{$name}))) { $model->__unset($name); } } }
php
public function fillModel(&$model, \Illuminate\Http\Request $input, array $fields) { //run through the edit fields to see if we need to unset relationships or uneditable fields foreach ($fields as $name => $field) { if (!$field->getOption('external') && $field->getOption('editable')) { $field->fillModel($model, $input->get($name, null)); } //if this is an "external" field (i.e. it's not a column on this model's table) or uneditable, unset it elseif ($name !== $model->getKeyName()) { $model->__unset($name); } } //loop through the fields again to unset any setter fields foreach ($fields as $name => $field) { $type = $field->getOption('type'); if (($field->getOption('setter') && $type !== 'password') || ($type === 'password' && empty($model->{$name}))) { $model->__unset($name); } } }
[ "public", "function", "fillModel", "(", "&", "$", "model", ",", "\\", "Illuminate", "\\", "Http", "\\", "Request", "$", "input", ",", "array", "$", "fields", ")", "{", "//run through the edit fields to see if we need to unset relationships or uneditable fields", "foreac...
Prepare a model for saving given a post input array. @param \Illuminate\Database\Eloquent\Model $model @param \Illuminate\Http\Request $input @param array $fields
[ "Prepare", "a", "model", "for", "saving", "given", "a", "post", "input", "array", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L330-L351
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getModelValidationRules
public function getModelValidationRules() { $optionsRules = $this->getOption('rules'); //if the 'rules' option was provided for this model, it takes precedent if (is_array($optionsRules)) { return $optionsRules; } //otherwise look for the rules as a static property on the model return $rules = $this->getModelStaticValidationRules() ?: array(); }
php
public function getModelValidationRules() { $optionsRules = $this->getOption('rules'); //if the 'rules' option was provided for this model, it takes precedent if (is_array($optionsRules)) { return $optionsRules; } //otherwise look for the rules as a static property on the model return $rules = $this->getModelStaticValidationRules() ?: array(); }
[ "public", "function", "getModelValidationRules", "(", ")", "{", "$", "optionsRules", "=", "$", "this", "->", "getOption", "(", "'rules'", ")", ";", "//if the 'rules' option was provided for this model, it takes precedent", "if", "(", "is_array", "(", "$", "optionsRules"...
Gets the validation rules for this model. @return array
[ "Gets", "the", "validation", "rules", "for", "this", "model", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L358-L369
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getModelValidationMessages
public function getModelValidationMessages() { $optionsMessages = $this->getOption('messages'); //if the 'rules' option was provided for this model, it takes precedent if (is_array($optionsMessages)) { return $optionsMessages; } //otherwise look for the messages as a static property on the model return $rules = $this->getModelStaticValidationMessages() ?: array(); }
php
public function getModelValidationMessages() { $optionsMessages = $this->getOption('messages'); //if the 'rules' option was provided for this model, it takes precedent if (is_array($optionsMessages)) { return $optionsMessages; } //otherwise look for the messages as a static property on the model return $rules = $this->getModelStaticValidationMessages() ?: array(); }
[ "public", "function", "getModelValidationMessages", "(", ")", "{", "$", "optionsMessages", "=", "$", "this", "->", "getOption", "(", "'messages'", ")", ";", "//if the 'rules' option was provided for this model, it takes precedent", "if", "(", "is_array", "(", "$", "opti...
Gets the validation messages for this model. @return array
[ "Gets", "the", "validation", "messages", "for", "this", "model", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L376-L387
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getModelStaticValidationRules
public function getModelStaticValidationRules() { $model = $this->getDataModel(); return isset($model::$rules) && is_array($model::$rules) ? $model::$rules : false; }
php
public function getModelStaticValidationRules() { $model = $this->getDataModel(); return isset($model::$rules) && is_array($model::$rules) ? $model::$rules : false; }
[ "public", "function", "getModelStaticValidationRules", "(", ")", "{", "$", "model", "=", "$", "this", "->", "getDataModel", "(", ")", ";", "return", "isset", "(", "$", "model", "::", "$", "rules", ")", "&&", "is_array", "(", "$", "model", "::", "$", "r...
Gets the static rules propery for a model if one exists. @return mixed
[ "Gets", "the", "static", "rules", "propery", "for", "a", "model", "if", "one", "exists", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L394-L399
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getModelStaticValidationMessages
public function getModelStaticValidationMessages() { $model = $this->getDataModel(); return isset($model::$messages) && is_array($model::$messages) ? $model::$messages : false; }
php
public function getModelStaticValidationMessages() { $model = $this->getDataModel(); return isset($model::$messages) && is_array($model::$messages) ? $model::$messages : false; }
[ "public", "function", "getModelStaticValidationMessages", "(", ")", "{", "$", "model", "=", "$", "this", "->", "getDataModel", "(", ")", ";", "return", "isset", "(", "$", "model", "::", "$", "messages", ")", "&&", "is_array", "(", "$", "model", "::", "$"...
Gets the static messages propery for a model if one exists. @return mixed
[ "Gets", "the", "static", "messages", "propery", "for", "a", "model", "if", "one", "exists", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L406-L411
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.formatRelationshipInput
protected function formatRelationshipInput($value, Field $field) { $value = trim($value); if ($field->getOption('multiple_values')) { $value = $value ? explode(',', $value) : array(); } return $value; }
php
protected function formatRelationshipInput($value, Field $field) { $value = trim($value); if ($field->getOption('multiple_values')) { $value = $value ? explode(',', $value) : array(); } return $value; }
[ "protected", "function", "formatRelationshipInput", "(", "$", "value", ",", "Field", "$", "field", ")", "{", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "if", "(", "$", "field", "->", "getOption", "(", "'multiple_values'", ")", ")", "{", "$...
Gets the formatted value of a relationship input. @param string $value @param \Frozennode\Administrator\Fields\Field $field @return mixed array | string
[ "Gets", "the", "formatted", "value", "of", "a", "relationship", "input", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L443-L452
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.saveRelationships
public function saveRelationships(\Illuminate\Http\Request $input, &$model, array $fields) { //run through the edit fields to see if we need to set relationships foreach ($fields as $name => $field) { if ($field->getOption('external')) { $field->fillModel($model, $input->get($name, null)); } } }
php
public function saveRelationships(\Illuminate\Http\Request $input, &$model, array $fields) { //run through the edit fields to see if we need to set relationships foreach ($fields as $name => $field) { if ($field->getOption('external')) { $field->fillModel($model, $input->get($name, null)); } } }
[ "public", "function", "saveRelationships", "(", "\\", "Illuminate", "\\", "Http", "\\", "Request", "$", "input", ",", "&", "$", "model", ",", "array", "$", "fields", ")", "{", "//run through the edit fields to see if we need to set relationships", "foreach", "(", "$...
After a model has been saved, this is called to save the relationships. @param \Illuminate\Http\Request $input @param \Illuminate\Database\Eloquent\Model $model @param array $fields
[ "After", "a", "model", "has", "been", "saved", "this", "is", "called", "to", "save", "the", "relationships", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L461-L469
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getModelLink
public function getModelLink() { $linkCallback = $this->getOption('link'); if ($linkCallback && is_callable($linkCallback)) { return $linkCallback($this->getDataModel()); } else { return false; } }
php
public function getModelLink() { $linkCallback = $this->getOption('link'); if ($linkCallback && is_callable($linkCallback)) { return $linkCallback($this->getDataModel()); } else { return false; } }
[ "public", "function", "getModelLink", "(", ")", "{", "$", "linkCallback", "=", "$", "this", "->", "getOption", "(", "'link'", ")", ";", "if", "(", "$", "linkCallback", "&&", "is_callable", "(", "$", "linkCallback", ")", ")", "{", "return", "$", "linkCall...
Gets a model's link if one was provided, substituting for field names with this format: (:field_name). @return mixed
[ "Gets", "a", "model", "s", "link", "if", "one", "was", "provided", "substituting", "for", "field", "names", "with", "this", "format", ":", "(", ":", "field_name", ")", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L476-L485
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.runQueryFilter
public function runQueryFilter(\Illuminate\Database\Query\Builder &$query) { if ($filter = $this->getOption('query_filter')) { $filter($query); } }
php
public function runQueryFilter(\Illuminate\Database\Query\Builder &$query) { if ($filter = $this->getOption('query_filter')) { $filter($query); } }
[ "public", "function", "runQueryFilter", "(", "\\", "Illuminate", "\\", "Database", "\\", "Query", "\\", "Builder", "&", "$", "query", ")", "{", "if", "(", "$", "filter", "=", "$", "this", "->", "getOption", "(", "'query_filter'", ")", ")", "{", "$", "f...
Runs a user-supplied query filter if one is supplied. @param \Illuminate\Database\Query\Builder $query
[ "Runs", "a", "user", "-", "supplied", "query", "filter", "if", "one", "is", "supplied", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L492-L497
summerblue/administrator
src/Frozennode/Administrator/Config/Model/Config.php
Config.getFilledDataModel
public function getFilledDataModel(\Illuminate\Http\Request $input, array $fields, $id = 0) { $model = $this->getDataModel(); if ($id) { $model = $model->find($id); } $this->fillModel($model, $input, $fields); return $model; }
php
public function getFilledDataModel(\Illuminate\Http\Request $input, array $fields, $id = 0) { $model = $this->getDataModel(); if ($id) { $model = $model->find($id); } $this->fillModel($model, $input, $fields); return $model; }
[ "public", "function", "getFilledDataModel", "(", "\\", "Illuminate", "\\", "Http", "\\", "Request", "$", "input", ",", "array", "$", "fields", ",", "$", "id", "=", "0", ")", "{", "$", "model", "=", "$", "this", "->", "getDataModel", "(", ")", ";", "i...
Fetches the data model for a config given a post input array. @param \Illuminate\Http\Request $input @param array $fields @param int $id @return \Illuminate\Database\Eloquent\Model
[ "Fetches", "the", "data", "model", "for", "a", "config", "given", "a", "post", "input", "array", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Model/Config.php#L508-L519
summerblue/administrator
src/Frozennode/Administrator/Fields/Boolean.php
Boolean.build
public function build() { parent::build(); $value = $this->validator->arrayGet($this->suppliedOptions, 'value', true); //we need to set the value to 'false' when it is falsey so it plays nicely with select2 if (!$value && $value !== '') { $this->suppliedOptions['value'] = 'false'; } }
php
public function build() { parent::build(); $value = $this->validator->arrayGet($this->suppliedOptions, 'value', true); //we need to set the value to 'false' when it is falsey so it plays nicely with select2 if (!$value && $value !== '') { $this->suppliedOptions['value'] = 'false'; } }
[ "public", "function", "build", "(", ")", "{", "parent", "::", "build", "(", ")", ";", "$", "value", "=", "$", "this", "->", "validator", "->", "arrayGet", "(", "$", "this", "->", "suppliedOptions", ",", "'value'", ",", "true", ")", ";", "//we need to s...
Builds a few basic options.
[ "Builds", "a", "few", "basic", "options", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Boolean.php#L19-L29
summerblue/administrator
src/Frozennode/Administrator/Fields/Boolean.php
Boolean.fillModel
public function fillModel(&$model, $input) { $model->{$this->getOption('field_name')} = $input === 'true' || $input === '1' || $input === true ? 1 : 0; }
php
public function fillModel(&$model, $input) { $model->{$this->getOption('field_name')} = $input === 'true' || $input === '1' || $input === true ? 1 : 0; }
[ "public", "function", "fillModel", "(", "&", "$", "model", ",", "$", "input", ")", "{", "$", "model", "->", "{", "$", "this", "->", "getOption", "(", "'field_name'", ")", "}", "=", "$", "input", "===", "'true'", "||", "$", "input", "===", "'1'", "|...
Fill a model with input data. @param \Illuminate\Database\Eloquent\Model $model @param mixed $input
[ "Fill", "a", "model", "with", "input", "data", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Boolean.php#L37-L40
summerblue/administrator
src/Frozennode/Administrator/Fields/Boolean.php
Boolean.setFilter
public function setFilter($filter) { parent::setFilter($filter); $this->userOptions['value'] = $this->validator->arrayGet($filter, 'value', ''); //if it isn't null, we have to check the 'true'/'false' string if ($this->userOptions['value'] !== '') { $this->userOptions['value'] = $this->userOptions['value'] === 'false' || !$this->userOptions['value'] ? 0 : 1; } }
php
public function setFilter($filter) { parent::setFilter($filter); $this->userOptions['value'] = $this->validator->arrayGet($filter, 'value', ''); //if it isn't null, we have to check the 'true'/'false' string if ($this->userOptions['value'] !== '') { $this->userOptions['value'] = $this->userOptions['value'] === 'false' || !$this->userOptions['value'] ? 0 : 1; } }
[ "public", "function", "setFilter", "(", "$", "filter", ")", "{", "parent", "::", "setFilter", "(", "$", "filter", ")", ";", "$", "this", "->", "userOptions", "[", "'value'", "]", "=", "$", "this", "->", "validator", "->", "arrayGet", "(", "$", "filter"...
Sets the filter options for this item. @param array $filter
[ "Sets", "the", "filter", "options", "for", "this", "item", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Boolean.php#L47-L57
summerblue/administrator
src/Frozennode/Administrator/Fields/Boolean.php
Boolean.filterQuery
public function filterQuery(QueryBuilder &$query, &$selects = null) { //if the field isn't empty if ($this->getOption('value') !== '') { $query->where($this->config->getDataModel()->getTable().'.'.$this->getOption('field_name'), '=', $this->getOption('value')); } }
php
public function filterQuery(QueryBuilder &$query, &$selects = null) { //if the field isn't empty if ($this->getOption('value') !== '') { $query->where($this->config->getDataModel()->getTable().'.'.$this->getOption('field_name'), '=', $this->getOption('value')); } }
[ "public", "function", "filterQuery", "(", "QueryBuilder", "&", "$", "query", ",", "&", "$", "selects", "=", "null", ")", "{", "//if the field isn't empty", "if", "(", "$", "this", "->", "getOption", "(", "'value'", ")", "!==", "''", ")", "{", "$", "query...
Filters a query object. @param \Illuminate\Database\Query\Builder $query @param array $selects
[ "Filters", "a", "query", "object", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Boolean.php#L65-L71
summerblue/administrator
src/controllers/AdminController.php
AdminController.item
public function item($modelName, $itemId = 0) { $config = app('itemconfig'); $fieldFactory = app('admin_field_factory'); $actionFactory = app('admin_action_factory'); $columnFactory = app('admin_column_factory'); $actionPermissions = $actionFactory->getActionPermissions(); $fields = $fieldFactory->getEditFields(); //if it's ajax, we just return the item information as json if ($this->request->ajax()) { //try to get the object $model = $config->getModel($itemId, $fields, $columnFactory->getIncludedColumns($fields)); if ($model->exists) { $model = $config->updateModel($model, $fieldFactory, $actionFactory); } $response = $actionPermissions['view'] ? response()->json($model) : response()->json(array( 'success' => false, 'errors' => 'You do not have permission to view this item', )); //set the Vary : Accept header to avoid the browser caching the json response return $response->header('Vary', 'Accept'); } else { $view = view('administrator::index', array( 'itemId' => $itemId, )); //set the layout content and title $this->layout->content = $view; return $this->layout; } }
php
public function item($modelName, $itemId = 0) { $config = app('itemconfig'); $fieldFactory = app('admin_field_factory'); $actionFactory = app('admin_action_factory'); $columnFactory = app('admin_column_factory'); $actionPermissions = $actionFactory->getActionPermissions(); $fields = $fieldFactory->getEditFields(); //if it's ajax, we just return the item information as json if ($this->request->ajax()) { //try to get the object $model = $config->getModel($itemId, $fields, $columnFactory->getIncludedColumns($fields)); if ($model->exists) { $model = $config->updateModel($model, $fieldFactory, $actionFactory); } $response = $actionPermissions['view'] ? response()->json($model) : response()->json(array( 'success' => false, 'errors' => 'You do not have permission to view this item', )); //set the Vary : Accept header to avoid the browser caching the json response return $response->header('Vary', 'Accept'); } else { $view = view('administrator::index', array( 'itemId' => $itemId, )); //set the layout content and title $this->layout->content = $view; return $this->layout; } }
[ "public", "function", "item", "(", "$", "modelName", ",", "$", "itemId", "=", "0", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "fieldFactory", "=", "app", "(", "'admin_field_factory'", ")", ";", "$", "actionFactory", "=", "...
Gets the item edit page / information. @param string $modelName @param mixed $itemId
[ "Gets", "the", "item", "edit", "page", "/", "information", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L75-L110
summerblue/administrator
src/controllers/AdminController.php
AdminController.save
public function save($modelName, $id = false) { $config = app('itemconfig'); $fieldFactory = app('admin_field_factory'); $actionFactory = app('admin_action_factory'); if (array_key_exists('form_request', $config->getOptions()) && $this->formRequestErrors !== null) { return response()->json(array( 'success' => false, 'errors' => $this->formRequestErrors, )); } $save = $config->save($this->request, $fieldFactory->getEditFields(), $actionFactory->getActionPermissions(), $id); if (is_string($save)) { $save = implode('<br>', explode('. ', $save)); return response()->json(array( 'success' => false, 'errors' => $save, )); } else { //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); //grab the latest model data $columnFactory = app('admin_column_factory'); $fields = $fieldFactory->getEditFields(); $model = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields)); if ($model->exists) { $model = $config->updateModel($model, $fieldFactory, $actionFactory); } return response()->json(array( 'success' => true, 'data' => $model->toArray(), )); } }
php
public function save($modelName, $id = false) { $config = app('itemconfig'); $fieldFactory = app('admin_field_factory'); $actionFactory = app('admin_action_factory'); if (array_key_exists('form_request', $config->getOptions()) && $this->formRequestErrors !== null) { return response()->json(array( 'success' => false, 'errors' => $this->formRequestErrors, )); } $save = $config->save($this->request, $fieldFactory->getEditFields(), $actionFactory->getActionPermissions(), $id); if (is_string($save)) { $save = implode('<br>', explode('. ', $save)); return response()->json(array( 'success' => false, 'errors' => $save, )); } else { //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); //grab the latest model data $columnFactory = app('admin_column_factory'); $fields = $fieldFactory->getEditFields(); $model = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields)); if ($model->exists) { $model = $config->updateModel($model, $fieldFactory, $actionFactory); } return response()->json(array( 'success' => true, 'data' => $model->toArray(), )); } }
[ "public", "function", "save", "(", "$", "modelName", ",", "$", "id", "=", "false", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "fieldFactory", "=", "app", "(", "'admin_field_factory'", ")", ";", "$", "actionFactory", "=", "...
POST save method that accepts data via JSON POST and either saves an old item (if id is valid) or creates a new one. @param string $modelName @param int $id @return JSON
[ "POST", "save", "method", "that", "accepts", "data", "via", "JSON", "POST", "and", "either", "saves", "an", "old", "item", "(", "if", "id", "is", "valid", ")", "or", "creates", "a", "new", "one", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L120-L160
summerblue/administrator
src/controllers/AdminController.php
AdminController.delete
public function delete($modelName, $id) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $baseModel = $config->getDataModel(); $model = $baseModel::find($id); $errorResponse = array( 'success' => false, 'error' => 'There was an error deleting this item. Please reload the page and try again.', ); //if the model or the id don't exist, send back an error $permissions = $actionFactory->getActionPermissions(); if (!$model->exists || !$permissions['delete']) { return response()->json($errorResponse); } //delete the model // 如果删除成功,或者数据库里面再也找不到了,就算成功 if ($model->delete() || !$baseModel::find($id)) { return response()->json(array( 'success' => true, )); } else { return response()->json($errorResponse); } }
php
public function delete($modelName, $id) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $baseModel = $config->getDataModel(); $model = $baseModel::find($id); $errorResponse = array( 'success' => false, 'error' => 'There was an error deleting this item. Please reload the page and try again.', ); //if the model or the id don't exist, send back an error $permissions = $actionFactory->getActionPermissions(); if (!$model->exists || !$permissions['delete']) { return response()->json($errorResponse); } //delete the model // 如果删除成功,或者数据库里面再也找不到了,就算成功 if ($model->delete() || !$baseModel::find($id)) { return response()->json(array( 'success' => true, )); } else { return response()->json($errorResponse); } }
[ "public", "function", "delete", "(", "$", "modelName", ",", "$", "id", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "actionFactory", "=", "app", "(", "'admin_action_factory'", ")", ";", "$", "baseModel", "=", "$", "config", ...
POST delete method that accepts data via JSON POST and either saves an old. @param string $modelName @param int $id @return JSON
[ "POST", "delete", "method", "that", "accepts", "data", "via", "JSON", "POST", "and", "either", "saves", "an", "old", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L170-L197
summerblue/administrator
src/controllers/AdminController.php
AdminController.batchDelete
public function batchDelete($modelName) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $baseModel = $config->getDataModel(); $errorResponse = array( 'success' => false, 'error' => 'There was an error perform batch deletion. Please reload the page and try again.', ); //if don't have permission, send back request $permissions = $actionFactory->getActionPermissions(); if (!$permissions['delete']) { return response()->json($errorResponse); } //request ids: 1,3,5 $ids = explode(',', $this->request->ids); //delete the model if ($baseModel::whereIn('id', $ids)->delete()) { return response()->json(array( 'success' => true, )); } else { return response()->json($errorResponse); } }
php
public function batchDelete($modelName) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $baseModel = $config->getDataModel(); $errorResponse = array( 'success' => false, 'error' => 'There was an error perform batch deletion. Please reload the page and try again.', ); //if don't have permission, send back request $permissions = $actionFactory->getActionPermissions(); if (!$permissions['delete']) { return response()->json($errorResponse); } //request ids: 1,3,5 $ids = explode(',', $this->request->ids); //delete the model if ($baseModel::whereIn('id', $ids)->delete()) { return response()->json(array( 'success' => true, )); } else { return response()->json($errorResponse); } }
[ "public", "function", "batchDelete", "(", "$", "modelName", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "actionFactory", "=", "app", "(", "'admin_action_factory'", ")", ";", "$", "baseModel", "=", "$", "config", "->", "getDataM...
Batch delete @param string $modelName @param int $id @return JSON
[ "Batch", "delete" ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L207-L233
summerblue/administrator
src/controllers/AdminController.php
AdminController.customModelItemAction
public function customModelItemAction($modelName, $id = null) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $model = $config->getDataModel(); $model = $model::find($id); $actionName = $this->request->input('action_name', false); //get the action and perform the custom action $action = $actionFactory->getByName($actionName); $result = $action->perform($model); //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); //if the result is a string, return that as an error. if (is_string($result)) { return response()->json(array('success' => false, 'error' => $result)); } //if it's falsy, return the standard error message elseif (!$result) { $messages = $action->getOption('messages'); return response()->json(array('success' => false, 'error' => $messages['error'])); } else { $fieldFactory = app('admin_field_factory'); $columnFactory = app('admin_column_factory'); $fields = $fieldFactory->getEditFields(); $model = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields)); if ($model->exists) { $model = $config->updateModel($model, $fieldFactory, $actionFactory); } $response = array('success' => true, 'data' => $model->toArray()); //if it's a download response, flash the response to the session and return the download link if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) { $file = $result->getFile()->getRealPath(); $headers = $result->headers->all(); $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers)); $response['download'] = route('admin_file_download'); } //if it's a redirect, put the url into the redirect key so that javascript can transfer the user elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) { $response['redirect'] = $result->getTargetUrl(); } return response()->json($response); } }
php
public function customModelItemAction($modelName, $id = null) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $model = $config->getDataModel(); $model = $model::find($id); $actionName = $this->request->input('action_name', false); //get the action and perform the custom action $action = $actionFactory->getByName($actionName); $result = $action->perform($model); //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); //if the result is a string, return that as an error. if (is_string($result)) { return response()->json(array('success' => false, 'error' => $result)); } //if it's falsy, return the standard error message elseif (!$result) { $messages = $action->getOption('messages'); return response()->json(array('success' => false, 'error' => $messages['error'])); } else { $fieldFactory = app('admin_field_factory'); $columnFactory = app('admin_column_factory'); $fields = $fieldFactory->getEditFields(); $model = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields)); if ($model->exists) { $model = $config->updateModel($model, $fieldFactory, $actionFactory); } $response = array('success' => true, 'data' => $model->toArray()); //if it's a download response, flash the response to the session and return the download link if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) { $file = $result->getFile()->getRealPath(); $headers = $result->headers->all(); $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers)); $response['download'] = route('admin_file_download'); } //if it's a redirect, put the url into the redirect key so that javascript can transfer the user elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) { $response['redirect'] = $result->getTargetUrl(); } return response()->json($response); } }
[ "public", "function", "customModelItemAction", "(", "$", "modelName", ",", "$", "id", "=", "null", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "actionFactory", "=", "app", "(", "'admin_action_factory'", ")", ";", "$", "model", ...
POST method for handling custom model item actions. @param string $modelName @param int $id @return JSON
[ "POST", "method", "for", "handling", "custom", "model", "item", "actions", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L298-L349
summerblue/administrator
src/controllers/AdminController.php
AdminController.dashboard
public function dashboard() { //if the dev has chosen to use a dashboard if (config('administrator.use_dashboard')) { //set the layout dashboard $this->layout->dashboard = true; //set the layout content $this->layout->content = view(config('administrator.dashboard_view')); return $this->layout; } //else we should redirect to the menu item else { $configFactory = app('admin_config_factory'); $home = config('administrator.home_page'); //first try to find it if it's a model config item $config = $configFactory->make($home); if (!$config) { throw new \InvalidArgumentException('Administrator: '.trans('administrator::administrator.valid_home_page')); } elseif ($config->getType() === 'model') { return redirect()->route('admin_index', array($config->getOption('name'))); } elseif ($config->getType() === 'settings') { return redirect()->route('admin_settings', array($config->getOption('name'))); } } }
php
public function dashboard() { //if the dev has chosen to use a dashboard if (config('administrator.use_dashboard')) { //set the layout dashboard $this->layout->dashboard = true; //set the layout content $this->layout->content = view(config('administrator.dashboard_view')); return $this->layout; } //else we should redirect to the menu item else { $configFactory = app('admin_config_factory'); $home = config('administrator.home_page'); //first try to find it if it's a model config item $config = $configFactory->make($home); if (!$config) { throw new \InvalidArgumentException('Administrator: '.trans('administrator::administrator.valid_home_page')); } elseif ($config->getType() === 'model') { return redirect()->route('admin_index', array($config->getOption('name'))); } elseif ($config->getType() === 'settings') { return redirect()->route('admin_settings', array($config->getOption('name'))); } } }
[ "public", "function", "dashboard", "(", ")", "{", "//if the dev has chosen to use a dashboard", "if", "(", "config", "(", "'administrator.use_dashboard'", ")", ")", "{", "//set the layout dashboard", "$", "this", "->", "layout", "->", "dashboard", "=", "true", ";", ...
Shows the dashboard page. @return Response
[ "Shows", "the", "dashboard", "page", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L356-L384
summerblue/administrator
src/controllers/AdminController.php
AdminController.results
public function results($modelName) { $dataTable = app('admin_datatable'); //get the sort options and filters $page = $this->request->input('page', 1); $sortOptions = $this->request->input('sortOptions', array()); $filters = $this->request->input('filters', array()); //return the rows return response()->json($dataTable->getRows(app('db'), $filters, $page, $sortOptions)); }
php
public function results($modelName) { $dataTable = app('admin_datatable'); //get the sort options and filters $page = $this->request->input('page', 1); $sortOptions = $this->request->input('sortOptions', array()); $filters = $this->request->input('filters', array()); //return the rows return response()->json($dataTable->getRows(app('db'), $filters, $page, $sortOptions)); }
[ "public", "function", "results", "(", "$", "modelName", ")", "{", "$", "dataTable", "=", "app", "(", "'admin_datatable'", ")", ";", "//get the sort options and filters", "$", "page", "=", "$", "this", "->", "request", "->", "input", "(", "'page'", ",", "1", ...
Gets the database results for the current model. @param string $modelName @return array of rows
[ "Gets", "the", "database", "results", "for", "the", "current", "model", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L393-L404
summerblue/administrator
src/controllers/AdminController.php
AdminController.updateOptions
public function updateOptions($modelName) { $fieldFactory = app('admin_field_factory'); $response = array(); //iterate over the supplied constrained fields foreach ($this->request->input('fields', array()) as $field) { //get the constraints, the search term, and the currently-selected items $constraints = array_get($field, 'constraints', array()); $term = array_get($field, 'term', array()); $type = array_get($field, 'type', false); $fieldName = array_get($field, 'field', false); $selectedItems = array_get($field, 'selectedItems', false); $response[$fieldName] = $fieldFactory->updateRelationshipOptions($fieldName, $type, $constraints, $selectedItems, $term); } return response()->json($response); }
php
public function updateOptions($modelName) { $fieldFactory = app('admin_field_factory'); $response = array(); //iterate over the supplied constrained fields foreach ($this->request->input('fields', array()) as $field) { //get the constraints, the search term, and the currently-selected items $constraints = array_get($field, 'constraints', array()); $term = array_get($field, 'term', array()); $type = array_get($field, 'type', false); $fieldName = array_get($field, 'field', false); $selectedItems = array_get($field, 'selectedItems', false); $response[$fieldName] = $fieldFactory->updateRelationshipOptions($fieldName, $type, $constraints, $selectedItems, $term); } return response()->json($response); }
[ "public", "function", "updateOptions", "(", "$", "modelName", ")", "{", "$", "fieldFactory", "=", "app", "(", "'admin_field_factory'", ")", ";", "$", "response", "=", "array", "(", ")", ";", "//iterate over the supplied constrained fields", "foreach", "(", "$", ...
Gets a list of related items given constraints. @param string $modelName @return array of objects [{id: string} ... {1: 'name'}, ...]
[ "Gets", "a", "list", "of", "related", "items", "given", "constraints", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L413-L431
summerblue/administrator
src/controllers/AdminController.php
AdminController.fileUpload
public function fileUpload($modelName, $fieldName) { $fieldFactory = app('admin_field_factory'); //get the model and the field object $field = $fieldFactory->findField($fieldName); return response()->JSON($field->doUpload()); }
php
public function fileUpload($modelName, $fieldName) { $fieldFactory = app('admin_field_factory'); //get the model and the field object $field = $fieldFactory->findField($fieldName); return response()->JSON($field->doUpload()); }
[ "public", "function", "fileUpload", "(", "$", "modelName", ",", "$", "fieldName", ")", "{", "$", "fieldFactory", "=", "app", "(", "'admin_field_factory'", ")", ";", "//get the model and the field object", "$", "field", "=", "$", "fieldFactory", "->", "findField", ...
The POST method that runs when a user uploads a file on a file field. @param string $modelName @param string $fieldName @return JSON
[ "The", "POST", "method", "that", "runs", "when", "a", "user", "uploads", "a", "file", "on", "a", "file", "field", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L462-L470
summerblue/administrator
src/controllers/AdminController.php
AdminController.fileDownload
public function fileDownload() { if ($response = $this->session->get('administrator_download_response')) { $this->session->forget('administrator_download_response'); $filename = substr($response['headers']['content-disposition'][0], 22, -1); return response()->download($response['file'], $filename, $response['headers']); } else { return redirect()->back(); } }
php
public function fileDownload() { if ($response = $this->session->get('administrator_download_response')) { $this->session->forget('administrator_download_response'); $filename = substr($response['headers']['content-disposition'][0], 22, -1); return response()->download($response['file'], $filename, $response['headers']); } else { return redirect()->back(); } }
[ "public", "function", "fileDownload", "(", ")", "{", "if", "(", "$", "response", "=", "$", "this", "->", "session", "->", "get", "(", "'administrator_download_response'", ")", ")", "{", "$", "this", "->", "session", "->", "forget", "(", "'administrator_downl...
The GET method that runs when a user needs to download a file. @return JSON
[ "The", "GET", "method", "that", "runs", "when", "a", "user", "needs", "to", "download", "a", "file", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L477-L487
summerblue/administrator
src/controllers/AdminController.php
AdminController.rowsPerPage
public function rowsPerPage($modelName) { $dataTable = app('admin_datatable'); //get the inputted rows and the model rows $rows = (int) $this->request->input('rows', 20); $dataTable->setRowsPerPage(app('session.store'), 0, $rows); return response()->JSON(array('success' => true)); }
php
public function rowsPerPage($modelName) { $dataTable = app('admin_datatable'); //get the inputted rows and the model rows $rows = (int) $this->request->input('rows', 20); $dataTable->setRowsPerPage(app('session.store'), 0, $rows); return response()->JSON(array('success' => true)); }
[ "public", "function", "rowsPerPage", "(", "$", "modelName", ")", "{", "$", "dataTable", "=", "app", "(", "'admin_datatable'", ")", ";", "//get the inputted rows and the model rows", "$", "rows", "=", "(", "int", ")", "$", "this", "->", "request", "->", "input"...
The POST method for setting a user's rows per page. @param string $modelName @return JSON
[ "The", "POST", "method", "for", "setting", "a", "user", "s", "rows", "per", "page", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L496-L505
summerblue/administrator
src/controllers/AdminController.php
AdminController.page
public function page($page) { //set the page $this->layout->page = $page; //set the layout content and title $this->layout->content = view($page); return $this->layout; }
php
public function page($page) { //set the page $this->layout->page = $page; //set the layout content and title $this->layout->content = view($page); return $this->layout; }
[ "public", "function", "page", "(", "$", "page", ")", "{", "//set the page", "$", "this", "->", "layout", "->", "page", "=", "$", "page", ";", "//set the layout content and title", "$", "this", "->", "layout", "->", "content", "=", "view", "(", "$", "page",...
The pages view. @return Response
[ "The", "pages", "view", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L512-L521
summerblue/administrator
src/controllers/AdminController.php
AdminController.settingsSave
public function settingsSave() { $config = app('itemconfig'); $save = $config->save($this->request, app('admin_field_factory')->getEditFields()); if (is_string($save)) { return response()->json(array( 'success' => false, 'errors' => $save, )); } else { //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); return response()->json(array( 'success' => true, 'data' => $config->getDataModel(), 'actions' => app('admin_action_factory')->getActionsOptions(), )); } }
php
public function settingsSave() { $config = app('itemconfig'); $save = $config->save($this->request, app('admin_field_factory')->getEditFields()); if (is_string($save)) { return response()->json(array( 'success' => false, 'errors' => $save, )); } else { //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); return response()->json(array( 'success' => true, 'data' => $config->getDataModel(), 'actions' => app('admin_action_factory')->getActionsOptions(), )); } }
[ "public", "function", "settingsSave", "(", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "save", "=", "$", "config", "->", "save", "(", "$", "this", "->", "request", ",", "app", "(", "'admin_field_factory'", ")", "->", "getEd...
POST save settings method that accepts data via JSON POST and either saves an old item (if id is valid) or creates a new one. @return JSON
[ "POST", "save", "settings", "method", "that", "accepts", "data", "via", "JSON", "POST", "and", "either", "saves", "an", "old", "item", "(", "if", "id", "is", "valid", ")", "or", "creates", "a", "new", "one", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L543-L563
summerblue/administrator
src/controllers/AdminController.php
AdminController.settingsCustomAction
public function settingsCustomAction($settingsName) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $actionName = $this->request->input('action_name', false); //get the action and perform the custom action $action = $actionFactory->getByName($actionName); $data = $config->getDataModel(); $result = $action->perform($data); //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); //if the result is a string, return that as an error. if (is_string($result)) { return response()->json(array('success' => false, 'error' => $result)); } //if it's falsy, return the standard error message elseif (!$result) { $messages = $action->getOption('messages'); return response()->json(array('success' => false, 'error' => $messages['error'])); } else { $response = array('success' => true, 'actions' => $actionFactory->getActionsOptions(true)); //if it's a download response, flash the response to the session and return the download link if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) { $file = $result->getFile()->getRealPath(); $headers = $result->headers->all(); $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers)); $response['download'] = route('admin_file_download'); } //if it's a redirect, put the url into the redirect key so that javascript can transfer the user elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) { $response['redirect'] = $result->getTargetUrl(); } return response()->json($response); } }
php
public function settingsCustomAction($settingsName) { $config = app('itemconfig'); $actionFactory = app('admin_action_factory'); $actionName = $this->request->input('action_name', false); //get the action and perform the custom action $action = $actionFactory->getByName($actionName); $data = $config->getDataModel(); $result = $action->perform($data); //override the config options so that we can get the latest app('admin_config_factory')->updateConfigOptions(); //if the result is a string, return that as an error. if (is_string($result)) { return response()->json(array('success' => false, 'error' => $result)); } //if it's falsy, return the standard error message elseif (!$result) { $messages = $action->getOption('messages'); return response()->json(array('success' => false, 'error' => $messages['error'])); } else { $response = array('success' => true, 'actions' => $actionFactory->getActionsOptions(true)); //if it's a download response, flash the response to the session and return the download link if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) { $file = $result->getFile()->getRealPath(); $headers = $result->headers->all(); $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers)); $response['download'] = route('admin_file_download'); } //if it's a redirect, put the url into the redirect key so that javascript can transfer the user elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) { $response['redirect'] = $result->getTargetUrl(); } return response()->json($response); } }
[ "public", "function", "settingsCustomAction", "(", "$", "settingsName", ")", "{", "$", "config", "=", "app", "(", "'itemconfig'", ")", ";", "$", "actionFactory", "=", "app", "(", "'admin_action_factory'", ")", ";", "$", "actionName", "=", "$", "this", "->", ...
POST method for handling custom actions on the settings page. @param string $settingsName @return JSON
[ "POST", "method", "for", "handling", "custom", "actions", "on", "the", "settings", "page", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/controllers/AdminController.php#L572-L613
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Relationships/Relationship.php
Relationship.build
public function build() { $model = $this->config->getDataModel(); $options = $this->suppliedOptions; $this->tablePrefix = $this->db->getTablePrefix(); $relationship = $model->{$options['relationship']}(); $relevant_model = $model; $selectTable = $options['column_name'].'_'.$this->tablePrefix.$relationship->getRelated()->getTable(); //set the relationship object so we can use it later $this->relationshipObject = $relationship; //replace the (:table) with the generated $selectTable $options['select'] = str_replace('(:table)', $selectTable, $options['select']); $this->suppliedOptions = $options; }
php
public function build() { $model = $this->config->getDataModel(); $options = $this->suppliedOptions; $this->tablePrefix = $this->db->getTablePrefix(); $relationship = $model->{$options['relationship']}(); $relevant_model = $model; $selectTable = $options['column_name'].'_'.$this->tablePrefix.$relationship->getRelated()->getTable(); //set the relationship object so we can use it later $this->relationshipObject = $relationship; //replace the (:table) with the generated $selectTable $options['select'] = str_replace('(:table)', $selectTable, $options['select']); $this->suppliedOptions = $options; }
[ "public", "function", "build", "(", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "options", "=", "$", "this", "->", "suppliedOptions", ";", "$", "this", "->", "tablePrefix", "=", "$", "this", "->...
Builds the necessary fields on the object.
[ "Builds", "the", "necessary", "fields", "on", "the", "object", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Relationships/Relationship.php#L33-L50
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Relationships/Relationship.php
Relationship.getRelationshipWheres
public function getRelationshipWheres($relationship, $tableAlias, $pivotAlias = null, $pivot = null) { //get the relationship model $relationshipModel = $relationship->getRelated(); //get the query instance $query = $relationship->getQuery()->getQuery(); //get the connection instance $connection = $query->getConnection(); //one element of the relationship query's wheres is always useless (it will say pivot_table.other_id is null) //depending on whether or not softdeletes are enabled on the other model, this will be in either position 0 //or 1 of the wheres array array_splice($query->wheres, (method_exists($relationshipModel, 'getDeletedAtColumn') ? 1 : 0), 1); //iterate over the wheres to properly alias the columns foreach ($query->wheres as &$where) { //alias the where columns $where['column'] = $this->aliasRelationshipWhere($where['column'], $tableAlias, $pivotAlias, $pivot); } $sql = $query->toSql(); $fullQuery = $this->interpolateQuery($sql, $connection->prepareBindings($query->getBindings())); $split = explode(' where ', $fullQuery); return isset($split[1]) ? $split[1] : ''; }
php
public function getRelationshipWheres($relationship, $tableAlias, $pivotAlias = null, $pivot = null) { //get the relationship model $relationshipModel = $relationship->getRelated(); //get the query instance $query = $relationship->getQuery()->getQuery(); //get the connection instance $connection = $query->getConnection(); //one element of the relationship query's wheres is always useless (it will say pivot_table.other_id is null) //depending on whether or not softdeletes are enabled on the other model, this will be in either position 0 //or 1 of the wheres array array_splice($query->wheres, (method_exists($relationshipModel, 'getDeletedAtColumn') ? 1 : 0), 1); //iterate over the wheres to properly alias the columns foreach ($query->wheres as &$where) { //alias the where columns $where['column'] = $this->aliasRelationshipWhere($where['column'], $tableAlias, $pivotAlias, $pivot); } $sql = $query->toSql(); $fullQuery = $this->interpolateQuery($sql, $connection->prepareBindings($query->getBindings())); $split = explode(' where ', $fullQuery); return isset($split[1]) ? $split[1] : ''; }
[ "public", "function", "getRelationshipWheres", "(", "$", "relationship", ",", "$", "tableAlias", ",", "$", "pivotAlias", "=", "null", ",", "$", "pivot", "=", "null", ")", "{", "//get the relationship model", "$", "relationshipModel", "=", "$", "relationship", "-...
Sets up the existing relationship wheres. @param \Illuminate\Database\Eloquent\Relations\Relation $relationship @param string $tableAlias @param string $pivotAlias @param string $pivot @return string
[ "Sets", "up", "the", "existing", "relationship", "wheres", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Relationships/Relationship.php#L84-L111
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Relationships/Relationship.php
Relationship.aliasRelationshipWhere
public function aliasRelationshipWhere($column, $tableAlias, $pivotAlias, $pivot) { //first explode the string on "." in case it was given with the table already included $split = explode('.', $column); //if the second split item exists, there was a "." if (isset($split[1])) { //if the table name is the pivot table, append the pivot alias if ($split[0] === $pivot) { return $pivotAlias.'.'.$split[1]; } //otherwise append the table alias else { return $tableAlias.'.'.$split[1]; } } else { return $tableAlias.'.'.$column; } }
php
public function aliasRelationshipWhere($column, $tableAlias, $pivotAlias, $pivot) { //first explode the string on "." in case it was given with the table already included $split = explode('.', $column); //if the second split item exists, there was a "." if (isset($split[1])) { //if the table name is the pivot table, append the pivot alias if ($split[0] === $pivot) { return $pivotAlias.'.'.$split[1]; } //otherwise append the table alias else { return $tableAlias.'.'.$split[1]; } } else { return $tableAlias.'.'.$column; } }
[ "public", "function", "aliasRelationshipWhere", "(", "$", "column", ",", "$", "tableAlias", ",", "$", "pivotAlias", ",", "$", "pivot", ")", "{", "//first explode the string on \".\" in case it was given with the table already included", "$", "split", "=", "explode", "(", ...
Aliases an existing where column. @param string $column @param string $tableAlias @param string $pivotAlias @param string $pivot @return string
[ "Aliases", "an", "existing", "where", "column", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Relationships/Relationship.php#L123-L141
summerblue/administrator
src/Frozennode/Administrator/Fields/Relationships/HasOneOrMany.php
HasOneOrMany.build
public function build() { parent::build(); $options = $this->suppliedOptions; $model = $this->config->getDataModel(); $relationship = $model->{$options['field_name']}(); $related_model = $relationship->getRelated(); $options['table'] = $related_model->getTable(); $options['column'] = $relationship->getQualifiedForeignKeyName(); $this->suppliedOptions = $options; }
php
public function build() { parent::build(); $options = $this->suppliedOptions; $model = $this->config->getDataModel(); $relationship = $model->{$options['field_name']}(); $related_model = $relationship->getRelated(); $options['table'] = $related_model->getTable(); $options['column'] = $relationship->getQualifiedForeignKeyName(); $this->suppliedOptions = $options; }
[ "public", "function", "build", "(", ")", "{", "parent", "::", "build", "(", ")", ";", "$", "options", "=", "$", "this", "->", "suppliedOptions", ";", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "relations...
Builds a few basic options.
[ "Builds", "a", "few", "basic", "options", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Relationships/HasOneOrMany.php#L22-L36
summerblue/administrator
src/Frozennode/Administrator/Fields/Relationships/HasOneOrMany.php
HasOneOrMany.constrainQuery
public function constrainQuery(EloquentBuilder &$query, $relatedModel, $constraint) { $query->where($this->getOption('column'), '=', $constraint); }
php
public function constrainQuery(EloquentBuilder &$query, $relatedModel, $constraint) { $query->where($this->getOption('column'), '=', $constraint); }
[ "public", "function", "constrainQuery", "(", "EloquentBuilder", "&", "$", "query", ",", "$", "relatedModel", ",", "$", "constraint", ")", "{", "$", "query", "->", "where", "(", "$", "this", "->", "getOption", "(", "'column'", ")", ",", "'='", ",", "$", ...
Constrains a query by a given set of constraints. @param \Illuminate\Database\Eloquent\Builder $query @param \Illuminate\Database\Eloquent\Model $relatedModel @param string $constraint
[ "Constrains", "a", "query", "by", "a", "given", "set", "of", "constraints", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Relationships/HasOneOrMany.php#L66-L69
summerblue/administrator
src/Frozennode/Administrator/AdministratorServiceProvider.php
AdministratorServiceProvider.boot
public function boot() { $this->loadViewsFrom(__DIR__.'/../../views', 'administrator'); $this->mergeConfigFrom( __DIR__.'/../../config/administrator.php', 'administrator' ); $this->loadTranslationsFrom(__DIR__.'/../../lang', 'administrator'); $this->publishes([ __DIR__.'/../../config/administrator.php' => config_path('administrator.php'), ]); $this->publishes([ __DIR__.'/../../../public' => public_path('packages/summerblue/administrator'), ], 'public'); //set the locale $this->setLocale(); $this->app['events']->fire('administrator.ready'); }
php
public function boot() { $this->loadViewsFrom(__DIR__.'/../../views', 'administrator'); $this->mergeConfigFrom( __DIR__.'/../../config/administrator.php', 'administrator' ); $this->loadTranslationsFrom(__DIR__.'/../../lang', 'administrator'); $this->publishes([ __DIR__.'/../../config/administrator.php' => config_path('administrator.php'), ]); $this->publishes([ __DIR__.'/../../../public' => public_path('packages/summerblue/administrator'), ], 'public'); //set the locale $this->setLocale(); $this->app['events']->fire('administrator.ready'); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "loadViewsFrom", "(", "__DIR__", ".", "'/../../views'", ",", "'administrator'", ")", ";", "$", "this", "->", "mergeConfigFrom", "(", "__DIR__", ".", "'/../../config/administrator.php'", ",", "'admin...
Bootstrap the application events.
[ "Bootstrap", "the", "application", "events", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/AdministratorServiceProvider.php#L27-L49
summerblue/administrator
src/Frozennode/Administrator/AdministratorServiceProvider.php
AdministratorServiceProvider.register
public function register() { //include our view composers, and routes to avoid issues with catch-all routes defined by users include __DIR__.'/../../viewComposers.php'; include __DIR__.'/../../helpers.php'; // Load route with web middleware Route::group([ 'middleware' => 'web', ], function () { $this->loadRoutesFrom(__DIR__.'/../../routes.php'); }); //the admin validator $this->app->singleton('admin_validator', function ($app) { //get the original validator class so we can set it back after creating our own $originalValidator = LValidator::make(array(), array()); $originalValidatorClass = get_class($originalValidator); //temporarily override the core resolver LValidator::resolver(function ($translator, $data, $rules, $messages) use ($app) { $validator = new Validator($translator, $data, $rules, $messages); $validator->setUrlInstance($app->make('url')); return $validator; }); //grab our validator instance $validator = LValidator::make(array(), array()); //set the validator resolver back to the original validator LValidator::resolver(function ($translator, $data, $rules, $messages) use ($originalValidatorClass) { return new $originalValidatorClass($translator, $data, $rules, $messages); }); //return our validator instance return $validator; }); //set up the shared instances $this->app->singleton('admin_config_factory', function ($app) { return new ConfigFactory($app->make('admin_validator'), LValidator::make(array(), array()), config('administrator')); }); $this->app->singleton('admin_field_factory', function ($app) { return new FieldFactory($app->make('admin_validator'), $app->make('itemconfig'), $app->make('db')); }); $this->app->singleton('admin_datatable', function ($app) { $dataTable = new DataTable($app->make('itemconfig'), $app->make('admin_column_factory'), $app->make('admin_field_factory')); $dataTable->setRowsPerPage($app->make('session.store'), config('administrator.global_rows_per_page')); return $dataTable; }); $this->app->singleton('admin_column_factory', function ($app) { return new ColumnFactory($app->make('admin_validator'), $app->make('itemconfig'), $app->make('db')); }); $this->app->singleton('admin_action_factory', function ($app) { return new ActionFactory($app->make('admin_validator'), $app->make('itemconfig'), $app->make('db')); }); $this->app->singleton('admin_menu', function ($app) { return new Menu($app->make('config'), $app->make('admin_config_factory')); }); }
php
public function register() { //include our view composers, and routes to avoid issues with catch-all routes defined by users include __DIR__.'/../../viewComposers.php'; include __DIR__.'/../../helpers.php'; // Load route with web middleware Route::group([ 'middleware' => 'web', ], function () { $this->loadRoutesFrom(__DIR__.'/../../routes.php'); }); //the admin validator $this->app->singleton('admin_validator', function ($app) { //get the original validator class so we can set it back after creating our own $originalValidator = LValidator::make(array(), array()); $originalValidatorClass = get_class($originalValidator); //temporarily override the core resolver LValidator::resolver(function ($translator, $data, $rules, $messages) use ($app) { $validator = new Validator($translator, $data, $rules, $messages); $validator->setUrlInstance($app->make('url')); return $validator; }); //grab our validator instance $validator = LValidator::make(array(), array()); //set the validator resolver back to the original validator LValidator::resolver(function ($translator, $data, $rules, $messages) use ($originalValidatorClass) { return new $originalValidatorClass($translator, $data, $rules, $messages); }); //return our validator instance return $validator; }); //set up the shared instances $this->app->singleton('admin_config_factory', function ($app) { return new ConfigFactory($app->make('admin_validator'), LValidator::make(array(), array()), config('administrator')); }); $this->app->singleton('admin_field_factory', function ($app) { return new FieldFactory($app->make('admin_validator'), $app->make('itemconfig'), $app->make('db')); }); $this->app->singleton('admin_datatable', function ($app) { $dataTable = new DataTable($app->make('itemconfig'), $app->make('admin_column_factory'), $app->make('admin_field_factory')); $dataTable->setRowsPerPage($app->make('session.store'), config('administrator.global_rows_per_page')); return $dataTable; }); $this->app->singleton('admin_column_factory', function ($app) { return new ColumnFactory($app->make('admin_validator'), $app->make('itemconfig'), $app->make('db')); }); $this->app->singleton('admin_action_factory', function ($app) { return new ActionFactory($app->make('admin_validator'), $app->make('itemconfig'), $app->make('db')); }); $this->app->singleton('admin_menu', function ($app) { return new Menu($app->make('config'), $app->make('admin_config_factory')); }); }
[ "public", "function", "register", "(", ")", "{", "//include our view composers, and routes to avoid issues with catch-all routes defined by users", "include", "__DIR__", ".", "'/../../viewComposers.php'", ";", "include", "__DIR__", ".", "'/../../helpers.php'", ";", "// Load route w...
Register the service provider.
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/AdministratorServiceProvider.php#L54-L120
summerblue/administrator
src/Frozennode/Administrator/AdministratorServiceProvider.php
AdministratorServiceProvider.setLocale
public function setLocale() { if ($locale = $this->app->session->get('administrator_locale')) { $this->app->setLocale($locale); } }
php
public function setLocale() { if ($locale = $this->app->session->get('administrator_locale')) { $this->app->setLocale($locale); } }
[ "public", "function", "setLocale", "(", ")", "{", "if", "(", "$", "locale", "=", "$", "this", "->", "app", "->", "session", "->", "get", "(", "'administrator_locale'", ")", ")", "{", "$", "this", "->", "app", "->", "setLocale", "(", "$", "locale", ")...
Sets the locale if it exists in the session and also exists in the locales option.
[ "Sets", "the", "locale", "if", "it", "exists", "in", "the", "session", "and", "also", "exists", "in", "the", "locales", "option", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/AdministratorServiceProvider.php#L136-L141
summerblue/administrator
src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php
BelongsToMany.build
public function build() { parent::build(); $options = $this->suppliedOptions; $model = $this->config->getDataModel(); $relationship = $model->{$options['field_name']}(); $relatedModel = $relationship->getRelated(); $options['table'] = $relationship->getTable(); $options['column'] = $relationship->getQualifiedForeignPivotKeyName(); $options['column2'] = $relationship->getQualifiedRelatedPivotKeyName(); $options['foreign_key'] = $relatedModel->getKeyName(); $this->suppliedOptions = $options; }
php
public function build() { parent::build(); $options = $this->suppliedOptions; $model = $this->config->getDataModel(); $relationship = $model->{$options['field_name']}(); $relatedModel = $relationship->getRelated(); $options['table'] = $relationship->getTable(); $options['column'] = $relationship->getQualifiedForeignPivotKeyName(); $options['column2'] = $relationship->getQualifiedRelatedPivotKeyName(); $options['foreign_key'] = $relatedModel->getKeyName(); $this->suppliedOptions = $options; }
[ "public", "function", "build", "(", ")", "{", "parent", "::", "build", "(", ")", ";", "$", "options", "=", "$", "this", "->", "suppliedOptions", ";", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "relations...
Builds a few basic options.
[ "Builds", "a", "few", "basic", "options", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php#L24-L40
summerblue/administrator
src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php
BelongsToMany.fillModel
public function fillModel(&$model, $input) { $input = $input ? explode(',', $input) : array(); $fieldName = $this->getOption('field_name'); $relationship = $model->{$fieldName}(); //if this field is sortable, delete all the old records and insert the new ones one at a time if ($sortField = $this->getOption('sort_field')) { //first delete all the old records $relationship->detach(); //then re-attach them in the correct order foreach ($input as $i => $item) { $relationship->attach($item, array($sortField => $i)); } } else { //elsewise the order doesn't matter, so use sync $relationship->sync($input); } //unset the attribute on the model $model->__unset($fieldName); }
php
public function fillModel(&$model, $input) { $input = $input ? explode(',', $input) : array(); $fieldName = $this->getOption('field_name'); $relationship = $model->{$fieldName}(); //if this field is sortable, delete all the old records and insert the new ones one at a time if ($sortField = $this->getOption('sort_field')) { //first delete all the old records $relationship->detach(); //then re-attach them in the correct order foreach ($input as $i => $item) { $relationship->attach($item, array($sortField => $i)); } } else { //elsewise the order doesn't matter, so use sync $relationship->sync($input); } //unset the attribute on the model $model->__unset($fieldName); }
[ "public", "function", "fillModel", "(", "&", "$", "model", ",", "$", "input", ")", "{", "$", "input", "=", "$", "input", "?", "explode", "(", "','", ",", "$", "input", ")", ":", "array", "(", ")", ";", "$", "fieldName", "=", "$", "this", "->", ...
Fill a model with input data. @param \Illuminate\Database\Eloquent\Model $model @param mixed $input @return array
[ "Fill", "a", "model", "with", "input", "data", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Relationships/BelongsToMany.php#L50-L72
summerblue/administrator
src/Frozennode/Administrator/Fields/Image.php
Image.doUpload
public function doUpload() { // CJ: Create a folder if it doesn't already exist if (!file_exists($this->getOption('location'))) { mkdir($this->getOption('location'), 0777, true); } //use the multup library to perform the upload $result = Multup::open('file', 'image|max:'.$this->getOption('size_limit') * 1000, $this->getOption('location'), $this->getOption('naming') === 'random') ->sizes($this->getOption('sizes')) ->set_length($this->getOption('length')) ->upload(); return $result[0]; }
php
public function doUpload() { // CJ: Create a folder if it doesn't already exist if (!file_exists($this->getOption('location'))) { mkdir($this->getOption('location'), 0777, true); } //use the multup library to perform the upload $result = Multup::open('file', 'image|max:'.$this->getOption('size_limit') * 1000, $this->getOption('location'), $this->getOption('naming') === 'random') ->sizes($this->getOption('sizes')) ->set_length($this->getOption('length')) ->upload(); return $result[0]; }
[ "public", "function", "doUpload", "(", ")", "{", "// CJ: Create a folder if it doesn't already exist", "if", "(", "!", "file_exists", "(", "$", "this", "->", "getOption", "(", "'location'", ")", ")", ")", "{", "mkdir", "(", "$", "this", "->", "getOption", "(",...
This static function is used to perform the actual upload and resizing using the Multup class. @return array
[ "This", "static", "function", "is", "used", "to", "perform", "the", "actual", "upload", "and", "resizing", "using", "the", "Multup", "class", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Image.php#L32-L47
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Relationships/BelongsToMany.php
BelongsToMany.filterQuery
public function filterQuery(&$selects) { $model = $this->config->getDataModel(); $joins = $where = ''; $columnName = $this->getOption('column_name'); $relationship = $model->{$this->getOption('relationship')}(); $from_table = $this->tablePrefix.$model->getTable(); $field_table = $columnName.'_'.$from_table; $other_table = $this->tablePrefix.$relationship->getRelated()->getTable(); $other_alias = $columnName.'_'.$other_table; $other_model = $relationship->getRelated(); $other_key = $other_model->getKeyName(); $int_table = $this->tablePrefix.$relationship->getTable(); $int_alias = $columnName.'_'.$int_table; $column1 = explode('.', $relationship->getForeignKey()); $column1 = $column1[1]; $column2 = explode('.', $relationship->getOtherKey()); $column2 = $column2[1]; $joins .= ' LEFT JOIN '.$int_table.' AS '.$int_alias.' ON '.$int_alias.'.'.$column1.' = '.$field_table.'.'.$model->getKeyName() .' LEFT JOIN '.$other_table.' AS '.$other_alias.' ON '.$other_alias.'.'.$other_key.' = '.$int_alias.'.'.$column2; //grab the existing where clauses that the user may have set on the relationship $relationshipWheres = $this->getRelationshipWheres($relationship, $other_alias, $int_alias, $int_table); $where = $this->tablePrefix.$model->getTable().'.'.$model->getKeyName().' = '.$int_alias.'.'.$column1 .($relationshipWheres ? ' AND '.$relationshipWheres : ''); $selects[] = $this->db->raw('(SELECT '.$this->getOption('select').' FROM '.$from_table.' AS '.$field_table.' '.$joins.' WHERE '.$where.') AS '.$this->db->getQueryGrammar()->wrap($columnName)); }
php
public function filterQuery(&$selects) { $model = $this->config->getDataModel(); $joins = $where = ''; $columnName = $this->getOption('column_name'); $relationship = $model->{$this->getOption('relationship')}(); $from_table = $this->tablePrefix.$model->getTable(); $field_table = $columnName.'_'.$from_table; $other_table = $this->tablePrefix.$relationship->getRelated()->getTable(); $other_alias = $columnName.'_'.$other_table; $other_model = $relationship->getRelated(); $other_key = $other_model->getKeyName(); $int_table = $this->tablePrefix.$relationship->getTable(); $int_alias = $columnName.'_'.$int_table; $column1 = explode('.', $relationship->getForeignKey()); $column1 = $column1[1]; $column2 = explode('.', $relationship->getOtherKey()); $column2 = $column2[1]; $joins .= ' LEFT JOIN '.$int_table.' AS '.$int_alias.' ON '.$int_alias.'.'.$column1.' = '.$field_table.'.'.$model->getKeyName() .' LEFT JOIN '.$other_table.' AS '.$other_alias.' ON '.$other_alias.'.'.$other_key.' = '.$int_alias.'.'.$column2; //grab the existing where clauses that the user may have set on the relationship $relationshipWheres = $this->getRelationshipWheres($relationship, $other_alias, $int_alias, $int_table); $where = $this->tablePrefix.$model->getTable().'.'.$model->getKeyName().' = '.$int_alias.'.'.$column1 .($relationshipWheres ? ' AND '.$relationshipWheres : ''); $selects[] = $this->db->raw('(SELECT '.$this->getOption('select').' FROM '.$from_table.' AS '.$field_table.' '.$joins.' WHERE '.$where.') AS '.$this->db->getQueryGrammar()->wrap($columnName)); }
[ "public", "function", "filterQuery", "(", "&", "$", "selects", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "joins", "=", "$", "where", "=", "''", ";", "$", "columnName", "=", "$", "this", "->"...
Adds selects to a query. @param array $selects
[ "Adds", "selects", "to", "a", "query", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Relationships/BelongsToMany.php#L21-L52
summerblue/administrator
src/Frozennode/Administrator/DataTable/Columns/Relationships/BelongsToMany.php
BelongsToMany.getIncludedColumn
public function getIncludedColumn() { $model = $this->config->getDataModel(); $fk = $model->{$this->getOption('relationship')}()->getRelated()->getKeyName(); return array($fk => $model->getTable().'.'.$fk); }
php
public function getIncludedColumn() { $model = $this->config->getDataModel(); $fk = $model->{$this->getOption('relationship')}()->getRelated()->getKeyName(); return array($fk => $model->getTable().'.'.$fk); }
[ "public", "function", "getIncludedColumn", "(", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "$", "fk", "=", "$", "model", "->", "{", "$", "this", "->", "getOption", "(", "'relationship'", ")", "}", "...
Gets all default values. @return array
[ "Gets", "all", "default", "values", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/DataTable/Columns/Relationships/BelongsToMany.php#L59-L65
summerblue/administrator
src/Frozennode/Administrator/Config/Config.php
Config.build
public function build() { $options = $this->suppliedOptions; //check the permission $options['permission'] = isset($options['permission']) ? $options['permission']() : true; $this->suppliedOptions = $options; }
php
public function build() { $options = $this->suppliedOptions; //check the permission $options['permission'] = isset($options['permission']) ? $options['permission']() : true; $this->suppliedOptions = $options; }
[ "public", "function", "build", "(", ")", "{", "$", "options", "=", "$", "this", "->", "suppliedOptions", ";", "//check the permission", "$", "options", "[", "'permission'", "]", "=", "isset", "(", "$", "options", "[", "'permission'", "]", ")", "?", "$", ...
Builds the necessary fields on the object.
[ "Builds", "the", "necessary", "fields", "on", "the", "object", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Config.php#L84-L92
summerblue/administrator
src/Frozennode/Administrator/Config/Config.php
Config.validateData
public function validateData(array $data, array $rules, array $messages) { if ($rules) { $this->customValidator->setData($data); $this->customValidator->setRules($rules); $this->customValidator->setCustomMessages($messages); //if the validator fails, kick back the errors if ($this->customValidator->fails()) { return implode('. ', $this->customValidator->messages()->all()); } } return true; }
php
public function validateData(array $data, array $rules, array $messages) { if ($rules) { $this->customValidator->setData($data); $this->customValidator->setRules($rules); $this->customValidator->setCustomMessages($messages); //if the validator fails, kick back the errors if ($this->customValidator->fails()) { return implode('. ', $this->customValidator->messages()->all()); } } return true; }
[ "public", "function", "validateData", "(", "array", "$", "data", ",", "array", "$", "rules", ",", "array", "$", "messages", ")", "{", "if", "(", "$", "rules", ")", "{", "$", "this", "->", "customValidator", "->", "setData", "(", "$", "data", ")", ";"...
Validates the supplied data against the options rules. @param array $data @param array $rules @param array $messages @param mixed
[ "Validates", "the", "supplied", "data", "against", "the", "options", "rules", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Config/Config.php#L168-L182
summerblue/administrator
src/Frozennode/Administrator/Fields/Number.php
Number.setFilter
public function setFilter($filter) { parent::setFilter($filter); $minValue = $this->getOption('min_value'); $maxValue = $this->getOption('max_value'); $this->userOptions['min_value'] = $minValue ? str_replace(',', '', $minValue) : $minValue; $this->userOptions['max_value'] = $maxValue ? str_replace(',', '', $maxValue) : $maxValue; }
php
public function setFilter($filter) { parent::setFilter($filter); $minValue = $this->getOption('min_value'); $maxValue = $this->getOption('max_value'); $this->userOptions['min_value'] = $minValue ? str_replace(',', '', $minValue) : $minValue; $this->userOptions['max_value'] = $maxValue ? str_replace(',', '', $maxValue) : $maxValue; }
[ "public", "function", "setFilter", "(", "$", "filter", ")", "{", "parent", "::", "setFilter", "(", "$", "filter", ")", ";", "$", "minValue", "=", "$", "this", "->", "getOption", "(", "'min_value'", ")", ";", "$", "maxValue", "=", "$", "this", "->", "...
Sets the filter options for this item. @param array $filter
[ "Sets", "the", "filter", "options", "for", "this", "item", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Number.php#L37-L46
summerblue/administrator
src/Frozennode/Administrator/Fields/Number.php
Number.fillModel
public function fillModel(&$model, $input) { $model->{$this->getOption('field_name')} = is_null($input) || $input === '' ? null : $this->parseNumber($input); }
php
public function fillModel(&$model, $input) { $model->{$this->getOption('field_name')} = is_null($input) || $input === '' ? null : $this->parseNumber($input); }
[ "public", "function", "fillModel", "(", "&", "$", "model", ",", "$", "input", ")", "{", "$", "model", "->", "{", "$", "this", "->", "getOption", "(", "'field_name'", ")", "}", "=", "is_null", "(", "$", "input", ")", "||", "$", "input", "===", "''",...
Fill a model with input data. @param \Illuminate\Database\Eloquent\Model $model @param mixed $input @return array
[ "Fill", "a", "model", "with", "input", "data", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Number.php#L56-L59
summerblue/administrator
src/Frozennode/Administrator/Fields/Field.php
Field.build
public function build() { $options = $this->suppliedOptions; //set the title if it doesn't exist $options['title'] = $this->validator->arrayGet($options, 'title', $options['field_name']); //run the visible property closure if supplied $visible = $this->validator->arrayGet($options, 'visible'); if (is_callable($visible)) { $options['visible'] = $visible($this->config->getDataModel()) ? true : false; } //run the editable property's closure if supplied $editable = $this->validator->arrayGet($options, 'editable'); if (isset($editable) && is_callable($editable)) { $options['editable'] = $editable($this->config->getDataModel()); } $this->suppliedOptions = $options; }
php
public function build() { $options = $this->suppliedOptions; //set the title if it doesn't exist $options['title'] = $this->validator->arrayGet($options, 'title', $options['field_name']); //run the visible property closure if supplied $visible = $this->validator->arrayGet($options, 'visible'); if (is_callable($visible)) { $options['visible'] = $visible($this->config->getDataModel()) ? true : false; } //run the editable property's closure if supplied $editable = $this->validator->arrayGet($options, 'editable'); if (isset($editable) && is_callable($editable)) { $options['editable'] = $editable($this->config->getDataModel()); } $this->suppliedOptions = $options; }
[ "public", "function", "build", "(", ")", "{", "$", "options", "=", "$", "this", "->", "suppliedOptions", ";", "//set the title if it doesn't exist", "$", "options", "[", "'title'", "]", "=", "$", "this", "->", "validator", "->", "arrayGet", "(", "$", "option...
Builds a few basic options.
[ "Builds", "a", "few", "basic", "options", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Field.php#L108-L130
summerblue/administrator
src/Frozennode/Administrator/Fields/Field.php
Field.setFilter
public function setFilter($filter) { $this->userOptions['value'] = $this->getFilterValue($this->validator->arrayGet($filter, 'value', $this->getOption('value'))); $this->userOptions['min_value'] = $this->getFilterValue($this->validator->arrayGet($filter, 'min_value', $this->getOption('min_value'))); $this->userOptions['max_value'] = $this->getFilterValue($this->validator->arrayGet($filter, 'max_value', $this->getOption('max_value'))); }
php
public function setFilter($filter) { $this->userOptions['value'] = $this->getFilterValue($this->validator->arrayGet($filter, 'value', $this->getOption('value'))); $this->userOptions['min_value'] = $this->getFilterValue($this->validator->arrayGet($filter, 'min_value', $this->getOption('min_value'))); $this->userOptions['max_value'] = $this->getFilterValue($this->validator->arrayGet($filter, 'max_value', $this->getOption('max_value'))); }
[ "public", "function", "setFilter", "(", "$", "filter", ")", "{", "$", "this", "->", "userOptions", "[", "'value'", "]", "=", "$", "this", "->", "getFilterValue", "(", "$", "this", "->", "validator", "->", "arrayGet", "(", "$", "filter", ",", "'value'", ...
Sets the filter options for this item. @param array $filter
[ "Sets", "the", "filter", "options", "for", "this", "item", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Field.php#L175-L180
summerblue/administrator
src/Frozennode/Administrator/Fields/Field.php
Field.filterQuery
public function filterQuery(QueryBuilder &$query, &$selects = null) { $model = $this->config->getDataModel(); //if this field has a min/max range, set it if ($this->getOption('min_max')) { if ($minValue = $this->getOption('min_value')) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '>=', $minValue); } if ($maxValue = $this->getOption('max_value')) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '<=', $maxValue); } } }
php
public function filterQuery(QueryBuilder &$query, &$selects = null) { $model = $this->config->getDataModel(); //if this field has a min/max range, set it if ($this->getOption('min_max')) { if ($minValue = $this->getOption('min_value')) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '>=', $minValue); } if ($maxValue = $this->getOption('max_value')) { $query->where($model->getTable().'.'.$this->getOption('field_name'), '<=', $maxValue); } } }
[ "public", "function", "filterQuery", "(", "QueryBuilder", "&", "$", "query", ",", "&", "$", "selects", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "config", "->", "getDataModel", "(", ")", ";", "//if this field has a min/max range, set it", ...
Filters a query object given. @param \Illuminate\Database\Query\Builder $query @param array $selects
[ "Filters", "a", "query", "object", "given", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Field.php#L188-L202
summerblue/administrator
src/Frozennode/Administrator/Fields/Field.php
Field.getFilterValue
public function getFilterValue($value) { if (($value !== 0 && $value !== '0' && empty($value)) || (is_string($value) && trim($value) === '')) { return false; } else { return $value; } }
php
public function getFilterValue($value) { if (($value !== 0 && $value !== '0' && empty($value)) || (is_string($value) && trim($value) === '')) { return false; } else { return $value; } }
[ "public", "function", "getFilterValue", "(", "$", "value", ")", "{", "if", "(", "(", "$", "value", "!==", "0", "&&", "$", "value", "!==", "'0'", "&&", "empty", "(", "$", "value", ")", ")", "||", "(", "is_string", "(", "$", "value", ")", "&&", "tr...
Helper function to determine if a filter value should be considered "empty" or not. @param string value @return false|string
[ "Helper", "function", "to", "determine", "if", "a", "filter", "value", "should", "be", "considered", "empty", "or", "not", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Fields/Field.php#L211-L218
summerblue/administrator
src/Frozennode/Administrator/Http/Middleware/ValidateSettings.php
ValidateSettings.handle
public function handle($request, Closure $next) { $settingsName = $request->route()->parameter('settings'); app()->singleton('itemconfig', function ($app) use ($settingsName) { $configFactory = app('admin_config_factory'); return $configFactory->make($configFactory->getSettingsPrefix().$settingsName, true); }); return $next($request); }
php
public function handle($request, Closure $next) { $settingsName = $request->route()->parameter('settings'); app()->singleton('itemconfig', function ($app) use ($settingsName) { $configFactory = app('admin_config_factory'); return $configFactory->make($configFactory->getSettingsPrefix().$settingsName, true); }); return $next($request); }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ")", "{", "$", "settingsName", "=", "$", "request", "->", "route", "(", ")", "->", "parameter", "(", "'settings'", ")", ";", "app", "(", ")", "->", "singleton", "(", "'...
Handle an incoming request. @param \Illuminate\Http\Request $request @param \Closure $next @return mixed
[ "Handle", "an", "incoming", "request", "." ]
train
https://github.com/summerblue/administrator/blob/ef29593de6250b56776506b4590a3bbf91db9b37/src/Frozennode/Administrator/Http/Middleware/ValidateSettings.php#L17-L28
soberwp/intervention
src/Labels.php
Labels.setLabels
public function setLabels($type, $config) { global $wp_post_types; $labels = $wp_post_types[$type]->labels; // route to one and many if ($this->isArrayValueSet(0, $config)) { $this->setLabelMany($labels, $config[0]); } if ($this->isArrayValueSet(1, $config)) { $this->setLabelOne($labels, $config[1]); } }
php
public function setLabels($type, $config) { global $wp_post_types; $labels = $wp_post_types[$type]->labels; // route to one and many if ($this->isArrayValueSet(0, $config)) { $this->setLabelMany($labels, $config[0]); } if ($this->isArrayValueSet(1, $config)) { $this->setLabelOne($labels, $config[1]); } }
[ "public", "function", "setLabels", "(", "$", "type", ",", "$", "config", ")", "{", "global", "$", "wp_post_types", ";", "$", "labels", "=", "$", "wp_post_types", "[", "$", "type", "]", "->", "labels", ";", "// route to one and many", "if", "(", "$", "thi...
Get post type labels from $wp_post_types Call methods to update plural and singular labels @param string $type @param string|array $config
[ "Get", "post", "type", "labels", "from", "$wp_post_types", "Call", "methods", "to", "update", "plural", "and", "singular", "labels" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Labels.php#L16-L27
soberwp/intervention
src/Labels.php
Labels.setLabelMany
public function setLabelMany($labels, $many) { $labels->name = __($many); $labels->view_items = __('View ' . $many); $labels->search_items = __('Search ' . $many); $labels->not_found = __('No ' . strtolower($many) . ' Found'); $labels->not_found_in_trash = __('No ' . strtolower($many) . ' found in Trash'); $labels->all_items = __('All ' . $many); $labels->filter_items_list = __('Filter ' . $many . ' list'); $labels->items_list_navigation = __($many . ' list navigation'); $labels->items_list = __($many . ' list'); $labels->menu_name = __($many); return $labels; }
php
public function setLabelMany($labels, $many) { $labels->name = __($many); $labels->view_items = __('View ' . $many); $labels->search_items = __('Search ' . $many); $labels->not_found = __('No ' . strtolower($many) . ' Found'); $labels->not_found_in_trash = __('No ' . strtolower($many) . ' found in Trash'); $labels->all_items = __('All ' . $many); $labels->filter_items_list = __('Filter ' . $many . ' list'); $labels->items_list_navigation = __($many . ' list navigation'); $labels->items_list = __($many . ' list'); $labels->menu_name = __($many); return $labels; }
[ "public", "function", "setLabelMany", "(", "$", "labels", ",", "$", "many", ")", "{", "$", "labels", "->", "name", "=", "__", "(", "$", "many", ")", ";", "$", "labels", "->", "view_items", "=", "__", "(", "'View '", ".", "$", "many", ")", ";", "$...
Set post type plural labels @param object $labels @param string $many @return object
[ "Set", "post", "type", "plural", "labels" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Labels.php#L37-L50
soberwp/intervention
src/Labels.php
Labels.setLabelOne
public function setLabelOne($labels, $one) { $labels->singular_name = __($one); $labels->add_new = __('Add ' . $one); $labels->add_new_item = __('Add New ' . $one); $labels->edit_item = __('Edit ' . $one); $labels->new_item = __('New ' . $one); $labels->view_item = __('View ' . $one); $labels->parent_item_colon = __('Parent ' . $one . ':'); $labels->archives = __($one . ' Archives'); $labels->attributes = __($one . ' Attributes'); $labels->insert_into_item = __('Insert into ' . strtolower($one)); $labels->uploaded_to_this_item = __('Uploaded to this ' . strtolower($one)); $labels->filter_items_list = __('Filter ' . strtolower($one) . ' list '); $labels->name_admin_bar = __($one); return $labels; }
php
public function setLabelOne($labels, $one) { $labels->singular_name = __($one); $labels->add_new = __('Add ' . $one); $labels->add_new_item = __('Add New ' . $one); $labels->edit_item = __('Edit ' . $one); $labels->new_item = __('New ' . $one); $labels->view_item = __('View ' . $one); $labels->parent_item_colon = __('Parent ' . $one . ':'); $labels->archives = __($one . ' Archives'); $labels->attributes = __($one . ' Attributes'); $labels->insert_into_item = __('Insert into ' . strtolower($one)); $labels->uploaded_to_this_item = __('Uploaded to this ' . strtolower($one)); $labels->filter_items_list = __('Filter ' . strtolower($one) . ' list '); $labels->name_admin_bar = __($one); return $labels; }
[ "public", "function", "setLabelOne", "(", "$", "labels", ",", "$", "one", ")", "{", "$", "labels", "->", "singular_name", "=", "__", "(", "$", "one", ")", ";", "$", "labels", "->", "add_new", "=", "__", "(", "'Add '", ".", "$", "one", ")", ";", "...
Set post type singular labels @param object $labels @param string $one @return object
[ "Set", "post", "type", "singular", "labels" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Labels.php#L59-L75
soberwp/intervention
src/Labels.php
Labels.setLabelIcon
public function setLabelIcon($type, $config) { global $menu; switch ($type) { case 'post': $position = 5; break; case 'page': $position = 20; break; } if ($this->isArrayValueSet(2, $config)) { $icon = $config[2]; // Append 'dashicons-' prefix if it has not been included if (strpos($icon, 'dashicons-') === false) { $icon = 'dashicons-' . $icon; } $menu[$position][6] = $icon; } }
php
public function setLabelIcon($type, $config) { global $menu; switch ($type) { case 'post': $position = 5; break; case 'page': $position = 20; break; } if ($this->isArrayValueSet(2, $config)) { $icon = $config[2]; // Append 'dashicons-' prefix if it has not been included if (strpos($icon, 'dashicons-') === false) { $icon = 'dashicons-' . $icon; } $menu[$position][6] = $icon; } }
[ "public", "function", "setLabelIcon", "(", "$", "type", ",", "$", "config", ")", "{", "global", "$", "menu", ";", "switch", "(", "$", "type", ")", "{", "case", "'post'", ":", "$", "position", "=", "5", ";", "break", ";", "case", "'page'", ":", "$",...
Set post type icon @param object $labels @param string $many
[ "Set", "post", "type", "icon" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Labels.php#L83-L102
soberwp/intervention
src/Utils.php
Utils.isArrayValueSet
public function isArrayValueSet($pos, $arr) { if (is_array($arr) && array_key_exists($pos, $arr) && !empty($arr[$pos])) { return true; } }
php
public function isArrayValueSet($pos, $arr) { if (is_array($arr) && array_key_exists($pos, $arr) && !empty($arr[$pos])) { return true; } }
[ "public", "function", "isArrayValueSet", "(", "$", "pos", ",", "$", "arr", ")", "{", "if", "(", "is_array", "(", "$", "arr", ")", "&&", "array_key_exists", "(", "$", "pos", ",", "$", "arr", ")", "&&", "!", "empty", "(", "$", "arr", "[", "$", "pos...
Determine if array value has been set @param int $pos @param array $arr @return bool
[ "Determine", "if", "array", "value", "has", "been", "set" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Utils.php#L14-L19
soberwp/intervention
src/Instance.php
Instance.setDefaultConfig
protected function setDefaultConfig($args) { if (!current($this->config)) { $this->config = $this->toArray($args); } }
php
protected function setDefaultConfig($args) { if (!current($this->config)) { $this->config = $this->toArray($args); } }
[ "protected", "function", "setDefaultConfig", "(", "$", "args", ")", "{", "if", "(", "!", "current", "(", "$", "this", "->", "config", ")", ")", "{", "$", "this", "->", "config", "=", "$", "this", "->", "toArray", "(", "$", "args", ")", ";", "}", ...
Setup $config default values @param string|array $args
[ "Setup", "$config", "default", "values" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Instance.php#L27-L32
soberwp/intervention
src/Instance.php
Instance.setDefaultRoles
protected function setDefaultRoles($args) { if (!current($this->roles)) { $this->roles = $this->toArray($args); } }
php
protected function setDefaultRoles($args) { if (!current($this->roles)) { $this->roles = $this->toArray($args); } }
[ "protected", "function", "setDefaultRoles", "(", "$", "args", ")", "{", "if", "(", "!", "current", "(", "$", "this", "->", "roles", ")", ")", "{", "$", "this", "->", "roles", "=", "$", "this", "->", "toArray", "(", "$", "args", ")", ";", "}", "}"...
Setup $roles default values @param string|array $args
[ "Setup", "$roles", "default", "values" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Instance.php#L39-L44
soberwp/intervention
src/Instance.php
Instance.aliasUserRoles
protected function aliasUserRoles($args) { if (in_array('all', $args)) { $args = $this->getUserRoles(); } if (in_array('all-not-admin', $args)) { $args = $this->getUserRoles(false); } $args = preg_replace('/\badmin\b/', 'administrator', $args); return $args; }
php
protected function aliasUserRoles($args) { if (in_array('all', $args)) { $args = $this->getUserRoles(); } if (in_array('all-not-admin', $args)) { $args = $this->getUserRoles(false); } $args = preg_replace('/\badmin\b/', 'administrator', $args); return $args; }
[ "protected", "function", "aliasUserRoles", "(", "$", "args", ")", "{", "if", "(", "in_array", "(", "'all'", ",", "$", "args", ")", ")", "{", "$", "args", "=", "$", "this", "->", "getUserRoles", "(", ")", ";", "}", "if", "(", "in_array", "(", "'all-...
Alias user roles 'all' and 'all-not-admin' Replace short-hand 'admin' with 'administrator' @param string|array $args @return string|array
[ "Alias", "user", "roles", "all", "and", "all", "-", "not", "-", "admin", "Replace", "short", "-", "hand", "admin", "with", "administrator" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Instance.php#L53-L63
soberwp/intervention
src/Instance.php
Instance.getUserRoles
public static function getUserRoles($incl_admin = true) { $wp_roles = new \WP_Roles(); $wp_roles = $wp_roles->get_names(); if (!$incl_admin) { unset($wp_roles['administrator']); } $roles = []; foreach ($wp_roles as $key => $value) { $roles[] = $key; } return $roles; }
php
public static function getUserRoles($incl_admin = true) { $wp_roles = new \WP_Roles(); $wp_roles = $wp_roles->get_names(); if (!$incl_admin) { unset($wp_roles['administrator']); } $roles = []; foreach ($wp_roles as $key => $value) { $roles[] = $key; } return $roles; }
[ "public", "static", "function", "getUserRoles", "(", "$", "incl_admin", "=", "true", ")", "{", "$", "wp_roles", "=", "new", "\\", "WP_Roles", "(", ")", ";", "$", "wp_roles", "=", "$", "wp_roles", "->", "get_names", "(", ")", ";", "if", "(", "!", "$",...
Get all user roles from WordPress @param bool $include_admin @return array
[ "Get", "all", "user", "roles", "from", "WordPress" ]
train
https://github.com/soberwp/intervention/blob/78e1d139c3156ce8cf36adb489429c72097bf127/src/Instance.php#L71-L83
commerceguys/intl
src/NumberFormat/NumberFormatRepository.php
NumberFormatRepository.get
public function get($locale) { $definitions = $this->getDefinitions(); $availableLocales = array_keys($definitions); $locale = Locale::resolve($availableLocales, $locale, $this->fallbackLocale); $definition = $this->processDefinition($locale, $definitions[$locale]); return new NumberFormat($definition); }
php
public function get($locale) { $definitions = $this->getDefinitions(); $availableLocales = array_keys($definitions); $locale = Locale::resolve($availableLocales, $locale, $this->fallbackLocale); $definition = $this->processDefinition($locale, $definitions[$locale]); return new NumberFormat($definition); }
[ "public", "function", "get", "(", "$", "locale", ")", "{", "$", "definitions", "=", "$", "this", "->", "getDefinitions", "(", ")", ";", "$", "availableLocales", "=", "array_keys", "(", "$", "definitions", ")", ";", "$", "locale", "=", "Locale", "::", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/commerceguys/intl/blob/0fc176165f45d9f3dd9af50a05293c3fa99e4691/src/NumberFormat/NumberFormatRepository.php#L32-L40
commerceguys/intl
src/NumberFormat/NumberFormatRepository.php
NumberFormatRepository.processDefinition
protected function processDefinition($locale, array $definition) { $definition['locale'] = $locale; // The generation script strips all keys that have the same values // as the ones in 'en'. if ($definition['locale'] != 'en') { $definitions = $this->getDefinitions(); $definition += $definitions['en']; } return $definition; }
php
protected function processDefinition($locale, array $definition) { $definition['locale'] = $locale; // The generation script strips all keys that have the same values // as the ones in 'en'. if ($definition['locale'] != 'en') { $definitions = $this->getDefinitions(); $definition += $definitions['en']; } return $definition; }
[ "protected", "function", "processDefinition", "(", "$", "locale", ",", "array", "$", "definition", ")", "{", "$", "definition", "[", "'locale'", "]", "=", "$", "locale", ";", "// The generation script strips all keys that have the same values", "// as the ones in 'en'.", ...
Processes the number format definition for the provided locale. @param string $locale The locale. @param array $definition The definition @return array The processed definition.
[ "Processes", "the", "number", "format", "definition", "for", "the", "provided", "locale", "." ]
train
https://github.com/commerceguys/intl/blob/0fc176165f45d9f3dd9af50a05293c3fa99e4691/src/NumberFormat/NumberFormatRepository.php#L50-L61
commerceguys/intl
src/Formatter/NumberFormatter.php
NumberFormatter.format
public function format($number, array $options = []) { if (!is_numeric($number)) { $message = sprintf('The provided value "%s" is not a valid number or numeric string.', $number); throw new InvalidArgumentException($message); } $this->validateOptions($options); $options = array_replace($this->defaultOptions, $options); $number = (string) $number; // Percentages are passed as decimals (e.g. 0.2 for 20%). if ($options['style'] == 'percent') { $number = Calculator::multiply($number, '100'); } $numberFormat = $this->getNumberFormat($options['locale']); $number = $this->formatNumber($number, $numberFormat, $options); return $number; }
php
public function format($number, array $options = []) { if (!is_numeric($number)) { $message = sprintf('The provided value "%s" is not a valid number or numeric string.', $number); throw new InvalidArgumentException($message); } $this->validateOptions($options); $options = array_replace($this->defaultOptions, $options); $number = (string) $number; // Percentages are passed as decimals (e.g. 0.2 for 20%). if ($options['style'] == 'percent') { $number = Calculator::multiply($number, '100'); } $numberFormat = $this->getNumberFormat($options['locale']); $number = $this->formatNumber($number, $numberFormat, $options); return $number; }
[ "public", "function", "format", "(", "$", "number", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "number", ")", ")", "{", "$", "message", "=", "sprintf", "(", "'The provided value \"%s\" is not a valid numb...
{@inheritdoc}
[ "{" ]
train
https://github.com/commerceguys/intl/blob/0fc176165f45d9f3dd9af50a05293c3fa99e4691/src/Formatter/NumberFormatter.php#L68-L86