/** * will store the content of the report on disk and return the Url for the file * * @param string $partner_id * @param string $report_title * @param string $report_text * @param string $headers * @param int $report_type * @param reportsInputFilter $input_filter * @param string $dimension * @param string $object_ids * @param int $page_size * @param int $page_index * @param string $order_by */ public static function getUrlForReportAsCsv($partner_id, $report_title, $report_text, $headers, $report_type, reportsInputFilter $input_filter, $dimension = null, $object_ids = null, $page_size = 10, $page_index = 0, $order_by) { // create file_name // TODO - check if file already exists - if so - serve it if not expired list($file_name, $url) = self::createFileName($partner_id, $report_type, $input_filter, $dimension, $object_ids, $page_size, $page_index, $order_by); // TODO - remove comment and read from disk /* if ( file_exists ( $file_name ) ) { return $url; } */ $arr = self::getGraph($partner_id, $report_type, $input_filter, $dimension, $object_ids); list($total_header, $total_data) = self::getTotal($partner_id, $report_type, $input_filter, $object_ids); list($table_header, $table_data, $table_total_count) = self::getTable($partner_id, $report_type, $input_filter, $page_size, $page_index, $order_by, $object_ids); if ($input_filter instanceof endUserReportsInputFilter) { $table_total_count = self::getTotalTableCount($partner_id, $report_type, $input_filter, $page_size, $page_index, $order_by, $object_ids); } $data = myCsvReport::createReport($report_title, $report_text, $headers, $report_type, $input_filter, $dimension, $arr, $total_header, $total_data, $table_header, $table_data, $table_total_count); // return URL if (!file_exists(dirname($file_name))) { kFile::fullMkfileDir(dirname($file_name), 0777); } //adding BOM for fixing problem in open .csv file with special chars using excel. $BOM = ""; file_put_contents($file_name, $BOM . $data); return $url; }
/** * will store the content of the report on disk and return the Url for the file * * @param string $partner_id * @param string $report_title * @param string $report_text * @param string $headers * @param int $report_type * @param reportsInputFilter $input_filter * @param string $dimension * @param string $object_ids * @param int $page_size * @param int $page_index * @param string $order_by */ public static function getUrlForReportAsCsv($partner_id, $report_title, $report_text, $headers, $report_type, reportsInputFilter $input_filter, $dimension = null, $object_ids = null, $page_size = 10, $page_index = 0, $order_by) { // create file_name // TODO - check if file already exists - if so - serve it if not expired list($file_path, $file_name) = self::createFileName($partner_id, $report_type, $input_filter, $dimension, $object_ids, $page_size, $page_index, $order_by); // TODO - remove comment and read from disk /* if ( file_exists ( $file_path ) ) { return $url; } */ $arr = self::getGraph($partner_id, $report_type, $input_filter, $dimension, $object_ids); list($total_header, $total_data) = self::getTotal($partner_id, $report_type, $input_filter, $object_ids); $csv = new myCsvWrapper(); if ($page_size < self::REPORTS_TABLE_RESULTS_SINGLE_ITERATION_SIZE) { list($table_header, $table_data, $table_total_count) = self::getTable($partner_id, $report_type, $input_filter, $page_size, $page_index, $order_by, $object_ids); if ($input_filter instanceof endUserReportsInputFilter) { $table_total_count = self::getTotalTableCount($partner_id, $report_type, $input_filter, $page_size, $page_index, $order_by, $object_ids); } $csv = myCsvReport::createReport($report_title, $report_text, $headers, $report_type, $input_filter, $dimension, $arr, $total_header, $total_data, $table_header, $table_data, $table_total_count, $csv); $data = $csv->getData(); // return URLwq if (!file_exists(dirname($file_path))) { kFile::fullMkfileDir(dirname($file_path), 0777); } //adding BOM for fixing problem in open .csv file with special chars using excel. $BOM = ""; file_put_contents($file_path, $BOM . $data); } else { $tempCsv = new myCsvWrapper(); if (!$page_size || $page_size < 0) { $page_size = 10; } if (!$page_index || $page_index < 1) { $page_index = 1; } //checking if query is too big $table_amount = self::getTotalTableCount($partner_id, $report_type, $input_filter, $page_size, $page_index, $order_by, $object_ids); if ($table_amount > self::REPORTS_CSV_MAX_QUERY_SIZE && $page_size > self::REPORTS_CSV_MAX_QUERY_SIZE) { throw new kCoreException("Exceeded max query size: " . self::REPORTS_CSV_MAX_QUERY_SIZE, kCoreException::SEARCH_TOO_GENERAL); } $start_offest = ($page_index - 1) * $page_size; $end_offset = $start_offest + $page_size; $iteration_page_size = self::REPORTS_TABLE_RESULTS_SINGLE_ITERATION_SIZE; for ($current_offset = $start_offest; $current_offset < $end_offset; $current_offset = $current_offset + $iteration_page_size) { $offset_difference = $end_offset - $current_offset; if ($offset_difference < self::REPORTS_TABLE_RESULTS_SINGLE_ITERATION_SIZE) { $iteration_page_size = $offset_difference; } //here page_index is redundant list($table_header, $table_data, $table_total_count) = self::getTable($partner_id, $report_type, $input_filter, $iteration_page_size, $page_index, $order_by, $object_ids, $current_offset); if (!$table_data) { break; } //first iteration - create the beginning of the report if ($current_offset == $start_offest) { $csv = myCsvReport::createReport($report_title, $report_text, $headers, $report_type, $input_filter, $dimension, $arr, $total_header, $total_data, $table_header, $table_data, $table_amount, $csv); $data = $csv->getData(); // return URL if (!file_exists(dirname($file_path))) { kFile::fullMkfileDir(dirname($file_path), 0777); } //adding BOM for fixing problem in open .csv file with special chars using excel. $BOM = ""; file_put_contents($file_path, $BOM . $data); } else { //append data from query to file $tempCsv->clearData(); $tempCsv = myCsvReport::appendLines($tempCsv, $table_data); $data = $tempCsv->getData(); file_put_contents($file_path, $data, FILE_APPEND); } } } $url = self::createUrl($partner_id, $file_name); return $url; }
/** * will store the content of the report on disk and return the Url for the file * * @param string $partner_id * @param string $report_title * @param string $report_text * @param string $headers * @param int $report_type * @param reportsInputFilter $input_filter * @param string $dimension * @param string $object_ids * @param int $page_size * @param int $page_index * @param string $order_by */ public static function getUrlForReportAsCsv($partner_id, $report_title, $report_text, $headers, $report_type, reportsInputFilter $input_filter, $dimension = null, $object_ids = null, $page_size = 10, $page_index = 0, $order_by) { // create file_name // TODO - check if file already exists - if so - serve it if not expired list($file_name, $url) = self::createFileName($partner_id, $report_type, $input_filter, $dimension, $object_ids, $page_size, $page_index, $order_by); // TODO - remove comment and read from disk /* if ( file_exists ( $file_name ) ) { return $url; } */ $arr = self::getGraph($partner_id, $report_type, $input_filter, $dimension, $object_ids); list($total_header, $total_data) = self::getTotal($partner_id, $report_type, $input_filter, $object_ids); list($table_header, $table_data, $table_total_count) = self::getTable($partner_id, $report_type, $input_filter, $page_size, $page_index, $order_by, $object_ids); $data = myCsvReport::createReport($report_title, $report_text, $headers, $report_type, $input_filter, $dimension, $arr, $total_header, $total_data, $table_header, $table_data, $table_total_count); // return URL if (!file_exists(dirname($file_name))) { kFile::fullMkfileDir(dirname($file_name), 0777); } file_put_contents($file_name, $data); return $url; }