%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home1/dimen328/libertysa.com.br/admin/modules/redesocial/
Upload File :
Create Path :
Current File : //home1/dimen328/libertysa.com.br/admin/modules/redesocial/DAO.php

<?php
/**
 * Created by PhpStorm.
 * User: Tassyo
 * Date: 05/10/2015
 * Time: 11:16
 */
session_start();
include_once("../../configuration/config.inc.php");

class DAO
{

    private $pdo;
	private $idioma;
	
	public function __construct(){
		
		switch ($_SESSION['idioma']){
			case 'en':
				$this->idioma = "eng_";
			break;
			
			case 'pt':
				$this->idioma = "";
			break;

			default:
			break;
		}
		
		$this->pdo = $GLOBALS['pdo'];
	}

    public function inserir($descricao, $link, $tipo, $status)
    {

        $retorno = array();

        $sql = "INSERT INTO ".$this->idioma."cms_redesocial (descricao, link,tipo, status)values(:descricao, :link, :tipo, :status)";

        $vars = array(":descricao" => $descricao, ":link" => $link,":tipo" => $tipo, ":status" => $status);

        $stmt = $this->pdo->prepare($sql);

        foreach ($vars as $index => $value) {
            $stmt->bindValue($index, $value);
        }

        if ($stmt->execute()) {
            return array("msg" => '1');
        } else {
            return array("msg" => '0');
        }
    }

    public function listar($filtro)
    {

        $retorno = array();

        $sql = "SELECT * FROM ".$this->idioma."cms_redesocial WHERE (descricao LIKE :descricao)AND status <> :status;";

        $vars = array(":descricao" => "%{$filtro}%", ":status" => 3);

        $stmt = $this->pdo->prepare($sql);

        foreach ($vars as $index => $value) {
            $stmt->bindValue($index, $value);
        }

        if ($stmt->execute()) {
            $count = $stmt->rowCount();
            $rows = $stmt->fetchAll(PDO::FETCH_OBJ);
            $rows['msg'] = '1';
            $rows['length'] = $count;

            $i = 0;
            while ($i < $count) {
                foreach ($rows[$i] as $index => $value) {
                    $rows[$i]->$index = utf8_encode($value);
                }
                $i++;
            }

            return $rows;
        } else {
            return array("msg" => '0');
        }
    }

    public function preencher($id)
    {
        $return = array();

        $sql = "SELECT * FROM ".$this->idioma."cms_redesocial WHERE id = :id;";

        $vars = array(":id" => $id);

        $stmt = $this->pdo->prepare($sql);

        foreach ($vars as $index => $value) {
            $stmt->bindValue($index, $value);

        }
        if ($stmt->execute()) {
            $rows = $stmt->fetch(PDO::FETCH_OBJ);
            $rows->msg = '1';

            foreach ($rows as $index => $value) {
                $rows->$index = utf8_encode($value);
            }

            return $rows;
        } else {
            return array("msg" => '0');
        }
    }

    public function atualizar($id, $descricao, $link, $tipo, $status)
    {

        $return = array();

        $sql = "UPDATE ".$this->idioma."cms_redesocial SET descricao = :descricao, link = :link, tipo =:tipo, status = :status WHERE id = :id;";

        $vars = array(":id" => $id, ":descricao" => $descricao, ":link" => $link, ":tipo" => $tipo, ":status" => $status);

        $stmt = $this->pdo->prepare($sql);

        foreach ($vars as $index => $value) {
            $stmt->bindValue($index, $value);
        }
        $stmt->execute();

        if ($stmt->rowCount()) {
            return array("msg" => '1');
        } else {
            return array("msg" => '0');
        }

    }

    public function excluir($id)
    {

        $retorno = array();

        $sql = "UPDATE ".$this->idioma."cms_redesocial SET status = :status WHERE id = :id;";

        $vars = array(":id" => $id, ":status" => '3');

        $stmt = $this->pdo->prepare($sql);

        foreach ($vars as $index => $value) {
            $stmt->bindValue($index, $value);
        }

        $stmt->execute();

        if ($stmt->rowCount()) {
            return array("msg" => '1');
        } else {
            return array("msg" => '0');
        }
    }
	
	public function listarSite()
    {

        $retorno = array();

        $sql = "SELECT link, tipo, descricao FROM cms_redesocial WHERE status = :status;";

        $vars = array(":status" => 1);

        $stmt = $this->pdo->prepare($sql);

        if ($stmt->execute($vars)) {
            $count = $stmt->rowCount();
            $rows = $stmt->fetchAll(PDO::FETCH_OBJ);
            $rows['msg'] = '1';
            $rows['length'] = $count;

            $i = 0;
            while ($i < $count) {
                foreach ($rows[$i] as $index => $value) {
                    $rows[$i]->$index = utf8_encode($value);
                }
                $i++;
            }

            return $rows;
        } else {
            return array("msg" => '0');
        }
    }

}

?>

Zerion Mini Shell 1.0