Dec 04, 2008, 01:16 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Read what MODx Developers say: MODx Dev. Blogs
Pages: [1]   Go Down
  Print  
Author Topic: Ditto number of results  (Read 1297 times)
0 Members and 1 Guest are viewing this topic.
coleh
Jr. Member
*
Posts: 37



WWW
« on: Feb 19, 2008, 07:30 AM »

Probably being a bit thick but is there a way to query/return the number of documents that a Ditto call will return without returning the actual documents or links to them?

Cole
Logged
sottwell
Documentation Team
*
Posts: 8,170



WWW
« Reply #1 on: Feb 19, 2008, 07:42 AM »

I don't find any reference to Ditto ever returning the number of documents found. You may need to use a different snippet for that information.

Wait a minute... if pagination is being used, there is a [+total+] placeholder. But how to use only that value without anything else may be another matter. Perhaps set its parameters to get all, but only display one, and have your template chunk just display [+total+]?
« Last Edit: Feb 19, 2008, 07:46 AM by sottwell » Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
dev_cw
Testers
*
Posts: 2,758



WWW
« Reply #2 on: Feb 19, 2008, 09:52 AM »

All you want is the total of docs? You do not want to display any docs but just the total?

If this is what you want I can think of a slick way to get this by using Ditto to generate the doc list of a given parent and then transform the results into an array and then use the count() function to do the math and return a number.

This would be the snippet code:
Code:
<?php
// totalDocs
$parent = isset($parent) ? $parent : $modx -> documentObject['parent'];
$depth = isset($depth) ? $depth : "1";
$showPublishedOnly = isset($showPublishedOnly) ? $showPublishedOnly : "1";
$seeThruUnpub = isset($seeThruUnpub) ? $seeThruUnpub : "0";
$showInMenuOnly = isset($showInMenuOnly) ? $showInMenuOnly : "1";

// Use Ditto to generate document list
$documents = $modx->runSnippet("Ditto", array(
"parents" => $parent,
"display" => "all",
"depth" => $depth,
"showPublishedOnly" => $showPublishedOnly,
"seeThruUnpub" => $seeThruUnpub,
"showInMenuOnly" => $showInMenuOnly,
"tpl" => "@CODE [+id+]," ));

$documents = explode( ',', $documents);

$totalDocs = (count($documents) - 1);

return
$totalDocs;

?>

And use it like this:
Code:
This container has [!countDocs? &parent=`0` !] documents
And the returned value will be the number of published not hidden documents in a given container.

Note: this has limited testing, you may need to adjust/add parameters to get the desired results. I had to reduce the count by one in order to get the right number, not sure why, maybe somone else could enlighten us.  Grin

Note2: To get the showPublishedOnly to work correctly you will need the latest Ditto beta release. Currently it will select only the published or unpublished docs, in the new relese it will also count the total of both pub and unpub docs.

Anyway, hope this works out.

Edit: you may be able to get the results using the getChildIds API function since it returns an array of ids for the children of a given doc. However it does not seem to have parameters for published or hidden documents. So IMO using Ditto will allow more flexibility.
http://wiki.modxcms.com/index.php/API:getChildIds
« Last Edit: Feb 19, 2008, 10:04 AM by dev_cw » Logged

Shane Sponagle | Snippet Call Anatomy | Document Specific Variables

Something is happening here, but you don't know what it is.
Do you, Mr. Jones?  -  [bob dylan]
ganeshXL
Testers
*
Posts: 1,549



WWW
« Reply #3 on: Feb 19, 2008, 10:41 AM »

You can use the save parameter:

snippet: dittoSaveVars:

Code:
<?php
if($dittoID) {
$resource = $modx->getPlaceholder($dittoID . "_ditto_resource");
$c = count($resource);
return($c);
}
?>


In the document:

Code:
[!Ditto? &id=`dittoTest` &save=`3` &parents=`0` &depth=`5` &display=`100` &total=`100` &debug=`1`!]
The above (invisible) Ditto call returned [!dittoSaveVars? &dittoID=`dittoTest`!] documents.


Further reading:
http://ditto.modxcms.com/files/snippet-ditto-php.html#save
http://modxcms.com/forums/index.php?topic=20929.0
« Last Edit: Feb 19, 2008, 10:48 AM by ganeshXL » Logged

coleh
Jr. Member
*
Posts: 37



WWW
« Reply #4 on: Feb 19, 2008, 10:46 AM »

Thanks everyone for your suggestions - plenty of scope to achieve this.
Had a go at creating a snippet which pulled out the TV am using to filter the Ditto call and used a mysql query then to cross-reference this with the relevant instances in the 'modx_site_tmplvar_contentvalues' table of the database, although this seemed quite crude given the APIs available.
Will work through your suggestions to see if can improve on what had worked on

Thanks again

Cole
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!