* @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 variance_of_time_in_project extends baseCalc { public $dataset = 'getAllProjects'; public $fieldList = array('t1.id', 't1.begin', 't1.end', 't1.realBegan', 't1.realEnd', 't1.status'); public $result = array(); public function calculate($row) { $project = $row->id; $begin = $row->begin; $end = $row->end; $realBegan = $row->realBegan; $realEnd = $row->realEnd; $status = $row->status; if($status != 'doing' and $status != 'closed') return false; $plan = (strtotime($end) - strtotime($begin)) / 86400; if($status == 'doing') { if(!$this->isDate($realBegan)) return false; $realEnd = date('Y-m-d'); } if($status == 'closed' && (!$this->isDate($realBegan) || !$this->isDate($realEnd))) return false; $actual = (strtotime($realEnd) - strtotime($realBegan)) / 86400; $this->result[$project] = $actual - $plan; } public function getResult($options = array()) { $records = $this->getRecords(array('project', 'value')); return $this->filterByOptions($records, $options); } }