* @package * @uses func * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) * @Link https://www.zentao.net */ class count_of_delayed_finished_task extends baseCalc { public $dataset = ''; public $fieldList = array(); public $result = array(); public $dateCounts = array(); public $startDate = ''; public $endDate = ''; public function calculate($row) { if(!empty($row->executionStartDate) && empty($this->startDate)) $this->startDate = $row->executionStartDate; if(!empty($row->executionEndDate) && empty($this->endDate)) $this->endDate = $row->executionEndDate; if(empty($row->finishedDate)) return false; $finishedDate = substr($row->finishedDate, 0, 10); if(!isset($this->dateCounts[$finishedDate])) $this->dateCounts[$finishedDate] = 0; $this->dateCounts[$finishedDate] ++; } public function getDatesBetween($startDate, $endDate) { $current = strtotime($startDate); $end = strtotime($endDate); $dates = []; while($current <= $end) { $dates[date('Y-m-d', $current)] = 0; $current += 86400; } return $dates; } public function getResult($options = array()) { $dateList = $this->getDatesBetween($this->startDate, $this->endDate); foreach($dateList as $date => $value) { if(isset($this->dateCounts[$date])) $value = $this->dateCounts[$date]; $this->result[$date] = $value; } $records = $this->getRecords(array('date', 'value')); return $this->filterByOptions($records, $options); } }