Skip to content

Commit

Permalink
Merge pull request #23 from douglas-88/dev
Browse files Browse the repository at this point in the history
Painel Admin
  • Loading branch information
douglas-88 authored Mar 18, 2020
2 parents 60a518c + d9184fb commit 70ef1f5
Show file tree
Hide file tree
Showing 20 changed files with 615 additions and 259 deletions.
2 changes: 1 addition & 1 deletion app/Controller/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AdminController extends Controller
*/
public function index() {

$this->view("admin/master",["template_admin" => $this->templateAdmin]);
$this->view("admin/painel",["template_admin" => $this->templateAdmin]);

}

Expand Down
114 changes: 114 additions & 0 deletions app/Controller/Admin/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace App\Controller\Admin;

use Core\Controller;
use Slim\Http\Request;
use Slim\Http\Response;
use App\Model\Category;
use Core\Validate;
use Core\Redirect;

class CategoryController extends Controller {
/**
* Página Inicial
*/
public function index() {

$category = new Category;
$categories = $category->select()->busca("name")->paginate(3)->get();
$this->view("admin/categories/index", [
"template_admin" => $this->templateAdmin,
"categories" => $categories,
"links" => $category->links()
]);

}

/**
* Exibe o formulário de criação
*/
public function create() {
$this->view("admin/categories/create", ["template_admin" => $this->templateAdmin]);
}

/**
* Processa Formulário de criação
*/
public function store(Request $request, Response $response) {
//$data = filter_input_array(($_SERVER['REQUEST_METHOD'] == "POST") ? INPUT_POST : INPUT_GET, FILTER_SANITIZE_STRING);
$validate = new Validate();
$data = $validate->validate([
"name" => "required"
]);

if($validate->hasErros()){
foreach($data as $field => $value){
flash("post_".$field,$data[$field]);
}
back();
}

$category = new Category;
$category->create($data);
if($category->lastCreated > 0){
flash("name",success("Cadastrado com sucesso"));
Redirect::redirect("/painel/admin/category");
}
}

/**
* Exibe dado do Banco de dados
*/
public function show($id) {
echo 'show';
}

/**
* Exibe o formulário de edição
*/
public function edit(Request $request, Response $response, $args) {
$category = new Category;
$category = $category->select()->where2(["id","=",$args["id"]])->first();
return $response->write($this->view("admin/categories/edit", [
"template_admin" => $this->templateAdmin,
"category" => $category
]));

}

/**
* Processa o formulário de edição
*/
public function update(Request $request, Response $response, $args) {

$validate = new Validate();
$data = $validate->validate([
"name" => "required"
]);



if($validate->hasErros()){
foreach($data as $field => $value){
flash("post_".$field,$data[$field]);
}
back();
}

$category = new Category;
$category->update2(["name" => $data["name"]])->where2(["id","=",$args["id"]])->exec();
return Redirect::redirect("/painel/admin/category");
}

/**
* Remove dados do Banco
*/
public function destroy(Request $request, Response $response, $args) {
$category = new Category();
$category->delete2()->where2(["id","=",$args["id"]])->exec();

return Redirect::redirect("/painel/admin/category");
}

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

namespace App\Controller\Admin;

use Core\Controller;
use Slim\Http\Request;
use Slim\Http\Response;

class PostController extends Controller {
/**
* Página Inicial
*/
public function index() {

$this->view("admin/post/index", ["template_admin" => $this->templateAdmin]);

}

/**
* Exibe o formulário de criação
*/
public function create() {
$this->view("admin/post/create", ["template_admin" => $this->templateAdmin]);
}

/**
* Processa Formulário de criação
*/
public function store(Request $request, Response $response) {
echo 'store';
}

/**
* Exibe dado do Banco de dados
*/
public function show($id) {
echo 'show';
}

/**
* Exibe o formulário de edição
*/
public function edit($id) {
echo 'edit';
}

/**
* Processa o formulário de edição
*/
public function update(Request $request, Response $response, $args) {
echo 'update';
}

/**
* Remove dados do Banco
*/
public function destroy($id) {
echo 'destroy';
}

}
13 changes: 12 additions & 1 deletion app/Functions/twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Twig\TwigFunction;
use Core\Flash;
use Core\Validate;
use Carbon\Carbon;


$erros = new TwigFunction("erros",function($index){
Expand All @@ -25,4 +26,14 @@

});

return [$erros,$sent,$message,$admin];
$timeAgo = new TwigFunction("timeAgo",function($date) {

Carbon::setLocale("pt-br");

$created = Carbon::parse($date);

return $created->diffForHumans();

});

return [$erros,$sent,$message,$admin,$timeAgo];
10 changes: 10 additions & 0 deletions app/Model/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Model;

use Core\Model;

class Category extends Model {
protected $table = "categories";

}
1 change: 1 addition & 0 deletions app/traits/Validations.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ trait Validations
protected function required($field){

if(empty($_POST[$field]) OR !isset($_POST[$field])){
$_POST[$field] = "";
$this->erros[$field][] = flash($field, error("Favor preencha esse campo"));
}
}
Expand Down
46 changes: 23 additions & 23 deletions app/traits/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

namespace App\traits;
use Core\Load;
use Twig\Loader\FilesystemLoader;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

trait View{
trait View {

protected $twig;
protected $templateAdmin = "../assets/templates";
protected $twig;
protected $templateAdmin = "/assets/templates";

protected function twig(){
protected function twig() {

$loader = new FilesystemLoader(__DIR__ . "/../../views");
$this->twig = new Environment($loader, ['debug' => true]);
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
}
$loader = new FilesystemLoader(__DIR__ . "/../../views");
$this->twig = new Environment($loader, ['debug' => true]);
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
}

protected function functions(){
$functions = Load::file("/app/Functions/twig.php");
protected function functions() {
$functions = Load::file("/app/Functions/twig.php");

foreach ($functions as $function){
$this->twig->addFunction($function);
}
}
foreach ($functions as $function) {
$this->twig->addFunction($function);
}
}

protected function load(){
$this->twig();
$this->functions();
}
protected function load() {
$this->twig();
$this->functions();
}

protected function view(string $view, array $data = []){
$this->load();
echo $this->twig->render(str_replace(".","/",$view).".html",$data);
}
protected function view(string $view, array $data = []) {
$this->load();
echo $this->twig->render(str_replace(".", "/", $view) . ".html", $data);
}
}
63 changes: 35 additions & 28 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,69 @@
session_start();
require __DIR__ . "/vendor/autoload.php";

use Slim\App;
use Dotenv\Dotenv;
use Core\Whoops;
use Core\Middleware;

use Core\Whoops;
use Dotenv\Dotenv;
use Slim\App;

$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

$config['displayErrorDetails'] = true;
$config['addContentLengthHeader'] = false;
$config['db'] = [
'driver' => 'mysql',
'host' => $_ENV["DB_HOST"],
'database' => $_ENV["DB_DATABASE"],
'username' => $_ENV["DB_USERNAME"],
'password' => $_ENV["DB_PASSWORD"],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
'driver' => 'mysql',
'host' => $_ENV["DB_HOST"],
'database' => $_ENV["DB_DATABASE"],
'username' => $_ENV["DB_USERNAME"],
'password' => $_ENV["DB_PASSWORD"],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
];

$app = new App(['settings' => $config]);
$container = $app->getContainer();


$container['AdminController'] = function ($container) {
$service = new \App\Controller\Admin\AdminController($container);
return $service;
$service = new \App\Controller\Admin\AdminController($container);
return $service;
};

$container['ProfessorController'] = function ($container) {
$service = new \App\Controller\Admin\ProfessorController($container);
return $service;
$service = new \App\Controller\Admin\ProfessorController($container);
return $service;
};

$container['LoginController'] = function ($container) {
$service = new \App\Controller\Admin\LoginController($container);
return $service;
$service = new \App\Controller\Admin\LoginController($container);
return $service;
};

$container['PasswordRecoveryController'] = function ($container) {
$service = new \App\Controller\Admin\PasswordRecoveryController($container);
return $service;
$service = new \App\Controller\Admin\PasswordRecoveryController($container);
return $service;
};

$container['db'] = function ($container) {
$container['PostController'] = function ($container) {
$service = new \App\Controller\Admin\PostController($container);
return $service;
};

$config = $container->get('settings');
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($config["db"]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
$container['CategoryController'] = function ($container) {
$service = new \App\Controller\Admin\CategoryController($container);
return $service;
};

$container['db'] = function ($container) {

$config = $container->get('settings');
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($config["db"]);
$capsule->setAsGlobal();
$capsule->bootEloquent();

return $capsule;
return $capsule;
};

$whoops = new Whoops();
Expand Down
Loading

0 comments on commit 70ef1f5

Please sign in to comment.