Skip to content

Commit

Permalink
Added Developer Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ConsoleTVs committed Jun 19, 2016
1 parent e3ee6ef commit 50df646
Show file tree
Hide file tree
Showing 25 changed files with 1,616 additions and 181 deletions.
164 changes: 164 additions & 0 deletions app/Http/Controllers/Admin/Data/Create/DevGet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

/*
+---------------------------------------------------------------------------+
| Laralum Developer Data Fetcher |
+---------------------------------------------------------------------------+
| |
| * Requires: |
| |
| $row - The row information |
| |
| * Available variables: |
| |
| $data - The table settings |
| $table - The table name +-------------+
| $hidden: Columns that will not be displayed in the edit form, and they won't be updated +----------------------------+
| $empty: Columns that will not have their current value when editing them (eg: password field is hidden in the model) |
| $confirmed: fields that will need to be confirmed twice +-+
| $encrypted: Fields that will be encrypted using: Crypt::encrypt(); when they are saved and decrypted when editing them +---------------------------+
| $hashed: Fields that will be hashed when they are saved in the database, will be empty on editing, and if saved as empty they will not be modified |
| $masked: Fields that will be displayed as a type='password', so their content when beeing modified won't be visible +------------------------------+
| $default_random: Fields that if no data is set, they will be randomly generated (10 characters) +-------------------+
| $su_hidden: Columns that will be added to the hidden array if the user is su +------------------+
| $columns: the row columns +--+
| $fields: get the available fields |
| |
+---------------------------------------------------------------------------+
| |
| This file creates the variables nessesary to make |
| the dynamic field edition avialable to all the controllers |
| regardless of it's differences. |
| |
+---------------------------------------------------------------------------+
*/

require('../app/Http/Controllers/Admin/Data/DevData.php');




if(array_key_exists($name, $data)) {
$data = $data[$name];
if(!array_key_exists('create', $data)){
$data['create'] = [];
}
if(!array_key_exists('edit', $data)){
$data['edit'] = [];
}
} else {
$data = ['create' => [], 'edit' => []];
}




# Get the table data
$table = $name;



if(array_key_exists('allow', $data['create'])) {
$allow = $data['create']['allow'];
} else {
$allow = true;
}

$su_hidden = [];
$empty = [];

if(array_key_exists('hidden', $data['create'])) {
$hidden = $data['create']['hidden'];
} else {
$hidden = [];
}

if(array_key_exists('default_random', $data['create'])) {
$default_random = $data['create']['default_random'];
} else {
$default_random = [];
}

if(array_key_exists('confirmed', $data['create'])) {
$confirmed = $data['create']['confirmed'];
} else {
$confirmed = [];
}

if(array_key_exists('encrypted', $data['create'])) {
$encrypted = $data['create']['encrypted'];
} else {
$encrypted = [];
}

if(array_key_exists('hashed', $data['create'])) {
$hashed = $data['create']['hashed'];
} else {
$hashed = [];
}

if(array_key_exists('masked', $data['create'])) {
$masked = $data['create']['masked'];
} else {
$masked = [];
}

if(array_key_exists('validator', $data['create'])) {
$validator = $data['create']['validator'];
} else {
$validator = [];
}

if(array_key_exists('code', $data['edit'])) {
$code = $data['edit']['code'];
} else {
$code = [];
}

if(array_key_exists('wysiwyg', $data['create'])) {
$wysiwyg = $data['create']['wysiwyg'];
} else {
$wysiwyg = [];
}

















# Get the row table columns
$columns = Schema::getColumnListing($table);

# Add su_hidden to hidden if the row is su
if(Schema::hasColumn($table, 'su') and $row->su) {
# Add the su_hidden fields to the hiden variable
foreach($su_hidden as $su_hid) {
array_push($hidden, $su_hid);
}
}

# Gets the fields available to edit / update
$final_columns = [];
foreach($columns as $column) {
$add = true;
foreach($hidden as $hide) {
if($column == $hide) {
$add = false;
}
}
if($add) {
array_push($final_columns, $column);
}
}
$fields = $final_columns;
86 changes: 86 additions & 0 deletions app/Http/Controllers/Admin/Data/Create/DevSave.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/*
+---------------------------------------------------------------------------+
| Laralum Data Saver |
+---------------------------------------------------------------------------+
| |
| * Requires: |
| |
| $row - The row information |
| $request - The form requrest information |
| |
+---------------------------------------------------------------------------+
| |
| This files saves the new information to the database | |
| |
+---------------------------------------------------------------------------+
*/

include('DevGet.php');

# Validate The Request
$this->validate($request, $validator);

# Update the row
foreach($fields as $field) {

$save = true;

# Check the field type
$type = Schema::getColumnType($table, $field);

# Get the value
$value = $request->input($field);

if($type == 'string' or $type == 'integer') {

# Check if it's a default_random field
foreach($default_random as $random) {
if($random == $field) {
if(!$value) {
$value = str_random(10);
}
}
}

# Check if it's a hashed field
foreach($hashed as $hash) {
if($hash == $field) {
if($value) {
$value = Hash::make($value);
} else {
$save = false;
}
}
}

# Check if it's an encrypted field
foreach($encrypted as $encrypt) {
if($encrypt == $field) {
$value = Crypt::encrypt($value);
}
}

# Save it
if($save) {
$update[$field] = $value;
}

} elseif($type == 'boolean') {

# Save it
if($value) {
$update[$field] = true;
} else {
$update[$field] = false;
}

} else {
# Save it
$update[$field] = $value;
}
}

# Save the row
DB::table($name)->insert($update);
4 changes: 2 additions & 2 deletions app/Http/Controllers/Admin/Data/Create/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| * Requires: |
| |
| $row - The row information |
| $data_index - The Data array index for the table configuration |
| |
| * Available variables: |
| |
Expand All @@ -20,8 +21,7 @@
| $hashed: Fields that will be hashed when they are saved in the database, will be empty on editing, and if saved as empty they will not be modified |
| $masked: Fields that will be displayed as a type='password', so their content when beeing modified won't be visible +------------------------------+
| $default_random: Fields that if no data is set, they will be randomly generated (10 characters) +-------------------+
| $su_hidden: Columns that will be added to the hidden array if the user is su +------------------+
| $columns: the row columns +--+
| $columns: the row columns +---------------------+
| $fields: get the available fields |
| |
+---------------------------------------------------------------------------+
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/Admin/Data/Create/SimpleGet.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
| Laralum Simple Data Fetcher |
+---------------------------------------------------------------------------+
| |
| * Requires: |
| |
| $row - The row information |
| $data_index - The Data array index for the table configuration |
| |
| * Available variables: |
| |
| $data - The table settings |
Expand All @@ -15,8 +20,7 @@
| $hashed: Fields that will be hashed when they are saved in the database, will be empty on editing, and if saved as empty they will not be modified |
| $masked: Fields that will be displayed as a type='password', so their content when beeing modified won't be visible +------------------------------+
| $default_random: Fields that if no data is set, they will be randomly generated (10 characters) +-------------------+
| $su_hidden: Columns that will be added to the hidden array if the user is su +------------------+
| +--+
| +---------------------+
+---------------------------------------------------------------------------+
| |
| This file creates the variables nessesary to make |
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Admin/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
| wysiwyg: Fields that can be edited using a wysiwyg editor |
| validator: validator settings when executing: $this->validate(); |
| |
| Note: Do not change the first index |
| |
+---------------------------------------------------------------------------+
| |
| This file allows you to setup all the information |
Expand Down
89 changes: 89 additions & 0 deletions app/Http/Controllers/Admin/Data/DevData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

<?php
/*
+---------------------------------------------------------------------------+
| Laralum Developer Data Configuration |
+---------------------------------------------------------------------------+
| |
| * Available settings: |
| |
| hide_display: Hides the field when the table is displayed |
| table: The table name +-------------+
| hidden: Columns that will not be displayed in the edit form, and they won't be updated +----------------------------+
| empty: Columns that will not have their current value when editing them (eg: password field is hidden in the model) |
| confirmed: fields that will need to be confirmed twice +-+
| encrypted: Fields that will be encrypted using: Crypt::encrypt(); when they are saved and decrypted when editing them +---------------------------+
| hashed: Fields that will be hashed when they are saved in the database, will be empty on editing, and if saved as empty they will not be modified |
| masked: Fields that will be displayed as a type='password', so their content when beeing modified won't be visible +------------------------------+
| default_random: Fields that if no data is set, they will be randomly generated (10 characters) +-------------------+
| su_hidden: Columns that will be added to the hidden array if the user is su +------------------+
| code: Fields that can be edited using a code editor +-+
| wysiwyg: Fields that can be edited using a wysiwyg editor |
| validator: validator settings when executing: $this->validate(); |
| allow: allows to create/edit the row |
| delete: allows to delete the row |
| |
| Note: The first index indicates the table name |
| |
+---------------------------------------------------------------------------+
| |
| This file allows you to setup all the information |
| to be able to manage your app without problems |
| |
+---------------------------------------------------------------------------+
*/

if(!isset($row)){
# the row will be the user logged in if no row is set
$row = Auth::user();
}

$data = [


'users' => [

'hide_display' => ['password'],
'delete' => false,
'create' => [
'allowed' => true,
'hidden' => ['id', 'su', 'active', 'banned', 'register_ip', 'activation_key', 'remember_token', 'created_at', 'updated_at'],
'default_random' => ['password'],
'confirmed' => ['password'],
'encrypted' => [],
'hashed' => ['password'],
'masked' => ['password'],
'code' => [],
'wysiwyg' => [],
'validator' => [
'name' => 'required|max:255',
'email' => 'required|email|unique:users',
'password' => 'confirmed|min:6',
'country_code' => 'required',
],
],
'edit' => [
'hidden' => ['id', 'su', 'email', 'register_ip', 'activation_key', 'remember_token', 'created_at', 'updated_at'],
'su_hidden' => ['name', 'active', 'banned', 'password', 'country_code'],
'empty' => ['password'],
'default_random' => [],
'confirmed' => ['password'],
'encrypted' => [],
'hashed' => ['password'],
'masked' => ['password'],
'code' => [],
'wysiwyg' => [],
'validator' => [
'name' => 'sometimes|required|max:255',
'password' => 'sometimes|confirmed|min:6',
'country_code' => 'sometimes|required',
],
],
],

'settings' => [
'create' => [
'allow' => false,
],
]
];
Loading

0 comments on commit 50df646

Please sign in to comment.