Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrutinizer Auto-Fixes #5

Merged
merged 1 commit into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/CrudServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function boot()

// PUBLISH FILES
// publish lang files
$this->publishes([ __DIR__.'/resources/lang' => resource_path('lang/vendor/backpack'), ], 'lang');
$this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack'), ], 'lang');
// publish views
$this->publishes([ __DIR__.'/resources/views' => resource_path('views/vendor/backpack/crud'), ], 'views');
$this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/crud'), ], 'views');
// publish public Backpack CRUD assets
$this->publishes([ __DIR__.'/public' => public_path('vendor/backpack'), ], 'public');
$this->publishes([__DIR__.'/public' => public_path('vendor/backpack'), ], 'public');
// publish custom files for elFinder
$this->publishes([
__DIR__.'/config/elfinder.php' => config_path('elfinder.php'),
Expand Down Expand Up @@ -68,7 +68,7 @@ public function register()

private function registerCRUD()
{
$this->app->bind('CRUD',function($app){
$this->app->bind('CRUD', function($app) {
return new CRUD($app);
});
}
Expand Down
13 changes: 6 additions & 7 deletions src/CrudTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait CrudTrait {
|--------------------------------------------------------------------------
*/

public static function getPossibleEnumValues($field_name){
public static function getPossibleEnumValues($field_name){
$instance = new static; // create an instance of the model to be able to get the table name
$type = DB::select( DB::raw('SHOW COLUMNS FROM '.$instance->getTable().' WHERE Field = "'.$field_name.'"') )[0]->Type;
preg_match('/^enum\((.*)\)$/', $type, $matches);
Expand All @@ -27,9 +27,9 @@ public static function getPossibleEnumValues($field_name){

public static function isColumnNullable($column_name) {
$instance = new static; // create an instance of the model to be able to get the table name
$answer = DB::select( DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$instance->getTable()."' AND COLUMN_NAME='".$column_name."' AND table_schema='".env('DB_DATABASE')."'") )[0];
$answer = DB::select(DB::raw("SELECT IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='".$instance->getTable()."' AND COLUMN_NAME='".$column_name."' AND table_schema='".env('DB_DATABASE')."'"))[0];

return ($answer->IS_NULLABLE == 'YES'?true:false);
return ($answer->IS_NULLABLE == 'YES' ? true : false);
}


Expand Down Expand Up @@ -67,7 +67,7 @@ public function addFakes($columns = ['extras']) {
* Return the entity with fake fields as attributes.
*
* @param array $columns - the database columns that contain the JSONs
* @return obj
* @return CrudTrait
*/
public function withFakes($columns = [])
{
Expand All @@ -76,8 +76,7 @@ public function withFakes($columns = [])
if (!count($columns)) {
if (property_exists($model, 'fakeColumns')) {
$columns = $this->fakeColumns;
}
else
} else
{
$columns = ['extras'];
}
Expand Down Expand Up @@ -128,7 +127,7 @@ public function allTranslations()

public function translation($translation_lang = false)
{
if ($translation_lang==false) {
if ($translation_lang == false) {
$translation_lang = Lang::locale();
}

Expand Down
50 changes: 22 additions & 28 deletions src/app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public function index()
if (property_exists($model, 'translatable'))
{
$this->data['entries'] = $model::where('translation_lang', \Lang::locale())->get();
}
else
} else
{
$this->data['entries'] = $model::all();
}
Expand Down Expand Up @@ -106,7 +105,7 @@ public function create()
* Store a newly created resource in the database.
*
* @param StoreRequest $request - type injection used for validation using Requests
* @return Response
* @return \Illuminate\Http\RedirectResponse
*/
public function storeCrud(StoreRequest $request = null)
{
Expand All @@ -124,7 +123,7 @@ public function storeCrud(StoreRequest $request = null)
// if it's a relationship with a pivot table, also sync that
$this->prepareFields();
foreach ($this->crud['fields'] as $k => $field) {
if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name']))
{
$model::find($item->id)->$field['name']()->attach(\Request::input($field['name']));
}
Expand Down Expand Up @@ -182,7 +181,7 @@ public function edit($id)
* Update the specified resource in the database.
*
* @param UpdateRequest $request - type injection used for validation using Requests
* @return Response
* @return \Illuminate\Http\RedirectResponse
*/
public function updateCrud(UpdateRequest $request = null)
{
Expand All @@ -198,7 +197,7 @@ public function updateCrud(UpdateRequest $request = null)

// if it's a relationship with a pivot table, also sync that
foreach ($this->crud['fields'] as $k => $field) {
if (isset($field['pivot']) && $field['pivot']==true && \Request::has($field['name']))
if (isset($field['pivot']) && $field['pivot'] == true && \Request::has($field['name']))
{
$model::find(\Request::input('id'))->$field['name']()->sync(\Request::input($field['name']));
}
Expand Down Expand Up @@ -235,7 +234,7 @@ public function show($id)
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
* @return string
*/
public function destroy($id)
{
Expand Down Expand Up @@ -279,8 +278,7 @@ public function reorder($lang = false)
$this->data['entries'] = $model::where('translation_lang', $lang)->get();
$this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
$this->data['active_language'] = $lang;
}
else
} else
{
$this->data['entries'] = $model::all();
}
Expand Down Expand Up @@ -323,8 +321,7 @@ public function saveReorder()
$count++;
}
}
}
else
} else
{
return false;
}
Expand Down Expand Up @@ -358,7 +355,7 @@ public function showDetailsRow($id)
$this->data['languages'] = \Backpack\LangFileManager\app\Models\Language::all();
$this->data['languages_already_translated_in'] = $this->data['entry']->translationLanguages();
$this->data['languages_to_translate_in'] = $this->data['languages']->diff($this->data['languages_already_translated_in']);
$this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function ($item) {
$this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function($item) {
return $item->abbr == \Lang::locale();
});
}
Expand All @@ -381,8 +378,7 @@ public function translateItem($id, $lang)
if ($existing_translation)
{
$new_entry = $existing_translation;
}
else
} else
{
// get the info for that entry
$new_entry_attributes = $this->data['entry']->getAttributes();
Expand Down Expand Up @@ -421,22 +417,21 @@ protected function compactFakeFields($request) {
// go through each defined field
foreach ($this->crud['fields'] as $k => $field) {
// if it's a fake field
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) {
// add it to the request in its appropriate variable - the one defined, if defined
if (isset($this->crud['fields'][$k]['store_in'])) {
$request[$this->crud['fields'][$k]['store_in']][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];

$remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) {
array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
}
}
else //otherwise in the one defined in the $crud variable
} else //otherwise in the one defined in the $crud variable
{
$request['extras'][$this->crud['fields'][$k]['name']] = $request[$this->crud['fields'][$k]['name']];

$remove_fake_field = array_pull($request, $this->crud['fields'][$k]['name']);
if(!in_array('extras', $fake_field_columns_to_encode, true)){
if (!in_array('extras', $fake_field_columns_to_encode, true)) {
array_push($fake_field_columns_to_encode, 'extras');
}
}
Expand Down Expand Up @@ -469,16 +464,15 @@ protected function getFakeColumnsAsArray() {

foreach ($this->crud['fields'] as $k => $field) {
// if it's a fake field
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake']==true) {
if (isset($this->crud['fields'][$k]['fake']) && $this->crud['fields'][$k]['fake'] == true) {
// add it to the request in its appropriate variable - the one defined, if defined
if (isset($this->crud['fields'][$k]['store_in'])) {
if(!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)){
if (!in_array($this->crud['fields'][$k]['store_in'], $fake_field_columns_to_encode, true)) {
array_push($fake_field_columns_to_encode, $this->crud['fields'][$k]['store_in']);
}
}
else //otherwise in the one defined in the $crud variable
} else //otherwise in the one defined in the $crud variable
{
if(!in_array('extras', $fake_field_columns_to_encode, true)){
if (!in_array('extras', $fake_field_columns_to_encode, true)) {
array_push($fake_field_columns_to_encode, 'extras');
}
}
Expand Down Expand Up @@ -536,8 +530,7 @@ protected function prepareFields($entry = false)
if (isset($this->crud['create_fields']))
{
$this->crud['fields'] = $this->crud['create_fields'];
}
elseif (isset($this->crud['update_fields']))
} elseif (isset($this->crud['update_fields']))
{
$this->crud['fields'] = $this->crud['update_fields'];
}
Expand Down Expand Up @@ -569,8 +562,9 @@ protected function prepareFields($entry = false)

// if no field type is defined, assume the "text" field type
foreach ($this->crud['fields'] as $k => $field) {
if (!isset($this->crud['fields'][$k]['type']))
$this->crud['fields'][$k]['type'] = 'text';
if (!isset($this->crud['fields'][$k]['type'])) {
$this->crud['fields'][$k]['type'] = 'text';
}
}

// if an entry was passed, we're preparing for the update form, not create
Expand Down
10 changes: 5 additions & 5 deletions src/resources/views-elfinder/filepicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

<!-- elFinder CSS (REQUIRED) -->
<link rel="stylesheet" type="text/css" href="<?= asset($dir . '/css/elfinder.min.css') ?>">
<link rel="stylesheet" type="text/css" href="<?= asset($dir.'/css/elfinder.min.css') ?>">
<!-- <link rel="stylesheet" type="text/css" href="<?= asset($dir.'/css/theme.css') ?>"> -->
<link rel="stylesheet" type="text/css" href="<?= asset('vendor/backpack/elfinder/elfinder.backpack.theme.css') ?>">

<!-- elFinder JS (REQUIRED) -->
<script src="<?= asset($dir . '/js/elfinder.min.js') ?>"></script>
<script src="<?= asset($dir.'/js/elfinder.min.js') ?>"></script>

<?php if ($locale) { ?>
<!-- elFinder translation (OPTIONAL) -->
<script src="<?= asset($dir . "/js/i18n/elfinder.$locale.js") ?>"></script>
<script src="<?= asset($dir."/js/i18n/elfinder.$locale.js") ?>"></script>
<?php } ?>
<!-- Include jQuery, jQuery UI, elFinder (REQUIRED) -->

<?php
$mimeTypes = implode(',',array_map(function($t){return "'".$t."'";}, explode(',',$type)));
$mimeTypes = implode(',', array_map(function($t) {return "'".$t."'"; }, explode(',', $type)));
?>

<script type="text/javascript">
$().ready(function () {
var elf = $('#elfinder').elfinder({
// set your elFinder options here
<?php if($locale){ ?>
<?php if ($locale) { ?>
lang: '<?= $locale ?>', // locale
<?php } ?>
customData: {
Expand Down
6 changes: 3 additions & 3 deletions src/resources/views/fields/page_or_link.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class="form-control"
</div>
<div class="col-sm-9">
<!-- external link input -->
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type!='external_link') { echo 'hidden'; } ?>" id="page_or_link_external_link">
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type != 'external_link') { echo 'hidden'; } ?>" id="page_or_link_external_link">
<input
type="url"
class="form-control"
Expand All @@ -58,7 +58,7 @@ class="form-control"
>
</div>
<!-- internal link input -->
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type!='internal_link') { echo 'hidden'; } ?>" id="page_or_link_internal_link">
<div class="page_or_link_value <?php if (!isset($entry) || $entry->type != 'internal_link') { echo 'hidden'; } ?>" id="page_or_link_internal_link">
<input
type="text"
class="form-control"
Expand All @@ -75,7 +75,7 @@ class="form-control"
>
</div>
<!-- page slug input -->
<div class="page_or_link_value <?php if (isset($entry) && $entry->type!='page_link') { echo 'hidden'; } ?>" id="page_or_link_page">
<div class="page_or_link_value <?php if (isset($entry) && $entry->type != 'page_link') { echo 'hidden'; } ?>" id="page_or_link_page">
<select
class="form-control"
name="page_id"
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/form_content.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
{{-- For each form type, load its assets, if needed --}}
{{-- But only once per field type (no need to include the same css/js files multiple times on the same page) --}}
<?php
$loaded_form_types_css = array();
$loaded_form_types_js = array();
$loaded_form_types_css = array();
$loaded_form_types_js = array();
?>

@section('after_styles')
Expand Down
16 changes: 8 additions & 8 deletions src/resources/views/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@
if ($results && $results->count()) {
$results_array = $results->lists($column['attribute'], 'id');
echo implode(', ', $results_array->toArray());
}
else
{
}
else
{
echo '-';
}
?></td>
}
?></td>
@elseif (isset($column['type']) && $column['type']=='select')
{{-- single relationships (1-1, 1-n) --}}
<td><?php
if ($entry->{$column['entity']}()->getResults()) {
echo $entry->{$column['entity']}()->getResults()->{$column['attribute']};
}
?></td>
}
?></td>
@elseif (isset($column['type']) && $column['type']=='model_function')
{{-- custom return value --}}
<td><?php
echo $entry->{$column['function_name']}();
?></td>
?></td>
@else
{{-- regular object attribute --}}
<td>{{ str_limit(strip_tags($entry->$column['name']), 80, "[...]") }}</td>
Expand Down