Passed
Push — EXTRACT_CLASSES ( ae6b5c...83d77a )
by Rafael
60:14 queued 23:58
created

WebPortalPartnership::getNomUrl()   F

Complexity

Conditions 34
Paths > 20000

Size

Total Lines 113
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 34
eloc 75
nc 34560
nop 5
dl 0
loc 113
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
/* Copyright (C) 2023-2024  Laurent Destailleur         <[email protected]>
4
 * Copyright (C) 2023-2024	Lionel Vessiller		    <[email protected]>
5
 * Copyright (C) 2024		MDW							<[email protected]>
6
 * Copyright (C) 2024       Frédéric France             <[email protected]>
7
 * Copyright (C) 2024       Rafael San José             <[email protected]>
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21
 */
22
23
namespace Dolibarr\Code\WebPortal\Classes;
24
25
use Dolibarr\Code\Partnerships\Classes\Partnership;
26
27
/**
28
 * \file        htdocs/webportal/class/webportalpartnership.class.php
29
 * \ingroup     webportal
30
 * \brief       This file is a CRUD class file for WebPortalPartnership (Create/Read/Update/Delete)
31
 */
32
33
/**
34
 * Class for WebPortalPartnership
35
 */
36
class WebPortalPartnership extends Partnership
37
{
38
    /**
39
     * @var string ID of module.
40
     */
41
    public $module = 'webportal';
42
43
    /**
44
     * Status list (short label)
45
     */
46
    const ARRAY_STATUS_LABEL = array(
47
        Partnership::STATUS_DRAFT => 'Draft',
48
        Partnership::STATUS_VALIDATED => 'Accepted',
49
        Partnership::STATUS_APPROVED => 'Refused',
50
        Partnership::STATUS_REFUSED => 'Suspended',
51
        Partnership::STATUS_CANCELED => 'Terminated',
52
    );
53
54
    /**
55
     * @var Partnership Partnership for static methods
56
     */
57
    protected $partnership_static = null;
58
59
    /**
60
     *  'type' field format:
61
     *    'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',
62
     *    'select' (list of values are in 'options'),
63
     *    'varchar(x)',
64
     *    'text', 'html',
65
     *    'double(24,8)', 'price',
66
     *    'date', 'datetime',
67
     *    'checkbox', 'radio',
68
     *    'mail', 'phone', 'url', 'password'
69
     *        Note: Filter must be a Dolibarr Universal Filter syntax string. Example: "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.status:!=:0) or (t.nature:is:NULL)"
70
     *  'label' the translation key.
71
     *  'picto' is code of a picto to show before value in forms
72
     *  'enabled' is a condition when the field must be managed (Example: 1 or 'getDolGlobalInt('MY_SETUP_PARAM') or 'isModEnabled("multicurrency")' ...)
73
     *  'position' is the sort order of field.
74
     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
75
     *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
76
     *  'noteditable' says if field is not editable (1 or 0)
77
     *  'alwayseditable' says if field can be modified also when status is not draft ('1' or '0')
78
     *  'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
79
     *  'index' if we want an index in database.
80
     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommended to name the field fk_...).
81
     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
82
     *  'isameasure' must be set to 1 or 2 if field can be used for measure. Field type must be summable like integer or double(24,8). Use 1 in most cases, or 2 if you don't want to see the column total into list (for example for percentage)
83
     *  'css' and 'cssview' and 'csslist' is the CSS style to use on field. 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
84
     *  'help' and 'helplist' is a 'TranslationString' to use to show a tooltip on field. You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click.
85
     *  'showoncombobox' if value of the field must be visible into the label of the combobox that list record
86
     *  'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
87
     *  'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar'
88
     *  'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1.
89
     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
90
     *    'validate' is 1 if need to validate with $this->validateField()
91
     *  'copytoclipboard' is 1 or 2 to allow to add a picto to copy value into clipboard (1=picto after label, 2=picto after value)
92
     *  'showonheader' is 1 to show on the top of the card (header section)
93
     *
94
     *  Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
95
     */
96
97
    // BEGIN MODULEBUILDER PROPERTIES
98
    /**
99
     * @var array<string,array{type:string,label:string,enabled:int<0,2>|string,position:int,notnull?:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,csslist?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}>  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string,array{type:...ring>,comment?:string}> at position 16 could not be parsed: Expected '}' at position 16, but found 'int'.
Loading history...
100
     */
101
    public $fields = array(
102
        'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'css' => 'left', 'comment' => "Id",),
103
        'ref' => array('type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 5, 'noteditable' => 1, 'default' => '(PROV)', 'index' => 1, 'searchall' => 1, 'showoncombobox' => 1, 'comment' => "Reference of object", 'showonheader' => 1,),
104
        'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 15, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
105
106
        'fk_type' => array('type' => 'integer:PartnershipType:partnership/class/partnership_type.class.php:0:(active:=:1)', 'label' => 'Type', 'enabled' => 1, 'position' => 20, 'notnull' => 1, 'visible' => 5, 'csslist' => '',),
107
        'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php:1:((status:=:1) AND (entity:IN:__SHARED_ENTITIES__))', 'label' => 'ThirdParty', 'picto' => 'company', 'enabled' => 1, 'position' => 50, 'notnull' => -1, 'visible' => 5, 'index' => 1, 'css' => '', 'csslist' => '',),
108
        'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'position' => 61, 'notnull' => 0, 'visible' => 0,),
109
        'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'position' => 62, 'notnull' => 0, 'visible' => 0,),
110
        'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 500, 'notnull' => 1, 'visible' => -2,),
111
        'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 501, 'notnull' => 0, 'visible' => -2,),
112
        'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'position' => 510, 'notnull' => 1, 'visible' => -2, 'foreignkey' => 'user.rowid',),
113
        'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'position' => 511, 'notnull' => -1, 'visible' => -2,),
114
        'last_main_doc' => array('type' => 'varchar(255)', 'label' => 'LastMainDoc', 'enabled' => 1, 'position' => 600, 'notnull' => 0, 'visible' => 0,),
115
        'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 1000, 'notnull' => -1, 'visible' => -2,),
116
        'model_pdf' => array('type' => 'varchar(255)', 'label' => 'Model pdf', 'enabled' => 1, 'position' => 1010, 'notnull' => -1, 'visible' => 0,),
117
        'date_partnership_start' => array('type' => 'date', 'label' => 'DatePartnershipStart', 'enabled' => 1, 'position' => 52, 'notnull' => 1, 'visible' => 5,),
118
        'date_partnership_end' => array('type' => 'date', 'label' => 'DatePartnershipEnd', 'enabled' => 1, 'position' => 53, 'notnull' => 0, 'visible' => 5,),
119
        'url_to_check' => array('type' => 'varchar(255)', 'label' => 'UrlToCheck', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => -5,),
120
        'count_last_url_check_error' => array('type' => 'integer', 'label' => 'CountLastUrlCheckError', 'enabled' => 1, 'position' => 71, 'notnull' => 0, 'visible' => -2, 'default' => '0',),
121
        'last_check_backlink' => array('type' => 'datetime', 'label' => 'LastCheckBacklink', 'enabled' => 1, 'position' => 72, 'notnull' => 0, 'visible' => -2,),
122
        'reason_decline_or_cancel' => array('type' => 'text', 'label' => 'ReasonDeclineOrCancel', 'enabled' => 1, 'position' => 73, 'notnull' => 0, 'visible' => -2,),
123
        'ip' => array('type' => 'varchar(250)', 'label' => 'Ip', 'enabled' => 1, 'position' => 74, 'notnull' => 0, 'visible' => -2,),
124
125
        'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 2000, 'notnull' => 1, 'visible' => 5, 'default' => '0', 'index' => 1, 'arrayofkeyval' => self::ARRAY_STATUS_LABEL, 'showonheader' => 1,),
126
    );
127
    //public $rowid;
128
    //public $ref;
129
    //public $entity;
130
    //public $fk_type;
131
    //public $note_public;
132
    //public $note_private;
133
    //public $date_creation;
134
    //public $fk_user_creat;
135
    //public $fk_user_modif;
136
    //public $last_main_doc;
137
    //public $import_key;
138
    //public $model_pdf;
139
    //public $date_partnership_start;
140
    //public $date_partnership_end;
141
    //public $url_to_check;
142
    //public $count_last_url_check_error;
143
    //public $last_check_backlink;
144
    //public $reason_decline_or_cancel;
145
    //public $fk_soc;
146
    //public $fk_member;
147
    //public $ip;
148
    //public $status;
149
    // END MODULEBUILDER PROPERTIES
150
151
    /**
152
     * Get partnership for static method
153
     *
154
     * @return  Partnership
155
     */
156
    protected function getPartnershipStatic()
157
    {
158
        if (!$this->partnership_static) {
159
            $this->partnership_static = new Partnership($this->db);
160
        }
161
162
        return $this->partnership_static;
163
    }
164
165
    /**
166
     * Constructor
167
     *
168
     * @param   DoliDb  $db     Database handler
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\WebPortal\Classes\DoliDb was not found. Did you mean DoliDb? If so, make sure to prefix the type with \.
Loading history...
169
     */
170
    public function __construct(DoliDB $db)
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\WebPortal\Classes\DoliDB was not found. Did you mean DoliDB? If so, make sure to prefix the type with \.
Loading history...
171
    {
172
        global $langs;
173
174
        $this->db = $db;
175
176
        $this->isextrafieldmanaged = 0;
177
178
        $this->getPartnershipStatic();
179
180
        // Translate some data of arrayofkeyval
181
        if (is_object($langs)) {
182
            foreach ($this->fields as $key => $val) {
183
                if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
184
                    foreach ($val['arrayofkeyval'] as $key2 => $val2) {
185
                        $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
186
                    }
187
                }
188
            }
189
        }
190
    }
191
192
    /**
193
     * getTooltipContentArray
194
     *
195
     * @param   array   $params     Params to construct tooltip data
196
     * @return  array
197
     * @since v18
198
     */
199
    public function getTooltipContentArray($params)
200
    {
201
        global $conf, $langs;
202
203
        $datas = [];
204
205
        if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) {
206
            return ['optimize' => $langs->trans("WebPortalPartnership")];
207
        }
208
        $datas['picto'] = img_picto('', $this->picto) . ' <u>' . $langs->trans("WebPortalPartnership") . '</u>';
209
        if (isset($this->status)) {
210
            $datas['picto'] .= ' ' . $this->getLibStatut(5);
211
        }
212
        $datas['ref'] .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
213
214
        return $datas;
215
    }
216
217
    /**
218
     *  Return a link to the object card (with optionally the picto)
219
     *
220
     * @param   int     $withpicto              Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
221
     * @param   string  $option                 On what the link point to ('nolink', ...)
222
     * @param   int     $notooltip              1=Disable tooltip
223
     * @param   string  $morecss                Add more css on link
224
     * @param   int     $save_lastsearch_value  -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
225
     * @return  string  String with URL
226
     */
227
    public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
228
    {
229
        global $conf, $langs, $hookmanager;
230
231
        if (!empty($conf->dol_no_mouse_hover)) {
232
            $notooltip = 1; // Force disable tooltips
233
        }
234
235
        $option = 'nolink';
236
237
        $result = '';
238
        $params = [
239
            'id' => $this->id,
240
            'objecttype' => $this->element,
241
            'option' => $option,
242
        ];
243
        $classfortooltip = 'classfortooltip';
244
        $dataparams = '';
245
        if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
246
            $classfortooltip = 'classforajaxtooltip';
247
            $dataparams = ' data-params="' . dol_escape_htmltag(json_encode($params)) . '"';
248
            $label = '';
249
        } else {
250
            $label = implode($this->getTooltipContentArray($params));
251
        }
252
253
        $url = '';
254
        //$url = DOL_URL_ROOT.'/partnership/partnership_card.php?id='.$this->id;
255
256
        if ($option != 'nolink') {
257
            // Add param to save lastsearch_values or not
258
            $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
259
            if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
260
                $add_save_lastsearch_values = 1;
261
            }
262
            if ($add_save_lastsearch_values) {
263
                $url .= '&save_lastsearch_values=1';
264
            }
265
        }
266
267
        $linkclose = '';
268
        if (empty($notooltip)) {
269
            if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
270
                $label = $langs->trans("ShowPartnership");
271
                $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
272
            }
273
            $linkclose .= ($label ? ' title="' . dol_escape_htmltag($label, 1) . '"' : ' title="tocomplete"');
274
            $linkclose .= $dataparams . ' class="' . $classfortooltip . ($morecss ? ' ' . $morecss : '') . '"';
275
        } else {
276
            $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
277
        }
278
279
        if ($option == 'nolink') {
280
            $linkstart = '<span';
281
        } else {
282
            $linkstart = '<a href="' . $url . '"';
283
        }
284
        $linkstart .= $linkclose . '>';
285
        if ($option == 'nolink') {
286
            $linkend = '</span>';
287
        } else {
288
            $linkend = '</a>';
289
        }
290
291
        $result .= $linkstart;
292
293
        if (empty($this->showphoto_on_popup)) {
294
            if ($withpicto) {
295
                $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams . ' class="' . (($withpicto != 2) ? 'paddingright ' : '') . $classfortooltip . '"'), 0, 0, $notooltip ? 0 : 1);
296
            }
297
        } else {
298
            if ($withpicto) {
299
                require_once constant('DOL_DOCUMENT_ROOT') . '/core/lib/files.lib.php';
300
301
                list($class, $module) = explode('@', $this->picto);
302
                $upload_dir = $conf->$module->multidir_output[$conf->entity] . "/$class/" . dol_sanitizeFileName($this->ref);
303
                $filearray = dol_dir_list($upload_dir, "files");
304
                $filename = $filearray[0]['name'];
305
                if (!empty($filename)) {
306
                    $pospoint = strpos($filearray[0]['name'], '.');
307
308
                    $pathtophoto = $class . '/' . $this->ref . '/thumbs/' . substr($filename, 0, $pospoint) . '_mini' . substr($filename, $pospoint);
309
                    if (!getDolGlobalString(strtoupper($module . '_' . $class) . '_FORMATLISTPHOTOSASUSERS')) {
310
                        $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo' . $module . '" alt="No photo" border="0" src="' . constant('BASE_URL') . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div></div>';
311
                    } else {
312
                        $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="' . constant('BASE_URL') . '/viewimage.php?modulepart=' . $module . '&entity=' . $conf->entity . '&file=' . urlencode($pathtophoto) . '"></div>';
313
                    }
314
315
                    $result .= '</div>';
316
                } else {
317
                    $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="' . (($withpicto != 2) ? 'paddingright ' : '') . 'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
318
                }
319
            }
320
        }
321
322
        if ($withpicto != 2) {
323
            $result .= $this->ref;
324
        }
325
326
        $result .= $linkend;
327
        //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
328
329
        global $action, $hookmanager;
330
        $hookmanager->initHooks(array('partnershipdao'));
331
        $parameters = array('id' => $this->id, 'getnomurl' => &$result);
332
        $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
333
        if ($reshook > 0) {
334
            $result = $hookmanager->resPrint;
335
        } else {
336
            $result .= $hookmanager->resPrint;
337
        }
338
339
        return $result;
340
    }
341
342
    /**
343
     *  Return the label of the status
344
     *
345
     * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
346
     * @return    string                   Label of status
347
     */
348
    public function getLibStatut($mode = 0)
349
    {
350
        return $this->LibStatut($this->status, $mode);
351
    }
352
353
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
354
355
    /**
356
     *  Return the status
357
     *
358
     * @param int $status Id status
359
     * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
360
     * @return string                   Label of status
361
     */
362
    public function LibStatut($status, $mode = 0)
363
    {
364
		// phpcs:enable
365
        return $this->getPartnershipStatic()->LibStatut($status, $mode);
366
    }
367
}
368