Conditions | 58 |
Paths | > 20000 |
Total Lines | 172 |
Code Lines | 110 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
117 | public function getBannerAddress($htmlkey, $object) |
||
118 | { |
||
119 | global $conf, $langs, $form, $extralanguages; |
||
120 | |||
121 | $countriesusingstate = ['AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR']; // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
||
122 | |||
123 | $contactid = 0; |
||
124 | $thirdpartyid = 0; |
||
125 | $elementforaltlanguage = $this->element; |
||
126 | if ($this->element == 'societe') { |
||
127 | /** @var Societe $this */ |
||
128 | $thirdpartyid = $this->id; |
||
129 | } |
||
130 | if ($this->element == 'contact') { |
||
131 | /** @var Contact $this */ |
||
132 | $contactid = $this->id; |
||
133 | $thirdpartyid = empty($this->fk_soc) ? 0 : $this->fk_soc; |
||
134 | } |
||
135 | if ($this->element == 'user') { |
||
136 | /** @var User $this */ |
||
137 | $contactid = $this->contact_id; |
||
138 | $thirdpartyid = empty($object->fk_soc) ? 0 : $object->fk_soc; |
||
139 | } |
||
140 | |||
141 | $out = ''; |
||
142 | |||
143 | $outdone = 0; |
||
144 | $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT')); |
||
|
|||
145 | if ($coords) { |
||
146 | if (!empty($conf->use_javascript_ajax)) { |
||
147 | // Add picto with tooltip on map |
||
148 | $namecoords = ''; |
||
149 | if ($this->element == 'contact' && getDolGlobalString('MAIN_SHOW_COMPANY_NAME_IN_BANNER_ADDRESS')) { |
||
150 | $namecoords .= $object->name . '<br>'; |
||
151 | } |
||
152 | $namecoords .= $this->getFullName($langs, 1) . '<br>' . $coords; |
||
153 | // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
||
154 | $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\'' . dol_escape_js($namecoords) . '\',\'' . dol_escape_js($langs->trans("HelpCopyToClipboard")) . '\');">'; |
||
155 | $out .= img_picto($langs->trans("Address"), 'map-marker-alt'); |
||
156 | $out .= '</a> '; |
||
157 | } |
||
158 | $address = dol_print_address($coords, 'address_' . $htmlkey . '_' . $this->id, $this->element, $this->id, 1, ', '); |
||
159 | if ($address) { |
||
160 | $out .= $address; |
||
161 | $outdone++; |
||
162 | } |
||
163 | $outdone++; |
||
164 | |||
165 | // List of extra languages |
||
166 | $arrayoflangcode = []; |
||
167 | if (getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE')) { |
||
168 | $arrayoflangcode[] = getDolGlobalString('PDF_USE_ALSO_LANGUAGE_CODE'); |
||
169 | } |
||
170 | |||
171 | if (is_array($arrayoflangcode) && count($arrayoflangcode)) { |
||
172 | if (!is_object($extralanguages)) { |
||
173 | include_once DOL_DOCUMENT_ROOT . '/core/class/extralanguages.class.php'; |
||
174 | $extralanguages = new ExtraLanguages($this->db); |
||
175 | } |
||
176 | $extralanguages->fetch_name_extralanguages($elementforaltlanguage); |
||
177 | |||
178 | if (!empty($extralanguages->attributes[$elementforaltlanguage]['address']) || !empty($extralanguages->attributes[$elementforaltlanguage]['town'])) { |
||
179 | $out .= "<!-- alternatelanguage for '" . $elementforaltlanguage . "' set to fields '" . implode(',', $extralanguages->attributes[$elementforaltlanguage]) . "' -->\n"; |
||
180 | $this->fetchValuesForExtraLanguages(); |
||
181 | if (!is_object($form)) { |
||
182 | $form = new Form($this->db); |
||
183 | } |
||
184 | $htmltext = ''; |
||
185 | // If there is extra languages |
||
186 | foreach ($arrayoflangcode as $extralangcode) { |
||
187 | $s = picto_from_langcode($extralangcode, 'class="pictoforlang paddingright"'); |
||
188 | // This also call dol_format_address() |
||
189 | $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT, $extralangcode); |
||
190 | $htmltext .= $s . dol_print_address($coords, 'address_' . $htmlkey . '_' . $this->id, $this->element, $this->id, 1, ', '); |
||
191 | } |
||
192 | $out .= $form->textwithpicto('', $htmltext, -1, 'language', 'opacitymedium paddingleft'); |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | |||
197 | // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
||
198 | if ( |
||
199 | !in_array($this->country_code, $countriesusingstate) && !getDolGlobalString('MAIN_FORCE_STATE_INTO_ADDRESS') |
||
200 | && !getDolGlobalString('SOCIETE_DISABLE_STATE') && $this->state |
||
201 | ) { |
||
202 | if (getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT') == 1 && $this->region) { |
||
203 | $out .= ($outdone ? ' - ' : '') . $this->region . ' - ' . $this->state; |
||
204 | } else { |
||
205 | $out .= ($outdone ? ' - ' : '') . $this->state; |
||
206 | } |
||
207 | $outdone++; |
||
208 | } |
||
209 | |||
210 | if ($outdone) { |
||
211 | $out = '<div class="address inline-block">' . $out . '</div>'; |
||
212 | } |
||
213 | |||
214 | if (!empty($this->phone) || !empty($this->phone_pro) || !empty($this->phone_mobile) || !empty($this->phone_perso) || !empty($this->fax) || !empty($this->office_phone) || !empty($this->user_mobile) || !empty($this->office_fax)) { |
||
215 | $out .= ($outdone ? '<br>' : ''); |
||
216 | } |
||
217 | if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
||
218 | $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); |
||
219 | $outdone++; |
||
220 | } |
||
221 | if (!empty($this->phone_pro)) { |
||
222 | $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); |
||
223 | $outdone++; |
||
224 | } |
||
225 | if (!empty($this->phone_mobile)) { |
||
226 | $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); |
||
227 | $outdone++; |
||
228 | } |
||
229 | if (!empty($this->phone_perso)) { |
||
230 | $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePerso")); |
||
231 | $outdone++; |
||
232 | } |
||
233 | if (!empty($this->office_phone)) { |
||
234 | $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); |
||
235 | $outdone++; |
||
236 | } |
||
237 | if (!empty($this->user_mobile)) { |
||
238 | $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); |
||
239 | $outdone++; |
||
240 | } |
||
241 | if (!empty($this->fax)) { |
||
242 | $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); |
||
243 | $outdone++; |
||
244 | } |
||
245 | if (!empty($this->office_fax)) { |
||
246 | $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); |
||
247 | $outdone++; |
||
248 | } |
||
249 | |||
250 | if ($out) { |
||
251 | $out .= '<div style="clear: both;"></div>'; |
||
252 | } |
||
253 | $outdone = 0; |
||
254 | if (!empty($this->email)) { |
||
255 | $out .= dol_print_email($this->email, $this->id, $object->id, 1, 0, 0, 1); |
||
256 | $outdone++; |
||
257 | } |
||
258 | if (!empty($this->url)) { |
||
259 | //$out.=dol_print_url($this->url,'_goout',0,1);//steve changed to blank |
||
260 | if (!empty($this->email)) { |
||
261 | $out .= ' '; |
||
262 | } |
||
263 | $out .= dol_print_url($this->url, '_blank', 0, 1); |
||
264 | $outdone++; |
||
265 | } |
||
266 | |||
267 | if (isModEnabled('socialnetworks')) { |
||
268 | $outsocialnetwork = ''; |
||
269 | |||
270 | if (!empty($this->socialnetworks) && is_array($this->socialnetworks) && count($this->socialnetworks) > 0) { |
||
271 | $socialnetworksdict = getArrayOfSocialNetworks(); |
||
272 | foreach ($this->socialnetworks as $key => $value) { |
||
273 | if ($value) { |
||
274 | $outsocialnetwork .= dol_print_socialnetworks($value, $this->id, $object->id, $key, $socialnetworksdict); |
||
275 | } |
||
276 | $outdone++; |
||
277 | } |
||
278 | } |
||
279 | |||
280 | if ($outsocialnetwork) { |
||
281 | $out .= '<div style="clear: both;">' . $outsocialnetwork . '</div>'; |
||
282 | } |
||
283 | } |
||
284 | |||
285 | if ($out) { |
||
286 | return '<!-- BEGIN part to show address block -->' . "\n" . $out . '<!-- END Part to show address block -->' . "\n"; |
||
287 | } else { |
||
288 | return ''; |
||
289 | } |
||
326 |