objects_type = str_replace('rent_', '', get_class($this)); $this->init_filters($filters); $this->init_pager($pager); $this->init_applied_sort($applied_sort); $this->fetch_data(); $this->_sort(); $this->_limit(); } protected function fetch_data() { $this->objects = array(); $this->messages = ""; } /** * Sélecteur des exercices comptables en cours */ static public function gen_selector_exercices($id_entity, $filter_type = '', $selected = 0) { global $msg; $display = ''; entites::setSessionBibliId($id_entity); $query = exercices::listByEntite($id_entity,1); $display=gen_liste($query,'id_exercice','libelle', $filter_type.'_search_form_exercices', '', $selected, 0,$msg['acquisition_account_exercices_empty'],0,''); return $display; } /** * Initialisation des filtres de recherche */ public function init_filters($filters=array()) { } /** * Initialisation de la pagination */ public function init_pager($pager=array()) { $this->pager = array( 'page' => 1, 'nb_per_page' => 15, 'nb_results' => 0, 'nb_page' => 1 ); if(isset($_SESSION['rent_'.$this->objects_type.'_pager']['nb_per_page'])) { $this->pager['nb_per_page'] = $_SESSION['rent_'.$this->objects_type.'_pager']['nb_per_page']; } if(count($pager)){ foreach ($pager as $key => $val){ $this->pager[$key]=$val; } } } /** * Ajout d'un tri */ protected function add_applied_sort($by, $asc_desc='asc') { if(empty($this->applied_sort)) { $this->applied_sort = array(); } array_push($this->applied_sort, array('by' => $by, 'asc_desc' => $asc_desc)); } /** * Initialisation du tri appliqué */ public function init_applied_sort($applied_sort=array()) { $this->add_applied_sort('id', 'desc'); if(isset($_SESSION['rent_'.$this->objects_type.'_applied_sort'][0]['by'])) { $this->applied_sort[0]['by'] = $_SESSION['rent_'.$this->objects_type.'_applied_sort'][0]['by']; if(isset($_SESSION['rent_'.$this->objects_type.'_applied_sort'][0]['asc_desc'])) { $this->applied_sort[0]['asc_desc'] = $_SESSION['rent_'.$this->objects_type.'_applied_sort'][0]['asc_desc']; } else { $this->applied_sort[0]['asc_desc'] = 'asc'; } } if(count($applied_sort)){ foreach ($applied_sort as $key => $val){ if(is_array($val)) { $this->applied_sort[$key] = $val; } else { $this->applied_sort[0][$key]=$val; } } } //Sauvegarde du tri appliqué en session $this->set_applied_sort_in_session(); } /** * Filtres provenant du formulaire */ public function set_filters_from_form() { } /** * Pagination provenant du formulaire */ public function set_pager_from_form() { $page = $this->objects_type.'_page'; global ${$page}; $nb_per_page = $this->objects_type.'_nb_per_page'; global ${$nb_per_page}; if(${$page}*1) { $this->pager['page'] = ${$page}*1; } if(${$nb_per_page}*1) { $this->pager['nb_per_page'] = ${$nb_per_page}*1; } //Sauvegarde de la pagination en session $this->set_pager_in_session(); } /** * Affichage du formulaire de recherche */ public function get_search_form() { return ""; } /** * Filtre SQL */ protected function _get_query_filters() { return ''; } /** * Limit SQL */ protected function _get_query_pager() { $limit_query = ''; $this->set_pager_from_form(); $limit_query .= ' limit '.(($this->pager['page']-1)*$this->pager['nb_per_page']).', '.$this->pager['nb_per_page']; return $limit_query; } protected function intcmp($a,$b) { if((int)$a == (int)$b)return 0; else if((int)$a > (int)$b)return 1; else if((int)$a < (int)$b)return -1; } /** * Fonction de callback * @param $a * @param $b */ protected function _compare_objects($a, $b) { } /** * Tri des objets */ protected function _sort() { if($this->applied_sort[0]['asc_desc'] == 'desc') { usort($this->objects, array($this, "_compare_objects")); $this->objects= array_reverse($this->objects); } else { usort($this->objects, array($this, "_compare_objects")); } } /** * Limite des demandes */ protected function _limit() { $this->set_pager_from_form(); $this->objects = array_slice( $this->objects, ($this->pager['page']-1)*$this->pager['nb_per_page'], $this->pager['nb_per_page']); } /** * Liste des objets */ public function get_display_content_list() { return ''; } /** * Construction dynamique des cellules du header * @param string $name */ protected function _get_cell_header($name) { return ''; } /** * Header de la liste */ public function get_display_header_list() { return ''; } /** * Affiche la recherche + la liste des demandes */ public function get_display_list() { return ''; } protected function pager() { global $msg; if (!$this->pager['nb_results']) return; $this->pager['nb_page']=ceil($this->pager['nb_results']/$this->pager['nb_per_page']); $suivante = $this->pager['page']+1; $precedente = $this->pager['page']-1; $nav_bar = ''; // affichage du lien précédent si nécéssaire if($precedente > 0) { $nav_bar .= "objects_type."_search_form.".$this->objects_type."_page.value=".$precedente."; document.".$this->objects_type."_search_form.submit(); return false;\">"; } $deb = $this->pager['page'] - 10 ; if ($deb<1) $deb=1; for($i = $deb; ($i <= $this->pager['nb_page']) && ($i <= $this->pager['page']+10); $i++) { if($i==$this->pager['page']) $nav_bar .= "".$i.""; else $nav_bar .= "objects_type."_search_form.".$this->objects_type."_page.value=".$i."; document.".$this->objects_type."_search_form.submit(); return false;\">".$i.""; if($i<$this->pager['nb_page']) $nav_bar .= " "; } if($suivante <= $this->pager['nb_page']) { $nav_bar .= "objects_type."_search_form.".$this->objects_type."_page.value=".$suivante."; document.".$this->objects_type."_search_form.submit(); return false;\">"; } if($this->pager['nb_page'] && ($this->pager['nb_results'] > $this->pager['nb_per_page'])) { $nav_bar .= " | ".$msg['per_page']." "; $nav_bar .= "objects_type."_search_form.".$this->objects_type."_page.value=1;document.".$this->objects_type."_search_form.".$this->objects_type."_nb_per_page.value=25; document.".$this->objects_type."_search_form.submit(); return false;\"> 25 "; $nav_bar .= "objects_type."_search_form.".$this->objects_type."_page.value=1;document.".$this->objects_type."_search_form.".$this->objects_type."_nb_per_page.value=50; document.".$this->objects_type."_search_form.submit(); return false;\"> 50 "; $nav_bar .= "objects_type."_search_form.".$this->objects_type."_page.value=1;document.".$this->objects_type."_search_form.".$this->objects_type."_nb_per_page.value=100; document.".$this->objects_type."_search_form.submit(); return false;\"> 100 "; } // affichage de la barre de navigation return "