. */ namespace Util; /** * Classe dedicata alla gestione delle righe fantasma per il miglioramento grafico delle stampe tabellari. * * @since 2.3 */ class Autofill { protected $space = 0; protected $current = 0; protected $max_rows = 26; protected $max_rows_first_page = 38; protected $max_additional = 0; public function __construct(protected $column_number, protected $char_number = 70) { } public function setRows($rows, $additional = null, $first_page = null) { $this->max_rows = $rows; $this->max_additional = isset($additional) ? $additional: $this->max_rows; $this->max_rows_first_page = $first_page ?? $this->max_rows_first_page; } public function count($text, $small = null) { $text = strip_tags($text); $count = ceil(strlen($text) / $this->char_number); if ($small) { $count /= 1.538461538; } $this->set($count); } public function set($count) { $this->current += $count; } public function next() { $this->space += $this->current; $this->current = 0; } public function getAdditionalNumber() { if ($this->space <= $this->max_rows) { $page = 1; } else { if ($this->space <= $this->max_rows_first_page) { $page = 2; } else { $page = ceil(1 + (($this->space - $this->max_rows_first_page) / $this->max_rows)); } } if ($page > 1) { $rows = $this->space - $this->max_rows_first_page * ($page - 1); } else { $rows = ceil($this->space); } $number = $this->max_rows - $rows; return $number; } public function generate() { $this->next(); $result = ''; $number = $this->getAdditionalNumber(); for ($i = 0; $i < $number; ++$i) { $result .= ' '; for ($c = 0; $c < $this->column_number; ++$c) { $result .= '  '; } $result .= ' '; } return $result; } }