Passed
Push — EXTRACT_CLASSES ( 231cec...0382f2 )
by Rafael
65:54 queued 05:18
created

Subscription   F

Complexity

Total Complexity 82

Size/Duplication

Total Lines 545
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 262
dl 0
loc 545
rs 2
c 0
b 0
f 0
wmc 82

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getLibStatut() 0 3 1
B getKanbanView() 0 35 10
B update() 0 55 11
A info() 0 20 3
D getNomUrl() 0 46 17
A LibStatut() 0 7 1
A __construct() 0 5 1
F create() 0 90 22
A fetch() 0 36 3
C delete() 0 67 13

How to fix   Complexity   

Complex Class

Complex classes like Subscription 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 Subscription, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/* Copyright (C) 2002-2004  Rodolphe Quiedeville        <[email protected]>
4
 * Copyright (C) 2006-2015  Laurent Destailleur         <[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\Adherents\Classes;
24
25
/**
26
 *      \file       htdocs/adherents/class/subscription.class.php
27
 *      \ingroup    member
28
 *      \brief      File of class to manage subscriptions of foundation members
29
 */
30
31
//namespace DolibarrMember;
32
33
use Dolibarr\Core\Base\CommonObject;
34
35
36
/**
37
 *  Class to manage subscriptions of foundation members
38
 */
39
class Subscription extends CommonObject
40
{
41
    /**
42
     * @var string ID to identify managed object
43
     */
44
    public $element = 'subscription';
45
46
    /**
47
     * @var string Name of table without prefix where object is stored
48
     */
49
    public $table_element = 'subscription';
50
51
    /**
52
     * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
53
     */
54
    public $picto = 'payment';
55
56
    /**
57
     * Date creation record (datec)
58
     *
59
     * @var integer
60
     */
61
    public $datec;
62
63
    /**
64
     * Date modification record (tms)
65
     *
66
     * @var integer
67
     */
68
    public $datem;
69
70
    /**
71
     * Subscription start date (date subscription)
72
     *
73
     * @var integer
74
     */
75
    public $dateh;
76
77
    /**
78
     * Subscription end date
79
     *
80
     * @var integer
81
     */
82
    public $datef;
83
84
    /**
85
     * @var int ID
86
     */
87
    public $fk_type;
88
89
    /**
90
     * @var int Member ID
91
     */
92
    public $fk_adherent;
93
94
    /**
95
     * @var double amount subscription
96
     */
97
    public $amount;
98
99
    /**
100
     * @var int     ID of bank in llx_bank
101
     */
102
    public $fk_bank;
103
104
    /**
105
     * @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...
106
     */
107
    public $fields = array(
108
        'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
109
        'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 15),
110
        'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 20),
111
        'fk_adherent' => array('type' => 'integer', 'label' => 'Member', 'enabled' => 1, 'visible' => -1, 'position' => 25),
112
        'dateadh' => array('type' => 'datetime', 'label' => 'DateSubscription', 'enabled' => 1, 'visible' => -1, 'position' => 30),
113
        'datef' => array('type' => 'datetime', 'label' => 'DateEndSubscription', 'enabled' => 1, 'visible' => -1, 'position' => 35),
114
        'subscription' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'visible' => -1, 'position' => 40, 'isameasure' => 1),
115
        'fk_bank' => array('type' => 'integer', 'label' => 'BankId', 'enabled' => 1, 'visible' => -1, 'position' => 45),
116
        'note' => array('type' => 'html', 'label' => 'Note', 'enabled' => 1, 'visible' => -1, 'position' => 50),
117
        'fk_type' => array('type' => 'integer', 'label' => 'MemberType', 'enabled' => 1, 'visible' => -1, 'position' => 55),
118
        'fk_user_creat' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'enabled' => 1, 'visible' => -2, 'position' => 60),
119
        'fk_user_valid' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'position' => 65),
120
    );
121
122
123
    /**
124
     *  Constructor
125
     *
126
     *  @param      DoliDB      $db     Database handler
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\Adherents\Classes\DoliDB was not found. Did you mean DoliDB? If so, make sure to prefix the type with \.
Loading history...
127
     */
128
    public function __construct($db)
129
    {
130
        $this->db = $db;
131
132
        $this->ismultientitymanaged = 'fk_adherent@adherent';
0 ignored issues
show
Documentation Bug introduced by
The property $ismultientitymanaged was declared of type integer, but 'fk_adherent@adherent' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
133
    }
134
135
136
    /**
137
     *  Function who permitted creation of the subscription
138
     *
139
     *  @param  User    $user           User that create
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\Adherents\Classes\User was not found. Did you mean User? If so, make sure to prefix the type with \.
Loading history...
140
     *  @param  int     $notrigger      0=launch triggers after, 1=disable triggers
141
     *  @return int                     Return integer <0 if KO, Id subscription created if OK
142
     */
143
    public function create($user, $notrigger = 0)
144
    {
145
        global $langs;
146
147
        $error = 0;
148
149
        $now = dol_now();
150
151
        // Check parameters
152
        if ($this->datef <= $this->dateh) {
153
            $this->error = $langs->trans("ErrorBadValueForDate");
154
            return -1;
155
        }
156
        if (empty($this->datec)) {
157
            $this->datec = $now;
158
        }
159
160
        $this->db->begin();
161
162
        $sql = "INSERT INTO " . MAIN_DB_PREFIX . "subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note)";
163
164
        require_once constant('DOL_DOCUMENT_ROOT') . '/adherents/class/adherent.class.php';
165
        $member = new Adherent($this->db);
166
        $result = $member->fetch($this->fk_adherent);
167
168
        if ($this->fk_type == null) {   // If type not defined, we use the type of member
169
            $type = $member->typeid;
170
        } else {
171
            $type = $this->fk_type;
172
        }
173
        $sql .= " VALUES (" . ((int) $this->fk_adherent) . ", '" . $this->db->escape($type) . "', '" . $this->db->idate($now) . "',";
174
        $sql .= " '" . $this->db->idate($this->dateh) . "',";
175
        $sql .= " '" . $this->db->idate($this->datef) . "',";
176
        $sql .= " " . ((float) $this->amount) . ",";
177
        $sql .= " '" . $this->db->escape($this->note_public ? $this->note_public : $this->note) . "')";
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

177
        $sql .= " '" . $this->db->escape($this->note_public ? $this->note_public : /** @scrutinizer ignore-deprecated */ $this->note) . "')";

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
178
179
        $resql = $this->db->query($sql);
180
        if (!$resql) {
181
            $error++;
182
            $this->errors[] = $this->db->lasterror();
183
        }
184
185
        if (!$error) {
186
            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
187
            $this->fk_type = $type;
188
        }
189
190
        if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {  // To use new linkedObjectsIds instead of old linked_objects
191
            $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
192
        }
193
194
        // Add object linked
195
        if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
196
            foreach ($this->linked_objects as $origin => $tmp_origin_id) {
197
                if (is_array($tmp_origin_id)) {       // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
198
                    foreach ($tmp_origin_id as $origin_id) {
199
                        $ret = $this->add_object_linked($origin, $origin_id);
200
                        if (!$ret) {
201
                            $this->error = $this->db->lasterror();
202
                            $error++;
203
                        }
204
                    }
205
                } else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
206
                    $origin_id = $tmp_origin_id;
207
                    $ret = $this->add_object_linked($origin, $origin_id);
208
                    if (!$ret) {
209
                        $this->error = $this->db->lasterror();
210
                        $error++;
211
                    }
212
                }
213
            }
214
        }
215
216
        if (!$error && !$notrigger) {
217
            $this->context = array('member' => $member);
218
            // Call triggers
219
            $result = $this->call_trigger('MEMBER_SUBSCRIPTION_CREATE', $user);
220
            if ($result < 0) {
221
                $error++;
222
            }
223
            // End call triggers
224
        }
225
226
        // Commit or rollback
227
        if ($error) {
228
            $this->db->rollback();
229
            return -1;
230
        } else {
231
            $this->db->commit();
232
            return $this->id;
233
        }
234
    }
235
236
237
    /**
238
     *  Method to load a subscription
239
     *
240
     *  @param  int     $rowid      Id subscription
241
     *  @return int                 Return integer <0 if KO, =0 if not found, >0 if OK
242
     */
243
    public function fetch($rowid)
244
    {
245
        $sql = "SELECT rowid, fk_type, fk_adherent, datec,";
246
        $sql .= " tms,";
247
        $sql .= " dateadh as dateh,";
248
        $sql .= " datef,";
249
        $sql .= " subscription, note as note_public, fk_bank";
250
        $sql .= " FROM " . MAIN_DB_PREFIX . "subscription";
251
        $sql .= " WHERE rowid = " . ((int) $rowid);
252
253
        dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
254
        $resql = $this->db->query($sql);
255
        if ($resql) {
256
            if ($this->db->num_rows($resql)) {
257
                $obj = $this->db->fetch_object($resql);
258
259
                $this->id             = $obj->rowid;
260
                $this->ref            = $obj->rowid;
261
262
                $this->fk_type        = $obj->fk_type;
263
                $this->fk_adherent    = $obj->fk_adherent;
264
                $this->datec          = $this->db->jdate($obj->datec);
265
                $this->datem          = $this->db->jdate($obj->tms);
266
                $this->dateh          = $this->db->jdate($obj->dateh);
267
                $this->datef          = $this->db->jdate($obj->datef);
268
                $this->amount         = $obj->subscription;
269
                $this->note           = $obj->note_public;  // deprecated
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

269
                /** @scrutinizer ignore-deprecated */ $this->note           = $obj->note_public;  // deprecated

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
270
                $this->note_public    = $obj->note_public;
271
                $this->fk_bank        = $obj->fk_bank;
272
                return 1;
273
            } else {
274
                return 0;
275
            }
276
        } else {
277
            $this->error = $this->db->lasterror();
278
            return -1;
279
        }
280
    }
281
282
283
    /**
284
     *  Update subscription
285
     *
286
     *  @param  User    $user           User who updated
287
     *  @param  int     $notrigger      0=Disable triggers
288
     *  @return int                     Return integer <0 if KO, >0 if OK
289
     */
290
    public function update($user, $notrigger = 0)
291
    {
292
        $error = 0;
293
294
        $this->db->begin();
295
296
        if (!is_numeric($this->amount)) {
297
            $this->error = 'BadValueForParameterAmount';
298
            return -1;
299
        }
300
301
        if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

301
        if (empty($this->note_public) && !empty(/** @scrutinizer ignore-deprecated */ $this->note)) { // For backward compatibility

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
302
            $this->note_public = $this->note;
0 ignored issues
show
Deprecated Code introduced by
The property Dolibarr\Core\Base\CommonObject::$note has been deprecated: Use $note_private instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

302
            $this->note_public = /** @scrutinizer ignore-deprecated */ $this->note;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
303
        }
304
305
        $sql = "UPDATE " . MAIN_DB_PREFIX . "subscription SET ";
306
        $sql .= " fk_type = " . ((int) $this->fk_type) . ",";
307
        $sql .= " fk_adherent = " . ((int) $this->fk_adherent) . ",";
308
        $sql .= " note = " . ($this->note_public ? "'" . $this->db->escape($this->note_public) . "'" : 'null') . ",";
309
        $sql .= " subscription = " . (float) price2num($this->amount) . ",";
310
        $sql .= " dateadh = '" . $this->db->idate($this->dateh) . "',";
311
        $sql .= " datef = '" . $this->db->idate($this->datef) . "',";
312
        $sql .= " datec = '" . $this->db->idate($this->datec) . "',";
313
        $sql .= " fk_bank = " . ($this->fk_bank ? ((int) $this->fk_bank) : 'null');
314
        $sql .= " WHERE rowid = " . ((int) $this->id);
315
316
        dol_syslog(get_class($this) . "::update", LOG_DEBUG);
317
        $resql = $this->db->query($sql);
318
        if ($resql) {
319
            require_once constant('DOL_DOCUMENT_ROOT') . '/adherents/class/adherent.class.php';
320
            $member = new Adherent($this->db);
321
            $result = $member->fetch($this->fk_adherent);
322
            $result = $member->update_end_date($user);
323
324
            if (!$error && !$notrigger) {
325
                $this->context = array('member' => $member);
326
                // Call triggers
327
                $result = $this->call_trigger('MEMBER_SUBSCRIPTION_MODIFY', $user);
328
                if ($result < 0) {
329
                    $error++;
330
                } //Do also here what you must do to rollback action if trigger fail
331
                // End call triggers
332
            }
333
        } else {
334
            $error++;
335
            $this->error = $this->db->lasterror();
336
        }
337
338
        // Commit or rollback
339
        if ($error) {
340
            $this->db->rollback();
341
            return -1;
342
        } else {
343
            $this->db->commit();
344
            return $this->id;
345
        }
346
    }
347
348
    /**
349
     *  Delete a subscription
350
     *
351
     *  @param  User    $user       User that delete
352
     *  @param  int     $notrigger  0=launch triggers after, 1=disable triggers
353
     *  @return int                 Return integer <0 if KO, 0 if not found, >0 if OK
354
     */
355
    public function delete($user, $notrigger = 0)
356
    {
357
        $error = 0;
358
359
        // It subscription is linked to a bank transaction, we get it
360
        if ($this->fk_bank > 0) {
361
            require_once constant('DOL_DOCUMENT_ROOT') . '/compta/bank/class/account.class.php';
362
            $accountline = new AccountLine($this->db);
0 ignored issues
show
Bug introduced by
The type Dolibarr\Code\Adherents\Classes\AccountLine was not found. Did you mean AccountLine? If so, make sure to prefix the type with \.
Loading history...
363
            $result = $accountline->fetch($this->fk_bank);
364
        }
365
366
        $this->db->begin();
367
368
        if (!$error) {
369
            if (!$notrigger) {
370
                // Call triggers
371
                $result = $this->call_trigger('MEMBER_SUBSCRIPTION_DELETE', $user);
372
                if ($result < 0) {
373
                    $error++;
374
                } // Do also here what you must do to rollback action if trigger fail
375
                // End call triggers
376
            }
377
        }
378
379
        if (!$error) {
380
            $sql = "DELETE FROM " . MAIN_DB_PREFIX . "subscription WHERE rowid = " . ((int) $this->id);
381
            dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
382
            $resql = $this->db->query($sql);
383
            if ($resql) {
384
                $num = $this->db->affected_rows($resql);
385
                if ($num) {
386
                    require_once constant('DOL_DOCUMENT_ROOT') . '/adherents/class/adherent.class.php';
387
                    $member = new Adherent($this->db);
388
                    $result = $member->fetch($this->fk_adherent);
389
                    $result = $member->update_end_date($user);
390
391
                    if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) {    // If we found bank account line (this means this->fk_bank defined)
392
                        $result = $accountline->delete($user); // Return false if refused because line is reconciled
393
                        if ($result > 0) {
394
                            $this->db->commit();
395
                            return 1;
396
                        } else {
397
                            $this->error = $accountline->error;
398
                            $this->db->rollback();
399
                            return -1;
400
                        }
401
                    } else {
402
                        $this->db->commit();
403
                        return 1;
404
                    }
405
                } else {
406
                    $this->db->commit();
407
                    return 0;
408
                }
409
            } else {
410
                $error++;
411
                $this->error = $this->db->lasterror();
412
            }
413
        }
414
415
        // Commit or rollback
416
        if ($error) {
417
            $this->db->rollback();
418
            return -1;
419
        } else {
420
            $this->db->commit();
421
            return 1;
422
        }
423
    }
424
425
426
    /**
427
     *  Return clicable name (with picto eventually)
428
     *
429
     *  @param  int     $withpicto                  0=No picto, 1=Include picto into link, 2=Only picto
430
     *  @param  int     $notooltip                  1=Disable tooltip
431
     *  @param  string  $option                     Page for link ('', 'nolink', ...)
432
     *  @param  string  $morecss                    Add more css on link
433
     *  @param  int     $save_lastsearch_value      -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
434
     *  @return string                              Chaine avec URL
435
     */
436
    public function getNomUrl($withpicto = 0, $notooltip = 0, $option = '', $morecss = '', $save_lastsearch_value = -1)
437
    {
438
        global $langs;
439
440
        $result = '';
441
442
        $langs->load("members");
443
444
        $label = img_picto('', $this->picto) . ' <u class="paddingrightonly">' . $langs->trans("Subscription") . '</u>';
445
        /*if (isset($this->statut)) {
446
            $label .= ' '.$this->getLibStatut(5);
447
        }*/
448
        $label .= '<br><b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
449
        if (!empty($this->dateh)) {
450
            $label .= '<br><b>' . $langs->trans('DateStart') . ':</b> ' . dol_print_date($this->dateh, 'day');
451
        }
452
        if (!empty($this->datef)) {
453
            $label .= '<br><b>' . $langs->trans('DateEnd') . ':</b> ' . dol_print_date($this->datef, 'day');
454
        }
455
456
        $url = constant('BASE_URL') . '/adherents/subscription/card.php?rowid=' . ((int) $this->id);
457
458
        if ($option != 'nolink') {
459
            // Add param to save lastsearch_values or not
460
            $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
461
            if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
462
                $add_save_lastsearch_values = 1;
463
            }
464
            if ($add_save_lastsearch_values) {
465
                $url .= '&save_lastsearch_values=1';
466
            }
467
        }
468
469
        $linkstart = '<a href="' . $url . '" class="classfortooltip" title="' . dol_escape_htmltag($label, 1) . '">';
470
        $linkend = '</a>';
471
472
        $result .= $linkstart;
473
        if ($withpicto) {
474
            $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);
475
        }
476
        if ($withpicto != 2) {
477
            $result .= $this->ref;
478
        }
479
        $result .= $linkend;
480
481
        return $result;
482
    }
483
484
485
    /**
486
     *  Return the label of the status
487
     *
488
     *  @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
489
     *  @return string                 Label of status
490
     */
491
    public function getLibStatut($mode = 0)
492
    {
493
        return '';
494
    }
495
496
	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
497
    /**
498
     *  Return the label of a given status
499
     *
500
     *  @param  int     $status        Id status
501
     *  @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
502
     *  @return string                 Label of status
503
     */
504
    public function LibStatut($status, $mode = 0)
505
    {
506
		// phpcs:enable
507
508
        //$langs->load("members");
509
510
        return '';
511
    }
512
513
    /**
514
     *  Load information of the subscription object
515
     *
516
     *  @param  int     $id       Id subscription
517
     *  @return void
518
     */
519
    public function info($id)
520
    {
521
        $sql = 'SELECT c.rowid, c.datec,';
522
        $sql .= ' c.tms as datem';
523
        $sql .= ' FROM ' . MAIN_DB_PREFIX . 'subscription as c';
524
        $sql .= ' WHERE c.rowid = ' . ((int) $id);
525
526
        $resql = $this->db->query($sql);
527
        if ($resql) {
528
            if ($this->db->num_rows($resql)) {
529
                $obj = $this->db->fetch_object($resql);
530
                $this->id = $obj->rowid;
531
532
                $this->date_creation = $this->db->jdate($obj->datec);
533
                $this->date_modification = $this->db->jdate($obj->datem);
534
            }
535
536
            $this->db->free($resql);
537
        } else {
538
            dol_print_error($this->db);
539
        }
540
    }
541
542
    /**
543
     *  Return clicable link of object (with eventually picto)
544
     *
545
     *  @param      string      $option                 Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
546
     *  @param      array       $arraydata              Array of data
547
     *  @return     string                              HTML Code for Kanban thumb.
548
     */
549
    public function getKanbanView($option = '', $arraydata = null)
550
    {
551
        $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
552
553
        $return = '<div class="box-flex-item box-flex-grow-zero">';
554
        $return .= '<div class="info-box info-box-sm">';
555
        $return .= '<span class="info-box-icon bg-infobox-action">';
556
        $return .= img_picto('', $this->picto);
557
        $return .= '</span>';
558
559
        $return .= '<div class="info-box-content">';
560
        $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">';
561
        $return .= $this->getNomUrl(0);
562
        $return .= '</span>';
563
        if ($selected >= 0) {
564
            $return .= '<input id="cb' . $this->id . '" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
565
        }
566
        if (property_exists($this, 'dateh') || property_exists($this, 'datef')) {
567
            $return .= '<br><span class="info-box-status opacitymedium small">' . dol_print_date($this->dateh, 'day') . ' - ' . dol_print_date($this->datef, 'day') . '</span>';
568
        }
569
570
        if (!empty($arraydata['member']) && is_object($arraydata['member'])) {
571
            $return .= '<br><div class="inline-block tdoverflowmax150">' . $arraydata['member']->getNomUrl(-4) . '</div>';
572
        }
573
574
        if (property_exists($this, 'amount')) {
575
            $return .= '<br><span class="amount inline-block">' . price($this->amount) . '</span>';
576
            if (!empty($arraydata['bank'])) {
577
                $return .= ' &nbsp; <span class="info-box-label ">' . $arraydata['bank']->getNomUrl(-1) . '</span>';
578
            }
579
        }
580
        $return .= '</div>';
581
        $return .= '</div>';
582
        $return .= '</div>';
583
        return $return;
584
    }
585
}
586