1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2024 Rafael San José <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Dolibarr\Lib; |
20
|
|
|
|
21
|
|
|
use Illuminate\Database\Capsule\Manager as DB; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class AveryLabels |
25
|
|
|
*/ |
26
|
|
|
class AveryLabels |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Contains label information. |
30
|
|
|
* |
31
|
|
|
* @var array|null |
32
|
|
|
*/ |
33
|
|
|
private static $averyLabels; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the label array statically |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
public static function getAveryLabels(): array |
41
|
|
|
{ |
42
|
|
|
if (!isset(self::$averyLabels)) { |
43
|
|
|
self::$averyLabels = self::loadAveryLabels(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return self::$averyLabels; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Loads the info into static averyLabels var. |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
private static function loadAveryLabels() |
55
|
|
|
{ |
56
|
|
|
/** |
57
|
|
|
* Unit of metric are defined into field 'metric' in mm. |
58
|
|
|
* To get into inch, just /25.4 |
59
|
|
|
* Size of pages available on: http://www.worldlabel.com/Pages/pageaverylabels.htm |
60
|
|
|
* _PosX = marginLeft+(_COUNTX*(width+SpaceX)); |
61
|
|
|
*/ |
62
|
|
|
|
63
|
|
|
$sql = "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM " . MAIN_DB_PREFIX . "c_format_cards WHERE active=1 ORDER BY code ASC"; |
64
|
|
|
$labels = DB::select($sql); |
65
|
|
|
$result = []; |
66
|
|
|
foreach ($labels as $label) { |
67
|
|
|
$result[$label->code] = [ |
68
|
|
|
'name' => $label->name . ' (' . $label->paper_size . ' - ' . $label->nx . 'x' . $label->ny . ')', |
69
|
|
|
'paper-size' => $label->paper_size, |
70
|
|
|
'orientation' => $label->orientation, |
71
|
|
|
'metric' => $label->metric, |
72
|
|
|
'marginLeft' => $label->leftmargin, |
73
|
|
|
'marginTop' => $label->topmargin, |
74
|
|
|
'NX' => $label->nx, |
75
|
|
|
'NY' => $label->ny, |
76
|
|
|
'SpaceX' => $label->spacex, |
77
|
|
|
'SpaceY' => $label->spacey, |
78
|
|
|
'width' => $label->width, |
79
|
|
|
'height' => $label->height, |
80
|
|
|
'font-size' => $label->font_size, |
81
|
|
|
'custom_x' => $label->custom_x, |
82
|
|
|
'custom_y' => $label->custom_y, |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
return $result; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|