Skip to content

Commit

Permalink
[wiki:sfSimpleForumPlugin] Fixed empty forums not being displayed in …
Browse files Browse the repository at this point in the history
…Forum list (closes #2330)
  • Loading branch information
francois committed Oct 10, 2007
1 parent 76c3be2 commit b478af1
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 11 deletions.
6 changes: 6 additions & 0 deletions data/fixtures/fixtures.yml
Expand Up @@ -43,6 +43,12 @@ sfSimpleForumForum:
name: General discussion
description: "If you don't know where to write, try here"
category_id: c2
rank: 1
f4:
name: Empty discussion
description: This discussion is emtpty but should still appear in the forum list
category_id: c2
rank: 2

sfSimpleForumTopic:
topic_1:
Expand Down
99 changes: 97 additions & 2 deletions lib/model/sfSimpleForumForumPeer.php
Expand Up @@ -23,8 +23,8 @@ public static function getAllOrderedByCategory()
$c->addJoin(self::CATEGORY_ID, sfSimpleForumCategoryPeer::ID);
$c->addAscendingOrderByColumn(sfSimpleForumCategoryPeer::RANK);
$c->addAscendingOrderByColumn(self::RANK);

return self::doSelectJoinAll($c);
return self::doSelectJoinCategoryLeftJoinPost($c);
}

public static function getAllAsArray()
Expand All @@ -39,4 +39,99 @@ public static function getAllAsArray()

return $res;
}

public static function doSelectJoinCategoryLeftJoinPost(Criteria $c, $con = null)
{

foreach (sfMixer::getCallables('BasesfSimpleForumForumPeer:doSelectJoinAll:doSelectJoinAll') as $callable)
{
call_user_func($callable, 'BasesfSimpleForumForumPeer', $c, $con);
}

$c = clone $c;

if ($c->getDbName() == Propel::getDefaultDB())
{
$c->setDbName(self::DATABASE_NAME);
}

sfSimpleForumForumPeer::addSelectColumns($c);
$startcol2 = (sfSimpleForumForumPeer::NUM_COLUMNS - sfSimpleForumForumPeer::NUM_LAZY_LOAD_COLUMNS) + 1;

sfSimpleForumCategoryPeer::addSelectColumns($c);
$startcol3 = $startcol2 + sfSimpleForumCategoryPeer::NUM_COLUMNS;

sfSimpleForumPostPeer::addSelectColumns($c);
$startcol4 = $startcol3 + sfSimpleForumPostPeer::NUM_COLUMNS;

$c->addJoin(sfSimpleForumForumPeer::CATEGORY_ID, sfSimpleForumCategoryPeer::ID);

$c->addJoin(sfSimpleForumForumPeer::LATEST_POST_ID, sfSimpleForumPostPeer::ID, Criteria::LEFT_JOIN);

$rs = BasePeer::doSelect($c, $con);
$results = array();

while($rs->next())
{

$omClass = sfSimpleForumForumPeer::getOMClass();

$cls = Propel::import($omClass);
$obj1 = new $cls();
$obj1->hydrate($rs);

$omClass = sfSimpleForumCategoryPeer::getOMClass();

$cls = Propel::import($omClass);
$obj2 = new $cls();
$obj2->hydrate($rs, $startcol2);

$newObject = true;
for ($j=0, $resCount=count($results); $j < $resCount; $j++)
{
$temp_obj1 = $results[$j];
$temp_obj2 = $temp_obj1->getsfSimpleForumCategory();
if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey())
{
$newObject = false;
$temp_obj2->addsfSimpleForumForum($obj1);
break;
}
}

if ($newObject)
{
$obj2->initsfSimpleForumForums();
$obj2->addsfSimpleForumForum($obj1);
}

$omClass = sfSimpleForumPostPeer::getOMClass();

$cls = Propel::import($omClass);
$obj3 = new $cls();
$obj3->hydrate($rs, $startcol3);

$newObject = true;
for ($j=0, $resCount=count($results); $j < $resCount; $j++)
{
$temp_obj1 = $results[$j];
$temp_obj3 = $temp_obj1->getsfSimpleForumPost();
if ($temp_obj3->getPrimaryKey() === $obj3->getPrimaryKey())
{
$newObject = false;
$temp_obj3->addsfSimpleForumForum($obj1);
break;
}
}

if ($newObject)
{
$obj3->initsfSimpleForumForums();
$obj3->addsfSimpleForumForum($obj1);
}

$results[] = $obj1;
}
return $results;
}
}
14 changes: 8 additions & 6 deletions modules/sfSimpleForum/templates/_forum.php
Expand Up @@ -7,11 +7,13 @@
<td class="forum_threads"><?php echo $forum->getNbTopics() ?></td>
<td class="forum_posts"><?php echo $forum->getNbPosts() ?></td>
<td class="forum_recent">
<?php $latest_post = $forum->getsfSimpleForumPost(); ?>
<?php echo link_to($latest_post->getTitle(), 'sfSimpleForum/post?id='.$latest_post->getId()) ?><br />
<?php echo __('%date% ago by %author%', array(
'%date%' => distance_of_time_in_words($latest_post->getCreatedAt('U')),
'%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())
)) ?>
<?php if ($forum->getLatestPostId()): ?>
<?php $latest_post = $forum->getsfSimpleForumPost(); ?>
<?php echo link_to($latest_post->getTitle(), 'sfSimpleForum/post?id='.$latest_post->getId()) ?><br />
<?php echo __('%date% ago by %author%', array(
'%date%' => distance_of_time_in_words($latest_post->getCreatedAt('U')),
'%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())
)) ?>
<?php endif ;?>
</td>
</tr>
11 changes: 8 additions & 3 deletions modules/sfSimpleForum/templates/forumSuccess.php
Expand Up @@ -28,8 +28,13 @@
'feed_title' => $feed_title
)) ?>

<?php include_partial('sfSimpleForum/topic_list', array('topics' => $topics, 'include_forum' => false)) ?>

<?php echo pager_navigation($topic_pager, 'sfSimpleForum/forum?forum_name='.$forum->getStrippedName()) ?>
<?php if ($forum->getNbTopics()): ?>

<?php include_partial('sfSimpleForum/topic_list', array('topics' => $topics, 'include_forum' => false)) ?>

<?php echo pager_navigation($topic_pager, 'sfSimpleForum/forum?forum_name='.$forum->getStrippedName()) ?>
<?php else: ?>
<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>
<?php endif; ?>

</div>

0 comments on commit b478af1

Please sign in to comment.