-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redirect gid for featured debate if required
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
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters