Changeset 678
- Timestamp:
- 12/05/07 22:19:57 (1 year ago)
- Files:
-
- trunk/lib/jelix/CREDITS (modified) (1 diff)
- trunk/lib/jelix/CREDITS (modified) (1 diff)
- trunk/lib/jelix/plugins/tpl/html/function.pagelinks.php (modified) (2 diffs)
- trunk/lib/jelix/plugins/tpl/html/function.pagelinks.php (modified) (2 diffs)
- trunk/testapp/www/design/screen.css (modified) (1 diff)
- trunk/testapp/www/design/screen.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jelix/CREDITS
r675 r678 92 92 - bug fixes on PDO support in jDb 93 93 94 Christian Tritten 95 - improvements on paglinks plugin (#340) 96 94 97 Yann 95 98 - improvements in jResponseHtml (description and keywords) trunk/lib/jelix/CREDITS
r675 r678 92 92 - bug fixes on PDO support in jDb 93 93 94 Christian Tritten 95 - improvements on paglinks plugin (#340) 96 94 97 Yann 95 98 - improvements in jResponseHtml (description and keywords) trunk/lib/jelix/plugins/tpl/html/function.pagelinks.php
r570 r678 5 5 * @author Jouanneau Laurent 6 6 * @copyright 2007 Jouanneau laurent 7 * @contributor Christian Tritten (christian.tritten@laposte.net) 8 * @copyright 2007 Christian Tritten 7 9 * @link http://www.jelix.org 8 10 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 19 21 * @param integer $offset index of the first item to display 20 22 * @param string $paramName name of the parameter in the actionParams which will content a page offset 21 */ 22 function jtpl_function_html_pagelinks($tpl, $action, $actionParams, $itemsTotal, $offset, $pageSize=15, $paramName='offset' ) 23 * @param array $displayProperties properties for the links display 24 * */ 25 function jtpl_function_html_pagelinks($tpl, $action, $actionParams, $itemsTotal, $offset, $pageSize = 15, 26 $paramName = 'offset', $displayProperties = array()) 23 27 { 24 $offset =intval($offset);25 if ($offset<=0)26 $offset =0;28 $offset = intval($offset); 29 if ($offset <= 0) 30 $offset = 0; 27 31 28 $itemsTotal =intval($itemsTotal);32 $itemsTotal = intval($itemsTotal); 29 33 30 $pageSize =intval($pageSize);31 if ($pageSize <1)32 $pageSize =1;34 $pageSize = intval($pageSize); 35 if ($pageSize < 1) 36 $pageSize = 1; 33 37 34 $urlaction = jUrl::get($action, $actionParams, jUrl::JURLACTION); 38 // If there are at least two pages of results 39 if ($itemsTotal > $pageSize) { 40 $jUrlEngine = jUrl::getEngine(); 35 41 36 $pages = array(); // tableau des indices de toutes les pages42 $urlaction = jUrl::get($action, $actionParams, jUrl::JURLACTION); 37 43 38 $current_page=1; 39 $pages[1]=0; 44 $defaultDisplayProperties = array('start-label' => '|<', 45 'prev-label' => '<', 46 'next-label' => '>', 47 'end-label' => '>|', 48 'area-size' => 0); 40 49 41 $numpage=1; 42 //$nextpage=0; 43 //$prevpage=0; 50 if (is_array($displayProperties) && count($displayProperties) > 0) 51 $displayProperties = array_merge($defaultDisplayProperties, $displayProperties); 52 else 53 $displayProperties = $defaultDisplayProperties; 44 54 45 // generates list of page offsets 46 for($curidx = 0; $curidx < $itemsTotal; $curidx += $pageSize){ 47 if( $offset >= $curidx && $offset < $curidx + $pageSize){ 48 //$current_page=$numpage; 49 //$nextpage=$numpage+1; 50 //$prevpage=$numpage-1; 51 echo ' <strong>'.$numpage.'</strong>'; 52 }else{ 53 $urlaction->params[$paramName] = $curidx; 54 $url = jUrl::getEngine()->create($urlaction); 55 echo ' <a href="'.$url->toString(true).'">'.$numpage.'</a>'; 56 //$pages[$numpage++]=$curidx; 55 $pages = array(); 56 57 $currentPage = 1; 58 59 $numpage = 1; 60 61 $prevBound = 0; 62 63 $nextBound = 0; 64 65 // Generates list of page offsets 66 for($curidx = 0; $curidx < $itemsTotal; $curidx += $pageSize) { 67 if($offset >= $curidx && $offset < $curidx + $pageSize) { 68 $pages[$numpage] = '<li class="pagelinks-current">'.$numpage.'</li>'; 69 $prevBound = $curidx - $pageSize; 70 $nextBound = $curidx + $pageSize; 71 $currentPage = $numpage; 72 } else { 73 $urlaction->params[$paramName] = $curidx; 74 $url = $jUrlEngine->create($urlaction); 75 $pages[$numpage] = '<li><a href="'.$url->toString(true).'">'.$numpage.'</a></li>'; 76 } 77 $numpage++; 57 78 } 58 $numpage++; 79 80 // Calculate start page url 81 $urlaction->params[$paramName] = 0; 82 $urlStartPage = $jUrlEngine->create($urlaction); 83 84 // Calculate previous page url 85 $urlaction->params[$paramName] = $prevBound; 86 $urlPrevPage = $jUrlEngine->create($urlaction); 87 88 // Calculate next page url 89 $urlaction->params[$paramName] = $nextBound; 90 $urlNextPage = $jUrlEngine->create($urlaction); 91 92 // Calculate end page url 93 $urlaction->params[$paramName] = (count($pages) - 1) * $pageSize; 94 $urlEndPage = $jUrlEngine->create($urlaction); 95 96 97 // Links display 98 echo '<ul class="pagelinks">'; 99 100 // Start link 101 if (!empty($displayProperties['start-label'])) { 102 echo '<li class="pagelinks-start'; 103 if ($prevBound >= 0) { 104 echo '"><a href="', $urlStartPage->toString(true), '">', $displayProperties['start-label'], '</a>'; 105 } else { 106 echo ' pagelinks-disabled">',$displayProperties['start-label'] ; 107 } 108 echo '</li>', "\n"; 109 } 110 111 // Previous link 112 if (!empty($displayProperties['prev-label'])) { 113 echo '<li class="pagelinks-prev'; 114 if ($prevBound >= 0) { 115 echo '"><a href="', $urlPrevPage->toString(true), '">', $displayProperties['prev-label'], '</a>'; 116 } else { 117 echo ' pagelinks-disabled">',$displayProperties['prev-label'] ; 118 } 119 echo '</li>', "\n"; 120 } 121 122 // Pages links 123 foreach ($pages as $key => $page) { 124 if ($displayProperties['area-size'] == 0 || ($currentPage - $displayProperties['area-size'] <= $key) 125 && ($currentPage + $displayProperties['area-size'] >= $key)) 126 echo $page, "\n"; 127 } 128 129 // Next link 130 if (!empty($displayProperties['next-label'])) { 131 echo '<li class="pagelinks-next'; 132 if ($nextBound <= $itemsTotal) { 133 echo '"><a href="', $urlNextPage->toString(true), '">', $displayProperties['next-label'], '</a>'; 134 } else { 135 echo ' pagelinks-disabled">',$displayProperties['next-label'] ; 136 } 137 echo '</li>', "\n"; 138 } 139 140 // End link 141 if (!empty($displayProperties['end-label'])) { 142 echo '<li class="pagelinks-end'; 143 if ($nextBound <= $itemsTotal) { 144 echo '"><a href="', $urlEndPage->toString(true), '">', $displayProperties['end-label'], '</a>'; 145 } else { 146 echo ' pagelinks-disabled">',$displayProperties['end-label'] ; 147 } 148 echo '</li>', "\n"; 149 } 150 151 echo '</ul>'; 59 152 } 60 61 /*62 if(isset($pages[$nextpage]))63 $next_page_idx = $pages[$nextpage];64 else65 $next_page_idx = -1;66 67 if($current_page > 1)68 $prev_page_idx = $offset - $page_size;69 else70 $prev_page_idx = -1;71 */72 153 } 73 154 trunk/lib/jelix/plugins/tpl/html/function.pagelinks.php
r570 r678 5 5 * @author Jouanneau Laurent 6 6 * @copyright 2007 Jouanneau laurent 7 * @contributor Christian Tritten (christian.tritten@laposte.net) 8 * @copyright 2007 Christian Tritten 7 9 * @link http://www.jelix.org 8 10 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 19 21 * @param integer $offset index of the first item to display 20 22 * @param string $paramName name of the parameter in the actionParams which will content a page offset 21 */ 22 function jtpl_function_html_pagelinks($tpl, $action, $actionParams, $itemsTotal, $offset, $pageSize=15, $paramName='offset' ) 23 * @param array $displayProperties properties for the links display 24 * */ 25 function jtpl_function_html_pagelinks($tpl, $action, $actionParams, $itemsTotal, $offset, $pageSize = 15, 26 $paramName = 'offset', $displayProperties = array()) 23 27 { 24 $offset =intval($offset);25 if ($offset<=0)26 $offset =0;28 $offset = intval($offset); 29 if ($offset <= 0) 30 $offset = 0; 27 31 28 $itemsTotal =intval($itemsTotal);32 $itemsTotal = intval($itemsTotal); 29 33 30 $pageSize =intval($pageSize);31 if ($pageSize <1)32 $pageSize =1;34 $pageSize = intval($pageSize); 35 if ($pageSize < 1) 36 $pageSize = 1; 33 37 34 $urlaction = jUrl::get($action, $actionParams, jUrl::JURLACTION); 38 // If there are at least two pages of results 39 if ($itemsTotal > $pageSize) { 40 $jUrlEngine = jUrl::getEngine(); 35 41 36 $pages = array(); // tableau des indices de toutes les pages42 $urlaction = jUrl::get($action, $actionParams, jUrl::JURLACTION); 37 43 38 $current_page=1; 39 $pages[1]=0; 44 $defaultDisplayProperties = array('start-label' => '|<', 45 'prev-label' => '<', 46 'next-label' => '>', 47 'end-label' => '>|', 48 'area-size' => 0); 40 49 41 $numpage=1; 42 //$nextpage=0; 43 //$prevpage=0; 50 if (is_array($displayProperties) && count($displayProperties) > 0) 51 $displayProperties = array_merge($defaultDisplayProperties, $displayProperties); 52 else 53 $displayProperties = $defaultDisplayProperties; 44 54 45 // generates list of page offsets 46 for($curidx = 0; $curidx < $itemsTotal; $curidx += $pageSize){ 47 if( $offset >= $curidx && $offset < $curidx + $pageSize){ 48 //$current_page=$numpage; 49 //$nextpage=$numpage+1; 50 //$prevpage=$numpage-1; 51 echo ' <strong>'.$numpage.'</strong>'; 52 }else{ 53 $urlaction->params[$paramName] = $curidx; 54 $url = jUrl::getEngine()->create($urlaction); 55 echo ' <a href="'.$url->toString(true).'">'.$numpage.'</a>'; 56 //$pages[$numpage++]=$curidx; 55 $pages = array(); 56 57 $currentPage = 1; 58 59 $numpage = 1; 60 61 $prevBound = 0; 62 63 $nextBound = 0; 64 65 // Generates list of page offsets 66 for($curidx = 0; $curidx < $itemsTotal; $curidx += $pageSize) { 67 if($offset >= $curidx && $offset < $curidx + $pageSize) { 68 $pages[$numpage] = '<li class="pagelinks-current">'.$numpage.'</li>'; 69 $prevBound = $curidx - $pageSize; 70 $nextBound = $curidx + $pageSize; 71 $currentPage = $numpage; 72 } else { 73 $urlaction->params[$paramName] = $curidx; 74 $url = $jUrlEngine->create($urlaction); 75 $pages[$numpage] = '<li><a href="'.$url->toString(true).'">'.$numpage.'</a></li>'; 76 } 77 $numpage++; 57 78 } 58 $numpage++; 79 80 // Calculate start page url 81 $urlaction->params[$paramName] = 0; 82 $urlStartPage = $jUrlEngine->create($urlaction); 83 84 // Calculate previous page url 85 $urlaction->params[$paramName] = $prevBound; 86 $urlPrevPage = $jUrlEngine->create($urlaction); 87 88 // Calculate next page url 89 $urlaction->params[$paramName] = $nextBound; 90 $urlNextPage = $jUrlEngine->create($urlaction); 91 92 // Calculate end page url 93 $urlaction->params[$paramName] = (count($pages) - 1) * $pageSize; 94 $urlEndPage = $jUrlEngine->create($urlaction); 95 96 97 // Links display 98 echo '<ul class="pagelinks">'; 99 100 // Start link 101 if (!empty($displayProperties['start-label'])) { 102 echo '<li class="pagelinks-start'; 103 if ($prevBound >= 0) { 104 echo '"><a href="', $urlStartPage->toString(true), '">', $displayProperties['start-label'], '</a>'; 105 } else { 106 echo ' pagelinks-disabled">',$displayProperties['start-label'] ; 107 } 108 echo '</li>', "\n"; 109 } 110 111 // Previous link 112 if (!empty($displayProperties['prev-label'])) { 113 echo '<li class="pagelinks-prev'; 114 if ($prevBound >= 0) { 115 echo '"><a href="', $urlPrevPage->toString(true), '">', $displayProperties['prev-label'], '</a>'; 116 } else { 117 echo ' pagelinks-disabled">',$displayProperties['prev-label'] ; 118 } 119 echo '</li>', "\n"; 120 } 121 122 // Pages links 123 foreach ($pages as $key => $page) { 124 if ($displayProperties['area-size'] == 0 || ($currentPage - $displayProperties['area-size'] <= $key) 125 && ($currentPage + $displayProperties['area-size'] >= $key)) 126 echo $page, "\n"; 127 } 128 129 // Next link 130 if (!empty($displayProperties['next-label'])) { 131 echo '<li class="pagelinks-next'; 132 if ($nextBound <= $itemsTotal) { 133 echo '"><a href="', $urlNextPage->toString(true), '">', $displayProperties['next-label'], '</a>'; 134 } else { 135 echo ' pagelinks-disabled">',$displayProperties['next-label'] ; 136 } 137 echo '</li>', "\n"; 138 } 139 140 // End link 141 if (!empty($displayProperties['end-label'])) { 142 echo '<li class="pagelinks-end'; 143 if ($nextBound <= $itemsTotal) { 144 echo '"><a href="', $urlEndPage->toString(true), '">', $displayProperties['end-label'], '</a>'; 145 } else { 146 echo ' pagelinks-disabled">',$displayProperties['end-label'] ; 147 } 148 echo '</li>', "\n"; 149 } 150 151 echo '</ul>'; 59 152 } 60 61 /*62 if(isset($pages[$nextpage]))63 $next_page_idx = $pages[$nextpage];64 else65 $next_page_idx = -1;66 67 if($current_page > 1)68 $prev_page_idx = $offset - $page_size;69 else70 $prev_page_idx = -1;71 */72 153 } 73 154 trunk/testapp/www/design/screen.css
r380 r678 88 88 .diff ins { background: #9f9; } 89 89 90 90 .pagelinks li { display:inline; border:1px solid gray; padding:4px; color:black; } 91 .pagelinks li.pagelinks-disabled { color: gray;} 92 .pagelinks li.pagelinks-current { font-weight:bold;} 93 .pagelinks li a:hover, .pagelinks li:hover { background-color:#eee; } 91 94 92 95 #sidemenu { trunk/testapp/www/design/screen.css
r380 r678 88 88 .diff ins { background: #9f9; } 89 89 90 90 .pagelinks li { display:inline; border:1px solid gray; padding:4px; color:black; } 91 .pagelinks li.pagelinks-disabled { color: gray;} 92 .pagelinks li.pagelinks-current { font-weight:bold;} 93 .pagelinks li a:hover, .pagelinks li:hover { background-color:#eee; } 91 94 92 95 #sidemenu {
