Search

Im sure I am missing something fairly fundamental here. I need to return a count of comments (with a publish value set to true) for each article my data source returns. I have used a select box link to join comments to articles. Is this something I could use the Reflection field for?

Don’t take my word for it, but I would think that you need a data source for the comments, and then you can use count to count the number of comments

<xsl:value-of select="count(/comment)"/>

Im sure I am missing something fairly fundamental here

You’re not missing anything fundamental — Symphony doesn’t really cater for this use case. Your Article Data Source will have a comments attribute on each <entry> element (if that option is ticked in your Data Source) but obviously this just gives the total of all entries. Symphony unfortunately doesn’t have a way for you to add a filter to this count.

You could get the filtered count in several ways:

a) Previous discussion Categories including unpublished articles into article count:

Use Data Source chaining so that your Articles data source spits out a list of article entry IDs. Create your Comments DS (with the publish filter set) and filter the SBL field by the output parameter from the first DS. This works, but it means you actually query all of the comments, so it’s not very efficient. You should disable Included Elements from the comments DS to save database calls. As Aalandriel says, you can then count the matching comment entries in your XSLT

b) The alternative is to write some custom PHP. This could be in the form of a custom field in an extension. I made a start with this, but it’s only about 50% complete and I kind of gave up. The idea was that at the point of selecting the Output Parameter of a Data Source, the developer can also choose other Data Sources which should provide counts.

So in your example you have two Data Sources: Articles and Published Comments. Articles outputs its System ID to a param named $ds-articles, and Published Comments filters both on “published=Yes” and the Select Box Link on {$ds-articles}. This is standard data source chaining.

But this extension would allow you to select the Published Comments data source and “attach” it to the Articles data source, such that when the latter executes it also runs the chained Data Sources and counts the entries (without the performance deficit of pulling in all of the actual comment entries into your page XML).

screenshot

The output would be something like:

<articles>
    <entry id="1" comment="10" published-comments="2">
        ...
    </entry>
</articles>

Where the comments attribute is the original added by Symphony, and the published-comments is added by the extension.

Anyway, it’s just a pipe dream and it needs quite a lot of work. So I’m aware it’s not very useful to you. But that’s the idea behind it.

I’m also pretty sure there is code for a custom Data Source kicking around the forum which has an SQL statement to do this sort of counting…

Wow thanks @nickdunn for such a detailed response. Im going to carry on with the main developemnet for now and return to this problem towards the end.

I really need to get round to looking properly at extensions, custom data sources etc… So this might provide a great opportunity.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details