Adding a Comment Block to Group View

jseidle777 posted 30th of June 2009 in Community Voice. 5 comments.

How I added Comments to the Group page (Dolphin v6.1.6)

SOME BACKGROUND
This is the walk I took to figure out how to add the simple feature of comments to the group page.  I am grateful for the BoonEx team for naming things well so that anyone with a little intuition can guess where to start - not that there weren't somethings that were hard to figure out, but i know I was in the right location.

Intuitive Files and Locations (all relative to your Dolphin 6.1.x install directory):
grp.php
inc/classes/BxDolGroups.php
inc/classes/BxDolCmts.php

The NOT so intuitive Files and locations:
templates/{current_template}/page_71.html    => default template is 'tmpl_uni'
templates/{current_template}/scripts/BxTemplCmtsView.php
templates/base/scripts/BxBaseCmtsView.php

Ok, so now we're ready to start with our project - that is adding comments the group page (AND NOT breaking comments elsewhere)

Our entry point is 'grp.php' - to display the group the case statement for 'group' is executed. On approximately line 83 the following statement is executed in 'BxDolGroups.php' which is included by 'grp.php'

list($iNameIndex, $sHeader, $sHeaderT, $sMainCode, $sGrpBrd, $sGrpLCat, $sGrpLCreated, $sGrpLLocation, $sGrpLMemberCount, $sGrpLCreator, $sGrpLAbout, $sGrpLType, $sGrpLTypeHelp, $sGrpVImage, $sGrpVGalLink, $sGrpVCreatorThumb, $sGrpVCreatorLink, $sGrpVCat, $sGrpVCatLink, $sGrpVType, $sGrpVCreated, $sGrpVCountry, $sGrpVCity, $sGrpVMCount, $sGrpVAbout, $sGrpVDesc, $sGrpVStatus, $sGrpVActions, $sGrpVMembers, $sGrpVForum) = $oGroups->GenGroupMainPage($groupID, $memberID);

The function GenGroupMainPage in 'BxDolGroups.php' is mentioned here as an FYI, and is responsible for setting up the variables that make up the parts of the view for the group page, for example:
Forum View
Member Count
Group Creator

HOW ARE PAGES RENDERED IN DOLPHIN
Here is where some enlightening occurred for me.  I did not see any rendering code in the 'grp.php' and being a newbie, I found it highly frustrating.  How did this work?  Well here's the deal.

The Dolphin template model assigns html pages by a number.  Those templates are located in the templates/{current_template}/ and the are prefaced with 'page_'

If you look in the 'BxDolGroups.php' the page index assigned to variable '$iNameIndex' is 71, and we see that variable being used in 'grp.php' on line 84

$_page['name_index'] = $iNameIndex;

You will then see at the end, when the case for 'group' breaks and it exits the switch, there is a function called PageCode();

PageCode(), which is located in inc/design.inc.php takes the number '71' assigned to $_page['name_index'] and loads the file 'page_71.html', replacing the __attributenames__ with the values assigned to $_page['attributenames'] - it is very cool actually.

ADD COMMENT BLOCK TO PAGE CONTENTS
Back to business, in 'grp.php' file, in the case 'group', before the break on approximately line 116, I added the following code (which I borrowed from BxDolBlogs.php starting at line 1277):

$oCmtsView = new BxTemplCmtsView( 'groupposts', $groupID);
$sPostComm = $oCmtsView->getExtraCss();
$sPostComm .= $oCmtsView->getExtraJs();
$sPostComm .= (!$oCmtsView->isEnabled()) ? '' : $oCmtsView->getCommentsFirst();
$sPostComm = DesignBoxContent ('Comments', $sPostComm, 1);
$_page_cont[$_ni]['group_comments'] = $sPostComm;


Here's what the above code does:
Line 1:
Creates a templatized view that is used for the comments in other components like blogs, and profile comments.  The parameters are very important the first 'groupposts' identifies the item added in the array below and the second is the item identifies the comments specifically assigned to the current group.  To note, this line is creating a group that I added in the 'BxDolCmts.php' file.

Here's how.  On line 14 of 'BxDolCmts.php' file you will see the creation of an array called $_aSystems.  At the end of the array you will see a ), followed by a ); the ), is the last item in the array and the ); closes the array.  Add the following code after the last item but before the closing of the array:

'groupposts' => array (
'system_id' => 8,    // this system id
'table_cmts' => 'CmtsGroupPosts',    // table with comments
'table_track' => 'CmtsTrack',    // table to track duplicate ratings
'allow_tags' => 0,    // allow tags in comments or not
'nl2br' => 1,    // convert all new line caracters to <br /> tags
'sec_to_edit' => 90,    // number of seconds to allow edit comment after submit, 0 - do not allow edit
'per_view' => 6,    // comments per view, like paginate
'is_ratable' => 0,    // allow rate comments or not
'viewing_threshold' => -3,    // below this value comment is hidden by default
'animation_effect' => 'slide',    // animation effect : slide, fade or default
'animation_speed' => '2000',    // speed of animation effect in ms (1000 == 1 second)
'is_on' => 1    // is voting enabled or not
),


The important things to note here are that the 'system_id' must be unique.
The other thing is you need to NOTE the value of 'table_cmts', in this case I named it 'CmtsGroupPosts' - is actually the name of the table that needs to be created - (See the bottom of this blog to do this using phpMyAdmin)
Please refer to the comments in the code block above for additional details.

Lines 2 & 3: Just clean up the generated view and apply styling

Line 4: Gets all the comments from the database assigned to the defined table and group ID.  We will be coming back to this because currently the function getCommentsFirst(); makes comments appear oldest first - which is fine for blogs but not for our group :)

Line 5: Creates the chrome (the frame around) the comments and provides facilities for displaying, adding, editing and removing comments.  To note, the DesignBoxContent function can be found in inc/design.inc.php

Line 6: May be the most important line, as it is responsible for adding the page attribute group_comments which will be used to replace the attribute __group_comment__ in page_71.html

MODIFY 'page_71.html' FILE - THE GROUP RENDERING
The next step is to finally get the comments to appear on the page.  In the page_71.html file, insert the following code before the last closing </div>:

__group_comments__

Note if you have Orca installed you might want to insert it before the attribute __group_forum__

I will not take up space here to discuss the layout of the group page, but playing around here or having html skills will allow you to position it where you'd like.

Now, if you look at your group page on your site you will see the comment component view on it.  However, because we have not created the table 'CmtsGroupPosts' nothing gets saved.  Thankfully the BoonEx team has created very stable components and no errors are generated here.  So let's create the table

SET UP THE TABLE
Bring up phpMyAdmin and select the database for you Dolphin installation.  Select the table 'CmtsBlogPosts'.  You should see the structure view of the table.  Select the tab 'Operations'.  Look for the section entitled 'Copy table to (database.table)'. 

In the drop down make sure your Dolphin database is selected.  In the textbox that follows enter the name of the table that you assigned above for the array property 'table_cmts'.  In my case, it was called 'CmtsGroupPosts'.

Select the radio button 'Structure only' and click Go

Now everything should work with comments on your group page


 
Comments
·Oldest
·Top
Please login to post a comment.
Thanks for the Blog post, I'm sure this will help a lot of ppl...
Thanks for posting this!
Chrixxi
Great ! Very good explanation. Thanks for this.
jtadeo
Well done and thanks for sharing your knowledge. I know it took some of your time and I am sure many will benefit.
Thanks for sharing. Another deposit to my knowledge bank.
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.
PET:0.046504020690918