absences_OrganizationList::getnext()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 25
rs 8.8571
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
bab_Widgets()->includePhpClass('Widget_Form');
25
26
/**
27
 * Template class for organization list
28
 * 
29
 */
30
class absences_OrganizationList
31
{
32
    public $altbg = true;
33
    
34
    private $res;
35
    
36
    public function __construct()
37
    {
38
        global $babDB;
39
        
40
        $this->t_edit = absences_translate('Edit');
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...
41
        $this->t_name = absences_translate('Name');
0 ignored issues
show
Bug introduced by
The property t_name 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...
42
        $this->t_agents = absences_translate('Personnel members');
0 ignored issues
show
Bug introduced by
The property t_agents 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...
43
        $sync = (bool) absences_getVacationOption('organization_sync');
44
        $this->allowedit = !$sync;
0 ignored issues
show
Bug introduced by
The property allowedit 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...
45
        $this->res = $babDB->db_query('SELECT 
46
            
47
            o.id, o.name, COUNT(p.id) agents FROM absences_organization o 
48
                LEFT JOIN absences_personnel p ON p.id_organization=o.id 
49
            
50
            GROUP BY o.id 
51
            ORDER BY o.name');
52
    }
53
    
54
    public function getnext()
55
    {
56
        global $babDB;
57
        
58
        if ($arr = $babDB->db_fetch_assoc($this->res)) {
59
            $this->altbg = !$this->altbg;
60
            $this->name = bab_toHtml($arr['name']);
0 ignored issues
show
Bug introduced by
The property name 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...
61
            
62
            $url = bab_url::get_request('tg');
63
            $url->idx = 'edit';
64
            $url->id_organization = $arr['id'];
65
            
66
            $this->editurl = bab_toHtml($url->toString());
0 ignored issues
show
Bug introduced by
The property editurl 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...
67
            
68
            $this->agents = bab_toHtml($arr['agents']);
0 ignored issues
show
Bug introduced by
The property agents does not seem to exist. Did you mean t_agents?

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...
69
            
70
            $url = new bab_url(absences_Addon()->getUrl().'vacadm');
71
            $url->idx = 'lper';
72
            $url->filter = array('organization' => $arr['id']);
73
            $this->agentsurl = bab_toHtml($url->toString());
0 ignored issues
show
Bug introduced by
The property agentsurl 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...
74
            return true;
75
        }
76
        
77
        return false;
78
    }
79
80
}
81
82
83
84
85
/**
86
 * Get a html menu to create an organization
87
 * @return string
88
 */
89
function absences_organizationMenu()
90
{
91
    $toolbar = absences_getToolbar();
92
93
    $addon = bab_getAddonInfosInstance('absences');
94
    $sImgPath = $GLOBALS['babInstallPath'] . 'skins/ovidentia/images/Puces/';
95
96
    $sync = (int) absences_getVacationOption('organization_sync');
97 View Code Duplication
    if (!$sync)
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...
98
    {
99
    
100
        $toolbar->addToolbarItem(
101
            new BAB_ToolbarItem(
102
                absences_translate('Add organization'), 
103
                $addon->getUrl().'organizations&idx=edit',
104
                $sImgPath . 'edit_add.png', '', '', '')
105
        );
106
    
107
    }
108
109
    return $toolbar->printTemplate();
110
}
111
112
113
114
115
116
class absences_OrganizationEditor extends Widget_Form
117
{
118
119
    /**
120
     * @var absences_Organization
121
     */
122
    protected $organization;
123
    
124
    
125 View Code Duplication
    public function __construct(absences_Organization $organization)
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...
126
    {
127
        $W = bab_Widgets();
128
129
        parent::__construct(null, $W->VBoxLayout()->setVerticalSpacing(2,'em'));
130
131
        $this->organization = $organization;
132
133
        $this->setName('organization');
134
        $this->addClass('widget-bordered');
135
        $this->addClass('BabLoginMenuBackground');
136
        $this->addClass('widget-centered');
137
        $this->addClass(Func_Icons::ICON_LEFT_16);
138
        
139
        $this->colon();
140
141
        $this->setCanvasOptions($this->Options()->width(70,'em'));
0 ignored issues
show
Bug introduced by
It seems like $this->Options()->width(70, 'em') targeting Widget_CanvasOptions::width() can also be of type double; however, Widget_Item::setCanvasOptions() does only seem to accept object<Widget_CanvasOptions>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
142
143
        $this->addFields();
144
        $this->setValues($organization->getRow(), array('organization'));
145
146
        $this->addButtons();
147
        $this->setSelfPageHiddenFields();
148
    }
149
    
150
    
151
    
152
    protected function addFields()
153
    {
154
        $W = bab_Widgets();
155
156
        $this->addItem($W->LabelledWidget(
157
            absences_translate('Name'),
158
            $W->LineEdit()->setSize(70)->setMaxSize(255),
159
            'name'
160
        ));
161
    }
162
    
163
    
164
165
    protected function addButtons()
166
    {
167
        $W = bab_Widgets();
168
    
169
        $button = $W->FlowItems(
170
            $W->SubmitButton()->setName('save')->setLabel(absences_translate('Save'))
171
        )->setSpacing(2,'em')->setVerticalAlign('middle');
172
        
173
        $url = bab_url::get_request('tg');
174
        $url->idx = 'delete';
175
        $url->id_organization = $this->organization->id;
176
        
177
        $agents = $this->organization->getAgentInterator();
178
        
179
        if ($agents) {
180
        
181
            if ($agents->count()) {
182
                
183
                $button->addItem(
184
                    $W->Link(
185
                        $W->Icon(absences_translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), 
186
                        $url->toString()
187
                    )->setConfirmationMessage(sprintf(absences_translate('This organization is linked to %d users, do you really whant to delete it?'), $agents->count()))
188
                );
189
            } else {
190
                
191
                $button->addItem(
192
                    $W->Link($W->Icon(absences_translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), $url->toString())
193
                        ->setConfirmationMessage(absences_translate('Do you really whant to delete this organization?'))
194
                );
195
            }
196
        }
197
        
198
        
199
        $this->addItem($button);
200
    }
201
}
202