Skip to content

Commit

Permalink
version 1.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
maniaba committed Feb 6, 2023
1 parent 494e047 commit 1603c2a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 40 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maniaba/tctable",
"version": "1.2.5",
"version": "1.2.6",
"description": "Create quickly and efficiently tables without HTML formatting and with advanced page break options",
"keywords": [
"maniaba",
Expand Down Expand Up @@ -29,12 +29,12 @@
},
"autoload": {
"psr-4": {
"voilab\\tctable\\": "src"
"maniaba\\tctable\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"voilab\\tctable\\test\\": "tests"
"maniaba\\tctable\\test\\": "tests"
}
}
}
39 changes: 21 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Voilab TcTable for TCPDF
# TcTable for TCPDF

## Install

Expand All @@ -8,13 +8,13 @@ Create a composer.json file in your project root:
``` json
{
"require": {
"voilab/tctable": "1.*"
"maniaba/tctable": "1.*"
}
}
```

``` bash
$ composer require voilab/tctable
$ composer require maniaba/tctable
```

## Usage
Expand All @@ -25,11 +25,12 @@ the number of widow lines (minimum of lines that must appear on the last page),
and use plugins to customize the flow (see below).

### Basic usage

```php
$pdf = new \TCPDF();
$minRowHeight = 6; //mm

$tctable = new \voilab\tctable\TcTable($pdf, $minRowHeight);
$tctable = new \maniaba\tctable\TcTable($pdf, $minRowHeight);
$tctable->setColumns([
'description' => [
'isMultiLine' => true,
Expand All @@ -56,7 +57,7 @@ $rows = getMyDatasAsMyObjs();
// add a page so the content can be printed on something
$pdf->AddPage();
// draw body
$tctable->addBody($rows, function (\voilab\tctable\TcTable $table, \MyObj $row) {
$tctable->addBody($rows, function (\maniaba\tctable\TcTable $table, \MyObj $row) {
$change_rate = 0.8;
// map row data to TcTable column definitions
return [
Expand All @@ -71,9 +72,10 @@ $pdf->Output('tctable.pdf', 'I');

### Plugins
#### Have a column that fit the remaining page width

```php
$tctable
->addPlugin(new \voilab\tctable\plugin\FitColumn('text'))
->addPlugin(new \maniaba\tctable\plugin\FitColumn('text'))
->addColumn('text', [
'isMultiLine' => true,
'header' => 'Text'
Expand All @@ -83,13 +85,15 @@ $tctable
```

#### Stripe rows

```php
$tctable
// set true to have the first line with colored background
->addPlugin(new \voilab\tctable\plugin\StripeRows(true));
->addPlugin(new \maniaba\tctable\plugin\StripeRows(true));
```

#### Widows management

```php
// set the minimum elements you want to see on the last page (if any)
$nb = 4;
Expand All @@ -98,17 +102,18 @@ $nb = 4;
// to add to the pageBreakTrigger margin this line height: the footer
$mFooter = 10; // i.e: mm

$tctable->addPlugin(new \voilab\tctable\plugin\Widows($nb, $mFooter));
$tctable->addPlugin(new \maniaba\tctable\plugin\Widows($nb, $mFooter));
```

#### Debug
The TcTable comes with a debug plugin tool that display datas passed in each
event.

```php
// create the plugin. You can define which events to listen (default to rowadd,
// rowadded, rowskipped, headeradd, headeradded, pageadd and pageadded) and the
// printer object (default to an HTML output with <pre>)
$debug = new \voilab\tctable\plugin\Debug();
$debug = new \maniaba\tctable\plugin\Debug();
$debug
->setBounds($fromIndex = 0, $numberOfRows = 2, $dieWhenOutOfBounds = true);

Expand All @@ -119,8 +124,9 @@ $tctable->addPlugin($debug);
```

You can extend the printer object by creating your own:

```php
class MyDebugPrinter implements \voilab\tctable\plugin\debug\PrinterInterface {
class MyDebugPrinter implements \maniaba\tctable\plugin\debug\PrinterInterface {

public function output(TcTable $table, array $data) {
// do something, log, etc.
Expand All @@ -137,13 +143,14 @@ $debug->setPrinter(new MyDebugPrinter());
#### Advanced plugin: draw a subtotal for a column at end of each page
We can go further by calculating a sum for a column, and display the current
sum at the end of the page, and finally report it on the next page.

```php
<?php

namespace your\namespace;

use voilab\tctable\TcTable;
use voilab\tctable\Plugin;
use maniaba\tctable\TcTable;
use maniaba\tctable\Plugin;

class Report implements Plugin {

Expand Down Expand Up @@ -213,8 +220,9 @@ can simply define events without the need of plugins. It allows us to add some
usefull methods.

#### Add headers on each new page

```php
use \voilab\tctable\TcTable;
use maniaba\tctable\TcTable;
// ... create tctable

$tctable
Expand Down Expand Up @@ -333,11 +341,6 @@ $ phpunit

If you discover any security related issues, please use the issue tracker.

## Credits

- [tafel](https://github.com/tafel)
- [voilab](https://github.com/voilab)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace voilab\tctable;
namespace maniaba\tctable;

interface Plugin {

Expand Down
2 changes: 1 addition & 1 deletion src/TcTable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace voilab\tctable;
namespace maniaba\tctable;

/**
* This class can quickly and easily draw tables with an advanced management
Expand Down
6 changes: 3 additions & 3 deletions src/plugin/Debug.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace voilab\tctable\plugin;
namespace maniaba\tctable\plugin;

use voilab\tctable\TcTable;
use voilab\tctable\Plugin;
use maniaba\tctable\TcTable;
use maniaba\tctable\Plugin;

class Debug implements Plugin {

Expand Down
6 changes: 3 additions & 3 deletions src/plugin/FitColumn.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace voilab\tctable\plugin;
namespace maniaba\tctable\plugin;

use voilab\tctable\TcTable;
use voilab\tctable\Plugin;
use maniaba\tctable\TcTable;
use maniaba\tctable\Plugin;

class FitColumn implements Plugin {

Expand Down
6 changes: 3 additions & 3 deletions src/plugin/StripeRows.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace voilab\tctable\plugin;
namespace maniaba\tctable\plugin;

use voilab\tctable\TcTable;
use voilab\tctable\Plugin;
use maniaba\tctable\TcTable;
use maniaba\tctable\Plugin;

class StripeRows implements Plugin {

Expand Down
6 changes: 3 additions & 3 deletions src/plugin/Widows.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace voilab\tctable\plugin;
namespace maniaba\tctable\plugin;

use voilab\tctable\TcTable;
use voilab\tctable\Plugin;
use maniaba\tctable\TcTable;
use maniaba\tctable\Plugin;

class Widows implements Plugin {

Expand Down
4 changes: 2 additions & 2 deletions src/plugin/debug/PrinterHtml.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace voilab\tctable\plugin\debug;
namespace maniaba\tctable\plugin\debug;

use voilab\tctable\plugin\Debug;
use maniaba\tctable\plugin\Debug;

class PrinterHtml implements PrinterInterface {

Expand Down
4 changes: 2 additions & 2 deletions src/plugin/debug/PrinterInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace voilab\tctable\plugin\debug;
namespace maniaba\tctable\plugin\debug;

use voilab\tctable\plugin\Debug;
use maniaba\tctable\plugin\Debug;

interface PrinterInterface {

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace voilab\tctable\test;
namespace maniaba\tctable\test;

class TestCase extends \PHPUnit_Framework_TestCase {

Expand Down

0 comments on commit 1603c2a

Please sign in to comment.