Exemplo n.º 1
0
 /**
  * get query
  * 
  * @param integer $queryId
  * @param boolean $compatible
  * @return array 
  */
 public function getQuery($queryId, $page = 1, $size = 100, $compatible = false)
 {
     $code = API::ERROR_NONE;
     $info = '';
     if (empty($queryId)) {
         $code = API::ERROR_QUERY_EMPTY;
         $info = Yii::t('API', 'query id empty error info');
     }
     $result = UserQueryService::getQueryConditionById($queryId);
     if (CommonService::$ApiResult['FAIL'] == $result['status']) {
         $code = API::ERROR_QUERY;
         $info = $result['detail'];
     } else {
         $savedSearchCondition = $result['detail'];
         $result = ExportService::getExportData($savedSearchCondition['query_type'], $savedSearchCondition['search_condition'], $savedSearchCondition['product_id'], null, null, null, $size, $page);
         $detail = $result['detail'];
         if (CommonService::$ApiResult['FAIL'] == $result['status']) {
             $code = API::ERROR_QUERY;
             $info = $detail;
         } else {
             $lowerItem = strtolower($savedSearchCondition['query_type']);
             $itemList = ucfirst($lowerItem) . 'List';
             $idList = ucfirst($lowerItem) . 'IDs';
             $list = array();
             foreach ($detail as $val) {
                 $id = $val['id'];
                 if ($compatible) {
                     foreach ($val as $key => $field) {
                         unset($val[$key]);
                         $key = $this->fieldNew2Old($key, $lowerItem);
                         $val[$key] = $field;
                     }
                 }
                 $list[$id] = $val;
             }
             $info[$itemList] = $list;
             $info[$idList] = join(',', array_keys($list));
             $info['page'] = $page;
             $info['size'] = $size;
             $info['type'] = $lowerItem;
         }
     }
     return array($code, $info);
 }
Exemplo n.º 2
0
 public function actionIndex()
 {
     $this->layout = '//layouts/index';
     $expandClass = $this->getExpandClassName();
     $infoType = $this->getInfoType();
     $productId = $this->getProductId($infoType);
     $accessProductIdNameArr = Yii::app()->user->getState('visit_product_list');
     $productName = $accessProductIdNameArr[$productId];
     $defaultShowFieldArr = SearchService::getDefaultShowFieldArr($infoType);
     $showFieldArr = $this->getShowFieldArr($defaultShowFieldArr, $infoType, $productId);
     $queryTitle = $this->getQueryTitle($productId, $infoType);
     $productModuleId = $this->getModuleId($productId, $infoType);
     $searchRowArr = InfoService::getBlankSearchRowArr($productName, $productModuleId, $infoType);
     $searchFieldConfig = SearchService::getSearchableFields($infoType, $productId);
     $defaultSelectFieldOptionStr = SearchService::getSelectFieldsOption($searchFieldConfig, $defaultShowFieldArr);
     $defaultShowFieldOptionStr = SearchService::getShowFieldsOption($searchFieldConfig, $defaultShowFieldArr);
     $templateStr = InfoService::getTemplateStr($productId, $infoType, Yii::app()->user->id);
     $leftMenu = UserQueryService::getQueryLinkStr($productId, $infoType, Yii::app()->user->id);
     //not request from post query, save query and reset query
     $filterSql = '';
     $filterColumn = '';
     if (!empty($_POST['queryaction'])) {
         Yii::app()->user->setState($productId . '_' . $infoType . '_filterSql', null);
         Yii::app()->user->setState($productId . '_' . $infoType . '_filterColumn', null);
         if (!empty($_POST['reset'])) {
             Yii::app()->user->setState($productId . '_' . $infoType . '_showField', null);
             Yii::app()->user->setState($productId . '_' . $infoType . '_search', null);
         } else {
             if (!empty($_POST['saveQuery'])) {
                 $result = UserQueryService::editUserQuery($queryTitle, $productId, $infoType, $_POST[Info::QUERY_GROUP_NAME]);
                 if (CommonService::$ApiResult['FAIL'] == $result['status']) {
                     CommonService::jsAlert(Yii::t('Common', 'save query fail'));
                 }
                 CommonService::testRefreshSelf();
             }
             if (isset($_POST[Info::QUERY_GROUP_NAME])) {
                 $searchCondition = $_POST[Info::QUERY_GROUP_NAME];
                 $searchRowArr = SearchService::getSearchConditionArr($searchCondition);
             }
         }
     } else {
         if (isset($_GET['query_id'])) {
             $searchRowArr = $this->getSavedSearchRow($productId, $infoType, $_GET['query_id']);
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterSql', null);
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterColumn', null);
             $productModuleId = $this->getSavedQueryModuleId($searchRowArr, $productId, $infoType);
         } else {
             $sessionSearchRowArr = Yii::app()->user->getState($productId . '_' . $infoType . '_search');
             if ($sessionSearchRowArr !== null) {
                 $searchRowArr = $sessionSearchRowArr;
             }
         }
         if (!empty($_GET['filter'])) {
             $filterArr = CommonService::splitStringToArray('|', $_GET['filter']);
             if (Info::$InputType['date'] == $searchFieldConfig[$filterArr[0]]['type']) {
                 $filterSql = $filterArr[0] . " like '" . addslashes($filterArr[1]) . "%'";
             } else {
                 $filterSql = $filterArr[0] . " = '" . addslashes($filterArr[1]) . "'";
             }
             $filterColumn = $filterArr[0];
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterSql', $filterSql);
             Yii::app()->user->setState($productId . '_' . $infoType . '_filterColumn', $filterArr[0]);
         } else {
             $sessionFilterColumn = Yii::app()->user->getState($productId . '_' . $infoType . '_filterColumn');
             if ($sessionFilterColumn !== null) {
                 $filterSql = Yii::app()->user->getState($productId . '_' . $infoType . '_filterSql');
                 $filterColumn = $sessionFilterColumn;
             }
         }
     }
     if (isset($_GET['productmodule_id'])) {
         $searchRowArr[0]['leftParenthesesName'] = '';
         $searchRowArr[0]['field'] = 'module_name';
         $searchRowArr[0]['rightParenthesesName'] = '';
         $searchRowArr[0]['operator'] = 'UNDER';
         $searchRowArr[0]['andor'] = 'And';
         $searchRowArr[0]['value'] = '';
         $selectedModuleInfo = ProductModule::model()->findByPk($_GET['productmodule_id']);
         if ($selectedModuleInfo !== null) {
             $searchRowArr[0]['value'] = $productName . '/' . $selectedModuleInfo->full_path_name;
         } else {
             $searchRowArr[0]['value'] = $productName;
         }
     }
     $searchRowArr = $this->setSpecialModuleCondiftion($searchRowArr, $productName);
     Yii::app()->user->setState($productId . '_' . $infoType . '_search', $searchRowArr);
     $getSqlResult = SqlService::baseGetGroupQueryStr($searchFieldConfig, $infoType, $searchRowArr);
     if (CommonService::$ApiResult['FAIL'] == $getSqlResult['status']) {
         $whereStr = ' 1<>1 ';
     } else {
         $whereStr = $getSqlResult['detail'];
     }
     if ('' != $filterSql) {
         $whereStr .= ' and ' . $filterSql;
     }
     $selectFieldOptionStr = SearchService::getSelectFieldsOption($searchFieldConfig, $showFieldArr);
     $showFieldOptionStr = SearchService::getShowFieldsOption($searchFieldConfig, $showFieldArr);
     $defaultSelectFieldOptionStr = addslashes($defaultSelectFieldOptionStr);
     $defaultSelectFieldOptionStr = str_replace(array("\r\n", "\r", "\n"), "", $defaultSelectFieldOptionStr);
     $defaultShowFieldOptionStr = addslashes($defaultShowFieldOptionStr);
     $defaultShowFieldOptionStr = str_replace(array("\r\n", "\r", "\n"), "", $defaultShowFieldOptionStr);
     $jsValueStr = SearchService::getJsValueOption($this, $searchFieldConfig);
     $jsOperatorStr = SearchService::getJsOperatorOption($searchFieldConfig);
     $searchConditionHtml = SearchService::getSearchHtml($infoType, $searchFieldConfig, $searchRowArr);
     $searchConditionHtmlTemplate = SearchService::getSearchConditionRowHtml(Info::TEMPLATE_NUMBER, $searchFieldConfig, InfoService::getTemplateSearchRowArr());
     $searchConditionHtmlTemplate = addslashes($searchConditionHtmlTemplate);
     $searchConditionHtmlTemplate = str_replace(array("\r\n", "\r", "\n"), "", $searchConditionHtmlTemplate);
     $showType = Yii::app()->user->getState($productId . '_' . $infoType . '_showtype');
     if (empty($showType)) {
         $showType = Info::SHOW_TYPE_GRID;
     }
     $relatedFields = $this->getRelatedFields($searchRowArr, $showFieldArr);
     $isAllBasicField = SearchService::isAllBasicField(SearchService::getBasicFieldArr($infoType), $relatedFields);
     $renderArr = array('expandClass' => $expandClass, 'productId' => $productId, 'productModuleId' => $productModuleId, 'infoType' => $infoType, 'searchFieldConfig' => $searchFieldConfig, 'selectFieldOptionStr' => $selectFieldOptionStr, 'showFieldOptionStr' => $showFieldOptionStr, 'defaultSelectFieldOptionStr' => $defaultSelectFieldOptionStr, 'defaultShowFieldOptionStr' => $defaultShowFieldOptionStr, 'searchConditionHtml' => $searchConditionHtml, 'searchConditionHtmlTemplate' => $searchConditionHtmlTemplate, 'queryTitle' => $queryTitle, 'jsValueStr' => $jsValueStr, 'jsOperatorStr' => $jsOperatorStr, 'leftMenu' => $leftMenu, 'templateStr' => $templateStr, 'showType' => $showType, 'showMyQueryDiv' => Yii::app()->user->getState('my_query_div'));
     if ($showType == Info::SHOW_TYPE_GRID) {
         $renderArr = array_merge($renderArr, $this->getGridShowContent($searchFieldConfig, $showFieldArr, $infoType, $productId, $filterColumn, $whereStr, $isAllBasicField));
         $renderArr['rowCssClassExpressionStr'] = InfoService::getRowCssClassExpressionStr($infoType);
     }
     $this->render('index', $renderArr);
 }
Exemplo n.º 3
0
 /**
  * check if show field is legal
  *
  * @author                                  youzhao.zxw<*****@*****.**>
  * @param   int         $queryId            query id
  * @param   array       $showFieldArr       show field array
  * @param   array       $orderArr           order array
  * @param   string      $filterSql          filter sql
  * @param   int         $pageSize           page size
  * @param   int         $currentPageSize    current page size
  * @return  array                           export date result
  */
 public static function getExportDataByQueryId($queryId, $showFieldArr = null, $orderArr = null, $filterSql = null, $pageSize = null, $currentPage = null)
 {
     $resultInfo = UserQueryService::getQueryConditionById($queryId);
     if (CommonService::$ApiResult['FAIL'] == $resultInfo['status']) {
         return $resultInfo;
     }
     $savedSearchCondition = $resultInfo['detail'];
     return self::getExportData($savedSearchCondition['query_type'], $savedSearchCondition['search_condition'], $savedSearchCondition['product_id'], $showFieldArr, $orderArr, $filterSql, $pageSize, $currentPage);
 }