Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion SimplePagesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function hookInstall()
`modified_by_user_id` int(10) unsigned NOT NULL,
`created_by_user_id` int(10) unsigned NOT NULL,
`is_published` tinyint(1) NOT NULL,
`is_searchable` tinyint(1) NOT NULL,
`title` tinytext COLLATE utf8_unicode_ci NOT NULL,
`slug` tinytext COLLATE utf8_unicode_ci NOT NULL,
`text` mediumtext COLLATE utf8_unicode_ci,
Expand All @@ -67,12 +68,13 @@ public function hookInstall()
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
$db->query($sql);

// Save an example page.
$page = new SimplePagesPage;
$page->modified_by_user_id = current_user()->id;
$page->created_by_user_id = current_user()->id;
$page->is_published = 1;
$page->is_searchable = 1;
$page->parent_id = 0;
$page->title = 'About';
$page->slug = 'about';
Expand Down Expand Up @@ -154,6 +156,22 @@ public function hookUpgrade($args)
if ($oldVersion < '3.0.2') {
$db->query("ALTER TABLE `$db->SimplePagesPage` MODIFY `text` MEDIUMTEXT COLLATE utf8_unicode_ci");
}

if ($oldVersion < '3.0.4') {
// Check if "is_searchable" exists, because the patch is rebased.
$sql = "SHOW columns FROM `$db->SimplePagesPage` WHERE `Field` = 'is_searchable';";
$result = $db->query($sql)->fetchAll();
if (empty($result)) {
$sql = "
ALTER TABLE `$db->SimplePagesPage`
ADD `is_searchable` tinyint(1) NOT NULL AFTER `is_published`
";
$db->query($sql);
// Set all existing pages as searchable.
$sql = "UPDATE `$db->SimplePagesPage` SET `is_searchable` = '1';";
$db->query($sql);
}
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ protected function _getForm($page = null)
$form->addElement('sessionCsrfToken', 'csrf_token');
}

$form->addElementToSaveGroup(
'checkbox', 'is_searchable',
array(
'id' => 'simple_pages_is_searchable',
'values' => array(1, 0),
'checked' => $page->is_searchable,
'label' => __('Is this page searchable?'),
'description' => __('Checking this box will make this page searchable')
)
);

return $form;
}

Expand Down
1 change: 1 addition & 0 deletions models/Api/SimplePagesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public function getRepresentation(Omeka_Record_AbstractRecord $record)
'id' =>$record->id,
'url' => $this->getResourceUrl("/simple_pages/{$record->id}"),
'is_published' => (bool)$record->is_published,
'is_searchable' => (bool)$record->is_searchable,
'title' => $record->title,
'slug' => $record->slug,
'text' => $record->text,
Expand Down
12 changes: 8 additions & 4 deletions models/SimplePagesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class SimplePagesPage extends Omeka_Record_AbstractRecord implements Zend_Acl_Re
public $modified_by_user_id;
public $created_by_user_id;
public $is_published = 0;
// A page is searchable by default.
public $is_searchable = 1;
public $title;
public $slug;
public $text = null;
Expand Down Expand Up @@ -116,12 +118,14 @@ protected function beforeSave($args)

protected function afterSave($args)
{
if (!$this->is_published) {
if (!$this->is_published || !$this->is_searchable) {
$this->setSearchTextPrivate();
}
$this->setSearchTextTitle($this->title);
$this->addSearchText($this->title);
$this->addSearchText($this->text);
if ($this->is_searchable) {
$this->setSearchTextTitle($this->title);
$this->addSearchText($this->title);
$this->addSearchText($this->text);
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions models/SimplePagesPageTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function applySearchFilters($select, $params)
$alias = $this->getTableAlias();
$paramNames = array('parent_id',
'is_published',
'is_searchable',
'title',
'slug',
'created_by_user_id',
Expand Down