Exemple #1
0
 public function actionExport()
 {
     $infoType = $this->getInfoType();
     $productId = $this->getProductId($infoType);
     $fieldCookieKey = $productId . '_' . $infoType . '_showField';
     $cookieShowFieldStr = $this->getShowFieldCookie($fieldCookieKey);
     if (!empty($cookieShowFieldStr) && is_string($cookieShowFieldStr)) {
         $showFieldArr = CommonService::splitStringToArray(',', $cookieShowFieldStr);
     } else {
         $showFieldArr = SearchService::getDefaultShowFieldArr($infoType);
     }
     $searchRowArr = Yii::app()->user->getState($productId . '_' . $infoType . '_search');
     $filterSql = Yii::app()->user->getState($productId . '_' . $infoType . '_filterSql');
     $orderArr = Yii::app()->user->getState($productId . '_' . $infoType . '_sortArr');
     if (Info::TYPE_BUG == $infoType) {
         $showFieldArr[] = 'repeat_step';
     } else {
         if (Info::TYPE_CASE == $infoType) {
             $showFieldArr[] = 'case_step';
         } else {
             if (Info::TYPE_RESULT == $infoType) {
                 $showFieldArr[] = 'result_step';
             }
         }
     }
     if (!in_array('id', $showFieldArr)) {
         array_unshift($showFieldArr, 'id');
     }
     $exportDataResult = ExportService::getExportData($infoType, $searchRowArr, $productId, $showFieldArr, $orderArr, $filterSql);
     if (CommonService::$ApiResult['SUCCESS'] == $exportDataResult['status']) {
         $rawData = $exportDataResult['detail'];
     } else {
         throw new CHttpException(400, $exportDataResult['detail']);
     }
     $fileStoreUrl = Yii::app()->params->uploadPath . '/' . $infoType . 'list.xml';
     $file = fopen($fileStoreUrl, "w");
     $searchFieldConfig = SearchService::getSearchableFields($infoType, $productId);
     $searchFieldConfig['case_step'] = array('label' => Yii::t('CaseInfo', 'case_step'), 'isBasic' => true);
     $searchFieldConfig['result_step'] = array('label' => Yii::t('ResultInfo', 'result_step'), 'isBasic' => true);
     $searchFieldConfig['repeat_step'] = array('label' => Yii::t('BugInfo', 'repeat_step'), 'isBasic' => true);
     $searchFieldConfig['action_note'] = array('label' => Yii::t('Common', 'action_note'), 'isBasic' => false);
     $showFieldArr[] = 'action_note';
     $content = ExportService::exportXML($rawData, $showFieldArr, $searchFieldConfig);
     file_put_contents($fileStoreUrl, $content);
     header('Content-type: text/xml; charset=utf-8');
     header('Content-Disposition: attachment; filename=' . $infoType . 'list.xml');
     readfile($fileStoreUrl);
     //      exit; //enable this will not output log
 }
Exemple #2
0
 /**
  * query
  * 
  * @param string $xml
  * @param string $schema
  * @return array 
  */
 public function query($xml, $schema, $productId, $compatible = false)
 {
     $code = API::ERROR_NONE;
     $info = '';
     if (empty($xml)) {
         $code = API::ERROR_QUERY_EMPTY;
         $info = Yii::t('API', 'query empty error info');
     } else {
         Yii::app()->request->stripSlashes($xml);
         $xml = preg_replace("/>\\s+</", "><", $xml);
         libxml_use_internal_errors(true);
         $dom = new DOMDocument();
         $dom->loadXML($xml);
         if ($dom->schemaValidateSource($schema)) {
             $query = $dom->getElementsByTagName('query');
             $query = $query->item(0);
             $infoType = strtolower($query->getAttribute('table'));
             $showFieldArr = $query->getAttribute('select') ? explode(',', $query->getAttribute('select')) : null;
             $order = $query->getAttribute('order') ? $query->getAttribute('order') : null;
             $isAsc = $query->getAttribute('asc') ? $query->getAttribute('asc') : false;
             $orderArr = $order ? array($order => $isAsc) : null;
             $currentPage = $query->getAttribute('page') ? $query->getAttribute('page') : 1;
             $pageSize = $query->getAttribute('size') ? $query->getAttribute('size') : 100;
             $arr = array();
             $searchRowArr = $this->getSearchRowArr($query->firstChild, $arr, $infoType, $compatible);
             $result = ExportService::getExportData($infoType, $searchRowArr, $productId, $showFieldArr, $orderArr, null, $pageSize, $currentPage);
             $detail = $result['detail'];
             if (CommonService::$ApiResult['FAIL'] == $result['status']) {
                 $code = API::ERROR_QUERY;
                 $info = $detail;
             } else {
                 $list = array();
                 if ('count(*)' == $showFieldArr[0]) {
                     $list = $detail;
                 } else {
                     foreach ($detail as $val) {
                         $id = $val['id'];
                         if ($compatible) {
                             foreach ($val as $key => $field) {
                                 unset($val[$key]);
                                 $key = $this->fieldNew2Old($key, $infoType);
                                 $val[$key] = $field;
                             }
                         }
                         $list[$id] = $val;
                     }
                 }
                 $info['QueryList'] = $list;
                 $info['size'] = $pageSize;
                 $info['page'] = $currentPage;
             }
         } else {
             $code = API::ERROR_QUERY_EMPTY;
             $info = Yii::t('API', 'query xml invalid info');
         }
     }
     return array($code, $info);
 }