require_once('loja.fisica.php');
require_once('loja.virtual.php');
require_once('categoria.cor.php');
class Marca extends Model_Image {
const TABLE = 'marcas';
const IMG_SIZE = '300x130';
const CATALOGO = '300x340';
const ORDER_BY = 'ordem, id';
protected $id = 0;
protected $titulo = '';
protected $tag = '';
protected $url = '';
protected $descricaoBR = '';
protected $descricaoEN = '';
protected $descricaoES = '';
protected $catalogo = '';
protected $capaCatalogo = '';
protected $ordem = 0;
protected $images = array('logomarca' => '');
protected static $path = 'img/marcas/';
public function __get($field){
if ($field == 'descricao') {
if (property_exists(__CLASS__,$field.LANG)){
return $this->{$field.LANG};
} else {
return '';
}
} elseif ($field == 'tag_lang') {
switch ($this->tag){
case 'adoleta-bebe': return 'ADOLETA'; break;
case 'dream-baby':
case 'dreambaby': return 'DREAMBABY';break;
case 'nuby': return 'NUBY';break;
default: return 'NUBY';
}
} else {
return parent::__get($field);
}
}
public function __set($field,$value){
if ($field == 'descricao'){
if (property_exists(__CLASS__,$field.LANG)){
$this->{$field.LANG} = trim($value);
}
} else {
return parent::__set($field,$value);
}
}
public function post(){
$args = get_object_vars($this);
unset($args['id']);
unset($args['images']);
unset($args['catalogo']);
unset($args['capaCatalogo']);
unset($args['ordem']);
foreach ($args as $var => $value){
$val = (isset($_POST[$var])) ? $_POST[$var] : null;
$this->__set($var,$val);
}
if (isset($_GET['id'])){
$this->id = intval($_GET['id']);
}
$this->tag = Functions::montaTag($this->titulo);
}
public function gravar(){
$params = get_object_vars($this);
$table = self::TABLE;
unset($params['images']);
unset($params['catalogo']);
unset($params['capaCatalogo']);
if (!$this->id){
unset($params['id']);
self::$db->insert($table,$params,true);
$this->id = self::$db->lastID();
} else {
$params['id'] = $this->id;
self::$db->update($table,$params,array('id' => $this->id));
}
$path = self::path();
$img_ext = array('jpg','jpeg','png','gif');
if (isset($_FILES['logomarca']) && is_uploaded_file($_FILES['logomarca']['tmp_name'])){
$filename = $_FILES['logomarca']['name'];
$aux = explode('.',$filename);
$ext = array_pop($aux);
$ext = strtolower($ext);
if (!in_array($ext,$img_ext)){
throw new Exception("O arquivo $filename não é uma extensão de imagem válida!");
}
$img = $this->images['logomarca'];
if (is_file($path.$img)){
unlink($path.$img);
}
$filename = Functions::corrigeNome($filename);
$file = $this->id.'_'.$filename;
if (is_file($path.$file)){
$i = 1;
$file = $this->id.'_'.$i.'_'.$filename;
while (is_file($path.$file)){
$file = $this->id.'_'.(++$i).'_'.$filename;
}
}
$this->images['logomarca'] = $file;
move_uploaded_file($_FILES['logomarca']['tmp_name'],$path.$file);
self::$db->update(self::TABLE,array('logomarca' => $file),array('id' => $this->id));
$this->resize($file, false, self::IMG_SIZE);
}
if (isset($_FILES['capaCatalogo']) && is_uploaded_file($_FILES['capaCatalogo']['tmp_name'])){
$filename = $_FILES['capaCatalogo']['name'];
$aux = explode('.',$filename);
$ext = array_pop($aux);
$ext = strtolower($ext);
if (!in_array($ext,$img_ext)){
throw new Exception("O arquivo $filename não é uma extensão de imagem válida!");
}
$img = $this->capaCatalogo;
if (is_file($path.$img)){
unlink($path.$img);
}
$filename = Functions::corrigeNome($filename);
$file = $this->id.'_'.$filename;
if (is_file($path.$file)){
$i = 1;
$file = $this->id.'_'.$i.'_'.$filename;
while (is_file($path.$file)){
$file = $this->id.'_'.(++$i).'_'.$filename;
}
}
$this->capaCatalogo = $file;
move_uploaded_file($_FILES['capaCatalogo']['tmp_name'],$path.$file);
self::$db->update(self::TABLE,array('capaCatalogo' => $file),array('id' => $this->id));
$this->resize($file, false, self::CATALOGO);
}
$path = '../catalogos/';
if (isset($_FILES['catalogo']) && is_uploaded_file($_FILES['catalogo']['tmp_name'])){
$filename = $_FILES['catalogo']['name'];
$aux = explode('.',$filename);
$ext = array_pop($aux);
$ext = strtolower($ext);
if ($ext != 'pdf'){
throw new Exception("O arquivo $filename não é uma extensão pdf válida!");
}
$pdf = $this->catalogo;
if (is_file($path.$pdf)){
unlink($path.$pdf);
}
$filename = Functions::corrigeNome($filename);
$file = $this->id.'_'.$filename;
if (is_file($path.$file)){
$i = 1;
$file = $this->id.'_'.$i.'_'.$filename;
while (is_file($path.$file)){
$file = $this->id.'_'.(++$i).'_'.$filename;
}
}
$this->catalogo = $file;
move_uploaded_file($_FILES['catalogo']['tmp_name'],$path.$file);
self::$db->update(self::TABLE,array('catalogo' => $file),array('id' => $this->id));
}
}
public function lojasFisicas(){
self::initDB();
$sql = 'select l.* ';
$sql .= 'from '.LojaFisica::TABLE.' as l ';
$sql .= 'inner join '.LojaFisica::REL.' as r ';
$sql .= 'on l.id = r.idLoja ';
$sql .= 'where r.idMarca = '.$this->id.' ';
$sql .= 'order by '.LojaFisica::ORDER_BY;
self::$db->setClass('LojaFisica');
$lojas = self::$db->query($sql);
self::$db->setClass(null);
return is_array($lojas)?$lojas:array($lojas);
}
public function lojasVirtuais(){
self::initDB();
$sql = 'select l.* ';
$sql .= 'from '.LojaVirtual::TABLE.' as l ';
$sql .= 'inner join '.LojaVirtual::REL.' as r ';
$sql .= 'on l.id = r.idLoja ';
$sql .= 'where r.idMarca = '.$this->id.' ';
$sql .= 'order by '.LojaVirtual::ORDER_BY;
self::$db->setClass('LojaVirtual');
$lojas = self::$db->query($sql);
self::$db->setClass(null);
return is_array($lojas)?$lojas:array($lojas);
}
public function cores(){
$sql = 'select cat.* ';
$sql .= 'from '.CatCor::TABLE.' as cat ';
$sql .= 'inner join '.Cor::TABLE.' as cor ';
$sql .= 'on cat.id = cor.idCat ';
$sql .= 'where cor.idMarca = '.$this->id;
self::$db->setClass('CatCor');
$cores = self::$db->query($sql,$params);
self::$db->setClass(null);
}
public static function marcas($idCat = null,$idSubCat = null,$idSubSubCat = null){
self::initDB();
$sql = 'select m.* ';
$sql .= 'from '.self::TABLE.' as m ';
$sql .= 'inner join '.Produto::TABLE.' as p ';
$sql .= 'on m.id = p.idMarca ';
$sql .= 'inner join '.Produto::REL.' as rel ';
$sql .= 'on p.id = rel.idProduto ';
$sql .= 'where m.id != -1 ';
$params = array();
if ($idSubSubCat !== null && $idSubSubCat !== ''){
$sql .= 'and rel.idSubSubCat in (:idSubSubCat) ';
$params[':idSubSubCat'] = $idSubSubCat;
} elseif ($idSubCat !== null && $idSubCat !== ''){
$sql .= 'and rel.idSubCat in (:idSubCat) ';
$params[':idSubCat'] = $idSubCat;
} elseif ($idCat !== null && $idCat !== ''){
$sql .= 'and rel.idCat = :idCat ';
$params[':idCat'] = intval($idCat);
}
$sql .= 'group by m.id ';
$sql .= 'order by titulo'.LANG;
self::$db->setClass('Marca');
$marcas = self::$db->query($sql,$params);
self::$db->setClass(null);
return is_array($marcas)?$marcas:array($marcas);
}
public function categorias(){
$sql = 'select c.* ';
$sql .= 'from '.Categoria::TABLE.' as c ';
$sql .= 'inner join '.Produto::REL.' as rel ';
$sql .= 'on c.id = rel.idCat ';
$sql .= 'inner join '.Produto::TABLE.' as p ';
$sql .= 'on p.id = rel.idProduto ';
$sql .= 'where p.idMarca = :id ';
$sql .= 'group by c.id ';
$params = array(':id' => $this->id);
self::$db->setClass('Categoria');
$categorias = self::$db->query($sql,$params);
self::$db->setClass(null);
return is_array($categorias)?$categorias:array($categorias);
}
}
Fatal error: Uncaught Error: Class 'Marca' not found in /home/storage/6/95/8d/adoleta1/public_html/includes/header.php:8
Stack trace:
#0 /home/storage/6/95/8d/adoleta1/public_html/topo.php(1): include()
#1 /home/storage/6/95/8d/adoleta1/public_html/produtos.php(2): include('/home/storage/6...')
#2 {main}
thrown in /home/storage/6/95/8d/adoleta1/public_html/includes/header.php on line 8