Add L10n parameter to Pager classes

This commit is contained in:
Hypolite Petovan 2020-02-16 11:53:52 -05:00
parent 682fb7e4e2
commit 561472b975
20 changed files with 53 additions and 52 deletions

View File

@ -107,7 +107,7 @@ function common_content(App $a)
return $o;
}
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
if ($cid) {
$common_friends = Model\GContact::commonFriends($uid, $cid, $pager->getStart(), $pager->getItemsPerPage());

View File

@ -296,7 +296,7 @@ function message_content(App $a)
$total = $r[0]['total'];
}
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$r = get_messages(local_user(), $pager->getStart(), $pager->getItemsPerPage());

View File

@ -377,7 +377,7 @@ function networkFlatView(App $a, $update = 0)
}
}
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
networkPager($a, $pager, $update);
@ -669,7 +669,7 @@ function networkThreadedView(App $a, $update, $parent)
$sql_range = '';
}
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$pager_sql = networkPager($a, $pager, $update);

View File

@ -69,7 +69,7 @@ function notes_content(App $a, $update = false)
$condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT,
'contact-id'=> $a->contact['id']];
$pager = new Pager(DI::args()->getQueryString(), 40);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 40);
$params = ['order' => ['created' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

View File

@ -1023,7 +1023,7 @@ function photos_content(App $a)
$total = count($r);
}
$pager = new Pager(DI::args()->getQueryString(), 20);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
/// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
$order_field = $_GET['order'] ?? '';
@ -1299,7 +1299,7 @@ function photos_content(App $a)
$condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
$total = DBA::count('item', $condition);
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
@ -1565,7 +1565,7 @@ function photos_content(App $a)
$total = count($r);
}
$pager = new Pager(DI::args()->getQueryString(), 20);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
$r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,

View File

@ -225,7 +225,7 @@ function videos_content(App $a)
$total = count($r);
}
$pager = new Pager(DI::args()->getQueryString(), 20);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
$r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`

View File

@ -21,17 +21,18 @@
namespace Friendica\Content;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Util\Network;
use Friendica\Util\Strings;
/**
* This pager should be used by lists using the since_id/max_id parameters
* This pager should be used by lists using the since_id/max_id parameters
*
* In this context, "id" refers to the value of the column that the list is ordered by.
* This pager automatically identifies if the sorting is done increasingly or decreasingly if the first item id
* and last item id are different. Otherwise it defaults to decreasingly like reverse chronological lists.
* This pager automatically identifies if the sorting is done increasingly or decreasingly if the first item id†
* and last item id† are different. Otherwise it defaults to decreasingly like reverse chronological lists.
*
* In this context, "id" refers to the value of the column that the item list is ordered by.
*/
class BoundariesPager extends Pager
{
@ -42,14 +43,15 @@ class BoundariesPager extends Pager
/**
* Instantiates a new Pager with the base parameters.
*
* @param L10n $l10n
* @param string $queryString The query string of the current page
* @param string $first_item_id The i
* @param string $last_item_id
* @param string $first_item_id The id† of the first item in the displayed item list
* @param string $last_item_id The id† of the last item in the displayed item list
* @param integer $itemsPerPage An optional number of items per page to override the default value
*/
public function __construct($queryString, $first_item_id = null, $last_item_id = null, $itemsPerPage = 50)
public function __construct(L10n $l10n, $queryString, $first_item_id = null, $last_item_id = null, $itemsPerPage = 50)
{
parent::__construct($queryString, $itemsPerPage);
parent::__construct($l10n, $queryString, $itemsPerPage);
$this->first_item_id = $first_item_id;
$this->last_item_id = $last_item_id;
@ -111,7 +113,7 @@ class BoundariesPager extends Pager
($this->first_item_id >= $this->last_item_id ?
'&since_id=' . $this->first_item_id : '&max_id=' . $this->first_item_id)
),
'text' => DI::l10n()->t('newer'),
'text' => $this->l10n->t('newer'),
'class' => 'previous' . ($this->first_page ? ' disabled' : '')
],
'next' => [
@ -119,7 +121,7 @@ class BoundariesPager extends Pager
($this->first_item_id >= $this->last_item_id ?
'&max_id=' . $this->last_item_id : '&since_id=' . $this->last_item_id)
),
'text' => DI::l10n()->t('older'),
'text' => $this->l10n->t('older'),
'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
]
];

View File

@ -21,8 +21,8 @@
namespace Friendica\Content;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Util\Strings;
/**
@ -30,30 +30,29 @@ use Friendica\Util\Strings;
*/
class Pager
{
/**
* @var integer
*/
/** @var integer */
private $page = 1;
/**
* @var integer
*/
/** @var integer */
protected $itemsPerPage = 50;
/**
* @var string
*/
/** @var string */
protected $baseQueryString = '';
/** @var L10n */
protected $l10n;
/**
* Instantiates a new Pager with the base parameters.
*
* Guesses the page number from the GET parameter 'page'.
*
* @param L10n $l10n
* @param string $queryString The query string of the current page
* @param integer $itemsPerPage An optional number of items per page to override the default value
*/
public function __construct($queryString, $itemsPerPage = 50)
public function __construct(L10n $l10n, $queryString, $itemsPerPage = 50)
{
$this->l10n = $l10n;
$this->setQueryString($queryString);
$this->setItemsPerPage($itemsPerPage);
$this->setPage(($_GET['page'] ?? 0) ?: 1);
@ -166,12 +165,12 @@ class Pager
'class' => 'pager',
'prev' => [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
'text' => DI::l10n()->t('newer'),
'text' => $this->l10n->t('newer'),
'class' => 'previous' . ($this->getPage() == 1 ? ' disabled' : '')
],
'next' => [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
'text' => DI::l10n()->t('older'),
'text' => $this->l10n->t('older'),
'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
]
];
@ -211,12 +210,12 @@ class Pager
if ($totalItemCount > $this->getItemsPerPage()) {
$data['first'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=1'),
'text' => DI::l10n()->t('first'),
'text' => $this->l10n->t('first'),
'class' => $this->getPage() == 1 ? 'disabled' : ''
];
$data['prev'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() - 1)),
'text' => DI::l10n()->t('prev'),
'text' => $this->l10n->t('prev'),
'class' => $this->getPage() == 1 ? 'disabled' : ''
];
@ -271,12 +270,12 @@ class Pager
$data['next'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
'text' => DI::l10n()->t('next'),
'text' => $this->l10n->t('next'),
'class' => $this->getPage() == $lastpage ? 'disabled' : ''
];
$data['last'] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $lastpage),
'text' => DI::l10n()->t('last'),
'text' => $this->l10n->t('last'),
'class' => $this->getPage() == $lastpage ? 'disabled' : ''
];
}

View File

@ -1805,7 +1805,7 @@ class Contact
$cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
}
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$params = ['order' => ['received' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

View File

@ -68,7 +68,7 @@ class Contact extends BaseAdmin
$total = DBA::count('contact', $condition);
$pager = new Pager(DI::args()->getQueryString(), 30);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
$contacts = Model\Contact::selectToArray([], $condition, ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);

View File

@ -194,7 +194,7 @@ class Users extends BaseAdmin
/* get pending */
$pending = Register::getPending();
$pager = new Pager(DI::args()->getQueryString(), 100);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100);
// @TODO Move below block to Model\User::getUsers($start, $count, $order = 'contact.name', $order_direction = '+')
$valid_orders = [

View File

@ -67,7 +67,7 @@ class AllFriends extends BaseModule
$total = Model\GContact::countAllFriends(local_user(), $cid);
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
if (empty($friends)) {

View File

@ -102,7 +102,7 @@ abstract class BaseNotifications extends BaseModule
}
// Set the pager
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
// Add additional informations (needed for json output)
$notifications = [
@ -132,7 +132,7 @@ abstract class BaseNotifications extends BaseModule
$tabs = self::getTabs();
// Set the pager
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
$notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl');
return Renderer::replaceMacros($notif_tpl, [

View File

@ -81,8 +81,7 @@ class BaseSearch extends BaseModule
$header = DI::l10n()->t('Forum Search - %s', $search);
}
$args = DI::args();
$pager = new Pager($args->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
if ($localSearch && empty($results)) {
$pager->setItemsPerPage(80);

View File

@ -731,7 +731,7 @@ class Contact extends BaseModule
}
DBA::close($stmt);
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$sql_values[] = $pager->getStart();
$sql_values[] = $pager->getItemsPerPage();

View File

@ -104,6 +104,7 @@ class Community extends BaseModule
$o .= conversation(DI::app(), $items, 'community', false, false, 'commented', local_user());
$pager = new BoundariesPager(
DI::l10n(),
DI::args()->getQueryString(),
$items[0]['commented'],
$items[count($items) - 1]['commented'],

View File

@ -70,7 +70,7 @@ class Directory extends BaseModule
$gDirPath = Profile::zrl($dirURL, true);
}
$pager = new Pager(DI::args()->getQueryString(), 60);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 60);
$profiles = Profile::searchProfiles($pager->getStart(), $pager->getItemsPerPage(), $search);

View File

@ -85,7 +85,7 @@ class Contacts extends BaseProfile
$total = DBA::count('contact', $condition);
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];

View File

@ -180,7 +180,7 @@ class Status extends BaseProfile
$itemspage_network = $a->force_max_items;
}
$pager = new Pager($args->getQueryString(), $itemspage_network);
$pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
$pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());

View File

@ -137,7 +137,7 @@ class Index extends BaseSearch
// OR your own posts if you are a logged in member
// No items will be shown if the member has a blocked profile wall.
$pager = new Pager(DI::args()->getQueryString());
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
if ($tag) {
Logger::info('Start tag search.', ['q' => $search]);