Total Complexity | 50 |
Total Lines | 462 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like doc_generic_recruitmentjobposition_odt often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use doc_generic_recruitmentjobposition_odt, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
45 | class doc_generic_recruitmentjobposition_odt extends ModelePDFRecruitmentJobPosition |
||
46 | { |
||
47 | /** |
||
48 | * Issuer |
||
49 | * @var Societe |
||
50 | */ |
||
51 | public $emetteur; |
||
52 | |||
53 | /** |
||
54 | * @var array{0:int,1:int} Minimum version of PHP required by module. |
||
55 | * e.g.: PHP ≥ 7.0 = array(7, 0) |
||
56 | */ |
||
57 | public $phpmin = array(7, 0); |
||
58 | |||
59 | /** |
||
60 | * @var string Dolibarr version of the loaded document |
||
61 | */ |
||
62 | public $version = 'dolibarr'; |
||
63 | |||
64 | |||
65 | /** |
||
66 | * Constructor |
||
67 | * |
||
68 | * @param DoliDB $db Database handler |
||
69 | */ |
||
70 | public function __construct($db) |
||
71 | { |
||
72 | global $conf, $langs, $mysoc; |
||
73 | |||
74 | // Load translation files required by the page |
||
75 | $langs->loadLangs(array("main", "companies")); |
||
76 | |||
77 | $this->db = $db; |
||
78 | $this->name = "ODT templates"; |
||
79 | $this->description = $langs->trans("DocumentModelOdt"); |
||
80 | $this->scandir = 'RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
||
81 | |||
82 | // Page size for A4 format |
||
83 | $this->type = 'odt'; |
||
84 | $this->page_largeur = 0; |
||
85 | $this->page_hauteur = 0; |
||
86 | $this->format = array($this->page_largeur, $this->page_hauteur); |
||
87 | $this->marge_gauche = 0; |
||
88 | $this->marge_droite = 0; |
||
89 | $this->marge_haute = 0; |
||
90 | $this->marge_basse = 0; |
||
91 | |||
92 | $this->option_logo = 1; // Display logo |
||
93 | $this->option_tva = 0; // Manage the vat option COMMANDE_TVAOPTION |
||
94 | $this->option_modereg = 0; // Display payment mode |
||
95 | $this->option_condreg = 0; // Display payment terms |
||
96 | $this->option_multilang = 1; // Available in several languages |
||
97 | $this->option_escompte = 0; // Displays if there has been a discount |
||
98 | $this->option_credit_note = 0; // Support credit notes |
||
99 | $this->option_freetext = 1; // Support add of a personalised text |
||
100 | $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
||
101 | |||
102 | // Get source company |
||
103 | $this->emetteur = $mysoc; |
||
104 | if (!$this->emetteur->country_code) { |
||
105 | $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
||
106 | } |
||
107 | } |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Return description of a module |
||
112 | * |
||
113 | * @param Translate $langs Lang object to use for output |
||
114 | * @return string Description |
||
115 | */ |
||
116 | public function info($langs) |
||
117 | { |
||
118 | global $conf, $langs; |
||
119 | |||
120 | // Load translation files required by the page |
||
121 | $langs->loadLangs(array("errors", "companies")); |
||
122 | |||
123 | $form = new Form($this->db); |
||
124 | |||
125 | $texte = $this->description . ".<br>\n"; |
||
126 | $texte .= '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST" enctype="multipart/form-data">'; |
||
127 | $texte .= '<input type="hidden" name="token" value="' . newToken() . '">'; |
||
128 | $texte .= '<input type="hidden" name="page_y" value="">'; |
||
129 | $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
||
130 | $texte .= '<input type="hidden" name="param1" value="RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH">'; |
||
131 | $texte .= '<table class="nobordernopadding centpercent">'; |
||
132 | |||
133 | // List of directories area |
||
134 | $texte .= '<tr><td>'; |
||
135 | $texttitle = $langs->trans("ListOfDirectories"); |
||
136 | $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim(getDolGlobalString('RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH')))); |
||
137 | $listoffiles = array(); |
||
138 | foreach ($listofdir as $key => $tmpdir) { |
||
139 | $tmpdir = trim($tmpdir); |
||
140 | $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
||
141 | if (!$tmpdir) { |
||
142 | unset($listofdir[$key]); |
||
143 | continue; |
||
144 | } |
||
145 | if (!is_dir($tmpdir)) { |
||
146 | $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
||
147 | } else { |
||
148 | $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
||
149 | if (count($tmpfiles)) { |
||
150 | $listoffiles = array_merge($listoffiles, $tmpfiles); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
||
155 | // Add list of substitution keys |
||
156 | $texthelp .= '<br>' . $langs->trans("FollowingSubstitutionKeysCanBeUsed") . '<br>'; |
||
157 | $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
||
158 | |||
159 | $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
||
160 | $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
||
161 | $texte .= '<textarea class="flat" cols="60" name="value1">'; |
||
162 | $texte .= getDolGlobalString('RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH'); |
||
163 | $texte .= '</textarea>'; |
||
164 | $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
||
165 | $texte .= '<input type="submit" class="button small reposition" name="modify" value="' . $langs->trans("Modify") . '">'; |
||
166 | $texte .= '<br></div></div>'; |
||
167 | |||
168 | // Scan directories |
||
169 | $nbofiles = count($listoffiles); |
||
170 | if (getDolGlobalString('RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH')) { |
||
171 | $texte .= $langs->trans("NumberOfModelFilesFound") . ': <b>'; |
||
172 | //$texte.=$nbofiles?'<a id="a_'.get_only_class($this).'" href="#">':''; |
||
173 | $texte .= count($listoffiles); |
||
174 | //$texte.=$nbofiles?'</a>':''; |
||
175 | $texte .= '</b>'; |
||
176 | } |
||
177 | |||
178 | if ($nbofiles) { |
||
179 | $texte .= '<div id="div_' . get_only_class($this) . '" class="hidden">'; |
||
180 | foreach ($listoffiles as $file) { |
||
181 | $texte .= '- ' . $file['name']; |
||
182 | //$texte .= ' <a href="'.DOL_URL_ROOT.'/document.php?modulepart=doctemplates&file=recruitementjobposition/'.urlencode(basename($file['name'])).'">'.img_picto('', 'listlight').'</a>'; |
||
183 | //$texte .= ' <a class="reposition" href="'.$_SERVER["PHP_SELF"].'?modulepart=doctemplates&keyforuploaddir=RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH&action=deletefile&token='.newToken().'&file='.urlencode(basename($file['name'])).'">'.img_picto('', 'delete').'</a>'; |
||
184 | $texte .= '<br>'; |
||
185 | } |
||
186 | $texte .= '</div>'; |
||
187 | } |
||
188 | // Add input to upload a new template file. |
||
189 | $texte .= '<div>' . $langs->trans("UploadNewTemplate"); |
||
190 | $maxfilesizearray = getMaxFileSizeArray(); |
||
191 | $maxmin = $maxfilesizearray['maxmin']; |
||
192 | if ($maxmin > 0) { |
||
193 | $texte .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxmin * 1024) . '">'; // MAX_FILE_SIZE must precede the field type=file |
||
194 | } |
||
195 | $texte .= ' <input type="file" name="uploadfile">'; |
||
196 | $texte .= '<input type="hidden" value="RECRUITMENT_RECRUITMENTJOBPOSITION_ADDON_PDF_ODT_PATH" name="keyforuploaddir">'; |
||
197 | $texte .= '<input type="submit" class="button smallpaddingimp reposition" value="' . dol_escape_htmltag($langs->trans("Upload")) . '" name="upload">'; |
||
198 | $texte .= '</div>'; |
||
199 | $texte .= '</td>'; |
||
200 | |||
201 | $texte .= '<td rowspan="2" class="tdtop hideonsmartphone">'; |
||
202 | $texte .= '<span class="opacitymedium">'; |
||
203 | $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
||
204 | $texte .= '</span>'; |
||
205 | $texte .= '</td>'; |
||
206 | $texte .= '</tr>'; |
||
207 | |||
208 | $texte .= '</table>'; |
||
209 | $texte .= '</form>'; |
||
210 | |||
211 | return $texte; |
||
212 | } |
||
213 | |||
214 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
215 | /** |
||
216 | * Function to build a document on disk using the generic odt module. |
||
217 | * |
||
218 | * @param RecruitmentJobPosition $object Object source to build document |
||
219 | * @param Translate $outputlangs Lang output object |
||
220 | * @param string $srctemplatepath Full path of source filename for generator using a template file |
||
221 | * @param int $hidedetails Do not show line details |
||
222 | * @param int $hidedesc Do not show desc |
||
223 | * @param int $hideref Do not show ref |
||
224 | * @return int 1 if OK, <=0 if KO |
||
225 | */ |
||
226 | public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
||
507 | } |
||
508 | } |
||
509 |