Website Comments - getRecords

4 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 28, 2012   (RSS)

Re: [Perchpole] Website Comments - getRecords

By Dave - May 27, 2012

Hi Perch,

Glad to hear you are liking the plugin! :) Here's some answers to your questions (and some extra background info you may find helpful).

>Can I run a getRecords call to list the comments?

The standard way to list comments is with the wsc_comments() function call (see the readme.txt and the plugin examples). The output displayed for comments can be modified in plugins/websiteComments/themes/default.php

It actually already loads all the details about the user who created each comment, so if you wanted to display the comment creators fullname for example you could use: <?php echo $comment['createdBy.fullname'] ?>.

This is actually an undocumented feature of getRecords(), anytime there is a createdByUserNum field it loads that record and adds all those fields with the "createdBy." prefix. Note that the fields are not loaded with a join so you can search or sort on them.

We have a utility function called showme() that outputs all the variables in an array or record. So anytime you want to see what's available to you just add some temporary debug code: <?php showme($record); ?>.

Next, if you want to do a direct getRecords() call you can copy the code for that from wsc_comments_getRecords() in websiteComments.php or just call that function directly.

And lastly, the double underscore is intended. Many of the plugins need to create their own tables, but we have no way of knowing which tables a user may have already created, so the CMS doesn't allow you to create tables that start with an underscore and the plugins all use tables that start with an underscore so there is no chance of a collision.

Hope that helps! Let me know any questions.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Website Comments - getRecords

By Perchpole - May 27, 2012

Hi, Dave -

Thanks for your note. My main reason for asking this question is because I want to feed a couple of comments on to the front page of the site. These will form a bit of interest in the page footer under the heading of "Latest Comments..."

After reading your suggestions I've done this...

<?php
// load comments
list($quickcomments) = getRecords(array(
'tableName' => '_wsc_comments',
'orderBy' => ($GLOBALS['WSC_SORT_ORDER'] == 'newest') ? 'createdDate DESC' : 'createdDate',
'limit' => '2',
'allowSearch' => false,
));
?>


I've stripped out some the erroneous code and it seems to work ok!

On the page I've inserted the following loop where the comments appear...

<?php foreach ($quickcomments as $qcomment): ?>
<?php $commentRec = mysql_get('record', $qcomment['recordNum']); ?>
<?php $commentCat = mysql_get('category', $commentRec['category']); ?>
comments here...
<a href="./index.php?cat=<?php echo $commentCat['num'] ?>&rec=<?php echo $qcomment['recordNum'] ?>">Link...</a>
<?php endforeach ?>


Again, what a great little plugin. It has added an entirely new dimension to my latest project.

:0)

Perch

Re: [Perchpole] Website Comments - getRecords

By Dave - May 28, 2012

Great, glad to hear you've got it working that way you need. :)
Dave Edis - Senior Developer
interactivetools.com