Permalink
Browse files

search action for topics

Add a search_string to a topic and associated action for searching for
more content on TWFY.
  • Loading branch information...
struan committed Feb 23, 2017
1 parent 3d0ae92 commit be4f1a8b393c1f8fd6b783ebadcd5a75d75cbb78
Showing with 42 additions and 4 deletions.
  1. +16 −2 classes/Topic.php
  2. +2 −2 classes/Topics.php
  3. +1 −0 db/0011-add-topics-tables.sql
  4. +1 −0 db/schema.sql
  5. +5 −0 www/docs/admin/edittopic.php
  6. +17 −0 www/docs/topic/topic.php
View
@@ -19,6 +19,7 @@ class Topic {
private $title;
private $slug;
private $description;
private $search_string;
/**
* Constructor
@@ -38,6 +39,7 @@ public function __construct($data = NULL)
$this->title = $data['title'];
$this->slug = $data['slug'];
$this->description = $data['description'];
$this->search_string = $data['search_string'];
}
@@ -80,6 +82,14 @@ function set_description($description) {
$this->description = $description;
}
function search_string() {
return $this->search_string;
}
function set_search_string($search_string) {
$this->search_string = $search_string;
}
function getContent() {
$q = $this->db->query(
"SELECT body, gid, ep.epobject_id FROM epobject ep JOIN hansard h on ep.epobject_id = h.epobject_id
@@ -183,12 +193,16 @@ function addPolicySets($sets) {
function save() {
$q = $this->db->query(
"REPLACE INTO topics (id, title, slug, description) VALUES(:id, :title, :slug, :description)",
"REPLACE INTO topics
(id, title, slug, description, search_string)
VALUES
(:id, :title, :slug, :description, :search_string)",
array(
':id' => $this->id,
':slug' => $this->slug(),
':title' => $this->title(),
':description' => $this->description()
':description' => $this->description(),
':search_string' => $this->search_string()
)
);
View
@@ -25,7 +25,7 @@ public function __construct()
}
public function getTopics() {
$q = $this->db->query("SELECT id, slug, title, description FROM topics");
$q = $this->db->query("SELECT id, slug, title, description, search_string FROM topics");
$topics = array();
$count = $q->rows();
@@ -39,7 +39,7 @@ public function getTopics() {
public function getTopic($topic_name) {
$q = $this->db->query(
"SELECT id, slug, title, description FROM topics WHERE slug = :slug",
"SELECT id, slug, title, description, search_string FROM topics WHERE slug = :slug",
array(':slug' => $topic_name)
);
if ($q->rows) {
@@ -3,6 +3,7 @@ CREATE TABLE `topics` (
`slug` varchar(100) NOT NULL,
`title` text NOT NULL,
`description` text,
`search_string` text,
PRIMARY KEY (`id`),
UNIQUE KEY `slug` (`slug`)
);
View
@@ -524,6 +524,7 @@ CREATE TABLE `topics` (
`slug` varchar(100) NOT NULL,
`title` text NOT NULL,
`description` text,
`search_string` text,
PRIMARY KEY (`id`),
UNIQUE KEY `slug` (`slug`)
);
@@ -57,6 +57,10 @@
<label for="title">Title:</label> <input id="title" name="title" value="<?= $topic->title() ?>">
</p>
<p>
<label for="search_string">Search string:</label> <input id="search_string" name="search_string" value="<?= $topic->search_string() ?>">
</p>
<p>
<label for="description">Description</label><br>
<textarea id="description" rows="5" name="description"><?= $topic->description() ?></textarea>
@@ -116,6 +120,7 @@ function update_topic($topic) {
$topic->set_title(get_http_var('title'));
$topic->set_description(get_http_var('description'));
$topic->set_front_page(get_http_var('front_page'));
$topic->set_search_string(get_http_var('search_string'));
return $topic->save();
}
View
@@ -37,6 +37,23 @@
$data['actions'] = $topic->getContent();
$DATA->set_page_metadata('topic', 'title', $topic->title());
if ($topic->search_string()) {
$search = urlencode($topic->search_string());
$data['actions'][] = array(
'title' => 'Search the whole site',
'icon' => 'search',
'href' => 'https://www.theyworkforyou.com/search/?s=%22' . $search . '%22',
'description' => 'Search TheyWorkForYou to find mentions of ' . $topic->search_string() . '. You may also filter your results by time, speaker and section.'
);
$data['actions'][] = array(
'title' => 'Sign up for email alerts',
'icon' => 'alert',
'href' => 'https://www.theyworkforyou.com/alert/?alertsearch=%22' . $search . '%22',
'description' => 'We&rsquo;ll let you know every time ' . $topic->search_string() . ' are mentioned in Parliament.'
);
}
// Is there a specified set of policy positions to worry about?
if ($policySets) {

0 comments on commit be4f1a8

Please sign in to comment.