/** * get reports * * @param string $infoType * @param integer $productId * @param string $where * @param array $selected * @return array */ public function getReports($infoType, $productId, $selected = array()) { $reports = array(); $productIds = Yii::app()->user->getState('visit_product_id'); $condition = 'product_id IN (' . join(',', $productIds) . ')'; if (isset($productId)) { $condition .= ' AND product_id = ' . $productId; } $searchRowArr = Yii::app()->user->getState($productId . '_' . $infoType . '_search'); if (null == $searchRowArr) { $searchRowArr = array(); } $searchFieldConfig = SearchService::getSearchableFields($infoType, $productId); $result = SqlService::baseGetGroupQueryStr($searchFieldConfig, $infoType, $searchRowArr); if (CommonService::$ApiResult['SUCCESS'] == $result['status']) { $condition .= ' AND ' . $result['detail']; } $reportDatas = $this->getReportData($infoType, $productId, $condition, $selected); foreach ($reportDatas as $key => $data) { $show = false; if (!empty($selected) && in_array($key, $selected)) { $show = true; } $reports[] = new Report($infoType, $productId, $data['type'], $condition, $data, $show); } return $reports; }
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); }
/** * check if show field is legal * * @author youzhao.zxw<*****@*****.**> * @param string $infoType bug,case or result * @param array $searchRowArr search condition * @param int $productId product 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 getExportData($infoType, $searchRowArr, $productId = null, $showFieldArr = null, $orderArr = null, $filterSql = null, $pageSize = null, $currentPage = null) { $resultInfo = array(); if (!empty($productId)) { $accessIdArr = Yii::app()->user->getState('visit_product_id'); if (!in_array($productId, $accessIdArr)) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = Yii::t('Product', 'No access right to this product'); return $resultInfo; } } $searchFieldConfig = SearchService::getSearchableFields($infoType, $productId); $checkSearchRowResult = self::checkSearchRowField($searchFieldConfig, $searchRowArr); if ('' != $checkSearchRowResult) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = $checkSearchRowResult; return $resultInfo; } if (!empty($showFieldArr)) { $showFieldCheckResult = self::checkShowField($searchFieldConfig, $showFieldArr); if ('' != $showFieldCheckResult) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = $showFieldCheckResult; return $resultInfo; } } $getSqlResult = SqlService::baseGetGroupQueryStr($searchFieldConfig, $infoType, $searchRowArr); if (CommonService::$ApiResult['FAIL'] == $getSqlResult['status']) { $resultInfo = $getSqlResult; return $resultInfo; } $whereStr = $getSqlResult['detail']; if (!empty($filterSql)) { $whereStr .= ' and ' . $filterSql; } if (empty($showFieldArr)) { $showFieldArr = array_keys($searchFieldConfig); $showFieldArr = array_diff($showFieldArr, array(Info::MARK)); } $allRelatedFieldArr = array(); foreach ($searchRowArr as $searchRowTmp) { $allRelatedFieldArr[] = $searchRowTmp['field']; } $isAllBasicField = SearchService::isAllBasicField(SearchService::getBasicFieldArr($infoType), array_merge($showFieldArr, $allRelatedFieldArr)); $sql = SqlService::getRawDataSql($searchFieldConfig, $infoType, $productId, $showFieldArr, $whereStr, $isAllBasicField); $totalNum = SqlService::getTotalFoundNum($infoType, $productId, $whereStr, $isAllBasicField); if (empty($pageSize)) { $pageSize = $totalNum; } if ($pageSize > 5000) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = 'items can not exceed 5000'; return $resultInfo; } if (!isset($currentPage)) { $currentPage = 1; } else { if (0 == $currentPage) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = 'page should start from 1'; return $resultInfo; } $maxPage = ceil($totalNum / $pageSize); if ($currentPage > $maxPage && 0 != $maxPage) { $resultInfo['status'] = CommonService::$ApiResult['FAIL']; $resultInfo['detail'] = 'current page [' . $currentPage . '] is greater than the max page [' . $maxPage . ']'; return $resultInfo; } } if (empty($orderArr)) { $orderArr = array('{{bug_info_view}}.id' => true); } $dataProvider = new CSqlDataProvider($sql, array('totalItemCount' => $totalNum, 'sort' => array('defaultOrder' => $orderArr, 'attributes' => array_keys($searchFieldConfig)), 'pagination' => array('pageSize' => $pageSize, 'currentPage' => $currentPage - 1))); $rawData = $dataProvider->getData(); $rawData = SqlService::handleRawData($rawData, $infoType, $searchFieldConfig, $showFieldArr, $productId); $rawData = self::getExportComment($infoType, $rawData, $productId); $resultInfo['status'] = CommonService::$ApiResult['SUCCESS']; $resultInfo['detail'] = $rawData; return $resultInfo; }