Exemplo n.º 1
0
 protected function beforeValidate()
 {
     if ($this->isNewRecord) {
         if (empty($this->related_case_id)) {
             $this->addError('related_case_id', Yii::t('ResultInfo', 'related_case_id can not be blank'));
         } else {
             $caseModel = CaseInfo::model()->findByPk($this->related_case_id);
             if ($caseModel == null) {
                 $this->addError('related_case_id', Yii::t('Common', 'Requested object does not exist'));
             } else {
                 $this->title = $caseModel->title;
                 $this->product_id = $caseModel->product_id;
                 $this->productmodule_id = $caseModel->productmodule_id;
             }
         }
     }
     return parent::beforeValidate();
 }
Exemplo n.º 2
0
 /**
  * Save info page
  *
  * @author                                    youzhao.zxw<*****@*****.**>
  * @param   String          $infoType         bug,case or result
  * @param   String          $actionType       edit action type
  * @param   array           $basicInfo        basic info array
  * @param   array           $customInfo       custom information
  * @param   array           $attachmentFile   attachment information
  * @param   array           $requestIdArr     user requested id info
  * @return  array                             save result info
  */
 public static function saveInfo($infoType, $actionType, $basicInfo, $customInfo, $attachmentFile, $requestIdArr = array())
 {
     $mixedInfo = array('basic' => $basicInfo, 'custom' => $customInfo, 'attachment_file' => $attachmentFile);
     $result = self::editInfo($infoType, $actionType, $mixedInfo);
     if (CommonService::$ApiResult['SUCCESS'] == $result['status']) {
         if (isset($requestIdArr['result_id'])) {
             $resultModel = ResultInfo::model()->findByPk($requestIdArr['result_id']);
             $resultModel->assign_to_name = CommonService::getUserRealName($resultModel->assign_to);
             if (!empty($resultModel->related_bug)) {
                 $resultModel->related_bug = $resultModel->related_bug . ',' . $result['detail']['id'];
             } else {
                 $resultModel->related_bug = $result['detail']['id'];
             }
             $resultModel->save();
         } elseif (isset($requestIdArr['case_id'])) {
             $caseModel = CaseInfo::model()->findByPk($requestIdArr['case_id']);
             $oldRecordAttributs = array();
             $oldRecordAttributs['basic'] = $caseModel->attributes;
             $oldRecordAttributs['custom'] = array();
             $caseModel->assign_to_name = CommonService::getUserRealName($caseModel->assign_to);
             if (!empty($caseModel->related_result)) {
                 $caseModel->related_result = $caseModel->related_result . ',' . $result['detail']['id'];
             } else {
                 $caseModel->related_result = $result['detail']['id'];
             }
             $caseModel->save();
             if (isset($_GET['step_run']) && 1 == $_GET['step_run']) {
                 $addActionResult = self::addActionNotes(Info::TYPE_CASE, CaseInfo::ACTION_STEP_RUN, $caseModel, $oldRecordAttributs);
             } else {
                 $addActionResult = self::addActionNotes(Info::TYPE_CASE, CaseInfo::ACTION_RUN, $caseModel, $oldRecordAttributs);
             }
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Exemplo n.º 4
0
 /**
  * import sheet data to bugfree
  *
  * @param mixed $sheet file or string
  * @param string $infoType
  */
 public function import($sheet, $productId, $infoType, $productModuleId)
 {
     $sheetConv = new SheetConv();
     $data = $sheetConv->xml2array($sheet);
     $results = array();
     // sheet index
     foreach ($data as $sidx => $items) {
         $sheetResult = array();
         // item index
         foreach ($items as $iidx => $item) {
             // hard code for product_id
             $basicInfo = array('product_id' => $productId, 'productmodule_id' => $productModuleId);
             $customInfo = array();
             $isEmpty = true;
             foreach ($item as $key => $val) {
                 unset($item[$key]);
                 list($field, $isBasic) = $this->fieldConv($key, $productId, $infoType);
                 if ($field) {
                     if ($isBasic) {
                         $basicInfo[$field] = $val;
                     } else {
                         $customInfo[$field] = $val;
                     }
                 }
                 if ('' != $val) {
                     $isEmpty = false;
                 }
             }
             if (!$isEmpty) {
                 $action = Info::ACTION_IMPORT;
                 if (isset($basicInfo['id']) && '' != trim($basicInfo['id'])) {
                     if (Info::TYPE_BUG == $infoType) {
                         $sheetResult[] = array('status' => CommonService::$ApiResult['FAIL'], 'detail' => array(Yii::t('Common', 'can not update bug by import')));
                         continue;
                     } else {
                         $existedCaseInfo = CaseInfo::model()->findByPk((int) $basicInfo['id']);
                         $resultInfo = array();
                         if (empty($existedCaseInfo)) {
                             $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
                             $resultInfo['detail']['id'] = '[id:' . $basicInfo['id'] . ']' . Yii::t('Common', 'Requested object does not exist');
                             $sheetResult[] = $resultInfo;
                             continue;
                         } else {
                             $basicInfo['action_note'] = '';
                             //import action_note only when doing new action
                             if ($productId != $existedCaseInfo['product_id']) {
                                 $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
                                 $resultInfo['detail']['id'] = Yii::t('Common', 'product is different');
                                 $sheetResult[] = $resultInfo;
                                 continue;
                             }
                         }
                     }
                 }
                 $basicInfo = $this->basicInfoConv($basicInfo, $infoType);
                 $sheetResult[] = InfoService::saveInfo($infoType, $action, $basicInfo, $customInfo, array(), array());
             }
         }
         $results[$sidx] = $sheetResult;
     }
     return $this->getResultMsg($results);
 }
Exemplo n.º 5
0
 public function relatedCaseValidator($attribute, $params)
 {
     if (isset($this->related_case)) {
         $this->related_case = $this->handleSpliter($this->related_case);
         $relatedBugArr = CommonService::splitStringToArray(',', $this->related_case);
         foreach ($relatedBugArr as $caseIdTmp) {
             $infoObj = CaseInfo::model()->findByPk($caseIdTmp);
             if ($infoObj == null || $infoObj->id != $caseIdTmp) {
                 $this->addError('related_case', 'Case ID[' . $caseIdTmp . ']' . Yii::t('Common', 'is not existed'));
             } elseif (!Info::isProductAccessable($infoObj->product_id)) {
                 $this->addError('related_case', 'Case ID[' . $caseIdTmp . ']' . Yii::t('Common', 'No access right'));
             }
         }
     }
 }