Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Forum Module /

Discuss the Forum Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Closing Thread


Go to End


4 Posts   2390 Views

Avatar
ihaveqquestion

Community Member, 12 Posts

31 January 2014 at 1:08pm

Hey there,

I recently have installed forum in Silverstripe 3. What I am trying to do is to figure out how to close solved thread. Currently, it doesn't have any button or function, I can tell, which can be used for that in Forum module.

The scenario:

Whoever post thread should have the power to close it or mark as solved/completed.

Next step after this is to make it popup on the homepage in order to be presented in 'solved topics' section.

Can anyone give me an idea how to structure this close function? What do I need to do?

Thanks

Avatar
DryerLintPurple

Community Member, 7 Posts

3 February 2014 at 12:46am

Edited: 03/02/2014 12:49am

So basically, you want a one-step process that locks a user's own thread and moves it to a subforum or something?

Honestly, that's probably going to be a lot of work. I don't think Silverstripe's forum module has much in the way of permissions granularity that you could tap into for something like that. The functionality for editing your own post would be a starting point, and then you'd add locking and moving functionality to it. But again, you'd need to mind the permissions/security, and I'm not sure how much help you'd get there.

Avatar
Willr

Forum Moderator, 5523 Posts

3 February 2014 at 6:30pm

In terms of permission granularity I think you'd be fine as the only permission you have is for a user to edit their own post which is already there. As for steps to get it built (without editing the 'core' module)

* Setup a Forum for the 'solved' post and set the CanPostType in the CMS to no one (so posts cannot be created solved)
* Create a new Controller which has an action for the user to mark / unmark a thread as solved (and the permission check - can the user edit that post). That action should change $thread->ForumID to the ID of your solved forum.
* Update your Forum templates to include the link for the author of the post to mark it as solved.

Good Luck!

Avatar
ihaveqquestion

Community Member, 12 Posts

4 February 2014 at 6:05pm

Hey Willr,

Thanks for your reply.

For your solution, I thought its bit complex for me.

Currently, what i am doing is to get it done on Forum.php.

function AdminFormFeatures() {
if (!$this->canPost()) return;

$id = (isset($this->urlParams['ID'])) ? $this->urlParams['ID'] : false;

$fields = new FieldList(
new CheckboxField('IsReadOnly', _t('Forum.ISREADONLYTHREAD','Is this query solved?')),

new HiddenField("ID", "Thread")
);

if(($forums = Forum::get()) && $forums->exists()) {
$fields->push(new DropdownField("ForumID", _t('Forum.CHANGETHREADFORUM',"Change Thread Forum"), $forums->map('ID', 'Title', 'Select New Category:')), '', null, 'Select New Location:');
}

$actions = new FieldList(
new FormAction('doAdminFormFeatures', _t('Forum.SAVE', 'Save'))
);

$form = new Form($this, 'AdminFormFeatures', $fields, $actions);

// need this id wrapper since the form method is called on save as
// well and needs to return a valid form object
if($id) {
$thread = ForumThread::get()->byID($id);
$form->loadDataFrom($thread);
}

return $form;
}

/**
* Process's the moving of a given topic. Has to check for admin privledges,
* passed an old topic id (post id in URL) and a new topic id
*/
function doAdminFormFeatures($data, $form) {
if(isset($data['ID'])) {
$thread = ForumThread::get()->byID($data['ID']);

if($thread) {
if (!$thread->canPost()) {
return Security::permissionFailure($this);
}

$form->saveInto($thread);
$thread->write();
}
}

return $this->redirect($this->Link());
}
}

Basically, I have replaced 'canModerator' with 'canPost'. So as non-admin or non-moderator can switch this thread into readonly mode.

However, there are two issues which are bothering me a lot.
1. Even I have changed 'Is this a Read only Thread? ' into 'Is this query solved' on Forum.php, however, it doesnt show up on the site. Also, I couldn't any other code could be possible to store this label.

2. I only wish the topic author can switch this thread into readonly mode. What's the code?

Thanks so much for your help.