From c21f651fec8740b448de6046776daa975cf984b5 Mon Sep 17 00:00:00 2001 From: lanzongjun Date: Fri, 28 Apr 2023 15:57:46 +0800 Subject: [PATCH] * Code format. --- module/todo/config/form.php | 5 + module/todo/control.php | 243 ++++++++++--------------------- module/todo/model.php | 91 ++++++------ module/todo/tao.php | 33 ++--- module/todo/test/model/close.php | 1 - module/todo/zen.php | 150 +++++++++++++++++-- 6 files changed, 276 insertions(+), 247 deletions(-) diff --git a/module/todo/config/form.php b/module/todo/config/form.php index d4ee2ecc3d..d4db331850 100644 --- a/module/todo/config/form.php +++ b/module/todo/config/form.php @@ -35,3 +35,8 @@ $config->todo->assignTo->form['assignedTo'] = array('required' => true, 'type $config->todo->batchClose = new stdclass; $config->todo->batchClose->form = array(); $config->todo->batchClose->form['todoIDList'] = array('required' => true, 'type' => 'array'); + +$config->todo->batchEdit = new stdClass; +$config->todo->batchEdit->form = array(); +$config->todo->batchEdit->form['todoIDList'] = array('required' => true, 'type' => 'array'); +$config->todo->batchEdit->form['names'] = array('required' => true, 'type' => 'array'); \ No newline at end of file diff --git a/module/todo/control.php b/module/todo/control.php index c03295c8f6..db6aecfe0c 100755 --- a/module/todo/control.php +++ b/module/todo/control.php @@ -2,7 +2,7 @@ declare(strict_types=1); /** - * The control file of example module of ZenTaoPMS. + * The control file of todo module of ZenTaoPMS. * * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net) * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) @@ -29,15 +29,15 @@ class todo extends control } /** - * 创建待办 + * 创建待办。 * Create a todo. * * @param string $date * @param string $from todo|feedback|block * @access public - * @return int|void + * @return int */ - public function create(string $date = 'today', string $from = 'todo') + public function create(string $date = 'today', string $from = 'todo'): int { if($date == 'today') $date = date::today(); @@ -56,7 +56,7 @@ class todo extends control if($from == 'block') { - $todo = $this->todo->getById($todoID); + $todo = $this->todo->getByID($todoID); $todo->begin = date::formatTime($todo->begin); return $this->send(array('result' => 'success', 'id' => $todoID, 'name' => $todo->name, 'pri' => $todo->pri, 'priName' => $this->lang->todo->priList[$todo->pri], 'time' => date(DT_DATE4, strtotime($todo->date)) . ' ' . $todo->begin)); } @@ -69,12 +69,7 @@ class todo extends control unset($this->lang->todo->typeList['cycle']); - $this->view->title = $this->lang->todo->common . $this->lang->colon . $this->lang->todo->create; - $this->view->date = date('Y-m-d', strtotime($date)); - $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); - $this->view->time = date::now(); - $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted|noempty'); - $this->display(); + $this->buildCreateForm($date); } /** @@ -128,17 +123,16 @@ class todo extends control } /** - * 编辑待办数据 + * 编辑待办数据。 * Edit a todo. * * @param string $todoID * @access public - * @return void + * @return int */ - public function edit(string $todoID) + public function edit(string $todoID): int { - $todoID = (int)$todoID; - + $todoID = (int)$todoID; if(!empty($_POST)) { $formData = form::data($this->config->todo->edit->form); @@ -164,18 +158,12 @@ class todo extends control } /* Judge a private todo or not, If private, die. */ - $todo = $this->todo->getById($todoID); + $todo = $this->todo->getByID($todoID); if($todo->private and $this->app->user->account != $todo->account) return print('private'); unset($this->lang->todo->typeList['cycle']); - $todo->date = date("Y-m-d", strtotime($todo->date)); - $this->view->title = $this->lang->todo->common . $this->lang->colon . $this->lang->todo->edit; - $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); - $this->view->todo = $todo; - $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted|noempty'); - - $this->display(); + $this->renderEditData($todoID); } /** @@ -188,113 +176,26 @@ class todo extends control * @access public * @return void */ - public function batchEdit($from = '', $type = 'today', $userID = '', $status = 'all') + public function batchEdit(string $from = '', string $type = 'today', string $userID = '', string $status = 'all') { /* Get form data for my-todo. */ - if($from == 'myTodo') + if($from == 'myTodo') $this->todoZen->batchEditFromMyTodo($type, $userID, $status); + if($from == 'todoBatchEdit') { - /* Initialize vars. */ - $editedTodos = array(); - $todoIDList = array(); - $columns = 7; - - if($userID == '') $userID = $this->app->user->id; - $user = $this->loadModel('user')->getById($userID, 'id'); - $account = $user->account; - - $reviews = array(); - if($this->config->edition == 'max') $reviews = $this->loadModel('review')->getUserReviewPairs($account); - $allTodos = $this->todo->getList($type, $account, $status); - if($this->post->todoIDList) $todoIDList = $this->post->todoIDList; - - /* Initialize todos whose need to edited. */ - foreach($allTodos as $todo) - { - if(in_array($todo->id, $todoIDList)) - { - $editedTodos[$todo->id] = $todo; - if($todo->type != 'custom') - { - if(!isset($objectIDList[$todo->type])) $objectIDList[$todo->type] = array(); - $objectIDList[$todo->type][$todo->objectID] = $todo->objectID; - } - } - } - - $bugs = $this->bug->getUserBugPairs($account, true, 0, '', '', isset($objectIDList['bug']) ? $objectIDList['bug'] : ''); - $tasks = $this->task->getUserTaskPairs($account, 'wait,doing', '', isset($objectIDList['task']) ? $objectIDList['task'] : ''); - $storys = $this->loadModel('story')->getUserStoryPairs($account, 10, 'story', '', isset($objectIDList['story']) ? $objectIDList['story'] : ''); - if($this->config->edition != 'open') $this->view->feedbacks = $this->loadModel('feedback')->getUserFeedbackPairs($account, '', isset($objectIDList['feedback']) ? $objectIDList['feedback'] : ''); - if($this->config->edition == 'max') - { - $issues = $this->loadModel('issue')->getUserIssuePairs($account); - $risks = $this->loadmodel('risk')->getUserRiskPairs($account); - $opportunities = $this->loadmodel('opportunity')->getUserOpportunityPairs($account); - } - $testtasks = $this->loadModel('testtask')->getUserTestTaskPairs($account); - - /* Judge whether the edited todos is too large. */ - $countInputVars = count($editedTodos) * $columns; - $showSuhosinInfo = common::judgeSuhosinSetting($countInputVars); - - unset($this->lang->todo->typeList['cycle']); - /* Set Custom*/ - foreach(explode(',', $this->config->todo->list->customBatchEditFields) as $field) $customFields[$field] = $this->lang->todo->$field; - $this->view->customFields = $customFields; - $this->view->showFields = $this->config->todo->custom->batchEditFields; - - /* Assign. */ - $title = $this->lang->todo->common . $this->lang->colon . $this->lang->todo->batchEdit; - $position[] = html::a($this->createLink('my', 'todo'), $this->lang->my->todo); - $position[] = $this->lang->todo->common; - $position[] = $this->lang->todo->batchEdit; - - if($showSuhosinInfo) $this->view->suhosinInfo = extension_loaded('suhosin') ? sprintf($this->lang->suhosinInfo, $countInputVars) : sprintf($this->lang->maxVarsInfo, $countInputVars); - $this->view->bugs = $bugs; - $this->view->tasks = $tasks; - $this->view->storys = $storys; - if($this->config->edition == 'max') - { - $this->view->issues = $issues; - $this->view->risks = $risks; - $this->view->opportunities = $opportunities; - } - $this->view->reviews = $reviews; - $this->view->testtasks = $testtasks; - $this->view->editedTodos = $editedTodos; - $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); - $this->view->time = date::now(); - $this->view->title = $title; - $this->view->position = $position; - $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted|noempty'); - - $this->display(); - } - /* Get form data from todo-batchEdit. */ - elseif($from == 'todoBatchEdit') - { - $allChanges = $this->todo->batchUpdate(); - foreach($allChanges as $todoID => $changes) - { - if(empty($changes)) continue; - - $actionID = $this->loadModel('action')->create('todo', $todoID, 'edited'); - $this->action->logHistory($actionID, $changes); - } - - return print(js::locate($this->session->todoList, 'parent')); + $formData = form::data($this->config->todo->batchEdit->form); + $this->todoZen->batchEditFromTodoBatchEdit($formData); } } /** - * 开启待办事项 + * 开启待办事项。 * Start a todo. * * @param string $todoID * @access public - * @return void + * @return int */ - public function start(string $todoID) + public function start(string $todoID): int { $todoID = (int)$todoID; $todo = $this->todo->getByID($todoID); @@ -303,79 +204,86 @@ class todo extends control if(in_array($todo->type, array('bug', 'task', 'story'))) return $this->todoZen->printConfirm($todo); if(isonlybody()) return print(js::reload('parent.parent')); - echo js::reload('parent'); + return print(js::reload('parent')); } /** - * 激活待办事项 + * 激活待办事项。 * Activated a todo. * * @param string $todoID * @access public - * @return void + * @return int */ - public function activate(string $todoID) + public function activate(string $todoID): int { $todoID = (int)$todoID; $todo = $this->todo->getByID($todoID); - if($todo->status == 'done' or $todo->status == 'closed') $this->todo->activate($todoID); + if($todo->status == 'done' || $todo->status == 'closed') + { + $isActivate = $this->todo->activate($todoID); + if($isActivate === false) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + } if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success')); if(isonlybody()) return print(js::reload('parent.parent')); - echo js::reload('parent'); + return print(js::reload('parent')); } /** + * 关闭待办。 * Closed todo. * - * @param $todoID - * + * @param string $todoID * @access public - * @return void + * @return int */ - public function close($todoID) + public function close(string $todoID): int { - $todo = $this->todo->getById($todoID); + $todoID = (int)$todoID; + $todo = $this->todo->getByID($todoID); if($todo->status == 'done') $this->todo->close($todoID); if(isonlybody()) return print(js::reload('parent.parent')); - echo js::reload('parent'); + + return print(js::reload('parent')); } /** - * 指派待办. + * 指派待办。 * Assign todo. * * @param string $todoID * @access public - * @return void + * @return int */ - public function assignTo(string $todoID) + public function assignTo(string $todoID): int { + $todoID = (int)$todoID; if(!empty($_POST)) { $formData = form::data($this->config->todo->assignTo->form); $todo = $this->todoZen->beforeAssignTo($formData); - $todo->id = (int)$todoID; - $res = $this->todoZen->doAssignTo($todo); - if(!$res) return print(js::error(dao::getError())); + $todo->id = $todoID; + $isAssigned = $this->todoZen->doAssignTo($todo); + if(!$isAssigned) return print(js::error(dao::getError())); return print(js::reload('parent.parent')); } - $this->view->todo = $this->todo->getById((int)$todoID); + $this->view->todo = $this->todo->getByID($todoID); $this->view->members = $this->loadModel('user')->getPairs('noclosed|noempty|nodeleted'); $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); - $this->view->actions = $this->loadModel('action')->getList('todo', (int)$todoID); + $this->view->actions = $this->loadModel('action')->getList('todo', $todoID); $this->view->users = $this->user->getPairs('noletter'); $this->view->time = date::now(); $this->display(); } /** - * 获取待办的信息. - * Get info of todo . + * 获取待办的信息。 + * Get info of todo. * * @param string $todoID * @param string $from my|company @@ -383,9 +291,9 @@ class todo extends control * @access public * @return void */ - public function view(string $todoID,string $from = 'company') + public function view(string $todoID, string $from = 'company') { - $todo = $this->todo->getById((int)$todoID, true); + $todo = $this->todo->getByID((int)$todoID, true); if(!$todo) { @@ -416,7 +324,6 @@ class todo extends control if(!isset($this->session->project)) $this->session->set('project', (int)key($projects)); $this->view->title = $account == $todo->account ? "{$this->lang->todo->common} #$todo->id $todo->name" : $this->lang->todo->common; - $this->view->position[] = $this->lang->todo->view; $this->view->todo = $todo; $this->view->times = date::buildTimeList((int)$this->config->todo->times->begin, (int)$this->config->todo->times->end, 5); $this->view->from = $from; @@ -427,7 +334,7 @@ class todo extends control } /** - * 删除待办. + * 删除待办。 * Delete a todo. * * @param string $todoID @@ -437,28 +344,23 @@ class todo extends control */ public function delete(string $todoID, string $confirm = 'no') { + $todoID = (int)$todoID; if($confirm == 'no') { - return print(js::confirm($this->lang->todo->confirmDelete, $this->createLink('todo', 'delete', "todoID=(int)$todoID&confirm=yes"))); + return print(js::confirm($this->lang->todo->confirmDelete, $this->createLink('todo', 'delete', "todoID={$todoID}&confirm=yes"))); } else { - $this->todo->delete(TABLE_TODO, (int)$todoID); + $this->todo->delete(TABLE_TODO, $todoID); - /* if ajax request, send result. */ - if($this->server->ajax) + if(helper::isAjaxRequest()) { - $response = array(); + $response = array('result' => 'success', 'message' => ''); if(dao::isError()) { $response['result'] = 'fail'; $response['message'] = dao::getError(); } - else - { - $response['result'] = 'success'; - $response['message'] = ''; - } return $this->send($response); } @@ -480,7 +382,7 @@ class todo extends control */ public function finish(string $todoID) { - $todo = $this->todo->getById((int)$todoID); + $todo = $this->todo->getByID((int)$todoID); if($todo->status != 'done' && $todo->status != 'closed') $this->todo->finish((int)$todoID); if(in_array($todo->type, array('bug', 'task', 'story'))) @@ -488,15 +390,20 @@ class todo extends control $confirmNote = 'confirm' . ucfirst($todo->type); $okTarget = isonlybody() ? 'parent' : 'window.parent.$.apps.open'; $confirmURL = $this->createLink($todo->type, 'view', "id=$todo->objectID"); + if($todo->type == 'bug') $app = 'qa'; if($todo->type == 'task') $app = 'execution'; if($todo->type == 'story') $app = 'product'; - $cancelURL = $this->server->HTTP_REFERER; + $cancelURL = $this->server->http_referer; if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success', 'message' => sprintf($this->lang->todo->$confirmNote, $todo->objectID), 'locate' => $confirmURL)); return print(strpos($cancelURL, 'calendar') ? json_encode(array(sprintf($this->lang->todo->$confirmNote, $todo->objectID), $confirmURL)) : js::confirm(sprintf($this->lang->todo->$confirmNote, $todo->objectID), $confirmURL, $cancelURL, $okTarget, 'parent', $app)); } - if(defined('RUN_MODE') && RUN_MODE == 'api') return $this->send(array('status' => 'success')); + if(defined('RUN_MODE') && RUN_MODE == 'api') + { + $this->send(array('status' => 'success')); + return; + } if(isonlybody()) return print(js::reload('parent.parent')); echo js::reload('parent'); } @@ -518,8 +425,8 @@ class todo extends control if($todo->status == 'done' || $todo->status == 'closed') unset($todoList[$todoID]); } - $res = $this->todo->batchFinish((array)array_keys($todoList)); - if(!$res) return false; + $isBatchFinished = $this->todo->batchFinish(array_keys($todoList)); + if(!$isBatchFinished) return false; return print(js::reload('parent')); } @@ -529,27 +436,27 @@ class todo extends control * Batch close todos. The status of todo which need to close should be done. * * @access public - * @return void + * @return int */ - public function batchClose(): void + public function batchClose(): int { $waitIdList = array(); $todoIdlist = form::data($this->config->todo->batchClose->form)->get('todoIDList'); foreach($todoIdlist as $todoID) { $todoID = (int) $todoID; - $todo = $this->todo->getById($todoID); + $todo = $this->todo->getByID($todoID); if($todo->status == 'done') $this->todo->close($todoID); if($todo->status != 'done' and $todo->status != 'closed') $waitIdList[] = $todoID; } if(!empty($waitIdList)) echo js::alert(sprintf($this->lang->todo->unfinishedTodo, implode(',', $waitIdList))); - echo js::reload('parent'); + return print(js::reload('parent')); } /** * 修改选中待办的日期。 - * Import selected todoes to today. + * Import selected todos to today. * * @param string $todoID * @access public @@ -559,10 +466,10 @@ class todo extends control { $todoIDList = $_POST ? $this->post->todoIDList : array($todoID); $date = !empty($_POST['date']) ? $_POST['date'] : date::today(); - if(!$date || !$todoIDList) $this->locate((string)$this->session->todoList); + if(!$date || !$todoIDList) return $this->locate((string)$this->session->todoList); $this->todo->editDate((array)$todoIDList, (string)$date); - $this->locate((string)$this->session->todoList); + return this->locate((string)$this->session->todoList); } /** @@ -577,7 +484,7 @@ class todo extends control { if($_POST) { - $user = $this->loadModel('user')->getById($userID, 'id'); + $user = $this->loadModel('user')->getByID($userID, 'id'); $account = $user->account; $todoLang = $this->lang->todo; diff --git a/module/todo/model.php b/module/todo/model.php index bc493f7b95..eb136fe9a6 100755 --- a/module/todo/model.php +++ b/module/todo/model.php @@ -2,7 +2,7 @@ declare(strict_types=1); /** - * The model file of example module of ZenTaoPMS. + * The model file of todo module of ZenTaoPMS. * * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net) * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html) @@ -128,7 +128,7 @@ class todoModel extends model } /** - * 更新待办数据 + * 更新待办数据。 * update a todo. * * @param int $todoID @@ -138,7 +138,7 @@ class todoModel extends model */ public function update(int $todoID, object $todo): array|false { - $oldTodo = $this->dao->findById($todoID)->from(TABLE_TODO)->fetch(); + $oldTodo = $this->dao->findByID($todoID)->from(TABLE_TODO)->fetch(); if(!$this->todoTao->updateRow($todoID, $todo)) return false; @@ -271,8 +271,8 @@ class todoModel extends model { foreach($todoIDList as $todoID) { - $res = $this->dealFinishData($todoID); - if(!$res) return $res; + $finishResult = $this->dealFinishData($todoID); + if(!$finishResult) return $finishResult; } return true; } @@ -288,20 +288,20 @@ class todoModel extends model */ public function getByID(int $todoID, $setImgSize = false): object|false { - $todo = $this->dao->findById($todoID)->from(TABLE_TODO)->fetch(); + $todo = $this->dao->findByID($todoID)->from(TABLE_TODO)->fetch(); if(!$todo) return false; $todo = $this->loadModel('file')->replaceImgURL((object)$todo, 'desc'); if($setImgSize) $todo->desc = $this->file->setImgSize($todo->desc); - if($todo->type == 'story') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_STORY)->fetch('title'); - if($todo->type == 'task') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_TASK)->fetch('name'); - if($todo->type == 'bug') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_BUG)->fetch('title'); - if($todo->type == 'issue' and $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_ISSUE)->fetch('title'); - if($todo->type == 'risk' and $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_RISK)->fetch('name'); - if($todo->type == 'opportunity' and $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_OPPORTUNITY)->fetch('name'); - if($todo->type == 'review' and $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_REVIEW)->fetch('title'); - if($todo->type == 'testtask') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_TESTTASK)->fetch('name'); - if($todo->type == 'feedback') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_FEEDBACK)->fetch('title'); + if($todo->type == 'story') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_STORY)->fetch('title'); + if($todo->type == 'task') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_TASK)->fetch('name'); + if($todo->type == 'bug') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_BUG)->fetch('title'); + if($todo->type == 'issue' and $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_ISSUE)->fetch('title'); + if($todo->type == 'risk' and $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_RISK)->fetch('name'); + if($todo->type == 'opportunity' and $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_OPPORTUNITY)->fetch('name'); + if($todo->type == 'review' and $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_REVIEW)->fetch('title'); + if($todo->type == 'testtask') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_TESTTASK)->fetch('name'); + if($todo->type == 'feedback') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_FEEDBACK)->fetch('title'); $todo->date = str_replace('-', '', $todo->date); return $todo; @@ -412,15 +412,15 @@ class todoModel extends model while($todo = $stmt->fetch()) { - if($todo->type == 'story') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_STORY)->fetch('title'); - if($todo->type == 'task') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_TASK)->fetch('name'); - if($todo->type == 'bug') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_BUG)->fetch('title'); - if($todo->type == 'testtask') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_TESTTASK)->fetch('name'); - if($todo->type == 'issue' && $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_ISSUE)->fetch('title'); - if($todo->type == 'risk' && $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_RISK)->fetch('name'); - if($todo->type == 'opportunity' && $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_OPPORTUNITY)->fetch('name'); - if($todo->type == 'review' && $this->config->edition == 'max') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_REVIEW)->fetch('title'); - if($todo->type == 'feedback' and $this->config->edition != 'open') $todo->name = $this->dao->findById($todo->objectID)->from(TABLE_FEEDBACK)->fetch('title'); + if($todo->type == 'story') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_STORY)->fetch('title'); + if($todo->type == 'task') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_TASK)->fetch('name'); + if($todo->type == 'bug') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_BUG)->fetch('title'); + if($todo->type == 'testtask') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_TESTTASK)->fetch('name'); + if($todo->type == 'issue' && $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_ISSUE)->fetch('title'); + if($todo->type == 'risk' && $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_RISK)->fetch('name'); + if($todo->type == 'opportunity' && $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_OPPORTUNITY)->fetch('name'); + if($todo->type == 'review' && $this->config->edition == 'max') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_REVIEW)->fetch('title'); + if($todo->type == 'feedback' and $this->config->edition != 'open') $todo->name = $this->dao->findByID($todo->objectID)->from(TABLE_FEEDBACK)->fetch('title'); $todo->begin = date::formatTime($todo->begin); $todo->end = date::formatTime($todo->end); @@ -556,18 +556,16 @@ class todoModel extends model { $isClosed = $this->todoTao->closeTodo($todoID); - if($isClosed) - { - $this->loadModel('action')->create('todo', $todoID, 'closed', '', 'closed'); + if(!$isClosed) return false; - if($this->config->edition == 'biz' || $this->config->edition == 'max') - { - $feedbackID = $this->dao->select('objectID')->from(TABLE_TODO)->where('id')->eq($todoID)->andWhere('type')->eq('feedback')->fetch('objectID'); - if($feedbackID) $this->loadModel('feedback')->updateStatus('todo', $feedbackID, 'closed'); - } - return true; + $this->loadModel('action')->create('todo', $todoID, 'closed', '', 'closed'); + + if($this->config->edition == 'biz' || $this->config->edition == 'max') + { + $feedbackID = $this->dao->select('objectID')->from(TABLE_TODO)->where('id')->eq($todoID)->andWhere('type')->eq('feedback')->fetch('objectID'); + if($feedbackID) $this->loadModel('feedback')->updateStatus('todo', $feedbackID, 'closed'); } - return false; + return true; } /** @@ -656,25 +654,24 @@ class todoModel extends model $todo->finishedBy = $this->app->user->account; $this->todoTao->updateRow($todoID, $todo); - if(!dao::isError()) - { - $this->loadModel('action')->create('todo', $todoID, 'finished', '', 'done'); + if(dao::isError()) return false; - if(($this->config->edition == 'biz' || $this->config->edition == 'max')) - { - $todo = $this->todoTao->fetch($todoID); - $feedbackID = $todo->idvalue ?? '' ; - if($feedbackID) $this->loadModel('feedback')->updateStatus('todo', $feedbackID, 'done'); - } - return true; + $this->loadModel('action')->create('todo', $todoID, 'finished', '', 'done'); + + if(($this->config->edition == 'biz' || $this->config->edition == 'max')) + { + $todo = $this->todoTao->fetch($todoID); + $feedbackID = $todo->idvalue ?? '' ; + if($feedbackID) $this->loadModel('feedback')->updateStatus('todo', $feedbackID, 'done'); } - return false; + return true; } - /** 修改待办事项的时间。 + /** + * 修改待办事项的时间。 * Edit the date of todo. * - * @param array $idList + * @param array $todoIDList * @param string $date * @access public * @return int diff --git a/module/todo/tao.php b/module/todo/tao.php index a6d5091f6b..3a4c3f043b 100644 --- a/module/todo/tao.php +++ b/module/todo/tao.php @@ -75,11 +75,10 @@ class todoTao extends todoModel ->where('id')->eq($todoID) ->exec(); return !dao::isError(); - } - /* - * 处理要创建的todo的数据 + /** + * 处理要创建的todo的数据。 * Process the data for the todo to be created. * * @param object $todoData @@ -118,13 +117,13 @@ class todoTao extends todoModel } if(empty($todoData->cycle)) unset($todoData->config); - $todoData = $this->loadModel('file')->processImgURL($todoData, $this->config->todo->editor->create['id'], $this->post->uid); - return $todoData; + return $this->loadModel('file')->processImgURL($todoData, $this->config->todo->editor->create['id'], $this->post->uid); } /** - * 获取周期待办列表 - * Get cycle list. + * 获取周期待办列表。 + * Get cycle list. + * * @param array $todoList * @param string $orderBy * @access protected @@ -132,18 +131,18 @@ class todoTao extends todoModel */ protected function getCycleList(array $todoList, string $orderBy = 'date_asc'): array { - return $this->dao->select('*') - ->from(TABLE_TODO)->where('type')->eq('cycle') + return $this->dao->select('*')->from(TABLE_TODO) + ->where('type')->eq('cycle') ->andWhere('deleted')->eq('0') ->andWhere('objectID')->in(array_keys($todoList)) ->orderBy($orderBy) ->fetchAll('objectID'); } - /** * 通过待办构建周期待办数据 * Build cycle todo. + * * @param object $todo * @access protected * @return stdclass @@ -168,9 +167,9 @@ class todoTao extends todoModel } /** - * 通过周期待办,获取要生成待办的日期 - * + * 通过周期待办,获取要生成待办的日期。 * Gets the date by the cycle todo. + * * @param object $todo * @param object|string $lastCycle * @param string $today @@ -207,8 +206,7 @@ class todoTao extends todoModel } /** - * 通过周期待办,获取要生成每日待办的日期 - * + * 通过周期待办,获取要生成每日待办的日期。 * Gets the daily todo date by the cycle todo. * * @param object $todo @@ -305,6 +303,7 @@ class todoTao extends todoModel return false; } $todoData->config['beforeDays'] = (int)$todoData->config['beforeDays']; + $todoData->config = json_encode($todoData->config); $todoData->type = 'cycle'; @@ -317,11 +316,11 @@ class todoTao extends todoModel * * @param array $idList * @param string $date - * @return int + * @return bool */ - protected function updateDate(array $todoIdList, string $date): int + protected function updateDate(array $todoIdList, string $date): bool { $this->dao->update(TABLE_TODO)->set('date')->eq($date)->where('id')->in($todoIdList)->exec(); - return dao::isError() ? 0 : 1; + return !dao::isError(); } } diff --git a/module/todo/test/model/close.php b/module/todo/test/model/close.php index b583b0e319..42890cbbcd 100755 --- a/module/todo/test/model/close.php +++ b/module/todo/test/model/close.php @@ -3,7 +3,6 @@ declare(strict_types=1); include dirname(__FILE__, 5) . "/test/lib/init.php"; -include dirname(__FILE__, 2) . '/todo.class.php'; su('admin'); /** diff --git a/module/todo/zen.php b/module/todo/zen.php index ffd72aab30..a238e91a41 100755 --- a/module/todo/zen.php +++ b/module/todo/zen.php @@ -3,11 +3,39 @@ declare(strict_types=1); class todoZen extends todo { + /** + * 生成创建待办视图数据。 + * Build create form data. + * + * @param string $date + * @access protected + * @return void + */ + protected function buildCreateForm(string $date): void + { + $this->view->title = $this->lang->todo->common . $this->lang->colon . $this->lang->todo->create; + $this->view->date = date('Y-m-d', strtotime($date)); + $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); + $this->view->time = date::now(); + $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted|noempty'); + $this->display(); + } + + protected function renderEditData(int $todoID) + { + $todo->date = date("Y-m-d", strtotime($todo->date)); + $this->view->title = $this->lang->todo->common . $this->lang->colon . $this->lang->todo->edit; + $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); + $this->view->todo = $todo; + $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted|noempty'); + + $this->display(); + } + /** * 处理请求数据 * Processing request data. * - * @process protected * @param object $formData * @access protected * @return object @@ -36,12 +64,13 @@ class todoZen extends todo ->stripTags($this->config->todo->editor->create['id'], $this->config->allowedTags) ->remove(implode(',', $this->config->todo->moduleList) . ',uid') ->get(); + return $data; } /** - * Create a todo after data processing - * 创建完成待办后数据处理 + * 创建完成待办后数据处理。 + * Create a todo after data processing. * * @param object $todo * @access protected @@ -65,7 +94,7 @@ class todoZen extends todo } /** - * 处理编辑待办的请求数据 + * 处理编辑待办的请求数据。 * Processing edit request data. * * @param int $todoID @@ -75,7 +104,7 @@ class todoZen extends todo */ protected function beforeEdit(int $todoID, object $formData): object|false { - $oldTodo = $this->dao->findById($todoID)->from(TABLE_TODO)->fetch(); + $oldTodo = $this->dao->findByID($todoID)->from(TABLE_TODO)->fetch(); $objectID = 0; $rowData = $formData->rawdata; @@ -96,7 +125,7 @@ class todoZen extends todo ->remove(implode(',', $this->config->todo->moduleList) . ',uid') ->get(); - $todo = (object) array_merge((array) $rowData, (array) $todo); + $todo = (object)array_merge((array)$rowData, (array)$todo); if(in_array($todo->type, $this->config->todo->moduleList)) { @@ -114,9 +143,7 @@ class todoZen extends todo if(!empty($oldTodo->cycle)) $this->handleCycleConfig($todo); - $todo = $this->loadModel('file')->processImgURL($todo, $this->config->todo->editor->edit['id'], $rowData->uid); - - return $todo; + return $this->loadModel('file')->processImgURL($todo, $this->config->todo->editor->edit['id'], $rowData->uid); } /** @@ -135,15 +162,109 @@ class todoZen extends todo $this->action->logHistory($actionID, $changes); } + protected function batchEditFromMyTodo($type, $userID, $status) + { + /* Initialize vars. */ + $editedTodos = array(); + $todoIDList = array(); + $reviews = array(); + $columns = 7; + + if($userID == '') $userID = $this->app->user->id; + $user = $this->loadModel('user')->getById($userID, 'id'); + $account = $user->account; + + if($this->config->edition == 'max') $reviews = $this->loadModel('review')->getUserReviewPairs($account); + $allTodos = $this->todo->getList($type, $account, $status); + if($this->post->todoIDList) $todoIDList = $this->post->todoIDList; + + /* Initialize todos whose need to edited. */ + foreach($allTodos as $todo) + { + if(in_array($todo->id, $todoIDList)) + { + $editedTodos[$todo->id] = $todo; + if($todo->type != 'custom') + { + if(!isset($objectIDList[$todo->type])) $objectIDList[$todo->type] = array(); + $objectIDList[$todo->type][$todo->objectID] = $todo->objectID; + } + } + } + + $bugs = $this->bug->getUserBugPairs($account, true, 0, '', '', isset($objectIDList['bug']) ? $objectIDList['bug'] : ''); + $tasks = $this->task->getUserTaskPairs($account, 'wait,doing', '', isset($objectIDList['task']) ? $objectIDList['task'] : ''); + $storys = $this->loadModel('story')->getUserStoryPairs($account, 10, 'story', '', isset($objectIDList['story']) ? $objectIDList['story'] : ''); + if($this->config->edition != 'open') $this->view->feedbacks = $this->loadModel('feedback')->getUserFeedbackPairs($account, '', isset($objectIDList['feedback']) ? $objectIDList['feedback'] : ''); + if($this->config->edition == 'max') + { + $issues = $this->loadModel('issue')->getUserIssuePairs($account); + $risks = $this->loadmodel('risk')->getUserRiskPairs($account); + $opportunities = $this->loadmodel('opportunity')->getUserOpportunityPairs($account); + } + $testtasks = $this->loadModel('testtask')->getUserTestTaskPairs($account); + + /* Judge whether the edited todos is too large. */ + $countInputVars = count($editedTodos) * $columns; + $showSuhosinInfo = common::judgeSuhosinSetting($countInputVars); + + unset($this->lang->todo->typeList['cycle']); + /* Set Custom*/ + foreach(explode(',', $this->config->todo->list->customBatchEditFields) as $field) $customFields[$field] = $this->lang->todo->$field; + $this->view->customFields = $customFields; + $this->view->showFields = $this->config->todo->custom->batchEditFields; + + /* Assign. */ + $title = $this->lang->todo->common . $this->lang->colon . $this->lang->todo->batchEdit; + $position[] = html::a($this->createLink('my', 'todo'), $this->lang->my->todo); + $position[] = $this->lang->todo->common; + $position[] = $this->lang->todo->batchEdit; + + if($showSuhosinInfo) $this->view->suhosinInfo = extension_loaded('suhosin') ? sprintf($this->lang->suhosinInfo, $countInputVars) : sprintf($this->lang->maxVarsInfo, $countInputVars); + $this->view->bugs = $bugs; + $this->view->tasks = $tasks; + $this->view->storys = $storys; + if($this->config->edition == 'max') + { + $this->view->issues = $issues; + $this->view->risks = $risks; + $this->view->opportunities = $opportunities; + } + $this->view->reviews = $reviews; + $this->view->testtasks = $testtasks; + $this->view->editedTodos = $editedTodos; + $this->view->times = date::buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); + $this->view->time = date::now(); + $this->view->title = $title; + $this->view->position = $position; + $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted|noempty'); + + $this->display(); + } + + protected function batchEditFromTodoBatchEdit($formData) + { + $allChanges = $this->todo->batchUpdate(); + foreach($allChanges as $todoID => $changes) + { + if(empty($changes)) continue; + + $actionID = $this->loadModel('action')->create('todo', $todoID, 'edited'); + $this->action->logHistory($actionID, $changes); + } + + return print(js::locate($this->session->todoList, 'parent')); + } + /** - * 处理循环待办的配置文件 + * 处理周期待办的配置值。 * Handle cycle config. * * @param object $todo * @access private * @return void */ - private function handleCycleConfig(object &$todo): void + private function handleCycleConfig(object $todo): void { $todo->date = date('Y-m-d'); $todo->config['begin'] = $todo->date; @@ -215,7 +336,7 @@ class todoZen extends todo } /** - * 输出确认弹框 + * 输出确认弹框。 * Output confirm alert. * * @param object $todo @@ -230,7 +351,8 @@ class todoZen extends todo if($todo->type == 'bug') $app = 'qa'; if($todo->type == 'task') $app = 'execution'; if($todo->type == 'story') $app = 'product'; - $cancelURL = $this->server->HTTP_REFERER; + $cancelURL = $this->server->http_referer; + return print(js::confirm(sprintf($this->lang->todo->$confirmNote, $todo->objectID), $confirmURL, $cancelURL, $okTarget, 'parent', $app)); } @@ -244,7 +366,7 @@ class todoZen extends todo protected function getProjectPairsByModel(string $model): array { $model = $model == 'opportunity' ? 'waterfall' : 'all'; - return $this->loadModel('project')->getPairsByModel((string)$model); + return $this->loadModel('project')->getPairsByModel($model); } /**