| Conditions | 4 |
| Paths | 1 |
| Total Lines | 341 |
| Code Lines | 218 |
| Lines | 64 |
| Ratio | 18.77 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 32 | function absences_listVacationRequestsb() |
||
| 33 | { |
||
| 34 | global $babBody; |
||
| 35 | |||
| 36 | class temp extends absences_Paginate |
||
|
|
|||
| 37 | { |
||
| 38 | var $nametxt; |
||
| 39 | var $urlname; |
||
| 40 | var $url; |
||
| 41 | var $editurl; |
||
| 42 | var $begindatetxt; |
||
| 43 | var $enddatetxt; |
||
| 44 | var $quantitytxt; |
||
| 45 | var $statustxt; |
||
| 46 | var $begindate; |
||
| 47 | var $enddate; |
||
| 48 | var $quantity; |
||
| 49 | var $status; |
||
| 50 | |||
| 51 | var $arr = array(); |
||
| 52 | var $count; |
||
| 53 | var $res; |
||
| 54 | |||
| 55 | var $statarr; |
||
| 56 | var $total; |
||
| 57 | var $checkall; |
||
| 58 | var $uncheckall; |
||
| 59 | |||
| 60 | var $usersbrowurl; |
||
| 61 | var $datetxt; |
||
| 62 | var $filteron; |
||
| 63 | var $usertxt; |
||
| 64 | var $begintxt; |
||
| 65 | var $endtxt; |
||
| 66 | var $userval; |
||
| 67 | var $userid; |
||
| 68 | var $dateb; |
||
| 69 | var $datee; |
||
| 70 | var $dateburl; |
||
| 71 | var $dateeurl; |
||
| 72 | var $topurl; |
||
| 73 | var $bottomurl; |
||
| 74 | var $nexturl; |
||
| 75 | var $prevurl; |
||
| 76 | var $topname; |
||
| 77 | var $bottomname; |
||
| 78 | var $nextname; |
||
| 79 | var $prevname; |
||
| 80 | var $pos; |
||
| 81 | |||
| 82 | var $resettxt; |
||
| 83 | |||
| 84 | var $entryid; |
||
| 85 | var $alttxt; |
||
| 86 | var $altbg = true; |
||
| 87 | |||
| 88 | function temp() |
||
| 89 | { |
||
| 90 | |||
| 91 | |||
| 92 | $idstatus = $this->param('idstatus'); |
||
| 93 | $userid = (int) $this->param('userid'); |
||
| 94 | $organization = (int) $this->param('organization'); |
||
| 95 | $dateb = $this->param('dateb'); |
||
| 96 | $datee = $this->param('datee'); |
||
| 97 | $vpos = (int) $this->param('vpos', 0); |
||
| 98 | $pos = (int) $this->param('pos', 0); |
||
| 99 | $archived = (int) bab_rp('archived', 0); |
||
| 100 | |||
| 101 | include_once $GLOBALS['babInstallPath']."utilit/urlincl.php"; |
||
| 102 | |||
| 103 | global $babDB, $babBody; |
||
| 104 | |||
| 105 | if ($archived) |
||
| 106 | { |
||
| 107 | $babBody->setTitle(absences_translate("Archived vacations requests list")); |
||
| 108 | } else { |
||
| 109 | $babBody->setTitle(absences_translate("Vacations requests list")); |
||
| 110 | } |
||
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | $this->uncheckall = absences_translate("Uncheck all"); |
||
| 115 | $this->checkall = absences_translate("Check all"); |
||
| 116 | $this->nametxt = absences_translate("Fullname"); |
||
| 117 | $this->begindatetxt = absences_translate("Begin date"); |
||
| 118 | $this->enddatetxt = absences_translate("End date"); |
||
| 119 | $this->quantitytxt = absences_translate("Quantity"); |
||
| 120 | $this->statustxt = absences_translate("Status"); |
||
| 121 | $this->datetxt = absences_translate("Date")." ( ".absences_translate("dd-mm-yyyy")." )"; |
||
| 122 | $this->filteron = absences_translate("Filter on"); |
||
| 123 | $this->usertxt = absences_translate("User"); |
||
| 124 | $this->begintxt = absences_translate("Begin"); |
||
| 125 | $this->endtxt = absences_translate("End"); |
||
| 126 | $this->resettxt = absences_translate("Reset"); |
||
| 127 | $this->alttxt = absences_translate("Modify"); |
||
| 128 | $this->t_edit = absences_translate("Modification"); |
||
| 129 | $this->t_delete = absences_translate("Delete"); |
||
| 130 | |||
| 131 | $this->t_first_page = absences_translate("First page"); |
||
| 132 | $this->t_previous_page = absences_translate("Previous page"); |
||
| 133 | $this->t_next_page = absences_translate("Next page"); |
||
| 134 | $this->t_last_page = absences_translate("Last page"); |
||
| 135 | |||
| 136 | $this->topurl = ""; |
||
| 137 | $this->bottomurl = ""; |
||
| 138 | $this->nexturl = ""; |
||
| 139 | $this->prevurl = ""; |
||
| 140 | |||
| 141 | $this->t_position = ''; |
||
| 142 | |||
| 143 | |||
| 144 | $this->statarr = array(absences_translate("Waiting"), absences_translate("Accepted"), absences_translate("Refused"), absences_translate('Previsional')); |
||
| 145 | $this->dateb = $dateb; |
||
| 146 | $this->datee = $datee; |
||
| 147 | $this->idstatus = $idstatus; |
||
| 148 | $this->userid = $userid; |
||
| 149 | $this->pos = $pos; |
||
| 150 | $this->userval = $userid != "" ? bab_toHtml(bab_getUserName($userid)) : ""; |
||
| 151 | $aaareq = array(); |
||
| 152 | |||
| 153 | $req = 'absences_entries e, |
||
| 154 | bab_users u LEFT JOIN absences_personnel p ON p.id_user=u.id WHERE '; |
||
| 155 | |||
| 156 | $aaareq[] = 'u.id=e.id_user'; |
||
| 157 | $aaareq[] = 'e.archived='.$babDB->quote($archived); |
||
| 158 | |||
| 159 | if( $idstatus != "" || $userid > 0 || $organization > 0 || $dateb != "" || $datee != "") |
||
| 160 | { |
||
| 161 | |||
| 162 | if( $idstatus != "") |
||
| 163 | { |
||
| 164 | switch($idstatus) |
||
| 165 | { |
||
| 166 | case 0: |
||
| 167 | $aaareq[] = "e.status=''"; break; |
||
| 168 | case 1: |
||
| 169 | $aaareq[] = "e.status='Y'"; break; |
||
| 170 | case 2: |
||
| 171 | $aaareq[] = "e.status='N'"; break; |
||
| 172 | case 3: |
||
| 173 | $aaareq[] = "e.status='P'"; break; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | if( $userid > 0) |
||
| 178 | { |
||
| 179 | $aaareq[] = "e.id_user='".$babDB->db_escape_string($userid)."'"; |
||
| 180 | } |
||
| 181 | |||
| 182 | if ($organization > 0) { |
||
| 183 | |||
| 184 | $aaareq[] = "p.id_organization='".$babDB->db_escape_string($organization)."'"; |
||
| 185 | } |
||
| 186 | |||
| 187 | View Code Duplication | if( $dateb != "" ) |
|
| 188 | { |
||
| 189 | $ar = explode("-", $dateb); |
||
| 190 | $dateb = $ar[2]."-".$ar[1]."-".$ar[0]; |
||
| 191 | } |
||
| 192 | |||
| 193 | View Code Duplication | if( $datee != "" ) |
|
| 194 | { |
||
| 195 | $ar = explode("-", $datee); |
||
| 196 | $datee = $ar[2]."-".$ar[1]."-".$ar[0]; |
||
| 197 | } |
||
| 198 | |||
| 199 | if( $datee != "" ) |
||
| 200 | { |
||
| 201 | $aaareq[] = "e.date_begin <= DATE_ADD('".$babDB->db_escape_string($datee)."', INTERVAL 1 DAY)"; |
||
| 202 | } |
||
| 203 | if( $dateb != "" ) |
||
| 204 | { |
||
| 205 | $aaareq[] = "e.date_end >= '".$babDB->db_escape_string($dateb)."'"; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 209 | View Code Duplication | if( sizeof($aaareq) > 0 ) |
|
| 210 | { |
||
| 211 | if( sizeof($aaareq) > 1 ) |
||
| 212 | $req .= implode(' AND ', $aaareq); |
||
| 213 | else |
||
| 214 | $req .= $aaareq[0]; |
||
| 215 | } |
||
| 216 | |||
| 217 | |||
| 218 | $orderby = bab_rp('orderby', 'begin'); |
||
| 219 | |||
| 220 | $url = bab_url::request('tg', 'idx', 'idstatus', 'userid', 'dateb', 'datee', 'vpos', 'orderby', 'archived'); |
||
| 221 | |||
| 222 | $this->orderby = bab_toHtml($orderby); |
||
| 223 | |||
| 224 | |||
| 225 | switch($orderby) { |
||
| 226 | |||
| 227 | case 'begin.asc': |
||
| 228 | $this->orderbyname = bab_url::mod($url, 'orderby', 'name'); |
||
| 229 | $this->orderbybegin = bab_url::mod($url, 'orderby', 'begin.desc'); |
||
| 230 | $req .= " ORDER BY e.date_begin ASC, u.lastname, u.firstname"; |
||
| 231 | break; |
||
| 232 | |||
| 233 | case 'begin.desc': |
||
| 234 | View Code Duplication | case 'begin': |
|
| 235 | $this->orderbyname = bab_url::mod($url, 'orderby', 'name'); |
||
| 236 | $this->orderbybegin = bab_url::mod($url, 'orderby', 'begin.asc'); |
||
| 237 | $req .= " ORDER BY e.date_begin desc, u.lastname, u.firstname"; |
||
| 238 | break; |
||
| 239 | |||
| 240 | View Code Duplication | case 'name.desc': |
|
| 241 | $this->orderbyname = bab_url::mod($url, 'orderby', 'name.asc'); |
||
| 242 | $this->orderbybegin = bab_url::mod($url, 'orderby', 'begin'); |
||
| 243 | $req .= " ORDER BY u.lastname DESC, u.firstname DESC, e.date desc"; |
||
| 244 | break; |
||
| 245 | |||
| 246 | case 'name.asc': |
||
| 247 | View Code Duplication | case 'name': |
|
| 248 | $this->orderbyname = bab_url::mod($url, 'orderby', 'name.desc'); |
||
| 249 | $this->orderbybegin = bab_url::mod($url, 'orderby', 'begin'); |
||
| 250 | $req .= " ORDER BY u.lastname ASC, u.firstname ASC, e.date desc"; |
||
| 251 | break; |
||
| 252 | } |
||
| 253 | |||
| 254 | |||
| 255 | list($total) = $babDB->db_fetch_row($babDB->db_query("select count(*) as total from ".$req)); |
||
| 256 | $this->paginate($total, ABSENCES_MAX_REQUESTS_LIST); |
||
| 257 | |||
| 258 | |||
| 259 | if( $total > ABSENCES_MAX_REQUESTS_LIST) |
||
| 260 | { |
||
| 261 | $req .= " limit ".$pos.",".ABSENCES_MAX_REQUESTS_LIST; |
||
| 262 | } |
||
| 263 | |||
| 264 | |||
| 265 | bab_debug("select e.*, u.lastname, u.firstname from ".$req); |
||
| 266 | |||
| 267 | $this->res = $babDB->db_query("select e.*, u.lastname, u.firstname from ".$req); |
||
| 268 | $this->count = $babDB->db_num_rows($this->res); |
||
| 269 | |||
| 270 | |||
| 271 | $this->searchform = $this->getSearchForm(); |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return string |
||
| 276 | */ |
||
| 277 | private function getSearchForm() |
||
| 278 | { |
||
| 279 | $f = new absences_getRequestSearchForm(); |
||
| 280 | return $f->getHtmlForm($this->statarr); |
||
| 281 | } |
||
| 282 | |||
| 283 | |||
| 284 | View Code Duplication | private function param($name, $default = '') |
|
| 285 | { |
||
| 286 | if (isset($_REQUEST[$name])) |
||
| 287 | { |
||
| 288 | $_SESSION['babVacation'][$name] = $_REQUEST[$name]; |
||
| 289 | return $_REQUEST[$name]; |
||
| 290 | } |
||
| 291 | |||
| 292 | if (isset($_SESSION['babVacation'][$name])) |
||
| 293 | { |
||
| 294 | return $_SESSION['babVacation'][$name]; |
||
| 295 | } |
||
| 296 | |||
| 297 | return $default; |
||
| 298 | } |
||
| 299 | |||
| 300 | public function getnext() |
||
| 301 | { |
||
| 302 | global $babDB; |
||
| 303 | static $i = 0; |
||
| 304 | if( $i < $this->count) |
||
| 305 | { |
||
| 306 | $this->altbg = !$this->altbg; |
||
| 307 | $arr = $babDB->db_fetch_array($this->res); |
||
| 308 | |||
| 309 | $entry = new absences_Entry(); |
||
| 310 | $entry->setRow($arr); |
||
| 311 | |||
| 312 | $this->urlname = bab_toHtml($arr['lastname'].' '.$arr['firstname']); |
||
| 313 | $this->url = bab_toHtml(absences_addon()->getUrl()."vacadmb&idx=morvw&id=".$arr['id']); |
||
| 314 | $this->editconfirmed = false; |
||
| 315 | if ($entry->firstconfirm && '' === $entry->status) { |
||
| 316 | $this->editconfirmed = absences_translate('Modification of an allready confirmed request'); |
||
| 317 | } |
||
| 318 | |||
| 319 | $this->todelete = false; |
||
| 320 | if ($entry->todelete) { |
||
| 321 | $this->todelete = absences_translate('Deletion request'); |
||
| 322 | } |
||
| 323 | |||
| 324 | $this->editurl = bab_toHtml($entry->getEditUrl(1)); |
||
| 325 | $url = absences_addon()->getUrl()."vacadmb&idx=lreq"; |
||
| 326 | $this->urldelete = bab_toHtml(absences_addon()->getUrl()."vacadmb&idx=delete&id_entry=".$arr['id']."&from=".urlencode($url)); |
||
| 327 | $this->quantity = bab_toHtml(absences_vacEntryQuantity($arr['id'])); |
||
| 328 | |||
| 329 | $this->begindate = bab_toHtml(absences_shortDate(bab_mktime($arr['date_begin']))); |
||
| 330 | $this->enddate = bab_toHtml(absences_shortDate(bab_mktime($arr['date_end']))); |
||
| 331 | |||
| 332 | $this->status = $entry->getStatusStr(); |
||
| 333 | |||
| 334 | $i++; |
||
| 335 | return true; |
||
| 336 | } |
||
| 337 | else |
||
| 338 | return false; |
||
| 339 | |||
| 340 | } |
||
| 341 | |||
| 342 | View Code Duplication | function getnextstatus() |
|
| 343 | { |
||
| 344 | static $i = 0; |
||
| 345 | if( $i < count($this->statarr)) |
||
| 346 | { |
||
| 347 | $this->statusid = $i; |
||
| 348 | $this->statusname = bab_toHtml($this->statarr[$i]); |
||
| 349 | if( $this->idstatus != "" && $i == $this->idstatus ) |
||
| 350 | $this->selected = "selected"; |
||
| 351 | else |
||
| 352 | $this->selected = ""; |
||
| 353 | $i++; |
||
| 354 | return true; |
||
| 355 | } |
||
| 356 | else |
||
| 357 | return false; |
||
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 361 | $temp = new temp(); |
||
| 362 | |||
| 363 | /*@var $babBody babBody */ |
||
| 364 | |||
| 365 | |||
| 366 | absences_addSpoofButton('entry', absences_translate('Add a vacation request')); |
||
| 367 | |||
| 368 | $babBody->addStyleSheet(absences_addon()->getStylePath().'vacation.css'); |
||
| 369 | $babBody->addJavascriptFile($GLOBALS['babInstallPath'].'scripts/bab_dialog.js'); |
||
| 370 | $babBody->babecho( bab_printTemplate($temp, absences_addon()->getRelativePath()."vacadmb.html", "vrequestslist")); |
||
| 371 | return $temp->count; |
||
| 372 | } |
||
| 373 | |||
| 1007 |
This check looks for classes that have been defined more than once.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.