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() ;
* 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() ;
?>
$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() ;
$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() {
?>