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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Forum Module /

Discuss the Forum Module.

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

Archive ReadOnly Threads


Go to End


2 Posts   1209 Views

Avatar
ihaveqquestion

Community Member, 12 Posts

26 February 2014 at 4:53pm

Hey there,

I am really SS. but so far I love it. also i dont have much knowledge about PHP.

I'v been trying to work out a function which store the 'readOnly' threads. Once the thread is taged as IsReadOnly = 1, it will be shifted into ForumArchive page.

the page structure is as following:

InfoPage; Project1 ->
ForumHolder1 ->
- Forum1
- ForumArchive1
InfoPage:Project2 -> ForumHolder2 ->
- Forum2
- ForumArchive2

ForumArchive php:

<?php
class ForumArchive extends Forum {
}
class ForumArchive_Controller extends Forum_Controller {

}

ForumArchive ss:

<% include SideBar %>
<div class="content-container unit size3of4 lastUnit">
<div class="content">
<table class="forum-topics" summary="List of topics in this forum" style="width: 100%">
<tr class="category">
<!--<td colspan="4"><% _t('Forum_ss.THREADS', 'Thread') %></td>-->
</tr>
<tr>
<th class="odd">Query</th> <!--<% _t('Forum_ss.TOPIC','Topic') %> -->
<th class="odd"><% _t('Forum_ss.POSTS','Posts') %></th>
<th class="even"><% _t('Forum_ss.LASTPOST','Last Post') %></th>
</tr>

<% loop ReadOnlyTopics %>
<% include TopicListing %>
<% end_loop %>
</table>
</div>
</div>

I also create a function in forum.php:

function getReadOnlyTopics() {

// Get Threads that are readOnly & in this forum
$where = '("ForumThread"."ForumID" = '.$this->ID.' AND "ForumThread"."IsReadOnly" = 1)';
// Get the underlying query
$query = ForumThread::get()->where($where)->dataQuery()->query();
// Build result as ArrayList
$res = new ArrayList();
$rows = $query->execute();
if ($rows) foreach ($rows as $row) $res->push(new ForumThread($row));

return $res;
}

The result is NULL.
Maybe i should get ForumHolderID for this ForumArchive page, because the Forum page and ForumArchive are the same Parent. but how to it get it?

i have been working on this for one week. but still trying....

Can someone give me a hand? thanks in advance.

Avatar
Willr

Forum Moderator, 5523 Posts

1 March 2014 at 11:31am

I would recommend creating a DataExtension on the ForumThread class and defined onBeforeWrite function which detects whether a forum is going to be readonly, if so, move to the ForumArchive holder.

public function onBeforeWrite() {
parent::onBeforeWrite();

if($this->owner->IsReadOnly) {
// change $this->owner->ForumID to the archive forum
}
}

http://doc.silverstripe.org/framework/en/reference/dataextension