コード例 #1
0
ファイル: API.php プロジェクト: mjrao/BugFree
 /**
  * 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);
 }
コード例 #2
0
ファイル: ImportService.php プロジェクト: riccoyu/BugFree
 /**
  * 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);
 }