Skip to content

Commit

Permalink
Merge pull request #10 from PlasticStudio/feature/dms_documents
Browse files Browse the repository at this point in the history
Feature/dms documents
  • Loading branch information
monkeyfeet authored Mar 18, 2021
2 parents c0a8cc2 + 7d0af07 commit ec445ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/SearchPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@

use Page;
use SilverStripe\ORM\DB;
use SilverStripe\Versioned\Versioned;

class SearchPage extends Page {

private static $description = "Search engine and results page. You only need one of these page types.";

private static $defaults = [
'ShowInMenus' => 0,
'ShowInSearch' => 0
];

/**
* We need to have a SearchPage to use it
*/
public function requireDefaultRecords() {
public function requireDefaultRecords()
{
parent::requireDefaultRecords();

if (static::class == self::class && $this->config()->create_default_pages) {
if (!SearchPage::get()){
if (count(SearchPage::get()) < 1) {
$page = SearchPage::create();
$page->Title = 'Search';
$page->Content = '';
$page->ShowInMenus = false;
$page->ShowInSearch = false;
$page->write();
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$page->flushCache();
DB::alteration_message('Search page created', 'created');
}
Expand Down
5 changes: 5 additions & 0 deletions src/SearchPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ public function PerformSearch(){

// Remove duplicates
$allResults->removeDuplicates('ID');

// filter by permission
if($allResults) foreach($allResults as $result) {
if(!$result->canView()) $allResults->remove($result);
}

// load into a paginated list. To change the items per page, set via the template (ie Results.setPageLength(20))
$paginatedItems = PaginatedList::create($allResults, $this->request);
Expand Down

0 comments on commit ec445ea

Please sign in to comment.