Skip to content

Commit

Permalink
🎨 Adição de data/hora e foto
Browse files Browse the repository at this point in the history
Criado informação de criação e alteração de um registro.
Adição de foto ao cadastro do cliente.
Correção de bugs
  • Loading branch information
douglascarlos-dev committed Jul 2, 2023
1 parent bfc3e80 commit c0d9eb5
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 64 deletions.
1 change: 1 addition & 0 deletions controller/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function update( $cpf ) {
$customer->setBirthDate($_REQUEST['data_de_nascimento']);
$customer->setSex($_REQUEST['sexo']);
$customer->setMaritalStatus($_REQUEST['estado_civil']);
$customer->setUpdated($_REQUEST['estado_civil']);
$customer->post_customer_update();
CustomerController::edit($customer->getCPF());
}
Expand Down
63 changes: 63 additions & 0 deletions controller/PhotoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

require_once 'model/photoModel.php';
require_once 'controller/CustomerController.php';

class PhotoController {

public function new( $cpf ){
require_once 'view/photo_new.php';
}

public function save( $cpf ){
$photo = new Photo();
$photo->setCPF($cpf);

if(isset($_FILES['photo'])){
$errors= array();
$file_name = $_FILES['photo']['name'];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
$file_name_2 = md5($cpf).".".$file_ext;
$file_size =$_FILES['photo']['size'];
$file_tmp =$_FILES['photo']['tmp_name'];
$file_type=$_FILES['photo']['type'];
@$file_ext=strtolower(end(explode('.',$_FILES['photo']['name'])));

$extensions= array("jpeg","jpg","png");

if(in_array($file_ext,$extensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}

if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}

if(empty($errors)==true){
move_uploaded_file($file_tmp,"images/".$file_name_2);

$file_name_3 = md5($cpf).".jpg";
$image = new Imagick("images/".$file_name_3);
$image->readImage("images/".$file_name_2);
$image->resizeImage(133,133,Imagick::FILTER_LANCZOS,1);
$image->setImageFormat('jpeg');
$image->setImageCompressionQuality(95);
$image->stripImage();

$image->writeImage("images/".$file_name_3);
if($file_type != "image/jpeg"){
unlink("images/".$file_name_2);
}

$photo->setPhoto($file_name_3);
$photo->post_photo_save();
CustomerController::edit($photo->getCPF());

}else{
CustomerController::edit($cpf);
}
}
}

}
?>
2 changes: 1 addition & 1 deletion controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function login() {

public function createUserSession($user) {
$_SESSION['username'] = $user["username"];
require_once 'view/user_view.php';
require_once 'view/home_view.php';
}

public function logout() {
Expand Down
Binary file added images/e2ddfcc9c5c901ee37f71319310f1894.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/f981ff940a68e4f69aadc0aade9f6b2a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 41 additions & 13 deletions model/customerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Customer extends Connection {
private $birthdate;
private $sex;
private $maritalstatus;
private $created;
private $updated;
private $photo;

public function setId($id){
$this->id=$id;
Expand Down Expand Up @@ -38,6 +41,24 @@ public function setMaritalStatus($maritalstatus){
$this->maritalstatus=$maritalstatus;
return $this;
}
public function setCreated($created){
$created = strftime("%d/%m/%Y %H:%M", strtotime($created));
$this->created=$created;
return $this;
}
public function setUpdated($updated){
if(is_null($updated)){
$updated = "";
} else {
$updated = strftime("%d/%m/%Y %H:%M", strtotime($updated));
}
$this->updated=$updated;
return $this;
}
public function setPhoto($photo){
$this->photo=$photo;
return $this;
}

public function getId()
{
Expand Down Expand Up @@ -67,6 +88,18 @@ public function getMaritalStatus()
{
return $this->maritalstatus;
}
public function getCreated()
{
return $this->created;
}
public function getUpdated()
{
return $this->updated;
}
public function getPhoto()
{
return $this->photo;
}

function database_select_all_var($valor1, $valor2, $valor3){
$pdo = $this->o_db;
Expand All @@ -89,18 +122,6 @@ function get_all_customer(){
return $consulta;
}

function get_cliente_telefone($id){
$id = (string) $id;
$consulta = $this->database_select_all_var('view_telefone_cliente', 'cpf', $id);
return $consulta;
}

function get_cliente_address($id){
$id = (string) $id;
$consulta = $this->database_select_all_var('view_address', 'cpf', $id);
return $consulta;
}

function customer_insert(){
$sql_query = "SELECT * FROM customer_insert_function
(
Expand All @@ -124,14 +145,18 @@ function post_customer_new(){
}

function custumer_update(){
date_default_timezone_set('America/Sao_Paulo');
$date = new DateTimeImmutable();
$date = $date->format('Y-m-d H:i:s O');
$sql_query = "SELECT * FROM customer_update_function
(
'" . $this->getName() . "',
'" . $this->getEmail() . "',
'" . $this->getCPF() . "',
'" . $this->getBirthDate() . "',
'" . $this->getSex() . "',
'" . $this->getMaritalStatus() . "'
'" . $this->getMaritalStatus() . "',
'" . $date . "'
)";
$pdo = $this->o_db;
$stmt = $pdo->prepare($sql_query);
Expand Down Expand Up @@ -174,6 +199,9 @@ function customer_list(){
$cliente->setBirthDate($row[5]);
$cliente->setSex($row[6]);
$cliente->setMaritalStatus($row[7]);
$cliente->setUpdated($row[8]);
$cliente->setCreated($row[9]);
$cliente->setPhoto($row[10]);
return $cliente;
}

Expand Down
51 changes: 51 additions & 0 deletions model/photoModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
include_once 'connection.php';

class Photo extends Connection{
private $id;
private $cpf;
private $photo;

public function setId($id){
$this->id=$id;
return $this;
}

public function setCPF($cpf){
$this->cpf=$cpf;
return $this;
}

public function setPhoto($photo){
$this->photo=$photo;
return $this;
}

public function getId(){
return $this->id;
}

public function getCPF(){
return $this->cpf;
}

public function getPhoto(){
return $this->photo;
}

function photo_save(){
$sql_query = "UPDATE public.clientes SET photo='" . $this->getPhoto() . "' WHERE cpf='" . $this->getCPF() . "'";
$pdo = $this->o_db;
$stmt = $pdo->prepare($sql_query);
$stmt->execute();
$row = $stmt->fetch();
return $row;
}

function post_photo_save(){
$result = $this->photo_save();
return $result;
}

}
?>
42 changes: 34 additions & 8 deletions pgmodeler/database_model.dbm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ CAUTION: Do not modify this file unless you know what you are doing.
<enumeration label="Trabalho"/>
</usertype>

<table name="clientes" layers="0" collapse-mode="2" max-obj-count="9" z-value="0">
<table name="clientes" layers="0" collapse-mode="2" max-obj-count="13" z-value="0">
<schema name="public"/>
<role name="postgres"/>
<position x="20" y="80"/>
Expand Down Expand Up @@ -88,6 +88,15 @@ CAUTION: Do not modify this file unless you know what you are doing.
<column name="estado_civil_cliente" not-null="true">
<type name="public.estado_civil" length="0"/>
</column>
<column name="created" default-value="NOW()">
<type name="timestamptz" length="0"/>
</column>
<column name="updated">
<type name="timestamptz" length="0"/>
</column>
<column name="photo">
<type name="character varying" length="100"/>
</column>
<constraint name="cliente_pk" type="pk-constr" table="public.clientes">
<columns names="id" ref-type="src-columns"/>
</constraint>
Expand Down Expand Up @@ -131,7 +140,7 @@ CAUTION: Do not modify this file unless you know what you are doing.
<view name="view_phone_customer" layers="0" collapse-mode="2" max-obj-count="1" z-value="0">
<schema name="public"/>
<role name="postgres"/>
<position x="600" y="260"/>
<position x="620" y="280"/>
<reference>
<expression><![CDATA[ SELECT clientes.id,
clientes.cpf,
Expand Down Expand Up @@ -161,7 +170,7 @@ CAUTION: Do not modify this file unless you know what you are doing.
dst-table="public.clientes"
src-required="false" dst-required="false">
<label ref-type="name-label">
<position x="-14.3074" y="43.5182"/>
<position x="-2.30738" y="1.08768"/>
</label>
</relationship>

Expand Down Expand Up @@ -254,7 +263,7 @@ END;]]></definition>
<table name="users" layers="0" collapse-mode="2" max-obj-count="3" z-value="0">
<schema name="public"/>
<role name="postgres"/>
<position x="540" y="640"/>
<position x="560" y="640"/>
<column name="id" not-null="true" sequence="public.users_id_seq">
<type name="integer" length="0"/>
</column>
Expand Down Expand Up @@ -286,10 +295,10 @@ END;]]></definition>
<enumeration label="Caixa postal"/>
</usertype>

<table name="address" layers="0" collapse-mode="2" max-obj-count="13" z-value="0">
<table name="address" layers="0" collapse-mode="2" max-obj-count="15" z-value="0">
<schema name="public"/>
<role name="postgres"/>
<position x="20" y="380"/>
<position x="20" y="400"/>
<column name="id" not-null="true" sequence="public.endereco_id_seq">
<type name="integer" length="0"/>
</column>
Expand Down Expand Up @@ -320,15 +329,29 @@ END;]]></definition>
<column name="complemento">
<type name="character varying" length="60"/>
</column>
<column name="created" default-value="NOW()">
<type name="timestamptz" length="0"/>
</column>
<column name="updated">
<type name="timestamptz" length="0"/>
</column>
<constraint name="endereco_pk" type="pk-constr" table="public.address">
<columns names="id" ref-type="src-columns"/>
</constraint>

<customidxs object-type="column">
<object name="id_clientes" index="1"/>
</customidxs>

<customidxs object-type="constraint">
<object name="clientes_fk" index="1"/>
</customidxs>
</table>

<view name="view_address" layers="0" collapse-mode="2" max-obj-count="1" z-value="0">
<schema name="public"/>
<role name="postgres"/>
<position x="520" y="380"/>
<position x="540" y="400"/>
<reference>
<expression><![CDATA[ SELECT clientes.id,
clientes.cpf,
Expand Down Expand Up @@ -581,10 +604,13 @@ END;]]></definition>
<parameter name="estado_civil_cliente_">
<type name="public.estado_civil" length="0"/>
</parameter>
<parameter name="updated_">
<type name="timestamptz" length="0"/>
</parameter>
<definition><![CDATA[DECLARE id_retorno integer;
BEGIN
UPDATE clientes SET nome = nome_, email = email_, data_de_nascimento = data_de_nascimento_, sexo_cliente = sexo_cliente_, estado_civil_cliente = estado_civil_cliente_ WHERE cpf = cpf_;
UPDATE clientes SET nome = nome_, email = email_, data_de_nascimento = data_de_nascimento_, sexo_cliente = sexo_cliente_, estado_civil_cliente = estado_civil_cliente_, updated = updated_ WHERE cpf = cpf_;
SELECT id INTO id_retorno FROM clientes WHERE clientes.cpf=cpf_;
Expand Down
Loading

0 comments on commit c0d9eb5

Please sign in to comment.