Skip to content

Commit

Permalink
Merge branch 'master' into feature/routine
Browse files Browse the repository at this point in the history
  • Loading branch information
ljpalaciom committed Mar 10, 2020
2 parents bbb987b + 0b188f4 commit 995ec7e
Show file tree
Hide file tree
Showing 21 changed files with 882 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/Charts/RecordChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Charts;

use ConsoleTVs\Charts\Classes\Chartjs\Chart;

class RecordChart extends Chart
{
/**
* Initializes the chart.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
}
72 changes: 72 additions & 0 deletions app/Http/Controllers/RecordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Http\Controllers;
use App\Record;
use App\Charts\RecordChart;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class RecordController extends Controller
{
public function create()
{
return view('record.create');
}

public function list(){

$user = Auth::user();

$data = []; //to be sent to the view
$data["title"] = __('record.record');

if($user->getRole() == 1){
$record = Record::where('user_id', $user->getId())->get();
$data["records"] = $record;
$chart = new RecordChart;
$chart->labels($record->pluck('created_at')->pluck('month')->all());
$chart->dataset(__('record.chartTitle'), 'line', $record->pluck('weight')->all())->color("rgb(0, 102, 255)");

return view('record.user.list', compact('chart'))->with("data",$data);
}else{
$record = Record::all();
$data["records"] = $record;
return view('record.list')->with("data",$data);
}
}

public function sort($order){
$data = []; //to be sent to the view
$data["title"] = __('record.record');
$data["records"] = Record::orderBy($order)->get();

return redirect("/record/list")->with("data",$data);
}



public function show($id)
{
$data = []; //to be sent to the view
$record = Record::findOrFail($id);

$data["title"] = __('record.record');
$data["record"] = $record;
return view('record.show')->with("data",$data);
}

public function delete($id)
{
Record::destroy($id);
return redirect()->route('record.list');
}


public function save(Request $request){

Record::validate($request);
Record::create($request->only(["name","weight","height","imc"]));
return back()->with('success',__('record.recordCreated'));
}

}
89 changes: 89 additions & 0 deletions app/Record.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Record extends Model
{
//attributes id, name, weight, height,imc, created_at, updated_at
protected $fillable = ['name','weight', 'height','imc'];


//TODO: Add validations


public static function validate(Request $request){
$request->validate([
"name" => "required|regex:/^[\pL\s\-]+$/u",
"weight" => "required|numeric|min:0",
"height" => "required|numeric|min:0",
"imc" => "required|numeric|min:0"
]);

}
public function getId()
{
return $this->attributes['id'];
}

public function setId($id)
{
$this->attributes['id'] = $id;
}

public function getName()
{
return $this->attributes['name'];
}

public function setName($name)
{
$this->attributes['name'] = $name;
}

public function getWeight()
{
return $this->attributes['weight'];
}

public function setWeight($weight)
{
$this->attributes['weight'] = $weight;
}

public function getHeight()
{
return $this->attributes['height'];
}

public function setHeight($height)
{
$this->attributes['height'] = $height;
}

public function getIMC()
{
return $this->attributes['imc'];
}

public function setIMC($imc)
{
$this->attributes['imc'] = $imc;
}

public function getCreatedAt()
{
return $this->attributes['created_at'];
}

public function setCreatedAt($created)
{
$this->attributes['created_at'] = $created;
}

public function user(){
return $this->belongsTo(User::class);
}
}
92 changes: 92 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,96 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];


public static function validate(Request $request){
$request->validate([
'name' => 'required',
'last_name' => 'required',
'age' => 'required|integer|min:0|max:120',
'email' => 'required|email|unique:users',
'password' => 'required',
'role' => 'required'
]);
}

public function getId()
{
return $this->attributes['id'];
}

public function setId($id)
{
$this->attributes['id'] = $id;
}

public function getName()
{
return $this->attributes['name'];
}

public function setName($name)
{
$this->attributes['name'] = $name;
}

public function getLastName()
{
return $this->attributes['last_name'];
}

public function setLastName($lastName)
{
$this->attributes['last_name'] = $lastName;
}

public function getAge()
{
return $this->attributes['age'];
}

public function setAge($age)
{
$this->attributes['age'] = $age;
}

public function getEmail()
{
return $this->attributes['email'];
}

public function setEmail($email)
{
$this->attributes['email'] = $email;
}

public function getPassword()
{
return $this->attributes['password'];
}

public function setPassword($password)
{
$this->attributes['password'] = $password;
}

public function getRole()
{
return $this->attributes['role'];
}

public function setRole($role)
{
$this->attributes['role'] = $role;
}

public function records(){
return $this->hasMany(Record::class);
}

/**
public function appointment(){
return $this->hasMany(Appointment::class);
}
*/
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"license": "MIT",
"require": {
"php": "^7.2",
"consoletvs/charts": "6.*",
"fideloper/proxy": "^4.0",
"laravel/framework": "^6.2",
"laravel/tinker": "^2.0"
"laravel/tinker": "^2.0",
"laraveldaily/laravel-charts": "^0.1.14"
},
"require-dev": {
"facade/ignition": "^1.4",
Expand Down
Loading

0 comments on commit 995ec7e

Please sign in to comment.