diff --git a/module/product/config/form.php b/module/product/config/form.php index ae2802aef3..c118f9016e 100644 --- a/module/product/config/form.php +++ b/module/product/config/form.php @@ -46,3 +46,6 @@ $config->product->form->batchEdit['status'] = array('type' => 'array', 'c $config->product->form->batchEdit['desc'] = array('type' => 'array', 'control' => 'textarea', 'required' => false, 'default' => ''); $config->product->form->batchEdit['acl'] = array('type' => 'array', 'control' => 'radio', 'required' => false, 'default' => 'private', 'options' => $lang->product->aclList); if($config->systemMode != 'ALM') unset($config->product->form->batchEdit['program'], $config->product->form->batchEdit['line']); + +$config->product->form->close = array(); +$config->product->form->close['status'] = array('type' => 'string', 'control' => 'hidden', 'required' => false, 'default' => 'close'); diff --git a/module/product/control.php b/module/product/control.php index 243007103f..ff5a4b97e5 100755 --- a/module/product/control.php +++ b/module/product/control.php @@ -322,39 +322,29 @@ class product extends control /** * Close product. * - * @param int $productID + * @param string $productID * @access public * @return void */ - public function close($productID) + public function close(string $productID) { - $product = $this->product->getById($productID); - $actions = $this->loadModel('action')->getList('product', $productID); + $productID = (int)$productID; if(!empty($_POST)) { - $changes = $this->product->close($productID); - if(dao::isError()) return print(js::error(dao::getError())); + $formConfig = $this->productZen->appendFlowFields($this->config->product->form->close); + $data = form::data($formConfig); + $product = $this->productZen->prepareCloseExtras($data); - if($this->post->comment != '' or !empty($changes)) - { - $actionID = $this->action->create('product', $productID, 'Closed', $this->post->comment); - $this->action->logHistory($actionID, $changes); - } + $changes = $this->product->close($productID, $product); + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->executeHooks($productID); - - return print(js::reload('parent.parent')); + $response = $this->productZen->responseAfterClose($productID, $changes, $this->post->comment); + $this->send($response); } $this->product->setMenu($productID); - - $this->view->product = $product; - $this->view->title = $this->view->product->name . $this->lang->colon .$this->lang->close; - $this->view->position[] = $this->lang->close; - $this->view->actions = $actions; - $this->view->users = $this->loadModel('user')->getPairs('noletter'); - $this->display(); + $this->productZen->buildCloseForm($productID); } /** diff --git a/module/product/model.php b/module/product/model.php index 395379f5e8..7e97b6984d 100755 --- a/module/product/model.php +++ b/module/product/model.php @@ -627,28 +627,23 @@ class productModel extends model /** * Close product. * - * @param int $productID. + * @param int $productID + * @param object $product must have status field. * @access public - * @return void + * @return array|false */ - public function close($productID) + public function close(int $productID, object $product): array|false { $oldProduct = $this->getById($productID); - $product = fixer::input('post') - ->add('id', $productID) - ->setDefault('status', 'closed') - ->stripTags($this->config->product->editor->close['id'], $this->config->allowedTags) - ->remove('comment') - ->get(); + if(empty($product)) return false; - $product = $this->loadModel('file')->processImgURL($product, $this->config->product->editor->close['id'], $this->post->uid); - $this->dao->update(TABLE_PRODUCT)->data($product) - ->autoCheck() + $this->dao->update(TABLE_PRODUCT)->data($product)->autoCheck() ->checkFlow() - ->where('id')->eq((int)$productID) + ->where('id')->eq($productID) ->exec(); - if(!dao::isError()) return common::createChanges($oldProduct, $product); + if(dao::isError()) return false; + return common::createChanges($oldProduct, $product); } /** diff --git a/module/product/test/model/close.php b/module/product/test/model/close.php index 275de37ce1..f06d9ebba2 100755 --- a/module/product/test/model/close.php +++ b/module/product/test/model/close.php @@ -3,22 +3,17 @@ include dirname(__FILE__, 5) . "/test/lib/init.php"; include dirname(__FILE__, 2) . '/product.class.php'; +zdTable('product')->gen(10); + /** title=productModel->close(); cid=1 pid=1 -测试关闭产品1 >> status,normal,closed -测试关闭产品2 >> status,normal,closed -测试关闭产品3 >> status,normal,closed -测试关闭产品4 >> status,normal,closed -测试关闭产品5 >> status,normal,closed -测试关闭不存在产品 >> 0 - */ -$productIDList = array('1', '2', '3', '4', '5', '1000001'); +$productIDList = array(1, 2, 3, 4, 5, 1000001, 0); $product = new productTest('admin'); @@ -28,3 +23,4 @@ r($product->closeTest($productIDList[2])) && p('0:field,old,new') && e('status,n r($product->closeTest($productIDList[3])) && p('0:field,old,new') && e('status,normal,closed'); // 测试关闭产品4 r($product->closeTest($productIDList[4])) && p('0:field,old,new') && e('status,normal,closed'); // 测试关闭产品5 r($product->closeTest($productIDList[5])) && p() && e('0'); // 测试关闭不存在产品 +r($product->closeTest($productIDList[6])) && p() && e('0'); // 测试关闭不存在产品 diff --git a/module/product/test/product.class.php b/module/product/test/product.class.php index a92a6b8763..49660f8c82 100644 --- a/module/product/test/product.class.php +++ b/module/product/test/product.class.php @@ -587,20 +587,17 @@ class productTest * * @param int $productID * @access public - * @return array + * @return array|false */ - public function closeTest($productID) + public function closeTest(int $productID): array|false { - $changes = $this->objectModel->close($productID); + $data = new stdclass(); + $data->status = 'closed'; - if(dao::isError()) - { - return dao::getError(); - } - else - { - return $changes; - } + $changes = $this->objectModel->close($productID, $data); + + if(dao::isError()) return dao::getError(); + return $changes; } /** diff --git a/module/product/zen.php b/module/product/zen.php index 7e407003ef..3aed1c7b65 100644 --- a/module/product/zen.php +++ b/module/product/zen.php @@ -283,6 +283,22 @@ class productZen extends product return $fields; } + /** + * 获取关闭产品页面的表单配置。 + * Get form fields for close product page. + * + * @access private + * @return array + */ + private function getFormFields4Close(): array + { + /* Init fields. */ + $fields = $this->appendFlowFields($this->config->product->form->close); + $fields['comment'] = array('type' => 'string', 'control' => 'editor', 'required' => false, 'default' => '', 'width' => 'full'); + + return $fields; + } + /** * Get product lines and product lines of program. * @@ -469,6 +485,7 @@ class productZen extends product $this->view->title = $this->lang->product->batchEdit; $this->view->lines = $lines; $this->view->products = $products; + $this->view->fields = $this->getFormFields4BatchEdit(); $this->view->programID = $programID; $this->view->authPrograms = array('' => '') + $authPrograms; $this->view->unauthPrograms = $unauthPrograms; @@ -477,6 +494,24 @@ class productZen extends product $this->display(); } + /** + * 构建关闭产品页面数据。 + * Build close product form. + * + * @param int $productID + * @access protected + * @return void + */ + protected function buildCloseForm(int $productID) + { + $this->view->title = $this->view->product->name . $this->lang->colon .$this->lang->close; + $this->view->product = $this->product->getById($productID); + $this->view->actions = $this->loadModel('action')->getList('product', $productID); + $this->view->users = $this->loadModel('user')->getPairs('noletter'); + $this->view->fields = $this->getFormFields4Close(); + $this->display(); + } + /** * 为view层设置要用数据。 * Set view variables and display for project page. @@ -597,6 +632,23 @@ class productZen extends product return $products; } + /** + * 预处理关闭产品数据。 + * Prepare close product extras. + * + * @param form $data + * @access protected + * @return object + */ + protected function prepareCloseExtras(form $data): object + { + $product = $data->setDefault('status', 'closed') + ->stripTags($this->config->product->editor->close['id'], $this->config->allowedTags) + ->get(); + $product = $this->loadModel('file')->processImgURL($product, $this->config->product->editor->close['id'], $this->post->uid); + return $product; + } + /** * 成功插入产品数据后,其他的额外操作。 * Process after create product. @@ -672,6 +724,28 @@ class productZen extends product return $response; } + /** + * 成功关闭产品数据后,后续操作。 + * Response after close product + * + * @param int $productID + * @param array $changes + * @param string $comment + * @access protected + * @return void + */ + protected function responseAfterClose(int $productID, array $changes = array(), string $comment = '') + { + if(!empty($comment) or !empty($changes)) + { + $actionID = $this->loadModel('action')->create('product', $productID, 'Closed', $comment); + $this->action->logHistory($actionID, $changes); + } + + $this->executeHooks($productID); + return array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => 'loadCurrentPage()'); + } + /** * 从产品统计数据中统计项目集。 * Statistics program data from statistics data of product.