public function getPositionInTopic()
 {
     $c = new Criteria();
     $c->clearSelectColumns();
     $c->addSelectColumn(sfSimpleForumPostPeer::ID);
     $c->add(sfSimpleForumPostPeer::TOPIC_ID, $this->getTopicId());
     $c->addAscendingOrderByColumn(sfSimpleForumPostPeer::CREATED_AT);
     $rs = sfSimpleForumPostPeer::doSelectRS($c);
     $messages = array();
     while ($rs->next()) {
         $messages[] = $rs->getInt(1);
     }
     return array_search($this->getId(), $messages);
 }
예제 #2
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = sfSimpleForumPostPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setTitle($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setContent($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setTopicId($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setUserId($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setCreatedAt($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setForumId($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setAuthorName($arr[$keys[7]]);
     }
 }
  <h1><?php 
echo $title;
?>
</h1>

  <?php 
if (sfConfig::get('app_sfSimpleForumPlugin_allow_new_topic_outside_forum', true)) {
    ?>
  <ul class="forum_actions">
    <li><?php 
    echo link_to(__('New topic', null, 'sfSimpleForum'), 'sfSimpleForum/createTopic');
    ?>
</li>
  </ul>    
  <?php 
}
?>
  
  <?php 
include_partial('sfSimpleForum/figures', array('display_topic_link' => false, 'nb_topics' => $topics_pager->getNbResults(), 'topic_rule' => '', 'display_post_link' => true, 'nb_posts' => sfSimpleForumPostPeer::doCount(new Criteria()), 'post_rule' => 'sfSimpleForum/latestPosts', 'feed_rule' => 'sfSimpleForum/latestTopicsFeed', 'feed_title' => $feed_title));
?>
    
  <?php 
include_partial('sfSimpleForum/topic_list', array('topics' => $topics_pager->getResults(), 'include_forum' => true));
?>
  
  <?php 
echo pager_navigation($topics_pager, 'sfSimpleForum/latestTopics');
?>

</div>
예제 #4
0
 public function getPostsPager($page = 1, $max_per_page = 10)
 {
     return sfSimpleForumPostPeer::getForForumPager($this->getStrippedName(), $page, $max_per_page);
 }
예제 #5
0
 public function getPostsPager($page = 1, $max_per_page = 10)
 {
     return sfSimpleForumPostPeer::getForTopicPager($this->getId(), $page, $max_per_page);
 }
$t->is($topic->getNbPosts(), 2, 'Adding a second message increments the topic number of posts');
$t->is($topic->getNbReplies(), 1, 'A topic can calculate its number of replies based on its number of posts');
$t->is($topic->getUpdatedAt('U'), $msg2->getCreatedAt('U'), 'Adding a second message changes the latest reply date of the topic to the message creation date');
$t->is($topic->getLatestPost()->getAuthorName(), $user2->getUsername(), 'Adding a second message changes the latest reply author name to the message author name');
sleep(1);
$msg3 = new sfSimpleForumPost();
$msg3->setTopicId($topic->getId());
$msg3->setUserId($user3->getId());
$msg3->save();
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$t->is($topic->getNbPosts(), 3, 'Adding a third message increments the topic number of replies');
$t->is($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Adding a third message changes the latest reply date of the topic to the message creation date');
$t->is($topic->getLatestPost()->getAuthorName(), $user3->getUsername(), 'Adding a third message changes the latest reply author name to the  message author name');
$t->diag('Updating a message');
sleep(1);
$msg1 = sfSimpleForumPostPeer::retrieveByPk($msg1->getId());
$msg1->setTitle('this is a test');
$msg1->save();
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$t->is($topic->getNbPosts(), 3, 'Updating a message doesn\'t change the topic post count');
$t->is($topic->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the topic\'s last update date');
$t->is($topic->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the topic\'s latest reply');
$forum = sfSimpleForumForumPeer::retrieveByPk($forum->getId());
$t->is($forum->getNbPosts(), 3, 'Updating a message doesn\'t change the forum\'s post count');
$t->is($forum->getUpdatedAt('U'), $msg3->getCreatedAt('U'), 'Updating a message doesn\'t change the forum\'s last update date');
$t->is($forum->getLatestPost()->getId(), $msg3->getId(), 'Updating a message doesn\'t change the forum\'s last reply');
$t->diag('Updating the topic');
sleep(1);
$topic = sfSimpleForumTopicPeer::retrieveByPk($topic->getId());
$topic->setTitle('this is another test');
$topic->save();
예제 #7
0
 public function getsfSimpleForumPostsJoinsfSimpleForumForum($criteria = null, $con = null)
 {
     include_once 'lib/model/om/BasesfSimpleForumPostPeer.php';
     if ($criteria === null) {
         $criteria = new Criteria();
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collsfSimpleForumPosts === null) {
         if ($this->isNew()) {
             $this->collsfSimpleForumPosts = array();
         } else {
             $criteria->add(sfSimpleForumPostPeer::USER_ID, $this->getId());
             $this->collsfSimpleForumPosts = sfSimpleForumPostPeer::doSelectJoinsfSimpleForumForum($criteria, $con);
         }
     } else {
         $criteria->add(sfSimpleForumPostPeer::USER_ID, $this->getId());
         if (!isset($this->lastsfSimpleForumPostCriteria) || !$this->lastsfSimpleForumPostCriteria->equals($criteria)) {
             $this->collsfSimpleForumPosts = sfSimpleForumPostPeer::doSelectJoinsfSimpleForumForum($criteria, $con);
         }
     }
     $this->lastsfSimpleForumPostCriteria = $criteria;
     return $this->collsfSimpleForumPosts;
 }
 public function executeLatestPosts()
 {
     $this->posts = sfSimpleForumPostPeer::getLatest(sfConfig::get('app_sfSimpleForumPlugin_max_per_block', 10));
 }
 public static function doSelectJoinAllExceptsfSimpleForumCategory(Criteria $c, $con = null)
 {
     foreach (sfMixer::getCallables('BasesfSimpleForumForumPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') 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;
     sfSimpleForumPostPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + sfSimpleForumPostPeer::NUM_COLUMNS;
     $c->addJoin(sfSimpleForumForumPeer::LATEST_POST_ID, sfSimpleForumPostPeer::ID);
     $rs = BasePeer::doSelect($c, $con);
     $results = array();
     while ($rs->next()) {
         $omClass = sfSimpleForumForumPeer::getOMClass();
         $cls = Propel::import($omClass);
         $obj1 = new $cls();
         $obj1->hydrate($rs);
         $omClass = sfSimpleForumPostPeer::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->getsfSimpleForumPost();
             if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
                 $newObject = false;
                 $temp_obj2->addsfSimpleForumForum($obj1);
                 break;
             }
         }
         if ($newObject) {
             $obj2->initsfSimpleForumForums();
             $obj2->addsfSimpleForumForum($obj1);
         }
         $results[] = $obj1;
     }
     return $results;
 }
예제 #10
0
 /**
  * Selects a collection of sfSimpleForumPost objects pre-filled with related topic and forum objects.
  *
  * @return     array Array of sfSimpleForumPost objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *             rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinTopicAndForum(Criteria $c, $con = null)
 {
     foreach (sfMixer::getCallables('BasesfSimpleForumPostPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable) {
         call_user_func($callable, 'BasesfSimpleForumPostPeer', $c, $con);
     }
     $c = clone $c;
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     sfSimpleForumPostPeer::addSelectColumns($c);
     $startcol2 = sfSimpleForumPostPeer::NUM_COLUMNS - sfSimpleForumPostPeer::NUM_LAZY_LOAD_COLUMNS + 1;
     sfSimpleForumTopicPeer::addSelectColumns($c);
     $startcol3 = $startcol2 + sfSimpleForumTopicPeer::NUM_COLUMNS;
     sfSimpleForumForumPeer::addSelectColumns($c);
     $startcol4 = $startcol3 + sfSimpleForumForumPeer::NUM_COLUMNS;
     $c->addJoin(sfSimpleForumPostPeer::TOPIC_ID, sfSimpleForumTopicPeer::ID);
     $c->addJoin(sfSimpleForumPostPeer::FORUM_ID, sfSimpleForumForumPeer::ID);
     $rs = BasePeer::doSelect($c, $con);
     $results = array();
     while ($rs->next()) {
         $post = new sfSimpleForumPost();
         $post->hydrate($rs);
         $topic = new sfSimpleForumTopic();
         $topic->hydrate($rs, $startcol2);
         $newObject = true;
         foreach ($results as $temp_post) {
             $existing_topic = $temp_post->getsfSimpleForumTopic();
             if ($existing_topic->getPrimaryKey() === $topic->getPrimaryKey()) {
                 $newObject = false;
                 $existing_topic->addsfSimpleForumPost($post);
                 break;
             }
         }
         if ($newObject) {
             $topic->initsfSimpleForumPosts();
             $topic->addsfSimpleForumPost($post);
         }
         $forum = new sfSimpleForumForum();
         $forum->hydrate($rs, $startcol3);
         $newObject = true;
         foreach ($results as $temp_post) {
             $existing_forum = $temp_post->getsfSimpleForumForum();
             if ($existing_forum->getPrimaryKey() === $forum->getPrimaryKey()) {
                 $newObject = false;
                 $existing_forum->addsfSimpleForumPost($post);
                 break;
             }
         }
         if ($newObject) {
             $forum->initsfSimpleForumPosts();
             $forum->addsfSimpleForumPost($post);
         }
         $results[] = $post;
     }
     return $results;
 }
예제 #11
0
  <h1><?php 
echo $title;
?>
</h1>

  <?php 
if (sfConfig::get('app_sfSimpleForumPlugin_allow_new_topic_outside_forum', true)) {
    ?>
  <ul class="forum_actions">
    <li><?php 
    echo link_to(__('New topic'), 'forums/createTopic');
    ?>
</li>
  </ul>    
  <?php 
}
?>
  
  <?php 
include_partial('forums/figures', array('display_topic_link' => false, 'nb_topics' => $topics_pager->getNbResults(), 'topic_rule' => '', 'display_post_link' => true, 'nb_posts' => sfSimpleForumPostPeer::countForUser($user->getUserId()), 'post_rule' => 'forums/userLatestPosts?username='******'&project=' . $project->getSlug(), 'feed_rule' => 'forums/userLatestTopicsFeed?username='******'feed_title' => $feed_title));
?>
    
  <?php 
include_partial('forums/topic_list', array('topics' => $topics_pager->getResults(), 'project' => $project, 'include_forum' => true));
?>
  
  <?php 
echo pager_navigation($topics_pager, 'forums/userLatestTopics?username='******'&project=' . $project->getSlug());
?>

</div>
예제 #12
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(sfSimpleForumPostPeer::ID, $pks, Criteria::IN);
         $objs = sfSimpleForumPostPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 public function executeDeletePost()
 {
     $post = sfSimpleForumPostPeer::retrieveByPk($this->getRequestParameter('id'));
     $this->forward404Unless($post);
     $topic = $post->getTopic();
     if ($topic->countsfSimpleForumPosts() == 1) {
         // it is the last post of the topic, so delete the whole topic
         $topic->delete();
         $forum = $post->getsfSimpleForumForum();
         $this->redirect($this->getModuleName() . '/forum?forum_name=' . $forum->getStrippedName());
     } else {
         // delete only one message and redirect to the topic
         $post->delete();
         $this->redirect($this->getModuleName() . '/topic?id=' . $topic->getId() . '&stripped_title=' . $topic->getStrippedTitle());
     }
 }