Exemplo n.º 1
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);
 }