Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like absences_Request 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 absences_Request, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 47 | abstract class absences_Request extends absences_Record |
||
| 48 | { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * |
||
| 52 | * @var absences_Agent |
||
| 53 | */ |
||
| 54 | protected $agent; |
||
| 55 | |||
| 56 | |||
| 57 | /** |
||
| 58 | * |
||
| 59 | * @var absences_Movement |
||
| 60 | */ |
||
| 61 | private $lastMovement; |
||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * @param int $id |
||
| 67 | * @return absences_Request |
||
| 68 | */ |
||
| 69 | abstract static public function getById($id); |
||
| 70 | |||
| 71 | |||
| 72 | /** |
||
| 73 | * @return absences_Agent |
||
| 74 | */ |
||
| 75 | 5 | View Code Duplication | public function getAgent() |
|
|
|||
| 76 | { |
||
| 77 | 5 | require_once dirname(__FILE__).'/agent.class.php'; |
|
| 78 | |||
| 79 | 5 | if (!isset($this->agent)) |
|
| 80 | 5 | { |
|
| 81 | 5 | $row = $this->getRow(); |
|
| 82 | 5 | $this->agent = absences_Agent::getFromIdUser($row['id_user']); |
|
| 83 | 5 | } |
|
| 84 | |||
| 85 | 5 | return $this->agent; |
|
| 86 | } |
||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | /** |
||
| 92 | * Method to sort requests by creation date |
||
| 93 | */ |
||
| 94 | public function createdOn() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Method to sort requests by modification date |
||
| 101 | */ |
||
| 102 | public function modifiedOn() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | public function getUserName() |
||
| 115 | |||
| 116 | |||
| 117 | protected function labelledValue($title, $value) |
||
| 118 | { |
||
| 119 | $W = bab_Widgets(); |
||
| 120 | return $W->FlowItems($W->Label($title)->addClass('widget-strong')->colon(), $W->Label($value))->setHorizontalSpacing(.4,'em'); |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * |
||
| 125 | * @return string |
||
| 126 | */ |
||
| 127 | abstract public function getRequestType(); |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Get status on date |
||
| 131 | * @param string $date |
||
| 132 | * @return string |
||
| 133 | */ |
||
| 134 | 10 | public function getDateStatus($date) |
|
| 135 | { |
||
| 136 | 10 | if (!isset($date) || '0000-00-00' === $date) { |
|
| 137 | 4 | return $this->status; |
|
| 138 | } |
||
| 139 | |||
| 140 | |||
| 141 | 7 | require_once dirname(__FILE__).'/movement.class.php'; |
|
| 142 | 7 | $I = new absences_MovementIterator(); |
|
| 143 | 7 | $I->setRequest($this); |
|
| 144 | 7 | $I->createdOn = $date; |
|
| 145 | |||
| 146 | 7 | foreach($I as $movement) { |
|
| 147 | |||
| 148 | // mouvement le plus recent avant la date |
||
| 149 | |||
| 150 | 4 | if (!isset($movement->status)) { |
|
| 151 | // movement created before status field in database |
||
| 152 | return $this->status; |
||
| 153 | } |
||
| 154 | |||
| 155 | 4 | return $movement->status; |
|
| 156 | |||
| 157 | 6 | } |
|
| 158 | |||
| 159 | 6 | return $this->status; |
|
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return string |
||
| 164 | */ |
||
| 165 | 1 | public function getShortStatusStr() |
|
| 166 | { |
||
| 167 | 1 | switch($this->status) |
|
| 168 | { |
||
| 169 | 1 | case 'Y': |
|
| 170 | 1 | return absences_translate("Accepted"); |
|
| 171 | case 'N': |
||
| 172 | return absences_translate("Refused"); |
||
| 173 | case 'P': |
||
| 174 | return absences_translate("Previsional request"); |
||
| 175 | default: |
||
| 176 | return absences_translate("Waiting approval"); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | |||
| 181 | /** |
||
| 182 | * Get status as a string |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | public function getStatusStr() |
||
| 186 | { |
||
| 187 | switch($this->status) |
||
| 188 | { |
||
| 189 | case 'Y': |
||
| 190 | return absences_translate("Accepted"); |
||
| 191 | case 'N': |
||
| 192 | return absences_translate("Refused"); |
||
| 193 | case 'P': |
||
| 194 | return absences_translate("Previsional request"); |
||
| 195 | default: |
||
| 196 | if ($this->todelete) { |
||
| 197 | return sprintf(absences_translate("Will be deleted after approval by %s"), $this->getNextApprovers()); |
||
| 198 | } |
||
| 199 | return sprintf(absences_translate("Waiting approval by %s"), $this->getNextApprovers()); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | /** |
||
| 206 | * @return Widget_Icon |
||
| 207 | */ |
||
| 208 | public function getStatusIcon() |
||
| 209 | { |
||
| 210 | $W = bab_Widgets(); |
||
| 211 | |||
| 212 | switch($this->status) |
||
| 213 | { |
||
| 214 | case 'Y': |
||
| 215 | $icon = Func_Icons::ACTIONS_DIALOG_OK; |
||
| 216 | break; |
||
| 217 | case 'N': |
||
| 218 | $icon = Func_Icons::ACTIONS_DIALOG_CANCEL; |
||
| 219 | break; |
||
| 220 | case 'P': |
||
| 221 | $icon = Func_Icons::STATUS_DIALOG_QUESTION; |
||
| 222 | break; |
||
| 223 | default: |
||
| 224 | $icon = Func_Icons::ACTIONS_VIEW_HISTORY; |
||
| 225 | break; |
||
| 226 | } |
||
| 227 | |||
| 228 | return $W->Icon($this->getStatusStr(), $icon); |
||
| 229 | } |
||
| 230 | |||
| 231 | |||
| 232 | /** |
||
| 233 | * Test if the has been fixed by a manager (not modifiable by the user) |
||
| 234 | * @return bool |
||
| 235 | */ |
||
| 236 | public function isFixed() |
||
| 237 | { |
||
| 238 | return false; |
||
| 239 | |||
| 240 | } |
||
| 241 | |||
| 242 | |||
| 243 | 4 | private function getNames($arr) |
|
| 244 | 4 | { |
|
| 245 | $return = array(); |
||
| 246 | |||
| 247 | foreach($arr as $k => $id_user) |
||
| 248 | 4 | { |
|
| 249 | $return[$k] = bab_getUserName($id_user); |
||
| 250 | } |
||
| 251 | |||
| 252 | return $return; |
||
| 253 | } |
||
| 254 | |||
| 255 | |||
| 256 | /** |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | 4 | public function getNextApprovers() |
|
| 260 | { |
||
| 261 | 4 | require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
|
| 262 | |||
| 263 | $arr = bab_WFGetWaitingApproversInstance($this->idfai); |
||
| 264 | |||
| 265 | if (count($arr) <= 3) |
||
| 266 | { |
||
| 267 | return implode(', ', $this->getNames($arr)); |
||
| 268 | 4 | } |
|
| 269 | |||
| 270 | $first = array_shift($arr); |
||
| 271 | $second = array_shift($arr); |
||
| 272 | |||
| 273 | return sprintf(absences_translate('%s, %s and %d other approvers'), bab_getUserName($first), bab_getUserName($second), count($arr)); |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Get the apporbation sheme ID for the request |
||
| 278 | * @return int |
||
| 279 | */ |
||
| 280 | 4 | abstract public function getApprobationId(); |
|
| 281 | |||
| 282 | |||
| 283 | |||
| 284 | /** |
||
| 285 | * @return bool |
||
| 286 | */ |
||
| 287 | 4 | protected function autoApproval() |
|
| 288 | { |
||
| 289 | $this->onConfirm(); |
||
| 290 | $this->addMovement(sprintf(absences_translate('The %s has been accepted with auto-approval'), $this->getTitle())); |
||
| 291 | 4 | return false; |
|
| 292 | } |
||
| 293 | |||
| 294 | |||
| 295 | |||
| 296 | 4 | private function getAutoApprovalUserId() |
|
| 297 | { |
||
| 298 | if (!absences_getVacationOption('auto_approval')) { |
||
| 299 | return 0; |
||
| 300 | } |
||
| 301 | |||
| 302 | return bab_getUserId(); |
||
| 303 | 4 | } |
|
| 304 | |||
| 305 | |||
| 306 | |||
| 307 | /** |
||
| 308 | * Create approbation instance and set it "notified" but do not send email notification |
||
| 309 | * retourne TRUE si la demande est bien devenue en attente d'approbation |
||
| 310 | * @return bool |
||
| 311 | */ |
||
| 312 | 4 | public function createApprobationInstance() |
|
| 313 | { |
||
| 314 | require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
||
| 315 | |||
| 316 | if (isset($this->idfai) && $this->idfai > 0) |
||
| 317 | { |
||
| 318 | bab_WFDeleteInstance($this->idfai); |
||
| 319 | } |
||
| 320 | |||
| 321 | // si le 3eme parametre est passe avec l'id user en cours, cela active l'auto-approbation |
||
| 322 | // l'auto-approbation a ete active a partir de la version 2.21 du module |
||
| 323 | // le dernier parametre necessite la version 8.0.100 d'ovidentia pour fonctionner (correction du bug de detection du supperieur hierarchique quand le gestionnaire depose l'absence) |
||
| 324 | |||
| 325 | $idfai = bab_WFMakeInstance($this->getApprobationId(), get_class($this).':'.$this->id, $this->getAutoApprovalUserId(), $this->id_user); |
||
| 326 | if (is_int($idfai)) |
||
| 327 | { |
||
| 328 | $users = bab_WFGetWaitingApproversInstance($idfai, true); |
||
| 329 | if (count($users) == 0) |
||
| 330 | { |
||
| 331 | $a = bab_WFGetApprobationInfos($this->getApprobationId()); |
||
| 332 | |||
| 333 | // l'instance n'a pas fonctionne |
||
| 334 | bab_WFDeleteInstance($idfai); |
||
| 335 | //TRANSLATORS: \n%1: request type (vacation request), \n%2: schema type (Staff schema), \n%3: schema name |
||
| 336 | $this->addMovement(sprintf(absences_translate('The approval initialisation failed on the %s because no approvers were found on %s %s'), $this->getTitle(), mb_strtolower($a['type']), $a['name'])); |
||
| 337 | return $this->autoApproval(); |
||
| 338 | } |
||
| 339 | |||
| 340 | if (isset($this->todelete) && $this->todelete) { |
||
| 341 | 4 | $this->addMovement(sprintf(absences_translate('The %s has been sent to deletion approval'), $this->getTitle())); |
|
| 342 | 4 | } else { |
|
| 343 | 4 | $this->addMovement(sprintf(absences_translate('The %s has been sent for approval'), $this->getTitle())); |
|
| 344 | 4 | } |
|
| 345 | |||
| 346 | 4 | } else { // $idfai == TRUE : auto-approbation end schema |
|
| 347 | 4 | return $this->autoApproval(); |
|
| 348 | 4 | } |
|
| 349 | |||
| 350 | $this->idfai = $idfai; |
||
| 351 | $this->status = ''; |
||
| 352 | $this->id_approver = 0; |
||
| 353 | $this->appr_notified = 0; |
||
| 354 | $this->comment2 = ''; |
||
| 355 | $this->save(); |
||
| 356 | |||
| 357 | return true; |
||
| 358 | } |
||
| 359 | |||
| 360 | |||
| 361 | /** |
||
| 362 | * Approbator confirm |
||
| 363 | * move to next approbator or close instance and set the request accepted |
||
| 364 | * |
||
| 365 | * |
||
| 366 | * @param bool $status Accept or reject approbation step |
||
| 367 | * @param string $approver_comment |
||
| 368 | * |
||
| 369 | */ |
||
| 370 | public function approbationNext($status, $approver_comment) |
||
| 371 | { |
||
| 372 | require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
||
| 373 | $res = bab_WFUpdateInstance($this->idfai, bab_getUserId(), $status); |
||
| 374 | |||
| 375 | switch ($res) { |
||
| 376 | case 0: |
||
| 377 | bab_WFDeleteInstance($this->idfai); |
||
| 378 | $this->idfai = 0; |
||
| 379 | if ($this->todelete) { |
||
| 380 | |||
| 381 | // demande de suppression refusee |
||
| 382 | $this->status = 'Y'; |
||
| 383 | } else { |
||
| 384 | $this->status = 'N'; |
||
| 385 | } |
||
| 386 | $this->onReject(); |
||
| 387 | break; |
||
| 388 | |||
| 389 | case 1: |
||
| 390 | bab_WFDeleteInstance($this->idfai); |
||
| 391 | $this->idfai = 0; |
||
| 392 | $this->status = 'Y'; |
||
| 393 | |||
| 394 | if (!$this->firstconfirm) { |
||
| 395 | $this->firstconfirm = 1; |
||
| 396 | } |
||
| 397 | |||
| 398 | if ($this->todelete) { |
||
| 399 | return $this->delete(); |
||
| 400 | } |
||
| 401 | $this->onConfirm(); |
||
| 402 | break; |
||
| 403 | |||
| 404 | |||
| 405 | default: // -1 |
||
| 406 | $nfusers = bab_WFGetWaitingApproversInstance($this->idfai, true); |
||
| 407 | if (count($nfusers) > 0) { |
||
| 408 | $this->appr_notified = 0; |
||
| 409 | } else { |
||
| 410 | // no approvers found or approvers allready notified (all user must confirm without order) |
||
| 411 | // do nothing |
||
| 412 | } |
||
| 413 | |||
| 414 | break; |
||
| 415 | } |
||
| 416 | |||
| 417 | $this->id_approver = bab_getUserId(); |
||
| 418 | $this->comment2 = $approver_comment; |
||
| 419 | $this->save(); |
||
| 420 | |||
| 421 | |||
| 422 | $str_status = $status ? absences_translate('accepted') :absences_translate('rejected'); |
||
| 423 | |||
| 424 | // movement must be saved after status modification to save the new status in movement |
||
| 425 | $this->addMovement( |
||
| 426 | sprintf(absences_translate('The %s has been %s by %s'), $this->getTitle(), $str_status, bab_getUserName(bab_getUserId())), |
||
| 427 | $approver_comment |
||
| 428 | ); |
||
| 429 | |||
| 430 | } |
||
| 431 | |||
| 432 | |||
| 433 | |||
| 434 | /** |
||
| 435 | * Auto confirm the request |
||
| 436 | */ |
||
| 437 | public function autoConfirm() |
||
| 438 | { |
||
| 439 | $this->addMovement( |
||
| 440 | sprintf(absences_translate('The %s has been confirmed automatically because of the validation timout'), $this->getTitle()) |
||
| 441 | ); |
||
| 442 | |||
| 443 | |||
| 444 | if ($this->idfai > 0) |
||
| 445 | { |
||
| 446 | require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
||
| 447 | bab_WFDeleteInstance($this->idfai); |
||
| 448 | } |
||
| 449 | |||
| 450 | $this->idfai = 0; |
||
| 451 | $this->status = 'Y'; |
||
| 452 | $this->onConfirm(); |
||
| 453 | |||
| 454 | $this->id_approver = 0; |
||
| 455 | $this->save(); |
||
| 456 | $this->notifyOwner(); |
||
| 457 | } |
||
| 458 | |||
| 459 | |||
| 460 | |||
| 461 | /** |
||
| 462 | * Test if the logged in user can modify the entry |
||
| 463 | * @return bool |
||
| 464 | */ |
||
| 465 | public function canModify() |
||
| 466 | { |
||
| 467 | $modify_waiting = (bool) absences_getVacationOption('modify_waiting'); |
||
| 468 | $modify_confirmed = (bool) absences_getVacationOption('modify_confirmed'); |
||
| 469 | |||
| 470 | require_once dirname(__FILE__).'/agent.class.php'; |
||
| 471 | $agent = absences_Agent::getCurrentUser(); |
||
| 472 | |||
| 473 | $personal = ($agent->isInPersonnel() && $agent->id_user === $this->id_user); |
||
| 474 | |||
| 475 | switch($this->status) |
||
| 476 | { |
||
| 477 | case 'Y': // confirmed |
||
| 478 | if ($this->isFixed()) { |
||
| 479 | return false; |
||
| 480 | } |
||
| 481 | |||
| 482 | if ($modify_confirmed) { |
||
| 483 | return true; |
||
| 484 | } |
||
| 485 | |||
| 486 | return !$personal; // ce n'est pas ma propre demande, je suis gestionnaire delegue |
||
| 487 | |||
| 488 | |||
| 489 | |||
| 490 | case 'N': // rejected |
||
| 491 | return false; |
||
| 492 | |||
| 493 | case 'P': // previsional |
||
| 494 | return $personal; |
||
| 495 | |||
| 496 | default: // waiting |
||
| 497 | return ($personal && $modify_waiting); |
||
| 498 | } |
||
| 499 | } |
||
| 500 | |||
| 501 | |||
| 502 | /** |
||
| 503 | * Test if the user can delete the entry |
||
| 504 | * @return bool |
||
| 505 | */ |
||
| 506 | public function canDelete() |
||
| 510 | |||
| 511 | |||
| 512 | |||
| 513 | |||
| 514 | |||
| 515 | /** |
||
| 516 | * Process specific code when the request is rejected |
||
| 517 | * |
||
| 518 | */ |
||
| 519 | abstract protected function onReject(); |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Process specific code when the request is confirmed |
||
| 523 | */ |
||
| 524 | abstract protected function onConfirm(); |
||
| 525 | |||
| 526 | /** |
||
| 527 | * request title |
||
| 528 | * @return string |
||
| 529 | */ |
||
| 530 | abstract public function getTitle(); |
||
| 531 | |||
| 532 | |||
| 533 | |||
| 534 | /** |
||
| 535 | * Get a list of field to display in the notifications for this request |
||
| 536 | * @return array |
||
| 537 | */ |
||
| 538 | abstract public function getNotifyFields(); |
||
| 539 | |||
| 540 | |||
| 541 | /** |
||
| 542 | * annee de la demande |
||
| 543 | * @return int |
||
| 544 | */ |
||
| 545 | abstract public function getYear(); |
||
| 546 | |||
| 547 | |||
| 548 | /** |
||
| 549 | * annee de la demande, pour l'archivage par annee, tiens compte du parametrage du mois de debut de periode. |
||
| 550 | * Utilise dans l'archivage par annee |
||
| 551 | * @return int |
||
| 552 | */ |
||
| 553 | abstract public function getArchiveYear(); |
||
| 554 | |||
| 555 | |||
| 556 | abstract public function archive(); |
||
| 557 | |||
| 558 | |||
| 559 | /** |
||
| 560 | * approver has been notified |
||
| 561 | */ |
||
| 562 | abstract public function setNotified(); |
||
| 563 | |||
| 564 | |||
| 565 | /** |
||
| 566 | * Url to edit request as a manager |
||
| 567 | */ |
||
| 568 | abstract public function getManagerEditUrl(); |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Url to delete request as a manager |
||
| 572 | */ |
||
| 573 | abstract public function getManagerDeleteUrl(); |
||
| 574 | |||
| 575 | |||
| 576 | /** |
||
| 577 | * Notify request next approvers |
||
| 578 | */ |
||
| 579 | public function notifyApprovers() |
||
| 580 | { |
||
| 581 | $defer = (bool) absences_getVacationOption('approb_email_defer'); |
||
| 582 | if (!$defer) |
||
| 583 | { |
||
| 584 | require_once dirname(__FILE__).'/request.notify.php'; |
||
| 585 | absences_notifyRequestApprovers(); |
||
| 586 | } |
||
| 587 | } |
||
| 588 | |||
| 589 | |||
| 590 | /** |
||
| 591 | * Notify request owner about the approval or reject of the request |
||
| 592 | */ |
||
| 593 | public function notifyOwner() |
||
| 594 | { |
||
| 595 | $appliquant_email = (bool) absences_getVacationOption('appliquant_email'); |
||
| 596 | |||
| 597 | if (!$appliquant_email) |
||
| 598 | { |
||
| 599 | return; |
||
| 600 | } |
||
| 601 | |||
| 602 | require_once dirname(__FILE__).'/request.notify.php'; |
||
| 603 | |||
| 604 | |||
| 605 | |||
| 606 | switch($this->status) |
||
| 607 | { |
||
| 608 | case 'N': |
||
| 609 | $subject = sprintf(absences_translate("Your %s has been refused"), $this->getTitle()); |
||
| 610 | break; |
||
| 611 | |||
| 612 | case 'Y': |
||
| 613 | $subject = sprintf(absences_translate("Your %s has been accepted"), $this->getTitle()); |
||
| 614 | break; |
||
| 615 | |||
| 616 | default: // next approver |
||
| 617 | return; |
||
| 618 | } |
||
| 619 | |||
| 620 | absences_notifyRequestAuthor(array($this), $subject, $subject, $this->id_user); |
||
| 621 | } |
||
| 622 | |||
| 623 | |||
| 624 | /** |
||
| 625 | * Get request card frame to display in requests list |
||
| 626 | * @param bool $display_username Affiche le nom du demandeur dans la card frame ou non, utile pour les listes contenant plusieurs demandeurs possibles |
||
| 627 | * @param int $rfrom si les demandes de la liste sont modifiee par un gestionnaire ou gestionnaire delegue |
||
| 628 | * @param int $ide id entite de l'organigramme >0 si gestionnaire delegue seulement |
||
| 629 | * @return Widget_Frame |
||
| 630 | */ |
||
| 631 | abstract public function getCardFrame($display_username, $rfrom, $ide); |
||
| 632 | |||
| 633 | |||
| 634 | /** |
||
| 635 | * Get request frame to display in manager lists |
||
| 636 | * @return Widget_Frame |
||
| 637 | */ |
||
| 638 | abstract public function getManagerFrame(); |
||
| 639 | |||
| 640 | |||
| 641 | |||
| 642 | /** |
||
| 643 | * Delete request |
||
| 644 | */ |
||
| 645 | public function delete() |
||
| 646 | { |
||
| 647 | if ($this->idfai > 0) |
||
| 648 | { |
||
| 649 | require_once $GLOBALS['babInstallPath'].'utilit/wfincl.php'; |
||
| 650 | bab_WFDeleteInstance($this->idfai); |
||
| 656 | |||
| 657 | |||
| 658 | |||
| 659 | /** |
||
| 660 | * @return absences_MovementIterator |
||
| 661 | */ |
||
| 662 | public function getMovementIterator() |
||
| 671 | |||
| 672 | |||
| 673 | |||
| 674 | /** |
||
| 675 | * |
||
| 676 | * @param string $message Generated message |
||
| 677 | * @param string $comment Author comment |
||
| 678 | */ |
||
| 679 | 4 | View Code Duplication | public function addMovement($message, $comment = '', $createdOn = null) |
| 680 | { |
||
| 681 | 4 | require_once dirname(__FILE__).'/movement.class.php'; |
|
| 682 | |||
| 683 | 4 | $movement = new absences_Movement(); |
|
| 684 | 4 | $movement->message = $message; |
|
| 685 | 4 | $movement->comment = $comment; |
|
| 686 | 4 | $movement->setRequest($this); |
|
| 687 | 4 | $movement->setAgent($this->getAgent()); |
|
| 688 | 4 | $movement->createdOn = $createdOn; |
|
| 689 | 4 | $movement->save(); |
|
| 690 | 4 | } |
|
| 691 | |||
| 692 | |||
| 693 | |||
| 694 | /** |
||
| 695 | * @return absences_Movement |
||
| 696 | */ |
||
| 697 | public function getLastMovement() |
||
| 712 | |||
| 713 | |||
| 714 | /** |
||
| 715 | * Faut-il allerter l'approbateur que le delai d'approbation est depasse |
||
| 716 | * @return bool |
||
| 717 | */ |
||
| 718 | public function approbAlert() |
||
| 739 | } |
||
| 740 | |||
| 741 | |||
| 742 | |||
| 743 | |||
| 744 | |||
| 745 | |||
| 746 | |||
| 1014 |
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.