Development

Changeset 5447

You must first sign up to be able to contribute.

Changeset 5447

Show
Ignore:
Timestamp:
10/10/07 15:52:18 (1 year ago)
Author:
francois
Message:

sfSimpleForumPlugin Fixed empty forums not being displayed in Forum list (closes #2330)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfSimpleForumPlugin/trunk/data/fixtures/fixtures.yml

    r5287 r5447  
    4444    description: "If you don't know where to write, try here" 
    4545    category_id: c2 
     46    rank:        1 
     47  f4: 
     48    name: Empty discussion 
     49    description: This discussion is emtpty but should still appear in the forum list 
     50    category_id: c2 
     51    rank:        2 
    4652 
    4753sfSimpleForumTopic: 
  • plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForumPeer.php

    r5287 r5447  
    2424    $c->addAscendingOrderByColumn(sfSimpleForumCategoryPeer::RANK); 
    2525    $c->addAscendingOrderByColumn(self::RANK); 
    26  
    27     return self::doSelectJoinAll($c); 
     26     
     27    return self::doSelectJoinCategoryLeftJoinPost($c); 
    2828  } 
    2929   
     
    4040    return $res; 
    4141  } 
     42   
     43  public static function doSelectJoinCategoryLeftJoinPost(Criteria $c, $con = null) 
     44  { 
     45     
     46    foreach (sfMixer::getCallables('BasesfSimpleForumForumPeer:doSelectJoinAll:doSelectJoinAll') as $callable) 
     47    { 
     48      call_user_func($callable, 'BasesfSimpleForumForumPeer', $c, $con); 
     49    } 
     50     
     51    $c = clone $c; 
     52     
     53    if ($c->getDbName() == Propel::getDefaultDB())  
     54    { 
     55      $c->setDbName(self::DATABASE_NAME); 
     56    } 
     57     
     58    sfSimpleForumForumPeer::addSelectColumns($c); 
     59    $startcol2 = (sfSimpleForumForumPeer::NUM_COLUMNS - sfSimpleForumForumPeer::NUM_LAZY_LOAD_COLUMNS) + 1; 
     60     
     61    sfSimpleForumCategoryPeer::addSelectColumns($c); 
     62    $startcol3 = $startcol2 + sfSimpleForumCategoryPeer::NUM_COLUMNS; 
     63     
     64    sfSimpleForumPostPeer::addSelectColumns($c); 
     65    $startcol4 = $startcol3 + sfSimpleForumPostPeer::NUM_COLUMNS; 
     66     
     67    $c->addJoin(sfSimpleForumForumPeer::CATEGORY_ID, sfSimpleForumCategoryPeer::ID); 
     68     
     69    $c->addJoin(sfSimpleForumForumPeer::LATEST_POST_ID, sfSimpleForumPostPeer::ID, Criteria::LEFT_JOIN); 
     70     
     71    $rs = BasePeer::doSelect($c, $con); 
     72    $results = array(); 
     73     
     74    while($rs->next()) 
     75    { 
     76       
     77      $omClass = sfSimpleForumForumPeer::getOMClass(); 
     78       
     79      $cls = Propel::import($omClass); 
     80      $obj1 = new $cls(); 
     81      $obj1->hydrate($rs); 
     82       
     83      $omClass = sfSimpleForumCategoryPeer::getOMClass(); 
     84       
     85      $cls = Propel::import($omClass); 
     86      $obj2 = new $cls(); 
     87      $obj2->hydrate($rs, $startcol2); 
     88       
     89      $newObject = true; 
     90      for ($j=0, $resCount=count($results); $j < $resCount; $j++) 
     91      { 
     92        $temp_obj1 = $results[$j]; 
     93        $temp_obj2 = $temp_obj1->getsfSimpleForumCategory(); 
     94        if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) 
     95        { 
     96          $newObject = false; 
     97          $temp_obj2->addsfSimpleForumForum($obj1); 
     98          break; 
     99        } 
     100      } 
     101       
     102      if ($newObject) 
     103      { 
     104        $obj2->initsfSimpleForumForums(); 
     105        $obj2->addsfSimpleForumForum($obj1); 
     106      } 
     107       
     108      $omClass = sfSimpleForumPostPeer::getOMClass(); 
     109       
     110      $cls = Propel::import($omClass); 
     111      $obj3 = new $cls(); 
     112      $obj3->hydrate($rs, $startcol3); 
     113       
     114      $newObject = true; 
     115      for ($j=0, $resCount=count($results); $j < $resCount; $j++)  
     116      { 
     117        $temp_obj1 = $results[$j]; 
     118        $temp_obj3 = $temp_obj1->getsfSimpleForumPost(); 
     119        if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey()) 
     120        { 
     121          $newObject = false; 
     122          $temp_obj3->addsfSimpleForumForum($obj1); 
     123          break; 
     124        } 
     125      } 
     126       
     127      if ($newObject) 
     128      { 
     129        $obj3->initsfSimpleForumForums(); 
     130        $obj3->addsfSimpleForumForum($obj1); 
     131      } 
     132       
     133      $results[] = $obj1; 
     134    } 
     135    return $results; 
     136  } 
    42137} 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_forum.php

    r5414 r5447  
    88  <td class="forum_posts"><?php echo $forum->getNbPosts() ?></td> 
    99  <td class="forum_recent"> 
    10     <?php $latest_post = $forum->getsfSimpleForumPost(); ?> 
    11     <?php echo link_to($latest_post->getTitle(), 'sfSimpleForum/post?id='.$latest_post->getId()) ?><br /> 
    12     <?php echo __('%date% ago by %author%', array( 
    13       '%date%'   => distance_of_time_in_words($latest_post->getCreatedAt('U')), 
    14       '%author%' => link_to(get_partial('sfSimpleForum/author_name', array('author' => $latest_post->getAuthorName(), 'sf_cache_key' => $latest_post->getAuthorName())), 'sfSimpleForum/userLatestPosts?username='.$latest_post->getAuthorName()) 
    15       )) ?> 
     10    <?php if ($forum->getLatestPostId()): ?> 
     11      <?php $latest_post = $forum->getsfSimpleForumPost(); ?> 
     12      <?php echo link_to($latest_post->getTitle(), 'sfSimpleForum/post?id='.$latest_post->getId()) ?><br /> 
     13      <?php echo __('%date% ago by %author%', array( 
     14        '%date%'   => distance_of_time_in_words($latest_post->getCreatedAt('U')), 
     15        '%author%' => link_to(get_partial('sfSimpleForum/author_name', array('author' => $latest_post->getAuthorName(), 'sf_cache_key' => $latest_post->getAuthorName())), 'sfSimpleForum/userLatestPosts?username='.$latest_post->getAuthorName()) 
     16        )) ?> 
     17    <?php endif ;?> 
    1618  </td> 
    1719</tr> 
  • plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/forumSuccess.php

    r5293 r5447  
    2929  )) ?> 
    3030   
    31   <?php include_partial('sfSimpleForum/topic_list', array('topics' => $topics, 'include_forum' => false)) ?> 
    32    
    33   <?php echo pager_navigation($topic_pager, 'sfSimpleForum/forum?forum_name='.$forum->getStrippedName()) ?> 
     31  <?php if ($forum->getNbTopics()): ?> 
     32     
     33    <?php include_partial('sfSimpleForum/topic_list', array('topics' => $topics, 'include_forum' => false)) ?> 
     34     
     35    <?php echo pager_navigation($topic_pager, 'sfSimpleForum/forum?forum_name='.$forum->getStrippedName()) ?>     
     36  <?php else: ?> 
     37    <p><?php echo __('There is no topic in this discussion yet. Perhaps you would like to %start%?', array('%start%' =>  link_to(__('start a new one'), 'sfSimpleForum/createTopic?forum_name='.$forum->getStrippedName()))) ?></p> 
     38  <?php endif; ?> 
    3439 
    3540</div>