<?php
// +-------------------------------------------------+
// 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: cms_module_common_filter_animations_by_status.class.php,v 1.1.4.2 2026/06/24 07:45:46 tsamson Exp $

if (stristr($_SERVER['REQUEST_URI'], ".class.php")) {
    die("no access");
}

class cms_module_common_filter_animations_by_status extends cms_module_common_filter
{
    /**
     * @return array
     */
    public function get_filter_from_selectors()
    {
        return array(
            "cms_module_common_selector_animation_by_status_from"
        );
    }
    
    /**
     * @return array
     */
    public function get_filter_by_selectors()
    {
        return array(
            "cms_module_common_selector_animation_by_status"
        );
    }
    
    /**
     * Filtre les animations par statut selon les identifiants configures dans le selecteur
     *
     * @param array $datas Tableau d'identifiants d'animations
     * @return array
     */
    public function filter($datas)
    {
        if (empty($datas)) {
            return $datas;
        }
        
        $selector_by = $this->get_selected_selector("by");
        if (!$selector_by) {
            return $datas;
        }
        
        $status_ids = $selector_by->get_value();
        if (empty($status_ids)) {
            return $datas;
        }
        
        $status_ids = array_map('intval', (array) $status_ids);
        $animation_ids = array_map('intval', $datas);
        
        $query = "SELECT id_animation FROM anim_animations
                    WHERE num_status IN (" . implode(',', $status_ids) . ")
                    AND id_animation IN (" . implode(',', $animation_ids) . ")";
        
        $result = pmb_mysql_query($query);
        
        $filtered_datas = [];
        while ($row = pmb_mysql_fetch_row($result)) {
            $filtered_datas[] = $row[0];
        }
        
        return $filtered_datas;
    }
}
