Example #1
0
 /**
  * edit user query
  *
  * @author                                   youzhao.zxw<*****@*****.**>
  * @param   string       $title              user query title
  * @param   int          $productId          product id
  * @param   string       $type               bug,case or result
  * @param   array        $searchConditionArr search condition array
  * @return  array                            edit user query result information
  */
 public static function editUserQuery($title, $productId, $type, $searchConditionArr)
 {
     $resultInfo = array();
     $updateFlag = false;
     $title = trim($title);
     $userQuery = UserQuery::model()->findByAttributes(array('query_type' => $type, 'product_id' => $productId, 'created_by' => Yii::app()->user->id, 'title' => $title));
     if (false != $userQuery) {
         $updateFlag = true;
         $userQuery->updated_at = date(CommonService::DATE_FORMAT);
     } else {
         $userQuery = new UserQuery();
         $userQuery->created_by = Yii::app()->user->id;
         $userQuery->created_at = date(CommonService::DATE_FORMAT);
         $userQuery->updated_at = $userQuery->created_at;
         $userQuery->query_type = $type;
         $userQuery->product_id = $productId;
         $userQuery->title = $title;
     }
     $searchRowConditionArr = SearchService::getSearchConditionArr($searchConditionArr);
     $queryConditonArr = array();
     $keyArr = array('leftParenthesesName', 'field', 'operator', 'value', 'rightParenthesesName', 'andor');
     foreach ($searchRowConditionArr as $rowCondtion) {
         foreach ($rowCondtion as $key => $value) {
             $queryConditonArr[$key][] = $value;
         }
     }
     $userQuery->left_parentheses = serialize($queryConditonArr['leftParenthesesName']);
     $userQuery->fieldlist = serialize($queryConditonArr['field']);
     $userQuery->operatorlist = serialize($queryConditonArr['operator']);
     $userQuery->valuelist = serialize($queryConditonArr['value']);
     $userQuery->right_parentheses = serialize($queryConditonArr['rightParenthesesName']);
     $userQuery->andorlist = serialize($queryConditonArr['andor']);
     if ($userQuery->save()) {
         $resultInfo['status'] = CommonService::$ApiResult['SUCCESS'];
         if ($updateFlag) {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_UPDATE_SUCCESS));
         } else {
             $resultInfo['detail'] = array('id' => Yii::t('Common', self::TIP_CREATE_SUCCESS));
         }
     } else {
         $resultInfo['status'] = CommonService::$ApiResult['FAIL'];
         $resultInfo['detail'] = $userQuery->getErrors();
     }
     return $resultInfo;
 }