change amount for number

This commit is contained in:
Diego Najar 2018-08-06 21:46:58 +02:00
parent bb2023cb5b
commit 942f3c04cb
19 changed files with 82 additions and 78 deletions

View File

@ -47,7 +47,7 @@ class dbJSON {
return true; return true;
} }
// Returns the amount of rows in the database // Returns the number of rows in the database
public function count() public function count()
{ {
return count($this->db); return count($this->db);

View File

@ -34,7 +34,7 @@ class dbList extends dbJSON
} }
// Returns the list of keys filter by pageNumber // Returns the list of keys filter by pageNumber
public function getList($key, $pageNumber, $amountOfItems) public function getList($key, $pageNumber, $numberOfItems)
{ {
if (!isset($this->db[$key])) { if (!isset($this->db[$key])) {
Log::set(__METHOD__.LOG_SEP.'Error key does not exist '.$key); Log::set(__METHOD__.LOG_SEP.'Error key does not exist '.$key);
@ -45,7 +45,7 @@ class dbList extends dbJSON
$list = $this->db[$key]['list']; $list = $this->db[$key]['list'];
// Returns all the items from the list // Returns all the items from the list
if ($amountOfItems==-1) { if ($numberOfItems==-1) {
// Invert keys to values, is necesary returns as key the key pages // Invert keys to values, is necesary returns as key the key pages
$list = array_flip($list); $list = array_flip($list);
return $list; return $list;
@ -53,7 +53,7 @@ class dbList extends dbJSON
// The first page number is 1, so the real is 0 // The first page number is 1, so the real is 0
$realPageNumber = $pageNumber - 1; $realPageNumber = $pageNumber - 1;
$chunks = array_chunk($list, $amountOfItems); $chunks = array_chunk($list, $numberOfItems);
if (isset($chunks[$realPageNumber])) { if (isset($chunks[$realPageNumber])) {
return $chunks[$realPageNumber]; return $chunks[$realPageNumber];
} }

View File

@ -24,9 +24,9 @@ checkRole(array('admin', 'editor'));
// List of published pages // List of published pages
$onlyPublished = true; $onlyPublished = true;
$amountOfItems = ITEMS_PER_PAGE_ADMIN; $numberOfItems = ITEMS_PER_PAGE_ADMIN;
$pageNumber = $url->pageNumber(); $pageNumber = $url->pageNumber();
$published = $pages->getList($pageNumber, $amountOfItems, $onlyPublished); $published = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
// Check if out of range the pageNumber // Check if out of range the pageNumber
if (empty($published) && $url->pageNumber()>1) { if (empty($published) && $url->pageNumber()>1) {

View File

@ -9,7 +9,7 @@ if (!empty($listOfFilesByPage[0])) {
} }
} }
// Amount of pages for the paginator // Amount of pages for the paginator
$amountOfPages = count($listOfFilesByPage); $numberOfPages = count($listOfFilesByPage);
?> ?>
<div id="jsbluditMediaModal" class="modal fade" tabindex="-1" role="dialog"> <div id="jsbluditMediaModal" class="modal fade" tabindex="-1" role="dialog">
@ -53,7 +53,7 @@ $amountOfPages = count($listOfFilesByPage);
<!-- Paginator --> <!-- Paginator -->
<nav> <nav>
<ul class="pagination justify-content-center"> <ul class="pagination justify-content-center">
<?php for ($i=1; $i<=$amountOfPages; $i++): ?> <?php for ($i=1; $i<=$numberOfPages; $i++): ?>
<li class="page-item"><button type="button" class="btn btn-link page-link" onClick="getFiles(<?php echo $i ?>)"><?php echo $i ?></button></li> <li class="page-item"><button type="button" class="btn btn-link page-link" onClick="getFiles(<?php echo $i ?>)"><?php echo $i ?></button></li>
<?php endfor; ?> <?php endfor; ?>
</ul> </ul>

View File

@ -168,7 +168,7 @@ function table($type) {
<div class="tab-pane show active" id="pages" role="tabpanel"> <div class="tab-pane show active" id="pages" role="tabpanel">
<?php table('published'); ?> <?php table('published'); ?>
<?php if (Paginator::amountOfPages() > 1): ?> <?php if (Paginator::numberOfPages() > 1): ?>
<!-- Paginator --> <!-- Paginator -->
<nav class="paginator"> <nav class="paginator">
<ul class="pagination flex-wrap justify-content-center"> <ul class="pagination flex-wrap justify-content-center">

View File

@ -30,7 +30,7 @@ if (isset($listOfFilesByPage[$pageNumber])) {
array_push($tmp, basename($file)); array_push($tmp, basename($file));
} }
// Returns the amount of chunks for the paginator // Returns the number of chunks for the paginator
// Returns the files inside the chunk // Returns the files inside the chunk
exit (json_encode(array( exit (json_encode(array(
'status'=>0, 'status'=>0,

View File

@ -5,7 +5,7 @@
// ============================================================================ // ============================================================================
// Array with pages, each page is a Page Object // Array with pages, each page is a Page Object
// Filtered by pagenumber, amount of items per page and sorted by date/position // Filtered by pagenumber, number of items per page and sorted by date/position
/* /*
array( array(
0 => Page Object, 0 => Page Object,

View File

@ -6,35 +6,35 @@ Paginator::set('currentPage', $currentPage);
if($url->whereAmI()=='admin') { if($url->whereAmI()=='admin') {
$itemsPerPage = ITEMS_PER_PAGE_ADMIN; $itemsPerPage = ITEMS_PER_PAGE_ADMIN;
$amountOfItems = $pages->count(true); $numberOfItems = $pages->count(true);
} }
elseif($url->whereAmI()=='tag') { elseif($url->whereAmI()=='tag') {
$itemsPerPage = $site->itemsPerPage(); $itemsPerPage = $site->itemsPerPage();
$tagKey = $url->slug(); $tagKey = $url->slug();
$amountOfItems = $tags->numberOfPages($tagKey); $numberOfItems = $tags->numberOfPages($tagKey);
} }
elseif($url->whereAmI()=='category') { elseif($url->whereAmI()=='category') {
$itemsPerPage = $site->itemsPerPage(); $itemsPerPage = $site->itemsPerPage();
$categoryKey = $url->slug(); $categoryKey = $url->slug();
$amountOfItems = $categories->numberOfPages($categoryKey); $numberOfItems = $categories->numberOfPages($categoryKey);
} }
else { else {
$itemsPerPage = $site->itemsPerPage(); $itemsPerPage = $site->itemsPerPage();
$amountOfItems = $pages->count(true); $numberOfItems = $pages->count(true);
} }
// Items per page // Items per page
Paginator::set('itemsPerPage', $itemsPerPage); Paginator::set('itemsPerPage', $itemsPerPage);
// Amount of items // Amount of items
Paginator::set('amountOfItems', $amountOfItems); Paginator::set('numberOfItems', $numberOfItems);
// Amount of pages // Amount of pages
$amountOfPages = (int) max(ceil($amountOfItems / $itemsPerPage), 1); $numberOfPages = (int) max(ceil($numberOfItems / $itemsPerPage), 1);
Paginator::set('amountOfPages', $amountOfPages); Paginator::set('numberOfPages', $numberOfPages);
// TRUE if exists a next page to show // TRUE if exists a next page to show
$showNext = $amountOfPages > $currentPage; $showNext = $numberOfPages > $currentPage;
Paginator::set('showNext', $showNext); Paginator::set('showNext', $showNext);
// TRUE if exists a previous page to show // TRUE if exists a previous page to show
@ -50,5 +50,5 @@ $nextPage = max(0, $currentPage+1);
Paginator::set('nextPage', $nextPage); Paginator::set('nextPage', $nextPage);
// Integer with the previous page // Integer with the previous page
$prevPage = min($amountOfPages, $currentPage-1); $prevPage = min($numberOfPages, $currentPage-1);
Paginator::set('prevPage', $prevPage); Paginator::set('prevPage', $prevPage);

View File

@ -90,8 +90,8 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
if ($for=='home') { if ($for=='home') {
$onlyPublished = true; $onlyPublished = true;
$amountOfItems = $site->itemsPerPage(); $numberOfItems = $site->itemsPerPage();
$list = $pages->getList($pageNumber, $amountOfItems, $onlyPublished); $list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
// Include sticky pages only in the first page // Include sticky pages only in the first page
if ($pageNumber==1) { if ($pageNumber==1) {
@ -100,12 +100,12 @@ function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
} }
} }
elseif ($for=='category') { elseif ($for=='category') {
$amountOfItems = $site->itemsPerPage(); $numberOfItems = $site->itemsPerPage();
$list = $categories->getList($categoryKey, $pageNumber, $amountOfItems); $list = $categories->getList($categoryKey, $pageNumber, $numberOfItems);
} }
elseif ($for=='tag') { elseif ($for=='tag') {
$amountOfItems = $site->itemsPerPage(); $numberOfItems = $site->itemsPerPage();
$list = $tags->getList($tagKey, $pageNumber, $amountOfItems); $list = $tags->getList($tagKey, $pageNumber, $numberOfItems);
} }
// There are not items, invalid tag, invalid category, out of range, etc... // There are not items, invalid tag, invalid category, out of range, etc...

View File

@ -4,8 +4,8 @@ class Paginator {
public static $pager = array( public static $pager = array(
'itemsPerPage'=>0, 'itemsPerPage'=>0,
'amountOfPages'=>1, 'numberOfPages'=>1,
'amountOfItems'=>0, 'numberOfItems'=>0,
'firstPage'=>1, 'firstPage'=>1,
'nextPage'=>1, 'nextPage'=>1,
'prevPage'=>1, 'prevPage'=>1,
@ -25,9 +25,9 @@ class Paginator {
return self::$pager[$key]; return self::$pager[$key];
} }
public static function amountOfPages() public static function numberOfPages()
{ {
return self::get('amountOfPages'); return self::get('numberOfPages');
} }
public static function currentPage() public static function currentPage()
@ -69,7 +69,7 @@ class Paginator {
// Returns the absolute URL for the last page // Returns the absolute URL for the last page
public static function lastPageUrl() public static function lastPageUrl()
{ {
return self::numberUrl( self::amountOfPages() ); return self::numberUrl( self::numberOfPages() );
} }
// Returns the absolute URL for the next page // Returns the absolute URL for the next page
@ -148,7 +148,7 @@ class Paginator {
global $Language; global $Language;
$total_pages = self::amountOfPages(); $total_pages = self::numberOfPages();
$howMany = 2; $howMany = 2;
$currentPage = self::currentPage(); $currentPage = self::currentPage();
$first_page = self::firstPage(); $first_page = self::firstPage();

View File

@ -453,9 +453,9 @@ class Pages extends dbJSON {
// Returns an array with a list of key of pages, FALSE if out of range // Returns an array with a list of key of pages, FALSE if out of range
// The database is sorted by date or by position // The database is sorted by date or by position
// (int) $pageNumber, the page number // (int) $pageNumber, the page number
// (int) $amountOfItems, amount of items to return, if -1 returns all the items // (int) $numberOfItems, amount of items to return, if -1 returns all the items
// (boolean) $onlyPublished, TRUE to return only published pages // (boolean) $onlyPublished, TRUE to return only published pages
public function getList($pageNumber, $amountOfItems, $onlyPublished=true) public function getList($pageNumber, $numberOfItems, $onlyPublished=true)
{ {
$db = array_keys($this->db); $db = array_keys($this->db);
@ -463,7 +463,7 @@ class Pages extends dbJSON {
$db = $this->getPublishedDB(true); $db = $this->getPublishedDB(true);
} }
if ($amountOfItems==-1) { if ($numberOfItems==-1) {
return $db; return $db;
} }
@ -471,12 +471,12 @@ class Pages extends dbJSON {
$realPageNumber = $pageNumber - 1; $realPageNumber = $pageNumber - 1;
$total = count($db); $total = count($db);
$init = (int) $amountOfItems * $realPageNumber; $init = (int) $numberOfItems * $realPageNumber;
$end = (int) min( ($init + $amountOfItems - 1), $total ); $end = (int) min( ($init + $numberOfItems - 1), $total );
$outrange = $init<0 ? true : $init>$end; $outrange = $init<0 ? true : $init>$end;
if (!$outrange) { if (!$outrange) {
return array_slice($db, $init, $amountOfItems, true); return array_slice($db, $init, $numberOfItems, true);
} }
return false; return false;

View File

@ -168,12 +168,18 @@ class Page {
return $this->categoryMap('name'); return $this->categoryMap('name');
} }
// Returns the category name // Returns the category template
public function categoryTemplate() public function categoryTemplate()
{ {
return $this->categoryMap('template'); return $this->categoryMap('template');
} }
// Returns the category description
public function categoryDescription()
{
return $this->categoryMap('description');
}
// Returns the category key // Returns the category key
public function categoryKey() public function categoryKey()
{ {
@ -196,10 +202,8 @@ class Page {
if ($field=='key') { if ($field=='key') {
return $this->categoryKey(); return $this->categoryKey();
} elseif($field=='name') { } elseif(isset($map[$field])) {
return $map['name']; return $map[$field];
} elseif($field=='list') {
return $map['list'];
} }
return false; return false;

View File

@ -11,7 +11,7 @@ class pluginAPI extends Plugin {
$this->dbFields = array( $this->dbFields = array(
'token'=>$token, // API Token 'token'=>$token, // API Token
'amountOfItems'=>15 // Amount of items to return 'numberOfItems'=>15 // Amount of items to return
); );
} }
@ -31,7 +31,7 @@ class pluginAPI extends Plugin {
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Amount of pages').'</label>'; $html .= '<label>'.$L->get('Amount of pages').'</label>';
$html .= '<input id="jsamountOfItems" name="amountOfItems" type="text" value="'.$this->getValue('amountOfItems').'">'; $html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">';
$html .= '<span class="tip">'.$L->get('This is the maximum of pages to return when you call to').'</span>'; $html .= '<span class="tip">'.$L->get('This is the maximum of pages to return when you call to').'</span>';
$html .= '</div>'; $html .= '</div>';
@ -238,13 +238,13 @@ class pluginAPI extends Plugin {
global $pages; global $pages;
$onlyPublished = true; $onlyPublished = true;
$amountOfItems = $this->getValue('amountOfItems'); $numberOfItems = $this->getValue('numberOfItems');
$pageNumber = 1; $pageNumber = 1;
$list = $pages->getList($pageNumber, $amountOfItems, $onlyPublished); $list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
$tmp = array( $tmp = array(
'status'=>'0', 'status'=>'0',
'message'=>'List of pages, amount of items: '.$amountOfItems, 'message'=>'List of pages, amount of items: '.$numberOfItems,
'data'=>array() 'data'=>array()
); );

View File

@ -8,7 +8,7 @@ class pluginNavigation extends Plugin {
$this->dbFields = array( $this->dbFields = array(
'label'=>'Navigation', 'label'=>'Navigation',
'homeLink'=>true, 'homeLink'=>true,
'amountOfItems'=>5 'numberOfItems'=>5
); );
} }
@ -39,7 +39,7 @@ class pluginNavigation extends Plugin {
if (ORDER_BY=='date') { if (ORDER_BY=='date') {
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Amount of items').'</label>'; $html .= '<label>'.$L->get('Amount of items').'</label>';
$html .= '<input id="jsamountOfItems" name="amountOfItems" type="text" value="'.$this->getValue('amountOfItems').'">'; $html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">';
$html .= '</div>'; $html .= '</div>';
} }
@ -100,8 +100,8 @@ class pluginNavigation extends Plugin {
// List of published pages // List of published pages
$onlyPublished = true; $onlyPublished = true;
$pageNumber = 1; $pageNumber = 1;
$amountOfItems = $this->getValue('amountOfItems'); $numberOfItems = $this->getValue('numberOfItems');
$publishedPages = $pages->getList($pageNumber, $amountOfItems, $onlyPublished); $publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
foreach ($publishedPages as $pageKey) { foreach ($publishedPages as $pageKey) {
try { try {

View File

@ -6,7 +6,7 @@ class pluginRSS extends Plugin {
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'amountOfItems'=>5 'numberOfItems'=>5
); );
} }
@ -26,7 +26,7 @@ class pluginRSS extends Plugin {
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Amount of items').'</label>'; $html .= '<label>'.$L->get('Amount of items').'</label>';
$html .= '<input id="jsamountOfItems" name="amountOfItems" type="text" value="'.$this->getValue('amountOfItems').'">'; $html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">';
$html .= '<span class="tip">'.$L->get('Amount of items to show on the feed').'</span>'; $html .= '<span class="tip">'.$L->get('Amount of items to show on the feed').'</span>';
$html .= '</div>'; $html .= '</div>';
@ -40,7 +40,7 @@ class pluginRSS extends Plugin {
global $url; global $url;
// Amount of pages to show // Amount of pages to show
$amountOfItems = $this->getValue('amountOfItems'); $numberOfItems = $this->getValue('numberOfItems');
// Page number the first one // Page number the first one
$pageNumber = 1; $pageNumber = 1;
@ -49,7 +49,7 @@ class pluginRSS extends Plugin {
$onlyPublished = true; $onlyPublished = true;
// Get the list of pages // Get the list of pages
$list = $pages->getList($pageNumber, $amountOfItems, $onlyPublished, true); $list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished, true);
$xml = '<?xml version="1.0" encoding="UTF-8" ?>'; $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<rss version="2.0">'; $xml .= '<rss version="2.0">';

View File

@ -34,9 +34,9 @@ class pluginSitemap extends Plugin {
// Get DB // Get DB
$pageNumber = 1; $pageNumber = 1;
$amountOfItems = -1; $numberOfItems = -1;
$onlyPublished = true; $onlyPublished = true;
$list = $pages->getList($pageNumber, $amountOfItems, $onlyPublished); $list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
foreach($list as $pageKey) { foreach($list as $pageKey) {
try { try {

View File

@ -46,7 +46,7 @@
<?php endforeach ?> <?php endforeach ?>
<!-- Pagination --> <!-- Pagination -->
<?php if (Paginator::amountOfPages()>1): ?> <?php if (Paginator::numberOfPages()>1): ?>
<nav class="paginator"> <nav class="paginator">
<ul class="pagination flex-wrap justify-content-center"> <ul class="pagination flex-wrap justify-content-center">

View File

@ -40,7 +40,7 @@
<?php endforeach ?> <?php endforeach ?>
<!-- Pagination --> <!-- Pagination -->
<?php if (Paginator::amountOfPages()>1): ?> <?php if (Paginator::numberOfPages()>1): ?>
<nav class="paginator"> <nav class="paginator">
<ul class="pagination flex-wrap"> <ul class="pagination flex-wrap">

View File

@ -6,9 +6,6 @@ Things to do:
- settings->advanced->Predefined pages->Page not found - settings->advanced->Predefined pages->Page not found
-- Search and select a page -- Search and select a page
- manage->users->edit user
-- Change profile avatar
- Add to Settings - Add to Settings
-- time for autosave -- time for autosave
-- time for check user logged -- time for check user logged
@ -33,3 +30,6 @@ Things to do:
- Profile picture - Profile picture
-- Convert to PNG -- Convert to PNG
-- Resize image -- Resize image
- pagex.class.php
-- improve tags methods, compare with category