Completed
Push — master ( c3d86a...9979ee )
by Paul
07:00
created

absences_getAbsenceSearchForm::getHtmlForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 7
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
//-------------------------------------------------------------------------
3
// OVIDENTIA http://www.ovidentia.org
4
// Ovidentia is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 2, or (at your option)
7
// any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
// See the GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17
// USA.
18
//-------------------------------------------------------------------------
19
/**
20
 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
21
 * @copyright Copyright (c) 2006 by CANTICO ({@link http://www.cantico.fr})
22
 */
23
24
25
require_once dirname(__FILE__).'/utilit/vacincl.php';
26
require_once dirname(__FILE__).'/functions.php';
27
28
29
30
31
32
/**
33
 * formulaire de recherche pour les liste des demandes gestionnaire
34
 */
35
class absences_getAbsenceSearchForm  
36
{
37
    public function getForm()
38
    {
39
        bab_functionality::includeOriginal('Icons');
40
        $W = bab_Widgets();
41
        $form = $W->Form(null, $W->FlowLayout()->setSpacing(1, 'em', 3,'em'));
42
        $form->setSelfPageHiddenFields()->setReadOnly();
43
44
        $form->addClass('absences-filterform');
45
        $form->addClass('widget-bordered');
46
        $form->addClass('BabLoginMenuBackground');
47
        $form->addClass('widget-centered');
48
        $form->addClass(Func_Icons::ICON_LEFT_16);
49
        $form->colon();
50
51
        $form->setCanvasOptions($form->Options()->width(97,'%'));
52
53
        $period = $W->LabelledWidget(
54
                absences_translate('Date'),
55
                $W->PeriodPicker()->setNames('dateb', 'datee')
56
        );
57
        
58
        $date = $W->LabelledWidget(
59
            absences_translate('Date'),
60
            $W->DatePicker(),
61
            'date'
62
        );
63
        
64
        
65
        
66
        $form->addItem(
67
            $W->LabelledWidget(
68
                absences_translate('Search absences'),
69
                $W->Select()
70
                    ->setAssociatedDisplayable($date, array('1'))
71
                    ->setAssociatedDisplayable($period, array('2'))
72
                    ->addOption('1', absences_translate("Absences on a date"))
73
                    ->addOption('2', absences_translate("Absences in a period")),
74
                'searchtype'
75
            )
76
        );
77
        
78
79
        $form->addItem($period);
80
        $form->addItem($date);
81
82
        $values = array(
83
            'searchtype'     => $this->param('searchtype'),
84
            'dateb'          => $this->param('dateb'),
85
            'datee'          => $this->param('datee'),
86
            'date'           => $this->param('date'),
87
            'vpos'           => (int) $this->param('vpos', 0)
88
        );
89
90
        $form->setValues($values);
91
        $form->addItem($W->SubmitButton()->setLabel(absences_translate('Search')));
92
93
        return $form;
94
    }
95
96
97
98 View Code Duplication
    public function getHtmlForm(Array $statarr = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
99
    {
100
        $W = bab_Widgets();
101
        $form = $this->getForm($statarr);
0 ignored issues
show
Unused Code introduced by
The call to absences_getAbsenceSearchForm::getForm() has too many arguments starting with $statarr.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
102
         
103
        return $form->display($W->HtmlCanvas());
104
    }
105
106
107
    public function param($name, $default = '')
108
    {
109
        if (isset($_REQUEST[$name]))
110
        {
111
            $_SESSION['babVacationSearch'][$name] = $_REQUEST[$name];
112
            return $_REQUEST[$name];
113
        }
114
115
        if (isset($_SESSION['babVacationSearch'][$name]))
116
        {
117
            return $_SESSION['babVacationSearch'][$name];
118
        }
119
120
        return $default;
121
    }
122
}
123
124
125
126
127
128
129
class absences_SearchList extends absences_Paginate
130
{
131
    const MAX = 30;
132
133
    private $res;
134
135
    public $altbg = true;
136
137
    public function __construct()
138
    {
139
        $this->t_user = absences_translate('User');
0 ignored issues
show
Bug introduced by
The property t_user 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...
140
        $this->t_begin = absences_translate('Begin');
0 ignored issues
show
Bug introduced by
The property t_begin 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...
141
        $this->t_end = absences_translate('End');
0 ignored issues
show
Bug introduced by
The property t_end 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...
142
        $this->t_quantity = absences_translate('Quantity');
0 ignored issues
show
Bug introduced by
The property t_quantity 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...
143
144
        $f = new absences_getAbsenceSearchForm();
145
146
        require_once dirname(__FILE__).'/utilit/entry.class.php';
147
        $this->res = new absences_EntryIterator();
148
        
149
        $this->res->orderby = 'date_begin DESC';
150
        
151
        $this->res->archived = 0;
152
        $this->res->status = 'Y';
153
        
154
        
155
        $W = bab_Widgets();
156
        $datePicker = $W->DatePicker();
157
158
        if (2 === (int) bab_rp('searchtype')) {
159
            if ('0000-00-00' !== $begin = $datePicker->getISODate($f->param('dateb', null))) {
160
                $this->res->from = $begin;
161
            }
162
    
163 View Code Duplication
            if ('0000-00-00' !== $end = $datePicker->getISODate($f->param('datee', null))) {
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...
164
                $this->res->to = $this->addOneDay($end);
165
            }
166
        }
167
        
168
        if (1 === (int) bab_rp('searchtype')) {
169 View Code Duplication
            if ('0000-00-00' !== $date = $datePicker->getISODate($f->param('date', null))) {
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...
170
                $this->res->from = $date;
171
                $this->res->to = $this->addOneDay($date);
172
            }
173
        }
174
175
        $this->res->rewind();
176
177
        $this->paginate($this->res->count(), self::MAX);
178
        $this->res->seek($this->pos);
179
180
181
        $this->searchform = $f->getHtmlForm();
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...
182
    }
183
    
184
    
185
    /**
186
     * Add one day
187
     * @return string
188
     */
189
    private function addOneDay($strDate) {
190
        $date = BAB_DateTime::fromIsoDateTime($strDate);
191
        $date->add(1, BAB_DATETIME_DAY);
192
        return $date->getIsoDate();
193
    }
194
195
196
    public function getnext()
197
    {
198
        if (($this->res->key() - $this->pos) >= self::MAX)
199
        {
200
            return false;
201
        }
202
203
        if ($this->res->valid())
204
        {
205
            $entry = $this->res->current();
206
            /*@var $entry absences_Entry */
207
            	
208
            $this->altbg = !$this->altbg;
209
            	
210
            $this->username = bab_toHtml(bab_getUserName($entry->id_user));
0 ignored issues
show
Bug introduced by
The property username 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...
211
            $this->begin = bab_toHtml(bab_shortDate(bab_mktime($entry->date_begin)));
0 ignored issues
show
Bug introduced by
The property begin 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...
212
            $this->end = bab_toHtml(bab_shortDate(bab_mktime($entry->date_end)));
0 ignored issues
show
Bug introduced by
The property end 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...
213
            $this->quantity = bab_toHtml(absences_quantity($entry->getTotalDays(), 'D'));
0 ignored issues
show
Bug introduced by
The property quantity does not seem to exist. Did you mean t_quantity?

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...
214
215
            $this->res->next();
216
            return true;
217
        }
218
219
        return false;
220
    }
221
222
223
224
}
225
226
227
228
229
230
231
232
233
234
235
function absences_search()
236
{
237
    $babBody = bab_getBody();
238
    
239
    $list = new absences_SearchList();
240
    
241
    $babBody->setTitle(absences_translate('Absences'));
242
243
    $babBody->addStyleSheet(absences_Addon()->getStylePath().'vacation.css');
244
    $babBody->babEcho(bab_printTemplate($list, absences_addon()->getRelativePath()."search.html", "list"));
0 ignored issues
show
Deprecated Code introduced by
The method bab_addonInfos::getRelativePath() has been deprecated with message: Do not use relative path in addons Addons are subject to move out of the core folder in futures version for bab_printTemplate, replace with $addon->printTemplate() for babBody->addStyleSheet use $addon->getStylePath() instead of relative path the addStyleSheet method support full path starting with vendor/ since the 8.1.98 version

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
245
}
246
247
248
249
// Main
250
251
252
bab_requireAccess('absences_search_absences_groups', 1, absences_translate('You must be logged in'));
253
bab_siteMap::setPosition('absences','User');
254
255
absences_search();