Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 42 |
| WF_dateIt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
650.00 | |
0.00% |
0 / 42 |
| __construct | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 5 |
|||
| set_startDate | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 5 |
|||
| set_endDate | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 5 |
|||
| get_startDate | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| get_endDate | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| get_days | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| get_maxLatestEndTime | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 7 |
|||
| set_dates | |
0.00% |
0 / 1 |
72.00 | |
0.00% |
0 / 16 |
|||
| rescheduleActivity | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| <?php | |
| namespace ia\Work\Workflow; | |
| /** | |
| * a workflow's activity list is dated | |
| * | |
| */ | |
| //@TODO reschedule when late | |
| class WF_dateIt { | |
| use wfx; | |
| protected $dateStart; | |
| protected $dateEnd; | |
| private $diador; // init con hour/day, weekdayschedule, holidays | |
| public function __construct(array $activityList, $diadorInjected = null) { | |
| $this->activityList = $activityList; | |
| if($diadorInjected === null) { | |
| $this->diador = new WorkDayCalculator(); | |
| } else { | |
| $this->diador = $diadorInjected; | |
| } | |
| } | |
| public function set_startDate($fecha, $activity_id = '') { | |
| if(empty($activity_id)) { | |
| return $this->set_dates( $fecha ); | |
| } | |
| if(empty($this->activityList[$activity_id])) { | |
| throw new \Exception("Unknown activity_id: $activity_id", self::$WF_ERROR_ACTIVITY_NOT_FOUND); | |
| } | |
| return $this->set_dates( $this->diador->sub($fecha, $this->activityList[$activity_id]['est']) ); | |
| } | |
| public function set_endDate($fecha, $activity_id = '') { | |
| if(empty($activity_id)) { | |
| $activity_id = $this->get_maxLatestEndTime(); | |
| } | |
| if(empty($this->activityList[$activity_id])) { | |
| throw new \Exception("Unknown activity_id: $activity_id", self::$WF_ERROR_ACTIVITY_NOT_FOUND); | |
| } | |
| return $this->set_dates( $this->diador->sub($fecha, $this->activityList[$activity_id]['eet']) ); | |
| } | |
| public function get_startDate() { return $this->dateStart; } | |
| public function get_endDate() { return $this->dateEnd; } | |
| public function get_days() { return $this->diador->workDaysArray($this->dateStart, $this->dateEnd); } | |
| private function get_maxLatestEndTime() { | |
| $maxT = PHP_INT_MIN; | |
| $maxAct = null; | |
| foreach($this->get_activitiesEnd() as $activity_id => $act) { | |
| if($maxT < $act['let']) { | |
| $maxT = $act['let']; | |
| $maxAct = $activity_id; | |
| } | |
| } | |
| return $maxAct; | |
| } | |
| private function set_dates($day0) { | |
| $this->dateStart = null; | |
| $this->dateEnd = null; | |
| foreach($this->activityList as $id => &$act) { | |
| if( $act['est'] === $act['lst']) { | |
| $act['plan']['est'] = $act['plan']['lst'] = $this->diador->add($day0, $act['est']); | |
| } else { | |
| $act['plan']['est'] = $this->diador->add($day0, $act['est']); | |
| $act['plan']['lst'] = $this->diador->add($day0, $act['lst']); | |
| } | |
| if( $act['eet'] === $act['let']) { | |
| $act['plan']['eet'] = $act['plan']['let'] = $this->diador->add($day0, $act['eet']); | |
| } else { | |
| $act['plan']['eet'] = $this->diador->add($day0, $act['eet']); | |
| $act['plan']['let'] = $this->diador->add($day0, $act['let']); | |
| } | |
| if($this->dateStart > $act['plan']['est'] || empty($this->dateStart)) { | |
| $this->dateStart = $act['plan']['est']; | |
| } | |
| if($this->dateEnd < $act['plan']['let'] || empty($this->dateEnd)) { | |
| $this->dateEnd = $act['plan']['let']; | |
| } | |
| } | |
| return $this->activityList; | |
| } | |
| public function rescheduleActivity($startDate, $activity_id) { | |
| if(empty($this->activityList[$activity_id])) { | |
| throw new \Exception("Unknown activity id", self::$WF_ERROR_ACTIVITY_NOT_FOUND); | |
| } | |
| // set $activity_id start date | |
| $next = empty($this->activityList[$activity_id]['nextAll']) ? [] : $this->activityList[$activity_id]['nextAll']; | |
| // foreach if started or done skip, if not started new startdates | |
| } | |
| } |