-
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.
Merge branch 'master' into feature/routine
- Loading branch information
Showing
21 changed files
with
882 additions
and
6 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,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(); | ||
} | ||
} |
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,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')); | ||
} | ||
|
||
} |
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,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); | ||
} | ||
} |
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
Oops, something went wrong.