示例#1
0
 public static function mergeProduct($sourceId, $disId)
 {
     $resultInfo = array();
     $checkMergeResult = self::checkMergeable($sourceId, $disId);
     if (CommonService::$ApiResult['FAIL'] == $checkMergeResult['status']) {
         return $checkMergeResult;
     }
     $sourceProductInfo = Product::model()->findByPk($sourceId);
     $moduleInfo = array();
     $moduleInfo['name'] = $sourceProductInfo['name'];
     $moduleInfo['display_order'] = 0;
     $moduleInfo['product_id'] = $disId;
     $createModuleResult = ProductModuleService::editProductModule($moduleInfo);
     if (CommonService::$ApiResult['FAIL'] == $createModuleResult['status']) {
         return $createModuleResult;
     }
     $newModuleId = $createModuleResult['detail']['id'];
     try {
         //update top layer module
         Yii::app()->db->createCommand()->setText('update {{product_module}} set product_id=' . $disId . ',grade=grade+1' . ',full_path_name=CONCAT(' . Yii::app()->db->quoteValue($sourceProductInfo['name'] . ProductModule::MODULE_SPLITTER) . ',full_path_name),parent_id=' . $newModuleId . ' where product_id=' . $sourceId . ' and parent_id is null')->execute();
         //update other layer module
         Yii::app()->db->createCommand()->setText('update {{product_module}} set product_id=' . $disId . ',grade=grade+1' . ',full_path_name=CONCAT(' . Yii::app()->db->quoteValue($sourceProductInfo['name'] . ProductModule::MODULE_SPLITTER) . ',full_path_name) where product_id=' . $sourceId . ' and parent_id is not null')->execute();
         $infoTypeArr = array(Info::TYPE_BUG, Info::TYPE_CASE, Info::TYPE_RESULT);
         foreach ($infoTypeArr as $infoType) {
             Yii::app()->db->createCommand()->setText('update {{' . $infoType . '_info}} set product_id=' . $disId . ',productmodule_id=' . $newModuleId . ' where product_id=' . $sourceId . ' and productmodule_id is null')->execute();
             Yii::app()->db->createCommand()->setText('update {{' . $infoType . '_info}} set product_id=' . $disId . ' where productmodule_id in( select id from {{product_module}} where product_id=' . $disId . ')')->execute();
             $fieldNameStr = FieldConfigService::getActiveCustomFieldName($disId, $infoType);
             Yii::app()->db->createCommand()->setText('insert into {{etton' . $infoType . '_' . $disId . '}} (' . $fieldNameStr . ') select ' . $fieldNameStr . ' from {{etton' . $infoType . '_' . $sourceId . '}}')->execute();
             Yii::app()->db->createCommand()->setText('drop table if exists {{etton' . $infoType . '_' . $sourceId . '}} ')->execute();
         }
         //delete related record
         $relatedTableNameArr = array('field_config', 'map_product_user', 'map_product_group', 'user_query', 'user_template');
         foreach ($relatedTableNameArr as $relatedTableName) {
             Yii::app()->db->createCommand()->setText('delete from {{' . $relatedTableName . '}} where product_id =' . $sourceId)->execute();
         }
         //delete be merged product
         Yii::app()->db->createCommand()->setText('delete from {{product}} where id =' . $sourceId)->execute();
     } catch (Exception $e) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $e->getMessage();
         return $resultInfo;
     }
     $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
     return $resultInfo;
 }
示例#2
0
 /**
  * get module's html select element for info page use
  *
  * @author                                    youzhao.zxw<*****@*****.**>
  * @param   int             $productId        product id
  * @param   int             $productModuleId  productmodule's id
  * @param   string          $infoType         bug,case or result
  * @return  string                            module's html select string
  */
 public static function getModuleSelect($productId, $productModuleId, $infoType)
 {
     $productInfo = Product::model()->findByPk($productId);
     $productName = $productInfo['name'];
     $firstLayerModuleArr = ProductModuleService::getLayer1Module($productId, $productName);
     if (!empty($productModuleId)) {
         $fullIdArr = array();
         $fullIdArr = ProductModuleService::getFullPathId($fullIdArr, $productModuleId);
         $layer1Id = $fullIdArr[1];
     } else {
         $firstLayerIdArr = array_keys($firstLayerModuleArr);
         $layer1Id = $firstLayerIdArr[0];
     }
     $moduleSelectId = ucfirst(strtolower($infoType)) . 'InfoView_productmodule_id';
     $moduleSelectName = ucfirst(strtolower($infoType)) . 'InfoView[productmodule_id]';
     $returnStr = CHtml::dropDownList('layer1_module', $layer1Id, array($productName => $firstLayerModuleArr), array('style' => 'width:180px;', 'class' => 'required', 'onchange' => 'getChildModule($(this).val())'));
     $returnStr .= CHtml::dropDownList($moduleSelectName, $productModuleId, ProductModuleService::getChildModuleSelectOption($layer1Id), array('style' => 'width:400px;', 'class' => 'product_module', 'id' => $moduleSelectId, 'onchange' => 'setAssignTo(\'' . $infoType . '\')'));
     return $returnStr;
 }
示例#3
0
 public function actionGetChildModuleSelect()
 {
     $parentModuleId = $_GET['parent_id'];
     $infoType = $_GET['type'];
     $moduleSelectId = ucfirst(strtolower($infoType)) . 'InfoView_productmodule_id';
     $moduleSelectName = ucfirst(strtolower($infoType)) . 'InfoView[productmodule_id]';
     echo CHtml::dropDownList($moduleSelectName, '', ProductModuleService::getChildModuleSelectOption($parentModuleId), array('style' => 'width:400px;', 'class' => 'product_module', 'id' => $moduleSelectId, 'onchange' => 'setAssignTo(\'' . $infoType . '\')'));
 }
示例#4
0
 public function actionIndex()
 {
     self::checkEditable();
     $productId = $_GET['product_id'];
     $productInfo = Product::model()->findByPk($_GET['product_id']);
     $this->breadcrumbs = array(Yii::t('Product', 'Back To Product List') => array('/product/index'), $productInfo->name . Yii::t('ProductModule', 'Edit Product Modules'));
     $selectedId = 0;
     $selectedParentId = 0;
     $addedModel = new ProductModule();
     $addedModel->product_id = $productId;
     $addedModel->parent_id = 0;
     $addedModel->display_order = 0;
     $moduleOptionArr = ProductModuleService::getSelectModuleListOption($productId);
     if (isset($_GET['selected_id']) && 0 != $_GET['selected_id']) {
         $selectedId = $_GET['selected_id'];
         $editedModel = ProductModuleService::loadModel($selectedId);
         if ($editedModel->parent_id != null) {
             $selectedParentId = $editedModel->parent_id;
         }
         $addedModel->parent_id = $_GET['selected_id'];
     } else {
         $editedModel = new ProductModule();
     }
     if (isset($_POST['ProductModule'])) {
         $returnJson = array();
         $productModuleInfo = $_POST['ProductModule'];
         $productModuleInfo['product_id'] = $productId;
         //delete product module
         if (!empty($_POST['is_delete'])) {
             $editResult = ProductModuleService::deleteModule($_POST['ProductModule']['id']);
         } else {
             if (!empty($_POST['separate_as_product'])) {
                 $editResult = ProductModuleService::separateModule($_POST['ProductModule']['id']);
             } else {
                 if (isset($_POST['ProductModule']['id'])) {
                     if (!empty($_POST['is_delete'])) {
                         ProductModule::model()->findByPk($_POST['ProductModule']['id'])->delete();
                     }
                     $editedModel->attributes = $_POST['ProductModule'];
                     $productModuleInfo['add_owner_name'] = $productModuleInfo['owner_name'];
                 } else {
                     $addedModel->attributes = $_POST['ProductModule'];
                     $productModuleInfo['owner_name'] = $productModuleInfo['add_owner_name'];
                     if (!empty($_GET['selected_id'])) {
                         $productModuleInfo['parent_id'] = $_GET['selected_id'];
                     } else {
                         $productModuleInfo['parent_id'] = 0;
                     }
                 }
                 $editResult = ProductModuleService::editProductModule($productModuleInfo);
             }
         }
         $returnJson['status'] = $editResult['status'];
         if ($editResult['status'] == CommonService::$ApiResult['FAIL']) {
             if (isset($_POST['ProductModule']['id'])) {
                 $editedModel->addErrors($editResult['detail']);
                 $returnJson['formid'] = 'edit';
             } else {
                 $addedModel->addErrors($editResult['detail']);
                 $returnJson['formid'] = 'add';
             }
             $returnJson['detail'] = $editResult['detail'];
         } else {
             if (!empty($_POST['is_delete'])) {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module deleted successfully');
             } elseif (!empty($_POST['separate_as_product'])) {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module separated as product successfully');
             } elseif (isset($_POST['ProductModule']['id'])) {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module edited successfully');
             } else {
                 $returnJson['detail'] = Yii::t('ProductModule', 'Module added successfully');
             }
         }
         echo json_encode($returnJson);
         return;
     }
     $this->render('index', array('productId' => $productInfo->id, 'selectedId' => $selectedId, 'selectedParentId' => $selectedParentId, 'productName' => $productInfo->name, 'addedModel' => $addedModel, 'editedModel' => $editedModel, 'moduleOptionArr' => $moduleOptionArr));
 }
示例#5
0
 /**
  * edit product module
  *
  * @author                                    youzhao.zxw<*****@*****.**>
  * @param   array             $params         module's information
  * @return  array                             module update result
  */
 public static function editProductModule($params)
 {
     $resultInfo = array();
     $parentModule = array();
     $oldFullPathName = '';
     $actionType = BugfreeModel::ACTION_OPEN;
     $oldRecordAttributs = array();
     if (!empty($params['id'])) {
         $productModule = ProductModule::model()->findByPk((int) $params['id']);
         $oldRecordAttributs = $productModule->attributes;
         $actionType = BugfreeModel::ACTION_EDIT;
         $productModule = self::loadModel($params['id']);
         $oldFullPathName = $productModule->full_path_name;
     } else {
         $productModule = new ProductModule();
     }
     $connection = Yii::app()->db;
     $transaction = $connection->beginTransaction();
     try {
         $productModule->attributes = $params;
         if (0 != $productModule->parent_id) {
             $parentModule = ProductModuleService::loadModel((int) $productModule->parent_id);
             if (!empty($parentModule)) {
                 $productModule->grade = $parentModule->grade + 1;
                 $productModule->full_path_name = $parentModule->full_path_name . ProductModule::MODULE_SPLITTER . $params['name'];
             } else {
                 $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
                 $resultInfo['detail'] = array('parent_id' => Yii::t('ProductModule', self::ERROR_PARENT_MODULE_NOTEXIST));
                 return $resultInfo;
             }
         } else {
             $productModule->parent_id = null;
             $productModule->grade = 1;
             $productModule->full_path_name = $params['name'];
         }
         $productModule->scenario = ProductModule::SCENARIO_EDIT;
         if (!$productModule->save()) {
             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
             $resultInfo['detail'] = $productModule->getErrors();
         } else {
             $newRecord = self::loadModel($productModule->id);
             $addActionResult = AdminActionService::addActionNotes('product_module', $actionType, $newRecord, $oldRecordAttributs);
             if ('' != $oldFullPathName && $oldFullPathName != $newRecord['full_path_name']) {
                 $renameResult = self::updateChildModule($oldFullPathName);
                 if (CommonService::$ApiResult['SUCCESS'] == $renameResult['status']) {
                     $transaction->commit();
                     $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
                     $resultInfo['detail'] = array('id' => $productModule->id);
                 } else {
                     $resultInfo = $renameResult;
                 }
             } else {
                 $transaction->commit();
                 $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
                 $resultInfo['detail'] = array('id' => $productModule->id);
             }
         }
     } catch (Exception $e) {
         $transaction->rollBack();
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail']['id'] = $e->getMessage();
     }
     return $resultInfo;
 }