for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Banner Model
*
* @package TheyWorkForYou
*/
namespace MySociety\TheyWorkForYou\Model;
class Banner {
* DB handle
private $db;
/*
* Memcache handle
private $mem;
public function __construct()
{
$this->db = new \ParlDB;
$this->mem = new \MySociety\TheyWorkForYou\Memcache();
}
public function get_text() {
$text = $this->mem->get('banner');
if ( $text === false ) {
$text === false
true
$q = $this->db->query("SELECT value FROM editorial WHERE item = 'banner'")->first();
if ($q) {
$text = $q['value'];
if ( trim($text) == '' ) {
$text = NULL;
$this->mem->set('banner', $text, 86400);
return $text;
public function set_text($text) {
$q = $this->db->query("REPLACE INTO editorial set item = 'banner', value = :banner_text",
array(
':banner_text' => $text
)
);
if ( $q->success() ) {
return true;
return false;