Completed
Push — master ( 6fc3a1...47798a )
by Paul
03:19
created

absences_RightList::__construct()   F

Complexity

Conditions 19
Paths 12288

Size

Total Lines 130
Code Lines 82

Duplication

Lines 17
Ratio 13.08 %
Metric Value
dl 17
loc 130
rs 2
cc 19
eloc 82
nc 12288
nop 10

How to fix   Long Method    Complexity    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/************************************************************************
3
 * OVIDENTIA http://www.ovidentia.org                                   *
4
 ************************************************************************
5
 * Copyright (c) 2003 by CANTICO ( http://www.cantico.fr )              *
6
 *                                                                      *
7
 * This file is part of Ovidentia.                                      *
8
 *                                                                      *
9
 * Ovidentia 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 2, or (at your option)  *
12
 * any later version.													*
13
 *																		*
14
 * This program is distributed in the hope that it will be useful, but  *
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of			*
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.					*
17
 * See the  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, write to the Free Software			*
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,*
22
 * USA.																	*
23
************************************************************************/
24
25
26
27
28
class absences_RightList extends absences_Paginate
29
{
30
    public $typetxt;
31
    public $desctxt;
32
    public $quantitytxt;
33
    public $creditortxt;
34
    public $datetxt;
35
    public $date2txt;
36
    public $vrurl;
37
    public $vrviewurl;
38
    public $description;
39
40
    public $typename;
41
    public $quantity;
42
    public $creditor;
43
    public $date;
44
    public $addtxt;
45
    public $addurl;
46
    public $filteron;
47
    public $statustxt;
48
    public $activeyes;
49
    public $activeno;
50
    public $yselected;
51
    public $nselected;
52
53
    public $urllistp;
54
    public $altlistp;
55
    public $selected;
56
57
    public $begintxt;
58
    public $endtxt;
59
60
    public $arr = array();
61
    public $count;
62
    public $res;
63
    public $topurl;
64
    public $bottomurl;
65
    public $nexturl;
66
    public $prevurl;
67
    public $topname;
68
    public $bottomname;
69
    public $nextname;
70
    public $prevname;
71
    public $pos;
72
    public $bclose;
73
    public $closedtxt;
74
    public $openedtxt;
75
    public $statusval;
76
    public $alttxt;
77
    public $altbg = true;
78
79
    public function __construct($idtype, $idcoll, $rgroup, $dateb, $datee, $active, $pos, $archived, $recovery, $name)
80
    {
81
82
        $this->desctxt = absences_translate("Description");
83
        $this->typetxt = absences_translate("Type");
84
        $this->nametxt = absences_translate("Name");
0 ignored issues
show
Bug introduced by
The property nametxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
85
        $this->kindtxt = absences_translate("Right kind");
0 ignored issues
show
Bug introduced by
The property kindtxt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
86
        $this->quantitytxt = absences_translate("Quantity");
87
        $this->creditortxt = absences_translate("Author");
88
        $this->datetxt = absences_translate("Entry date");
89
        $this->date2txt = absences_translate("Entry date ( dd-mm-yyyy )");
90
        $this->addtxt = absences_translate("Allocate vacation rights");
91
        $this->filteron = absences_translate("Filter on");
92
        $this->begintxt = absences_translate("Begin");
93
        $this->endtxt = absences_translate("End");
94
        $this->altlistp = absences_translate("Beneficiaries");
95
        $this->statustxt = absences_translate("Active");
96
        $this->activeyes = absences_translate("Opened rights");
97
        $this->activeno = absences_translate("Closed rights");
98
        $this->closedtxt = absences_translate("Vac. closed");
99
        $this->openedtxt = absences_translate("Vac. opened");
100
        $this->alttxt = absences_translate("Modify");
101
        $this->t_edit = absences_translate("Modification");
0 ignored issues
show
Bug introduced by
The property t_edit does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
102
        $this->t_first_page = absences_translate("First page");
0 ignored issues
show
Bug introduced by
The property t_first_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
103
        $this->t_previous_page = absences_translate("Previous page");
0 ignored issues
show
Bug introduced by
The property t_previous_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
104
        $this->t_next_page = absences_translate("Next page");
0 ignored issues
show
Bug introduced by
The property t_next_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
105
        $this->t_last_page = absences_translate("Last page");
0 ignored issues
show
Bug introduced by
The property t_last_page does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
106
        $this->t_available = absences_translate("Availability");
0 ignored issues
show
Bug introduced by
The property t_available does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
107
        $this->topurl = "";
108
        $this->bottomurl = "";
109
        $this->nexturl = "";
110
        $this->prevurl = "";
111
        $this->yselected = "";
112
        $this->nselected = "";
113
        $this->t_position = '';
114
        global $babDB;
115
116
        $this->pos = $pos;
117
118
        $aaareq = array();
119
        $req = "".ABSENCES_RIGHTS_TBL." r LEFT JOIN ".ABSENCES_TYPES_TBL." t ON t.id=r.id_type where ";
120
121
        if( $name != "") {
122
            $aaareq[] = "r.description LIKE '%".$babDB->db_escape_like($name)."%'";
123
        }
124
125
        if( $active != "")
126
            $aaareq[] = "r.active='".$babDB->db_escape_string($active)."'";
127
128
        if( $idcoll != "")
129
        {
130
            $aaareq[] = "r.id IN(SELECT id_right FROM absences_coll_rights WHERE id_coll=".$babDB->quote($idcoll).")";
131
        }
132
        
133
        if( $idtype != "")
134
        {
135
            $aaareq[] = "r.id_type=".$babDB->quote($idtype);
136
        }
137
138
        if( $rgroup != "")
139
        {
140
            $aaareq[] = "r.id_rgroup=".$babDB->quote($rgroup);
141
        }
142
143 View Code Duplication
        if( $dateb != "" )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
144
        {
145
            $ar = explode("-", $dateb);
146
            $dateb = $ar[2]."-".$ar[1]."-".$ar[0];
147
        }
148
149 View Code Duplication
        if( $datee != "" )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
        {
151
            $ar = explode("-", $datee);
152
            $datee = $ar[2]."-".$ar[1]."-".$ar[0];
153
        }
154
155
        if( $dateb != "" && $datee != "")
156
        {
157
            $aaareq[] = "( r.date_entry between '".$babDB->db_escape_string($dateb)."' and '".$babDB->db_escape_string($datee)."')";
158
        }
159
        else if( $dateb == "" && $datee != "" )
160
        {
161
            $aaareq[] = "r.date_entry <= '".$babDB->db_escape_string($datee)."'";
162
        }
163
        else if ($dateb != "" )
164
        {
165
            $aaareq[] = "r.date_entry >= '".$babDB->db_escape_string($dateb)."'";
166
        }
167
168
        if ($archived)
169
        {
170
            $aaareq[] = "r.archived = ".$babDB->quote(1);
171
        }
172
173
        if ($recovery)
174
        {
175
            $aaareq[] = "r.kind = ".$babDB->quote(absences_Right::RECOVERY);
176
        } else {
177
            $aaareq[] = "r.kind <> ".$babDB->quote(absences_Right::RECOVERY);
178
        }
179
180
181 View Code Duplication
        if( isset($aaareq) && sizeof($aaareq) > 0 )
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
182
        {
183
            if( sizeof($aaareq) > 1 )
184
                $req .= implode(' and ', $aaareq);
185
            else
186
                $req .= $aaareq[0];
187
        }
188
        $req .= " order by r.date_entry desc, r.id";
189
190
        list($total) = $babDB->db_fetch_row($babDB->db_query("select count(*) as total from ".$req));
191
192
        $this->paginate($total, ABSENCES_MAX_RIGHTS_LIST);
193
194
        if( $total > ABSENCES_MAX_RIGHTS_LIST)
195
        {
196
            $req .= " limit ".$pos.",".ABSENCES_MAX_RIGHTS_LIST;
197
        }
198
        bab_debug("select r.*, t.name type, t.color typecolor from ".$req);
199
        $this->res = $babDB->db_query("select r.*, t.name type, t.color typecolor from ".$req);
200
        $this->count = $babDB->db_num_rows($this->res);
201
        $this->addurl = absences_addon()->getUrl()."vacadma&idx=addvr";
202
203
204
        $this->dateburl = $GLOBALS['babUrlScript']."?tg=month&callback=dateBegin&ymin=0&ymax=3";
0 ignored issues
show
Bug introduced by
The property dateburl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
205
        $this->dateeurl = $GLOBALS['babUrlScript']."?tg=month&callback=dateEnd&ymin=0&ymax=3";
0 ignored issues
show
Bug introduced by
The property dateeurl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
206
207
        $this->searchform = $this->getSearchForm();
0 ignored issues
show
Bug introduced by
The property searchform does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
208
    }
209
210
211
    private function getSearchForm()
212
    {
213
        global $babDB;
214
        bab_functionality::includeOriginal('Icons');
215
        $W = bab_Widgets();
216
        $form = $W->Form(null, $W->FlowLayout()->setSpacing(1,'em', 3,'em'));
217
        $form->setSelfPageHiddenFields()->setReadOnly();
218
219
        $form->addClass('widget-bordered');
220
        $form->addClass('BabLoginMenuBackground');
221
        $form->addClass('widget-centered');
222
        $form->addClass(Func_Icons::ICON_LEFT_16);
223
        $form->colon();
224
225
        $form->setCanvasOptions($form->Options()->width(97,'%'));
226
        
227
        
228
        
229
        $form->addItem(
230
            $W->LabelledWidget(
231
                absences_translate('Name'),
232
                $W->LineEdit(),
233
                'name'
234
            )
235
        );
236
        
237
        
238
239
        $types = $W->Select()->addOption('', '');
240
        $restype = $babDB->db_query("select * from ".ABSENCES_TYPES_TBL." order by name asc");
241
        while ($arr = $babDB->db_fetch_assoc($restype))
242
        {
243
            $types->addOption($arr['id'], $arr['name']);
244
        }
245
246
        $form->addItem(
247
                $W->LabelledWidget(
248
                        absences_translate('Type'),
249
                        $types,
250
                        'idtype'
251
                )
252
        );
253
254
255
        $collections = $W->Select()->addOption('', '');
256
        $rescoll = $babDB->db_query("select * from ".ABSENCES_COLLECTIONS_TBL." order by name asc");
257
        while ($arr = $babDB->db_fetch_assoc($rescoll))
258
        {
259
            $collections->addOption($arr['id'], $arr['name']);
260
        }
261
262
        $form->addItem(
263
                $W->LabelledWidget(
264
                        absences_translate('Collection'),
265
                        $collections,
266
                        'idcoll'
267
                )
268
        );
269
270
271
        $rgroups = $W->Select()->addOption('', '');
272
        $resrg = $babDB->db_query("select * from absences_rgroup order by name asc");
273
        while ($arr = $babDB->db_fetch_assoc($resrg))
274
        {
275
            $rgroups->addOption($arr['id'], $arr['name']);
276
        }
277
278
279
        $form->addItem(
280
                $W->LabelledWidget(
281
                        absences_translate('Right group'),
282
                        $rgroups,
283
                        'rgroup'
284
                )
285
        );
286
287
288
        $form->addItem(
289
                $W->LabelledWidget(
290
                        absences_translate('Status'),
291
                        $W->Select()
292
                        ->addOption('', '')
293
                        ->addOption('Y', absences_translate('Active'))
294
                        ->addOption('N', absences_translate('Inactive')),
295
                        'active'
296
                )
297
        );
298
299
300
        $form->addItem(
301
                $W->LabelledWidget(
302
                        absences_translate('Write date'),
303
                        $W->PeriodPicker()->setNames('dateb', 'datee')
304
                )
305
        );
306
307
308
        $form->setValues($_REQUEST);
309
310
311
312
        $form->addItem($W->SubmitButton()->setLabel(absences_translate('Search')));
313
314
        return $form->display($W->HtmlCanvas());
315
    }
316
317
    public function getnext()
318
    {
319
        static $i = 0;
320
        if( $i < $this->count)
321
        {
322
            global $babDB;
323
            $this->altbg = !$this->altbg;
324
            $arr = $babDB->db_fetch_array($this->res);
325
326
327
            $this->typecolor	= bab_toHtml($arr['typecolor']);
0 ignored issues
show
Bug introduced by
The property typecolor does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
328
            $this->typename		= bab_toHtml($arr['type']);
329
330
            unset($arr['typecolor']);
331
            unset($arr['type']);
332
333
334
            $right = new absences_Right($arr['id']);
335
            $right->setRow($arr);
336
337
338
            $this->vrurl		= bab_toHtml(absences_addon()->getUrl()."vacadma&idx=modvr&idvr=".$arr['id']);
339
            $this->vrviewurl	= bab_toHtml(absences_addon()->getUrl()."vacadma&idx=viewvr&idvr=".$arr['id']);
340
341
            $this->kind 		= bab_toHtml($right->getKindLabel());
0 ignored issues
show
Bug introduced by
The property kind does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
342
            $this->description	= bab_toHtml($right->description);
343
            if (0 === (int) round(100*$arr['quantity']))
344
            {
345
                $this->quantity	= '';
346
            } else {
347
                $this->quantity	= bab_toHtml(absences_quantity($arr['quantity'], $arr['quantity_unit']));
348
            }
349
            $this->creditor		= bab_toHtml(bab_getUserName($arr['id_creditor']));
350
            $this->date			= bab_toHtml(bab_shortDate(bab_mktime($arr['date_entry']), false));
351
            $this->bclose		= $arr['active'] == "N";
352
353
354
            $this->available	= $right->isAvailable() ? absences_translate('Available') : '';
0 ignored issues
show
Bug introduced by
The property available does not seem to exist. Did you mean t_available?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
355
356
            if( $this->bclose )
357
                $this->statusval = $this->closedtxt;
358
            else
359
                $this->statusval = $this->openedtxt;
360
361
            if (absences_Right::RECOVERY === $right->getKind())
362
            {
363
                $this->urllistp = false;
364
            } else {
365
                $this->urllistp = absences_addon()->getUrl()."vacadma&idx=lvrc&idvr=".$arr['id'];
366
            }
367
368
            $i++;
369
            return true;
370
        }
371
        else
372
            return false;
373
374
    }
375
376
}
377
378
379
380
381
382
/**
383
 * Display a menu to add items to the agent list
384
 * @return string
385
 */
386
function absences_rightListMenu()
387
{
388
    $toolbar = absences_getToolbar();
389
390
    $sImgPath = $GLOBALS['babInstallPath'] . 'skins/ovidentia/images/Puces/';
391
392
    $url = bab_url::get_request('tg', 'filter');
393
    $url->idx = 'addvr';
394
395
    $toolbar->addToolbarItem(
396
        new BAB_ToolbarItem(absences_translate('Add'), $url->toString(),
397
            $sImgPath . 'edit_add.png', '', '', '')
398
    );
399
    
400
401
    return $toolbar->printTemplate();
402
}
403