Passed
Push — GENERAL_BUG_REVIEW_240911 ( 3362b2...8cbbee )
by Rafael
49:13
created

PrintingDriver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A listDrivers() 0 23 5
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * Copyright (C) 2014-2023  Frederic France             <[email protected]>
5
 * Copyright (C) 2024		MDW							<[email protected]>
6
 * Copyright (C) 2024       Rafael San José             <[email protected]>
7
 *
8
 * This program is free software; you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation; either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
 * or see https://www.gnu.org/
21
 */
22
23
namespace Dolibarr\Code\Printing\Classes;
24
25
use DoliDB;
26
27
/**
28
 *      \file       htdocs/core/modules/printing/modules_printing.php
29
 *      \ingroup    printing
30
 *      \brief      File with parent class of printing modules
31
 */
32
33
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/functions.lib.php';
34
require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
35
36
/**
37
 *      Parent class of emailing target selectors modules
38
 */
39
class PrintingDriver
40
{
41
    /**
42
     * @var DoliDB Database handler.
43
     */
44
    public $db;
45
46
    /**
47
     * @var string Error code (or message)
48
     */
49
    public $error = '';
50
51
    /**
52
     * @var string Name
53
     */
54
    public $name;
55
56
    /**
57
     * @var string Description
58
     */
59
    public $desc;
60
61
    /**
62
     * @var string Html string returned for print
63
     */
64
    public $resprint;
65
66
    /**
67
     *  Constructor
68
     *
69
     * @param DoliDB $db Database handler
70
     */
71
    public function __construct($db)
72
    {
73
        $this->db = $db;
74
    }
75
76
    /**
77
     *  Return list of printing driver
78
     *
79
     * @param DoliDB $db Database handler
80
     * @param int $maxfilenamelength Max length of value to show
81
     * @return array<string,string>        List of drivers
82
     */
83
    public static function listDrivers($db, $maxfilenamelength = 0)
84
    {
85
        global $conf;
86
87
        $type = 'printing';
88
        $list = array();
89
90
        $listoffiles = array();
91
        if (!empty($conf->modules_parts['printing'])) {
92
            $dirmodels = array_merge(array('/core/modules/printing/'), (array)$conf->modules_parts['printing']);
93
        } else {
94
            $dirmodels = array('/core/modules/printing/');
95
        }
96
        foreach ($dirmodels as $dir) {
97
            $tmpfiles = dol_dir_list(dol_buildpath($dir, 0), 'all', 0, '\.modules.php', '', 'name', SORT_ASC, 0);
98
            if (!empty($tmpfiles)) {
99
                $listoffiles = array_merge($listoffiles, $tmpfiles);
100
            }
101
        }
102
        foreach ($listoffiles as $record) {
103
            $list[$record['fullname']] = str_replace('.modules.php', '', $record['name']);
104
        }
105
        return $list;
106
    }
107
108
    /**
109
     *  Return description of Printing Module
110
     *
111
     * @return     string      Return translation of key PrintingModuleDescXXX where XXX is module name, or $this->desc if not exists
112
     */
113
    public function getDesc()
114
    {
115
        global $langs;
116
        $langs->load("printing");
117
        $transstring = "PrintingModuleDesc" . $this->name;
118
        if ($langs->trans($transstring) != $transstring) {
119
            return $langs->trans($transstring);
120
        } else {
121
            return $this->desc;
122
        }
123
    }
124
}
125