<![CDATA[ pdoFetch examples anyone? - MODX Community Forums]]> https://forums.modx.com/thread/?thread=104571 <![CDATA[pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone?page=2#dis-post-562448 alipang Oct 31, 2018, 08:15 PM https://forums.modx.com/thread/104571/pdofetch-examples-anyone?page=2#dis-post-562448 <![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562831 andreer Nov 19, 2018, 08:37 PM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562831 <![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562520
$total = (int)$modx->getPlaceholder($totalVar);

That is probably a trick (preferred way?) to pass a number between pdoPage and the element used, but in my case something else intercepts the placeholder.]]>
alipang Nov 04, 2018, 12:44 PM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562520
<![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562518
@mrhaw: I'm glad I could help. smiley]]>
BobRay Nov 04, 2018, 03:17 AM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562518
<![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562516 Quote from: BobRay at Oct 31, 2018, 08:44 PM
You've seen this, right?

https://docs.modx.pro/en/components/pdotools/classes/pdofetch

WOW!! Thanks!! 8-)]]>
mrhaw Nov 04, 2018, 03:03 AM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562516
<![CDATA[Re: pdoFetch examples anyone? (Best Answer)]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562513 Quote from: BobRay
If (and it's a big if) you've properly created the tables as related objects of each other, you can use getCollectionGraph() to get them all in a single query. You can also use $query->leftJoin() with getCollection().
That was what I was missing. Lesson learned: getCollectionGraph() is handy through it's use of model definitions, but with some extra typing getCollection() can do the job too.

After examining the pdoTools code I figured out how to do it. No need to make a new snippet. pdoUsers has it all.
[[!pdoPage?
    &element=`pdoUsers`
    &leftJoin=`[{"class":"userData", "alias": "userData", "on":"userData.userdata_id = modUser.id"}]`
    &select=`{"userData": "firstName, lastName"}`
    &loadModels=`{'extendeduser': MODX_CORE_PATH.'components/classextender/model/'}`
    &toPlaceholder=`userlist`
    &tpl=`userItem`
    &tplWrapper=`usersWrapper`
    &setTotal=`1`
    &totalVar=`total`
    &showInactive=`0`
    &showBlocked=`0`
    &showLog=`1`
]]
[[!+userlist:notempty=`[[!+userlist]][[!+page.nav]]`]]
]]>
alipang Nov 03, 2018, 02:14 PM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562513
<![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562506
Can pdoResources and pdoUsers handle extended data?

I'd say definitely yes, but I don't know how to do it. That said, it's more complicated since ClassExtender's classes do not extend modUser and modResource. So, IIRC, the resource and the user (and maybe the profile) are related objects of the class extender objects, but not the other way around.

There's an example here, that does a join, but I think it's untested.

You probably know this, but ClassExtender has getExtUser and getExtResources snippets that may do what you want. If they don't, you can duplicate them and modify them to meet your needs. You can also look at them as examples of how to get related object data for users and resources.

]]>
BobRay Nov 02, 2018, 08:11 PM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562506
<![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562498
Can pdoResources and pdoUsers handle extended data? There are &loadModels and &class parameters, but how do I use them for example with ClassExtender?


BTW, pdoTools is not necessary, but it would be nice to master it.]]>
alipang Nov 02, 2018, 03:48 PM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562498
<![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562483
As far as I know there is a $pdo->getCollection, but there's no $pdo->getCollectionGraph().

$modx->getCollectionGraph() is quite fast and efficient in my experience, so even if you could somehow do the equivalent with pdoTools, I don't think you'd save much time unless you're querying massive amounts of data.]]>
BobRay Nov 02, 2018, 04:58 AM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562483
<![CDATA[Re: pdoFetch examples anyone?]]> https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562457
$c = $modx->newQuery('userData');
$c->where(array('User.active' => '1'));
$users = $modx->getCollectionGraph('userData', '{"Profile":{},"User":{}}', $c);

if we speak about ClassExtender. But it would be nice to know how to use it for any class.]]>
alipang Oct 31, 2018, 09:24 PM https://forums.modx.com/thread/104571/pdofetch-examples-anyone#dis-post-562457