Skip to content

Commit 5104eef

Browse files
committed
git init
0 parents  commit 5104eef

9 files changed

+629
-0
lines changed

LICENSE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2016 Artem Beliankin
3+
4+
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:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
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.

README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Telegram Bot Pagination
2+
3+
- [Installation](#installation)
4+
- [Composer](#composer)
5+
- [Configuration](#configuration)
6+
- [Service Provider](#service-provider)
7+
- [Usage](#usage)
8+
- [Test Data](#test-data)
9+
- [How To Use](#how-to-use)
10+
- [Result](#result)
11+
- [License](#license)
12+
13+
## Installation
14+
15+
### Composer
16+
```bash
17+
composer require "lartie/telegram-bot-pagination:^1.0.0"
18+
```
19+
20+
### Service Provider
21+
22+
You must install this service provider.
23+
```php
24+
// config/app.php
25+
'providers' => [
26+
...
27+
LArtie\TelegramBotPagination\TelegramBotPaginationServiceProvider::class,
28+
...
29+
];
30+
```
31+
32+
## Usage
33+
34+
### Test Data
35+
```php
36+
$items = range(1, 100);
37+
$command = 'testCommand'; // optional. Default: pagination
38+
$selectedPage = 10; // optional. Default: 1
39+
```
40+
41+
### How To Use
42+
```php
43+
44+
$cqPagination = new CallbackQueryPagination($items, $command);
45+
$cqPagination->setMaxButtons(6);
46+
$cqPagination->setWrapSelectedButton('< #VALUE# >');
47+
48+
$pagination = $cqPagination->pagination($selectedPage); //$cqPagination->setSelectedPage($selectedPage);
49+
50+
```
51+
52+
### Result
53+
```php
54+
if (!empty($paginate['keyboard'])) {
55+
$paginate['keyboard'][0]['callback_data']; // testCommand?currentPage10=&nextPage=1
56+
$paginate['keyboard'][1]['callback_data']; // testCommand?currentPage10=&nextPage=9
57+
...
58+
59+
$response = [
60+
'reply_markup' => json_encode([
61+
'inline_keyboard' => [
62+
$paginate['keyboard'],
63+
],
64+
]),
65+
];
66+
}
67+
```
68+
69+
## Code Quality
70+
71+
Run the PHPUnit tests with PHPUnit.
72+
73+
phpunit tests/
74+
75+
76+
## License
77+
78+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "lartie/telegram-bot-pagination",
3+
"description": "Telegram Bot Pagination ",
4+
"keywords": ["laravel", "telegram api", "telegram", "pagination", "telegram-callback", "telegram bot"],
5+
"type": "library",
6+
"homepage": "https://github.com/lartie/telegram-bot-pagination",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Artie",
11+
"email": "[email protected]",
12+
"homepage": "https://github.com/lartie"
13+
}
14+
],
15+
"require": {
16+
"php": ">=7.0"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^4.8 || ^5.0",
20+
"phpspec/prophecy": "^1.5"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"LArtie\\TelegramBotPagination\\": "src"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"LArtie\\TelegramBotPagination\\Tests\\": "tests/"
30+
}
31+
},
32+
"scripts": {
33+
"test": "phpunit"
34+
}
35+
}
36+

phpunit.xml.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="./../../../vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
beStrictAboutOutputDuringTests="true"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnError="false"
12+
stopOnFailure="false"
13+
verbose="true"
14+
>
15+
<testsuites>
16+
<testsuite name="Telegram Bot Pagination Test Suite">
17+
<directory suffix="Test.php">./tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist processUncoveredFilesFromWhitelist="true">
22+
<directory suffix=".php">./src</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace LArtie\TelegramBotPagination\Contract;
4+
5+
use LArtie\TelegramBotPagination\Core\CallbackQueryPagination;
6+
7+
/**
8+
* Interface CallbackQueryPaginationContract
9+
* @package LArtie\TelegramBotPagination
10+
*/
11+
interface CallbackQueryPaginationContract
12+
{
13+
/**
14+
* @param int $maxButtons
15+
* @return CallbackQueryPagination
16+
*/
17+
public function setMaxButtons(int $maxButtons = 5) : CallbackQueryPagination;
18+
19+
/**
20+
* >#VALUE#<, <#VALUE#>, |#VALUE#| etc...
21+
*
22+
* @param string $wrapSelectedButton
23+
* @return CallbackQueryPagination
24+
*/
25+
public function setWrapSelectedButton(string $wrapSelectedButton = '« #VALUE# »') : CallbackQueryPagination;
26+
27+
/**
28+
* @param string $command
29+
* @return CallbackQueryPagination
30+
*/
31+
public function setCommand(string $command = 'pagination'): CallbackQueryPagination;
32+
33+
/**
34+
* @param int $selectedPage
35+
* @return CallbackQueryPagination
36+
*/
37+
public function setSelectedPage(int $selectedPage): CallbackQueryPagination;
38+
39+
/**
40+
* CallbackQueryPaginationContract constructor.
41+
*
42+
* @param array $items
43+
* @param string $command
44+
* @param int $selectedPage
45+
* @param int $limit
46+
*/
47+
public function __construct(array $items, string $command, int $selectedPage, int $limit);
48+
49+
/**
50+
* @param int $selectedPage
51+
* @return array
52+
*/
53+
public function paginate(int $selectedPage = null) : array;
54+
}

0 commit comments

Comments
 (0)