Development

Changeset 5356

You must first sign up to be able to contribute.

Changeset 5356

Show
Ignore:
Timestamp:
10/03/07 22:45:21 (1 year ago)
Author:
francois
Message:

sfSimpleForumPlugin More partialization for better cache coverage

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSimpleForumPlugin/trunk/CHANGELOG

    r5317 r5356  
    11== Trunk == 
    22 
     3 * francois: Extended the cache coverage 
     4 * francois: Partialized templates for easier customization 
     5 * francois: Refactored Forum and Topic counts (now working with save and delete) 
    36 * francois: Made the schema customizable 
    4  * francois: Partialized and restyled moderator actions for easier customization 
    57 * francois: Added link to last page for multi-pages topics 
    68 * francois: Refactored actions class for easier custom templating 
  • plugins/sfSimpleForumPlugin/trunk/README

    r5287 r5356  
    196196== TODO == 
    197197 
    198  * Report message to moderator, list of reported messages 
     198 * Authors can edit a message during its first minutes 
     199 * Moderators can edit a message 
    199200 * Moderators can move a topic to another forum and a message to another topic 
    200201 * Add images to make the default style less ugly 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForum.php

    r5268 r5356  
    7070  } 
    7171   
    72   public function updateCounts($latestReply, $con = null) 
     72  public function updateCounts($latestReply = null, $con = null) 
    7373  { 
    74     $this->setNbPosts($this->countsfSimpleForumPosts()); 
    75     $this->setNbTopics($this->countsfSimpleForumTopics()); 
    76     $this->setLatestPostId($latestReply->getId()); 
     74    if($latestReply) 
     75    { 
     76      $this->setNbPosts($this->countsfSimpleForumPosts()); 
     77      $this->setNbTopics($this->countsfSimpleForumTopics()); 
     78      $this->setLatestPostId($latestReply->getId()); 
     79      $this->setUpdatedAt($latestReply->getCreatedAt()); 
     80    } 
     81    else 
     82    { 
     83      $this->setNbPosts(0); 
     84      $this->setNbTopics(0); 
     85      $this->setLatestPostId(null); 
     86    } 
    7787    $this->save($con); 
    7888  } 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPost.php

    r5268 r5356  
    5454  } 
    5555   
    56   public function save($con = null
     56  public function save($con = null, $preserveTopic = false
    5757  { 
    5858    if(!$con) 
     
    7474       
    7575      $latestPost = $topic->getLatestPostByQuery(); 
     76      if($preserveTopic) 
     77      { 
     78        $topic->leaveUpdatedAtUnchanged(); 
     79      } 
    7680      $topic->updateReplies($latestPost, $con); 
    77       $this->getsfSimpleForumForum()->updateCounts($latestPost, $con); 
    7881       
    7982      $con->commit(); 
     
    8689  } 
    8790 
    88   public function delete($con = null
     91  public function delete($con = null, $preserveTopic = true
    8992  { 
    9093    if(!$con) 
     
    100103       
    101104      $topic = $this->getsfSimpleForumTopic(); 
     105      if($preserveTopic) 
     106      { 
     107        $topic->leaveUpdatedAtUnchanged(); 
     108      } 
    102109      $latestPost = $topic->getLatestPostByQuery(); 
    103       $topic->setUpdatedAt($latestPost->getCreatedAt()); 
    104110      $topic->updateReplies($latestPost, $con); 
    105        
    106       $forum = $this->getsfSimpleForumForum(); 
    107       $latestPost = $forum->getLatestPostByQuery(); 
    108       $forum->setUpdatedAt($latestPost->getCreatedAt()); 
    109       $forum->updateCounts($latestPost, $con); 
    110111      
    111112      $con->commit(); 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPostPeer.php

    r5347 r5356  
    4848  }   
    4949   
    50   public static function getLatest($max = 10
     50  public static function getLatest($max = null
    5151  { 
    5252    $c = self::getLatestCriteria(); 
    53     $c->setLimit($max); 
     53    if($max) 
     54    { 
     55      $c->setLimit($max); 
     56    } 
    5457     
    5558    return self::doSelect($c); 
     
    7679  } 
    7780   
    78   public static function getForTopic($topic_id, $max
     81  public static function getForTopic($topic_id, $max = null
    7982  { 
    8083    $c = self::getForTopicCriteria($topic_id); 
    8184    $c->addDescendingOrderByColumn(self::ID); 
    82     $c->setLimit($max); 
     85    if($max) 
     86    { 
     87      $c->setLimit($max); 
     88    } 
    8389    $posts = self::doSelect($c); 
    8490     
     
    107113  }   
    108114   
    109   public static function getForForum($forum_name, $max = 10
     115  public static function getForForum($forum_name, $max = null
    110116  { 
    111117    $c = self::getForForumCriteria($forum_name); 
    112     $c->setLimit($max); 
     118    if($max) 
     119    { 
     120      $c->setLimit($max); 
     121    } 
    113122     
    114123    return self::doSelect($c); 
     
    136145  }   
    137146 
    138   public static function getForUser($user_id, $max = 10
     147  public static function getForUser($user_id, $max = null
    139148  { 
    140149    $c = self::getForUserCriteria($user_id); 
    141     $c->setLimit($max); 
     150    if($max) 
     151    { 
     152      $c->setLimit($max); 
     153    } 
    142154     
    143155    return self::doSelect($c); 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopic.php

    r5287 r5356  
    9191  } 
    9292   
    93   public function getPosts($max
     93  public function getPosts($max = null
    9494  { 
    9595    return sfSimpleForumPostPeer::getForTopic($this->getId(), $max); 
     
    101101  } 
    102102   
    103   public function updateReplies($latestReply, $con = null) 
     103  public function updateReplies($latestReply = null, $con = null) 
    104104  { 
    105105    if(!$this->isDeleted()) 
    106106    { 
    107       $this->setNbPosts($this->countsfSimpleForumPosts()); 
    108       $this->setLatestPostId($latestReply->getId()); 
    109       $this->save($con); 
     107      if($latestReply) 
     108      { 
     109        $this->setNbPosts($this->countsfSimpleForumPosts()); 
     110        $this->setLatestPostId($latestReply->getId()); 
     111        $this->setUpdatedAt($latestReply->getCreatedAt()); 
     112      } 
     113      else 
     114      { 
     115        $this->setNbPosts(0); 
     116        $this->setLatestPostId(null); 
     117      } 
     118      $this->save($con, $latestReply); 
    110119    } 
    111120  } 
    112    
    113   public function delete($con = null) 
     121 
     122  public function save($con = null, $latestPost = null) 
     123  { 
     124    if(!$con) 
     125    { 
     126      $con = Propel::getConnection(); 
     127    } 
     128 
     129    try 
     130    { 
     131      $con->begin(); 
     132       
     133      parent::save($con); 
     134       
     135      // Update the topic's forum counts 
     136      $forum = $this->getsfSimpleForumForum(); 
     137      if(!$latestPost) 
     138      { 
     139        $latestPost = $forum->getLatestPostByQuery(); 
     140      } 
     141      $forum->updateCounts($latestPost, $con); 
     142      
     143      $con->commit(); 
     144    } 
     145    catch (Exception $e) 
     146    { 
     147      $con->rollback(); 
     148      throw $e; 
     149    } 
     150  } 
     151     
     152  public function delete($con = null, $latestPost = null) 
    114153  { 
    115154    if(!$con) 
     
    126165      // Update the topic's forum counts 
    127166      $forum = $this->getsfSimpleForumForum(); 
    128       if($latestPost = $forum->getLatestPostByQuery()
     167      if(!$latestPost
    129168      { 
    130         $forum->setUpdatedAt($latestPost->getCreatedAt()); 
    131         $forum->updateCounts($latestPost, $con); 
     169        $latestPost = $forum->getLatestPostByQuery(); 
    132170      } 
    133       
     171      $forum->updateCounts($latestPost, $con); 
     172       
    134173      $con->commit(); 
    135174    } 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/config/cache.yml

    r4524 r5356  
     1_topic: 
     2  enabled: on 
     3 
     4_post: 
     5  enabled: on 
     6   
    17_author: 
    28  enabled: on 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/lib/BasesfSimpleForumActions.class.php

    r5293 r5356  
    340340      $this->forward404Unless($this->forum); 
    341341    } 
    342      
    343     $this->topic_name = ''; 
    344     $this->topic_id = null; 
    345342  } 
    346343   
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic.php

    r5317 r5356  
    4444    <?php endif; ?> 
    4545     
    46     <?php if ($sf_user->hasCredential('moderator')): ?> 
    47       <?php include_partial('sfSimpleForum/topic_moderator_actions', array('topic' => $topic)) ?> 
    48     <?php endif; ?> 
     46    <?php include_partial('sfSimpleForum/topic_moderator_actions', array('topic' => $topic, 'user_is_moderator' => $user_is_moderator)) ?> 
    4947     
    5048  </td> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic_list.php

    r5287 r5356  
    99  </tr> 
    1010  <?php foreach ($topics as $topic): ?> 
    11     <?php include_partial('sfSimpleForum/topic', array('topic' => $topic, 'include_forum' => $include_forum)) ?> 
     11    <?php include_partial('sfSimpleForum/topic', array( 
     12      'topic'             => $topic,  
     13      'include_forum'     => $include_forum,  
     14      'user_is_moderator' => $sf_user->hasCredential('moderator'), 
     15      'sf_cache_key'      => $topic->getId().'_'.$sf_user->hasCredential('moderator') 
     16      )) ?> 
    1217  <?php endforeach; ?> 
    1318</table> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic_moderator_actions.php

    r5317 r5356  
    11<?php echo use_helper('I18N') ?> 
    2 <ul class="post_actions"> 
    3   <li><?php echo link_to(__('Delete'), 'sfSimpleForum/deleteTopic?id='.$topic->getId(), array('confirm' =>__('Are you sure you want to delete this topic?'))) ?></li> 
    4 </ul> 
     2<?php if ($user_is_moderator): ?> 
     3  <ul class="post_actions"> 
     4    <li><?php echo link_to(__('Delete'), 'sfSimpleForum/deleteTopic?id='.$topic->getId(), array('confirm' =>__('Are you sure you want to delete this topic?'))) ?></li> 
     5  </ul> 
     6<?php endif ?> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/createTopicSuccess.php

    r5287 r5356  
    2121 
    2222  <h1><?php echo __('Create a new topic') ?></h1> 
    23  
    24   <?php echo form_tag('sfSimpleForum/addTopic', 'id=add_topic name=add_topic') ?> 
    25     <?php if ($forum): ?> 
    26       <?php echo input_hidden_tag('forum_name', $forum->getStrippedName()) ?> 
    27     <?php endif; ?> 
    28     <?php echo input_hidden_tag('topic_id', $topic_id) ?> 
    29      
    30     <?php echo form_error('title') ?> 
    31     <?php echo label_for('title', __('Title')) ?> 
    32     <?php echo input_tag('title', $topic_id ? __('Re: ') . $topic_name : '', 'id=topic_title') ?> 
    33      
    34     <?php if (!$forum): ?> 
    35       <?php echo label_for('forum', __('Forum')) ?> 
    36       <?php echo select_tag('forum_name', options_for_select(sfSimpleForumForumPeer::getAllAsArray())) ?> 
    37     <?php endif; ?> 
    38      
    39     <?php echo form_error('body') ?> 
    40     <?php echo label_for('body', __('Body')) ?> 
    41     <?php echo textarea_tag('body', '', 'id=topic_body') ?> 
    42     <?php if ($sf_user->hasCredential('moderator')): ?> 
    43     <div class="option"> 
    44       <?php echo checkbox_tag('is_sticked', '1')?> 
    45       <?php echo label_for('is_sticked', __('Sticked topic')) ?> 
    46     </div> 
    47     <div class="option"> 
    48       <?php echo checkbox_tag('is_locked', '1')?> 
    49       <?php echo label_for('is_locked', __('Locked topic')) ?> 
    50     </div> 
    51     <?php endif; ?> 
    52     <?php echo submit_tag(__('Post'), 'id=topic_submit') ?> 
    53   </form> 
     23   
     24  <?php include_partial('sfSimpleForum/add_post_form', array('forum' => $forum)) ?> 
    5425 
    5526</div> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/forumLatestPostsSuccess.php

    r5293 r5356  
    2727  )) ?> 
    2828   
    29   <table id="messages"> 
    30     <?php foreach ($post_pager->getResults() as $post): ?> 
    31       <?php include_partial('sfSimpleForum/post', array('post' => $post, 'include_topic' => true)) ?> 
    32     <?php endforeach; ?> 
    33   </table> 
     29  <?php include_partial('sfSimpleForum/post_list', array('posts' => $post_pager->getResults(), 'include_topic' => true)) ?> 
    3430   
    3531  <?php echo pager_navigation($post_pager, 'sfSimpleForum/forumLatestPosts?forum_name='.$name) ?> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/latestPostsSuccess.php

    r5293 r5356  
    2626  )) ?> 
    2727   
    28   <table id="messages"> 
    29     <?php foreach ($post_pager->getResults() as $post): ?> 
    30       <?php include_partial('sfSimpleForum/post', array('post' => $post, 'include_topic' => true)) ?> 
    31     <?php endforeach; ?> 
    32   </table> 
     28  <?php include_partial('sfSimpleForum/post_list', array('posts' => $post_pager->getResults(), 'include_topic' => true)) ?> 
    3329   
    3430  <?php echo pager_navigation($post_pager, 'sfSimpleForum/latestPosts') ?> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/topicSuccess.php

    r5312 r5356  
    3737    <?php echo format_number_choice('[1]1 message, no reply|(1,+Inf]%posts% messages', array('%posts%' => $post_pager->getNbResults()), $post_pager->getNbResults()) ?>  
    3838    <?php if (sfConfig::get('app_sfSimpleForumPlugin_count_views', true)): ?> 
    39     - <?php echo format_number_choice('[1]1 view|(1,+Inf]%views% views', array('%views%' => $topic->getNbViews()), $topic->getNbViews()) ?> 
     39    - <?php echo format_number_choice('[0,1]1 view|(1,+Inf]%views% views', array('%views%' => $topic->getNbViews()), $topic->getNbViews()) ?> 
    4040    <?php endif; ?> 
    4141    <?php if(sfConfig::get('app_sfSimpleForumPlugin_use_feeds', true)): ?> 
     
    4444  </div> 
    4545   
    46   <table id="messages"> 
    47     <?php foreach ($post_pager->getResults() as $post): ?> 
    48       <?php include_partial('sfSimpleForum/post', array('post' => $post, 'include_topic' => false)) ?> 
    49     <?php endforeach; ?> 
    50   </table> 
     46  <?php include_partial('sfSimpleForum/post_list', array('posts' => $post_pager->getResults(), 'include_topic' => false)) ?> 
    5147   
    5248  <?php echo pager_navigation($post_pager, 'sfSimpleForum/topic?id='.$topic->getId().'&stripped_title='.$topic->getStrippedTitle()) ?> 
     49   
    5350  <?php if (!$topic->getIsLocked() && $sf_user->isAuthenticated()): ?> 
     51     
    5452    <h2> 
    5553      <?php echo __('Post a reply') ?> 
    5654    </h2> 
    57  
    58     <?php echo form_tag('sfSimpleForum/addPost', 'id=add_topic name=add_topic') ?> 
    59       <?php echo input_hidden_tag('topic_id', $topic->getId()) ?> 
    60    
    61       <?php echo form_error('body') ?> 
    62       <?php echo label_for('body', __('Body')) ?> 
    63       <?php echo textarea_tag('body', '', 'id=topic_body') ?> 
    64  
    65       <?php echo submit_tag(__('Post'), 'id=topic_submit') ?> 
    66     </form> 
    67     <?php elseif (!$topic->getIsLocked() && !$sf_user->isAuthenticated()): ?> 
    68       <ul class="forum_actions"> 
    69           <li><?php echo link_to( 
    70             __('Post a reply'),  
    71             sfConfig::get('sf_login_module').'/'.sfConfig::get('sf_login_action') 
    72           ) ?></li> 
    73       </ul> 
     55    <?php include_partial('sfSimpleForum/add_post_form', array('topic' => $topic)) ?> 
     56       
     57  <?php elseif (!$topic->getIsLocked() && !$sf_user->isAuthenticated()): ?> 
     58     
     59    <ul class="forum_actions"> 
     60        <li><?php echo link_to( 
     61          __('Post a reply'),  
     62          sfConfig::get('sf_login_module').'/'.sfConfig::get('sf_login_action') 
     63        ) ?></li> 
     64    </ul> 
     65     
    7466  <?php elseif ($topic->getIsLocked() && $sf_user->isAuthenticated()): ?> 
     67     
    7568    <?php echo __('This topic was locked by a forum moderator. No reply can be added.') ?> 
     69     
    7670  <?php endif; ?> 
    7771</div> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/userLatestPostsSuccess.php

    r5293 r5356  
    2626  )) ?> 
    2727   
    28   <table id="messages"> 
    29     <?php foreach ($post_pager->getResults() as $post): ?> 
    30       <?php include_partial('sfSimpleForum/post', array('post' => $post, 'include_topic' => true)) ?> 
    31     <?php endforeach; ?> 
    32   </table> 
     28  <?php include_partial('sfSimpleForum/post_list', array('posts' => $post_pager->getResults(), 'include_topic' => true)) ?> 
    3329   
    3430  <?php echo pager_navigation($post_pager, 'sfSimpleForum/userLatestPosts?username='.$username) ?> 
  • plugins/sfSimpleForumPlugin/trunk/package.xml

    r5293 r5356  
    7878         <dir name="templates"> 
    7979           <file role="data" name="_author.php" /> 
     80           <file role="data" name="_add_post_form.php" /> 
    8081           <file role="data" name="_figures.php" /> 
    8182           <file role="data" name="_forum.php" /> 
    8283           <file role="data" name="_latestPosts.php" /> 
    8384           <file role="data" name="_post.php" /> 
     85           <file role="data" name="_post_list.php" /> 
     86           <file role="data" name="_post_moderator_actions.php" /> 
    8487           <file role="data" name="_topic.php" /> 
    8588           <file role="data" name="_topic_list.php" /> 
     89           <file role="data" name="_topic_moderator_actions.php" /> 
    8690           <file role="data" name="createTopicSuccess.php" /> 
    8791           <file role="data" name="forumLatestPostsSuccess.php" />