From feb8e765aee00b5f06704a1db96feda3ec070a60 Mon Sep 17 00:00:00 2001 From: qiyu-xie Date: Fri, 11 Dec 2020 16:07:43 +0800 Subject: [PATCH] * Optimize the code. --- module/program/model.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/module/program/model.php b/module/program/model.php index 95499d9001..efe58f7548 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1237,18 +1237,24 @@ class programModel extends model } } - /* When select create new product, product name cannot be empty. */ - if(isset($_POST['newProduct']) and empty($_POST['productName'])) + /* When select create new product, product name cannot be empty and duplicate. */ + if(isset($_POST['newProduct'])) { - dao::$errors[] = sprintf($this->lang->error->notempty, $this->app->loadLang('product')->product->name); - return false; - } - - $existProductName = $this->dao->select('name')->from(TABLE_PRODUCT)->where('name')->eq($_POST['productName'])->fetch('name'); - if(!empty($existProductName)) - { - dao::$errors[] = $this->lang->program->existProductName; - return false; + if(empty($_POST['productName'])) + { + $this->app->loadLang('product'); + dao::$errors[] = sprintf($this->lang->error->notempty, $this->lang->product->name); + return false; + } + else + { + $existProductName = $this->dao->select('name')->from(TABLE_PRODUCT)->where('name')->eq($_POST['productName'])->fetch('name'); + if(!empty($existProductName)) + { + dao::$errors[] = $this->lang->program->existProductName; + return false; + } + } } $requiredFields = $this->config->program->PRJCreate->requiredFields;