3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1990 Views |
-
[Solved]Get dataobjectsets from all child pages

8 April 2009 at 4:48pm Last edited: 8 April 2009 9:02pm
Hi, I have a 2 level site structure for products like this:
Die Cast Toys
----Pull Back Vehicles
----Free Wheel Vehicles
----Gunsetc
When I am on a child page , ie Pull Back Vehicles I currently have all the dataobjects listing no probs see here
I am using this code to do it:
#####in ProductPage.php#########
//get Product dataobjectset ready for pagination
function ProductItems() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];
$doSet = DataObject::get(
$callerClass = "Product",
$filter = "`ProductPageID` = '".$this->ID."'",
$sort = "",
$join = "",
$limit = "{$SQL_start},15"
);return $doSet ? $doSet : false;
}What I am having trouble with is figuring out how to get ALL child dataobjects. So if I go to 'Die Cast Toys' I need to see all dataobjects from the 3 child pages.
I'm not sure if I need to find and then loop through all the child id's within a function??? or some other way....
function AllChildProductItems() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];
$doSet = DataObject::get(
$callerClass = "Product",##### find and loop here???? ######
$filter = "`ProductPageID` = '".$this->ID."'",
###########################
$sort = "",
$join = "",
$limit = "{$SQL_start},15"
);return $doSet ? $doSet : false;
}Thanks for any suggestions in advance!!
-
Re: [Solved]Get dataobjectsets from all child pages

8 April 2009 at 8:10pm Last edited: 8 April 2009 8:11pm
Heya,
Pages are 'Heirarchical', so you should be able to do:
$pageIds = $this->getDescendantIDList();
This should create an array of ID's, with the current page and any descendant page ID's.
You could then do:
$doSet = DataObject::get(
"Product",
"`ProductPageID` IN (" . implode(",", $pageIDs) . ")",
"",
"",
"{$SQL_start},15"
);This should return all Product objects that have a ProductPageID that is either the current page's ID, or any child page of the current page.
-
Re: [Solved]Get dataobjectsets from all child pages

8 April 2009 at 9:00pm
Thanks Hamish, thats great.....it works perfectly:)
| 1990 Views | ||
|
Page:
1
|
Go to Top |

