total = (int) $total; $this->limitstart = (int) max( $limitstart, 0 ); $this->limit = (int) max( $limit, 1 ); if ($this->limit > $this->total) { $this->limitstart = 0; } if (($this->limit-1)*$this->limitstart > $this->total) { $this->limitstart -= $this->limitstart % $this->limit; } if ( $fieldNamingMethod ) { $this->_fieldNameFnct = $fieldNamingMethod; } else { $this->_fieldNameFnct = array( &$this, '_defaultFieldNameFnct' ); } } function _defaultFieldNameFnct( $name ) { return $name; } function _fieldName( $name ) { return call_user_func( $this->_fieldNameFnct, $name ); } /** * transforms a well-formed nested array : a[b[c[x]]] -> a['b']['c']['x'] (x optional) * * @param string $str * @return string */ function _unnestArray( $str ) { if ( substr( $str, -1, 1 ) == ']' ) { $res = strtok( $str, '[]' ); while ( false !== ( $token = strtok( '[]' ) ) ) { $res .= "['" . $token . "']"; } if ( strpos( $str, '[]' ) !== false ) { $res .= '[]'; } } else { $res = $str; } return $res; } function js_limitstart( $value ) { return "cbParentForm(this)." . "elements['".$this->_fieldName('limitstart') . "'].value=" . (int) $value . ";" . "cbParentForm(this).submit();return false;"; } /** * @return string The html for the limit # input box */ function getLimitBox ( $showLimitBox = true ) { if ( $showLimitBox ) { $limits = array(); foreach ( array(1,2,3,5,10,15,20,30,50,100) as $i ) { $limits[] = moscomprofilerHTML::makeOption( "$i" ); } // build the html select list $html = moscomprofilerHTML::selectList( $limits, $this->_fieldName( 'limit' ), 'class="inputbox" size="1" onchange="' . $this->js_limitstart(0) . '"', 'value', 'text', $this->limit, 2 ); } else { $html = "\n_fieldName( 'limit' ) . "\" value=\"$this->limit\" />"; } $html .= "\n_fieldName( 'limitstart' ) . "\" value=\"$this->limitstart\" />"; return $html; } /** * Writes the html limit # input box */ function writeLimitBox () { echo $this->getLimitBox(); } /** * Returns html for the pages counter, eg, Results 1-10 of x * @return string HTML */ function writePagesCounter() { echo $this->getPagesCounter(); } /** * @return string The html for the pages counter, eg, Results 1-10 of x */ function getPagesCounter() { $html = ''; $from_result = $this->limitstart+1; if ( $this->limitstart + $this->limit < $this->total ) { $to_result = $this->limitstart + $this->limit; } else { $to_result = $this->total; } if ($this->total > 0) { $html .= "\n" . _UE_RESULTS . " " . $from_result . " - " . $to_result . " " . _UE_OF_TOTAL . " " . $this->total . ""; } else { $html .= "\n" . _UE_NO_RESULTS . "."; } return $html; } /** * Writes the html for the pages counter, eg, Results 1-10 of x */ function writePagesLinks() { echo $this->getPagesLinks(); } /** * @return string The html links for pages, eg, previous, next, 1 2 3 ... x */ function getPagesLinks() { $limitstart = max( (int) $this->limitstart, 0 ); $limit = max( (int) $this->limit, 1 ); $total = (int) $this->total; $html = ''; $displayed_pages = 10; // set how many pages you want displayed in the menu (not including first&last, and ev. ... repl by single page number. $total_pages = ceil( $total / $limit ); $this_page = ceil( ($limitstart+1) / $limit ); // $start_loop = (floor(($this_page-1)/$displayed_pages))*$displayed_pages+1; $start_loop = $this_page-floor($displayed_pages/2); if ($start_loop < 1) { $start_loop = 1; } if ($start_loop == 3) { $start_loop = 2; } if ( $start_loop + $displayed_pages - 1 < $total_pages - 2 ) { $stop_loop = $start_loop + $displayed_pages - 1; } else { $stop_loop = $total_pages; } if ($this_page > 1) { $page = ($this_page - 2) * $this->limit; $html .= "\njs_limitstart(0) . "\"><< " . _UE_FIRST_PAGE . ""; $html .= "\njs_limitstart( $page ) . "\">< " . _UE_PREV_PAGE . ""; if ($start_loop > 1) { $html .= "\njs_limitstart(0) . "\"> 1"; } if ($start_loop > 2) { $html .= "\n ... "; } } else { $html .= "\n<< " . _UE_FIRST_PAGE . ""; $html .= "\n< " . _UE_PREV_PAGE . ""; } for ($i=$start_loop; $i <= $stop_loop; $i++) { $page = ($i - 1) * $this->limit; if ($i == $this_page) { $html .= "\n $i "; } else { $html .= "\njs_limitstart( $page ) . "\">$i"; } } if ($this_page < $total_pages) { $page = $this_page * $this->limit; $end_page = ($total_pages-1) * $this->limit; if ($stop_loop < $total_pages-1) { $html .= "\n ... "; } if ($stop_loop < $total_pages) { $html .= "\njs_limitstart( $end_page ) . "\"> " . $total_pages.""; } $html .= "\njs_limitstart( $page ) . "\"> " . _UE_NEXT_PAGE . " >"; $html .= "\njs_limitstart( $end_page ) . "\"> " . _UE_END_PAGE . " >>"; } else { $html .= "\nNext >"; $html .= "\nEnd >>"; } return $html; } /* function OLDgetListFooter( $showPageLinks = true, $showLimitBox = true, $showPagesCount = true ) { $html = ''; if ( $showPageLinks ) { $html .= ''; if ( $showPagesCount && ! $showLimitBox ) { $html .= ''; } $cols = ( $showLimitBox ? 3 : ( $showPagesCount ? 2 : 3 ) ); $html .= ''; } if ( $showLimitBox ) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
'; $html .= $this->getPagesCounter(); $html .= ''; $html .= $this->getPagesLinks(); if ( ! $showLimitBox ) { $html .= $this->getLimitBox( $showLimitBox ); } $html .= '
Display #' . $this->getLimitBox() . ''; if ( $showPagesCount ) { $html .= $this->getPagesCounter(); } $html .= '
'; return $html; } */ function getListFooter( $showPageLinks = true, $showLimitBox = true, $showPagesCount = true ) { $html = '
'; if ( $showLimitBox ) { $html .= 'Display # '; } $html .= $this->getLimitBox( $showLimitBox ); if ( $showLimitBox ) { $html .= ''; } if ( $showPageLinks ) { $html .= ''; $html .= $this->getPagesLinks(); $html .= ''; } if ( $showPagesCount ) { $html .= ''; $html .= $this->getPagesCounter(); $html .= ''; } $html .= '
'; return $html; } /** * @param int The row index * @return int */ function rowNumber( $i ) { return $i + 1 + $this->limitstart; } /** * @param int The row index * @param string The task to fire * @param string The alt text for the icon * @return string */ function orderUpIcon( $i=null, $condition=true, $task='orderup', $alt="Move Up" ) { if ( $i === null ) { $i = $this->_i; } if ( ( $i > 0 || ( $i+$this->limitstart > 0 ) ) && $condition ) { return "_controllerView->taskName( false ). "','" . $this->_controllerView->subtaskName( false ). "','" . $this->_controllerView->subtaskValue( $task, false ) . "', '" . $this->_controllerView->fieldId( 'id', null, false ) . "', " . $i . ')" title="'.$alt.'">' . ''.$alt.'' . ''; } else { return ' '; } } /** * @param int The row index * @param int The number of items in the list * @param string The task to fire * @param string The alt text for the icon * @return string */ function orderDownIcon( $i=null, $n=null, $condition=true, $task='orderdown', $alt="Move Down" ) { if ( $i === null ) { $i = $this->_i; } if ( $n === null ) { $n = $this->_n; } if ( ( $i < $n-1 || $i+$this->limitstart < $this->total-1 ) && $condition ) { return "_controllerView->taskName( false ). "','" . $this->_controllerView->subtaskName( false ). "','" . $this->_controllerView->subtaskValue( $task, false ) . "', '" . $this->_controllerView->fieldId( 'id', null, false ) . "', " . $i . ')" title="'.$alt.'">' . ''.$alt.'' . ''; } else { return ' '; } } /** * @param string $value The current value * @param boolean $toggling if it's toggling or just displaying icon * @param int $i The row index * @return string */ function publishedToggle( $name, $value, $toggling, $i=null ) { global $_CB_framework; if ( $i === null ) { $i = $this->_i; } $imgpath = $_CB_framework->getCfg( 'live_site' ) . '/components/com_comprofiler/images/'; $img = $value ? 'publish_g.png' : 'publish_x.png'; $task = $value ? 'unpublish/' . $name : 'publish/' . $name; $alt = $value ? 'Published' : 'Unpublished'; $action = $value ? 'Unpublish Item' : 'Publish item'; $html = ''; if ( $toggling ) { $html .= '_controllerView->taskName( false ). "','" // task . $this->_controllerView->subtaskName( false ). "','" // subtaskName . $this->_controllerView->subtaskValue( $task, false ) . "', '" // subtaskValue . $this->_controllerView->fieldId( 'id', null, false ) . "', " // fldName . $i // id . ")\" title=\"". $action .'">'; } $html .= ''. $alt . ''; if ( $toggling ) { $html .= ''; } return $html; } /** * @param string $name The field name (task to fire: enable_fieldname / disable_fieldname) * @param string $value The current value * @param boolean $toggling if it's toggling or just displaying icon * @param int $i The row index * @return string */ function checkMarkToggle( $name, $value, $toggling, $i=null ) { global $_CB_framework; if ( $i === null ) { $i = $this->_i; } $imgpath = $_CB_framework->getCfg( 'live_site' ) . '/components/com_comprofiler/images/'; $img = $value ? 'tick.png' : 'publish_x.png'; $task = $value ? 'disable/' . $name : 'enable/' . $name; $alt = $value ? 'Yes' : 'No'; $action = $value ? 'Disable Item' : 'Enable item'; $html = ''; if ( $toggling ) { $html .= '_controllerView->taskName( false ). "','" // task . $this->_controllerView->subtaskName( false ). "','" // subtaskName . $this->_controllerView->subtaskValue( $task, false ) . "', '" // subtaskValue . $this->_controllerView->fieldId( 'id', null, false ) . "', " // fldName . $i // id . ")\" title=\"". $action .'">'; } $html .= ''. $alt . ''; if ( $toggling ) { $html .= ''; } return $html; } /** * Set Current index of row during display for ordering icons feature * * @param cbDrawController $controllerView */ function setControllerView( &$controllerView ) { $this->_controllerView =& $controllerView; } /** * Set Number of rows displayed on the page * * @param int $n */ function setN( $n ) { $this->_n = $n; } /** * Set Current index of row during display for ordering icons feature * * @param unknown_type $i */ function setI( $i ) { $this->_i = $i; } //TBD: //FIXME pagination methods below are not yet adapted to CB: /** * @param int The row index * @param string The task to fire * @param string The alt text for the icon * @return string */ function orderUpIcon2( $id, $order, $condition=true, $task='orderup', $alt='#' ) { // handling of default value if ($alt == '#') { $alt = 'Move Up'; } if ($order == 0) { $img = 'uparrow0.png'; $show = true; } else if ($order < 0) { $img = 'uparrow-1.png'; $show = true; } else { $img = 'uparrow.png'; $show = true; }; if ($show) { $output = ''; $output .= ''. $alt .''; return $output; } else { return ' '; } } /** * @param int The row index * @param int The number of items in the list * @param string The task to fire * @param string The alt text for the icon * @return string */ function orderDownIcon2( $id, $order, $condition=true, $task='orderdown', $alt='#' ) { // handling of default value if ($alt == '#') { $alt = 'Move Down'; } if ($order == 0) { $img = 'downarrow0.png'; $show = true; } else if ($order < 0) { $img = 'downarrow-1.png'; $show = true; } else { $img = 'downarrow.png'; $show = true; }; if ($show) { $output = ''; $output .= ''. $alt .''; return $output; } else { return ' '; } } /** * Sets the vars for the page navigation template */ function setTemplateVars( &$tmpl, $name = 'admin-list-footer' ) { $tmpl->addVar( $name, 'PAGE_LINKS', $this->getPagesLinks() ); $tmpl->addVar( $name, 'PAGE_LIST_OPTIONS', $this->getLimitBox() ); $tmpl->addVar( $name, 'PAGE_COUNTER', $this->getPagesCounter() ); } } ?>