<?php 

require_once "conexion.php";

class ModeloMarcas{

    static public function MdlMostrarMarcas($tabla, $item, $valor){

        if($item != null){

            $stmt = Conexion:: conectar()->prepare("SELECT * FROM $tabla WHERE $item = :$item");

            $stmt -> bindParam(":".$item, $valor, PDO::PARAM_STR);
            
            $stmt -> execute();

            return $stmt -> fetch();

        }else {

            $stmt = Conexion:: conectar()->prepare("SELECT * FROM $tabla");
            
            $stmt -> execute();

            return $stmt -> fetchAll();
        }

        $stmt -> close();

        $stmt = null;
    }


    /** CREAR MARCA */

    static public function mdlIngresarMarca($tabla, $datos){

        $stmt = Conexion::conectar()->prepare("INSERT INTO $tabla(descripcion, proveedor) VALUES (:descripcion, :proveedor)");

        $stmt -> bindParam(":descripcion", $datos["descripcion"], PDO::PARAM_STR);
        $stmt -> bindParam(":proveedor", $datos["proveedor"], PDO::PARAM_INT);

        if($stmt -> execute()){
            return "ok";
        }else{
            return "error";
        }
        
        $stmt -> close();

        $stmt = null;
    }

    /** EDITAR MARCA */

    static public function mdlEditarMarca($tabla, $datos){

        $stmt = Conexion::conectar()->prepare("UPDATE $tabla SET descripcion = :descripcion, proveedor = :proveedor WHERE id = :id");

        $stmt -> bindParam(":descripcion", $datos["descripcion"], PDO::PARAM_STR);
        $stmt -> bindParam(":proveedor", $datos["proveedor"], PDO::PARAM_INT);
        $stmt -> bindParam(":id", $datos["id"], PDO::PARAM_STR);

        if($stmt -> execute()){
            return "ok";
        }else{
            return "error";
        }
        
        $stmt -> close();

        $stmt = null;
    }

        /*=============================================
	BORRAR MARCA
	=============================================*/

	static public function mdlBorrarMarca($tabla, $datos){

		$stmt = Conexion::conectar()->prepare("DELETE FROM $tabla WHERE id = :id");

		$stmt -> bindParam(":id", $datos, PDO::PARAM_INT);

		if($stmt -> execute()){

			return "ok";
		
		}else{

			return "error";	

		}

		$stmt -> close();

		$stmt = null;


	}
}