Beispiel #1
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;
 }
Beispiel #2
0
 /**
  * Get query string with one field
  *
  * @author                          Yupeng Lee<*****@*****.**>
  * @param  string  $fieldName       FieldName
  * @param  string  $operatorName    =,<,>,<= eg.
  * @param  string  $fieldValue      FieldValue
  * @return string                   Query string for SQL
  */
 private static function baseGetFieldQueryStr($searchFieldConfig, $type, $fieldName, $operatorName, $fieldValue)
 {
     $basicTableName = '{{' . $type . 'view}}';
     $fieldValue = trim($fieldValue);
     $fieldValue = addslashes($fieldValue);
     //handle search value %,_
     if ($operatorName == 'LIKE' || $operatorName == 'NOT LIKE') {
         $fieldValue = str_replace('%', '\\%', $fieldValue);
         $fieldValue = str_replace('_', '\\_', $fieldValue);
     }
     $queryStr = '';
     if ($fieldValue == '') {
         return self::handleEmptyQuery($searchFieldConfig, $basicTableName, $fieldName, $operatorName, $fieldValue);
     } elseif (Info::MARK == $fieldName) {
         $inOrNotIn = ' not in ';
         if ('1' == $fieldValue) {
             $inOrNotIn = ' in ';
         }
         return $basicTableName . '.id ' . $inOrNotIn . ' (select info_id from {{map_user_' . $type . '}} where test_user_id=' . Yii::app()->user->id . ')';
     } elseif ('delete_flag' == $fieldName) {
         $fieldValue = CommonService::getTrueFalseValue($fieldValue);
     }
     //basic search field's name should be transfer to user id
     $fieldType = $searchFieldConfig[$fieldName]['type'];
     if (Info::$InputType['date'] == $fieldType) {
         //date related search
         if (preg_match('/^-?[1-9]\\d*$|^0$/', $fieldValue)) {
             //如果输入为整数,则进行日期的换算
             $fieldValue = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") + $fieldValue, date("Y")));
         }
     } elseif (Info::$InputType['multipeople'] == $fieldType && true == $searchFieldConfig[$fieldName]['isBasic']) {
         $userNameArr = CommonService::splitStringToArray(',', $fieldValue);
         $userIdArr = array();
         foreach ($userNameArr as $userName) {
             $userInfo = TestUserService::getUserInfoByRealname($userName);
             if (empty($userInfo)) {
                 $userIdArr[] = '-99999';
             } else {
                 $userIdArr[] = $userInfo['id'];
             }
         }
         $fieldValue = join(',', $userIdArr);
     }
     if ($operatorName == 'LIKE') {
         $queryStr = "LIKE '%{$fieldValue}%' ";
     } elseif ($operatorName == 'NOT LIKE') {
         $queryStr = "NOT LIKE '%{$fieldValue}%' ";
     } elseif ($operatorName == 'UNDER') {
         $queryStr = "LIKE '{$fieldValue}%' ";
     } elseif ($operatorName == '!=') {
         if (Info::$InputType['date'] == $fieldType) {
             $queryStr = "NOT " . self::sysStrToDateSql($fieldValue);
         } else {
             $queryStr = "<> '" . $fieldValue . "' ";
         }
     } elseif ($operatorName == '=') {
         if (Info::$InputType['date'] == $fieldType) {
             $queryStr = self::sysStrToDateSql($fieldValue);
         } elseif (Info::$InputType['multipeople'] == $fieldType) {
             $queryStr = "LIKE '%" . $fieldValue . "%' ";
         } else {
             $queryStr = $operatorName . " '{$fieldValue}' ";
         }
     } elseif ($operatorName == 'IN') {
         $fieldValueArr = CommonService::splitStringToArray(',', $fieldValue);
         $inValueStr = '';
         foreach ($fieldValueArr as $valueTmp) {
             if ('' == $inValueStr) {
                 $inValueStr = '"' . $valueTmp . '"';
             } else {
                 $inValueStr .= ',"' . $valueTmp . '"';
             }
         }
         $queryStr = "IN ({$inValueStr}) ";
     } else {
         if (($operatorName == '>' || $operatorName == '<=') && Info::$InputType['date'] == $fieldType) {
             $dateTimeArray = explode(" ", self::sysStrToDateSql($fieldValue));
             $fieldValue = $dateTimeArray[4] . ' ' . $dateTimeArray[5];
             $queryStr = $operatorName . " {$fieldValue} ";
         } elseif (($operatorName == '>=' || $operatorName == '<') && Info::$InputType['date'] == $fieldType) {
             $dateTimeArray = explode(" ", self::sysStrToDateSql($fieldValue));
             $fieldValue = $dateTimeArray[1] . ' ' . $dateTimeArray[2];
             $queryStr = $operatorName . " {$fieldValue} ";
         } else {
             $queryStr = $operatorName . " '{$fieldValue}' ";
         }
     }
     if ('' != $queryStr) {
         if (true == $searchFieldConfig[$fieldName]['isBasic']) {
             $fieldName = $basicTableName . '.' . $fieldName;
         }
         if ($operatorName == 'UNDER') {
             $likeFieldValue = str_replace('%', '\\%', $fieldValue);
             $likeFieldValue = str_replace('_', '\\_', $likeFieldValue);
             $queryStr = '(' . $fieldName . " LIKE '{$likeFieldValue}" . ProductModule::MODULE_SPLITTER . "%' or " . $fieldName . " = '{$fieldValue}')";
         } else {
             $queryStr = $fieldName . ' ' . $queryStr;
         }
     }
     if ($operatorName == '!=') {
         $queryStr = '(' . $queryStr . ' or ' . $fieldName . ' is null or ' . $fieldName . ' ="")';
     }
     return $queryStr;
 }