示例#1
0
 public static function formOptionTreeData($infos, $parentId)
 {
     $parentModuleInfo = ProductModule::model()->findByPk($parentId);
     if ($parentModuleInfo == null) {
         return array();
     } else {
         $topGrade = $parentModuleInfo->grade + 1;
         $paNameLen = strlen($parentModuleInfo->full_path_name);
     }
     $treeArr = array();
     foreach ($infos as $info) {
         $treeNode = new TreeDataModel();
         $treeNode->id = $info['id'];
         $treeNode->pId = $info['parent_id'];
         $filteredName = substr($info['full_path_name'], $paNameLen, strlen($info['full_path_name']));
         $treeNode->name = $filteredName;
         $treeArr[$info['grade']][$info['id']] = $treeNode;
         if (isset($treeArr[$info['grade'] - 1][$info['parent_id']])) {
             $treeArr[$info['grade'] - 1][$info['parent_id']]->nodes[] = $treeNode;
         }
     }
     if (!empty($treeArr[$topGrade])) {
         return $treeArr[$topGrade];
     } else {
         return array();
     }
 }
示例#2
0
 /**
  * basic info convert
  *
  * @todo convert $action for bug import
  *
  * @param array $basicInfo
  * @param string $infoType
  * @return string
  */
 private function basicInfoConv($basicInfo, $infoType)
 {
     // hard code for productmodule_id
     if (isset($basicInfo['productmodule_id'])) {
         $moduleSplitterPos = strpos($basicInfo['productmodule_id'], ProductModule::MODULE_SPLITTER);
         if (false !== $moduleSplitterPos) {
             $moduleName = substr($basicInfo['productmodule_id'], $moduleSplitterPos + 1);
             $moduleInfo = ProductModule::model()->findByAttributes(array('product_id' => $basicInfo['product_id'], 'full_path_name' => $moduleName));
             if (!empty($moduleInfo)) {
                 $basicInfo['productmodule_id'] = $moduleInfo->id;
             }
         } else {
             //$basicInfo['productmodule_id'] = 0;
         }
     }
     // hard code for id
     if (isset($basicInfo['id']) && '' == $basicInfo['id']) {
         unset($basicInfo['id']);
     }
     // hard code for delete_flag
     if (isset($basicInfo['delete_flag'])) {
         $basicInfo['delete_flag'] = CommonService::getTrueFalseValue($basicInfo['delete_flag']);
     }
     if (isset($basicInfo['priority'])) {
         if (Info::TYPE_CASE == $infoType) {
             $basicInfo['priority'] = ProductService::getCasePriorityValueByName($basicInfo['product_id'], $basicInfo['priority']);
         } else {
             if (Info::TYPE_BUG == $infoType) {
                 $basicInfo['priority'] = ProductService::getBugPriorityValueByName($basicInfo['product_id'], $basicInfo['priority']);
             }
         }
     }
     if (isset($basicInfo['severity']) && Info::TYPE_BUG == $infoType) {
         $basicInfo['severity'] = ProductService::getBugSeverityValueByName($basicInfo['product_id'], $basicInfo['severity']);
     }
     // @TODO convert for bug import
     $bugUserKeyArr = array('resolved_by', 'closed_by');
     foreach ($bugUserKeyArr as $bugUserKey) {
         if (isset($basicInfo[$bugUserKey])) {
             $resolvedByInfo = TestUserService::getUserInfoByRealname($basicInfo[$bugUserKey]);
             if (!empty($resolvedByInfo)) {
                 $basicInfo[$bugUserKey] = $resolvedByInfo['id'];
             } else {
                 unset($basicInfo[$bugUserKey]);
             }
         }
     }
     $bugDateKeyArr = array('resolved_at', 'closed_at');
     foreach ($bugDateKeyArr as $bugDateKey) {
         if (empty($basicInfo[$bugDateKey])) {
             unset($basicInfo[$bugDateKey]);
         }
     }
     return $basicInfo;
 }
示例#3
0
 public function actionGetModuleOwner()
 {
     $moduleId = $_GET['module_id'];
     $moduleInfo = ProductModule::model()->findByPk($moduleId);
     $owner = '';
     if ($moduleInfo != null && !empty($moduleInfo->owner)) {
         $ownerInfo = TestUser::model()->findByPk($moduleInfo->owner);
         if ($ownerInfo != null) {
             $owner = $ownerInfo->realname;
         }
     }
     echo $owner;
 }
示例#4
0
 public function actionIndex()
 {
     $this->layout = '//layouts/index';
     $expandClass = $this->getExpandClassName();
     $infoType = $this->getInfoType();
     $productId = $this->getProductId($infoType);
     $accessProductIdNameArr = Yii::app()->user->getState('visit_product_list');
     $productName = $accessProductIdNameArr[$productId];
     $defaultShowFieldArr = SearchService::getDefaultShowFieldArr($infoType);
     $showFieldArr = $this->getShowFieldArr($defaultShowFieldArr, $infoType, $productId);
     $queryTitle = $this->getQueryTitle($productId, $infoType);
     $productModuleId = $this->getModuleId($productId, $infoType);
     $searchRowArr = InfoService::getBlankSearchRowArr($productName, $productModuleId, $infoType);
     $searchFieldConfig = SearchService::getSearchableFields($infoType, $productId);
     $defaultSelectFieldOptionStr = SearchService::getSelectFieldsOption($searchFieldConfig, $defaultShowFieldArr);
     $defaultShowFieldOptionStr = SearchService::getShowFieldsOption($searchFieldConfig, $defaultShowFieldArr);
     $templateStr = InfoService::getTemplateStr($productId, $infoType, Yii::app()->user->id);
     $leftMenu = UserQueryService::getQueryLinkStr($productId, $infoType, Yii::app()->user->id);
     //not request from post query, save query and reset query
     $filterSql = '';
     $filterColumn = '';
     if (!empty($_POST['queryaction'])) {
         Yii::app()->user->setState($productId . '_' . $infoType . '_filterSql', null);
         Yii::app()->user->setState($productId . '_' . $infoType . '_filterColumn', null);
         if (!empty($_POST['reset'])) {
             Yii::app()->user->setState($productId . '_' . $infoType . '_showField', null);
             Yii::app()->user->setState($productId . '_' . $infoType . '_search', null);
         } else {
             if (!empty($_POST['saveQuery'])) {
                 $result = UserQueryService::editUserQuery($queryTitle, $productId, $infoType, $_POST[Info::QUERY_GROUP_NAME]);
                 if (CommonService::$ApiResult['FAIL'] == $result['status']) {
                     CommonService::jsAlert(Yii::t('Common', 'save query fail'));
                 }
                 CommonService::testRefreshSelf();
             }
             if (isset($_POST[Info::QUERY_GROUP_NAME])) {
                 $searchCondition = $_POST[Info::QUERY_GROUP_NAME];
                 $searchRowArr = SearchService::getSearchConditionArr($searchCondition);
             }
         }
     } else {
         if (isset($_GET['query_id'])) {
             $searchRowArr = $this->getSavedSearchRow($productId, $infoType, $_GET['query_id']);
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterSql', null);
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterColumn', null);
             $productModuleId = $this->getSavedQueryModuleId($searchRowArr, $productId, $infoType);
         } else {
             $sessionSearchRowArr = Yii::app()->user->getState($productId . '_' . $infoType . '_search');
             if ($sessionSearchRowArr !== null) {
                 $searchRowArr = $sessionSearchRowArr;
             }
         }
         if (!empty($_GET['filter'])) {
             $filterArr = CommonService::splitStringToArray('|', $_GET['filter']);
             if (Info::$InputType['date'] == $searchFieldConfig[$filterArr[0]]['type']) {
                 $filterSql = $filterArr[0] . " like '" . addslashes($filterArr[1]) . "%'";
             } else {
                 $filterSql = $filterArr[0] . " = '" . addslashes($filterArr[1]) . "'";
             }
             $filterColumn = $filterArr[0];
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterSql', $filterSql);
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterColumn', $filterArr[0]);
         } else {
             $sessionFilterColumn = Yii::app()->user->getState($productId . '_' . $infoType . '_filterColumn');
             if ($sessionFilterColumn !== null) {
                 $filterSql = Yii::app()->user->getState($productId . '_' . $infoType . '_filterSql');
                 $filterColumn = $sessionFilterColumn;
             }
         }
     }
     if (isset($_GET['productmodule_id'])) {
         $searchRowArr[0]['leftParenthesesName'] = '';
         $searchRowArr[0]['field'] = 'module_name';
         $searchRowArr[0]['rightParenthesesName'] = '';
         $searchRowArr[0]['operator'] = 'UNDER';
         $searchRowArr[0]['andor'] = 'And';
         $searchRowArr[0]['value'] = '';
         $selectedModuleInfo = ProductModule::model()->findByPk($_GET['productmodule_id']);
         if ($selectedModuleInfo !== null) {
             $searchRowArr[0]['value'] = $productName . '/' . $selectedModuleInfo->full_path_name;
         } else {
             $searchRowArr[0]['value'] = $productName;
         }
     }
     $searchRowArr = $this->setSpecialModuleCondiftion($searchRowArr, $productName);
     Yii::app()->user->setState($productId . '_' . $infoType . '_search', $searchRowArr);
     $getSqlResult = SqlService::baseGetGroupQueryStr($searchFieldConfig, $infoType, $searchRowArr);
     if (CommonService::$ApiResult['FAIL'] == $getSqlResult['status']) {
         $whereStr = ' 1<>1 ';
     } else {
         $whereStr = $getSqlResult['detail'];
     }
     if ('' != $filterSql) {
         $whereStr .= ' and ' . $filterSql;
     }
     $selectFieldOptionStr = SearchService::getSelectFieldsOption($searchFieldConfig, $showFieldArr);
     $showFieldOptionStr = SearchService::getShowFieldsOption($searchFieldConfig, $showFieldArr);
     $defaultSelectFieldOptionStr = addslashes($defaultSelectFieldOptionStr);
     $defaultSelectFieldOptionStr = str_replace(array("\r\n", "\r", "\n"), "", $defaultSelectFieldOptionStr);
     $defaultShowFieldOptionStr = addslashes($defaultShowFieldOptionStr);
     $defaultShowFieldOptionStr = str_replace(array("\r\n", "\r", "\n"), "", $defaultShowFieldOptionStr);
     $jsValueStr = SearchService::getJsValueOption($this, $searchFieldConfig);
     $jsOperatorStr = SearchService::getJsOperatorOption($searchFieldConfig);
     $searchConditionHtml = SearchService::getSearchHtml($infoType, $searchFieldConfig, $searchRowArr);
     $searchConditionHtmlTemplate = SearchService::getSearchConditionRowHtml(Info::TEMPLATE_NUMBER, $searchFieldConfig, InfoService::getTemplateSearchRowArr());
     $searchConditionHtmlTemplate = addslashes($searchConditionHtmlTemplate);
     $searchConditionHtmlTemplate = str_replace(array("\r\n", "\r", "\n"), "", $searchConditionHtmlTemplate);
     $showType = Yii::app()->user->getState($productId . '_' . $infoType . '_showtype');
     if (empty($showType)) {
         $showType = Info::SHOW_TYPE_GRID;
     }
     $relatedFields = $this->getRelatedFields($searchRowArr, $showFieldArr);
     $isAllBasicField = SearchService::isAllBasicField(SearchService::getBasicFieldArr($infoType), $relatedFields);
     $renderArr = array('expandClass' => $expandClass, 'productId' => $productId, 'productModuleId' => $productModuleId, 'infoType' => $infoType, 'searchFieldConfig' => $searchFieldConfig, 'selectFieldOptionStr' => $selectFieldOptionStr, 'showFieldOptionStr' => $showFieldOptionStr, 'defaultSelectFieldOptionStr' => $defaultSelectFieldOptionStr, 'defaultShowFieldOptionStr' => $defaultShowFieldOptionStr, 'searchConditionHtml' => $searchConditionHtml, 'searchConditionHtmlTemplate' => $searchConditionHtmlTemplate, 'queryTitle' => $queryTitle, 'jsValueStr' => $jsValueStr, 'jsOperatorStr' => $jsOperatorStr, 'leftMenu' => $leftMenu, 'templateStr' => $templateStr, 'showType' => $showType, 'showMyQueryDiv' => Yii::app()->user->getState('my_query_div'));
     if ($showType == Info::SHOW_TYPE_GRID) {
         $renderArr = array_merge($renderArr, $this->getGridShowContent($searchFieldConfig, $showFieldArr, $infoType, $productId, $filterColumn, $whereStr, $isAllBasicField));
         $renderArr['rowCssClassExpressionStr'] = InfoService::getRowCssClassExpressionStr($infoType);
     }
     $this->render('index', $renderArr);
 }
示例#5
0
文件: API.php 项目: mjrao/BugFree
 public function getBugStatusDetail($moduleId, $beginDate, $endDate)
 {
     $code = API::ERROR_NONE;
     $moduleInfo = ProductModule::model()->findByPk($moduleId);
     if (empty($moduleInfo)) {
         $code = API::ERROR_MODULE_EMPTY;
         $info = Yii::t('API', 'module not found');
     } else {
         if (!$this->validateDate($beginDate)) {
             $code = API::ERROR_DATE_FORMAT;
             $info = 'beginDate ' . Yii::t('API', 'date format wrong');
         } else {
             if (!$this->validateDate($endDate)) {
                 $code = API::ERROR_DATE_FORMAT;
                 $info = 'endDate ' . Yii::t('API', 'date format wrong');
             } else {
                 $sql = 'select buginfo_id, old_value, new_value, {{bug_action}}.created_at from {{bug_history}}, {{bug_action}}, {{bug_info}}
                where {{bug_history}}.bugaction_id={{bug_action}}.id and {{bug_info}}.id={{bug_action}}.buginfo_id and
                action_field = "bug_status" and buginfo_id in (select {{bug_info}}.id from {{bug_info}}, {{product_module}}
                  where  {{bug_info}}.productmodule_id = {{product_module}}.id and (full_path_name = "' . $moduleInfo['full_path_name'] . '" or full_path_name like "' . $moduleInfo['full_path_name'] . '/%") and closed_at>="' . $beginDate . '" and closed_at<"' . $endDate . '") order by buginfo_id, {{bug_action}}.created_at';
                 $resultInfo = Yii::app()->db->createCommand()->setText($sql)->queryAll();
                 $info['result_info'] = $resultInfo;
             }
         }
     }
     return array($code, $info);
 }
示例#6
0
 /**
  * Prepare info page
  *
  * @author                                    youzhao.zxw<*****@*****.**>
  * @param   String          $infoType         bug,case or result
  * @param   CController     $controller       page controller
  * @param   String          $actionType       edit action
  * @param   array           $request          page request info
  * @return  array                             page information
  */
 public static function initInfoPage($infoType, $controller, $actionType, $request)
 {
     $basicModelName = ucfirst(strtolower($infoType)) . 'InfoView';
     $infoId = $request->getParam('id');
     $fileDeleteable = true;
     if ('view' == $actionType) {
         $fileDeleteable = false;
     }
     if (isset($infoId)) {
         $mixedInfo = InfoService::loadModel($infoType, $infoId, $fileDeleteable);
         $model = $mixedInfo->getBasicInfo();
         $customInfo = $mixedInfo->getCustomInfo();
         if (Info::TYPE_BUG == $infoType) {
             if (!in_array($actionType, BugInfo::model()->getLegalActionByState($model->getAttribute($infoType . '_status')))) {
                 throw new CHttpException(400, Yii::t('Common', 'Required URL not found or permission denied.'));
             }
             if ('view' != $actionType) {
                 $model->setAttribute('bug_status', self::getBugStatusByAction($actionType));
             }
             if (BugInfo::ACTION_OPEN == $actionType) {
             } elseif (BugInfo::ACTION_RESOLVE == $actionType) {
                 $model->resolved_at = date(CommonService::DATE_FORMAT);
                 $model->resolved_by = Yii::app()->user->id;
                 $model->assign_to = $model->created_by;
                 $model->assign_to_name = CommonService::getUserRealName($model->created_by);
             } elseif (BugInfo::ACTION_CLOSE == $actionType) {
                 $model->closed_at = date(CommonService::DATE_FORMAT);
                 $model->closed_by = Yii::app()->user->id;
                 $model->assign_to = TestUser::CLOSE_USER_ID;
                 $model->assign_to_name = TestUser::CLOSE_USER_NAME;
             } elseif (BugInfo::ACTION_ACTIVATE == $actionType) {
                 $customInfo = self::filterCustomInfoInReactive($customInfo, $model->product_id);
                 $model->reopen_count += 1;
                 $model->assign_to = $model->resolved_by;
                 $model->assign_to_name = CommonService::getUserRealName($model->resolved_by);
                 $model = self::setBugActiveModel($model);
             }
             $model->scenario = $actionType;
         }
         $productId = $model->product_id;
         $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
     } else {
         $model = new $basicModelName();
         $customInfo = array();
         $sourceId = $request->getParam('source_id');
         $templateId = $request->getParam('template_id');
         $caseId = $request->getParam('case_id');
         $resultId = $request->getParam('result_id');
         $bugId = $request->getParam('bug_id');
         $bactchRunProductId = $request->getParam('batch_product_id');
         if (isset($sourceId)) {
             $mixedInfo = InfoService::loadModel($infoType, $sourceId, $fileDeleteable);
             $model = $mixedInfo->getBasicInfo();
             unset($model->id);
             $model->setIsNewRecord(true);
             $productId = $model->product_id;
             if ('bug' == $infoType) {
                 $customInfo = FieldConfigService::getBugAvailableValueByAction($mixedInfo->getCustomInfo(), $actionType, $productId);
                 $model = self::setBugActiveModel($model);
             } else {
                 if ('case' == $infoType) {
                     $customInfo = $mixedInfo->getCustomInfo();
                     unset($customInfo['id']);
                     unset($customInfo['case_id']);
                 }
             }
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($templateId)) {
             $templateInfo = UserTemplate::model()->findByPk($templateId);
             if ($templateInfo === null) {
                 throw new CHttpException(404, 'The requested page does not exist.');
             }
             $mixedInfo = unserialize($templateInfo['template_content']);
             $model->attributes = $mixedInfo->getBasicInfo();
             $productId = $model->product_id;
             $productInfo = Product::model()->findByPk($productId);
             $model->product_name = $productInfo->name;
             $customInfo = $mixedInfo->getCustomInfo();
             //no need custom id and info_id from template
             if (Info::TYPE_BUG == $infoType) {
                 $customInfo = FieldConfigService::getBugAvailableValueByAction($customInfo, $actionType, $productId);
                 $model = self::setBugActiveModel($model);
             } else {
                 if (Info::TYPE_CASE == $infoType) {
                     unset($customInfo['id']);
                     unset($customInfo['case_id']);
                 }
             }
             //unset($model->id);
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($caseId)) {
             $caseMixedInfo = InfoService::loadModel('case', $caseId, $fileDeleteable);
             $caseModel = $caseMixedInfo->getBasicInfo();
             $model->related_case_id = $caseId;
             $model->title = $caseModel->title;
             $model->product_id = $caseModel->product_id;
             $model->product_name = $caseModel->product_name;
             $model->module_name = $caseModel->module_name;
             $model->productmodule_id = $caseModel->productmodule_id;
             $model->result_step = $caseModel->case_step;
             $model->assign_to = TestUser::CLOSE_USER_ID;
             $model->assign_to_name = TestUser::CLOSE_USER_NAME;
             $productId = $caseModel->product_id;
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($bugId)) {
             $bugMixedInfo = InfoService::loadModel(Info::TYPE_BUG, $bugId, $fileDeleteable);
             $bugModel = $bugMixedInfo->getBasicInfo();
             $model->related_bug = $bugId;
             $model->title = $bugModel->title;
             $model->product_id = $bugModel->product_id;
             $model->product_name = $bugModel->product_name;
             $model->priority = $bugModel->priority;
             $model->module_name = $bugModel->module_name;
             $model->productmodule_id = $bugModel->productmodule_id;
             $model->case_step = $bugModel->repeat_step;
             $model->assign_to = $bugModel->assign_to;
             $model->assign_to_name = $bugModel->assign_to_name;
             $model->mail_to = $bugModel->mail_to;
             $productId = $bugModel->product_id;
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($bactchRunProductId)) {
             $model->title = Yii::t('Common', 'Mutiple items');
             $model->product_id = $bactchRunProductId;
             $model->product_name = Yii::t('Common', 'Mutiple items');
             $model->module_name = Yii::t('Common', 'Mutiple items');
             $model->assign_to = TestUser::CLOSE_USER_ID;
             $model->assign_to_name = TestUser::CLOSE_USER_NAME;
             $productId = $bactchRunProductId;
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } elseif (isset($resultId)) {
             $resultMixedInfo = InfoService::loadModel('result', $resultId, $fileDeleteable);
             $resultModel = $resultMixedInfo->getBasicInfo();
             $resultCustomInfo = $resultMixedInfo->getCustomInfo();
             $model->related_result = $resultId;
             $model->title = $resultModel->title;
             $model->module_name = $resultModel->module_name;
             $model->repeat_step = ResultStepService::removeStepResultForBug($resultModel->result_step);
             $model->product_id = $resultModel->product_id;
             $model->productmodule_id = $resultModel->productmodule_id;
             $model->assign_to = TestUser::ACTIVE_USER_ID;
             $model->assign_to_name = TestUser::ACTIVE_USER_NAME;
             $productId = $resultModel->product_id;
             $copyFieldArr = FieldConfigService::getBugCopyableFields($productId);
             foreach ($copyFieldArr as $resultField) {
                 $copyFieldName = $resultField['field_name'];
                 if (isset($resultCustomInfo[$copyFieldName])) {
                     $customInfo[$copyFieldName] = $resultCustomInfo[$copyFieldName];
                 }
             }
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, $actionType, array(), $customInfo);
         } else {
             $productId = $request->getParam('product_id');
             $productInfo = Product::model()->findByPk($productId);
             $model->product_name = $productInfo->name;
             $selectModuleId = Yii::app()->user->getState($productId . '_' . $infoType . '_selectedModule');
             if (!empty($selectModuleId)) {
                 $model->productmodule_id = $selectModuleId;
                 $selectedModuleInfo = ProductModule::model()->findByPk($selectModuleId);
                 if (!empty($selectedModuleInfo)) {
                     $model->assign_to = $selectedModuleInfo['owner'];
                     $model->assign_to_name = CommonService::getUserRealName($selectedModuleInfo['owner']);
                 }
             }
             if (Info::TYPE_BUG == $infoType) {
                 $model->repeat_step = $productInfo[$infoType . '_step_template'];
             } elseif (Info::TYPE_CASE == $infoType) {
                 $model->case_step = $productInfo[$infoType . '_step_template'];
             }
             $customFieldArr = FieldConfigService::getCustomFieldConfig($productId, $infoType, $controller, Info::ACTION_OPEN);
         }
         if (Info::TYPE_RESULT != $infoType) {
             $model->setAttribute($infoType . '_status', 'Active');
         } else {
             $model->setAttribute($infoType . '_status', ResultInfo::STATUS_COMPLETED);
         }
         if (Info::TYPE_BUG == $infoType) {
             $model->reopen_count = 0;
         }
         if (Info::TYPE_CASE == $infoType) {
             $model->delete_flag = CommonService::$TrueFalseStatus['FALSE'];
         }
         $model->attachment_file = '';
         $model->created_at = date(CommonService::DATE_FORMAT);
         $model->created_by = Yii::app()->user->id;
         $model->updated_at = '';
         $model->updated_by = '';
     }
     $model->product_id = $productId;
     $assignToName = self::parseAssignToName($model->assign_to);
     if ('' != $assignToName) {
         $model->assign_to_name = $assignToName;
     }
     return array($productId, $model, $customInfo, $customFieldArr);
 }
示例#7
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));
 }
示例#8
0
 /**
  * get module's full path name
  *
  * @author                                  youzhao.zxw<*****@*****.**>
  * @param   int         $id                 module id
  * @return  string                          module's full path name
  */
 public static function getModuleFullNameById($id)
 {
     if (empty($id)) {
         return '/';
     } else {
         $productModuleInfo = ProductModule::model()->findByPk($id);
         if ($productModuleInfo == null) {
             return '/';
         } else {
             return $productModuleInfo->full_path_name;
         }
     }
 }
示例#9
0
 public function nameValidator($attribute, $params)
 {
     if (false !== strpos($this->name, ProductModule::MODULE_SPLITTER)) {
         $this->addError('name', Yii::t('ProductModule', self::ERROR_NAME_FORMAT));
     }
     $id = 0;
     if (!$this->isNewRecord) {
         $id = $this->id;
     }
     if (empty($this->parent_id)) {
         $isModuleExisted = ProductModule::model()->exists('id<> :id and product_id=:product_id and parent_id is null and name=:name', array(':id' => $id, ':name' => $this->name, ':product_id' => $this->product_id));
     } else {
         $isModuleExisted = ProductModule::model()->exists('id<> :id and product_id=:product_id and parent_id=:parent_id and name=:name', array(':id' => $id, ':parent_id' => $this->parent_id, ':name' => $this->name, ':product_id' => $this->product_id));
     }
     if ($isModuleExisted) {
         $this->addError('name', Yii::t('ProductModule', self::ERROR_NAME_EXISTED));
     }
 }
示例#10
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public static function loadModel($id)
 {
     $model = ProductModule::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     } else {
         $model->owner_name = CommonService::getUserRealName($model->owner);
         $model->product_name = $model->product->name;
     }
     return $model;
 }