当前位置: 首页>>代码示例>>PHP>>正文


PHP Misc::Array2CSV方法代码示例

本文整理汇总了PHP中Misc::Array2CSV方法的典型用法代码示例。如果您正苦于以下问题:PHP Misc::Array2CSV方法的具体用法?PHP Misc::Array2CSV怎么用?PHP Misc::Array2CSV使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Misc的用法示例。


在下文中一共展示了Misc::Array2CSV方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: unset

                     $row_columns[$column] = $column_data;
                     unset($column, $column_data);
                 }
                 $rows[] = $row_columns;
                 unset($row_columns);
             }
         }
     }
     //var_dump($rows);
     foreach ($filter_data['column_ids'] as $column_key) {
         $filter_columns[Misc::trimSortPrefix($column_key)] = $columns[$column_key];
     }
     if ($action == 'export') {
         if (isset($rows) and isset($filter_columns)) {
             Debug::Text('Exporting as CSV', __FILE__, __LINE__, __METHOD__, 10);
             $data = Misc::Array2CSV($rows, $filter_columns);
             Misc::FileDownloadHeader('report.csv', 'application/csv', strlen($data));
             echo $data;
         } else {
             echo TTi18n::gettext("No Data To Export!") . "<br>\n";
         }
     } else {
         $smarty->assign_by_ref('generated_time', TTDate::getTime());
         $smarty->assign_by_ref('pay_period_options', $pay_period_options);
         $smarty->assign_by_ref('filter_data', $filter_data);
         $smarty->assign_by_ref('columns', $filter_columns);
         $smarty->assign_by_ref('rows', $rows);
         $smarty->display('report/TimesheetSummaryReport.tpl');
     }
     break;
 case 'delete':
开发者ID:alachaum,项目名称:timetrex,代码行数:31,代码来源:TimesheetSummary.php

示例2: PayrollDeduction

                            $pd_obj = new PayrollDeduction($country, $province_code);
                            $pd_obj->setDate($effective_date);
                            $pd_obj->setAnnualPayPeriods($pay_periods);
                            $pd_obj->setEnableCPPAndEIDeduction(TRUE);
                            //Deduct CPP/EI.
                            $pd_obj->setFederalTotalClaimAmount($federal_claim);
                            $pd_obj->setProvincialTotalClaimAmount($provincial_claim);
                            $pd_obj->setEIExempt(FALSE);
                            $pd_obj->setCPPExempt(FALSE);
                            $pd_obj->setFederalTaxExempt(FALSE);
                            $pd_obj->setProvincialTaxExempt(FALSE);
                            $pd_obj->setYearToDateCPPContribution(0);
                            $pd_obj->setYearToDateEIContribution(0);
                            $pd_obj->setGrossPayPeriodIncome($income);
                            $retarr[] = array('country' => $country, 'province' => $province_code, 'date' => date('m/d/y', $effective_date), 'pay_periods' => $pay_periods, 'federal_claim' => $pd_obj->getFederalTotalClaimAmount(), 'provincial_claim' => $pd_obj->getProvincialTotalClaimAmount(), 'gross_income' => $income, 'federal_deduction' => Misc::MoneyFormat($pd_obj->getFederalPayPeriodDeductions(), FALSE), 'provincial_deduction' => Misc::MoneyFormat($pd_obj->getProvincialPayPeriodDeductions(), FALSE));
                        }
                    }
                }
            }
        }
        //generate column array.
        $column_keys = array_keys($retarr[0]);
        foreach ($column_keys as $column_key) {
            $columns[$column_key] = $column_key;
        }
        //var_dump($test_data);
        //var_dump($retarr);
        echo Misc::Array2CSV($retarr, $columns, FALSE, $include_header = TRUE);
    }
}
//Debug::Display();
开发者ID:alachaum,项目名称:timetrex,代码行数:31,代码来源:generate_payroll_deduction_test_csv.php

示例3: array

                 //
                 //header
                 //
                 $data = 'TC' . "\n";
                 $data .= '00001' . "\n";
                 $export_column_map = array('pay_period_end_date' => 'Entry Date', 'employee_number' => 'Employee Number', 'last_name' => 'Last Name', 'first_name' => 'First Name', 'hour_code' => 'Payroll Code', 'value' => 'Hours');
                 foreach ($rows as $row) {
                     foreach ($setup_data['surepayroll']['columns'] as $column_id => $column_data) {
                         if (isset($row[$column_id]) and trim($column_data['hour_code']) != '') {
                             Debug::Arr($column_data, 'Output2', __FILE__, __LINE__, __METHOD__, 10);
                             $tmp_rows[] = array('pay_period_end_date' => date('m/d/Y', $row['pay_period_end_date']), 'employee_number' => $row['employee_number'], 'last_name' => $row['last_name'], 'first_name' => $row['first_name'], 'hour_code' => trim($column_data['hour_code']), 'value' => TTDate::getTimeUnit($row[$column_id], 20));
                         }
                     }
                 }
                 if (isset($tmp_rows)) {
                     $data .= Misc::Array2CSV($tmp_rows, $export_column_map, FALSE, FALSE);
                     $data = str_replace('"', '', $data);
                 }
                 unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
                 break;
             default:
                 break;
         }
     }
 }
 if (Debug::getVerbosity() == 11) {
     Debug::Arr($data, 'Output', __FILE__, __LINE__, __METHOD__, 10);
     Debug::Display();
 } else {
     if (isset($data) and strlen($data) > 0) {
         Debug::Text('Exporting as CSV', __FILE__, __LINE__, __METHOD__, 10);
开发者ID:alachaum,项目名称:timetrex,代码行数:31,代码来源:PayrollExport.php

示例4: _outputPayrollExport

 function _outputPayrollExport($format = NULL)
 {
     $setup_data = $this->getFormConfig();
     Debug::Text('Generating Payroll Export... Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     if (isset($setup_data['export_type'])) {
         Debug::Text('Export Type: ' . $setup_data['export_type'], __FILE__, __LINE__, __METHOD__, 10);
     } else {
         Debug::Text('No Export Type defined!', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     Debug::Arr($setup_data, 'Setup Data: ', __FILE__, __LINE__, __METHOD__, 10);
     $rows = $this->data;
     //Debug::Arr($rows, 'PreData: ', __FILE__, __LINE__, __METHOD__,10);
     $file_name = strtolower(trim($setup_data['export_type'])) . '_' . date('Y_m_d') . '.txt';
     $mime_type = 'application/text';
     $data = NULL;
     switch (strtolower(trim($setup_data['export_type']))) {
         case 'adp':
             //ADP export format.
             //File format supports multiple rows per employee (file #) all using the same columns. No need to jump through nasty hoops to fit everything on row.
             $export_column_map = array('company_code' => 'Co Code', 'batch_id' => 'Batch ID', 'temp_dept' => 'Temp Dept', 'employee_number' => 'File #', 'regular_time' => 'Reg Hours', 'overtime' => 'O/T Hours', '3_code' => 'Hours 3 Code', '3_amount' => 'Hours 3 Amount', '4_code' => 'Hours 4 Code', '4_amount' => 'Hours 4 Amount');
             ksort($setup_data['adp']['columns']);
             $setup_data['adp']['columns'] = Misc::trimSortPrefix($setup_data['adp']['columns']);
             foreach ($setup_data['adp']['columns'] as $column_id => $column_data) {
                 $column_name = NULL;
                 if ($column_data['hour_column'] == 'regular_time') {
                     $export_data_map[$column_id] = 'regular_time';
                 } elseif ($column_data['hour_column'] == 'overtime') {
                     $export_data_map[$column_id] = 'overtime';
                 } elseif ($column_data['hour_column'] >= 3) {
                     $export_data_map[$column_id] = $column_data;
                 }
             }
             if (!isset($setup_data['adp']['company_code_value'])) {
                 $setup_data['adp']['company_code_value'] = NULL;
             }
             if (!isset($setup_data['adp']['batch_id_value'])) {
                 $setup_data['adp']['batch_id_value'] = NULL;
             }
             if (!isset($setup_data['adp']['temp_dept_value'])) {
                 $setup_data['adp']['temp_dept_value'] = NULL;
             }
             $company_code_column = Misc::trimSortPrefix($setup_data['adp']['company_code']);
             $batch_id_column = Misc::trimSortPrefix($setup_data['adp']['batch_id']);
             $temp_dept_column = Misc::trimSortPrefix($setup_data['adp']['temp_dept']);
             foreach ($rows as $row) {
                 $static_columns = array('company_code' => isset($row[$company_code_column]) ? $row[$company_code_column] : $setup_data['adp']['company_code_value'], 'batch_id' => isset($row[$batch_id_column]) ? $row[$batch_id_column] : $setup_data['adp']['batch_id_value'], 'temp_dept' => isset($row[$temp_dept_column]) ? $row[$temp_dept_column] : $setup_data['adp']['temp_dept_value'], 'employee_number' => str_pad($row['employee_number'], 6, 0, STR_PAD_LEFT));
                 foreach ($setup_data['adp']['columns'] as $column_id => $column_data) {
                     $column_data = Misc::trimSortPrefix($column_data, TRUE);
                     Debug::Text('ADP Column ID: ' . $column_id . ' Hour Column: ' . $column_data['hour_column'] . ' Code: ' . $column_data['hour_code'], __FILE__, __LINE__, __METHOD__, 10);
                     if (isset($row[$column_id]) and $column_data['hour_column'] != '0') {
                         foreach ($export_column_map as $export_column_id => $export_column_name) {
                             Debug::Arr($row, 'Row: Column ID: ' . $column_id . ' Export Column ID: ' . $export_column_id . ' Name: ' . $export_column_name, __FILE__, __LINE__, __METHOD__, 10);
                             if (($column_data['hour_column'] == $export_column_id or $column_data['hour_column'] . '_code' == $export_column_id) and !in_array($export_column_id, array('company_code', 'batch_id', 'temp_dept', 'employee_number'))) {
                                 if ((int) substr($export_column_id, 0, 1) > 0) {
                                     $tmp_row[$column_data['hour_column'] . '_code'] = $column_data['hour_code'];
                                     $tmp_row[$column_data['hour_column'] . '_amount'] = TTDate::getTimeUnit($row[$column_id], 20);
                                 } else {
                                     $tmp_row[$export_column_id] = TTDate::getTimeUnit($row[$column_id], 20);
                                 }
                                 //Break out every column onto its own row, that way its easier to handle multiple columns of the same type.
                                 $tmp_rows[] = array_merge($static_columns, $tmp_row);
                                 unset($tmp_row);
                             }
                         }
                     }
                 }
             }
             $file_name = 'EPI000000.csv';
             if (isset($tmp_rows)) {
                 //File format supports multiple entries per employee (file #) all using the same columns. No need to jump through nasty hoops to fit everyone one row.
                 $file_name = 'EPI' . $tmp_rows[0]['company_code'] . $tmp_rows[0]['batch_id'] . '.csv';
                 $data = Misc::Array2CSV($tmp_rows, $export_column_map, FALSE);
             }
             unset($tmp_rows, $export_column_map, $column_id, $column_data, $rows, $row);
             break;
         case 'adp_old':
             //ADP export format.
             $file_name = 'EPI' . $setup_data['adp']['company_code'] . $setup_data['adp']['batch_id'] . '.csv';
             $export_column_map = array();
             $static_export_column_map = array('company_code' => 'Co Code', 'batch_id' => 'Batch ID', 'employee_number' => 'File #');
             $static_export_data_map = array('company_code' => $setup_data['adp']['company_code'], 'batch_id' => $setup_data['adp']['batch_id']);
             //
             //Format allows for multiple duplicate columns.
             //ie: Hours 3 Code, Hours 3 Amount, Hours 3 Code, Hours 3 Amount, ...
             //However, we can only have a SINGLE O/T Hours column.
             //We also need to combine hours with the same code together.
             //
             ksort($setup_data['adp']['columns']);
             $setup_data['adp']['columns'] = Misc::trimSortPrefix($setup_data['adp']['columns']);
             foreach ($setup_data['adp']['columns'] as $column_id => $column_data) {
                 $column_name = NULL;
                 if ($column_data['hour_column'] == 'regular_time') {
                     $column_name = 'Reg Hours';
                     $export_data_map[$column_id] = trim($setup_data['adp']['columns'][$column_id]['hour_code']);
                 } elseif ($column_data['hour_column'] == 'overtime') {
                     $column_name = 'O/T Hours';
                     $export_data_map[$column_id] = trim($setup_data['adp']['columns'][$column_id]['hour_code']);
                 } elseif ($column_data['hour_column'] >= 3) {
                     $column_name = 'Hours ' . $column_data['hour_column'] . ' Amount';
//.........这里部分代码省略.........
开发者ID:alachaum,项目名称:timetrex,代码行数:101,代码来源:PayrollExportReport.class.php

示例5: _output

 function _output($format = NULL)
 {
     Debug::Text('Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     if ($format == 'raw') {
         //Should we rekey this array so the order can be presevered, which is critical to outputting it properly?
         return $this->data;
     } elseif ($format == 'csv' or $format == 'xml') {
         //Make sure we use the full readable column name when exporting to CSV.
         $column_options = (array) Misc::trimSortPrefix($this->getOptions('columns'));
         $column_config = (array) $this->getReportColumns();
         $columns = array();
         foreach ($column_config as $column => $tmp) {
             if (isset($column_options[$column])) {
                 $columns[$column] = $column_options[$column];
             }
         }
         //Debug::Arr($columns, 'Columns:  '. $format, __FILE__, __LINE__, __METHOD__,10);
         if ($format == 'csv') {
             $data = Misc::Array2CSV($this->data, $columns, FALSE, TRUE);
             $file_extension = 'csv';
         } elseif ($format == 'xml') {
             //Include report name with non-alphanumerics stripped out.
             $data = Misc::Array2XML($this->data, $columns, $this->getColumnFormatConfig(), FALSE, FALSE, preg_replace('/[^A-Za-z0-9]/', '', $this->config['other']['report_name']), 'row');
             $file_extension = 'xml';
         }
         return array('data' => $data, 'file_name' => $this->file_name . '_' . date('Y_m_d') . '.' . $file_extension, 'mime_type' => 'text/' . $file_extension);
     } else {
         Debug::Text('Exporting PDF format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
         return $this->_pdf();
     }
     return FALSE;
 }
开发者ID:alachaum,项目名称:timetrex,代码行数:32,代码来源:Report.class.php


注:本文中的Misc::Array2CSV方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。