available_filters = array('main_fields' => array( 'types' => 'scheduler_types', 'labels' => 'scheduler_labels', 'states' => 'scheduler_states', 'date' => 'scheduler_dates', ) ); $this->available_filters['custom_fields'] = array(); } /** * Initialisation des filtres de recherche */ public function init_filters($filters=array()) { $this->filters = array( 'types' => array(), 'labels' => array(), 'date_start' => '', 'date_end' => '', 'states' => array(), 'ids' => array() ); parent::init_filters($filters); } protected function init_default_selected_filters() { $this->add_selected_filter('types'); $this->add_selected_filter('labels'); $this->add_selected_filter('states'); $this->add_selected_filter('date'); } /** * Initialisation des colonnes disponibles */ protected function init_available_columns() { $this->available_columns = array('main_fields' => array( 'label' => 'planificateur_task', 'date_start' => 'planificateur_start_exec', 'date_end' => 'planificateur_end_exec', 'date_next' => 'planificateur_next_exec', 'progress' => 'planificateur_progress_task', 'state' => 'planificateur_etat_exec', 'command' => 'planificateur_commande_exec', ) ); } /** * Initialisation du tri par défaut appliqué */ protected function init_default_applied_sort() { $this->add_applied_sort('date_next', 'desc'); } /** * Fonction de callback * @param $a * @param $b */ protected function _compare_objects($a, $b) { $sort_by = $this->applied_sort[0]['by']; switch ($sort_by) { case 'date_start': case 'date_end': if($a->{$sort_by} == '0000-00-00 00:00:00') { return -1; } elseif($b->{$sort_by} == '0000-00-00 00:00:00') { return 1; } else { return strcmp($a->{$sort_by}, $b->{$sort_by}); } break; case 'date_next': $scheduler_dashboard = new scheduler_dashboard(); $a_date_next = strip_tags($scheduler_dashboard->command_waiting($a->id)); $b_date_next = strip_tags($scheduler_dashboard->command_waiting($b->id)); if($a_date_next == '' && $b_date_next == '') { return strcmp($a->date_start, $b->date_start); } elseif($a_date_next == '') { return -1; } elseif($b_date_next == '') { return 1; } else { return strcmp($a_date_next, $b_date_next); } break; default: return parent::_compare_objects($a, $b); } } /** * Filtres provenant du formulaire */ public function set_filters_from_form() { $this->set_filter_from_form('types', 'integer'); $this->set_filter_from_form('labels'); $this->set_filter_from_form('states'); $this->set_filter_from_form('date_start'); $this->set_filter_from_form('date_end'); parent::set_filters_from_form(); } protected function get_selection_actions() { global $msg; if(!isset($this->selection_actions)) { $delete_link = array( 'href' => static::get_controller_url_base()."&action=list_delete", 'confirm' => $msg['scheduler_delete_confirm'] ); $this->selection_actions = array( $this->get_selection_action('delete', $msg['63'], 'interdit.gif', $delete_link) ); } return $this->selection_actions; } protected function get_display_cell_html_value($object, $value) { if($object->state <= 2) { $value = ""; } return parent::get_display_cell_html_value($object, $value); } protected function init_default_columns() { $this->add_column_selection(); $this->add_column('label'); $this->add_column('date_start'); $this->add_column('date_end'); $this->add_column('date_next'); $this->add_column('progress'); $this->add_column('state'); $this->add_column('command'); } protected function init_default_settings() { parent::init_default_settings(); $this->set_setting_display('search_form', 'options', true); $this->set_setting_display('search_form', 'export_icons', false); } protected function get_search_filter_types() { global $msg, $charset; scheduler_tasks::parse_catalog(); $selector = ""; return $selector; } protected function get_search_filter_labels() { global $msg, $charset; $selector = ""; return $selector; } protected function get_search_filter_states() { global $msg, $charset; $selector = ""; return $selector; } protected function get_search_filter_date() { return $this->get_search_filter_interval_date('date'); } /** * Filtre SQL */ protected function _get_query_filters() { $filter_query = ''; $this->set_filters_from_form(); $filters = array(); if(is_array($this->filters['types']) && count($this->filters['types'])) { $filters [] = 'num_type_tache IN ("'.implode('","', $this->filters['types']).'")'; } if(is_array($this->filters['labels']) && count($this->filters['labels'])) { $filters [] = 'libelle_tache IN ("'.implode('","', addslashes_array($this->filters['labels'])).'")'; } if(is_array($this->filters['states']) && count($this->filters['states'])) { $filters [] = 'status IN ("'.implode('","', $this->filters['states']).'")'; } if($this->filters['date_start']) { $filters [] = 'start_at >= "'.$this->filters['date_start'].'"'; } if($this->filters['date_end']) { $filters [] = 'end_at <= "'.$this->filters['date_end'].' 23:59:59"'; } if($this->filters['ids']) { $filters [] = 'id_tache IN ('.$this->filters['ids'].')'; } if(count($filters)) { $filter_query .= ' where '.implode(' and ', $filters); } return $filter_query; } protected function _get_query_human_types() { $types_labels = array(); scheduler_tasks::parse_catalog(); foreach (scheduler_tasks::$xml_catalog['ACTION'] as $element) { if(in_array($element['ID'], $this->filters['types'])) { $types_labels[] = get_msg_to_display($element['COMMENT']); } } return $types_labels; } protected function _get_query_human_states() { global $msg; $states_labels = array(); foreach ($this->filters['states'] as $state) { $states_labels[] = $msg['planificateur_state_'.$state]; } return $states_labels; } protected function _get_query_human_date() { return $this->_get_query_human_interval_date('date'); } protected function get_commands($object) { global $charset; $scheduler_tasks = new scheduler_tasks(); foreach ($scheduler_tasks->tasks as $name=>$tasks_type) { if ($tasks_type->get_id() == $object->num_type_tache) { //présence de commandes .. selecteurs ?? $show_commands = ""; $states = $tasks_type->get_states(); foreach ($states as $aelement) { if ($object->state == $aelement["id"]) { foreach ($aelement["nextState"] as $state) { if ($state["command"] != "") { //récupère le label de la commande $commands = $tasks_type->get_commands(); foreach($commands as $command) { if (($state["command"] == $command["name"]) && ($state["dontsend"] != "yes")) { $show_commands .= ""; } } } } } } return $show_commands; } } return ''; } /** * Construction dynamique de la fonction JS de tri */ protected function get_js_sort_script_sort() { global $sub; $display = parent::get_js_sort_script_sort(); $display = str_replace('!!categ!!', 'planificateur', $display); $display = str_replace('!!sub!!', $sub, $display); $display = str_replace('!!action!!', 'list', $display); return $display; } protected function get_cell_content($object, $property) { global $msg; $content = ''; switch($property) { case 'date_start': case 'date_end': if($object->{$property} != '0000-00-00 00:00:00') { $content .= formatdate($object->{$property}, 1); } break; case 'date_next': $scheduler_dashboard = new scheduler_dashboard(); $content .= $scheduler_dashboard->command_waiting($object->id); break; case 'progress': $scheduler_progress_bar = new scheduler_progress_bar($object->progress); $content .= $scheduler_progress_bar->get_display(); break; case 'state': $content .= $msg['planificateur_state_'.$object->{$property}]; break; case 'command': $show_commands = $this->get_commands($object); if ($show_commands != "") { $content .= ""; } break; default : $content .= parent::get_cell_content($object, $property); break; } return $content; } protected function get_display_cell($object, $property) { if($property == 'date_next') { return $this->get_cell_content($object, $property); } else { //lien du rapport $line="onmousedown=\"if (event) e=event; else e=window.event; \" onClick='show_layer(); get_report_content(".$object->id.",".$object->num_type_tache.");' style='cursor: pointer'"; return "".$this->get_cell_content($object, $property).""; } } /** * Affiche la recherche + la liste */ public function get_display_list() { global $base_path; $display = " "; $display .= parent::get_display_list(); return $display; } protected function get_grouped_label($object, $property) { global $msg; $grouped_label = ''; switch($property) { case 'date_start': case 'date_end': case 'date_next': $grouped_label = substr($object->{$this->applied_group[0]},0,10); break; case 'state': $grouped_label = $msg['planificateur_state_'.$object->state]; break; case 'progress': $grouped_label = $object->progress.'%'; break; default: $grouped_label = parent::get_grouped_label($object, $property); break; } return $grouped_label; } public static function delete() { $selected_objects = static::get_selected_objects(); if(is_array($selected_objects) && count($selected_objects)) { foreach ($selected_objects as $id) { scheduler_task::delete($id); } } } }