From 83ed1f242396ed4fba37962c41e4ed733f4f409c Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Mon, 7 Dec 2020 17:55:45 +0800 Subject: [PATCH] * Adjust code. --- module/durationestimation/control.php | 94 +++++++++++-------- module/durationestimation/js/create.js | 4 +- module/durationestimation/model.php | 44 ++++++--- .../durationestimation/view/create.html.php | 2 +- module/durationestimation/view/index.html.php | 11 +-- module/workestimation/control.php | 14 +-- module/workestimation/lang/de.php | 4 +- module/workestimation/lang/en.php | 4 +- module/workestimation/lang/fr.php | 4 +- module/workestimation/lang/vi.php | 4 +- module/workestimation/lang/zh-cn.php | 4 +- module/workestimation/lang/zh-tw.php | 4 +- module/workestimation/model.php | 41 ++++---- module/workestimation/view/index.html.php | 4 +- 14 files changed, 131 insertions(+), 107 deletions(-) diff --git a/module/durationestimation/control.php b/module/durationestimation/control.php index 13a7d81a50..ba42d300cf 100644 --- a/module/durationestimation/control.php +++ b/module/durationestimation/control.php @@ -11,41 +11,55 @@ */ class durationestimation extends control { - public function index($programID) + /** + * Project duration estimation. + * + * @param int $projectID + * @access public + * @return void + */ + public function index($projectID) { - $workestimation = $this->loadModel('workestimation')->getBudget($programID); - if(!$workestimation) + $workestimation = $this->loadModel('workestimation')->getBudget($projectID); + if(empty($workestimation)) { echo js::alert($this->lang->durationestimation->setWorkestimation); - die(js::locate($this->createLink('workestimation', 'index', "currentProgram=$programID"))); + die(js::locate($this->createLink('workestimation', 'index', "projectID=$projectID"))); } - $this->loadModel('programplan'); - $program = $this->loadModel('project')->getById($programID); + $this->app->loadLang('programplan'); + $project = $this->loadModel('program')->getPRJByID($projectID); $stages = $this->loadModel('stage')->getStages(); - $title = $this->lang->durationestimation->common . $this->lang->colon . $program->name; - $this->view->estimationList = $this->durationestimation->getListByProgram($programID); - if(empty($this->view->estimationList)) $this->locate(inlink('create', "currentProgram=$programID")); + $estimationList = $this->durationestimation->getListByProject($projectID); + if(empty($estimationList)) $this->locate(inlink('create', "projectID=$projectID")); + + $this->view->title = $this->lang->durationestimation->common . $this->lang->colon . $project->name; + $this->view->position[] = $this->lang->durationestimation->common; $this->view->workestimation = $workestimation; - - $this->view->title = $title; - $this->view->program = $program; - $this->view->stages = $stages; - + $this->view->estimationList = $estimationList; + $this->view->project = $project; + $this->view->stages = $stages; $this->display(); } - public function create($programID = 0) + /** + * Save the project duration estimate. + * + * @param int $projectID + * @access public + * @return void + */ + public function create($projectID = 0) { - $workestimation = $this->loadModel('workestimation')->getBudget($programID); - if(!$workestimation) + $workestimation = $this->loadModel('workestimation')->getBudget($projectID); + if(empty($workestimation)) { echo js::alert($this->lang->durationestimation->setWorkestimation); - die(js::locate($this->createLink('workestimation', 'index', "currentProgram=$programID"))); + die(js::locate($this->createLink('workestimation', 'index', "projectID=$projectID"))); } - $this->loadModel('programplan'); + $this->app->loadLang('programplan'); if(!empty($_POST)) { $total = 0; @@ -54,49 +68,51 @@ class durationestimation extends control $workloadTotal = $this->config->durationestimation->workloadTotal; if($total != $workloadTotal) $this->send(array('result' => 'fail', 'message' => $this->lang->durationestimation->workloadError)); - $this->durationestimation->save($programID); + $this->durationestimation->save($projectID); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('index', "currentProgram={$programID}"))); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('index', "projectID={$projectID}"))); } - $this->view->estimationList = $this->durationestimation->getListByProgram($programID); + $project = $this->loadModel('program')->getPRJByID($projectID); + + $this->view->title = $this->lang->durationestimation->common . $this->lang->colon . $project->name; + $this->view->position[] = $this->lang->durationestimation->common; + $this->view->project = $project; + $this->view->stages = $this->loadModel('stage')->getStages(); + $this->view->estimationList = $this->durationestimation->getListByProject($projectID); $this->view->workestimation = $workestimation; - $program = $this->loadModel('project')->getById($programID); - $title = $this->lang->durationestimation->common . $this->lang->colon . $program->name; - - $this->view->title = $title; - $this->view->program = $program; - $this->view->stages = $this->loadModel('stage')->getStages(); - $this->display(); } /** - * ajaxGetDuration - * - * @param int $program - * @param int $workload - * @param int $worktimeRate - * @param int $people + * Calculate the end time of the duration. + * + * @param int $projectID + * @param int $stage + * @param int $workload + * @param int $worktimeRate + * @param int $people + * @param string $startDate * @access public * @return void */ - public function ajaxGetDuration($program, $stage, $workload, $worktimeRate, $people, $startDate) + public function ajaxGetDuration($projectID, $stage, $workload, $worktimeRate, $people, $startDate) { $startDate = str_replace('_', '-', $startDate); if($startDate == '0000-00-00') $this->send(array('result' => 'success', 'endDate' => '0000-00-00')); - $estimation = $this->loadModel('workestimation')->getBudget($program); + $estimation = $this->loadModel('workestimation')->getBudget($projectID); $duration = $estimation->duration * $workload / 100; $divisor = ($people == 0 || $estimation->dayHour == 0) ? 0 : $worktimeRate / 100 * $people * $estimation->dayHour; $duration = $divisor == 0 ? 0 : $duration / $divisor; if(!$divisor) $this->send(array('result' => 'fail')); - $holidays = array(); - $workDays = array(); + $holidays = array(); + $workDays = array(); $i = 0; + $this->loadModel('project'); $startedTime = strtotime($startDate); diff --git a/module/durationestimation/js/create.js b/module/durationestimation/js/create.js index 46374d3915..3951f85f7a 100644 --- a/module/durationestimation/js/create.js +++ b/module/durationestimation/js/create.js @@ -30,7 +30,7 @@ $().ready(function() $(':input').change(function() { var that = $(this); - programID = program.id; + projectID = project.id; stage = $(this).parents('tr').find('[name*=stage]').val(); workload = $(this).parents('tr').find('[name*=workload]').val(); worktimeRate = $(this).parents('tr').find('[name*=worktimeRate]').val(); @@ -39,7 +39,7 @@ $().ready(function() if(startDate) startDate = startDate.replace(/-/g, '_'); if(isNaN(workload) || isNaN(worktimeRate) || isNaN(people) || startDate == '') return false; - url = createLink('durationestimation', 'ajaxGetDuration', 'program=' + programID + '&stage=' + stage + '&workload=' + workload + '&worktimeRate=' + worktimeRate + '&people=' + people + '&startDate=' + startDate), + url = createLink('durationestimation', 'ajaxGetDuration', 'projectID=' + projectID + '&stage=' + stage + '&workload=' + workload + '&worktimeRate=' + worktimeRate + '&people=' + people + '&startDate=' + startDate), $.getJSON( url, function(response) diff --git a/module/durationestimation/model.php b/module/durationestimation/model.php index c43322f495..afb5abe32e 100644 --- a/module/durationestimation/model.php +++ b/module/durationestimation/model.php @@ -1,35 +1,49 @@ * @package durationestimation * @version $Id$ - * @link http://www.chanzhi.org + * @link http://www.zentao.net */ class durationestimationModel extends model { - public function getListByProgram($program) + /** + * Get the project duration estimate. + * + * @param int $projectID + * @access public + * @return void + */ + public function getListByProject($projectID) { - return $this->dao->select('*')->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($program)->fetchAll('stage'); + return $this->dao->select('*')->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($projectID)->fetchAll('stage'); } - public function save($program) + /** + * Save the project duration estimate. + * + * @param int $projectID + * @access public + * @return void + */ + public function save($projectID) { - $this->dao->delete()->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($program); + $this->dao->delete()->from(TABLE_DURATIONESTIMATION)->where('PRJ')->eq($projectID); foreach($this->post->stage as $i => $stage) { - $estimation = new stdclass; - $estimation->PRJ = $program; - $estimation->stage = $stage; - $estimation->workload = $this->post->workload[$i]; - $estimation->worktimeRate = $this->post->worktimeRate[$i]; - $estimation->people = $this->post->people[$i]; - $estimation->startDate = $this->post->startDate[$i]; - $estimation->endDate = $this->post->endDate[$i]; - $this->dao->insert(TABLE_DURATIONESTIMATION)->data($estimation)->exec(); + $data = new stdclass; + $data->PRJ = $projectID; + $data->stage = $stage; + $data->workload = $this->post->workload[$i]; + $data->worktimeRate = $this->post->worktimeRate[$i]; + $data->people = $this->post->people[$i]; + $data->startDate = $this->post->startDate[$i]; + $data->endDate = $this->post->endDate[$i]; + $this->dao->insert(TABLE_DURATIONESTIMATION)->data($data)->exec(); } return !dao::isError(); diff --git a/module/durationestimation/view/create.html.php b/module/durationestimation/view/create.html.php index 0fd12e4eb0..b27f3abfb6 100644 --- a/module/durationestimation/view/create.html.php +++ b/module/durationestimation/view/create.html.php @@ -1,5 +1,5 @@ - +