-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5104eef
Showing
9 changed files
with
629 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
The MIT License (MIT) | ||
Copyright (c) 2016 Artem Beliankin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Telegram Bot Pagination | ||
|
||
- [Installation](#installation) | ||
- [Composer](#composer) | ||
- [Configuration](#configuration) | ||
- [Service Provider](#service-provider) | ||
- [Usage](#usage) | ||
- [Test Data](#test-data) | ||
- [How To Use](#how-to-use) | ||
- [Result](#result) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
### Composer | ||
```bash | ||
composer require "lartie/telegram-bot-pagination:^1.0.0" | ||
``` | ||
|
||
### Service Provider | ||
|
||
You must install this service provider. | ||
```php | ||
// config/app.php | ||
'providers' => [ | ||
... | ||
LArtie\TelegramBotPagination\TelegramBotPaginationServiceProvider::class, | ||
... | ||
]; | ||
``` | ||
|
||
## Usage | ||
|
||
### Test Data | ||
```php | ||
$items = range(1, 100); | ||
$command = 'testCommand'; // optional. Default: pagination | ||
$selectedPage = 10; // optional. Default: 1 | ||
``` | ||
|
||
### How To Use | ||
```php | ||
|
||
$cqPagination = new CallbackQueryPagination($items, $command); | ||
$cqPagination->setMaxButtons(6); | ||
$cqPagination->setWrapSelectedButton('< #VALUE# >'); | ||
|
||
$pagination = $cqPagination->pagination($selectedPage); //$cqPagination->setSelectedPage($selectedPage); | ||
|
||
``` | ||
|
||
### Result | ||
```php | ||
if (!empty($paginate['keyboard'])) { | ||
$paginate['keyboard'][0]['callback_data']; // testCommand?currentPage10=&nextPage=1 | ||
$paginate['keyboard'][1]['callback_data']; // testCommand?currentPage10=&nextPage=9 | ||
... | ||
|
||
$response = [ | ||
'reply_markup' => json_encode([ | ||
'inline_keyboard' => [ | ||
$paginate['keyboard'], | ||
], | ||
]), | ||
]; | ||
} | ||
``` | ||
|
||
## Code Quality | ||
|
||
Run the PHPUnit tests with PHPUnit. | ||
|
||
phpunit tests/ | ||
|
||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "lartie/telegram-bot-pagination", | ||
"description": "Telegram Bot Pagination ", | ||
"keywords": ["laravel", "telegram api", "telegram", "pagination", "telegram-callback", "telegram bot"], | ||
"type": "library", | ||
"homepage": "https://github.com/lartie/telegram-bot-pagination", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Artie", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/lartie" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.0" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8 || ^5.0", | ||
"phpspec/prophecy": "^1.5" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"LArtie\\TelegramBotPagination\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"LArtie\\TelegramBotPagination\\Tests\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "phpunit" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./../../../vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
beStrictAboutOutputDuringTests="true" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Telegram Bot Pagination Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace LArtie\TelegramBotPagination\Contract; | ||
|
||
use LArtie\TelegramBotPagination\Core\CallbackQueryPagination; | ||
|
||
/** | ||
* Interface CallbackQueryPaginationContract | ||
* @package LArtie\TelegramBotPagination | ||
*/ | ||
interface CallbackQueryPaginationContract | ||
{ | ||
/** | ||
* @param int $maxButtons | ||
* @return CallbackQueryPagination | ||
*/ | ||
public function setMaxButtons(int $maxButtons = 5) : CallbackQueryPagination; | ||
|
||
/** | ||
* >#VALUE#<, <#VALUE#>, |#VALUE#| etc... | ||
* | ||
* @param string $wrapSelectedButton | ||
* @return CallbackQueryPagination | ||
*/ | ||
public function setWrapSelectedButton(string $wrapSelectedButton = '« #VALUE# »') : CallbackQueryPagination; | ||
|
||
/** | ||
* @param string $command | ||
* @return CallbackQueryPagination | ||
*/ | ||
public function setCommand(string $command = 'pagination'): CallbackQueryPagination; | ||
|
||
/** | ||
* @param int $selectedPage | ||
* @return CallbackQueryPagination | ||
*/ | ||
public function setSelectedPage(int $selectedPage): CallbackQueryPagination; | ||
|
||
/** | ||
* CallbackQueryPaginationContract constructor. | ||
* | ||
* @param array $items | ||
* @param string $command | ||
* @param int $selectedPage | ||
* @param int $limit | ||
*/ | ||
public function __construct(array $items, string $command, int $selectedPage, int $limit); | ||
|
||
/** | ||
* @param int $selectedPage | ||
* @return array | ||
*/ | ||
public function paginate(int $selectedPage = null) : array; | ||
} |
Oops, something went wrong.