Jump to:

1033 Posts in 809 Topics by 313 members

Forum Module

SilverStripe Forums » Forum Module » Archive ReadOnly Threads

Discuss the Forum Module.

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

Page: 1
Go to End
Author Topic: 328 Views
  • ihaveqquestion
    Avatar
    Community Member
    12 Posts

    Archive ReadOnly Threads Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Archive ReadOnly Threads Link to this post

    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

    328 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.