From fc036c5d99b3bb6c61928db4f3926b11afc55dda Mon Sep 17 00:00:00 2001 From: Yagami <976204163@qq.com> Date: Thu, 17 Sep 2020 16:37:18 +0800 Subject: [PATCH] * Finish task #7850,#7854. --- module/common/lang/zh-cn.php | 2 +- module/program/config.php | 22 +- module/program/control.php | 126 ++++---- module/program/css/pgmbrowse.css | 1 + .../program/css/{create.css => pgmcreate.css} | 0 module/program/lang/zh-cn.php | 20 +- module/program/model.php | 270 +++++++++++++++--- module/program/view/browsebylist.html.php | 8 +- module/program/view/edit.html.php | 43 +-- module/program/view/pgmbrowse.html.php | 17 +- module/program/view/pgmbrowsebygrid.html.php | 163 +++++++++++ module/program/view/pgmbrowsebylist.html.php | 124 ++++++++ module/program/view/pgmcreate.html.php | 162 +++++++++++ module/program/view/pgmedit.html.php | 93 ++++++ 14 files changed, 892 insertions(+), 159 deletions(-) create mode 100644 module/program/css/pgmbrowse.css rename module/program/css/{create.css => pgmcreate.css} (100%) create mode 100644 module/program/view/pgmbrowsebygrid.html.php create mode 100644 module/program/view/pgmbrowsebylist.html.php create mode 100644 module/program/view/pgmcreate.html.php create mode 100644 module/program/view/pgmedit.html.php diff --git a/module/common/lang/zh-cn.php b/module/common/lang/zh-cn.php index 3ea287aaf4..aeddd1dcc5 100755 --- a/module/common/lang/zh-cn.php +++ b/module/common/lang/zh-cn.php @@ -135,7 +135,7 @@ $lang->dividerMenu = ',admin,'; $lang->program = new stdclass(); $lang->program->menu = new stdclass(); $lang->program->menu->index = '主页|program|pgmindex|'; -$lang->program->menu->browse = '项目集|program|pgmbrowse|'; +$lang->program->menu->browse = array('link' => '项目集|program|pgmbrowse|', 'alias' => 'pgmcreate,pgmedit'); /* Product menu. */ $lang->productlist = new stdclass(); diff --git a/module/program/config.php b/module/program/config.php index 296bc728b4..a4d539cf2e 100644 --- a/module/program/config.php +++ b/module/program/config.php @@ -1,18 +1,18 @@ program = new stdclass(); $config->program->editor = new stdclass(); -$config->program->editor->create = array('id' => 'desc', 'tools' => 'simpleTools'); -$config->program->editor->edit = array('id' => 'desc', 'tools' => 'simpleTools'); -$config->program->editor->close = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->program->editor->start = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->program->editor->activate = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->program->editor->finish = array('id' => 'comment', 'tools' => 'simpleTools'); -$config->program->editor->suspend = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->pgmcreate = array('id' => 'desc', 'tools' => 'simpleTools'); +$config->program->editor->pgmedit = array('id' => 'desc', 'tools' => 'simpleTools'); +$config->program->editor->pgmclose = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->pgmstart = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->pgmactivate = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->pgmfinish = array('id' => 'comment', 'tools' => 'simpleTools'); +$config->program->editor->pgmsuspend = array('id' => 'comment', 'tools' => 'simpleTools'); $config->program->list = new stdclass(); $config->program->list->exportFields = 'id,name,code,template,category,status,begin,end,budget,PM,end,desc'; -$config->program->create = new stdclass(); -$config->program->edit = new stdclass(); -$config->program->create->requiredFields = 'name,code,begin,end'; -$config->program->edit->requiredFields = 'name,code,begin,end'; +$config->program->PGMCreate = new stdclass(); +$config->program->PGMEdit = new stdclass(); +$config->program->PGMCreate->requiredFields = 'name,code,begin,end'; +$config->program->PGMEdit->requiredFields = 'name,code,begin,end'; diff --git a/module/program/control.php b/module/program/control.php index a9478d5964..18b949aa3b 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -52,10 +52,10 @@ class program extends control * @access public * @return void */ - public function PGMBrowse($status = 'doing', $orderBy = 'order_desc', $recTotal = 0, $recPerPage = 50, $pageID = 1) + public function PGMBrowse($status = 'all', $orderBy = 'order_desc', $recTotal = 0, $recPerPage = 50, $pageID = 1) { $this->lang->navGroup->program = 'program'; - if(common::hasPriv('program', 'createGuide')) $this->lang->pageActions = html::a($this->createLink('program', 'createGuide'), " " . $this->lang->program->create, '', "class='btn btn-primary' data-toggle=modal"); + if(common::hasPriv('program', 'pgmcreate')) $this->lang->pageActions = html::a($this->createLink('program', 'pgmcreate'), " " . $this->lang->program->PGMCreate, '', "class='btn btn-primary'"); $this->app->session->set('programList', $this->app->getURI(true)); @@ -104,62 +104,66 @@ class program extends control * @access public * @return void */ - public function create($template = 'waterfall', $parentProgramID = 0, $copyProgramID = '') + public function PGMCreate($parentProgramID = 0) { + $this->lang->navGroup->program = 'program'; + if($_POST) { - $projectID = $this->program->create(); + $projectID = $this->program->PGMCreate(); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => $this->processErrors(dao::getError()))); $this->loadModel('action')->create('program', $projectID, 'opened'); - $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse', array('status' => 'wait', 'orderBy' => 'order_desc')))); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('pgmbrowse', array('status' => 'wait', 'orderBy' => 'order_desc')))); } - $name = ''; - $code = ''; - $team = ''; - $whitelist = ''; - $acl = 'open'; - $privway = 'extend'; + $this->view->title = $this->lang->program->PGMCreate; + $this->view->position[] = $this->lang->program->PGMCreate; - if($parentProgramID) - { - $parentProgram = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($parentProgramID)->fetch(); - if($this->program->checkHasContent($parentProgramID)) - { - echo js::alert($this->lang->program->cannotCreateChild); - die(js::locate('back')); - } - - if(empty($template)) $template = $parentProgram->template; - } - - if($copyProgramID) - { - $copyProgram = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($copyProgramID)->fetch(); - $name = $copyProgram->name; - $code = $copyProgram->code; - $team = $copyProgram->team; - $acl = $copyProgram->acl; - $privway = $copyProgram->privway; - $whitelist = $copyProgram->whitelist; - if(empty($template)) $template = $copyProgram->template; - } - - $this->view->title = $this->lang->program->create; - $this->view->position[] = $this->lang->program->create; $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->pmUsers = $this->loadModel('user')->getPairs('noclosed|nodeleted|pmfirst'); - $this->view->programs = array('' => '') + $this->program->getPairsByTemplate($template); - $this->view->template = $template; - $this->view->name = $name; - $this->view->code = $code; - $this->view->team = $team; - $this->view->acl = $acl; - $this->view->privway = $privway; - $this->view->whitelist = $whitelist; - $this->view->parentProgram = $parentProgramID ? $parentProgram : ''; - $this->view->copyProgramID = $copyProgramID; + $this->view->parentProgram = $parentProgramID ? $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($parentProgramID)->fetch() : ''; + $this->view->parents = $this->program->getParentPairs(); + $this->display(); + } + + /** + * Edit a program. + * + * @param int $programID + * @access public + * @return void + */ + public function PGMEdit($programID = 0) + { + $this->lang->navGroup->program = 'program'; + + $program = $this->project->getByID($programID); + + if($_POST) + { + $changes = $this->program->PGMUpdate($programID); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => $this->processErrors(dao::getError()))); + if($changes) + { + $actionID = $this->loadModel('action')->create('program', $programID, 'edited'); + $this->action->logHistory($actionID, $changes); + } + + $url = $this->session->PRJList ? $this->session->PRJList : inlink('pgmbrowse'); + $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $url)); + } + + $parents = $this->program->getParentPairs(); + unset($parents[$programID]); + + $this->view->title = $this->lang->program->PGMEdit; + $this->view->position[] = $this->lang->program->PGMEdit; + + $this->view->pmUsers = $this->loadModel('user')->getPairs('noclosed|nodeleted|pmfirst', $program->PM); + $this->view->program = $program; + $this->view->parents = $parents; + $this->view->groups = $this->loadModel('group')->getPairs(); $this->display(); } @@ -188,18 +192,40 @@ class program extends control $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $url)); } - $parents = $this->program->getParentPairs($program->template); + $parents = $this->program->getParentPairs(); unset($parents[$programID]); $this->view->pmUsers = $this->loadModel('user')->getPairs('noclosed|nodeleted|pmfirst', $program->PM); - $this->view->title = $this->lang->program->edit; - $this->view->position[] = $this->lang->program->edit; + $this->view->title = $this->lang->program->PGMEdit; + $this->view->position[] = $this->lang->program->PGMEdit; $this->view->program = $program; $this->view->parents = $parents; $this->view->groups = $this->loadModel('group')->getPairs(); $this->display(); } + /** + * Delete a program. + * + * @param int $projectID + * @param varchar $confirm + * @access public + * @return void + */ + public function PGMDelete($programID, $confirm = 'no') + { + $childrenCount = $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->andWhere('deleted')->eq(0)->fetch('count'); + if($childrenCount) die(js::alert($this->lang->program->hasChildren)); + + $program = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($programID)->fetch(); + if($confirm == 'no') die(js::confirm(sprintf($this->lang->program->confirmDelete, $program->name), $this->createLink('program', 'delete', "programID=$programID&confirm=yes"))); + + $this->dao->update(TABLE_PROGRAM)->set('deleted')->eq(1)->where('id')->eq($programID)->exec(); + $this->loadModel('action')->create('program', $programID, 'deleted', '', $extra = ACTIONMODEL::CAN_UNDELETED); + + die(js::reload('parent')); + } + /** * Browse groups. * diff --git a/module/program/css/pgmbrowse.css b/module/program/css/pgmbrowse.css new file mode 100644 index 0000000000..d7f6b7a8dd --- /dev/null +++ b/module/program/css/pgmbrowse.css @@ -0,0 +1 @@ +#mainMenu .pull-left .checkbox-primary {display: inline-block; margin-left: 10px;} diff --git a/module/program/css/create.css b/module/program/css/pgmcreate.css similarity index 100% rename from module/program/css/create.css rename to module/program/css/pgmcreate.css diff --git a/module/program/lang/zh-cn.php b/module/program/lang/zh-cn.php index 6d55db9abb..3726f3a562 100644 --- a/module/program/lang/zh-cn.php +++ b/module/program/lang/zh-cn.php @@ -22,7 +22,7 @@ $lang->program->PRJExport = '导出'; $lang->program->PRJManageGroupMember = '维护分组用户'; /* Fields. */ -$lang->program->PRJCommon = '项目'; +$lang->program->common = '项目'; $lang->program->stage = '阶段'; $lang->program->PRJName = '项目名称'; $lang->program->PRJTemplate = '项目模板'; @@ -43,7 +43,7 @@ $lang->program->bygrid = '看板'; $lang->program->bylist = '列表'; $lang->program->mine = '我参与的'; $lang->program->setPlanduration = '设置工期'; -$lang->program->privway = '权限控制'; +$lang->program->auth = '权限控制'; $lang->program->durationEstimation = '工作量估算'; $lang->program->PRJProgress = '项目进度'; $lang->program->teamCount = '投入人数'; @@ -86,8 +86,8 @@ $lang->program->PRJAclList['open'] = "默认设置(有项目视图权限, $lang->program->PRJAclList['private'] = "私有项目(只有项目团队成员才能访问)"; $lang->program->PRJAclList['custom'] = "自定义白名单(团队成员和白名单的成员可以访问)"; -$lang->program->PRJPrivwayList['extend'] = '继承(取项目权限与组织权限的并集)'; -$lang->program->PRJPrivwayList['reset'] = '重新定义(只取项目权限)'; +$lang->program->PRJAuthList['extend'] = '继承(取项目权限与组织权限的并集)'; +$lang->program->PRJAuthList['reset'] = '重新定义(只取项目权限)'; $lang->program->statusList['wait'] = '未开始'; $lang->program->statusList['doing'] = '进行中'; @@ -160,4 +160,14 @@ $lang->program->PGMAllInput = '项目集总投入'; $lang->program->PGMTeamCount = '项目集成员'; $lang->program->PGMLongTime = '长期项目'; -$lang->program->noPGM = '暂时没有项目集'; +$lang->program->noPGM = '暂时没有项目集'; +$lang->program->PGMShowClosed = '显示已关闭'; + +$lang->program->PGMAclList['open'] = "默认设置(有项目视图权限,即可访问)"; +$lang->program->PGMAclList['private'] = "私有项目(只有项目团队成员才能访问)"; +$lang->program->PGMAclList['custom'] = "自定义白名单(团队成员和白名单的成员可以访问)"; + +$lang->program->PGMAuthList['extend'] = '继承(取项目权限与组织权限的并集)'; +$lang->program->PGMAuthList['reset'] = '重新定义(只取项目权限)'; + +$lang->program->PGMFeatureBar['all'] = '所有'; diff --git a/module/program/model.php b/module/program/model.php index 3fb5611d16..8e531f22e6 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -14,7 +14,7 @@ class programModel extends model */ public function getList($status = 'all', $orderBy = 'id_desc', $pager = NULL, $includeCat = false, $mine = false) { - return $this->dao->select('*')->from(TABLE_PROJECT) + return $this->dao->select('*')->from(TABLE_PROGRAM) ->where('type')->eq('program') ->andWhere('deleted')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->programs)->fi() @@ -37,7 +37,7 @@ class programModel extends model */ public function getPairs() { - return $this->dao->select('id, name')->from(TABLE_PROJECT) + return $this->dao->select('id, name')->from(TABLE_PROGRAM) ->where('type')->eq('program') ->andWhere('deleted')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->programs)->fi() @@ -53,7 +53,7 @@ class programModel extends model */ public function getPairsByTemplate($model) { - return $this->dao->select('id, name')->from(TABLE_PROJECT) + return $this->dao->select('id, name')->from(TABLE_PROGRAM) ->where('type')->eq('program') ->andWhere('model')->eq($model) ->andWhere('deleted')->eq(0) @@ -75,7 +75,7 @@ class programModel extends model public function getProgramOverview($queryType = 'byStatus', $param = 'all', $orderBy = 'id_desc', $limit = 15) { $queryType = strtolower($queryType); - $programs = $this->dao->select('*')->from(TABLE_PROJECT) + $programs = $this->dao->select('*')->from(TABLE_PROGRAM) ->where('type')->eq('program') ->andWhere('deleted')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->programs)->fi() @@ -188,7 +188,7 @@ class programModel extends model if(empty($programs)) return array(); $programIdList = array_keys($programs); - $programs = $this->dao->select('*')->from(TABLE_PROJECT) + $programs = $this->dao->select('*')->from(TABLE_PROGRAM) ->where('id')->in($programIdList) ->orderBy($orderBy) ->limit($itemCounts) @@ -218,6 +218,18 @@ class programModel extends model return $programs; } + /** + * Get children by program id. + * + * @param int $programID + * @access private + * @return void + */ + public function getChildren($programID = 0) + { + return $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->fetch('count'); + } + /** * Show accessDenied response. * @@ -236,6 +248,167 @@ class programModel extends model die(js::locate('back')); } + /** + * Create a program. + * + * @access private + * @return void + */ + public function PGMCreate() + { + $program = fixer::input('post') + ->setDefault('status', 'wait') + ->add('type', 'program') + ->setIF($this->post->acl != 'custom', 'whitelist', '') + ->setDefault('openedBy', $this->app->user->account) + ->setDefault('end', '') + ->setDefault('parent', 0) + ->setDefault('openedDate', helper::now()) + ->setDefault('team', substr($this->post->name, 0, 30)) + ->join('whitelist', ',') + ->cleanInt('budget') + ->stripTags($this->config->program->editor->pgmcreate['id'], $this->config->allowedTags) + ->remove('workDays, delta, branch, uid') + ->get(); + + if($program->parent) + { + $parentProgram = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($program->parent)->fetch(); + if($parentProgram) + { + /* Child program begin cannot less than parent. */ + if($program->begin < $parentProgram->begin) dao::$errors['begin'] = sprintf($this->lang->program->beginLetterParent, $parentProgram->begin); + /* When parent set end then child program end cannot greater than parent. */ + if($parentProgram->end != '0000-00-00' and $program->end > $parentProgram->end) dao::$errors['end'] = sprintf($this->lang->program->endGreaterParent, $parentProgram->end); + /* When parent set end then child program cannot set longTime. */ + if(empty($program->end) and $this->post->longTime and $parentProgram->end != '0000-00-00') dao::$errors['end'] = sprintf($this->lang->program->endGreaterParent, $parentProgram->end); + + if(dao::isError()) return false; + } + } + + $program = $this->loadModel('file')->processImgURL($program, $this->config->program->editor->pgmcreate['id'], $this->post->uid); + $this->dao->insert(TABLE_PROGRAM)->data($program) + ->autoCheck() + ->batchcheck($this->config->program->PGMCreate->requiredFields, 'notempty') + ->check('name', 'unique', "deleted='0'") + ->check('code', 'unique', "deleted='0'") + ->exec(); + + /* Add the creater to the team. */ + if(!dao::isError()) + { + $programID = $this->dao->lastInsertId(); + $today = helper::today(); + //if($project->acl != 'open') $this->loadModel('user')->updateUserView($programID, 'program'); + + $this->dao->update(TABLE_PROGRAM)->set('`order`')->eq($programID * 5)->where('id')->eq($programID)->exec(); // Save order. + $this->file->updateObjectID($this->post->uid, $programID, 'project'); + + $this->setTreePath($programID); + + /* Add program admin.*/ + $groupPriv = $this->dao->select('t1.*')->from(TABLE_USERGROUP)->alias('t1') + ->leftJoin(TABLE_GROUP)->alias('t2')->on('t1.group = t2.id') + ->where('t1.account')->eq($this->app->user->account) + ->andWhere('t2.role')->eq('PRJadmin') + ->fetch(); + if(!empty($groupPriv)) + { + $newProgram = $groupPriv->program . ",$programID"; + $this->dao->update(TABLE_USERGROUP)->set('program')->eq($newProgram)->where('account')->eq($groupPriv->account)->andWhere('`group`')->eq($groupPriv->group)->exec(); + } + else + { + $PRJadminID = $this->dao->select('id')->from(TABLE_GROUP)->where('role')->eq('PRJadmin')->fetch('id'); + $groupPriv = new stdclass(); + $groupPriv->account = $this->app->user->account; + $groupPriv->group = $PRJadminID; + $groupPriv->program = $programID; + $this->dao->insert(TABLE_USERGROUP)->data($groupPriv)->exec(); + } + + return $programID; + } + } + + /** + * Update program. + * + * @param int $programID + * @access public + * @return array + */ + public function PGMUpdate($programID) + { + $programID = (int)$programID; + $oldProgram = $this->dao->findById($programID)->from(TABLE_PROGRAM)->fetch(); + + $program = fixer::input('post') + ->setDefault('team', $this->post->name) + ->setDefault('end', '') + ->setIF($this->post->begin == '0000-00-00', 'begin', '') + ->setIF($this->post->end == '0000-00-00', 'end', '') + ->setIF($this->post->acl != 'custom', 'whitelist', '') + ->setIF($this->post->acl == 'custom' and !isset($_POST['whitelist']), 'whitelist', '') + ->join('whitelist', ',') + ->stripTags($this->config->program->editor->pgmedit['id'], $this->config->allowedTags) + ->remove('uid') + ->get(); + + $program = $this->loadModel('file')->processImgURL($program, $this->config->program->editor->pgmedit['id'], $this->post->uid); + $children = $this->getChildren($programID); + + if($children > 0) + { + $minChildBegin = $this->dao->select('min(begin) as minBegin')->from(TABLE_PROGRAM)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->fetch('minBegin'); + $maxChildEnd = $this->dao->select('max(end) as maxEnd')->from(TABLE_PROGRAM)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->andWhere('end')->ne('0000-00-00')->fetch('maxEnd'); + + if($minChildBegin and $program->begin > $minChildBegin) dao::$errors['begin'] = sprintf($this->lang->program->beginGreateChild, $minChildBegin); + if($maxChildEnd and $program->end < $maxChildEnd and !$this->post->longTime) dao::$errors['end'] = sprintf($this->lang->program->endLetterChild, $maxChildEnd); + + $longTimeCount = $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->andWhere('end')->eq('0000-00-00')->fetch('count'); + if(!empty($program->end) and $longTimeCount != 0) dao::$errors['end'] = $this->lang->program->childLongTime; + } + + if($program->parent) + { + $parentProgram = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($program->parent)->fetch(); + if($parentProgram) + { + if($program->begin < $parentProgram->begin) dao::$errors['begin'] = sprintf($this->lang->program->beginLetterParent, $parentProgram->begin); + if($parentProgram->end != '0000-00-00' and $program->end > $parentProgram->end) dao::$errors['end'] = sprintf($this->lang->program->endGreaterParent, $parentProgram->end); + if(empty($program->end) and $this->post->longTime and $parentProgram->end != '0000-00-00') dao::$errors['end'] = sprintf($this->lang->program->endGreaterParent, $parentProgram->end); + } + } + if(dao::isError()) return false; + + $this->dao->update(TABLE_PROGRAM)->data($program) + ->autoCheck($skipFields = 'begin,end') + ->batchcheck($this->config->program->PGMEdit->requiredFields, 'notempty') + ->checkIF($program->begin != '', 'begin', 'date') + ->checkIF($program->end != '', 'end', 'date') + ->checkIF($program->end != '', 'end', 'gt', $program->begin) + ->check('name', 'unique', "id!=$programID and deleted='0'") + ->check('code', 'unique', "id!=$programID and deleted='0'") + ->where('id')->eq($programID) + ->limit(1) + ->exec(); + + if(!dao::isError()) + { + $this->file->updateObjectID($this->post->uid, $programID, 'project'); + if($program->acl != 'open' and ($program->acl != $oldProgram->acl or $program->whitelist != $oldProgram->whitelist)) + { + $this->loadModel('user')->updateUserView($programID, 'program'); + } + + if($oldProgram->parent != $program->parent) $this->processNode($programID, $program->parent, $oldProgram->parent, $oldProgram->path, $oldProgram->grade); + + return common::createChanges($oldProgram, $program); + } + } + /** * Create a program. * @@ -260,7 +433,7 @@ class programModel extends model if($project->parent) { - $parentProgram = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($project->parent)->fetch(); + $parentProgram = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($project->parent)->fetch(); if($parentProgram) { /* Child project begin cannot less than parent. */ @@ -278,7 +451,7 @@ class programModel extends model if($this->post->longTime) $requiredFields = trim(str_replace(',end,', ',', ",{$requiredFields},"), ','); $project = $this->loadModel('file')->processImgURL($project, $this->config->program->editor->create['id'], $this->post->uid); - $this->dao->insert(TABLE_PROJECT)->data($project) + $this->dao->insert(TABLE_PROGRAM)->data($project) ->autoCheck() ->batchcheck($requiredFields, 'notempty') ->check('name', 'unique', "deleted='0'") @@ -293,10 +466,10 @@ class programModel extends model if($project->acl != 'open') $this->loadModel('user')->updateUserView($programID, 'program'); /* Save order. */ - $this->dao->update(TABLE_PROJECT)->set('`order`')->eq($programID * 5)->where('id')->eq($programID)->exec(); + $this->dao->update(TABLE_PROGRAM)->set('`order`')->eq($programID * 5)->where('id')->eq($programID)->exec(); $this->file->updateObjectID($this->post->uid, $programID, 'project'); - if($project->parent > 0) $this->dao->update(TABLE_PROJECT)->set('isCat')->eq(1)->where('id')->eq($project->parent)->exec(); + if($project->parent > 0) $this->dao->update(TABLE_PROGRAM)->set('isCat')->eq(1)->where('id')->eq($project->parent)->exec(); $this->setTreePath($programID); /* Add program admin.*/ @@ -337,7 +510,7 @@ class programModel extends model $data = new stdclass(); $data->project = $programID; $data->product = $productID; - $this->dao->insert(TABLE_PROJECTPRODUCT)->data($data)->exec(); + $this->dao->insert(TABLE_PROGRAMPRODUCT)->data($data)->exec(); } return $programID; @@ -354,7 +527,7 @@ class programModel extends model public function update($programID) { $programID = (int)$programID; - $oldProgram = $this->dao->findById($programID)->from(TABLE_PROJECT)->fetch(); + $oldProgram = $this->dao->findById($programID)->from(TABLE_PROGRAM)->fetch(); $program = fixer::input('post') ->setDefault('team', $this->post->name) @@ -375,19 +548,19 @@ class programModel extends model if(!empty($program->isCat)) { - $minChildBegin = $this->dao->select('min(begin) as minBegin')->from(TABLE_PROJECT)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->fetch('minBegin'); - $maxChildEnd = $this->dao->select('max(end) as maxEnd')->from(TABLE_PROJECT)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->andWhere('end')->ne('0000-00-00')->fetch('maxEnd'); + $minChildBegin = $this->dao->select('min(begin) as minBegin')->from(TABLE_PROGRAM)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->fetch('minBegin'); + $maxChildEnd = $this->dao->select('max(end) as maxEnd')->from(TABLE_PROGRAM)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->andWhere('end')->ne('0000-00-00')->fetch('maxEnd'); if($minChildBegin and $program->begin > $minChildBegin) dao::$errors['begin'] = sprintf($this->lang->program->beginGreateChild, $minChildBegin); if($maxChildEnd and $program->end < $maxChildEnd and !$this->post->longTime) dao::$errors['end'] = sprintf($this->lang->program->endLetterChild, $maxChildEnd); - $longTimeCount = $this->dao->select('count(*) as count')->from(TABLE_PROJECT)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->andWhere('end')->eq('0000-00-00')->fetch('count'); + $longTimeCount = $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('id')->ne($programID)->andWhere('deleted')->eq(0)->andWhere('path')->like("%,{$programID},%")->andWhere('end')->eq('0000-00-00')->fetch('count'); if(!empty($program->end) and $longTimeCount != 0) dao::$errors['end'] = $this->lang->program->childLongTime; } if($program->parent) { - $parentProgram = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($program->parent)->fetch(); + $parentProgram = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($program->parent)->fetch(); if($parentProgram) { if($program->begin < $parentProgram->begin) dao::$errors['begin'] = sprintf($this->lang->program->beginLetterParent, $parentProgram->begin); @@ -400,7 +573,7 @@ class programModel extends model $requiredFields = $this->config->program->edit->requiredFields; if($this->post->longTime) $requiredFields = trim(str_replace(',end,', ',', ",{$requiredFields},"), ','); - $this->dao->update(TABLE_PROJECT)->data($program) + $this->dao->update(TABLE_PROGRAM)->data($program) ->autoCheck($skipFields = 'begin,end') ->batchcheck($requiredFields, 'notempty') ->checkIF($program->begin != '', 'begin', 'date') @@ -420,7 +593,7 @@ class programModel extends model $this->loadModel('user')->updateUserView($programID, 'program'); } - if($oldProgram->parent != $program->parent) $this->moveNode($programID, $program->parent, $oldProgram->path, $oldProgram->grade); + if($oldProgram->parent != $program->parent) $this->processNode($programID, $program->parent, $oldProgram->path, $oldProgram->grade); return common::createChanges($oldProgram, $program); } @@ -472,18 +645,18 @@ class programModel extends model if(empty($program)) return true; - if(!empty($program->isCat) and $action == 'group') return false; - if(!empty($program->isCat) and $action == 'managemembers') return false; - if(!empty($program->isCat) and $action == 'start') return false; - if(!empty($program->isCat) and $action == 'activate') return false; - if(!empty($program->isCat) and $action == 'suspend') return false; - if(!empty($program->isCat) and $action == 'close') return false; + if($program->type == 'program' and $action == 'pgmgroup') return false; + if($program->type == 'program' and $action == 'pgmmanagemembers') return false; + if($program->type == 'program' and $action == 'pgmstart') return false; + if($program->type == 'program' and $action == 'pgmactivate') return false; + if($program->type == 'program' and $action == 'pgmsuspend') return false; + if($program->type == 'program' and $action == 'pgmclose') return false; - if($action == 'start') return $program->status == 'wait' or $program->status == 'suspended'; - if($action == 'finish') return $program->status == 'wait' or $program->status == 'doing'; - if($action == 'close') return $program->status != 'closed'; - if($action == 'suspend') return $program->status == 'wait' or $program->status == 'doing'; - if($action == 'activate') return $program->status == 'done'; + if($action == 'pgmstart') return $program->status == 'wait' or $program->status == 'suspended'; + if($action == 'pgmfinish') return $program->status == 'wait' or $program->status == 'doing'; + if($action == 'pgmclose') return $program->status != 'closed'; + if($action == 'pgmsuspend') return $program->status == 'wait' or $program->status == 'doing'; + if($action == 'pgmactivate') return $program->status == 'done'; return true; } @@ -498,8 +671,8 @@ class programModel extends model public function checkHasContent($programID) { $count = 0; - $count += (int)$this->dao->select('count(*) as count')->from(TABLE_PROJECT)->where('program')->eq($programID)->fetch('count'); - $count += (int)$this->dao->select('count(*) as count')->from(TABLE_TASK)->where('program')->eq($programID)->fetch('count'); + $count += (int)$this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->fetch('count'); + $count += (int)$this->dao->select('count(*) as count')->from(TABLE_TASK)->where('PRJ')->eq($programID)->fetch('count'); return $count > 0; } @@ -513,7 +686,7 @@ class programModel extends model */ public function checkHasChildren($programID) { - $count = $this->dao->select('count(*) as count')->from(TABLE_PROJECT)->where('parent')->eq($programID)->fetch('count'); + $count = $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->fetch('count'); return $count > 0; } @@ -526,35 +699,35 @@ class programModel extends model */ public function setTreePath($programID) { - $program = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($programID)->fetch(); + $program = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($programID)->fetch(); $path['path'] = ",{$program->id},"; $path['grade'] = 1; if($program->parent) { - $parent = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($program->parent)->fetch(); + $parent = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($program->parent)->fetch(); $path['path'] = $parent->path . "{$program->id},"; $path['grade'] = $parent->grade + 1; } - $this->dao->update(TABLE_PROJECT)->set('path')->eq($path['path'])->set('grade')->eq($path['grade'])->where('id')->eq($program->id)->exec(); + $this->dao->update(TABLE_PROGRAM)->set('path')->eq($path['path'])->set('grade')->eq($path['grade'])->where('id')->eq($program->id)->exec(); return !dao::isError(); } /** * Get program parent pairs * + * @param string $model * @access public * @return array */ - public function getParentPairs($template = '') + public function getParentPairs($model = '') { - $modules = $this->dao->select('id,name,parent,path,grade')->from(TABLE_PROJECT) - ->where('isCat')->eq(1) + $modules = $this->dao->select('id,name,parent,path,grade')->from(TABLE_PROGRAM) + ->where('type')->eq('program') ->andWhere('deleted')->eq(0) - ->andWhere('template')->ne('') - ->beginIF($template)->andWhere('template')->eq($template)->fi() + ->beginIF($model)->andWhere('model')->eq($model)->fi() ->orderBy('grade desc, `order`') ->fetchAll('id'); @@ -602,16 +775,25 @@ class programModel extends model * @access public * @return bool */ - public function moveNode($programID, $parentID, $oldPath, $oldGrade) + public function processNode($programID, $parentID, $oldParentID, $oldPath, $oldGrade) { - $parent = $this->dao->select('id,parent,path,grade')->from(TABLE_PROJECT)->where('id')->eq($parentID)->fetch(); + $parent = $this->dao->select('id,parent,path,grade')->from(TABLE_PROGRAM)->where('id')->eq($parentID)->fetch(); - $childNodes = $this->dao->select('id,parent,path,grade')->from(TABLE_PROJECT) + $childNodes = $this->dao->select('id,parent,path,grade')->from(TABLE_PROGRAM) ->where('path')->like("{$oldPath}%") ->andWhere('deleted')->eq(0) - ->andWhere('template')->ne('') ->orderBy('grade') ->fetchAll(); + + /* Process old and new program parent field.*/ + $newChildren = $this->getChildren($parentID); + $oldChildren = $this->getChildren($oldParentID); + $newParent = $newChildren > 0 ? -1 : 0; + $oldParent = $oldChildren > 0 ? -1 : 0; + + $this->dao->update(TABLE_PROGRAM)->set('parent')->eq($newParent)->where('id')->eq($parentID)->exec(); + $this->dao->update(TABLE_PROGRAM)->set('parent')->eq($oldParent)->where('id')->eq($oldParentID)->exec(); + /* Process child node path and grade field. */ foreach($childNodes as $childNode) { @@ -622,7 +804,7 @@ class programModel extends model $path = rtrim($parent->path, ',') . $path; $grade = $parent->grade + $grade; } - $this->dao->update(TABLE_PROJECT)->set('path')->eq($path)->set('grade')->eq($grade)->where('id')->eq($childNode->id)->exec(); + $this->dao->update(TABLE_PROGRAM)->set('path')->eq($path)->set('grade')->eq($grade)->where('id')->eq($childNode->id)->exec(); } return !dao::isError(); diff --git a/module/program/view/browsebylist.html.php b/module/program/view/browsebylist.html.php index a61d26caff..212be194f8 100644 --- a/module/program/view/browsebylist.html.php +++ b/module/program/view/browsebylist.html.php @@ -9,11 +9,11 @@