Пример #1
0
 public function testConstruct()
 {
     $dataset = uniqid();
     $format = uniqid();
     $download = new Download($dataset, $format);
     $this->assertEquals($dataset, $download->getDataset());
     $this->assertEquals($format, $download->getFormat());
     $this->assertCount(2, $download->getParameters());
 }
 /**
  * @param string $dataset
  * @param string $_format
  * @param string $query
  *
  * @return Response
  */
 public function downloadAction($dataset, $_format, $query)
 {
     $response = new Response();
     $download = new Download($dataset, $_format);
     $download->setFilter($query);
     $local = $this->getLocalDataset($download);
     if (null !== $local) {
         $results = $local;
     } else {
         $results = $this->download($download);
     }
     switch (strtolower($_format)) {
         case 'json':
             $results = json_encode($results);
             break;
         case 'csv':
             $response->headers->set('Content-Type', 'text/csv');
             break;
     }
     $response->setContent($results);
     $response->headers->set('Content-Disposition', sprintf('attachment; filename="%s.%s"', $dataset, $_format));
     return $response;
 }
 /**
  * @param Download $download
  *
  * @return null|string
  */
 public function getLocalDatasetContent(Download $download)
 {
     $content = null;
     $filepath = $this->finder->findDataset($download->getDataset(), $download->getFormat(), $download->getFilter());
     if (false !== $filepath) {
         $content = $this->finder->getContent($filepath);
     }
     return $content;
 }