-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Borja José
committed
Sep 9, 2015
1 parent
c1557bb
commit bcf5131
Showing
7 changed files
with
493 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\User; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Helpers\AngularHelper; | ||
use Hash; | ||
use Validator; | ||
|
||
class UserController extends Controller { | ||
/* | ||
* This function render's the create form for the employee | ||
*/ | ||
|
||
public function getCreate() { | ||
return view('user.create'); | ||
} | ||
|
||
/* | ||
* This function get's the post request and creates the new user into db | ||
*/ | ||
|
||
public function postCreate(Request $request) { | ||
//Get the data | ||
$data = $request->all(); | ||
//Filter the data to check if any is wrong | ||
$validator = Validator::make($data, [ | ||
'name' => 'required|max:254', | ||
'password' => 'required|max:254', | ||
'address' => 'required|max:254', | ||
'nif' => 'required|max:254', | ||
'nomina' => 'required|max:254', | ||
]); | ||
//Check if validator fails | ||
if (!$validator->fails()) { | ||
$user = new User; | ||
$user->name = $data['name']; | ||
$user->email = $data['email']; | ||
$user->password = Hash::make($data['password']); | ||
$user->fk_company = 1; | ||
$user->fk_role = $data['fk_role']; | ||
$user->address = $data['address']; | ||
$user->cp = $data['cp']; | ||
$user->poblation = $data['poblation']; | ||
$user->nif = $data['nif']; | ||
$user->nomina = $data['nomina']; | ||
|
||
//Save the client | ||
if ($user->save()) { | ||
//Ok, go to view | ||
return redirect('user/view/' . $user->id); | ||
} else { | ||
//ko, return to form | ||
return redirect('user/create') | ||
->withErrors($validator) | ||
->withInput(); | ||
} | ||
} else { | ||
//Innitial validation KO, redirect to form | ||
return redirect('user/create') | ||
->withErrors($validator) | ||
->withInput(); | ||
} | ||
} | ||
|
||
/* | ||
* This function get's the post request and updates the user | ||
*/ | ||
|
||
public function postUpdate(Request $request) { | ||
//Get the data | ||
$data = $request->all(); | ||
//Filter the data to check if any is wrong | ||
$validator = Validator::make($data, [ | ||
'name' => 'required|max:254', | ||
'address' => 'required|max:254', | ||
'nif' => 'required|max:254', | ||
'nomina' => 'required|max:254', | ||
]); | ||
//Check if validator fails | ||
if (!$validator->fails()) { | ||
$user = User::find($data['id']); | ||
$user->name = $data['name']; | ||
$user->email = $data['email']; | ||
//Only change password if put on the field | ||
if (strlen($data['password']) > 0) | ||
$user->password = Hash::make($data['password']); | ||
$user->fk_company = 1; | ||
$user->fk_role = $data['fk_role']; | ||
$user->address = $data['address']; | ||
$user->cp = $data['cp']; | ||
$user->poblation = $data['poblation']; | ||
$user->nif = $data['nif']; | ||
$user->nomina = $data['nomina']; | ||
|
||
//Save the client | ||
if ($user->save()) { | ||
//Ok, go to view | ||
return redirect('user/view/' . $user->id); | ||
} else { | ||
//ko, return to form | ||
return redirect('user/create') | ||
->withErrors($validator) | ||
->withInput(); | ||
} | ||
} else { | ||
//Innitial validation KO, redirect to form | ||
return redirect('user/create') | ||
->withErrors($validator) | ||
->withInput(); | ||
} | ||
} | ||
|
||
/* | ||
* This function render's the view form for the user | ||
*/ | ||
|
||
public function getView($id) { | ||
//Load user | ||
$user = User::find($id); | ||
return view('user.view', ['user' => $user]); | ||
} | ||
|
||
/* | ||
* This function render's the list | ||
*/ | ||
|
||
public function getList() { | ||
$users = User::all(); | ||
return view('user.list', ['users' => $users]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class UserExtraFields extends Migration { | ||
|
||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() { | ||
Schema::table('users', function ($table) { | ||
//Add some extrafields to turn users into employee | ||
$table->string('address')->nullable(); | ||
$table->integer('cp')->nullable(); | ||
$table->string('poblation')->nullable(); | ||
$table->string('nif')->nullable(); | ||
$table->decimal('nomina',15,8)->nullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() { | ||
// | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
@extends('template') | ||
<!-- Content Header (Page header) --> | ||
@section('content') | ||
<section class="content-header"> | ||
<h1> | ||
Empleados | ||
<small>Crear</small> | ||
</h1> | ||
<ol class="breadcrumb"> | ||
<li><a href="#"><i class="fa fa-dashboard"></i> ></a></li> | ||
<li class="active">Crear</li> | ||
</ol> | ||
</section> | ||
|
||
<!-- Main content --> | ||
<section class="content"> | ||
|
||
<div class="row"> | ||
|
||
<div class="col-md-12"> | ||
<div class="box box-primary"> | ||
<div class="box-header with-border"> | ||
<h3 class="box-title">Formulario de creación</h3> | ||
</div><!-- /.box-header --> | ||
<!-- form start --> | ||
<form role="form" method="post" action="{{URL::to('/user/create')}}"> | ||
{!! csrf_field() !!} | ||
<div class="box-body"> | ||
|
||
<!-- Error zone --> | ||
@if (count($errors) > 0) | ||
<div class="alert alert-danger"> | ||
<ul> | ||
@foreach ($errors->all() as $error) | ||
<li>{{ $error }}</li> | ||
@endforeach | ||
</ul> | ||
</div> | ||
@endif | ||
<!-- Error zone end --> | ||
|
||
<div class="row"> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Nombre y apellidos</label> | ||
<input class="form-control" placeholder="" type="text" name="name"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Email</label> | ||
<input class="form-control" placeholder="" type="text" name="email"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Contraseña (plano)</label> | ||
<input class="form-control" placeholder="" type="text" name="password"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Rol que desempeñará</label> | ||
<select name="fk_role" class="form-control"> | ||
<option value="1">Administrador</option> | ||
<option value="2">Administración</option> | ||
<option value="3">Recepción</option> | ||
<option value="4">Profesor</option> | ||
</select> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Dirección postal</label> | ||
<input class="form-control" placeholder="" type="text" name="address"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Código postal</label> | ||
<input class="form-control" placeholder="" type="text" name="cp"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Población</label> | ||
<input class="form-control" placeholder="" type="text" name="poblation"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>DNI</label> | ||
<input class="form-control" placeholder="" type="text" name="nif"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<div class="form-group"> | ||
<label>Importe bruto de nómina</label> | ||
<input class="form-control" placeholder="" type="text" name="nomina"> | ||
</div> | ||
</div> | ||
|
||
<div class="col-md-12 center"> | ||
<hr/> | ||
<button type="submit" class="btn btn-xs btn-success center"><i class="fa fa-plus"></i> Crear</button> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
@stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
@extends('template') | ||
<!-- Content Header (Page header) --> | ||
@section('content') | ||
<section class="content-header"> | ||
<h1> | ||
Empleados | ||
<small>Listado</small> | ||
</h1> | ||
<ol class="breadcrumb"> | ||
<li><a href="#"><i class="fa fa-dashboard"></i> ></a></li> | ||
<li class="active">Listado</li> | ||
</ol> | ||
</section> | ||
|
||
<!-- Main content --> | ||
<section class="content"> | ||
|
||
<div class="row"> | ||
|
||
<div class="col-md-12"> | ||
<div class="box box-primary"> | ||
<div class="box-header with-border"> | ||
<h3 class="box-title">Usuarios / Empleados</h3> | ||
</div><!-- /.box-header --> | ||
<!-- form start --> | ||
<div class="box-body"> | ||
<table class="table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th>Nombre</th> | ||
<th>Email</th> | ||
<th style="width:30px;">Rol</th> | ||
<th style="width:30px;"> </th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach($users as $user) | ||
<tr> | ||
<td>{{$user->name}}</td> | ||
<td>{{$user->email}}</td> | ||
<td> | ||
@if($user->fk_role == 0) | ||
<small class="label pull-right">Sin rol</small> | ||
@endif | ||
@if($user->fk_role == 1) | ||
<small class="label pull-right bg-green">Administrador</small> | ||
@endif | ||
@if($user->fk_role == 2) | ||
<small class="label pull-right bg-blue">Administración</small> | ||
@endif | ||
@if($user->fk_role == 3) | ||
<small class="label pull-right bg-yellow">Recepción</small> | ||
@endif | ||
@if($user->fk_role == 4) | ||
<small class="label pull-right bg-red">Profesor</small> | ||
@endif | ||
</td> | ||
<td> | ||
<a href="{{URL::to('/user/view/'.$user->id)}}" class="btn btn-success btn-xs"><i class="fa fa-eye"></i>/<i class="fa fa-pencil"></i></a> | ||
</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
@stop |
Oops, something went wrong.