-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
119 additions
and
9 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,69 @@ | ||
<?php namespace Indikator\News\Components; | ||
|
||
use Cms\Classes\ComponentBase; | ||
use Cms\Classes\Page; | ||
use Indikator\News\Models\Posts; | ||
use Lang; | ||
|
||
class Tags extends ComponentBase | ||
{ | ||
public function componentDetails() | ||
{ | ||
return [ | ||
'name' => 'indikator.news::lang.component.tags', | ||
'description' => '' | ||
]; | ||
} | ||
|
||
public function defineProperties() | ||
{ | ||
return [ | ||
'slug' => [ | ||
'title' => 'indikator.news::lang.settings.tags_slug_title', | ||
'description' => 'indikator.news::lang.settings.tags_slug_description', | ||
'default' => '{{ :slug }}', | ||
'type' => 'string', | ||
], | ||
'noTagsMessage' => [ | ||
'title' => 'indikator.news::lang.settings.no_tags_title', | ||
'description' => 'indikator.news::lang.settings.no_tags_description', | ||
'type' => 'string', | ||
'default' => Lang::get('indikator.news::lang.settings.no_tags_found'), | ||
'showExternalParam' => false | ||
], | ||
'tagPage' => [ | ||
'title' => 'indikator.news::lang.settings.tag_page_title', | ||
'description' => 'indikator.news::lang.settings.tag_page_description', | ||
'type' => 'dropdown', | ||
'default' => '' | ||
] | ||
]; | ||
} | ||
|
||
public function getTagPageOptions() | ||
{ | ||
return Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName'); | ||
} | ||
|
||
public function onRun() | ||
{ | ||
$tags = []; | ||
$news = Posts::where('status', 1)->where('published_at', '<=', date('Y-m-d H:i:00'))->get()->all(); | ||
|
||
foreach ($news as $post) { | ||
foreach ($post['tags'] as $tag) { | ||
if (! in_array($tag, $tags)) { | ||
$tags[] = $tag; | ||
} | ||
} | ||
} | ||
|
||
usort($tags, function($item1, $item2) { | ||
return $item1 <=> $item2; | ||
}); | ||
|
||
$this->page['tags'] = $tags; | ||
$this->page['noTagsMessage'] = $this->property('noTagsMessage'); | ||
$this->page['tagPage'] = $this->property('tagPage'); | ||
} | ||
} |
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,13 @@ | ||
{% set tags = __SELF__.tags %} | ||
|
||
{% for tag in tags %} | ||
{% if loop.first %} | ||
<ul> | ||
{% endif %} | ||
<li><a href="/{{ tagPage }}/{{ tag }}">{{ tag }}</a></li> | ||
{% if loop.last %} | ||
</ul> | ||
{% endif %} | ||
{% else %} | ||
<span class="post-nodata">{{ noTagsMessage }}</span> | ||
{% endfor %} |
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