datatable.directory codebase
				https://datatable.directory/
			
			
		
			選択できるのは25トピックまでです。
			トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
		
		
		
		
		
			
		
			
				
					
					
						
							52 行
						
					
					
						
							1.0 KiB
						
					
					
				
			
		
		
	
	
							52 行
						
					
					
						
							1.0 KiB
						
					
					
				<?php
 | 
						|
 | 
						|
 | 
						|
namespace App\Tables;
 | 
						|
 | 
						|
 | 
						|
class CsvExporter extends BaseExporter
 | 
						|
{
 | 
						|
    private $delimiter = ',';
 | 
						|
 | 
						|
    public function withDelimiter($delimiter)
 | 
						|
    {
 | 
						|
        $this->delimiter = $delimiter;
 | 
						|
        return $this;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return string - mime type for the downloaded file
 | 
						|
     */
 | 
						|
    protected function getMimeType()
 | 
						|
    {
 | 
						|
        return $this->wantDownload ? 'text/csv' : 'text/plain';
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * @return string - file extension for the downloaded file
 | 
						|
     */
 | 
						|
    protected function getFileExtension()
 | 
						|
    {
 | 
						|
        return 'csv';
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Write the document to stdout ('php://output')
 | 
						|
     */
 | 
						|
    protected function writeDocument()
 | 
						|
    {
 | 
						|
        $handle = fopen('php://output', 'w');
 | 
						|
 | 
						|
        $columnNames = array_map(function (Column $c) {
 | 
						|
            return $c->title;
 | 
						|
        }, $this->columns);
 | 
						|
 | 
						|
        fputcsv($handle, $columnNames, $this->delimiter);
 | 
						|
 | 
						|
        foreach ($this->iterateRows() as $row) {
 | 
						|
            fputcsv($handle, array_values($row), $this->delimiter);
 | 
						|
        }
 | 
						|
 | 
						|
        fclose($handle);
 | 
						|
    }
 | 
						|
}
 | 
						|
 |