From dd83f2762fb0cb8129b47639897fb28c2c90f7e7 Mon Sep 17 00:00:00 2001 From: jeanbernard69 Date: Mon, 1 May 2017 07:35:11 +0200 Subject: [PATCH 001/124] Update AutoSet.php Avoid multiple database request to get column listing --- src/PanelTraits/AutoSet.php | 47 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/PanelTraits/AutoSet.php b/src/PanelTraits/AutoSet.php index f3310fef20..9028437694 100644 --- a/src/PanelTraits/AutoSet.php +++ b/src/PanelTraits/AutoSet.php @@ -20,21 +20,21 @@ public function setFromDb() // $this->labels[$field] = $this->makeLabel($field); $new_field = [ - 'name' => $field, - 'label' => ucfirst($field), - 'value' => null, - 'type' => $this->getFieldTypeFromDbColumnType($field), - 'values' => [], + 'name' => $field, + 'label' => ucfirst($field), + 'value' => null, + 'type' => $this->getFieldTypeFromDbColumnType($field), + 'values' => [], 'attributes' => [], ]; $this->create_fields[$field] = $new_field; $this->update_fields[$field] = $new_field; - if (! in_array($field, $this->model->getHidden())) { + if (!in_array($field, $this->model->getHidden())) { $this->columns[$field] = [ - 'name' => $field, + 'name' => $field, 'label' => ucfirst($field), - 'type' => $this->getFieldTypeFromDbColumnType($field), + 'type' => $this->getFieldTypeFromDbColumnType($field), ]; } }, $this->getDbColumnsNames()); @@ -47,9 +47,10 @@ public function setFromDb() */ public function getDbColumnTypes() { - $table_columns = $this->model->getConnection()->getSchemaBuilder()->getColumnListing($this->model->getTable()); + // Pass this variable in instance proprierty to avoid multiple request to database to get column listing + $this->table_columns = $this->model->getConnection()->getSchemaBuilder()->getColumnListing($this->model->getTable()); - foreach ($table_columns as $key => $column) { + foreach ($this->table_columns as $key => $column) { $column_type = $this->model->getConnection()->getSchemaBuilder()->getColumnType($this->model->getTable(), $column); $this->db_column_types[$column]['type'] = trim(preg_replace('/\(\d+\)(.*)/i', '', $column_type)); $this->db_column_types[$column]['default'] = ''; // no way to do this using DBAL?! @@ -67,7 +68,7 @@ public function getDbColumnTypes() */ public function getFieldTypeFromDbColumnType($field) { - if (! array_key_exists($field, $this->db_column_types)) { + if (!array_key_exists($field, $this->db_column_types)) { return 'text'; } @@ -85,13 +86,13 @@ public function getFieldTypeFromDbColumnType($field) case 'mediumint': case 'longint': return 'number'; - break; + break; case 'string': case 'varchar': case 'set': return 'text'; - break; + break; // case 'enum': // return 'enum'; @@ -99,29 +100,29 @@ public function getFieldTypeFromDbColumnType($field) case 'tinyint': return 'active'; - break; + break; case 'text': case 'mediumtext': case 'longtext': return 'textarea'; - break; + break; case 'date': return 'date'; - break; + break; case 'datetime': case 'timestamp': return 'datetime'; - break; + break; case 'time': return 'time'; - break; + break; default: return 'text'; - break; + break; } } @@ -145,11 +146,13 @@ public function makeLabel($value) public function getDbColumnsNames() { // Automatically-set columns should be both in the database, and in the $fillable variable on the Eloquent Model - $columns = $this->model->getConnection()->getSchemaBuilder()->getColumnListing($this->model->getTable()); + + $columns = $this->table_columns; + $fillable = $this->model->getFillable(); - if (! empty($fillable)) { - $columns = array_intersect($columns, $fillable); + if (!empty($fillable)) { + $columns = array_intersect($this->table_columns, $fillable); } // but not updated_at, deleted_at From a4b7f62a1779695df041dac66e0ba0024115a6fc Mon Sep 17 00:00:00 2001 From: ran81 Date: Tue, 9 Jan 2018 14:54:45 +0800 Subject: [PATCH 002/124] Allow custom sorting for crud columns --- src/PanelTraits/Query.php | 17 +++++++++++++++++ .../Http/Controllers/CrudFeatures/AjaxTable.php | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/src/PanelTraits/Query.php b/src/PanelTraits/Query.php index dee473c54d..1b61888415 100644 --- a/src/PanelTraits/Query.php +++ b/src/PanelTraits/Query.php @@ -53,6 +53,23 @@ public function orderBy($field, $order = 'asc') return $this->query->orderBy($field, $order); } + /** + * Order the results of the query in a custom way. + */ + public function customOrderBy($column, $column_direction) + { + if (isset($column['orderLogic'])) { + $this->query->getQuery()->orders = null; + + $orderLogic = $column['orderLogic']; + + if (is_callable($orderLogic)) { + return $orderLogic($this->query, $column, $column_direction); + } + } + return $this->query; + } + /** * Group the results of the query in a certain way. * diff --git a/src/app/Http/Controllers/CrudFeatures/AjaxTable.php b/src/app/Http/Controllers/CrudFeatures/AjaxTable.php index 5ed7bfe733..7a46f7218a 100644 --- a/src/app/Http/Controllers/CrudFeatures/AjaxTable.php +++ b/src/app/Http/Controllers/CrudFeatures/AjaxTable.php @@ -45,6 +45,11 @@ public function search() if ($column['tableColumn']) { $this->crud->orderBy($column['name'], $column_direction); } + + // check for custom order logic in the column definition + if (isset($column['orderLogic'])) { + $this->crud->customOrderBy($column, $column_direction); + } } $entries = $this->crud->getEntries(); From 23acdd3fe8f1fbab517021d21341b2379a7af0bd Mon Sep 17 00:00:00 2001 From: ran81 Date: Wed, 17 Jan 2018 11:46:48 +0800 Subject: [PATCH 003/124] Fix comments. --- src/PanelTraits/Query.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/PanelTraits/Query.php b/src/PanelTraits/Query.php index 1b61888415..3819348257 100644 --- a/src/PanelTraits/Query.php +++ b/src/PanelTraits/Query.php @@ -55,18 +55,26 @@ public function orderBy($field, $order = 'asc') /** * Order the results of the query in a custom way. + * + * @param [type] + * @param string + * + * @return [type] */ - public function customOrderBy($column, $column_direction) + public function customOrderBy($column, $column_direction = 'asc') { - if (isset($column['orderLogic'])) { - $this->query->getQuery()->orders = null; - - $orderLogic = $column['orderLogic']; + if (! isset($column['orderLogic'])) { + return $this->query; + } + + $this->query->getQuery()->orders = null; - if (is_callable($orderLogic)) { - return $orderLogic($this->query, $column, $column_direction); - } + $orderLogic = $column['orderLogic']; + + if (is_callable($orderLogic)) { + return $orderLogic($this->query, $column, $column_direction); } + return $this->query; } From e3d5e3370bb263df4fe8f62192913fbf716fa74a Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 2 May 2018 00:23:47 +0300 Subject: [PATCH 004/124] Replace ucfirst with mb_convert_case --- src/app/Http/Controllers/CrudController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Http/Controllers/CrudController.php b/src/app/Http/Controllers/CrudController.php index 23851b0068..f851db7678 100644 --- a/src/app/Http/Controllers/CrudController.php +++ b/src/app/Http/Controllers/CrudController.php @@ -64,7 +64,7 @@ public function index() $this->crud->hasAccessOrFail('list'); $this->data['crud'] = $this->crud; - $this->data['title'] = ucfirst($this->crud->entity_name_plural); + $this->data['title'] = mb_convert_case($this->crud->entity_name_plural, MB_CASE_TITLE); // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package return view($this->crud->getListView(), $this->data); From b7596e982e628dc41118fdc160353cab2af4a1d3 Mon Sep 17 00:00:00 2001 From: Cristian Tabacitu Date: Thu, 10 May 2018 05:40:38 +0000 Subject: [PATCH 005/124] fixes #1370 - multibyte ucfirst --- src/PanelTraits/AutoSet.php | 2 +- src/PanelTraits/Columns.php | 6 +++--- src/PanelTraits/Fields.php | 2 +- src/app/Http/Controllers/CrudFeatures/Revisions.php | 2 +- src/resources/views/inc/revision_timeline.blade.php | 4 ++-- src/resources/views/show.blade.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/PanelTraits/AutoSet.php b/src/PanelTraits/AutoSet.php index 9ce6e62e3a..a34c334d6a 100644 --- a/src/PanelTraits/AutoSet.php +++ b/src/PanelTraits/AutoSet.php @@ -164,7 +164,7 @@ public function makeLabel($value) return ($this->labeller)($value); } - return trim(preg_replace('/(id|at|\[\])$/i', '', ucfirst(str_replace('_', ' ', $value)))); + return trim(preg_replace('/(id|at|\[\])$/i', '', mb_ucfirst(str_replace('_', ' ', $value)))); } /** diff --git a/src/PanelTraits/Columns.php b/src/PanelTraits/Columns.php index 142f8804a7..fb112f6e98 100644 --- a/src/PanelTraits/Columns.php +++ b/src/PanelTraits/Columns.php @@ -37,7 +37,7 @@ public function setColumns($columns) } else { $this->addColumn([ 'name' => $column, - 'label' => ucfirst($column), + 'label' => mb_ucfirst($column), 'type' => 'text', ]); } @@ -47,7 +47,7 @@ public function setColumns($columns) if (is_string($columns)) { $this->addColumn([ 'name' => $columns, - 'label' => ucfirst($columns), + 'label' => mb_ucfirst($columns), 'type' => 'text', ]); } @@ -198,7 +198,7 @@ public function addDefaultTypeToColumn($column) public function addDefaultLabel($array) { if (! array_key_exists('label', (array) $array) && array_key_exists('name', (array) $array)) { - $array = array_merge(['label' => ucfirst($this->makeLabel($array['name']))], $array); + $array = array_merge(['label' => mb_ucfirst($this->makeLabel($array['name']))], $array); return $array; } diff --git a/src/PanelTraits/Fields.php b/src/PanelTraits/Fields.php index e836b37a6a..a31d55b235 100644 --- a/src/PanelTraits/Fields.php +++ b/src/PanelTraits/Fields.php @@ -32,7 +32,7 @@ public function addField($field, $form = 'both') // if the label is missing, we should set it if (! isset($completeFieldsArray['label'])) { - $completeFieldsArray['label'] = ucfirst($completeFieldsArray['name']); + $completeFieldsArray['label'] = mb_ucfirst($completeFieldsArray['name']); } // if the field type is missing, we should set it diff --git a/src/app/Http/Controllers/CrudFeatures/Revisions.php b/src/app/Http/Controllers/CrudFeatures/Revisions.php index 7e5ae1036f..b9819a137d 100644 --- a/src/app/Http/Controllers/CrudFeatures/Revisions.php +++ b/src/app/Http/Controllers/CrudFeatures/Revisions.php @@ -21,7 +21,7 @@ public function listRevisions($id) // get the info for that entry $this->data['entry'] = $this->crud->getEntry($id); $this->data['crud'] = $this->crud; - $this->data['title'] = ucfirst($this->crud->entity_name).' '.trans('backpack::crud.revisions'); + $this->data['title'] = mb_ucfirst($this->crud->entity_name).' '.trans('backpack::crud.revisions'); $this->data['id'] = $id; $this->data['revisions'] = $this->crud->listRevisions($id); diff --git a/src/resources/views/inc/revision_timeline.blade.php b/src/resources/views/inc/revision_timeline.blade.php index 7751419b54..dadd08cfb9 100644 --- a/src/resources/views/inc/revision_timeline.blade.php +++ b/src/resources/views/inc/revision_timeline.blade.php @@ -17,8 +17,8 @@

{{ $history->userResponsible()?$history->userResponsible()->name:trans('backpack::crud.guest_user') }} {{ trans('backpack::crud.changed_the') }} {{ $history->fieldName() }}

-
{{ ucfirst(trans('backpack::crud.from')) }}:
-
{{ ucfirst(trans('backpack::crud.to')) }}:
+
{{ mb_ucfirst(trans('backpack::crud.from')) }}:
+
{{ mb_ucfirst(trans('backpack::crud.to')) }}:
{{ $history->oldValue() }}
diff --git a/src/resources/views/show.blade.php b/src/resources/views/show.blade.php index 8ce5dc9800..e9d2e4bb1c 100644 --- a/src/resources/views/show.blade.php +++ b/src/resources/views/show.blade.php @@ -4,7 +4,7 @@

{{ $crud->entity_name_plural }} - {{ ucfirst(trans('backpack::crud.preview')).' '.$crud->entity_name }}. + {{ mb_ucfirst(trans('backpack::crud.preview')).' '.$crud->entity_name }}.