Skip to content

Commit

Permalink
Merge pull request #274 from jeanbez/fix-268
Browse files Browse the repository at this point in the history
this fixes #268 and remove pagination download
  • Loading branch information
gmarkomanolis authored May 8, 2024
2 parents c7e4849 + af7e07e commit 1ac1c50
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 87 deletions.
63 changes: 41 additions & 22 deletions src/Controller/ListingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public function list($bof = null, $url = null)
*/
public function download($bof = null, $url = null)
{
$limit = Configure::read('IO500.pagination');

$db = ConnectionManager::get('default');

// Create a schema collection.
Expand All @@ -105,17 +103,41 @@ public function download($bof = null, $url = null)
// Get columns list from table
$columns = $tableSchema->columns();

$release = $this->Listings->Releases->find('all')
->contain([
'Listings' => [
'Types',
],
])
->where([
'Releases.release_date <=' => date('Y-m-d'),
'Releases.acronym' => strtoupper($bof),
])
->first();
// If empty $bof get the last released one
if ($bof == null) {
$release = $this->Listings->Releases->find('all')
->contain([
'Listings' => [
'Types',
],
])
->where([
'Releases.release_date <=' => date('Y-m-d')
])
->order([
'Releases.release_date' => 'DESC'
])
->first();

$bof = $release->acronym;
} else {
$release = $this->Listings->Releases->find('all')
->contain([
'Listings' => [
'Types',
],
])
->where([
'Releases.release_date <=' => date('Y-m-d'),
'Releases.acronym' => strtoupper($bof),
])
->first();
}

// If empty $url get the historical one
if ($url == null) {
$url = 'historical';
}

$listing = $this->Listings->find('all')
->contain([
Expand All @@ -127,15 +149,11 @@ public function download($bof = null, $url = null)
'Releases.release_date <=' => date('Y-m-d'),
'Releases.acronym' => strtoupper($bof),
])
->order([
'Releases.release_date' => 'DESC'
])
->first();

$settings = [
'order' => [
'score' => 'DESC',
],
'limit' => $limit,
];

if (isset($this->request->getParam('?')['sort'])) {
$settings['sortWhitelist'][] = $this->request->getParam('?')['sort'];
}
Expand All @@ -148,10 +166,11 @@ public function download($bof = null, $url = null)
])
->where([
'ListingsSubmissions.listing_id' => $listing->id,
])
->order([
'ListingsSubmissions.score' => 'DESC'
]);

$submissions = $this->paginate($submissions, $settings);

$records = [];

foreach ($submissions as $i => $submission) {
Expand Down
67 changes: 4 additions & 63 deletions src/Controller/SubmissionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function graphs()
$submissions = $this->Submissions->find('all')
->where([
'LOWER(Submissions.information_list_name) IN' => $lists,
'Submissions.status' => 'VALID',
'Submissions.status_id' => 3,
]);

$this->set('lists', $lists);
Expand All @@ -143,7 +143,7 @@ public function ior()
$submissions = $this->Submissions->find('all')
->where([
'LOWER(Submissions.information_list_name) IN' => $lists,
'Submissions.status' => 'VALID',
'Submissions.status_id' => 3,
]);

$this->set('lists', $lists);
Expand All @@ -168,7 +168,7 @@ public function mdtest()
$submissions = $this->Submissions->find('all')
->where([
'LOWER(Submissions.information_list_name) IN' => $lists,
'Submissions.status' => 'VALID',
'Submissions.status_id' => 3,
]);

$this->set('lists', $lists);
Expand All @@ -193,7 +193,7 @@ public function pfind()
$submissions = $this->Submissions->find('all')
->where([
'LOWER(Submissions.information_list_name) IN' => $lists,
'Submissions.status' => 'VALID',
'Submissions.status_id' => 3,
]);

$this->set('lists', $lists);
Expand Down Expand Up @@ -423,63 +423,4 @@ public function customize($bof = null, $url = null)
$this->set('valid', $valid);
$this->set('submissions', $submissions);
}

/**
* Export method
*
* @return \Cake\Http\Response|null|void Downloads a CSV
*/
public function export()
{
$db = ConnectionManager::get('default');

// Create a schema collection.
$collection = $db->getSchemaCollection();

// Get a single table (instance of Schema\TableSchema)
$tableSchema = $collection->describe('submissions');

// Get columns list from table
$columns = $tableSchema->columns();

$releases = $this->Submissions->Releases->find('all')
->where([
'Releases.release_date <=' => date('Y-m-d'),
])
->order([
'Releases.release_date' => 'DESC',
]);

$records = [];

foreach ($releases as $release) {
$submissions = $this->Submissions->find('all')
->where([
'Submissions.information_submission_date <=' => $release->release_date->format('Y-m-d'),
'Submissions.valid_from <=' => $release->release_date,
'OR' => [
'Submissions.valid_to IS NULL',
'Submissions.valid_to >=' => $release->release_date,
],
'Submissions.status' => 'VALID',
])
->order([
'Submissions.io500_score' => 'DESC',
]);

foreach ($submissions as $submission) {
$submission['release_id'] = $release->acronym;
$records[] = $submission;
}
}

$this->set(compact('records'));
$this->setResponse($this->getResponse()->withDownload('io500-full-list.csv'));
$this->viewBuilder()
->setClassName('CsvView.Csv')
->setOptions([
'header' => $columns,
'serialize' => 'records',
]);
}
}
4 changes: 2 additions & 2 deletions templates/Releases/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<p>
You can <?php
echo $this->Html->link(__('download the CSV-file'), [
'controller' => 'submissions',
'action' => 'export'
'controller' => 'listings',
'action' => 'download'
],
[
'class' => 'link'
Expand Down

0 comments on commit 1ac1c50

Please sign in to comment.