Incérmentation id div
Posté : 20 juin 2023, 22:51
				
				Bonjour, 
Je rencontre un soucis, je vais essayé d'être clair dans mon explication:
Je souhaite intégrer un compte à rebours individuel pour chaque annonce d'enchère (remps restant).
Pour cela j'essaie d'incrémenter in ID de div dans une boucle. Le problème est que l'incrémentation ne reste pas fixe, mais varie entre plusieurs chiffres.
Je vous remercie d'avance.
Voici le code:
			Je rencontre un soucis, je vais essayé d'être clair dans mon explication:
Je souhaite intégrer un compte à rebours individuel pour chaque annonce d'enchère (remps restant).
Pour cela j'essaie d'incrémenter in ID de div dans une boucle. Le problème est que l'incrémentation ne reste pas fixe, mais varie entre plusieurs chiffres.
Je vous remercie d'avance.
Voici le code:
Code : Tout sélectionner
<script>
            var x = [];
        </script>
        
        <?php       
                                $id_annonce = 1;
                                foreach($annonces_en_cours as $annonce)
                                {   
                                    $id_annonce++;
                                    // Infos author
                                    $author_id = get_post($annonce->ID)->post_author;
                                    $user_info = get_userdata($author_id);
                                    $user_impl = implode(', ', $user_info->roles);
                                    // Infos annonce
                                    $all_post_meta = get_post_meta($annonce->ID);
                                    $get_title = get_the_title($annonce->ID);                                    
                                    $auction_type = get_the_terms($annonce->ID, 'vehica_19636');
                                    $auction_type_slug = $auction_type[0]->slug;                                      
                                    $annonce_auction_list = get_post_meta($annonce->ID, 'auction_list');
                                    $annonce_auction_status = get_post_meta($annonce->ID, 'auction_status', true);
                                    // Infos autheur
                                    $author_id = get_the_id($annonce);
                                    // Info du véhicule
                                    $get_mark = get_post_meta($annonce->ID, 'vehica_39814', true);
                                    $get_model = get_post_meta($annonce->ID, 'vehica_39815', true);
                                    $get_carburant = get_the_terms($annonce->ID, 'vehica_48489');
                                    $get_boite = get_the_terms($annonce->ID, 'vehica_48484');
                                    $get_km = get_post_meta($annonce->ID, 'vehica_48173', true);                                   
                                    $images_gallery = get_post_meta($annonce->ID, 'vehica_19246');
                                    $first_img_src = wp_get_attachment_image_src($images_gallery[0], 'medium');
                                    $link_to_annonce = get_permalink($annonce->ID);
                                    $get_first_imm = get_post_meta($annonce->ID, 'vehica_19190', true);
                                    $reserve_price = get_post_meta($annonce->ID, 'vehica_currency_19362_2316');
                                    // Infos date
                                    date_default_timezone_set('Europe/Paris');
                                    $start_date = get_post_meta($annonce->ID, 'vehica_20836', true);
                                    $start_hour = get_post_meta($annonce->ID, 'vehica_20856', true);
                                    $start_date_hour = $start_date . ' ' . $start_hour;
                                    $end_date = strtotime($start_date_hour . '+ 1 days');
                                    // Infos si autres annonces
                                    $content = wp_trim_words(get_post_field('post_content', $annonce->ID), 5, '...'); 
                                                                    
                                    // Reserve
                                    if(intval($reserve_price[0]) < 5001)
                                    {
                                            $start_price = intval($reserve_price[0]) * (1 -0.5);
                                        }
                                        else if(intval($reserve_price[0]) < 10001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.35);
                                        }
                                        else if(intval($reserve_price[0]) < 15001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.3);
                                        }
                                        else if(intval($reserve_price[0]) < 25001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.15);
                                        }
                                        else if(intval($reserve_price[0]) < 35001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.15);
                                        }
                                        else if(intval($reserve_price[0]) < 45001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        else if(intval($reserve_price[0]) < 55001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        else if(intval($reserve_price[0]) < 65001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        else if(intval($reserve_price[0]) < 75001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        else if(intval($reserve_price[0]) < 85001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        else if(intval($reserve_price[0]) < 95001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        else if(intval($reserve_price[0]) < 125001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        else if(intval($reserve_price[0]) > 125001)
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 -0.1);
                                        }
                                        
                                        if($auction_type_slug == "autres-annonces")
                                        {
                                            $start_price = intval($reserve_price[0]) * (1 - 0.3); 
                                            $step_price = 10; 
                                            $max_price = intval($reserve_price[0]) + 1000; 
                                    }
                                    if( !empty($annonce_auction_list))
                                    {
                                        $get_current_last_auction = end($annonce_auction_list[0]); 
                                        $get_actual_auction_price = number_format($get_current_last_auction['auctionner_price'], 0, ".", "'");
                                    }
                                    
                                    if($annonce_auction_status == 'demarrer')
                                    {
                                        echo'  
                                        
                                        <li class="afs-list-item list--list-item afs-car-' . $annonce->ID . '" data-id="' . $annonce->ID . '" data-gender="' . $auction_type_slug . '">                                        
                                        
                                            <div class="auction_end_date" style="display: none;">' . $end_date . '</div>
                                            <div class="get_home_auction_list_item_zone_text_hidden_end_date" style="display: none;">' . $end_date . '</div>
                                            <div class="get_home_auction_list_item_zone_text_date" style="display: none;">' . $start_date_hour . '</div>
                                            <div class="name" style="height: 1px;">' . $get_mark . '</div>
                                            <div class="address" style="height: 1px;">' . $user_impl . '</div>
                                            <div class="afs-card__inner">
                                                <a href="' . $link_to_annonce . '" class="afs-card-link"></a>         
                                                <div class="afs-list-item__image-bg" >
                                                    <div class="afs_list_item__image">
                                                        <img src="' . $first_img_src[0] . '" data-sizes="auto" alt="' . $get_title . '" class="lazyautosizes lazyloaded" sizes="248px" srcset="">                                                            
                                                    </div>
                                                </div>  
                                                <div style="display: flex; justify-content: space-between; background: #F37021; border-bottom: 1px solid #F37021; padding: 1% 0;">'; ?>
                                                    <script>
                                                        <?php 
                                                            $dateTime = $end_date;
                                                            $getDateTime = date("F d, Y H:i:s", $dateTime);
                                                        ?>
                                                        var countDownDate = new Date("<?php echo "$getDateTime"; ?>").getTime();
                                                        
                                                        // Update the count down every 1 second
                                                        
                                                        x[<?=$id_annonce?>] =  setInterval(function() {
                                                            var now = new Date().getTime();
                                                            // Find the distance between now an the count down date
                                                            var distance = countDownDate - now;                
                                                            // Time calculations for days, hours, minutes and seconds
                                                            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                                                            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                                                            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
                                                            // Output the result in an element with id="counter"11
                                                            if(distance > 0)
                                                            {
                                                                $('.afs_card_cardcounter').html(
                                                                "<ul id='afs_card_counter_'<? $id_annonce; ?>' class='afs_counter_card_number'>" +
                                                                    "<li>" + "<i class='fas fa-clock'></i> " + "</li>" +
                                                                    "<li>" + hours + "<span>" + " H" + "</span>" + "</li>" +
                                                                    "<li>" + minutes + "<span>" + " Min " + "</span>" + "</li>" +
                                                                    "<li>" + seconds + "<span>" + " Sec " + "</span>" + "</li>" +
                                                                "</ul>");     
                                                            }
                                                            else
                                                            {
                                                                $('.afs_card_cardcounter').html(
                                                                "<ul id='afs_card_counter_'<? $id_annonce; ?>' class='afs_counter_card_number'>" +
                                                                    "<li class='afs_counter_ended'>" + "<i class='fas fa-clock'></i> " + "Enchère terminée" + "</li>" +
                                                                "</ul>"
                                                                );
                                                            }                   
                                                        }, 1000);
                                                    </script>
                                                    
                                                    <?php
                                                    echo '
                                                    <div class="afs_card_cardcounter afs_card_cardcounter_in_progress_counter_background"></div>';                                                       
                                                    if(!empty($annonce_auction_list)) 
                                                    {
                                                        $get_current_last_auction = end($annonce_auction_list[0]); 
                                                        $get_actual_auction_price = number_format($get_current_last_auction['auctionner_price'], 0, ".", "'");
                                                    
                                                        echo '<div class="afs-card__image__seller" style="font-weight: 600;"><i class="fas fa-gavel" style="margin-right: 5px;"></i>' . $get_actual_auction_price  . '.- CHF</div>';
                                                    }
                                                    echo'
                                                </div>
                                                
                                                <div class="afs-list-item__content">
                                                
                                                    <div style="display: flex; align-items: baseline; justify-content: space-between;">
                                                        <a href="' . $link_to_annonce . '"title="' . $get_title . '"class="afs-list-item__name">' . $get_mark . ' ' . $get_model . '</a>                                                                                                    
                                                    </div>
                                                    
                                                    <div class="afs-card_price">Prix de départ : ';
                                                    
                                                        if($auction_type_slug == 'autres-annonces' && $start_price < 1000)
                                                        {
                                                            echo number_format(ceil($start_price/10)*10, 0, ".", "'") . ' CHF';
                                                        }
                                                        else
                                                        {
                                                            echo number_format(ceil($start_price/100)*100, 0, ".", "'") . ' CHF';
                                                        }
                                                        echo '
                                                    </div>
                                                                                        
                                                    <div class="afs-card-card__separator"></div>';
                                                    if($auction_type_slug == 'autres-annonces')
                                                    {
                                                        echo '<div class="afs-list-item-card__info">' . $content . '</div>';
                                                    }
                                                    else
                                                    {
                                                        echo'
                                                            
                                                        <div class="afs-list-item-card__info">';
                                                            if(!empty($get_first_imm))
                                                            {
                                                                echo '<div class="afs-list-item__info__single">' . $get_first_imm . '</div>';
                                                            }
                                                            if(!empty($get_km))
                                                            {
                                                                echo '<div class="afs-list-item__info__single">' . number_format($get_km, 0, ".", "'") . ' Km</div>';
                                                            }
                                                            if(!empty($get_boite))
                                                            {
                                                                echo '<div class="afs-list-item__info__single">' . $get_boite[0]->name . '</div>';
                                                            }
                                                            /*if(!empty($get_carburant))
                                                            {
                                                                echo '<div class="afs-list-item__info__single">' . $get_carburant[0]->name . '</div>';
                                                            }*/
                                                            
                                                            echo'       
                                                        </div>';   
                                                    }
                                                    
                                                    echo '
                                                
                                                </div>                          
                                                        
                                            </div>                                             
                                        </li>';
                                    }
                                }
                            ?>  
        
 
 