Completed
Push — master ( 2b8089...5dd80a )
by Danilo
05:26
created

InlineKeyboard::addButton()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
crap 2.0185
1
<?php
2
3
/*
4
 * This file is part of the PhpBotFramework.
5
 *
6
 * PhpBotFramework is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, version 3.
9
 *
10
 * PhpBotFramework is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace PhpBotFramework\Entities;
20
21
use PhpBotFramework\Exceptions\BotException;
22
23
/**
24
 * \addtogroup Entities Entities
25
 * @{
26
 */
27
28
/** \class InlineKeyboard
29
 * \brief Inline Keyboard handler that create and handle inline keyboard buttons.
30
 * \details It stores the inline keyboard buttons added until get() is called.
31
 * It also provides some basic button to get, like Menu and Back buttons plus the dynamic-keyboard for menu browsing.
32
 */
33
class InlineKeyboard
34
{
35
    /**
36
     * \addtogroup InlineKeyboard InlineKeyboard
37
     * \brief Handle an inline keyboard to send along with messages.
38
     * @{
39
     */
40
41
    /** \brief Store the array of InlineKeyboardButton */
42
    protected $inline_keyboard;
43
44
    /** \brief Store the current row. */
45
    private $row;
46
47
    /** \brief Store the current column. */
48
    private $column;
49
50
    /**
51
     * \brief Create an inline keyboard object.
52
     * @param array $buttons Buttons passed as inizialization.
53
     */
54 2
    public function __construct(
55
        array $buttons = array()
56
    ) {
57
        // If $buttons is empty, initialize it with an empty array
58 2
        $this->inline_keyboard = $buttons;
59
60
        // Set up vars
61 2
        $this->row = 0;
62 2
        $this->column = 0;
63 2
    }
64
65
    /**
66
     * \brief Get a JSON-serialized object containg the inline keyboard.
67
     * @param bool $clear_keyboard Remove all the buttons from this object.
68
     * @return string JSON-serialized string with the buttons.
69
     */
70 1 View Code Duplication
    public function get(bool $clear_keyboard = true) : string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        // Check if it is empty
73 1
        if (empty($this->inline_keyboard)) {
74
            throw new BotException("Inline keyboard is empty");
75
        }
76
77
        // Create a new array to put our buttons
78 1
        $reply_markup = ['inline_keyboard' => $this->inline_keyboard];
79
80
        // Encode the array in a json object
81 1
        $reply_markup = json_encode($reply_markup);
82
83 1
        if ($clear_keyboard) {
84
            $this->clearKeyboard();
85
        }
86
87 1
        return $reply_markup;
88
    }
89
90
    /**
91
     * \brief Get the array containing the buttons. (Use this method when adding keyboard to inline query results)
92
     * @param bool $clean_keyboard Remove all the button from this object.
93
     * @return array An array containing the buttons.
94
     */
95 1 View Code Duplication
    public function getArray(bool $clean_keyboard = true) : array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        // Check if it is empty
98 1
        if (empty($this->inline_keyboard)) {
99
            throw new BotException("Inline keyboard is empty");
100
        }
101
102
        // Create a new array to put the buttons
103 1
        $reply_markup = ['inline_keyboard' => $this->inline_keyboard];
104
105 1
        if ($clean_keyboard) {
106 1
            $this->clearKeyboard();
107
        }
108
109 1
        return $reply_markup;
110
    }
111
112
    /** \brief Add buttons for the current row of buttons
113
     * \details Each array sent as parameter require a text key
114
     * and one another key (as specified <a href="https://core.telegram.org/bots/api/#inlinekeyboardbutton" target="blank">here</a> between:
115
     * - url
116
     * - callback_data
117
     * - switch_inline_query
118
     * - switch_inline_query_current_chat
119
     * - callback_game
120
     *
121
     * Each call to this function add one or more button to a row. The next call add buttons on the next row.
122
     * Each row allows 8 buttons per row and 12 columns total.
123
     * Use this function with this syntax:
124
     *
125
     *     addLevelButtons(['text' => 'Click me!', 'url' => 'https://telegram.me']);
126
     *
127
     * If you want to add more than a button, use this syntax:
128
     *
129
     *     addLevelButtons(['text' => 'Button 1', 'url' => 'https://telegram.me/gamedev_ita'], ['text' => 'Button 2', 'url' => 'https://telegram.me/animewallpaper']);
130
     *
131
     * @param array ...$buttons One or more arrays, each one represent a button.
132
     */
133 1
    public function addLevelButtons(array ...$buttons)
134
    {
135
        // If the user has already added a button in this row
136 1
        if ($this->column != 0) {
137
             // Change row
138
             $this->changeRow();
139
        }
140
141
        // Add buttons to the next row
142 1
        $this->inline_keyboard[] = $buttons;
143
144
        // Switch to the next row
145 1
        $this->changeRow();
146 1
    }
147
148
    /** \brief Add a button.
149
     * \details The button will be added next to the last one or in the next row if the bot has reached the limit for the buttons per row.
150
     *
151
     * Each row allows 8 buttons per row and 12 columns total.
152
     * Use this function with this syntax:
153
     *
154
     *     addButton('Click me!', 'url', 'https://telegram.me');
155
     *
156
     * @param string $text Text showed on the button.
157
     * @param string $data_type The type of the button data.
158
     * Select one from these types.
159
     * - url
160
     * - callback_data
161
     * - switch_inline_query
162
     * - switch_inline_query_current_chat
163
     * - callback_game
164
     * @param string $data Data for the type selected.
165
     */
166 1
    public function addButton(string $text, string $data_type, string $data)
167
    {
168
        // If we get the end of the row
169 1
        if ($this->column == 8) {
170
            $this->changeRow();
171
        }
172
173
        // Add the button
174 1
        $this->inline_keyboard[$this->row][$this->column] = ['text' => $text, $data_type => $data];
175
176
        // Update column
177 1
        $this->column++;
178 1
    }
179
180
    /**
181
     * \brief Change row for the current keyboard.
182
     * \details Buttons will be added in the next row from now on (until next InlineKeyboard::addLevelButtons() or InlineKeyboard::changeRow() call or InlineKeyboard::addButton() reaches the max).
183
     */
184 1
    public function changeRow()
185
    {
186
187
        // Reset vars
188 1
        $this->row++;
189 1
        $this->column = 0;
190 1
    }
191
192
    /** \brief Remove all the buttons from the current inline keyboard. */
193 1
    public function clearKeyboard()
194
    {
195
        // Set the inline keyboard to an empty array
196 1
        $this->inline_keyboard = [];
197
198
        // Reset vars
199 1
        $this->row = 0;
200 1
        $this->column = 0;
201 1
    }
202
203
    /**
204
     * \brief Add 5 buttons or less, which will have as a callback data '$prefix/number'.
205
     * \details Create buttons for browsing something in the bot. Each button will have a number as text, plus some symbol as first page, or last page. The buttons are dinamically generated at runtime passing $index and $list. If there are less than 5 pages, then show only the required buttons (at least one, up to 4).
206
     * @param int $index The page which the user is currently.
207
     * @param int $list The total number of pages.
208
     * @param string $prefix Prefix to add at each callback_data of the button. Eg.: 'list/1'.
209
     */
210 1
    public function addListKeyboard(int $index, int $list, $prefix = 'list')
211
    {
212 1
        $buttons = [];
213
214 1
        if (($list > 0) && ($index >= 0)) {
215 1
            if ($index == 0) {
216
                if ($list > 1) {
217
                    if ($list > 2) {
218
                        if ($list > 3) {
219
                            if ($list > 4) {
220
                                if ($list > 5) {
221
                                    $buttons = [
222
                                            [
223
                                                'text' => '1',
224
                                                'callback_data' => $prefix . '/1'
225
                                            ],
226
                                            [
227
                                                'text' => '2',
228
                                                'callback_data' => $prefix . '/2'
229
                                            ],
230
                                            [
231
                                                'text' => '3',
232
                                                'callback_data' => $prefix . '/3'
233
                                            ],
234
                                            [
235
                                                'text' => '4 ›',
236
                                                'callback_data' => $prefix . '/4'
237
                                            ],
238
                                            [
239
                                                'text' => "$list ››",
240
                                                'callback_data' => $prefix . "/$list"
241
                                            ]
242
                                        ];
243
                                } else {
244
                                    $buttons = [
245
                                            [
246
                                                'text' => '1',
247
                                                'callback_data' => $prefix . '/1'
248
                                            ],
249
                                            [
250
                                                'text' => '2',
251
                                                'callback_data' => $prefix . '/2'
252
                                            ],
253
                                            [
254
                                                'text' => '3',
255
                                                'callback_data' => $prefix . '/3'
256
                                            ],
257
                                            [
258
                                                'text' => '4',
259
                                                'callback_data' => $prefix . '/4'
260
                                            ],
261
                                            [
262
                                                'text' => '5',
263
                                                'callback_data' => $prefix . '/5'
264
                                            ]
265
                                        ];
266
                                }
267
                            } else {
268
                                $buttons = [
269
                                        [
270
                                            'text' => '1',
271
                                            'callback_data' => $prefix . '/1'
272
                                        ],
273
                                        [
274
                                            'text' => '2',
275
                                            'callback_data' => $prefix . '/2'
276
                                        ],
277
                                        [
278
                                            'text' => '3',
279
                                            'callback_data' => $prefix . '/3'
280
                                        ],
281
                                        [
282
                                            'text' => '4',
283
                                            'callback_data' => $prefix . '/4'
284
                                        ],
285
                                    ];
286
                            }
287
                        } else {
288
                            $buttons = [
289
                                    [
290
                                        'text' => '1',
291
                                        'callback_data' => $prefix . '/1'
292
                                    ],
293
                                    [
294
                                        'text' => '2',
295
                                        'callback_data' => $prefix . '/2'
296
                                    ],
297
                                    [
298
                                        'text' => '3',
299
                                        'callback_data' => $prefix . '/3'
300
                                    ],
301
                                ];
302
                        }
303
                    } elseif ($list == 2) {
304
                        $buttons = [
305
                                [
306
                                    'text' => '1',
307
                                    'callback_data' => $prefix . '/1'
308
                                ],
309
                                [
310
                                    'text' => '2',
311
                                    'callback_data' => $prefix . '/2'
312
                                ],
313
                            ];
314
                    }
315
                } else {
316
                    $buttons = [
317
                            [
318
                                'text' => '1',
319
                                'callback_data' => $prefix . '/1'
320
                            ]
321
                    ];
322
                }
323 1
            } elseif ($index == 1) {
324
                if ($list > 1) {
325 View Code Duplication
                    if ($list > 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
326
                        if ($list > 3) {
327
                            if ($list > 4) {
328
                                if ($list > 5) {
329
                                    $buttons = [
330
                                            [
331
                                                'text' => '• 1 •',
332
                                                'callback_data' => 'null'
333
                                            ],
334
                                            [
335
                                                'text' => '2',
336
                                                'callback_data' => $prefix . '/2'
337
                                            ],
338
                                            [
339
                                                'text' => '3',
340
                                                'callback_data' => $prefix . '/3'
341
                                            ],
342
                                            [
343
                                                'text' => '4 ›',
344
                                                'callback_data' => $prefix . '/4'
345
                                            ],
346
                                            [
347
                                                'text' => "$list ››",
348
                                                'callback_data' => $prefix . "/$list"
349
                                            ]
350
                                        ];
351
                                } else {
352
                                    $buttons = [
353
                                            [
354
                                                'text' => '• 1 •',
355
                                                'callback_data' => 'null'
356
                                            ],
357
                                            [
358
                                                'text' => '2',
359
                                                'callback_data' => $prefix . '/2'
360
                                            ],
361
                                            [
362
                                                'text' => '3',
363
                                                'callback_data' => $prefix . '/3'
364
                                            ],
365
                                            [
366
                                                'text' => '4',
367
                                                'callback_data' => $prefix . '/4'
368
                                            ],
369
                                            [
370
                                                'text' => '5',
371
                                                'callback_data' => $prefix . '/5'
372
                                            ]
373
                                        ];
374
                                }
375
                            } else {
376
                                $buttons = [
377
                                        [
378
                                            'text' => '• 1 •',
379
                                                'callback_data' => 'null'
380
                                        ],
381
                                        [
382
                                                'text' => '2',
383
                                                'callback_data' => $prefix . '/2'
384
                                        ],
385
                                        [
386
                                                'text' => '3',
387
                                                'callback_data' => $prefix . '/3'
388
                                        ],
389
                                        [
390
                                                'text' => '4',
391
                                                'callback_data' => $prefix . '/4'
392
                                        ]
393
                                    ];
394
                            }
395
                        } else {
396
                            $buttons = [
397
                                    [
398
                                        'text' => '• 1 •',
399
                                        'callback_data' => 'null'
400
                                    ],
401
                                    [
402
                                        'text' => '2',
403
                                        'callback_data' => $prefix . '/2'
404
                                    ],
405
                                    [
406
                                        'text' => '3',
407
                                        'callback_data' => $prefix . '/3'
408
                                    ]
409
                                ];
410
                        }
411
                    } elseif ($list == 2) {
412
                        $buttons = [
413
                                [
414
                                    'text' => '• 1 •',
415
                                    'callback_data' => 'null'
416
                                ],
417
                                [
418
                                    'text' => '2',
419
                                    'callback_data' => $prefix . '/2'
420
                                ]
421
                            ];
422
                    }
423
                } else {
424
                    $buttons = [
425
                            [
426
                                'text' => '• 1 •',
427
                                'callback_data' => 'null'
428
                            ]
429
                        ];
430
                }
431 1 View Code Duplication
            } elseif ($index == 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
432
                if ($list > 3) {
433
                    if ($list > 4) {
434
                        if ($list > 5) {
435
                            $buttons = [
436
                                    [
437
                                        'text' => '1',
438
                                        'callback_data' => $prefix . '/1'
439
                                    ],
440
                                    [
441
                                        'text' => '• 2 •',
442
                                        'callback_data' => 'null'
443
                                    ],
444
                                    [
445
                                        'text' => '3',
446
                                        'callback_data' => $prefix . '/3'
447
                                    ],
448
                                    [
449
                                        'text' => '4 ›',
450
                                        'callback_data' => $prefix . '/4'
451
                                    ],
452
                                    [
453
                                        'text' => "$list ››",
454
                                        'callback_data' => $prefix . "/$list"
455
                                    ]
456
                                ];
457
                        } else {
458
                            $buttons = [
459
                                    [
460
                                        'text' => '1',
461
                                        'callback_data' => $prefix . '/1'
462
                                    ],
463
                                    [
464
                                        'text' => '• 2 •',
465
                                        'callback_data' => 'null'
466
                                    ],
467
                                    [
468
                                        'text' => '3',
469
                                        'callback_data' => $prefix . '/3'
470
                                    ],
471
                                    [
472
                                        'text' => '4',
473
                                        'callback_data' => '4'
474
                                    ],
475
                                    [
476
                                        'text' => '5',
477
                                        'callback_data' => $prefix . '/5'
478
                                    ]
479
                                ];
480
                        }
481
                    } else {
482
                        $buttons = [
483
                                [
484
                                    'text' => '1',
485
                                    'callback_data' => $prefix . '/1'
486
                                ],
487
                                [
488
                                    'text' => '• 2 •',
489
                                    'callback_data' => 'null'
490
                                ],
491
                                [
492
                                    'text' => '3',
493
                                    'callback_data' => $prefix . '/3'
494
                                ],
495
                                [
496
                                    'text' => '4',
497
                                    'callback_data' => $prefix . '/4'
498
                                ]
499
                            ];
500
                    }
501
                } elseif ($list == 3) {
502
                    $buttons = [
503
                            [
504
                                'text' => '1',
505
                                'callback_data' => $prefix . '/1'
506
                            ],
507
                            [
508
                                'text' => '• 2 •',
509
                                'callback_data' => 'null'
510
                            ],
511
                            [
512
                                'text' => '3',
513
                                'callback_data' => $prefix . '/3'
514
                            ]
515
                        ];
516
                } else {
517
                    $buttons = [
518
                            [
519
                                'text' => '1',
520
                                'callback_data' => $prefix . '/1'
521
                            ],
522
                            [
523
                                'text' => '• 2 •',
524
                                'callback_data' => 'null'
525
                            ]
526
                        ];
527
                }
528 1
            } elseif ($index == 3) {
529
                if ($list > 4) {
530
                    if ($list > 5) {
531
                        $buttons = [
532
                                [
533
                                    'text' => '1',
534
                                    'callback_data' => $prefix . '/1'
535
                                ],
536
                                [
537
                                    'text' => '2',
538
                                    'callback_data' => $prefix . '/2'
539
                                ],
540
                                [
541
                                    'text' => '• 3 •',
542
                                    'callback_data' => 'null'
543
                                ],
544
                                [
545
                                    'text' => '4 ›',
546
                                    'callback_data' => $prefix . '/4'
547
                                ],
548
                                [
549
                                    'text' => "$list ››",
550
                                    'callback_data' => $prefix . "/$list"
551
                                ]
552
                            ];
553
                    } else {
554
                        $buttons = [
555
                                [
556
                                    'text' => '1',
557
                                    'callback_data' => $prefix . '/1'
558
                                ],
559
                                [
560
                                    'text' => '2',
561
                                    'callback_data' => $prefix . '/2'
562
                                ],
563
                                [
564
                                    'text' => '• 3 •',
565
                                    'callback_data' => 'null'
566
                                ],
567
                                [
568
                                    'text' => '4',
569
                                    'callback_data' => $prefix . '/4'
570
                                ],
571
                                [
572
                                    'text' => '5',
573
                                    'callback_data' => $prefix . '/5'
574
                                ]
575
                            ];
576
                    }
577
                } elseif ($list == 4) {
578
                    $buttons = [
579
                            [
580
                                'text' => '1',
581
                                'callback_data' => $prefix . '/1'
582
                            ],
583
                            [
584
                                'text' => '2',
585
                                'callback_data' => $prefix . '/2'
586
                            ],
587
                            [
588
                                'text' => '• 3 •',
589
                                'callback_data' => 'null'
590
                            ],
591
                            [
592
                                'text' => '4',
593
                                'callback_data' => $prefix . '/4'
594
                            ]
595
                        ];
596
                } else {
597
                    $buttons = [
598
                            [
599
                                'text' => '1',
600
                                'callback_data' => $prefix . '/1'
601
                            ],
602
                            [
603
                                'text' => '2',
604
                                'callback_data' => $prefix . '/2'
605
                            ],
606
                            [
607
                                'text' => '• 3 •',
608
                                'callback_data' => 'null'
609
                            ]
610
                        ];
611
                }
612 1
            } elseif ($index == 4 && $list <= 5) {
613
                if ($list == 4) {
614
                    $buttons = [
615
                            [
616
                                'text' => '1',
617
                                'callback_data' => $prefix . '/1'
618
                            ],
619
                            [
620
                                'text' => '2',
621
                                'callback_data' => $prefix . '/2'
622
                            ],
623
                            [
624
                                'text' => '3',
625
                                'callback_data' => $prefix . '/3'
626
                            ],
627
                            [
628
                                'text' => '• 4 •',
629
                                'callback_data' => 'null'
630
                            ]
631
                        ];
632
                } elseif ($list == 5) {
633
                    $buttons = [
634
                            [
635
                                'text' => '1',
636
                                'callback_data' => $prefix . '/1'
637
                            ],
638
                            [
639
                                'text' => '2',
640
                                'callback_data' => $prefix . '/2'
641
                            ],
642
                            [
643
                                'text' => '3',
644
                                'callback_data' => $prefix . '/3'
645
                            ],
646
                            [
647
                                'text' => '• 4 •',
648
                                'callback_data' => 'null'
649
                            ],
650
                            [
651
                                'text' => '5',
652
                                'callback_data' => $prefix . '/5'
653
                            ]
654
                        ];
655
                }
656 1
            } elseif ($index == 5 && $list == 5) {
657
                $buttons = [
658
                        [
659
                            'text' => '1',
660
                            'callback_data' => $prefix . '/1'
661
                        ],
662
                        [
663
                            'text' => '2',
664
                            'callback_data' => $prefix . '/2'
665
                        ],
666
                        [
667
                            'text' => '3',
668
                            'callback_data' => $prefix . '/3'
669
                        ],
670
                        [
671
                            'text' => '4',
672
                            'callback_data' => $prefix . '/4'
673
                        ],
674
                        [
675
                            'text' => '• 5 •',
676
                            'callback_data' => 'null'
677
                        ]
678
                    ];
679
            } else {
680 1
                if ($index < $list - 2) {
681 1
                    $indexm = $index - 1;
682 1
                    $indexp = $index + 1;
683
                    $buttons = [
684
                            [
685 1
                                'text' => '‹‹ 1',
686 1
                                'callback_data' => $prefix . '/1'
687
                            ],
688
                            [
689 1
                                'text' => '‹ ' . $indexm,
690 1
                                'callback_data' => $prefix . '/' . $indexm
691
                            ],
692
                            [
693 1
                                'text' => '• ' . $index . ' •',
694 1
                                'callback_data' => 'null',
695
                            ],
696
                            [
697 1
                                'text' => $indexp . ' ›',
698 1
                                'callback_data' => $prefix . '/' . $indexp
699
                            ],
700
                            [
701 1
                                'text' => $list . ' ››',
702 1
                                'callback_data' => $prefix . '/' . $list
703
                            ]
704
                        ];
705
                } elseif ($index == ($list - 2)) {
706
                    $indexm = $index - 1;
707
                    $indexp = $index + 1;
708
                    $buttons = [
709
                            [
710
                                'text' => '‹‹1',
711
                                'callback_data' => $prefix . '/1'
712
                            ],
713
                            [
714
                                'text' => '' . $indexm,
715
                                'callback_data' => $prefix . '/' . $indexm
716
                            ],
717
                            [
718
                                'text' => '• ' . $index . ' •',
719
                                'callback_data' => 'null',
720
                            ],
721
                            [
722
                                'text' => '' . $indexp,
723
                                'callback_data' => $prefix . '/' . $indexp
724
                            ],
725
                            [
726
                                'text' => "$list",
727
                                'callback_data' => $prefix . "/$list"
728
                            ]
729
                        ];
730
                } elseif ($index == ($list - 1)) {
731
                    $indexm = $index - 1;
732
                    $indexmm = $index - 2;
733
                    $buttons = [
734
                            [
735
                                'text' => '‹‹ 1',
736
                                'callback_data' => $prefix . '/1'
737
                            ],
738
                            [
739
                                'text' => '‹ ' . $indexmm,
740
                                'callback_data' => $prefix . '/' . $indexmm
741
                            ],
742
                            [
743
                                'text' => '' . $indexm,
744
                                'callback_data' => $prefix . '/' . $indexm
745
                            ],
746
                            [
747
                                'text' => '• ' . $index . ' •',
748
                                'callback_data' => $prefix . '/' . $index
749
                            ],
750
                            [
751
                                'text' => "$list",
752
                                'callback_data' => $prefix . "/$list"
753
                            ]
754
                        ];
755
                } elseif ($index == $list) {
756
                    $indexm = $index - 1;
757
                    $indexmm = $index - 2;
758
                    $indexmmm = $index - 3;
759
                    $buttons = [
760
                            [
761
                                'text' => '‹‹ 1',
762
                                'callback_data' => $prefix . '/1'
763
                            ],
764
                            [
765
                                'text' => '‹ ' . $indexmmm,
766
                                'callback_data' => $prefix . '/' . $indexmmm
767
                            ],
768
                            [
769
                                'text' => '' . $indexmm,
770
                                'callback_data' => $prefix . '/' . $indexmm,
771
                            ],
772
                            [
773
                                'text' => '' . $indexm,
774
                                'callback_data' => $prefix . '/' . $indexm
775
                            ],
776
                            [
777
                                'text' => '• ' . $index . ' •',
778
                                'callback_data' => $prefix . '/' . $index
779
                            ]
780
                        ];
781
                }
782
            }
783
        }
784
785
        // If there are other buttons in this row (checking the column)
786 1
        if ($this->column !== 0) {
787
            // Go to the next
788
            $this->changeRow();
789
        }
790
791 1
        $this->inline_keyboard[$this->row] = $buttons;
792
793
        // We added a row
794 1
        $this->changeRow();
795 1
    }
796
797
    /** @} */
798
799
    /** @} */
800
}
801