Add missing classes
This commit is contained in:
8
core/src/Classes/Authorizable.php
Normal file
8
core/src/Classes/Authorizable.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Classes;
|
||||
|
||||
interface Authorizable
|
||||
{
|
||||
public function granted() : bool;
|
||||
}
|
||||
162
core/src/Classes/Pdf/BasePdfTemplate.php
Normal file
162
core/src/Classes/Pdf/BasePdfTemplate.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
namespace Classes\Pdf;
|
||||
|
||||
use Classes\SettingsManager;
|
||||
|
||||
class BasePdfTemplate extends \FPDF
|
||||
{
|
||||
protected $title;
|
||||
protected $date;
|
||||
|
||||
const WIDTH = 210;
|
||||
|
||||
public function initialize($title)
|
||||
{
|
||||
$this->AliasNbPages();
|
||||
$this->AddPage();
|
||||
$this->SetTitle($title);
|
||||
$this->date = $date = date('c');
|
||||
}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
function Header()
|
||||
{
|
||||
// Logo
|
||||
try {
|
||||
$this->Image(\Classes\UIManager::getInstance()->getCompanyLogoUrl(), 10, 10, 0, 10);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
PdfColour::setTextColor($this, PdfColour::GREY_100);
|
||||
// Arial bold 15
|
||||
$this->SetFont('Arial', '', 9);
|
||||
// Company name
|
||||
$companyName = SettingsManager::getInstance()->getSetting('Company: Name');
|
||||
$this->Cell(30, 23, $companyName, 0, 0, 'L');
|
||||
PdfColour::setDrawColor($this, PdfColour::GREY_100);
|
||||
$this->Line(10, 26, self::WIDTH - 10, 26);
|
||||
// Line break
|
||||
$this->Ln(20);
|
||||
}
|
||||
|
||||
function Footer()
|
||||
{
|
||||
PdfColour::setTextColor($this, PdfColour::GREY_100);
|
||||
// Position at 1.5 cm from bottom
|
||||
$this->SetY(-15);
|
||||
// Arial italic 8
|
||||
$this->SetFont('Arial', 'I', 8);
|
||||
// Page number
|
||||
$this->Cell(0, 10, 'Page '.$this->PageNo().'/{nb}, Date:'.$this->date, 0, 0, 'C');
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
public function addH1($title, $style = 'B', $textAlignment = 'C')
|
||||
{
|
||||
$this->addH($title, $style, $textAlignment, 21);
|
||||
}
|
||||
|
||||
public function addH2($title, $style = 'B', $textAlignment = 'C')
|
||||
{
|
||||
$this->addH($title, $style, $textAlignment, 17);
|
||||
}
|
||||
|
||||
public function addH3($title, $style = 'B', $textAlignment = 'C')
|
||||
{
|
||||
$this->addH($title, $style, $textAlignment, 14);
|
||||
}
|
||||
|
||||
public function addH($title, $style = 'B', $textAlignment = 'C', $fontSize = 16)
|
||||
{
|
||||
PdfColour::setTextColor($this, PdfColour::BLACK_LIGHT);
|
||||
$this->SetFont('Arial', $style, $fontSize);
|
||||
$this->Cell(0, 10, $title, 0, 1, $textAlignment);
|
||||
}
|
||||
|
||||
public function addBorderedText($text)
|
||||
{
|
||||
$this->addText($text, '', 'L', 10, PdfColour::BLACK_LIGHT, 1, PdfColour::GREY_DARK);
|
||||
}
|
||||
|
||||
public function addText(
|
||||
$text,
|
||||
$style = '',
|
||||
$textAlignment = 'L',
|
||||
$fontSize = 10,
|
||||
$color = PdfColour::BLACK_LIGHT,
|
||||
$cellBorder = 0,
|
||||
$cellBorderColor = PdfColour::GREY_DARK
|
||||
) {
|
||||
PdfColour::setTextColor($this, $color);
|
||||
$this->SetFont('Arial', $style, $fontSize);
|
||||
if ($cellBorder === 1) {
|
||||
PdfColour::setDrawColor($this, $cellBorderColor);
|
||||
}
|
||||
PdfColour::setFillColor($this, PdfColour::WHITE);
|
||||
$this->MultiCell(0, 5, $text, $cellBorder, 1, $textAlignment);
|
||||
}
|
||||
|
||||
public function addKeyValue($key, $value, $type = 'text')
|
||||
{
|
||||
PdfColour::setDrawColor($this, PdfColour::GREY_DARK);
|
||||
PdfColour::setFillColor($this, PdfColour::GREY);
|
||||
|
||||
|
||||
if ($type === 'textarea') {
|
||||
$this->Cell(0, 10, $key, 1, 1, 'L', true);
|
||||
} else {
|
||||
$this->Cell(80, 10, $key, 1, 0, 'L', true);
|
||||
}
|
||||
|
||||
PdfColour::setFillColor($this, PdfColour::WHITE);
|
||||
|
||||
if ($type === 'textarea') {
|
||||
$this->MultiCell(0, 5, $value, 1, 1, 'L');
|
||||
} elseif ($type === 'date') {
|
||||
$value = date('Y-m-d', strtotime($value));
|
||||
$this->Cell(110, 10, $value, 1, 1, 'L', true);
|
||||
} elseif ($type === 'select2multi') {
|
||||
$value = json_decode($value, true);
|
||||
$value = !empty($value) ? join(',', $value) : '';
|
||||
$this->Cell(110, 10, $value, 1, 1, 'L', true);
|
||||
} else {
|
||||
$this->Cell(110, 10, $value, 1, 1, 'L', true);
|
||||
}
|
||||
}
|
||||
|
||||
public function addKeyValueObject($key, $value)
|
||||
{
|
||||
PdfColour::setDrawColor($this, PdfColour::GREY_DARK);
|
||||
PdfColour::setFillColor($this, PdfColour::GREY);
|
||||
$this->Cell(80, 10, $key, 1, 0, 'L', true);
|
||||
|
||||
PdfColour::setFillColor($this, PdfColour::WHITE);
|
||||
$this->MultiCell(110, 10, $value, 1, 1, true);
|
||||
}
|
||||
|
||||
public function addHR($width = 0)
|
||||
{
|
||||
$this->Ln(2);
|
||||
PdfColour::setDrawColor($this, PdfColour::GREY_DARK);
|
||||
PdfColour::setFillColor($this, PdfColour::GREY_DARK);
|
||||
$this->Cell($width, 0.2, '', 0, 0, '', true);
|
||||
// Line break
|
||||
$this->Ln(3);
|
||||
}
|
||||
|
||||
public function getImageFromDataURI($dataURI)
|
||||
{
|
||||
$img = explode(',', $dataURI, 2)[1];
|
||||
return 'data://text/plain;base64,'. $img;
|
||||
}
|
||||
|
||||
public function addSignature($name, $data)
|
||||
{
|
||||
$image = $this->getImageFromDataURI($data);
|
||||
$this->Ln(10);
|
||||
$this->Image($image, $this->GetX(), $this->GetY(), 30, 0, 'png');
|
||||
$this->Ln(30);
|
||||
$this->addHR(30);
|
||||
$this->addText($name);
|
||||
}
|
||||
}
|
||||
27
core/src/Classes/Pdf/PDFRegister.php
Normal file
27
core/src/Classes/Pdf/PDFRegister.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Classes\Pdf;
|
||||
|
||||
use Forms\Common\EmployeeFormPDFBuilder;
|
||||
|
||||
class PDFRegister
|
||||
{
|
||||
protected static $register = [];
|
||||
|
||||
public static function init()
|
||||
{
|
||||
self::put('empf', function ($data) {
|
||||
return new EmployeeFormPDFBuilder($data);
|
||||
});
|
||||
}
|
||||
|
||||
public static function put($key, $callback)
|
||||
{
|
||||
self::$register[$key] = $callback;
|
||||
}
|
||||
|
||||
public static function get($key)
|
||||
{
|
||||
return self::$register[$key];
|
||||
}
|
||||
}
|
||||
8
core/src/Classes/Pdf/PdfBuilder.php
Normal file
8
core/src/Classes/Pdf/PdfBuilder.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Classes\Pdf;
|
||||
|
||||
interface PdfBuilder
|
||||
{
|
||||
public function createPdf();
|
||||
}
|
||||
27
core/src/Classes/Pdf/PdfColour.php
Normal file
27
core/src/Classes/Pdf/PdfColour.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Classes\Pdf;
|
||||
|
||||
class PdfColour
|
||||
{
|
||||
const GREY = [224, 224, 224];
|
||||
const GREY_DARK = [160, 160, 160];
|
||||
const WHITE = [255, 255, 255];
|
||||
const BLACK_LIGHT = [84, 84, 84];
|
||||
const GREY_100 = [100, 100, 100];
|
||||
|
||||
public static function setFillColor(\FPDF $pdf, $color)
|
||||
{
|
||||
$pdf->SetFillColor($color[0], $color[1], $color[2]);
|
||||
}
|
||||
|
||||
public static function setTextColor(\FPDF $pdf, $color)
|
||||
{
|
||||
$pdf->SetTextColor($color[0], $color[1], $color[2]);
|
||||
}
|
||||
|
||||
public static function setDrawColor(\FPDF $pdf, $color)
|
||||
{
|
||||
$pdf->SetDrawColor($color[0], $color[1], $color[2]);
|
||||
}
|
||||
}
|
||||
33
core/src/Classes/StatsHelper.php
Normal file
33
core/src/Classes/StatsHelper.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Classes;
|
||||
|
||||
use Employees\Common\Model\Employee;
|
||||
use Users\Common\Model\User;
|
||||
|
||||
class StatsHelper
|
||||
{
|
||||
public static function getEmployeeCount()
|
||||
{
|
||||
$employee = new Employee();
|
||||
$employeeCount = $employee->DB()->Execute("select count(id) from Employees");
|
||||
if ($employeeCount) {
|
||||
$employeeCount = intval($employeeCount->fields[0]);
|
||||
return $employeeCount;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function getUserCount()
|
||||
{
|
||||
$user = new User();
|
||||
$userCount = $user->DB()->Execute("select count(id) from Users");
|
||||
if ($userCount) {
|
||||
$userCount = intval($userCount->fields[0]);
|
||||
return $userCount;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
8
core/src/Model/SystemData.php
Normal file
8
core/src/Model/SystemData.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
class SystemData extends BaseModel
|
||||
{
|
||||
public $table = 'SystemData';
|
||||
}
|
||||
Reference in New Issue
Block a user