-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from chrometoasters/pulls/taxonomies-overview
Add Taxonomies overview feature
- Loading branch information
Showing
11 changed files
with
238 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Chrometoaster\AdvancedTaxonomies\Controllers; | ||
|
||
use Chrometoaster\AdvancedTaxonomies\Models\TaxonomyTerm; | ||
use SilverStripe\Control\Controller; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\View\ArrayData; | ||
|
||
/** | ||
* Class TaxonomyDirectoryController | ||
* | ||
* Controller for returning a list of pages tagged with a specific Taxonomy Term | ||
*/ | ||
class TaxonomyOverviewController extends Controller | ||
{ | ||
private static $url_handlers = [ | ||
'$ParentID' => 'index', | ||
]; | ||
|
||
private static $allowed_actions = [ | ||
'index', | ||
]; | ||
|
||
|
||
/** | ||
* Render a hierarchy | ||
* | ||
* @param HTTPRequest $request | ||
* @return \SilverStripe\ORM\FieldType\DBHTMLText | ||
*/ | ||
public function index(HTTPRequest $request) | ||
{ | ||
$parentID = (int) $request->param('ParentID'); // empty param is the same as 0 for the sake of this report | ||
|
||
$terms = TaxonomyTerm::get()->filter(['ParentID' => $parentID]); | ||
|
||
$parentTerm = null; | ||
if ($parentID) { | ||
$parentTerm = TaxonomyTerm::get()->byID($parentID); | ||
} | ||
|
||
return $this->customise(ArrayData::create([ | ||
'Terms' => $terms, | ||
'ParentTerm' => ($parentTerm && $parentTerm->exists()) ? $parentTerm : false, | ||
]))->renderWith(self::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Chrometoaster\AdvancedTaxonomies\Forms; | ||
|
||
use SilverStripe\Forms\GridField\GridField; | ||
use SilverStripe\Forms\GridField\GridField_HTMLProvider; | ||
use SilverStripe\View\ArrayData; | ||
|
||
/** | ||
* A button that contains a link to additional information | ||
*/ | ||
class GridFieldInfoLink implements GridField_HTMLProvider | ||
{ | ||
/** | ||
* Gridfield fragment | ||
* | ||
* @var string | ||
*/ | ||
protected $targetFragment; | ||
|
||
/** | ||
* Destination URL | ||
* | ||
* @var string | ||
*/ | ||
protected $url; | ||
|
||
/** | ||
* Button label | ||
* | ||
* @var string | ||
*/ | ||
protected $caption; | ||
|
||
|
||
/** | ||
* GridFieldInfoLink constructor. | ||
* | ||
* @param string $targetFragment | ||
* @param string $url | ||
* @param string $label | ||
*/ | ||
public function __construct(string $targetFragment, string $url, string $label) | ||
{ | ||
$this->targetFragment = $targetFragment; | ||
$this->url = $url; | ||
$this->label = $label; | ||
} | ||
|
||
|
||
/** | ||
* @param GridField $gridField | ||
* @return array | ||
*/ | ||
public function getHTMLFragments($gridField) | ||
{ | ||
$fragment = ArrayData::create([ | ||
'Url' => $this->url, | ||
'Label' => $this->label, | ||
])->renderWith(self::class); | ||
|
||
return [$this->targetFragment => $fragment]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
templates/Chrometoaster/AdvancedTaxonomies/Controllers/TaxonomyOverviewController.ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<!--[if IE 9]><html class="ie ie9 lt-ie10" lang="en"><![endif]--> | ||
<!--[if !IE]><!--> | ||
<html lang="en"><!--<![endif]--> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Advanced Taxonomies overview</title> | ||
|
||
<style> | ||
table { | ||
border-collapse: collapse; | ||
} | ||
|
||
thead { | ||
background-color: #eee; | ||
} | ||
|
||
th, td { | ||
border: 1px solid #ccc; | ||
text-align: left; | ||
padding: 4px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>Taxonomies overview</h1> | ||
<% if $ParentTerm %><p>Parent term: <strong>{$ParentTerm.Title}</strong></p><% end_if %> | ||
|
||
<% include Chrometoaster\AdvancedTaxonomies\Controllers\TaxonomyOverviewController_Terms %> | ||
</body> | ||
|
||
</html> |
14 changes: 14 additions & 0 deletions
14
templates/Chrometoaster/AdvancedTaxonomies/Controllers/TaxonomyOverviewController_TermRow.ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<% loop $Terms.Sort('Sort') %> | ||
<tr> | ||
<% if $TermLevel == 0 %> | ||
<td><strong>{$Name}</strong></td> | ||
<% else %> | ||
<td><% loop $TermLevelList %> - <% end_loop %>{$Name}</td> | ||
<% end_if %> | ||
<td>{$Description}</td> | ||
<td>{$AuthorDefinition}</td> | ||
</tr> | ||
<% if $Children.count %> | ||
<% include Chrometoaster\AdvancedTaxonomies\Controllers\TaxonomyOverviewController_TermRow Terms=$Children %> | ||
<% end_if %> | ||
<% end_loop %> |
12 changes: 12 additions & 0 deletions
12
templates/Chrometoaster/AdvancedTaxonomies/Controllers/TaxonomyOverviewController_Terms.ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Term</th> | ||
<th>Description</th> | ||
<th>Author definition</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% include Chrometoaster\AdvancedTaxonomies\Controllers\TaxonomyOverviewController_TermRow %> | ||
</tbody> | ||
</table> |
5 changes: 5 additions & 0 deletions
5
templates/Chrometoaster/AdvancedTaxonomies/Forms/GridFieldInfoLink.ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<a class="btn btn-secondary" href="{$Url.ATT}" target="_blank"> | ||
<span class="btn__title"> | ||
<span class="at-link-external">{$Label.XML}</span> | ||
</span> | ||
</a> |