Changeset 5356
- Timestamp:
- 10/03/07 22:45:21 (1 year ago)
- Files:
-
- plugins/sfSimpleForumPlugin/trunk/CHANGELOG (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/README (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForum.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPost.php (modified) (4 diffs)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPostPeer.php (modified) (4 diffs)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopic.php (modified) (3 diffs)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/config/cache.yml (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/lib/BasesfSimpleForumActions.class.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_add_post_form.php (added)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_post_list.php (added)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic_list.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic_moderator_actions.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/createTopicSuccess.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/forumLatestPostsSuccess.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/latestPostsSuccess.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/topicSuccess.php (modified) (2 diffs)
- plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/userLatestPostsSuccess.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/package.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfSimpleForumPlugin/trunk/CHANGELOG
r5317 r5356 1 1 == Trunk == 2 2 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) 3 6 * francois: Made the schema customizable 4 * francois: Partialized and restyled moderator actions for easier customization5 7 * francois: Added link to last page for multi-pages topics 6 8 * francois: Refactored actions class for easier custom templating plugins/sfSimpleForumPlugin/trunk/README
r5287 r5356 196 196 == TODO == 197 197 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 199 200 * Moderators can move a topic to another forum and a message to another topic 200 201 * Add images to make the default style less ugly plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForum.php
r5268 r5356 70 70 } 71 71 72 public function updateCounts($latestReply , $con = null)72 public function updateCounts($latestReply = null, $con = null) 73 73 { 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 } 77 87 $this->save($con); 78 88 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPost.php
r5268 r5356 54 54 } 55 55 56 public function save($con = null )56 public function save($con = null, $preserveTopic = false) 57 57 { 58 58 if(!$con) … … 74 74 75 75 $latestPost = $topic->getLatestPostByQuery(); 76 if($preserveTopic) 77 { 78 $topic->leaveUpdatedAtUnchanged(); 79 } 76 80 $topic->updateReplies($latestPost, $con); 77 $this->getsfSimpleForumForum()->updateCounts($latestPost, $con);78 81 79 82 $con->commit(); … … 86 89 } 87 90 88 public function delete($con = null )91 public function delete($con = null, $preserveTopic = true) 89 92 { 90 93 if(!$con) … … 100 103 101 104 $topic = $this->getsfSimpleForumTopic(); 105 if($preserveTopic) 106 { 107 $topic->leaveUpdatedAtUnchanged(); 108 } 102 109 $latestPost = $topic->getLatestPostByQuery(); 103 $topic->setUpdatedAt($latestPost->getCreatedAt());104 110 $topic->updateReplies($latestPost, $con); 105 106 $forum = $this->getsfSimpleForumForum();107 $latestPost = $forum->getLatestPostByQuery();108 $forum->setUpdatedAt($latestPost->getCreatedAt());109 $forum->updateCounts($latestPost, $con);110 111 111 112 $con->commit(); plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPostPeer.php
r5347 r5356 48 48 } 49 49 50 public static function getLatest($max = 10)50 public static function getLatest($max = null) 51 51 { 52 52 $c = self::getLatestCriteria(); 53 $c->setLimit($max); 53 if($max) 54 { 55 $c->setLimit($max); 56 } 54 57 55 58 return self::doSelect($c); … … 76 79 } 77 80 78 public static function getForTopic($topic_id, $max )81 public static function getForTopic($topic_id, $max = null) 79 82 { 80 83 $c = self::getForTopicCriteria($topic_id); 81 84 $c->addDescendingOrderByColumn(self::ID); 82 $c->setLimit($max); 85 if($max) 86 { 87 $c->setLimit($max); 88 } 83 89 $posts = self::doSelect($c); 84 90 … … 107 113 } 108 114 109 public static function getForForum($forum_name, $max = 10)115 public static function getForForum($forum_name, $max = null) 110 116 { 111 117 $c = self::getForForumCriteria($forum_name); 112 $c->setLimit($max); 118 if($max) 119 { 120 $c->setLimit($max); 121 } 113 122 114 123 return self::doSelect($c); … … 136 145 } 137 146 138 public static function getForUser($user_id, $max = 10)147 public static function getForUser($user_id, $max = null) 139 148 { 140 149 $c = self::getForUserCriteria($user_id); 141 $c->setLimit($max); 150 if($max) 151 { 152 $c->setLimit($max); 153 } 142 154 143 155 return self::doSelect($c); plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopic.php
r5287 r5356 91 91 } 92 92 93 public function getPosts($max )93 public function getPosts($max = null) 94 94 { 95 95 return sfSimpleForumPostPeer::getForTopic($this->getId(), $max); … … 101 101 } 102 102 103 public function updateReplies($latestReply , $con = null)103 public function updateReplies($latestReply = null, $con = null) 104 104 { 105 105 if(!$this->isDeleted()) 106 106 { 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); 110 119 } 111 120 } 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) 114 153 { 115 154 if(!$con) … … 126 165 // Update the topic's forum counts 127 166 $forum = $this->getsfSimpleForumForum(); 128 if( $latestPost = $forum->getLatestPostByQuery())167 if(!$latestPost) 129 168 { 130 $forum->setUpdatedAt($latestPost->getCreatedAt()); 131 $forum->updateCounts($latestPost, $con); 169 $latestPost = $forum->getLatestPostByQuery(); 132 170 } 133 171 $forum->updateCounts($latestPost, $con); 172 134 173 $con->commit(); 135 174 } plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/config/cache.yml
r4524 r5356 1 _topic: 2 enabled: on 3 4 _post: 5 enabled: on 6 1 7 _author: 2 8 enabled: on plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/lib/BasesfSimpleForumActions.class.php
r5293 r5356 340 340 $this->forward404Unless($this->forum); 341 341 } 342 343 $this->topic_name = '';344 $this->topic_id = null;345 342 } 346 343 plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic.php
r5317 r5356 44 44 <?php endif; ?> 45 45 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)) ?> 49 47 50 48 </td> plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic_list.php
r5287 r5356 9 9 </tr> 10 10 <?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 )) ?> 12 17 <?php endforeach; ?> 13 18 </table> plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/_topic_moderator_actions.php
r5317 r5356 1 1 <?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 21 21 22 22 <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)) ?> 54 25 55 26 </div> plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/forumLatestPostsSuccess.php
r5293 r5356 27 27 )) ?> 28 28 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)) ?> 34 30 35 31 <?php echo pager_navigation($post_pager, 'sfSimpleForum/forumLatestPosts?forum_name='.$name) ?> plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/latestPostsSuccess.php
r5293 r5356 26 26 )) ?> 27 27 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)) ?> 33 29 34 30 <?php echo pager_navigation($post_pager, 'sfSimpleForum/latestPosts') ?> plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/topicSuccess.php
r5312 r5356 37 37 <?php echo format_number_choice('[1]1 message, no reply|(1,+Inf]%posts% messages', array('%posts%' => $post_pager->getNbResults()), $post_pager->getNbResults()) ?> 38 38 <?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()) ?> 40 40 <?php endif; ?> 41 41 <?php if(sfConfig::get('app_sfSimpleForumPlugin_use_feeds', true)): ?> … … 44 44 </div> 45 45 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)) ?> 51 47 52 48 <?php echo pager_navigation($post_pager, 'sfSimpleForum/topic?id='.$topic->getId().'&stripped_title='.$topic->getStrippedTitle()) ?> 49 53 50 <?php if (!$topic->getIsLocked() && $sf_user->isAuthenticated()): ?> 51 54 52 <h2> 55 53 <?php echo __('Post a reply') ?> 56 54 </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 74 66 <?php elseif ($topic->getIsLocked() && $sf_user->isAuthenticated()): ?> 67 75 68 <?php echo __('This topic was locked by a forum moderator. No reply can be added.') ?> 69 76 70 <?php endif; ?> 77 71 </div> plugins/sfSimpleForumPlugin/trunk/modules/sfSimpleForum/templates/userLatestPostsSuccess.php
r5293 r5356 26 26 )) ?> 27 27 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)) ?> 33 29 34 30 <?php echo pager_navigation($post_pager, 'sfSimpleForum/userLatestPosts?username='.$username) ?> plugins/sfSimpleForumPlugin/trunk/package.xml
r5293 r5356 78 78 <dir name="templates"> 79 79 <file role="data" name="_author.php" /> 80 <file role="data" name="_add_post_form.php" /> 80 81 <file role="data" name="_figures.php" /> 81 82 <file role="data" name="_forum.php" /> 82 83 <file role="data" name="_latestPosts.php" /> 83 84 <file role="data" name="_post.php" /> 85 <file role="data" name="_post_list.php" /> 86 <file role="data" name="_post_moderator_actions.php" /> 84 87 <file role="data" name="_topic.php" /> 85 88 <file role="data" name="_topic_list.php" /> 89 <file role="data" name="_topic_moderator_actions.php" /> 86 90 <file role="data" name="createTopicSuccess.php" /> 87 91 <file role="data" name="forumLatestPostsSuccess.php" />