Esempio n. 1
0
 public static function editGroup($params)
 {
     $resultInfo = array();
     $actionType = BugfreeModel::ACTION_OPEN;
     $oldRecordAttributs = array();
     if (empty($params['id'])) {
         $group = new UserGroup();
     } else {
         $group = self::loadModel($params['id']);
         $oldRecordAttributs = $group->attributes;
         if (!empty($group->group_user)) {
             $oldRecordAttributs['group_user'] = join(',', $group->group_user);
         }
         $oldRecordAttributs['group_manager'] = $group->group_manager;
         $actionType = BugfreeModel::ACTION_EDIT;
     }
     if (!self::isGroupEditable($group->id)) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail']['id'] = Yii::t('Common', 'Required URL not found or permission denied.');
         return $resultInfo;
     }
     $group->attributes = $params;
     if (!$group->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $group->getErrors();
     } else {
         Yii::app()->db->createCommand()->delete('{{map_user_group}}', 'user_group_id=:groupId', array(':groupId' => $group->id));
         $managerNameArr = CommonService::splitStringToArray(',', $params['group_manager']);
         $managerIdArr = array();
         foreach ($managerNameArr as $mangerName) {
             $managerInfo = TestUserService::getUserInfoByRealname($mangerName);
             if ($managerInfo !== null) {
                 $managerIdArr[] = $managerInfo['id'];
             }
         }
         $allUserId = array_unique(array_merge($params['group_user'], $managerIdArr));
         foreach ($allUserId as $userId) {
             $mapUserGroup = new MapUserGroup();
             $mapUserGroup->test_user_id = $userId;
             $mapUserGroup->user_group_id = $group->id;
             if (in_array($userId, $managerIdArr)) {
                 $mapUserGroup->is_admin = CommonService::$TrueFalseStatus['TRUE'];
             } else {
                 $mapUserGroup->is_admin = CommonService::$TrueFalseStatus['FALSE'];
             }
             $mapUserGroup->save();
         }
         $newRecord = self::loadModel($group->id);
         if (!empty($newRecord->group_user)) {
             $newRecord->group_user = join(',', $newRecord->group_user);
         }
         $addActionResult = AdminActionService::addActionNotes('user_group', $actionType, $newRecord, $oldRecordAttributs);
         $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         $resultInfo['detail'] = array('id' => $group->id);
     }
     return $resultInfo;
 }
Esempio n. 2
0
 /**
  * find user by realname
  *
  * @param string $realName
  * @return array find user info array
  */
 public function findUser($realName)
 {
     $code = API::ERROR_NONE;
     $info = '';
     if (empty($realName)) {
         $code = API::ERROR_USER_EMPTY;
         $info = Yii::t('API', 'user realname empty error info');
     } else {
         $userInfo = TestUserService::getUserInfoByRealname($realName);
         if ($userInfo != null) {
             $info['userinfo'] = $userInfo->attributes;
             unset($info['userinfo']['password']);
         } else {
             $info['userinfo'] = '';
         }
     }
     return array($code, $info);
 }
Esempio n. 3
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;
 }
Esempio n. 4
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;
 }