Skip to content

Instantly share code, notes, and snippets.

@gilsonbp
Created August 29, 2013 17:14
Show Gist options
  • Save gilsonbp/6380838 to your computer and use it in GitHub Desktop.
Save gilsonbp/6380838 to your computer and use it in GitHub Desktop.
Método para seleção de imagens independente do objeto
// Instancie a classe para view
// $this->view->getImagens = new Application_Model_DbTable_Imagemrel();
//
// Na view basta chamar o método passando os parâmetros
// $this->getImagens->getImageCapa($noticias_left['id'], 'NOT', 'C', 140, 140, 'img-rounded img-destaque', '/noticia/' . $noticias_left['slug']);
// Método
/**
* Seleção de imagem de capa
* @param int $objeto_id Objeto relcionado
* @param string $objeto Itentifica qual objeto está relacionado
* @param string $tipo Tipo de objeto relacionado, define o tamanho na Model de imagens
* @param int $width Define o tamanho para HTML da imagem
* @param int $height Define a altura para o HTML da imagem
* @param string $class Define uma ou mais classes CSS para imagem
* @param string $link Define um link para imagem
* @return html Retorna a imagem junto com uma tag <a> e uma tag <img>
*/
public function getImageCapa($objeto_id, $objeto, $tipo, $width, $height, $class = '', $link = '') {
$row = $this->getAdapter()->fetchRow(
"SELECT b.*
FROM hr013 a INNER JOIN hr012 b ON (a.image_id = b.id)
WHERE a.objeto_id = $objeto_id AND a.objeto = '$objeto' AND b.tipo = '$tipo'
ORDER BY b.id DESC
LIMIT 1"
);
$img = '';
if ($row) {
if (!empty($link)) {
$img .= "<a href='$link'>";
}
$img .= "<img src='{$row['dir']}' width='$width' height='$height' title='{$row['legenda']}' alt='{$row['legenda']}' class='$class'>";
if (!empty($link)) {
$img .= "</a>";
}
}
echo $img;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment