Skip to content

Commit

Permalink
Merge branch 'release/1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jflearn committed Sep 7, 2023
2 parents aa1a56d + dda6faa commit 8fa4b3d
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 31 deletions.
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
# silverstripe-imagegallery
# silverstripe-faqpage

A module for the SilverStripe CMS which allows you to display a bunch of images
in a gallery format.
A module for the SilverStripe CMS which allows you to present a searchable list
of frequently asked questions.

## Why?

We needed a simple way to present a set of images that can be easily navigated
on any device.
We needed a simple way to present a set of searchable list of question/answer
pairs.

## Installation

```sh
composer require "logicbrush/silverstripe-imagegallery"
composer require "logicbrush/silverstripe-faqpage"
```

## Usage

Install the module and you'll have a new page type of "Gallery Page". You can
add and reorder images to the page from the "Images" tab in the CMS.
Install the module and you'll have a new page type of "FAQ Page". You can
add child "Question" pages and manage them independently.

In addition, this module provides a widget for displaying a gallery in a
sidebar. Add it to your WidgetArea and select the gallery you wish to display.


## Configuration

Select which column to sort the images by, via the "Sort By" dropdown.
Selecting "Newest First" will sort the images by "Created" in DESC order.
Selecting "Position" will sort the images by "SortOrder" in ASC order.

Reordering the images manually will only have effect if "Position" is selected.
5 changes: 5 additions & 0 deletions client/dist/css/faq.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.faq-section-heading.hidden,
.faq-table-of-contents>li.hidden,
.faq-table-of-contents>li>.content.hidden {
display: none;
}
40 changes: 40 additions & 0 deletions client/dist/js/faq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
jQuery(document).ready(function() {

/** FAQ filtering... **/
jQuery('.faq-filter-form').on('submit', function(e) {
e.preventDefault();
});
jQuery('.faq-filter').on('keyup.faq-filter, change.faq-filter', function() {
var searchVal = jQuery(this).val().toLowerCase();
var faqTableOfContents = jQuery('.faq-table-of-contents');
var filterItems = faqTableOfContents.find('li');
var faqHeadings = jQuery('.faq-section-heading');

filterItems.removeClass('hidden');
faqHeadings.removeClass('hidden');

if (searchVal != '') {
filterItems.each(function() {
var itemContent = jQuery(this).text().toLowerCase();
if (itemContent.indexOf(searchVal) < 0) {
jQuery(this).addClass('hidden');
}
});
}

faqTableOfContents.each(function() {
if ($(this).find('> li.hidden').length === $(this).find('> li').length) {
jQuery(this).prev('.faq-section-heading').addClass('hidden');
}
});
}).trigger('change.faq-filter');

/** Accordian behavior... */
jQuery('.faq-table-of-contents>li>a').each(function() {
$(this).on('click', function() {
$(this).next().toggleClass('hidden');
return false;
});
});

});
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"php": "^7.4||^8.0",
"silverstripe/cms": "^4.0",
"silverstripe/lumberjack": "^2.3",
"silverstripe/tagfield": "^2.11",
"symbiote/silverstripe-gridfieldextensions": "^3.6"
},
"require-dev": {
Expand All @@ -36,9 +37,7 @@
},
"extra": {
"expose": [
"css",
"images",
"javascript"
"client/dist"
]
},
"config": {
Expand Down
24 changes: 16 additions & 8 deletions src/Model/FAQPage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* src/Model/FAQPage.php
*
* @package default
*/


namespace Logicbrush\FAQPage\Model;

Expand All @@ -18,19 +24,18 @@
use Symbiote\GridFieldExtensions\GridFieldAddNewInlineButton;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\ORM\FieldType\DBField;


use SilverStripe\View\Requirements;

class FAQPage extends Page {

private static string $icon = 'mysite/images/treeicons/faq-page.png';
private static string $icon_class = 'font-icon-chat';
private static string $description = 'An faq page that rolls up content from its question children pages.';
private static string $singular_name = 'FAQ';
private static string $plural_name = 'FAQs';
private static $table_name = 'FAQPage';

private static array $allowed_children = [
'Question'
Question::class,
];

private static array $extensions = [
Expand Down Expand Up @@ -127,6 +132,9 @@ class FAQPageController extends PageController {
*/
public function index() {

Requirements::javascript( 'logicbrush/silverstripe-faqpage:client/dist/js/faq.js' );
Requirements::css( 'logicbrush/silverstripe-faqpage:client/dist/css/faq.css' );

$content = $this->AdvancedContent( Question::get()->filter( ['ParentID' => $this->ID] ), false, false );

return [
Expand Down Expand Up @@ -191,11 +199,11 @@ public function Other() {
*/
private function AdvancedContent( $questions = [], $hideForm = false, $isTag = false ) {

$searchText = $this->request->getVar( 'search' );
$searchText = $this->request->getVar( 'search' ) ?? '';

if ( ! $hideForm ) {
$content = $this->Content;
$content = '<form class="faq-filter-form"><input class="faq-filter" placeholder="Enter keywords..." value="' . htmlentities( $searchText ) . '" /></form>';
$content = '<form class="faq-filter-form"><input type="text" class="faq-filter" placeholder="Search the FAQ..." value="' . htmlentities( $searchText ) . '" /></form>';
} else {
$content = '<h2>' . htmlentities( $this->Title ) . '</h2>';
}
Expand All @@ -207,7 +215,7 @@ private function AdvancedContent( $questions = [], $hideForm = false, $isTag = f

foreach ( $this->Tags() as $tag ) {
if ( $tag->Questions()->count() ) {
$content .= '<h2 class="faq-section-heading"><a href="' . $tag->Link() . '">' . $tag->Title . '</a></h2>';
$content .= '<h2 class="faq-section-heading">' . $tag->Title . '</h2>';
$content .= $this->QuestionsContent( $tag->Questions() );
}
}
Expand Down Expand Up @@ -236,7 +244,7 @@ private function QuestionsContent( $questions = [] ) {
$questionContent = $question->hasMethod( 'Content' ) ? $question->Content() : $question->Content;
if ( $questionContent ) {
$content .= '<li><a href="' . $question->Link() . '">' . $question->MenuTitle . '</a>';
$content .= '<div class="content">';
$content .= '<div class="content hidden">';
$content .= $questionContent;
$content .= '</div>';
$content .= '</li>';
Expand Down
8 changes: 7 additions & 1 deletion src/Model/Question.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* src/Model/Question.php
*
* @package default
*/


namespace Logicbrush\FAQPage\Model;

Expand All @@ -8,7 +14,7 @@

class Question extends Page {

private static string $icon = 'mysite/images/treeicons/question-page.png';
private static string $icon_class = 'font-icon-comment';
private static string $description = 'An faq question page.';
private static string $singular_name = 'Question';
private static string $plural_name = 'Questions';
Expand Down
6 changes: 6 additions & 0 deletions src/Model/QuestionTag.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/**
* src/Model/QuestionTag.php
*
* @package default
*/


namespace Logicbrush\FAQPage\Model;

Expand Down
9 changes: 8 additions & 1 deletion tests/QuestionTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php
/**
* tests/QuestionTest.php
*
* @package default
*/


namespace Logicbrush\FAQPage\Tests;


use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Control\Director;
use Logicbrush\FAQPage\Model\FAQPage;
use Logicbrush\FAQPage\Model\Question;
use Logicbrush\FAQPage\Model\QuestionTag;

Expand Down Expand Up @@ -100,7 +107,7 @@ public function testQuestionTagLink() {
$questionTag->write();

$this->assertEquals( '/faqs/tag/the-future-is-female', $questionTag->Link() );
$this->assertEquals( Director::config()->alternate_base_url . 'faqs/tag/the-future-is-female', $questionTag->AbsoluteLink() );
$this->assertEquals( 'http://localhost/faqs/tag/the-future-is-female', $questionTag->AbsoluteLink() );
}


Expand Down

0 comments on commit 8fa4b3d

Please sign in to comment.