id = $SLframework_id_table ; $this->title = array() ; $this->order = $order ; $this->nbLigneTotal = $nb_all_Items ; $this->nbLignePerPage = $nb_max_per_page ; $this->hasFooter = true ; $this->search = $search ; $this->searchWords = "" ; $this->content = array() ; } /** ==================================================================================================================================================== * Set the titles of the columns * * @param array $array it is an array of string which is of the size of the number of columns. Each string is the title for a different column * @return void */ function title($array) { $this->title = $array ; } /** ==================================================================================================================================================== * Get the current page of the table. * This is relevant if the number of your items is greater than the number of lines * * @return integer the page number */ function current_page() { if (isset($_GET['paged_'.$this->id])) { $page_cur = preg_replace("/[^0-9]/", "", $_GET['paged_'.$this->id]) ; } else { $page_cur = 1 ; } return $page_cur ; } /** ==================================================================================================================================================== * Set the number of items (all). * * @return void */ function set_nb_all_Items($nb) { $this->nbLigneTotal = $nb ; } /** ==================================================================================================================================================== * Get the currentfilter of the table. * * @return string the filter */ function current_filter() { if (isset($_GET['filter_'.$this->id])) { $page_filter = trim(preg_replace("#(\xBB|\xAB|!|\xA1|%|,|:|;|\(|\)|\&|\"|\'|\.|-|\/|\?|\\\)#", " ", $_GET['filter_'.$this->id])) ; while ($page_filter != str_replace(" ", " ", $page_filter)) { $page_filter = str_replace(" ", " ", $page_filter) ; } } else { $page_filter = "" ; } return $page_filter ; } /** ==================================================================================================================================================== * Get the current column order of the table. * * @return integer the column number */ function current_ordercolumn() { if (isset($_GET['ordercol_'.$this->id])) { $col_cur = preg_replace("/[^0-9]/", "", $_GET['ordercol_'.$this->id]) ; } else { $col_cur = 1 ; } return $col_cur ; } /** ==================================================================================================================================================== * Get the current column direction of the table. * * @return string the column direction "ASC" or "DESC" */ function current_orderdir() { if (isset($_GET['orderdir_'.$this->id])) { $dir_cur = $_GET['orderdir_'.$this->id] ; if ($dir_cur != "DESC") { $dir_cur = "ASC" ; } } else { $dir_cur = "ASC" ; } return $dir_cur ; } /** ==================================================================================================================================================== * Remove the showed title at the footer of the table * By default, titles of the columns are displayed at the top of the table and at its footer. * * @return void */ function removeFooter() { $this->hasFooter = false ; } /** ==================================================================================================================================================== * Add a line in your table * For instance * $table = new SLFramework_Table() ;
$table->title(array("Col1", "Col2", "Col3") ) ;
$cel1 = new adminCell("Cel1-1") ;
$cel2 = new adminCell("Cel1-2") ;
$cel3 = new adminCell("Cel1-3") ;
$table->add_line(array($cel1, $cel2, $cel3), '1') ;
echo $table->flush() ;
* This code will display a table with a unique line * * @param array $array it is an array of adminCell object. The length of this array is the same size of the number of your columns * @param id $id it is the id of this line. It is useful when you add an action on a cell * @see adminCell::adminCell * @see adminCell:add_action * @return void */ function add_line($array, $id) { $n = 1 ; foreach ($array as $a) { $a->idLigne= $id ; $a->idCol = $n ; $n++ ; } $this->content[] = $array ; } /** ==================================================================================================================================================== * Return the table HTML code. You just have to echo it * * @return string the HTML code of the table */ function flush() { ob_start() ; $get = $_GET; // // Est-ce que on affiche la zone de recherche // if ($this->search) { $filter = $this->current_filter() ; ?>
$v) { if (($k!="filter_".$this->id)&&($k!="paged_".$this->id)) { ?> id."' value=\"".$filter."\" size='30'>") ?>
nbLigneTotal>count($this->content)) { $page_cur = $this->current_page() ; $page_tot = ceil($this->nbLigneTotal/$this->nbLignePerPage) ; $page_inf = max(1,$page_cur-1) ; $page_sup= min($page_tot,$page_cur+1) ; ?>
title as $name) { if ($this->order) { if ($this->current_ordercolumn()==$i_col) { $name .= " " ; if ($this->current_orderdir()=="DESC") { $name .= "id => 'ASC', 'ordercol_'.$this->id => $i_col ) )."'>" ; $name .= "" ; } else { $name .= "" ; $name .= "id => 'DESC', 'ordercol_'.$this->id => $i_col ) )."'>" ; } } else { $name .= " " ; $name .= "id => 'ASC', 'ordercol_'.$this->id => $i_col ) )."'>" ; $name .= "id => 'DESC', 'ordercol_'.$this->id => $i_col ) )."'>" ; } } $i_col++ ; ?> hasFooter) { ?> title as $name) { ?> content as $line) { $ligne++ ; // on recupere le premier id de la ligne et on considere que c'est le meme partout $id = $line[0]->idLigne ; ?> flush() ; } ?>
content = $content ; $this->action = array() ; } /** ==================================================================================================================================================== * To add a javascript action on this cell. * An action a small link at the bottom of the cell which call a javascript action when it is clicked * For instance : * $cel1 = new adminCell("content cell") ;
$cel1->add_action("Delete", "deleteFunction") ;
*with the following javascript code in the js/js_admin.js file to call a PHP function (deletePHP) in AJAX *function deleteFunction (element) {
     // Get the id of the line
     var idLine = element.getAttribute("id");
     // Prepare the argument for the AJAX call
     var arguments = {
           action: 'deletePHP',
           id : idLine
     }
     //POST the data
     jQuery.post(ajaxurl, arguments, function(response) {
           // The call is finished
     });
}
* and do not forget to add a add_action('wp_ajax_deletePHP', array($this,'deletePHP')); in the _init function of your plugin * If the function is only a string with no parantehsis (i.e. the_function), thus the id of the line will be passed in argument * If the function is a function name with arguments (i.e. the_function(arg1, arg2)), thus this function will be called directly * * @param string $name the text of the link to be displayed * @param string $javascript_function the name of the function to be called when the link is clicked * @return adminCell the cell object */ function add_action($name, $javascript_function) { $this->action[] = array($name, $javascript_function) ; } /** ==================================================================================================================================================== * Print the cell HTML code. * This function is not to be called from the plugin. It is called in the table class * * @access private * @return void */ function flush() { ?> content ?> action)) { ?>
action as $l) { $num ++ ; if (strpos($l[1],"(")>0) { $l[1] = str_replace('"', '\'', $l[1]) ; ?> img/ajax-loader.gif' style='display:none;'>action)) { echo " |" ; }?> img/ajax-loader.gif' style='display:none;'>action)) { echo " |" ; }?>