modules/archi/includes/archiAdresse.class.php
public function getFirstImageFromEvenement($idEvenement = 0)
    {
        $fetch=array();

        $reqVerifTri = "
                    SELECT ei.idImage
                    FROM _evenementImage ei
                    WHERE ei.idEvenement = '".$idEvenement."'
                    AND position<>0
        ";

        $resVerifTri = $this->connexionBdd->requete($reqVerifTri);

        if (mysql_num_rows($resVerifTri)>0) {
        // les images ont deja ete triés , on prend celle qui a la plus petite position <>0
            $req = "
                SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload , hi1.idImage as idImage
                FROM historiqueImage hi2,historiqueImage hi1
                RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement ='".$idEvenement."'
                RIGHT JOIN _evenementImage ei2 ON ei2.idEvenement = ei1.idEvenement
                WHERE hi1.idImage = ei1.idImage
                AND hi2.idImage = hi1.idImage
                AND ei1.position<>'0'
                AND ei2.position<>'0'
                GROUP BY hi1.idImage,ei1.position,hi1.idHistoriqueImage
                HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage) AND ei1.position = min(ei2.position)
                ORDER BY ei1.position ASC
            ";

            $res = $this->connexionBdd->requete($req);

            $fetch = mysql_fetch_assoc($res);
        } else {
            // pas d'image de position differente de zero , on selectionne la derniere ajoutée de l'evenement
            $req = "
                SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload, hi1.idImage as idImage
                FROM historiqueImage hi2,historiqueImage hi1
                RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement ='".$idEvenement."'
                WHERE hi1.idImage = ei1.idImage
                AND hi2.idImage = hi1.idImage
                GROUP BY hi1.idImage,hi1.idHistoriqueImage
                HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
                ORDER BY hi1.idHistoriqueImage
            ";

            $res = $this->connexionBdd->requete($req);

            if (mysql_num_rows($res)==0) {
            // pas d'image pour l'evenement courant, on va en chercher une pour l'adresse courante de l'evenement ( donc dans un evenement de la meme adresse)
                $req = "
                    SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload,ei1.position as position  , hi1.idImage as idImage
                    FROM historiqueImage hi2,historiqueImage hi1

                    RIGHT JOIN _evenementEvenement ee ON ee.idEvenementAssocie = '".$idEvenement."'
                    LEFT JOIN _evenementEvenement ee2 ON ee2.idEvenement = ee.idEvenement
                    RIGHT JOIN _evenementEvenement ee3 ON ee3.idEvenement = ee2.idEvenementAssocie
                    RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement = ee3.idEvenementAssocie

                    WHERE hi1.idImage = ei1.idImage
                    AND hi2.idImage = hi1.idImage
                    GROUP BY hi1.idImage,hi1.idHistoriqueImage
                    HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
                    ORDER BY position, hi1.idHistoriqueImage
                ";

                $res = $this->connexionBdd->requete($req);
                while ($fetchImagesAdresses = mysql_fetch_assoc($res)) {
                    if ($fetchImagesAdresses['position']=='1') {
                        $fetch = $fetchImagesAdresses;
                        break;
                    } else {
                        $fetch = $fetchImagesAdresses;
                    }
                }
            } else {
                $fetch = mysql_fetch_assoc($res);
            }
        }

        return $fetch;
    }
public function getFirstImageFromEvenement($idEvenement = 0)
    {
        $fetch=array();

        $reqVerifTri = "
                    SELECT ei.idImage
                    FROM _evenementImage ei
                    WHERE ei.idEvenement = '".$idEvenement."'
                    AND position<>0
        ";

        $resVerifTri = $this->connexionBdd->requete($reqVerifTri);

        if (mysql_num_rows($resVerifTri)>0) {
        // les images ont deja ete triés , on prend celle qui a la plus petite position <>0
            $req = "
                SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload , hi1.idImage as idImage
                FROM historiqueImage hi2,historiqueImage hi1
                RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement ='".$idEvenement."'
                RIGHT JOIN _evenementImage ei2 ON ei2.idEvenement = ei1.idEvenement
                WHERE hi1.idImage = ei1.idImage
                AND hi2.idImage = hi1.idImage
                AND ei1.position<>'0'
                AND ei2.position<>'0'
                GROUP BY hi1.idImage,ei1.position,hi1.idHistoriqueImage
                HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage) AND ei1.position = min(ei2.position)
                ORDER BY ei1.position ASC
            ";

            $res = $this->connexionBdd->requete($req);

            $fetch = mysql_fetch_assoc($res);
        } else {
            // pas d'image de position differente de zero , on selectionne la derniere ajoutée de l'evenement
            $req = "
                SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload, hi1.idImage as idImage
                FROM historiqueImage hi2,historiqueImage hi1
                RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement ='".$idEvenement."'
                WHERE hi1.idImage = ei1.idImage
                AND hi2.idImage = hi1.idImage
                GROUP BY hi1.idImage,hi1.idHistoriqueImage
                HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
                ORDER BY hi1.idHistoriqueImage
            ";

            $res = $this->connexionBdd->requete($req);

            if (mysql_num_rows($res)==0) {
            // pas d'image pour l'evenement courant, on va en chercher une pour l'adresse courante de l'evenement ( donc dans un evenement de la meme adresse)
                $req = "
                    SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload,ei1.position as position  , hi1.idImage as idImage
                    FROM historiqueImage hi2,historiqueImage hi1

                    RIGHT JOIN _evenementEvenement ee ON ee.idEvenementAssocie = '".$idEvenement."'
                    LEFT JOIN _evenementEvenement ee2 ON ee2.idEvenement = ee.idEvenement
                    RIGHT JOIN _evenementEvenement ee3 ON ee3.idEvenement = ee2.idEvenementAssocie
                    RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement = ee3.idEvenementAssocie

                    WHERE hi1.idImage = ei1.idImage
                    AND hi2.idImage = hi1.idImage
                    GROUP BY hi1.idImage,hi1.idHistoriqueImage
                    HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
                    ORDER BY position, hi1.idHistoriqueImage
                ";

                $res = $this->connexionBdd->requete($req);
                while ($fetchImagesAdresses = mysql_fetch_assoc($res)) {
                    if ($fetchImagesAdresses['position']=='1') {
                        $fetch = $fetchImagesAdresses;
                        break;
                    } else {
                        $fetch = $fetchImagesAdresses;
                    }
                }
            } else {
                $fetch = mysql_fetch_assoc($res);
            }
        }

        return $fetch;
    }
public function getFirstImageFromEvenement ( $ idEvenement = 0 ) { $ fetch = array ( ) ; $ reqVerifTri = "
                    SELECT ei.idImage
                    FROM _evenementImage ei
                    WHERE ei.idEvenement = '" . $ idEvenement . "'
                    AND position<>0
        " ; $ resVerifTri = $ this -> connexionBdd -> requete ( $ reqVerifTri ) ; if ( mysql_num_rows ( $ resVerifTri ) > 0 ) { // les images ont deja ete triés , on prend celle qui a la plus petite position <>0 $ req = "
                SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload , hi1.idImage as idImage
                FROM historiqueImage hi2,historiqueImage hi1
                RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement ='" . $ idEvenement . "'
                RIGHT JOIN _evenementImage ei2 ON ei2.idEvenement = ei1.idEvenement
                WHERE hi1.idImage = ei1.idImage
                AND hi2.idImage = hi1.idImage
                AND ei1.position<>'0'
                AND ei2.position<>'0'
                GROUP BY hi1.idImage,ei1.position,hi1.idHistoriqueImage
                HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage) AND ei1.position = min(ei2.position)
                ORDER BY ei1.position ASC
            " ; $ res = $ this -> connexionBdd -> requete ( $ req ) ; $ fetch = mysql_fetch_assoc ( $ res ) ; } else { // pas d'image de position differente de zero , on selectionne la derniere ajoutée de l'evenement $ req = "
                SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload, hi1.idImage as idImage
                FROM historiqueImage hi2,historiqueImage hi1
                RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement ='" . $ idEvenement . "'
                WHERE hi1.idImage = ei1.idImage
                AND hi2.idImage = hi1.idImage
                GROUP BY hi1.idImage,hi1.idHistoriqueImage
                HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
                ORDER BY hi1.idHistoriqueImage
            " ; $ res = $ this -> connexionBdd -> requete ( $ req ) ; if ( mysql_num_rows ( $ res ) == 0 ) { // pas d'image pour l'evenement courant, on va en chercher une pour l'adresse courante de l'evenement ( donc dans un evenement de la meme adresse) $ req = "
                    SELECT hi1.idHistoriqueImage as idHistoriqueImage, hi1.dateUpload as dateUpload,ei1.position as position  , hi1.idImage as idImage
                    FROM historiqueImage hi2,historiqueImage hi1

                    RIGHT JOIN _evenementEvenement ee ON ee.idEvenementAssocie = '" . $ idEvenement . "'
                    LEFT JOIN _evenementEvenement ee2 ON ee2.idEvenement = ee.idEvenement
                    RIGHT JOIN _evenementEvenement ee3 ON ee3.idEvenement = ee2.idEvenementAssocie
                    RIGHT JOIN _evenementImage ei1 ON ei1.idEvenement = ee3.idEvenementAssocie

                    WHERE hi1.idImage = ei1.idImage
                    AND hi2.idImage = hi1.idImage
                    GROUP BY hi1.idImage,hi1.idHistoriqueImage
                    HAVING hi1.idHistoriqueImage = max(hi2.idHistoriqueImage)
                    ORDER BY position, hi1.idHistoriqueImage
                " ; $ res = $ this -> connexionBdd -> requete ( $ req ) ; while ( $ fetchImagesAdresses = mysql_fetch_assoc ( $ res ) ) { if ( $ fetchImagesAdresses [ 'position' ] == '1' ) { $ fetch = $ fetchImagesAdresses ; break ; } else { $ fetch = $ fetchImagesAdresses ; } } } else { $ fetch = mysql_fetch_assoc ( $ res ) ; } } return $ fetch ; }
recupere la premiere image d'un evenement en fonction de sa position
recupere la premiere image d un evenement en fonction de sa position