silverstripe-blog/widgets/BlogRecentPostsWidget.php

44 lines
1.0 KiB
PHP
Raw Normal View History

2013-08-04 18:38:26 +02:00
<?php
2013-10-10 00:09:28 +02:00
if(class_exists("Widget")) {
2013-08-04 18:38:26 +02:00
2013-10-10 00:09:28 +02:00
class BlogRecentPostsWidget extends Widget {
private static $title = "Recent Posts";
2013-08-04 18:38:26 +02:00
2013-10-10 00:09:28 +02:00
private static $cmsTitle = "Recent Posts";
2013-08-04 18:38:26 +02:00
2013-10-10 00:09:28 +02:00
private static $description = "Displays a list of recent blog posts.";
2013-08-04 18:38:26 +02:00
2013-10-10 00:09:28 +02:00
private static $db = array(
"NumberOfPosts" => "Int",
);
2013-08-04 18:38:26 +02:00
2013-10-10 00:09:28 +02:00
private static $has_one = array(
"Blog" => "Blog",
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->push(DropdownField::create("BlogID", _t("BlogRecentPostsWidget.Blog", "Blog"), Blog::get()->map()));
$fields->push(NumericField::create("NumberOfPosts", _t("BlogRecentPostsWidget.NumberOfPosts", "Number of Posts")));
return $fields;
}
2013-08-04 18:38:26 +02:00
2013-10-10 00:09:28 +02:00
public function getPosts() {
$blog = $this->Blog();
if($blog) {
return $blog->getBlogPosts()
->sort("PublishDate DESC")
->limit($this->NumberOfPosts);
}
return array();
2013-08-04 18:38:26 +02:00
}
2013-10-10 00:09:28 +02:00
2013-08-04 18:38:26 +02:00
}
2013-10-10 00:09:28 +02:00
class BlogRecentPostsWidget_Controller extends Widget_Controller {
}
2013-08-04 18:38:26 +02:00
}