First off, I am a newbie when it comes to working with xpdo and custom tables within ModX. I have been pouring through posts, documentation, and tutorials (thanks bob!) for 2 days now and I cannot figure out what seems to be pretty simple. I have created my tables and generated a schema, classes, and maps according to
http://bobsguides.com. I am pretty sure my relationships are setup correctly in the schema file, but as a newbie, not 100% sure.
I have a techCategory table, categoryA table and categoryB table. I simply would like to display the techCategory and any subcategories under it like the following example:
Microsoft (techCategory.tCatName)
--Exchange (categoryA.catAName)
----2010 (categoryB.catBName)
----2012 (categoryB.catBName)
--Virtualization (categoryA.catAName)
Citrix (techCategory.tCatName)
etc...
Here is from my schema file:
<object class="TechCategory" table="techCategory" extends="xPDOObject">
<field key="tCatID" dbtype="int" precision="10" phptype="integer" null="false" index="pk" generated="native" />
<field key="tCatName" dbtype="varchar" precision="255" phptype="string" null="false" />
<field key="tCatDescription" dbtype="longtext" phptype="string" null="false" />
<field key="sortOrder" dbtype="int" precision="10" phptype="integer" null="false" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="tCatID" length="" collation="A" null="false" />
</index>
<composite alias="CategoryA" class="CategoryA" local="tCatID" foreign="tCatID" cardinality="one" owner="local" />
</object>
<object class="CategoryA" table="categoryA" extends="xPDOObject">
<field key="catAID" dbtype="int" precision="10" phptype="integer" null="false" index="pk" generated="native" />
<field key="tCatID" dbtype="int" precision="10" phptype="integer" null="false" />
<field key="catAName" dbtype="varchar" precision="255" phptype="string" null="false" />
<field key="catADescription" dbtype="longtext" phptype="string" null="false" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="catAID" length="" collation="A" null="false" />
</index>
<aggregate alias="TechCategory" class="TechCategory" local="tCatID" foreign="tCatID" cardinality="one" owner="foreign" />
<composite alias="CategoryB" class="CategoryB" local="catAID" foreign="catAID" cardinality="one" owner="local" />
</object>
<object class="CategoryB" table="categoryB" extends="xPDOObject">
<field key="catBID" dbtype="int" precision="10" phptype="integer" null="false" index="pk" generated="native" />
<field key="catAID" dbtype="int" precision="10" phptype="integer" null="false" />
<field key="catBName" dbtype="varchar" precision="255" phptype="string" null="false" />
<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
<column key="catBID" length="" collation="A" null="false" />
</index>
<aggregate alias="CategoryA" class="CategoryA" local="catAID" foreign="catAID" cardinality="one" owner="foreign" />
</object>
I can display all of any of those tables individually - NO PROBLEM:
$path = MODX_CORE_PATH . 'components/mypackage/';
$modx->addPackage('mypackage',$path . 'model/','xxxx_');
$output = '';
$criteria = $modx->newQuery('TechCategory');
$criteria->sortby('tCatName', 'ASC');
$categories = $modx->getCollection('TechCategory', $criteria);
echo '<ul>';
foreach($categories as $category) {
$catid = $category->get('tCatID');
$catname = $category->get('tCatName');
$output .= '<li><a href="[[~59? &cat=`' . $catid .'`]]" title="' . $catname . ' Courses">' . $catname . '</a></li>';
}
return $output;
echo '</ul>';
However, when I try to get all of the results I need combined, I have been 100% unsuccessful. The only progress I have made is showing the fist TechCategory and then ALL of the subcategories under it. X[ I have tried so many things that I don't even know what attempted code to post as examples of what I have done!
I have tried getCollectionGraph but I guess I just couldn't figure it out. I have tried implementing joins, getObject, all kinds of things, but I just seem to not be getting it. I am just not understanding what I am supposed to do. If there is any way anyone could help me set this up, I would be eternally grateful! I also have some money in the budget to pass on - I know everyone's time is valuable and I am not sure where else to turn. PM me if there is any interest in paid assistance.