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