public static function getSearchableField($productId) { $searchAbleArr = self::getBasicSearchFieldConfig($productId); if (!empty($productId)) { $searchAbleArr['solution'] = array('label' => BugInfo::model()->getAttributeLabel('solution'), 'type' => Info::$InputType['option'], 'isBasic' => true, 'value' => InfoService::getBugSolutionOptions($productId)); $customSearchAbleFieldArr = ProductService::getSearchableCostomField('bug', $productId); $searchAbleArr = array_merge($searchAbleArr, $customSearchAbleFieldArr); } return $searchAbleArr; }
/** * This is save info function, use it whatever saving or updating * * @param string $lowerItem * @param array $fields * @param array $systemFields * @param string $actionType * @return array */ public function saveInfo($lowerItem, $fields, $systemFields, $actionType, $compatible = false) { $item = ucfirst($lowerItem); $modelName = $item . 'InfoView'; $model = new $modelName(); $basicInfoFields = array_keys($model->attributes); $basicInfoFields[] = 'action_note'; $basicInfo = array(); $customInfo = array(); $isNeedBBCodeTransfer = true; if (isset($fields['no_bbcode_transfer']) && !empty($fields['no_bbcode_transfer'])) { $isNeedBBCodeTransfer = false; } foreach ($fields as $key => $field) { if (in_array($key, $systemFields)) { continue; } if ($compatible) { if ('AssignedTo' == $key || 'ScriptedBy' == $key) { $field = $this->getRealNameByName($field); } else { if ('MailTo' == $key) { $field = $this->getRealNamesByMailTo($field); } } $key = $this->fieldOld2New($key, $lowerItem); } if ($isNeedBBCodeTransfer && in_array($key, array('action_note', 'repeat_step', 'case_step', 'result_step'))) { $field = BBCode::bbcode2html($field); } if ('no_bbcode_transfer' != $key && !in_array($key, $basicInfoFields)) { $customInfo[$key] = $field; continue; } $basicInfo[$key] = $field; } if (Info::ACTION_OPEN == $actionType && isset($basicInfo['id'])) { unset($basicInfo['id']); } if (Info::ACTION_OPEN_EDIT == $actionType && 'bug' == $lowerItem && isset($basicInfo['id'])) { $bug = BugInfo::model()->findByPk($basicInfo['id']); if (!isset($basicInfo['bug_status'])) { $basicInfo['bug_status'] = $bug->bug_status; } if (null !== $bug) { switch ($basicInfo['bug_status']) { case BugInfo::STATUS_ACTIVE: if (BugInfo::STATUS_ACTIVE !== $bug->bug_status) { $actionType = BugInfo::ACTION_ACTIVATE; } else { $actionType = BugInfo::ACTION_OPEN_EDIT; } break; case BugInfo::STATUS_RESOLVED: if (BugInfo::STATUS_RESOLVED !== $bug->bug_status) { $actionType = BugInfo::ACTION_RESOLVE; } else { $actionType = BugInfo::ACTION_RESOLVE_EDIT; } break; case BugInfo::STATUS_CLOSED: if (BugInfo::STATUS_CLOSED !== $bug->bug_status) { $actionType = BugInfo::ACTION_CLOSE; } else { $actionType = BugInfo::ACTION_CLOSE_EDIT; } break; default: break; } } } $code = API::ERROR_NONE; $attachmentFile = CUploadedFile::getInstancesByName('attachment_file'); $result = InfoService::saveInfo($lowerItem, $actionType, $basicInfo, $customInfo, $attachmentFile); $info = $result['detail']; if (CommonService::$ApiResult['FAIL'] === $result['status']) { $code = API::ERROR_SAVE_INFO; } return array($code, $info); }
/** * 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); }
public function relatedBugValidator($attribute, $params) { if (isset($this->related_bug)) { $this->related_bug = $this->handleSpliter($this->related_bug); $relatedBugArr = CommonService::splitStringToArray(',', $this->related_bug); foreach ($relatedBugArr as $bugIdTmp) { $infoObj = BugInfo::model()->findByPk($bugIdTmp); if ($infoObj == null || $infoObj->id != $bugIdTmp) { $this->addError('related_bug', 'Bug ID[' . $bugIdTmp . ']' . Yii::t('Common', 'is not existed')); } elseif (!Info::isProductAccessable($infoObj->product_id)) { $this->addError('related_bug', 'Bug ID[' . $bugIdTmp . ']' . Yii::t('Common', 'No access right')); } } } }
public function duplicateIdValidator($attribute, $params) { if (self::DUPLICATE_SOLUTION == $this->solution) { $duplicatedIdError = $this->getError('duplicate_id'); if (empty($duplicatedIdError)) { if (empty($this->duplicate_id)) { $this->addError('duplicate_id', Yii::t('BugInfo', self::ERROR_DUPLICATE_ID)); } else { $this->duplicate_id = $this->handleSpliter($this->duplicate_id); $duplicatedIdArr = CommonService::splitStringToArray(',', $this->duplicate_id); foreach ($duplicatedIdArr as $dupId) { if ($dupId != ceil($dupId)) { $this->addError('duplicate_id', 'Duplicate ID[' . $dupId . ']' . Yii::t('BugInfo', self::ERROR_DUPLICATE_ID)); } else { $infoObj = BugInfo::model()->findByPk($dupId); if ($infoObj == null || $infoObj->id != $dupId) { $this->addError('duplicate_id', 'Duplicate ID[' . $dupId . ']' . Yii::t('BugInfo', self::ERROR_DUPLICATE_ID)); } elseif (!Info::isProductAccessable($infoObj->product_id)) { $this->addError('duplicate_id', 'Duplicate ID[' . $dupId . ']' . Yii::t('Common', 'No access right')); } } } } } } else { $this->duplicate_id = null; } }