Skip to content

Commit 5378f4d

Browse files
committed
Added an option to set each simple page searchable or not.
1 parent ce76cbe commit 5378f4d

6 files changed

Lines changed: 41 additions & 6 deletions

File tree

SimplePagesPlugin.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function hookInstall()
4848
`modified_by_user_id` int(10) unsigned NOT NULL,
4949
`created_by_user_id` int(10) unsigned NOT NULL,
5050
`is_published` tinyint(1) NOT NULL,
51+
`is_searchable` tinyint(1) NOT NULL,
5152
`title` tinytext COLLATE utf8_unicode_ci NOT NULL,
5253
`slug` tinytext COLLATE utf8_unicode_ci NOT NULL,
5354
`text` mediumtext COLLATE utf8_unicode_ci,
@@ -67,12 +68,13 @@ public function hookInstall()
6768
KEY `parent_id` (`parent_id`)
6869
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
6970
$db->query($sql);
70-
71+
7172
// Save an example page.
7273
$page = new SimplePagesPage;
7374
$page->modified_by_user_id = current_user()->id;
7475
$page->created_by_user_id = current_user()->id;
7576
$page->is_published = 1;
77+
$page->is_searchable = 1;
7678
$page->parent_id = 0;
7779
$page->title = 'About';
7880
$page->slug = 'about';
@@ -154,6 +156,22 @@ public function hookUpgrade($args)
154156
if ($oldVersion < '3.0.2') {
155157
$db->query("ALTER TABLE `$db->SimplePagesPage` MODIFY `text` MEDIUMTEXT COLLATE utf8_unicode_ci");
156158
}
159+
160+
if ($oldVersion < '3.0.4') {
161+
// Check if "is_searchable" exists, because the patch is rebased.
162+
$sql = "SHOW columns FROM `$db->SimplePagesPage` WHERE `Field` = 'is_searchable';";
163+
$result = $db->query($sql)->fetchAll();
164+
if (empty($result)) {
165+
$sql = "
166+
ALTER TABLE `$db->SimplePagesPage`
167+
ADD `is_searchable` tinyint(1) NOT NULL AFTER `is_published`
168+
";
169+
$db->query($sql);
170+
// Set all existing pages as searchable.
171+
$sql = "UPDATE `$db->SimplePagesPage` SET `is_searchable` = '1';";
172+
$db->query($sql);
173+
}
174+
}
157175
}
158176

159177
/**

controllers/IndexController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ protected function _getForm($page = null)
148148
$form->addElement('sessionCsrfToken', 'csrf_token');
149149
}
150150

151+
$form->addElementToSaveGroup(
152+
'checkbox', 'is_searchable',
153+
array(
154+
'id' => 'simple_pages_is_searchable',
155+
'values' => array(1, 0),
156+
'checked' => $page->is_searchable,
157+
'label' => __('Is this page searchable?'),
158+
'description' => __('Checking this box will make this page searchable')
159+
)
160+
);
161+
151162
return $form;
152163
}
153164

models/Api/SimplePagesPage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public function getRepresentation(Omeka_Record_AbstractRecord $record)
88
'id' =>$record->id,
99
'url' => $this->getResourceUrl("/simple_pages/{$record->id}"),
1010
'is_published' => (bool)$record->is_published,
11+
'is_searchable' => (bool)$record->is_searchable,
1112
'title' => $record->title,
1213
'slug' => $record->slug,
1314
'text' => $record->text,

models/SimplePagesPage.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class SimplePagesPage extends Omeka_Record_AbstractRecord implements Zend_Acl_Re
1616
public $modified_by_user_id;
1717
public $created_by_user_id;
1818
public $is_published = 0;
19+
// A page is searchable by default.
20+
public $is_searchable = 1;
1921
public $title;
2022
public $slug;
2123
public $text = null;
@@ -116,12 +118,14 @@ protected function beforeSave($args)
116118

117119
protected function afterSave($args)
118120
{
119-
if (!$this->is_published) {
121+
if (!$this->is_published || !$this->is_searchable) {
120122
$this->setSearchTextPrivate();
121123
}
122-
$this->setSearchTextTitle($this->title);
123-
$this->addSearchText($this->title);
124-
$this->addSearchText($this->text);
124+
if ($this->is_searchable) {
125+
$this->setSearchTextTitle($this->title);
126+
$this->addSearchText($this->title);
127+
$this->addSearchText($this->text);
128+
}
125129
}
126130

127131
/**

models/SimplePagesPageTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function applySearchFilters($select, $params)
2929
$alias = $this->getTableAlias();
3030
$paramNames = array('parent_id',
3131
'is_published',
32+
'is_searchable',
3233
'title',
3334
'slug',
3435
'created_by_user_id',

plugin.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ link="http://omeka.org/codex/Plugins/SimplePages_2.0"
77
support_link="http://omeka.org/forums/forum/plugins"
88
omeka_minimum_version="2.2"
99
omeka_target_version="2.2"
10-
version="3.0.3"
10+
version="3.0.4"

0 commit comments

Comments
 (0)