Skip to content

Commit

Permalink
Redirect gid for featured debate if required
Browse files Browse the repository at this point in the history
Make sure that if the gid for the featured debate has been redirected we
follow it rather than displaying nothing.

Fixes #873
  • Loading branch information
struan committed Jul 22, 2015
1 parent 7066f7a commit 9c924a8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions classes/Gid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace MySociety\TheyWorkForYou;

class Gid {

public $gid;
private $db;

public function __construct($gid) {
$this->gid = $gid;
$this->db = new \ParlDB;
}

public function checkForRedirect() {
$q = $this->db->query(
"SELECT gid_to FROM gidredirect WHERE gid_from = :gid",
array(':gid' => $this->gid)
);

if ($q->rows() == 0) {
return $this->gid;
} else {
do {
$gid = $q->field(0, 'gid_to');
$q = $this->db->query(
"SELECT gid_to FROM gidredirect WHERE gid_from = :gid",
array(':gid' => $gid)
);
} while ($q->rows() > 0);
return $gid;
}
}
}
2 changes: 2 additions & 0 deletions classes/Homepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ protected function getEditorialContent() {
$debatelist = new \DEBATELIST;
$featured = new Model\Featured;
$gid = $featured->get_gid();
$gidCheck = new Gid($gid);
$gid = $gidCheck->checkForRedirect();
if ( $gid ) {
$title = $featured->get_title();
$context = $featured->get_context();
Expand Down

0 comments on commit 9c924a8

Please sign in to comment.