Changeset 5520
- Timestamp:
- 10/15/07 11:20:33 (6 years ago)
- Files:
-
- plugins/sfSimpleForumPlugin/trunk/CHANGELOG (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/README (modified) (2 diffs)
- plugins/sfSimpleForumPlugin/trunk/config/schema.yml (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/config/schemaConfig.php (deleted)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumCategory.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumCategoryPeer.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumForum.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumForumPeer.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumPost.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumPostPeer.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumTopic.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumTopicPeer.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumTopicView.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/plugin/PluginsfSimpleForumTopicViewPeer.php (added)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumCategory.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumCategoryPeer.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForum.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForumPeer.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPost.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPostPeer.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopic.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopicPeer.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopicView.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopicViewPeer.php (modified) (1 diff)
- plugins/sfSimpleForumPlugin/trunk/package.xml (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfSimpleForumPlugin/trunk/CHANGELOG
r5448 r5520 1 1 == Trunk == 2 2 3 * francois: Switched schema configuration method to sfPropelAlternativeSchemaPlugin (now a prerequisite) 4 * francois: Added a supplementary customization layer to the model classes 5 3 6 == 2007-10-10 | 0.6.4 Beta == 4 7 plugins/sfSimpleForumPlugin/trunk/README
r5356 r5520 31 31 32 32 The prerequisites for using the `sfSimpleForum` plugin are: 33 - You must install the `sfPropelAlternativeSchemaPlugin` 33 34 - As the plugin doesn't contain a user management module, the project where you install it must have a table managing authors, or users (whatever the name), and the related Propel class must have a `__toString()` method. Both these conditions are satisfied by the [http://trac.symfony-project.com/trac/wiki/sfFeed2Plugin sfGuardPlugin], so installing this plugin is a good choice. 34 35 - If you want to use RSS feeds, you must install the [http://trac.symfony-project.com/trac/wiki/sfFeed2Plugin sfFeed2Plugin]. … … 104 105 105 106 == Configuration == 107 108 === Schema customization === 109 110 The schema file located under `config/schema.yml` uses an alternative schema syntax, allowed by the `sfPropelAlternativeSchemaPlugin`. This means that you can override this schema by creating a `sfSimpleForumPlugin_schema.custom.yml` file under your project's `config/` directory. This allows you to customize the connection name, table names, and even foreign classs associations. Refer to the [http://trac.symfony-project.com/wiki/sfPropelAlternativeSchemaPluginsfPropelAlternativeSchemaPlugin README file] for more information. 106 111 107 112 === app.yml === plugins/sfSimpleForumPlugin/trunk/config/schema.yml
r5317 r5520 1 <?php include_once('schemaConfig.php') ?> 2 <?php start_schema() ?> 3 4 %connection%: 5 6 %category_table%: 7 _attributes: { phpName: sfSimpleForumCategory, package: plugins.sfSimpleForumPlugin.lib.model } 8 id: 9 name: varchar(255) 10 stripped_name: varchar(255) 11 description: longvarchar 12 rank: integer 13 created_at: 1 <?php if(!is_callable(array('sfPropelDatabaseSchema', 'loadNewYaml'))) throw new Exception('You must install the sfPropelAlternativeSchemaPlugin to use the sfSimpleForum') ?> 2 classes: 3 sfSimpleForumCategory: 4 package: plugins.sfSimpleForumPlugin.lib.model 5 columns: 6 id: 7 name: varchar(255) 8 stripped_name: varchar(255) 9 description: longvarchar 10 rank: integer 11 created_at: 14 12 15 %forum_table%: 16 _attributes: { phpName: sfSimpleForumForum, package: plugins.sfSimpleForumPlugin.lib.model } 17 id: 18 name: varchar(255) 19 description: longvarchar 20 rank: integer 21 category_id: { type: integer, foreignTable: %category_table%, foreignReference: id, onDelete: cascade } 22 created_at: 23 updated_at: 24 # performance enhancers 25 stripped_name: { type: varchar, size: 255, index: unique } 26 latest_post_id: { type: integer, foreignTable: %post_table%, foreignReference: id, onDelete: setnull } 27 nb_posts: bigint 28 nb_topics: bigint 13 sfSimpleForumForum: 14 package: plugins.sfSimpleForumPlugin.lib.model 15 columns: 16 id: 17 name: varchar(255) 18 description: longvarchar 19 rank: integer 20 category_id: { type: integer, foreignClass: sfSimpleForumCategory, foreignReference: id, onDelete: cascade } 21 created_at: 22 updated_at: 23 # performance enhancers 24 stripped_name: { type: varchar, size: 255, index: unique } 25 latest_post_id: { type: integer, foreignClass: sfSimpleForumPost, foreignReference: id, onDelete: setnull } 26 nb_posts: bigint 27 nb_topics: bigint 29 28 30 %topic_table%: 31 _attributes: { phpName: sfSimpleForumTopic, package: plugins.sfSimpleForumPlugin.lib.model } 32 id: 33 title: varchar(255) 34 is_sticked: { type: boolean, default: false } 35 is_locked: { type: boolean, default: false } 36 forum_id: { type: integer, foreignTable: %forum_table%, foreignReference: id, onDelete: cascade } 37 created_at: 38 updated_at: 39 # performance enhancers 40 latest_post_id: { type: integer, foreignTable: %post_table%, foreignReference: id, onDelete: setnull } 41 user_id: { type: integer, foreignTable: %user_table%, foreignReference: %user_id%, onDelete: setnull } 42 stripped_title: varchar(255) 43 nb_posts: { type: bigint, default: 0 } 44 nb_views: { type: bigint, default: 0 } 29 sfSimpleForumTopic: 30 package: plugins.sfSimpleForumPlugin.lib.model 31 columns: 32 id: 33 title: varchar(255) 34 is_sticked: { type: boolean, default: false } 35 is_locked: { type: boolean, default: false } 36 forum_id: { type: integer, foreignClass: sfSimpleForumForum, foreignReference: id, onDelete: cascade } 37 created_at: 38 updated_at: 39 # performance enhancers 40 latest_post_id: { type: integer, foreignClass: sfSimpleForumPost, foreignReference: id, onDelete: setnull } 41 user_id: { type: integer, foreignClass: sfGuardUser, foreignReference: id, onDelete: setnull } 42 stripped_title: varchar(255) 43 nb_posts: { type: bigint, default: 0 } 44 nb_views: { type: bigint, default: 0 } 45 45 46 %post_table%: 47 _attributes: { phpName: sfSimpleForumPost, package: plugins.sfSimpleForumPlugin.lib.model } 48 id: 49 title: varchar(255) 50 content: longvarchar 51 topic_id: { type: integer, foreignTable: %topic_table%, foreignReference: id, onDelete: cascade } 52 user_id: { type: integer, foreignTable: %user_table%, foreignReference: %user_id%, onDelete: cascade } 53 created_at: 54 # performance enhancers 55 forum_id: { type: integer, foreignTable: %forum_table%, foreignReference: id, onDelete: cascade } 56 author_name: varchar(255) 46 sfSimpleForumPost: 47 package: plugins.sfSimpleForumPlugin.lib.model 48 columns: 49 id: 50 title: varchar(255) 51 content: longvarchar 52 topic_id: { type: integer, foreignClass: sfSimpleForumTopic, foreignReference: id, onDelete: cascade } 53 user_id: { type: integer, foreignClass: sfGuardUser, foreignReference: id, onDelete: cascade } 54 created_at: 55 # performance enhancers 56 forum_id: { type: integer, foreignClass: sfSimpleForumForum, foreignReference: id, onDelete: cascade } 57 author_name: varchar(255) 57 58 58 %topic_view_table%: 59 _attributes: { phpName: sfSimpleForumTopicView, package: plugins.sfSimpleForumPlugin.lib.model } 60 user_id: { type: integer, foreignTable: %user_table%, foreignReference: %user_id%, onDelete: cascade, primaryKey: true } 61 topic_id: { type: integer, foreignTable: %topic_table%, foreignReference: id, onDelete: cascade, primaryKey: true } 62 created_at: 63 64 <?php return end_schema() ?> 59 sfSimpleForumTopicView: 60 package: plugins.sfSimpleForumPlugin.lib.model 61 columns: 62 user_id: { type: integer, foreignClass: sfGuardUser, foreignReference: id, onDelete: cascade, primaryKey: true } 63 topic_id: { type: integer, foreignClass: sfSimpleForumTopic, foreignReference: id, onDelete: cascade, primaryKey: true } 64 created_at: plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumCategory.php
r4996 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumCategory extends BasesfSimpleForumCategory10 class sfSimpleForumCategory extends PluginsfSimpleForumCategory 11 11 { 12 public function getFora()13 {14 $c = new Criteria();15 $c->add(sfSimpleForumForumPeer::CATEGORY_ID, $this->getId());16 return sfSimpleForumForumPeer::doSelect($c);17 }18 19 public function __toString()20 {21 return $this->getName();22 }23 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumCategoryPeer.php
r4524 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumCategoryPeer extends BasesfSimpleForumCategoryPeer10 class sfSimpleForumCategoryPeer extends PluginsfSimpleForumCategoryPeer 11 11 { 12 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForum.php
r5356 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumForum extends BasesfSimpleForumForum10 class sfSimpleForumForum extends PluginsfSimpleForumForum 11 11 { 12 public function setName($name)13 {14 parent::setName($name);15 $this->setStrippedName(sfSimpleForumTools::stripText($name));16 }17 18 public function getTopics($max = 10)19 {20 $c = $this->getTopicsCriteria();21 $c->setLimit($max);22 23 return sfSimpleForumTopicPeer::doSelect($c);24 }25 26 public function getTopicsPager($page = 1, $max_per_page = 10)27 {28 $c = $this->getTopicsCriteria();29 $pager = new sfPropelPager('sfSimpleForumTopic', $max_per_page);30 $pager->setPage($page);31 $pager->setCriteria($c);32 $pager->setPeerMethod('doSelectJoinsfSimpleForumPost');33 $pager->init();34 35 return $pager;36 }37 38 public function getTopicsCriteria()39 {40 $c = new Criteria();41 $c->add(sfSimpleForumTopicPeer::FORUM_ID, $this->getId());42 $c->addDescendingOrderByColumn(sfSimpleForumTopicPeer::IS_STICKED);43 $c->addDescendingOrderByColumn(sfSimpleForumTopicPeer::UPDATED_AT);44 45 return $c;46 }47 48 public function getLatestPostByQuery()49 {50 $c = new Criteria();51 $c->add(sfSimpleForumPostPeer::FORUM_ID, $this->getId());52 $c->addDescendingOrderByColumn(sfSimpleForumPostPeer::CREATED_AT);53 54 return sfSimpleForumPostPeer::doSelectOne($c);55 }56 57 public function getLatestPost($con = null)58 {59 return $this->getsfSimpleForumPost($con);60 }61 62 public function getPosts($max)63 {64 return sfSimpleForumPostPeer::getForForum($this->getStrippedName(), $max);65 }66 67 public function getPostsPager($page = 1, $max_per_page = 10)68 {69 return sfSimpleForumPostPeer::getForForumPager($this->getStrippedName(), $page, $max_per_page);70 }71 72 public function updateCounts($latestReply = null, $con = null)73 {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 else82 {83 $this->setNbPosts(0);84 $this->setNbTopics(0);85 $this->setLatestPostId(null);86 }87 $this->save($con);88 }89 90 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumForumPeer.php
r5447 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumForumPeer extends BasesfSimpleForumForumPeer10 class sfSimpleForumForumPeer extends PluginsfSimpleForumForumPeer 11 11 { 12 public static function retrieveByStrippedName($stripped_name)13 {14 $c = new Criteria();15 $c->add(self::STRIPPED_NAME, $stripped_name);16 17 return self::doSelectOne($c);18 }19 20 public static function getAllOrderedByCategory()21 {22 $c = new Criteria();23 $c->addJoin(self::CATEGORY_ID, sfSimpleForumCategoryPeer::ID);24 $c->addAscendingOrderByColumn(sfSimpleForumCategoryPeer::RANK);25 $c->addAscendingOrderByColumn(self::RANK);26 27 return self::doSelectJoinCategoryLeftJoinPost($c);28 }29 30 public static function getAllAsArray()31 {32 $forums = self::getAllOrderedByCategory();33 $res = array();34 35 foreach ($forums as $forum)36 {37 $res[$forum->getStrippedName()] = $forum->getName();38 }39 40 return $res;41 }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 }137 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPost.php
r5403 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumPost extends BasesfSimpleForumPost10 class sfSimpleForumPost extends PluginsfSimpleForumPost 11 11 { 12 public function getUser()13 {14 return $this->getsfGuardUser();15 }16 17 public function setUserId($id)18 {19 parent::setUserId($id);20 $this->setAuthorName($this->getUser()->__toString());21 }22 23 public function getTopic()24 {25 return $this->getsfSimpleForumTopic();26 }27 28 public function setTopicId($id)29 {30 parent::setTopicId($id);31 if($this->isNew())32 {33 $topic = $this->getsfSimpleForumTopic();34 $this->setTitle($topic->getTitle());35 $this->setForumId($topic->getForumId());36 }37 }38 39 public function getPositionInTopic()40 {41 $c = new Criteria();42 $c->clearSelectColumns();43 $c->addSelectColumn(sfSimpleForumPostPeer::ID);44 $c->add(sfSimpleForumPostPeer::TOPIC_ID, $this->getTopicId());45 $c->addAscendingOrderByColumn(sfSimpleForumPostPeer::CREATED_AT);46 $rs = sfSimpleForumPostPeer::doSelectRS($c);47 $messages = array();48 while($rs->next())49 {50 $messages[] = $rs->getInt(1);51 }52 53 return array_search($this->getId(), $messages);54 }55 56 public function save($con = null, $preserveTopic = false)57 {58 if(!$con)59 {60 $con = Propel::getConnection();61 }62 63 try64 {65 $con->begin();66 67 $topic = $this->getsfSimpleForumTopic();68 if($this->isNew())69 {70 $topic->clearViews();71 }72 73 parent::save($con);74 75 $latestPost = $topic->getLatestPostByQuery();76 if($preserveTopic)77 {78 $topic->leaveUpdatedAtUnchanged();79 }80 $topic->updateReplies($latestPost, $con);81 82 $con->commit();83 }84 catch (Exception $e)85 {86 $con->rollback();87 throw $e;88 }89 }90 91 public function delete($con = null, $preserveTopic = true)92 {93 if(!$con)94 {95 $con = Propel::getConnection();96 }97 98 try99 {100 $con->begin();101 102 parent::delete($con);103 104 $topic = $this->getsfSimpleForumTopic();105 if($preserveTopic)106 {107 $topic->leaveUpdatedAtUnchanged();108 }109 $latestPost = $topic->getLatestPostByQuery();110 $topic->updateReplies($latestPost, $con);111 112 $con->commit();113 }114 catch (Exception $e)115 {116 $con->rollback();117 throw $e;118 }119 }120 121 public function getFeedLink()122 {123 return 'sfSimpleForum/topic?id='.$this->getTopicId().'&stripped_title='.$this->getsfSimpleForumTopic()->getStrippedTitle();124 }125 126 public function getCreationTimestamp()127 {128 return $this->getCreatedAt('U');129 }130 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumPostPeer.php
r5403 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumPostPeer extends BasesfSimpleForumPostPeer10 class sfSimpleForumPostPeer extends PluginsfSimpleForumPostPeer 11 11 { 12 13 public static function getOneJoinForum($id)14 {15 $c = new Criteria();16 $c->add(self::ID, $id);17 $c->setLimit(1);18 19 $objects = self::doSelectJoinsfSimpleForumForum($c);20 21 if ($objects)22 {23 return $objects[0];24 }25 return null;26 }27 public static function getLatestCriteria()28 {29 $c = new Criteria();30 $c->addDescendingOrderByColumn(self::ID);31 32 return $c;33 }34 35 public static function getLatest($max = null)36 {37 $c = self::getLatestCriteria();38 if($max)39 {40 $c->setLimit($max);41 }42 43 return self::doSelect($c);44 }45 46 public static function getLatestPager($page = 1, $max_per_page = 10)47 {48 $c = self::getLatestCriteria();49 $pager = new sfPropelPager('sfSimpleForumPost', $max_per_page);50 $pager->setPage($page);51 $pager->setCriteria($c);52 $pager->setPeerMethod('doSelectJoinsfSimpleForumForum');53 $pager->init();54 55 return $pager;56 }57 58 public static function getForTopicCriteria($topic_id)59 {60 $c = new Criteria();61 $c->add(sfSimpleForumPostPeer::TOPIC_ID, $topic_id);62 63 return $c;64 }65 66 public static function getForTopic($topic_id, $max = null)67 {68 $c = self::getForTopicCriteria($topic_id);69 $c->addDescendingOrderByColumn(self::ID);70 if($max)71 {72 $c->setLimit($max);73 }74 $posts = self::doSelect($c);75 76 return $posts;77 }78 79 public static function getForTopicPager($topic_id, $page = 1, $max_per_page = 10)80 {81 $c = self::getForTopicCriteria($topic_id);82 $c->addAscendingOrderByColumn(self::ID);83 $pager = new sfPropelPager('sfSimpleForumPost', $max_per_page);84 $pager->setPage($page);85 $pager->setCriteria($c);86 $pager->init();87 88 return $pager;89 }90 91 public static function getForForumCriteria($forum_name)92 {93 $c = self::getLatestCriteria();94 $c->addJoin(self::FORUM_ID, sfSimpleForumForumPeer::ID);95 $c->add(sfSimpleForumForumPeer::STRIPPED_NAME, $forum_name);96 97 return $c;98 }99 100 public static function getForForum($forum_name, $max = null)101 {102 $c = self::getForForumCriteria($forum_name);103 if($max)104 {105 $c->setLimit($max);106 }107 108 return self::doSelect($c);109 }110 111 public static function getForForumPager($forum_name = '', $page = 1, $max_per_page = 10)112 {113 $c = self::getForForumCriteria($forum_name);114 $pager = new sfPropelPager('sfSimpleForumPost', $max_per_page);115 $pager->setPage($page);116 $pager->setCriteria($c);117 $pager->setPeerMethod('doSelectJoinsfSimpleForumForum');118 $pager->init();119 120 return $pager;121 }122 123 public static function getForUserCriteria($user_id)124 {125 $c = new Criteria();126 $c->add(self::USER_ID, $user_id);127 $c->addDescendingOrderByColumn(self::ID);128 129 return $c;130 }131 132 public static function getForUser($user_id, $max = null)133 {134 $c = self::getForUserCriteria($user_id);135 if($max)136 {137 $c->setLimit($max);138 }139 140 return self::doSelect($c);141 }142 143 public static function getForUserPager($user_id, $page = 1, $max_per_page = 10)144 {145 $c = self::getForUserCriteria($user_id);146 $pager = new sfPropelPager('sfSimpleForumPost', $max_per_page);147 $pager->setPage($page);148 $pager->setCriteria($c);149 $pager->setPeerMethod('doSelectJoinsfSimpleForumForum');150 $pager->init();151 152 return $pager;153 }154 155 public static function countForUser($user_id)156 {157 $c = new Criteria();158 $c->add(self::USER_ID, $user_id);159 160 return self::doCount($c);161 }162 163 /**164 * Selects a collection of sfSimpleForumPost objects pre-filled with related topic and forum objects.165 *166 * @return array Array of sfSimpleForumPost objects.167 * @throws PropelException Any exceptions caught during processing will be168 * rethrown wrapped into a PropelException.169 */170 public static function doSelectJoinTopicAndForum(Criteria $c, $con = null)171 {172 foreach (sfMixer::getCallables('BasesfSimpleForumPostPeer:doSelectJoinAllExcept:doSelectJoinAllExcept') as $callable)173 {174 call_user_func($callable, 'BasesfSimpleForumPostPeer', $c, $con);175 }176 177 $c = clone $c;178 179 if ($c->getDbName() == Propel::getDefaultDB())180 {181 $c->setDbName(self::DATABASE_NAME);182 }183 184 sfSimpleForumPostPeer::addSelectColumns($c);185 $startcol2 = (sfSimpleForumPostPeer::NUM_COLUMNS - sfSimpleForumPostPeer::NUM_LAZY_LOAD_COLUMNS) + 1;186 sfSimpleForumTopicPeer::addSelectColumns($c);187 $startcol3 = $startcol2 + sfSimpleForumTopicPeer::NUM_COLUMNS;188 sfSimpleForumForumPeer::addSelectColumns($c);189 $startcol4 = $startcol3 + sfSimpleForumForumPeer::NUM_COLUMNS;190 $c->addJoin(sfSimpleForumPostPeer::TOPIC_ID, sfSimpleForumTopicPeer::ID);191 $c->addJoin(sfSimpleForumPostPeer::FORUM_ID, sfSimpleForumForumPeer::ID);192 193 $rs = BasePeer::doSelect($c, $con);194 $results = array();195 196 while($rs->next())197 {198 $post = new sfSimpleForumPost();199 $post->hydrate($rs);200 201 $topic = new sfSimpleForumTopic();202 $topic->hydrate($rs, $startcol2);203 204 $newObject = true;205 foreach ($results as $temp_post)206 {207 $existing_topic = $temp_post->getsfSimpleForumTopic();208 if ($existing_topic->getPrimaryKey() === $topic->getPrimaryKey())209 {210 $newObject = false;211 $existing_topic->addsfSimpleForumPost($post);212 break;213 }214 }215 216 if ($newObject)217 {218 $topic->initsfSimpleForumPosts();219 $topic->addsfSimpleForumPost($post);220 }221 222 $forum = new sfSimpleForumForum();223 $forum->hydrate($rs, $startcol3);224 225 $newObject = true;226 foreach ($results as $temp_post)227 {228 $existing_forum = $temp_post->getsfSimpleForumForum();229 if ($existing_forum->getPrimaryKey() === $forum->getPrimaryKey())230 {231 $newObject = false;232 $existing_forum->addsfSimpleForumPost($post);233 break;234 }235 }236 237 if ($newObject)238 {239 $forum->initsfSimpleForumPosts();240 $forum->addsfSimpleForumPost($post);241 }242 243 $results[] = $post;244 }245 return $results;246 }247 248 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopic.php
r5356 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumTopic extends BasesfSimpleForumTopic10 class sfSimpleForumTopic extends PluginsfSimpleForumTopic 11 11 { 12 protected13 $is_new = false;14 15 public function getIsNew()16 {17 return $this->is_new;18 }19 20 public function setIsNew($value = true)21 {22 $this->is_new = $value;23 }24 25 public function getUser()26 {27 return $this->getsfGuardUser();28 }29 30 public function setTitle($title)31 {32 parent::setTitle($title);33 $this->setStrippedTitle(sfSimpleForumTools::stripText($title));34 }35 36 public function leaveUpdatedAtUnchanged()37 {38 $this->modifiedColumns[] = sfSimpleForumTopicPeer::UPDATED_AT;39 }40 41 public function incrementViews()42 {43 $this->setNbViews($this->getNbViews() + 1);44 // Preserve the previous update date to avoid changing the topic order45 $this->leaveUpdatedAtUnchanged();46 parent::save();47 }48 49 public function addViewForUser($user_id)50 {51 //check if there is not already a topic view for this user52 if (sfSimpleForumTopicViewPeer::retrieveByPk($user_id, $this->getId()))53 {54 return;55 }56 $topicView = new sfSimpleForumTopicView();57 $topicView->setTopicId($this->getId());58 $topicView->setUserId($user_id);59 $topicView->save();60 }61 62 public function getViewForUser($user_id)63 {64 return sfSimpleForumTopicViewPeer::retrieveByPk($user_id, $this->getId());65 }66 67 public function clearViews()68 {69 $c = new Criteria();70 $c->add(sfSimpleForumTopicViewPeer::TOPIC_ID, $this->getId());71 sfSimpleForumTopicViewPeer::doDelete($c);72 }73 74 public function getNbReplies()75 {76 return $this->getNbPosts() - 1;77 }78 79 public function getLatestPostByQuery()80 {81 $c = new Criteria();82 $c->add(sfSimpleForumPostPeer::TOPIC_ID, $this->getId());83 $c->addDescendingOrderByColumn(sfSimpleForumPostPeer::CREATED_AT);84 85 return sfSimpleForumPostPeer::doSelectOne($c);86 }87 88 public function getLatestPost()89 {90 return $this->getsfSimpleForumPost();91 }92 93 public function getPosts($max = null)94 {95 return sfSimpleForumPostPeer::getForTopic($this->getId(), $max);96 }97 98 public function getPostsPager($page = 1, $max_per_page = 10)99 {100 return sfSimpleForumPostPeer::getForTopicPager($this->getId(), $page, $max_per_page);101 }102 103 public function updateReplies($latestReply = null, $con = null)104 {105 if(!$this->isDeleted())106 {107 if($latestReply)108 {109 $this->setNbPosts($this->countsfSimpleForumPosts());110 $this->setLatestPostId($latestReply->getId());111 $this->setUpdatedAt($latestReply->getCreatedAt());112 }113 else114 {115 $this->setNbPosts(0);116 $this->setLatestPostId(null);117 }118 $this->save($con, $latestReply);119 }120 }121 122 public function save($con = null, $latestPost = null)123 {124 if(!$con)125 {126 $con = Propel::getConnection();127 }128 129 try130 {131 $con->begin();132 133 parent::save($con);134 135 // Update the topic's forum counts136 $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)153 {154 if(!$con)155 {156 $con = Propel::getConnection();157 }158 159 try160 {161 $con->begin();162 163 parent::delete($con);164 165 // Update the topic's forum counts166 $forum = $this->getsfSimpleForumForum();167 if(!$latestPost)168 {169 $latestPost = $forum->getLatestPostByQuery();170 }171 $forum->updateCounts($latestPost, $con);172 173 $con->commit();174 }175 catch (Exception $e)176 {177 $con->rollback();178 throw $e;179 }180 }181 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopicPeer.php
r5403 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumTopicPeer extends BasesfSimpleForumTopicPeer10 class sfSimpleForumTopicPeer extends PluginsfSimpleForumTopicPeer 11 11 { 12 public static function setIsNewForUser($topics, $user_id)13 {14 $topic_ids = array();15 $topic_hash = array();16 foreach ($topics as $topic)17 {18 // A topic is new unless we can find a view from the user for it19 $topic->setIsNew(true);20 $id = $topic->getId();21 $topic_ids[] = $id;22 $topic_hash[$id] = $topic;23 }24 25 $c = new Criteria();26 $c->clearSelectColumns();27 $c->addSelectColumn(sfSimpleForumTopicViewPeer::TOPIC_ID);28 $c->add(sfSimpleForumTopicViewPeer::USER_ID, $user_id);29 $c->add(sfSimpleForumTopicViewPeer::TOPIC_ID, $topic_ids, Criteria::IN);30 $rs = sfSimpleForumTopicViewPeer::doSelectRS($c);31 32 while($rs->next())33 {34 $topic = $topic_hash[$rs->getInt(1)];35 $topic->setIsNew(false);36 }37 38 return $topic_hash;39 }40 41 public static function getLatestCriteria()42 {43 $c = new Criteria();44 $c->addDescendingOrderByColumn(self::UPDATED_AT);45 46 return $c;47 }48 49 public static function getLatest($max = 10)50 {51 $c = self::getLatestCriteria();52 $c->setLimit($max);53 54 return self::doSelectJoinAll($c);55 }56 57 public static function getLatestPager($page = 1, $max_per_page = 10)58 {59 $c = self::getLatestCriteria();60 $pager = new sfPropelPager('sfSimpleForumTopic', $max_per_page);61 $pager->setPage($page);62 $pager->setCriteria($c);63 $pager->setPeerMethod('doSelectJoinAll');64 $pager->init();65 66 return $pager;67 }68 69 public static function getForUserCriteria($user_id)70 {71 $c = new Criteria();72 $c->add(self::USER_ID, $user_id);73 $c->addDescendingOrderByColumn(self::UPDATED_AT);74 75 return $c;76 }77 78 public static function getForUser($user_id, $max = 10)79 {80 $c = self::getForUserCriteria($user_id);81 $c->setLimit($max);82 83 return self::doSelectJoinAll($c);84 }85 86 public static function getForUserPager($user_id, $page = 1, $max_per_page = 10)87 {88 $c = self::getForUserCriteria($user_id);89 $pager = new sfPropelPager('sfSimpleForumTopic', $max_per_page);90 $pager->setPage($page);91 $pager->setCriteria($c);92 $pager->setPeerMethod('doSelectJoinAll');93 $pager->init();94 95 return $pager;96 }97 98 public static function countForUser($user_id)99 {100 $c = new Criteria();101 $c->add(self::USER_ID, $user_id);102 103 return self::doCount($c);104 }105 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopicView.php
r5101 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumTopicView extends BasesfSimpleForumTopicView10 class sfSimpleForumTopicView extends PluginsfSimpleForumTopicView 11 11 { 12 12 } plugins/sfSimpleForumPlugin/trunk/lib/model/sfSimpleForumTopicViewPeer.php
r5101 r5520 8 8 * @package plugins.sfSimpleForumPlugin.lib.model 9 9 */ 10 class sfSimpleForumTopicViewPeer extends BasesfSimpleForumTopicViewPeer10 class sfSimpleForumTopicViewPeer extends PluginsfSimpleForumTopicViewPeer 11 11 { 12 12 } plugins/sfSimpleForumPlugin/trunk/package.xml
r5448 r5520 33 33 <dir name="config"> 34 34 <file role="data" name="schema.yml" /> 35 <file role="data" name="schemaConfig.php" />36 35 </dir> 37 36 … … 48 47 </dir> 49 48 <dir name="model"> 49 <dir name="plugin"> 50 <file role="data" name="PluginsfSimpleForumCategory.php" /> 51 <file role="data" name="PluginsfSimpleForumCategoryPeer.php" /> 52 <file role="data" name="PluginsfSimpleForumForum.php" /> 53 <file role="data" name="PluginsfSimpleForumForumPeer.php" /> 54 <file role="data" name="PluginsfSimpleForumPost.php" /> 55 <file role="data" name="PluginsfSimpleForumPostPeer.php" /> 56 <file role="data" name="PluginsfSimpleForumTopic.php" /> 57 <file role="data" name="PluginsfSimpleForumTopicPeer.php" /> 58 <file role="data" name="PluginsfSimpleForumTopicView.php" /> 59 <file role="data" name="PluginsfSimpleForumTopicViewPeer.php" /> 60 </dir> 50 61 <file role="data" name="sfSimpleForumCategory.php" /> 51 62 <file role="data" name="sfSimpleForumCategoryPeer.php" />