fixed some api compatibility issues, added a basic comment gridfield to comment admin

This commit is contained in:
Shea 2012-06-01 16:34:31 +10:00
parent 87aef53f22
commit 0adf17d363
4 changed files with 98 additions and 82 deletions

View File

@ -13,6 +13,8 @@ class CommentAdmin extends LeftAndMain {
static $menu_title = 'Comments';
static $template_path = null; // defaults to (project)/templates/email
static $allowed_actions = array(
'approvedmarked',
'deleteall',
@ -32,8 +34,65 @@ class CommentAdmin extends LeftAndMain {
public function init() {
parent::init();
Requirements::javascript(CMS_DIR . '/javascript/CommentAdmin_right.js');
Requirements::css(CMS_DIR . '/css/CommentAdmin.css');
//Requirements::javascript(CMS_DIR . '/javascript/CommentAdmin_right.js');
//Requirements::css(CMS_DIR . '/css/CommentAdmin.css');
}
public function getEditForm($id = null, $fields = null) {
// TODO Duplicate record fetching (see parent implementation)
if(!$id) $id = $this->currentPageID();
$form = parent::getEditForm($id);
// TODO Duplicate record fetching (see parent implementation)
$record = $this->getRecord($id);
if($record && !$record->canView()) return Security::permissionFailure($this);
$commentList = GridField::create(
'Comments',
false,
Comment::get(),
$commentListConfig = GridFieldConfig_RecordViewer::create()
//->addComponent(new GridFieldExportButton())
)->addExtraClass("comments_grid");
//$commentListConfig->getComponentByType('GridFieldDetailForm')->setValidator(new Comment_Validator());
$fields = new FieldList(
$root = new TabSet(
'Root',
$commentsTab = new Tab('Comments', _t('CommentAdmin.Comments', 'Comments'),
$commentList// ,
// new HeaderField(_t('CommentAdmin.IMPORTCOMMENTS', 'Import comments'), 3),
// new LiteralField(
// 'CommentImportFormIframe',
// sprintf(
// '<iframe src="%s" id="CommentImportFormIframe" width="100%%" height="250px" border="0"></iframe>',
// $this->Link('commentimport')
// )
// )
)
),
// necessary for tree node selection in LeftAndMain.EditForm.js
new HiddenField('ID', false, 0)
);
$root->setTemplate('CMSTabSet');
$actions = new FieldList();
$form = new Form(
$this,
'EditForm',
$fields,
$actions
);
$form->addExtraClass('cms-edit-form');
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
$this->extend('updateEditForm', $form);
return $form;
}
public function showtable($params) {
@ -58,79 +117,6 @@ class CommentAdmin extends LeftAndMain {
return $section;
}
public function EditForm() {
$section = $this->Section();
if($section == 'approved') {
$filter = "\"IsSpam\" = 0 AND \"NeedsModeration\" = 0";
$title = "<h2>". _t('CommentAdmin.APPROVEDCOMMENTS', 'Approved Comments')."</h2>";
} else if($section == 'unmoderated') {
$filter = '"NeedsModeration" = 1';
$title = "<h2>"._t('CommentAdmin.COMMENTSAWAITINGMODERATION', 'Comments Awaiting Moderation')."</h2>";
} else {
$filter = '"IsSpam" = 1';
$title = "<h2>"._t('CommentAdmin.SPAM', 'Spam')."</h2>";
}
$filter .= ' AND "ParentID">0';
$tableFields = array(
"Name" => _t('CommentAdmin.AUTHOR', 'Author'),
"Comment" => _t('CommentAdmin.COMMENT', 'Comment'),
"Parent.Title" => _t('CommentAdmin.PAGE', 'Page'),
"URL" => _t('CommentAdmin.COMMENTERURL', 'URL'),
"Created" => _t('CommentAdmin.DATEPOSTED', 'Date Posted')
);
$popupFields = new FieldSet(
new TextField('Name', _t('CommentAdmin.NAME', 'Name')),
new TextField('URL', _t('CommentAdmin.URL', 'URL')),
new TextareaField('Comment', _t('CommentAdmin.COMMENT', 'Comment'))
);
$idField = new HiddenField('ID', '', $section);
$table = new CommentTableField($this, "Comments", "Comment", $section, $tableFields, $popupFields, array($filter), 'Created DESC');
$table->setParentClass(false);
$table->setFieldCasting(array(
'Created' => 'SSDatetime->Full',
'Comment' => array('HTMLText->LimitCharacters', 150)
));
$table->setPageSize(self::get_comments_per_page());
$table->addSelectOptions(array('all'=>'All', 'none'=>'None'));
$table->Markable = true;
$fields = new FieldSet(
new LiteralField("Title", $title),
$idField,
$table
);
$actions = new FieldSet();
if($section == 'unmoderated') {
$actions->push(new FormAction('acceptmarked', _t('CommentAdmin.ACCEPT', 'Accept')));
}
if($section == 'approved' || $section == 'unmoderated') {
$actions->push(new FormAction('spammarked', _t('CommentAdmin.SPAMMARKED', 'Mark as spam')));
}
if($section == 'spam') {
$actions->push(new FormAction('hammarked', _t('CommentAdmin.MARKASNOTSPAM', 'Mark as not spam')));
}
$actions->push(new FormAction('deletemarked', _t('CommentAdmin.DELETE', 'Delete')));
if($section == 'spam') {
$actions->push(new FormAction('deleteall', _t('CommentAdmin.DELETEALL', 'Delete All')));
}
$form = new Form($this, "EditForm", $fields, $actions);
return $form;
}
function deletemarked() {
$numComments = 0;

View File

@ -76,7 +76,7 @@ class CommentingController extends Controller {
function CommentsForm() {
$member = Member::currentUser();
$fields = new FieldSet(
$fields = new FieldList(
new TextField("Name", _t('CommentInterface.YOURNAME', 'Your name')),
new EmailField("Email", _t('CommentingController.EMAILADDRESS', "Your email address (will not be published)")),
new TextField("URL", _t('CommentingController.WEBSITEURL', "Your website URL")),
@ -87,7 +87,7 @@ class CommentingController extends Controller {
);
// save actions
$actions = new FieldSet(
$actions = new FieldList(
new FormAction("doPostComment", _t('CommentInterface.POST', 'Post'))
);

View File

@ -34,6 +34,24 @@ class Comment extends DataObject {
static $casting = array(
"RSSTitle" => "Varchar",
);
static $searchable_fields = array(
'Name',
'Email',
'Comment',
'Created',
'BaseClass',
);
static $summary_fields = array(
'Name' => 'Submitted By',
'Email' => 'Email',
'Comment' => 'Comment',
'Created' => 'Date Posted',
'ParentTitle' => 'Parent',
);
/**
* Migrates the old {@link PageComment} objects to {@link Comment}
@ -107,6 +125,17 @@ class Comment extends DataObject {
return DataObject::get_by_id($this->BaseClass, $this->ParentID);
}
/**
* Returns a string to help identify the parent of the comment
*
* @return string
*/
function getParentTitle(){
$parent = $this->getParent();
return ($parent->Title) ? $parent->Title : $parent->ClassName . " #" . $parent->ID;
}
/**
* This method is called just before this object is

View File

@ -6,7 +6,7 @@
* @package comments
*/
class CommentsExtension extends DataObjectDecorator {
class CommentsExtension extends DataExtension {
/**
* Adds a relationship between this {@link DataObject} and its
@ -15,7 +15,7 @@ class CommentsExtension extends DataObjectDecorator {
*
* @return array
*/
public function extraStatics() {
function extraStatics($class = null, $extension = null) {
$fields = array();
$relationships = array(
@ -29,7 +29,7 @@ class CommentsExtension extends DataObjectDecorator {
$args = func_get_args();
if($args && ($owner = array_shift($args))) {
if(ClassInfo::is_subclass_of($owner, 'SiteTree') || $owner == "SiteTree") {
if(is_subclass_of($owner, 'SiteTree') || $owner == "SiteTree") {
$fields = array(
'db' => array(
'ProvideComments' => 'Boolean'
@ -40,6 +40,7 @@ class CommentsExtension extends DataObjectDecorator {
return array_merge($fields, $relationships);
}
/**
* If this extension is applied to a {@link SiteTree} record then
@ -50,7 +51,7 @@ class CommentsExtension extends DataObjectDecorator {
*
* @param FieldSet
*/
public function updateCMSFields(&$fields) {
public function updateCMSFields(FieldList $fields) {
if($this->attachedToSiteTree()) {
$fields->addFieldToTab('Root.Behaviour',
new CheckboxField('ProvideComments', _t('Comment.ALLOWCOMMENTS', 'Allow Comments'))
@ -127,7 +128,7 @@ class CommentsExtension extends DataObjectDecorator {
public function attachedToSiteTree() {
$class = $this->ownerBaseClass;
return (ClassInfo::is_subclass_of($class, 'SiteTree')) || ($class == 'SiteTree');
return (is_subclass_of($class, 'SiteTree')) || ($class == 'SiteTree');
}
/**