From b45b3e3661022ded82de2ad2b2899f13cafbae15 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 14 Sep 2022 14:07:00 +0800 Subject: [PATCH] * Finish task #68999. --- module/product/model.php | 2 ++ module/project/control.php | 2 +- module/project/js/create.js | 7 +++++++ module/project/model.php | 32 ++++++++++++++++------------- module/project/view/create.html.php | 4 ++++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/module/product/model.php b/module/product/model.php index 95766d7eea..cd622a11e0 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -267,6 +267,7 @@ class productModel extends model return $this->dao->select('t1.id as id,t1.*')->from(TABLE_PRODUCT)->alias('t1') ->leftJoin(TABLE_PROGRAM)->alias('t2')->on('t1.program = t2.id') ->where('t1.deleted')->eq(0) + ->andWhere('t1.shadow')->eq(0) ->beginIF($programID)->andWhere('t1.program')->eq($programID)->fi() ->beginIF($line > 0)->andWhere('t1.line')->eq($line)->fi() ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->products)->fi() @@ -323,6 +324,7 @@ class productModel extends model ->leftJoin(TABLE_PROGRAM)->alias('t2')->on('t1.program = t2.id') ->where($productQuery) ->andWhere('t1.deleted')->eq(0) + ->andWhere('t1.shadow')->eq(0) ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->products)->fi() ->andWhere('t1.vision')->eq($this->config->vision)->fi() ->orderBy('t1.order_asc') diff --git a/module/project/control.php b/module/project/control.php index 56282a0926..f34939be19 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -447,7 +447,7 @@ class project extends control $this->loadModel('action')->create('project', $projectID, 'opened'); /* Link the plan stories. */ - if(!empty($_POST['plans'])) + if(!empty($_POST['hasProduct']) && !empty($_POST['plans'])) { $planIdList = array(); foreach($_POST['plans'] as $plans) diff --git a/module/project/js/create.js b/module/project/js/create.js index 795cbd72aa..9f0033e7bf 100644 --- a/module/project/js/create.js +++ b/module/project/js/create.js @@ -1,5 +1,12 @@ $(function() { + $('[name=hasProduct]').change(function() + { + const hasProduct = $('[name=hasProduct]:checked').val(); + + $('#productTitle, #linkPlan').closest('tr').toggle(hasProduct == 1); + }); + $('#copyProjects a').click(function() { setCopyProject($(this).data('id')); diff --git a/module/project/model.php b/module/project/model.php index 64e107c2ab..eebdb9223d 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -1112,7 +1112,7 @@ class projectModel extends model if(isset($this->config->setCode) and $this->config->setCode == 0) unset($project->code); $linkedProductsCount = 0; - if(isset($_POST['products'])) + if($project->hasProduct && isset($_POST['products'])) { foreach($_POST['products'] as $product) { @@ -1126,7 +1126,7 @@ class projectModel extends model $program = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($project->parent)->fetch(); /* Judge products not empty. */ - if(empty($linkedProductsCount) and !isset($_POST['newProduct'])) + if($project->hasProduct && empty($linkedProductsCount) and !isset($_POST['newProduct'])) { dao::$errors['products0'] = $this->lang->project->productNotEmpty; return false; @@ -1160,7 +1160,7 @@ class projectModel extends model } /* When select create new product, product name cannot be empty and duplicate. */ - if(isset($_POST['newProduct'])) + if($project->hasProduct && isset($_POST['newProduct'])) { if(empty($_POST['productName'])) { @@ -1265,11 +1265,12 @@ class projectModel extends model $this->updateProducts($projectID); - if(isset($_POST['newProduct']) or (!$project->parent and empty($linkedProductsCount))) + if(!$project->hasProduct or isset($_POST['newProduct']) or (!$project->parent and empty($linkedProductsCount))) { /* If parent not empty, link products or create products. */ $product = new stdclass(); - $product->name = $this->post->productName ? $this->post->productName : $project->name; + $product->name = !$project->hasProduct ? "{$project->name}_{$projectID}" : ($this->post->productName ? $this->post->productName : $project->name); + $product->shadow = (int)empty($project->hasProduct); $product->bind = $this->post->parent ? 0 : 1; $product->program = $project->parent ? current(array_filter(explode(',', $program->path))) : 0; $product->acl = $project->acl == 'open' ? 'open' : 'private'; @@ -1292,15 +1293,18 @@ class projectModel extends model $this->dao->insert(TABLE_PROJECTPRODUCT)->data($projectProduct)->exec(); - /* Create doc lib. */ - $this->app->loadLang('doc'); - $lib = new stdclass(); - $lib->product = $productID; - $lib->name = $this->lang->doclib->main['product']; - $lib->type = 'product'; - $lib->main = '1'; - $lib->acl = 'default'; - $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); + if($project->hasProduct) + { + /* Create doc lib. */ + $this->app->loadLang('doc'); + $lib = new stdclass(); + $lib->product = $productID; + $lib->name = $this->lang->doclib->main['product']; + $lib->type = 'product'; + $lib->main = '1'; + $lib->acl = 'default'; + $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); + } } /* Save order. */ diff --git a/module/project/view/create.html.php b/module/project/view/create.html.php index d994c4f549..6a984bc8a8 100755 --- a/module/project/view/create.html.php +++ b/module/project/view/create.html.php @@ -72,6 +72,10 @@ + + project->type;?> + project->projectTypeList, 1);?> + project->PM;?>