コード例 #1
0
ファイル: excel.php プロジェクト: k-kalashnikov/geekcon_new
 function groupingReportResultHtml(&$arParams, &$arResult, $level = 0, $arRowSet = array())
 {
     $strHtml = '';
     $total = array();
     $arViewColumns =& $arResult['viewColumns'];
     $arData =& $arResult['data'];
     // static variables
     static $arGroups = array();
     static $arColumns = array();
     static $nGroups = 0;
     static $nColumns = 0;
     static $arValueTypes = array();
     static $marginWidth = 20;
     // initialize static variables
     if ($level === 0) {
         foreach ($arViewColumns as $viewColumnIndex => $viewColumn) {
             if ($viewColumn['grouping']) {
                 $arGroups[$nGroups++] = $viewColumnIndex;
             } else {
                 $arColumns[$nColumns++] = $viewColumnIndex;
             }
             $arValueTypes[$viewColumnIndex] = getResultColumnDataType($viewColumn);
         }
     }
     $nRows = count($arRowSet);
     $bUseRowSet = $nRows > 0 ? true : false;
     if (!$bUseRowSet) {
         $nRows = count($arData);
     }
     if ($nGroups > 0) {
         // grouping table header
         if ($level === 0) {
             $bFirstGroup = true;
             $strHtml .= "\t" . '<table class="reports-grouping-table" cellpadding=2 cellspacing=0>' . PHP_EOL . "\t\t" . '<thead>' . PHP_EOL;
             foreach ($arGroups as $groupColumnIndex) {
                 $strHtml .= "\t\t\t" . '<tr class="reports-grouping-table-head-row">' . PHP_EOL . "\t\t\t\t" . '<td>' . htmlspecialcharsbx($arViewColumns[$groupColumnIndex]['humanTitle']) . '</td>' . PHP_EOL;
                 if ($bFirstGroup) {
                     $bFirstGroup = false;
                     foreach ($arColumns as $viewColumnIndex) {
                         $strHtml .= "\t\t\t\t" . '<td style="text-align: center;"';
                         if ($nGroups > 1) {
                             $strHtml .= ' rowspan="' . htmlspecialcharsbx($nGroups) . '"';
                         }
                         $strHtml .= ' class="report-grouping-sort-column"';
                         $strHtml .= ' colId="' . $viewColumnIndex . '" defaultSort="' . $arViewColumns[$viewColumnIndex]['defaultSort'] . '">' . htmlspecialcharsbx($arViewColumns[$viewColumnIndex]['humanTitle']) . '</td>' . PHP_EOL;
                     }
                 }
                 $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL;
             }
             $strHtml .= "\t\t" . '</thead>' . PHP_EOL;
         }
         if ($nRows > 0) {
             // table header separator
             if ($level === 0) {
                 $strHtml .= "\t\t" . '<tbody>' . PHP_EOL . "\t\t\t" . '<tr class="reports-grouping-table-row-separator"><td></td></tr>' . PHP_EOL;
             }
             // init total
             if ($nColumns > 0) {
                 foreach (array_keys($arColumns) as $columnIndex) {
                     $total[$columnIndex] = null;
                 }
             }
             if ($level < $nGroups) {
                 // fill group arrays
                 $arGroupValues = array();
                 $arGroupValuesIndexes = array();
                 $rowNumber = 0;
                 $groupDataType = $arValueTypes[$arGroups[$level]];
                 $dataIndex = null;
                 reset($arData);
                 while ($rowNumber++ < $nRows) {
                     // get index
                     if ($bUseRowSet) {
                         list(, $dataIndex) = each($arRowSet);
                     } else {
                         list($dataIndex, ) = each($arData);
                     }
                     // fill index and value of group
                     $arGroupValuesIndexes[] = $dataIndex;
                     $groupValue = $arData[$dataIndex][$arViewColumns[$arGroups[$level]]['resultName']];
                     if ($groupDataType === 'date' || $groupDataType === 'datetime') {
                         $groupValue = MakeTimeStamp($groupValue, CSite::GetDateFormat('SHORT'));
                     }
                     // magic glue
                     if (is_array($groupValue)) {
                         $groupValue = join(' / ', $groupValue);
                     }
                     $arGroupValues[] = $groupValue;
                 }
                 // determine sort options
                 $groupSortOption = SORT_STRING;
                 $groupSortDirection = SORT_ASC;
                 if (in_array($groupDataType, array('date', 'datetime', 'integer', 'float'))) {
                     $groupSortOption = SORT_NUMERIC;
                 }
                 if ($arGroups[$level] == $arResult['sort_id']) {
                     if ($arResult['sort_type'] != 'ASC') {
                         $groupSortDirection = SORT_DESC;
                     }
                 }
                 // sort group
                 array_multisort($arGroupValues, $groupSortOption, $groupSortDirection, $arGroupValuesIndexes, SORT_NUMERIC, SORT_ASC);
                 // recursive scan
                 $prev = null;
                 $newRowSet = array();
                 $nGroupValues = count($arGroupValues);
                 $nSubRows = 0;
                 for ($i = 0; $i < $nGroupValues; $i++) {
                     $cur = $arGroupValues[$i];
                     if ($i == 0) {
                         $prev = $cur;
                     }
                     $bLastValue = $nGroupValues - 1 == $i;
                     if ($cur != $prev || $bLastValue) {
                         $n = $bLastValue && $cur != $prev ? 2 : 1;
                         while ($n-- > 0) {
                             if ($bLastValue && $cur == $prev) {
                                 $newRowSet[] = $arGroupValuesIndexes[$i];
                             }
                             $arGroupingResult = groupingReportResultHtml($arParams, $arResult, $level + 1, $newRowSet);
                             $arSubTotal = $arGroupingResult['total'];
                             $strSubHtml = $arGroupingResult['html'];
                             unset($arGroupingResult);
                             $newRowSet = array();
                             if (!$bLastValue) {
                                 $newRowSet[] = $arGroupValuesIndexes[$i];
                             }
                             $prev = $cur;
                             // show row
                             $groupValueIndex = $bLastValue && $n === 0 ? $i : $i - 1;
                             $groupValueKey = $arViewColumns[$arGroups[$level]]['resultName'];
                             $groupValue = $arData[$arGroupValuesIndexes[$groupValueIndex]][$groupValueKey];
                             // magic glue
                             if (is_array($groupValue)) {
                                 $groupValue = join(' / ', $groupValue);
                             }
                             if ($level == $nGroups - 1) {
                                 $rowClass = ' reports-grouping-data-row';
                             } else {
                                 $rowClass = ' reports-grouping-group-row';
                             }
                             if (!empty($rowClass)) {
                                 $rowClass = ' class="' . ltrim($rowClass) . '"';
                             }
                             $margin = $level > 0 ? ' style="margin-left: ' . $level * $marginWidth . 'px;"' : '';
                             /*$rowClass .= ' style="mso-outline-level:'.($level+1).'"';*/
                             $strHtml .= "\t\t\t" . '<tr' . $rowClass . '>' . PHP_EOL . "\t\t\t\t" . '<td><div' . $margin . '>' . $groupValue . '</div></td>' . PHP_EOL;
                             foreach ($arSubTotal as $k => $subValue) {
                                 $cellStyle = '';
                                 if ($arResult['settings']['red_neg_vals'] === true) {
                                     if (is_numeric($subValue) && $subValue < 0) {
                                         $cellStyle .= ' color: red;';
                                     }
                                 }
                                 // cell align
                                 $colAlign = $arViewColumns[$arColumns[$k]]['align'];
                                 if ($colAlign === null) {
                                     if (CReport::isColumnPercentable($arViewColumns[$arColumns[$k]])) {
                                         $cellStyle .= ' text-align: right;';
                                     }
                                 } else {
                                     if ($colAlign === 'right') {
                                         $cellStyle .= ' text-align: right;';
                                     }
                                 }
                                 if (!empty($cellStyle)) {
                                     $cellStyle = ' style="' . ltrim($cellStyle) . '"';
                                 }
                                 $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal'];
                                 if ($bGroupingSubtotal || $level == $nGroups - 1) {
                                     $finalSubValue = $subValue;
                                     if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) {
                                         // format subtotal value
                                         $subValueKey = $arViewColumns[$arColumns[$k]]['resultName'];
                                         call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalSubValue, 'cInfo' => &$arViewColumns[$arColumns[$k]]));
                                     }
                                 } else {
                                     $finalSubValue = '&nbsp;';
                                 }
                                 $strHtml .= "\t\t\t\t" . '<td' . $cellStyle . '>' . $finalSubValue . '</td>' . PHP_EOL;
                             }
                             $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL;
                             $strHtml .= $strSubHtml;
                             // total += subtotal
                             if ($nColumns > 0) {
                                 foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                                     $columnDataType = $arValueTypes[$viewColumnIndex];
                                     if ($columnDataType === 'integer' || $columnDataType === 'float') {
                                         if (is_string($arSubTotal[$columnIndex])) {
                                             $arSubTotal[$columnIndex] = str_replace(' ', '', $arSubTotal[$columnIndex]);
                                         }
                                         $total[$columnIndex] += $arSubTotal[$columnIndex];
                                     }
                                 }
                                 $nSubRows++;
                             }
                         }
                         // while ($n-- > 0)
                     } else {
                         $newRowSet[] = $arGroupValuesIndexes[$i];
                     }
                 }
                 // calculate average values
                 if ($nSubRows > 1) {
                     foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                         if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') {
                             $total[$columnIndex] = $total[$columnIndex] / $nSubRows;
                         }
                     }
                 }
             } else {
                 if ($nColumns > 0) {
                     $rowNumber = 0;
                     while ($rowNumber++ < $nRows) {
                         // get index
                         if ($bUseRowSet) {
                             list(, $dataIndex) = each($arRowSet);
                         } else {
                             list($dataIndex, ) = each($arData);
                         }
                         // total += values
                         foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                             $columnDataType = $arValueTypes[$viewColumnIndex];
                             if ($nRows == 1) {
                                 $dataValueKey = $arViewColumns[$viewColumnIndex]['resultName'];
                                 $dataValue = $arData[$dataIndex][$dataValueKey];
                                 if ($columnDataType === 'float' && is_string($dataValue)) {
                                     $dataValue = str_replace(' ', '', $dataValue);
                                 }
                                 $total[$columnIndex] = $dataValue;
                             } else {
                                 if ($columnDataType === 'integer' || $columnDataType === 'float') {
                                     $dataValue = $arData[$dataIndex][$arViewColumns[$viewColumnIndex]['resultName']];
                                     if (is_string($dataValue)) {
                                         $dataValue = str_replace(' ', '', $dataValue);
                                     }
                                     $total[$columnIndex] += $dataValue;
                                 }
                             }
                         }
                     }
                     // calculate average values
                     if ($nRows > 1) {
                         foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                             if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') {
                                 $total[$columnIndex] = $total[$columnIndex] / $nRows;
                             }
                         }
                     }
                 }
             }
         }
         // show total
         if ($level === 0) {
             if (count($total) > 0) {
                 // show total check
                 $bShowTotal = false;
                 foreach ($total as $k => $v) {
                     if ($arViewColumns[$arColumns[$k]]['grouping_subtotal']) {
                         $bShowTotal = true;
                         break;
                     }
                 }
                 if ($bShowTotal) {
                     $strHtml .= "\t\t\t" . '<tr class="reports-grouping-table-row-separator"><td></td></tr>' . PHP_EOL;
                     $strHtml .= "\t\t\t" . '<tr class="reports-grouping-total-row">' . PHP_EOL . "\t\t\t\t" . '<td>' . htmlspecialcharsbx(GetMessage('REPORT_TOTAL')) . '</td>' . PHP_EOL;
                     foreach ($total as $k => $v) {
                         $cellStyle = '';
                         if ($arResult['settings']['red_neg_vals'] === true) {
                             if (is_numeric($v) && $v < 0) {
                                 $cellStyle .= ' color: red;';
                             }
                         }
                         // cell align
                         $colAlign = $arViewColumns[$arColumns[$k]]['align'];
                         if ($colAlign === null) {
                             if (CReport::isColumnPercentable($arViewColumns[$arColumns[$k]])) {
                                 $cellStyle = ' text-align: right;';
                             }
                         } else {
                             if ($colAlign === 'right') {
                                 $cellStyle = ' text-align: right;';
                             }
                         }
                         $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal'];
                         if ($bGroupingSubtotal) {
                             $finalTotalValue = $v;
                             if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) {
                                 // format subtotal value
                                 $subValueKey = $arViewColumns[$arColumns[$k]]['resultName'];
                                 call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalTotalValue, 'cInfo' => &$arViewColumns[$arColumns[$k]]));
                             }
                         } else {
                             $finalTotalValue = '&nbsp;';
                         }
                         if (!empty($cellStyle)) {
                             $cellStyle = ' class="' . ltrim($cellStyle) . '"';
                         }
                         $strHtml .= "\t\t\t\t" . '<td' . $cellStyle . '>' . $finalTotalValue . '</td>' . PHP_EOL;
                     }
                     $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL;
                 }
             }
             $strHtml .= "\t\t" . '</tbody>' . PHP_EOL . "\t" . '</table>' . PHP_EOL;
         }
     }
     return array('total' => $total, 'html' => $strHtml);
 }
コード例 #2
0
ファイル: template.php プロジェクト: mrdeadmouse/u136006
 function prepareChartData(&$arResult, &$arGroupingResult = null)
 {
     $nMaxValues = 200;
     // check
     $chartSettings = $arResult['settings']['chart'];
     if (!isset($chartSettings['x_column'])) {
         return null;
     }
     $xColumnIndex = $chartSettings['x_column'];
     if (!is_array($chartSettings['y_columns'])) {
         return null;
     }
     $yColumnsCount = count($chartSettings['y_columns']);
     if ($yColumnsCount === 0) {
         return null;
     }
     $chartTypeIds = array();
     foreach ($arResult['chartTypes'] as $chartTypeInfo) {
         $chartTypeIds[] = $chartTypeInfo['id'];
     }
     if (!is_set($chartSettings['type']) || empty($chartSettings['type']) || !in_array($chartSettings['type'], $chartTypeIds)) {
         return null;
     }
     $chartType = $chartSettings['type'];
     if ($chartType === 'pie') {
         $yColumnsCount = 1;
     }
     // pie chart has only one array of a values
     $xColumnDataType = getResultColumnDataType($arResult['viewColumns'][$xColumnIndex], $arResult['customColumnTypes'], $arResult['helperClassName']);
     $xColumnResultName = $arResult['viewColumns'][$xColumnIndex]['resultName'];
     $yColumnsIndexes = array();
     $yColumnsResultNames = array();
     $columnsHumanTitles = array();
     $columnsHumanTitles[0] = $arResult['viewColumns'][$xColumnIndex]['humanTitle'];
     $columnsTypes = array();
     $columnsTypes[0] = $xColumnDataType;
     for ($i = 0; $i < $yColumnsCount; $i++) {
         $yColumnsIndexes[] = $yColumnIndex = $chartSettings['y_columns'][$i];
         $yColumnsResultNames[] = $arResult['viewColumns'][$yColumnIndex]['resultName'];
         $columnsHumanTitles[] = $arResult['viewColumns'][$yColumnIndex]['humanTitle'];
         $columnsTypes[$i + 1] = getResultColumnDataType($arResult['viewColumns'][$yColumnIndex], $arResult['customColumnTypes'], $arResult['helperClassName']);
     }
     $requestData = array('type' => $chartType, 'columnTypes' => $columnsTypes);
     if (!is_null($arGroupingResult) && is_array($arGroupingResult)) {
         $n = min($nMaxValues, count($arGroupingResult));
         for ($i = 0; $i < $n; $i++) {
             $row = array();
             $dataRow = $arGroupingResult[$i];
             $row[0] = htmlspecialcharsback(str_replace(array('&nbsp;', '&quot;'), array('', '"'), strip_tags($dataRow[$xColumnIndex])));
             foreach ($yColumnsIndexes as $yColumnIndex) {
                 $row[] = htmlspecialcharsback(str_replace(array('&nbsp;', '&quot;'), array('', '"'), strip_tags($dataRow[$yColumnIndex])));
             }
             $requestData['data'][] = $row;
         }
     } else {
         $n = min($nMaxValues, count($arResult['data']));
         for ($i = 0; $i < $n; $i++) {
             $row = array();
             $dataRow = $arResult['data'][$i];
             if (isset($arResult['customChartData'][$i][$xColumnResultName]['multiple'])) {
                 $customValueInfo = $arResult['customChartData'][$i][$xColumnResultName];
                 if ($customValueInfo['multiple'] === true) {
                     $nValue = 0;
                     foreach ($customValueInfo as $cvKey => $cvInfo) {
                         if ($cvKey !== 'multiple') {
                             $dataValue = null;
                             switch ($xColumnDataType) {
                                 case 'boolean':
                                 case 'float':
                                 case 'integer':
                                     if ($nValue === 0) {
                                         $dataValue = $cvInfo['value'];
                                     } else {
                                         $dataValue = $cvInfo['value'] + $dataValue;
                                     }
                                     break;
                                 case 'date':
                                 case 'datetime':
                                 case 'string':
                                 case 'enum':
                                     if ($nValue === 0) {
                                         $dataValue = $cvInfo['value'];
                                     } else {
                                         $dataValue = $dataValue . ' / ' . $cvInfo['value'];
                                     }
                                     break;
                             }
                             $nValue++;
                         }
                     }
                 } else {
                     $dataValue = $customValueInfo[0]['value'];
                 }
             } else {
                 $dataValue = $dataRow[$xColumnResultName];
             }
             $row[0] = htmlspecialcharsback(str_replace(array('&nbsp;', '&quot;'), array('', '"'), strip_tags($dataValue)));
             foreach ($yColumnsResultNames as $yColumnResultName) {
                 if (isset($arResult['customChartData'][$i][$yColumnResultName]['multiple'])) {
                     $customValueInfo = $arResult['customChartData'][$i][$yColumnResultName];
                     if ($customValueInfo['multiple'] === true) {
                         $dataValue = 0;
                         foreach ($customValueInfo as $cvKey => $cvInfo) {
                             if ($cvKey !== 'multiple') {
                                 $dataValue = $cvInfo['value'] + $dataValue;
                             }
                         }
                     } else {
                         $dataValue = $customValueInfo[0]['value'];
                     }
                 } else {
                     $dataValue = $dataRow[$yColumnResultName];
                 }
                 $row[] = htmlspecialcharsback(str_replace(array('&nbsp;', '&quot;'), array('', '"'), strip_tags($dataValue)));
             }
             $requestData['data'][] = $row;
         }
     }
     return array('requestData' => $requestData, 'columnsNames' => $columnsHumanTitles);
 }
コード例 #3
0
ファイル: template.php プロジェクト: rasuldev/torino
 function groupingReportResultHtml(&$arParams, &$arResult, $level = 0, $arRowSet = array())
 {
     $arReportData = array();
     $total = array();
     $arViewColumns =& $arResult['viewColumns'];
     $arData =& $arResult['data'];
     $finalRow = 0;
     $headerHtml = '';
     // static variables
     static $arGroups = array();
     static $arColumns = array();
     static $nGroups = 0;
     static $nColumns = 0;
     static $arValueTypes = array();
     // initialize static variables
     if ($level === 0) {
         foreach ($arViewColumns as $viewColumnIndex => $viewColumn) {
             if ($viewColumn['grouping']) {
                 $arGroups[$nGroups++] = $viewColumnIndex;
             } else {
                 $arColumns[$nColumns++] = $viewColumnIndex;
             }
             $arValueTypes[$viewColumnIndex] = getResultColumnDataType($viewColumn, $arResult['customColumnTypes']);
         }
         $headerHtml = getReportHeader($arGroups, $arResult);
     }
     $nRows = count($arRowSet);
     $bUseRowSet = $nRows > 0 ? true : false;
     if (!$bUseRowSet) {
         $nRows = count($arData);
     }
     if ($nGroups > 0) {
         if ($nRows > 0) {
             // init total
             if ($nColumns > 0) {
                 foreach (array_keys($arColumns) as $columnIndex) {
                     $total[$columnIndex] = null;
                 }
             }
             if ($level < $nGroups) {
                 // fill group arrays
                 $arGroupValues = array();
                 $arGroupValuesIndexes = array();
                 $rowNumber = 0;
                 $groupDataType = $arValueTypes[$arGroups[$level]];
                 $dataIndex = null;
                 reset($arData);
                 while ($rowNumber++ < $nRows) {
                     // get index
                     if ($bUseRowSet) {
                         list(, $dataIndex) = each($arRowSet);
                     } else {
                         list($dataIndex, ) = each($arData);
                     }
                     // fill index and value of group
                     $arGroupValuesIndexes[] = $dataIndex;
                     $groupValue = $arData[$dataIndex][$arViewColumns[$arGroups[$level]]['resultName']];
                     if ($groupDataType === 'date' || $groupDataType === 'datetime') {
                         $groupValue = MakeTimeStamp($groupValue, CSite::GetDateFormat('SHORT'));
                     }
                     // magic glue
                     if (is_array($groupValue)) {
                         $groupValue = join(' / ', $groupValue);
                     }
                     $arGroupValues[] = $groupValue;
                 }
                 // determine sort options
                 $groupSortOption = SORT_STRING;
                 $groupSortDirection = SORT_ASC;
                 if (in_array($groupDataType, array('date', 'datetime', 'integer', 'float'))) {
                     $groupSortOption = SORT_NUMERIC;
                 }
                 if ($arGroups[$level] == $arResult['sort_id']) {
                     if ($arResult['sort_type'] != 'ASC') {
                         $groupSortDirection = SORT_DESC;
                     }
                 }
                 // sort group
                 array_multisort($arGroupValues, $groupSortOption, $groupSortDirection, $arGroupValuesIndexes, SORT_NUMERIC, SORT_ASC);
                 // recursive scan
                 $prev = null;
                 $newRowSet = array();
                 $nGroupValues = count($arGroupValues);
                 $nSubRows = 0;
                 $closeTBody = false;
                 for ($i = 0; $i < $nGroupValues; $i++) {
                     $cur = $arGroupValues[$i];
                     if ($i == 0) {
                         $prev = $cur;
                     }
                     $bLastValue = $nGroupValues - 1 == $i;
                     if ($cur != $prev || $bLastValue) {
                         $n = $bLastValue && $cur != $prev ? 2 : 1;
                         while ($n-- > 0) {
                             $groupValueIndex = $bLastValue && $n === 0 ? $i : $i - 1;
                             if ($bLastValue && $cur == $prev) {
                                 $newRowSet[] = $arGroupValuesIndexes[$i];
                             }
                             $arGroupingResult = groupingReportResultHtml($arParams, $arResult, $level + 1, $newRowSet);
                             $arSubTotal = $arGroupingResult['total'];
                             $arReportData[$groupValueIndex]["CLOSED"] = true;
                             if (!empty($arGroupingResult['array'])) {
                                 $arReportData[$groupValueIndex]["SECTIONS"] = $arGroupingResult['array'];
                             }
                             unset($arGroupingResult);
                             $newRowSet = array();
                             if (!$bLastValue) {
                                 $newRowSet[] = $arGroupValuesIndexes[$i];
                             }
                             $prev = $cur;
                             // show row
                             $groupValueKey = $arViewColumns[$arGroups[$level]]['resultName'];
                             $groupValue = $arData[$arGroupValuesIndexes[$groupValueIndex]][$groupValueKey];
                             // magic glue
                             if (is_array($groupValue)) {
                                 $groupValue = join(' / ', $groupValue);
                             }
                             if ($level == 0) {
                                 $closeTBody = true;
                                 $rowClass = ' class="mobile-admin-report-category"';
                             } else {
                                 $rowClass = '';
                             }
                             foreach ($arSubTotal as $k => $subValue) {
                                 $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal'];
                                 if ($bGroupingSubtotal || $level == $nGroups - 1) {
                                     $finalSubValue = $subValue;
                                     if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) {
                                         // format subtotal value
                                         $subValueKey = $arViewColumns[$arColumns[$k]]['resultName'];
                                         call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalSubValue, 'cInfo' => &$arViewColumns[$arColumns[$k]]));
                                     }
                                 } else {
                                     $finalSubValue = '&nbsp;';
                                 }
                                 if ($k == 0) {
                                     $arReportData[$groupValueIndex]["TITLE"] = $groupValue;
                                 }
                                 if (empty($arReportData[$groupValueIndex]["SECTIONS"])) {
                                     $arReportData[$groupValueIndex]["CONTENT"][$k]["TITLE"] = $arViewColumns[$arColumns[$k]]['humanTitle'] . ": ";
                                     $arReportData[$groupValueIndex]["CONTENT"][$k]["VALUE"] = $finalSubValue;
                                 }
                             }
                             // total += subtotal
                             if ($nColumns > 0) {
                                 foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                                     $columnDataType = $arValueTypes[$viewColumnIndex];
                                     if ($columnDataType === 'integer' || $columnDataType === 'float') {
                                         if (is_string($arSubTotal[$columnIndex])) {
                                             $arSubTotal[$columnIndex] = str_replace(' ', '', $arSubTotal[$columnIndex]);
                                         }
                                         $total[$columnIndex] += $arSubTotal[$columnIndex];
                                     }
                                 }
                                 $nSubRows++;
                             }
                         }
                         // while ($n-- > 0)
                     } else {
                         $newRowSet[] = $arGroupValuesIndexes[$i];
                     }
                     $finalRow = $i;
                 }
                 // calculate average values
                 if ($nSubRows > 1) {
                     foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                         if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') {
                             $total[$columnIndex] = $total[$columnIndex] / $nSubRows;
                         }
                     }
                 }
             } else {
                 if ($nColumns > 0) {
                     $rowNumber = 0;
                     while ($rowNumber++ < $nRows) {
                         // get index
                         if ($bUseRowSet) {
                             list(, $dataIndex) = each($arRowSet);
                         } else {
                             list($dataIndex, ) = each($arData);
                         }
                         // total += values
                         foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                             $columnDataType = $arValueTypes[$viewColumnIndex];
                             if ($nRows == 1) {
                                 $dataValueKey = $arViewColumns[$viewColumnIndex]['resultName'];
                                 $dataValue = $arData[$dataIndex][$dataValueKey];
                                 if ($columnDataType === 'integer' || $columnDataType === 'float' && is_string($dataValue)) {
                                     $dataValue = str_replace(' ', '', $dataValue);
                                 }
                                 // normal value
                                 $total[$columnIndex] = $dataValue;
                             } else {
                                 if ($columnDataType === 'integer' || $columnDataType === 'float') {
                                     $dataValue = $arData[$dataIndex][$arViewColumns[$viewColumnIndex]['resultName']];
                                     if (is_string($dataValue)) {
                                         $dataValue = str_replace(' ', '', $dataValue);
                                     }
                                     $total[$columnIndex] += $dataValue;
                                 }
                             }
                         }
                     }
                     // calculate average values
                     if ($nRows > 1) {
                         foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                             if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') {
                                 $total[$columnIndex] = $total[$columnIndex] / $nRows;
                             }
                         }
                     }
                 }
             }
         }
         // show total
         if ($level === 0) {
             if (count($total) > 0) {
                 // show total check
                 $bShowTotal = false;
                 foreach ($total as $k => $v) {
                     if ($arViewColumns[$arColumns[$k]]['grouping_subtotal']) {
                         $bShowTotal = true;
                         break;
                     }
                 }
                 if ($bShowTotal) {
                     $arReportData[$finalRow + 1]["TITLE"] = GetMessage('REPORT_TOTAL');
                     $arReportData[$finalRow + 1]["CLOSED"] = true;
                     $arReportData[$finalRow + 1]["HIGHLIGHTED"] = true;
                     foreach ($total as $k => $v) {
                         $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal'];
                         if ($bGroupingSubtotal) {
                             $finalTotalValue = $v;
                             if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) {
                                 // format subtotal value
                                 $subValueKey = $arViewColumns[$arColumns[$k]]['resultName'];
                                 call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalTotalValue, 'cInfo' => &$arViewColumns[$arColumns[$k]]));
                             }
                         } else {
                             $finalTotalValue = '&nbsp;';
                         }
                         $arReportData[$finalRow + 1]["CONTENT"][$k]["TITLE"] = $arViewColumns[$arColumns[$k]]['humanTitle'] . ": ";
                         $arReportData[$finalRow + 1]["CONTENT"][$k]["VALUE"] = $finalTotalValue;
                         //$arReportData["finalTotalValue"][$k] = $finalTotalValue;
                     }
                 }
             }
         }
     }
     return array('total' => $total, 'array' => $arReportData, 'headerHtml' => $headerHtml);
 }
コード例 #4
0
ファイル: template.php プロジェクト: rasuldev/torino
 function groupingReportResultHtml(&$arParams, &$arResult, $level = 0, $arRowSet = array())
 {
     $strHtml = '';
     $total = array();
     $arViewColumns =& $arResult['viewColumns'];
     $arData =& $arResult['data'];
     // static variables
     static $arGroups = array();
     static $arColumns = array();
     static $nGroups = 0;
     static $nColumns = 0;
     static $arValueTypes = array();
     // initialize static variables
     if ($level === 0) {
         foreach ($arViewColumns as $viewColumnIndex => $viewColumn) {
             if ($viewColumn['grouping']) {
                 $arGroups[$nGroups++] = $viewColumnIndex;
             } else {
                 $arColumns[$nColumns++] = $viewColumnIndex;
             }
             $arValueTypes[$viewColumnIndex] = getResultColumnDataType($viewColumn, $arResult['customColumnTypes']);
         }
     }
     $nRows = count($arRowSet);
     $bUseRowSet = $nRows > 0 ? true : false;
     if (!$bUseRowSet) {
         $nRows = count($arData);
     }
     if ($nGroups > 0) {
         // grouping table header
         if ($level === 0) {
             $strHtml .= "\t" . '<div class="order_infoblock">' . PHP_EOL . "\t\t" . '<div class="order_infoblock_content">' . PHP_EOL . "\t\t\t" . '<table class="bx_table_item_remainder">' . PHP_EOL . "\t\t\t\t" . '<thead>' . PHP_EOL;
             $strHtml .= "\t\t\t\t\t" . '<tr class="mobile-admin-report-header">' . PHP_EOL . "\t\t\t\t\t\t" . '<td>' . htmlspecialcharsbx($arViewColumns[$groupColumnIndex]['humanTitle']);
             $bFirst = true;
             foreach ($arGroups as $groupColumnIndex) {
                 if ($bFirst) {
                     $strHtml .= htmlspecialcharsbx($arViewColumns[$groupColumnIndex]['humanTitle']);
                 } else {
                     $strHtml .= '<span>' . htmlspecialcharsbx($arViewColumns[$groupColumnIndex]['humanTitle']) . '</span>';
                 }
                 $bFirst = false;
             }
             $strHtml .= "\t\t\t\t\t\t" . '</td>' . PHP_EOL;
             foreach ($arColumns as $viewColumnIndex) {
                 $strHtml .= "\t\t\t\t\t\t" . '<td defaultSort="' . $arViewColumns[$viewColumnIndex]['defaultSort'] . '">' . htmlspecialcharsbx($arViewColumns[$viewColumnIndex]['humanTitle']) . "\t\t\t\t\t\t" . '</td>' . PHP_EOL;
             }
             $strHtml .= "\t\t\t\t\t" . '</tr>' . PHP_EOL;
             $strHtml .= "\t\t\t\t" . '</thead>' . PHP_EOL;
         }
         if ($nRows > 0) {
             // init total
             if ($nColumns > 0) {
                 foreach (array_keys($arColumns) as $columnIndex) {
                     $total[$columnIndex] = null;
                 }
             }
             if ($level < $nGroups) {
                 // fill group arrays
                 $arGroupValues = array();
                 $arGroupValuesIndexes = array();
                 $rowNumber = 0;
                 $groupDataType = $arValueTypes[$arGroups[$level]];
                 $dataIndex = null;
                 reset($arData);
                 while ($rowNumber++ < $nRows) {
                     // get index
                     if ($bUseRowSet) {
                         list(, $dataIndex) = each($arRowSet);
                     } else {
                         list($dataIndex, ) = each($arData);
                     }
                     // fill index and value of group
                     $arGroupValuesIndexes[] = $dataIndex;
                     $groupValue = $arData[$dataIndex][$arViewColumns[$arGroups[$level]]['resultName']];
                     if ($groupDataType === 'date' || $groupDataType === 'datetime') {
                         $groupValue = MakeTimeStamp($groupValue, CSite::GetDateFormat('SHORT'));
                     }
                     // magic glue
                     if (is_array($groupValue)) {
                         $groupValue = join(' / ', $groupValue);
                     }
                     $arGroupValues[] = $groupValue;
                 }
                 // determine sort options
                 $groupSortOption = SORT_STRING;
                 $groupSortDirection = SORT_ASC;
                 if (in_array($groupDataType, array('date', 'datetime', 'integer', 'float'))) {
                     $groupSortOption = SORT_NUMERIC;
                 }
                 if ($arGroups[$level] == $arResult['sort_id']) {
                     if ($arResult['sort_type'] != 'ASC') {
                         $groupSortDirection = SORT_DESC;
                     }
                 }
                 // sort group
                 array_multisort($arGroupValues, $groupSortOption, $groupSortDirection, $arGroupValuesIndexes, SORT_NUMERIC, SORT_ASC);
                 // recursive scan
                 $prev = null;
                 $newRowSet = array();
                 $nGroupValues = count($arGroupValues);
                 $nSubRows = 0;
                 $closeTBody = false;
                 for ($i = 0; $i < $nGroupValues; $i++) {
                     $cur = $arGroupValues[$i];
                     if ($i == 0) {
                         $prev = $cur;
                     }
                     $bLastValue = $nGroupValues - 1 == $i;
                     if ($cur != $prev || $bLastValue) {
                         $n = $bLastValue && $cur != $prev ? 2 : 1;
                         while ($n-- > 0) {
                             if ($bLastValue && $cur == $prev) {
                                 $newRowSet[] = $arGroupValuesIndexes[$i];
                             }
                             $arGroupingResult = groupingReportResultHtml($arParams, $arResult, $level + 1, $newRowSet);
                             $arSubTotal = $arGroupingResult['total'];
                             $strSubHtml = $arGroupingResult['html'];
                             unset($arGroupingResult);
                             $newRowSet = array();
                             if (!$bLastValue) {
                                 $newRowSet[] = $arGroupValuesIndexes[$i];
                             }
                             $prev = $cur;
                             // show row
                             $groupValueIndex = $bLastValue && $n === 0 ? $i : $i - 1;
                             $groupValueKey = $arViewColumns[$arGroups[$level]]['resultName'];
                             $groupValue = $arData[$arGroupValuesIndexes[$groupValueIndex]][$groupValueKey];
                             // magic glue
                             if (is_array($groupValue)) {
                                 $groupValue = join(' / ', $groupValue);
                             }
                             if ($level == 0) {
                                 if ($closeTBody) {
                                     $strHtml .= "\t\t\t\t" . '</tbody>' . PHP_EOL;
                                 }
                                 $strHtml .= "\t\t\t\t" . '<tbody>' . PHP_EOL;
                                 $closeTBody = true;
                                 $rowClass = ' class="mobile-admin-report-category"';
                             } else {
                                 $rowClass = '';
                             }
                             $strHtml .= "\t\t\t\t\t" . '<tr' . $rowClass . '>' . PHP_EOL . "\t\t\t\t\t\t" . '<td>';
                             if ($level == $nGroups - 1) {
                                 $strHtml .= '<span>' . $groupValue . '</span>';
                             } else {
                                 $strHtml .= $groupValue;
                             }
                             $strHtml .= "\t\t\t\t\t\t" . '</td>' . PHP_EOL;
                             foreach ($arSubTotal as $k => $subValue) {
                                 $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal'];
                                 if ($bGroupingSubtotal || $level == $nGroups - 1) {
                                     $finalSubValue = $subValue;
                                     if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) {
                                         // format subtotal value
                                         $subValueKey = $arViewColumns[$arColumns[$k]]['resultName'];
                                         call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalSubValue, 'cInfo' => &$arViewColumns[$arColumns[$k]]));
                                     }
                                 } else {
                                     $finalSubValue = '&nbsp;';
                                 }
                                 $strHtml .= "\t\t\t\t\t\t" . '<td>' . $finalSubValue . '</td>' . PHP_EOL;
                             }
                             $strHtml .= "\t\t\t\t\t" . '</tr>' . PHP_EOL;
                             $strHtml .= $strSubHtml;
                             // total += subtotal
                             if ($nColumns > 0) {
                                 foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                                     $columnDataType = $arValueTypes[$viewColumnIndex];
                                     if ($columnDataType === 'integer' || $columnDataType === 'float') {
                                         if (is_string($arSubTotal[$columnIndex])) {
                                             $arSubTotal[$columnIndex] = str_replace(' ', '', $arSubTotal[$columnIndex]);
                                         }
                                         $total[$columnIndex] += $arSubTotal[$columnIndex];
                                     }
                                 }
                                 $nSubRows++;
                             }
                         }
                         // while ($n-- > 0)
                     } else {
                         $newRowSet[] = $arGroupValuesIndexes[$i];
                     }
                 }
                 // calculate average values
                 if ($nSubRows > 1) {
                     foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                         if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') {
                             $total[$columnIndex] = $total[$columnIndex] / $nSubRows;
                         }
                     }
                 }
             } else {
                 if ($nColumns > 0) {
                     $rowNumber = 0;
                     while ($rowNumber++ < $nRows) {
                         // get index
                         if ($bUseRowSet) {
                             list(, $dataIndex) = each($arRowSet);
                         } else {
                             list($dataIndex, ) = each($arData);
                         }
                         // total += values
                         foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                             $columnDataType = $arValueTypes[$viewColumnIndex];
                             if ($nRows == 1) {
                                 $dataValueKey = $arViewColumns[$viewColumnIndex]['resultName'];
                                 $dataValue = $arData[$dataIndex][$dataValueKey];
                                 if ($columnDataType === 'integer' || $columnDataType === 'float' && is_string($dataValue)) {
                                     $dataValue = str_replace(' ', '', $dataValue);
                                 }
                                 // normal value
                                 $total[$columnIndex] = $dataValue;
                             } else {
                                 if ($columnDataType === 'integer' || $columnDataType === 'float') {
                                     $dataValue = $arData[$dataIndex][$arViewColumns[$viewColumnIndex]['resultName']];
                                     if (is_string($dataValue)) {
                                         $dataValue = str_replace(' ', '', $dataValue);
                                     }
                                     $total[$columnIndex] += $dataValue;
                                 }
                             }
                         }
                     }
                     // calculate average values
                     if ($nRows > 1) {
                         foreach ($arColumns as $columnIndex => $viewColumnIndex) {
                             if ($arViewColumns[$viewColumnIndex]['aggr'] === 'AVG' || $arViewColumns[$viewColumnIndex]['grouping_aggr'] === 'AVG') {
                                 $total[$columnIndex] = $total[$columnIndex] / $nRows;
                             }
                         }
                     }
                 }
             }
         }
         // show total
         if ($level === 0) {
             if (count($total) > 0) {
                 // show total check
                 $bShowTotal = false;
                 foreach ($total as $k => $v) {
                     if ($arViewColumns[$arColumns[$k]]['grouping_subtotal']) {
                         $bShowTotal = true;
                         break;
                     }
                 }
                 if ($bShowTotal) {
                     $strHtml .= "\t\t\t" . '</tbody><tbody><tr style="background: none repeat scroll 0 0 #EDF2D4;">' . PHP_EOL . "\t\t\t\t" . '<td>' . htmlspecialcharsbx(GetMessage('REPORT_TOTAL')) . ':</td>' . PHP_EOL;
                     foreach ($total as $k => $v) {
                         $bGroupingSubtotal = $arViewColumns[$arColumns[$k]]['grouping_subtotal'];
                         if ($bGroupingSubtotal) {
                             $finalTotalValue = $v;
                             if (method_exists($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal')) {
                                 // format subtotal value
                                 $subValueKey = $arViewColumns[$arColumns[$k]]['resultName'];
                                 call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'formatResultGroupingTotal'), array('k' => $subValueKey, 'v' => &$finalTotalValue, 'cInfo' => &$arViewColumns[$arColumns[$k]]));
                             }
                         } else {
                             $finalTotalValue = '&nbsp;';
                         }
                         $strHtml .= "\t\t\t\t" . '<td>' . $finalTotalValue . '</td>' . PHP_EOL;
                     }
                     $strHtml .= "\t\t\t" . '</tr>' . PHP_EOL;
                 }
             }
             $strHtml .= "\t" . '</tbody></table>' . PHP_EOL . '</div></div>' . PHP_EOL;
         }
     }
     return array('total' => $total, 'html' => $strHtml);
 }
コード例 #5
0
ファイル: template.php プロジェクト: Satariall/izurit
 function prepareChartData(&$arResult, &$arGroupingResult = null)
 {
     $nMaxValues = 500;
     // check
     $chartSettings = $arResult['settings']['chart'];
     if (!isset($chartSettings['x_column'])) {
         return null;
     }
     $xColumnIndex = $chartSettings['x_column'];
     if (!is_array($chartSettings['y_columns'])) {
         return null;
     }
     $yColumnsCount = count($chartSettings['y_columns']);
     if ($yColumnsCount === 0) {
         return null;
     }
     $chartTypeIds = array();
     foreach ($arResult['chartTypes'] as $chartTypeInfo) {
         $chartTypeIds[] = $chartTypeInfo['id'];
     }
     if (!is_set($chartSettings['type']) || empty($chartSettings['type']) || !in_array($chartSettings['type'], $chartTypeIds)) {
         return null;
     }
     $chartType = $chartSettings['type'];
     if ($chartType === 'pie') {
         $yColumnsCount = 1;
     }
     // pie chart has only one array of a values
     $xColumnDataType = getResultColumnDataType($arResult['viewColumns'][$xColumnIndex], $arResult['customColumnTypes'], $arResult['helperClassName']);
     $xColumnResultName = $arResult['viewColumns'][$xColumnIndex]['resultName'];
     $yColumnsIndexes = array();
     $yColumnsResultNames = array();
     $columnsHumanTitles = array();
     $columnsHumanTitles[0] = $arResult['viewColumns'][$xColumnIndex]['humanTitle'];
     $columnsTypes = array();
     $columnsTypes[0] = $xColumnDataType;
     for ($i = 0; $i < $yColumnsCount; $i++) {
         $yColumnsIndexes[] = $yColumnIndex = $chartSettings['y_columns'][$i];
         $yColumnsResultNames[] = $arResult['viewColumns'][$yColumnIndex]['resultName'];
         $columnsHumanTitles[] = $arResult['viewColumns'][$yColumnIndex]['humanTitle'];
         $columnsTypes[$i + 1] = getResultColumnDataType($arResult['viewColumns'][$yColumnIndex], $arResult['customColumnTypes'], $arResult['helperClassName']);
     }
     $requestData = array('type' => $chartType, 'columnTypes' => $columnsTypes);
     if (!is_null($arGroupingResult) && is_array($arGroupingResult)) {
         $n = min($nMaxValues, count($arGroupingResult));
         for ($i = 0; $i < $n; $i++) {
             $row = array();
             $dataRow = $arGroupingResult[$i];
             $row[0] = $dataRow[$xColumnIndex];
             foreach ($yColumnsIndexes as $yColumnIndex) {
                 $row[] = $dataRow[$yColumnIndex];
             }
             $requestData['data'][] = $row;
         }
     } else {
         $n = min($nMaxValues, count($arResult['data']));
         for ($i = 0; $i < $n; $i++) {
             $row = array();
             $dataRow = $arResult['data'][$i];
             $row[0] = $dataRow[$xColumnResultName];
             foreach ($yColumnsResultNames as $yColumnResultName) {
                 $row[] = $dataRow[$yColumnResultName];
             }
             $requestData['data'][] = $row;
         }
     }
     return array('requestData' => $requestData, 'columnsNames' => $columnsHumanTitles);
 }