Re: dynamicdata getitems function

[email protected] (mikespub) Wed, 10 Sep 2003 16:34:09 GMT
Newsgroups gmane.comp.cms.xaraya.knowledge-base
Organization not much
Message-ID <[email protected]>
In article <mailman.276.1063066508.9998.xaraya_knowledge-base-n5IRV0TL0hwRxVAL8JNkPw@public.gmane.org>, Xaraya Knowledge Base <[email protected]> wrote:
>Mikespub wrote:
>...
>> So for your block experiment, you *could* use the respective getitems()
>> APIs of hitcount and ratings, and the get_countlist() API for comments,
>> etc. after retrieving the items from DD. Or work the other way around and
>call
>> the respective topitems() APIs first and then retrieve those items from
>DD.
>>
>I am going to play with this a bit. Seems simple it enough. Just stick the
>additional  getitem calls in the the foreach loop when forming the array for
>the return to the template I take it?
>
Hmmm, you should retrieve all the items you want, build a list of item ids,
and then pass that list to the getitems() function of hitcount or ratings :

$items = xarModAPIFunc('dynamicdata', 'user', 'getitems',
                       array('module' => 'mymodule',
                             'itemtype' => 0,
                             'sort' => 'myfield DESC',
                             'numitems' => 20));
$idlist = array_keys($items);
$hits = xarModAPIFunc('hitcount', 'user', 'getitems',
                       array('modname' => 'mymodule',
                             'itemtype' => 0,
                             'itemids' => $idlist));
foreach ($idlist as $id) {
    $items[$id]['counter'] = $hits[$id];
}

Or in reverse, if you need to start with the top N items, call topitems()
first, and then retrieve the list of items with those ids from DD :

$tophits = xarModAPIFunc('hitcount', 'user', 'topitems',
                         array('modname' => 'mymodule',
                               'itemtype' => 0,
                               'numitems' => 20));
$idlist = array();
foreach ($tophits as $tophit) {
    $idlist[] = $tophit['itemid'];
}
$items = xarModAPIFunc('dynamicdata', 'user', 'getitems',
                       array('module' => 'mymodule',
                             'itemtype' => 0,
                             'itemids' => $idlist));
foreach ($tophits as $tophit) {
    $id = $tophit['itemid'];
    if (isset($items[$id])) {
        $items[$id]['counter'] = $tophit['hits'];
    }
}
[or equivalent $object->getItems() calls]

That way, you only have 2 function/SQL calls instead of 1 + N...

Better yet would be to retrieve everything at once, but that's not
feasible today (at least with DD).

>> P.S.: I'm glad to see that I'm not the only one who sees the potential
>> of replacing the whole articles code with generic DD stuff - it's my
>> secret dream for DD too (at least one of them) :-)
>
>Heh, I only stumbled into your dream when you encouraged me with a post to
>look at the dyn_example module a while back. The more I looked at it the
>better I understood its modularity and its simplicity. I am sure there are
>going to be reasons people want to use the "examples" approach and build
>from a seperate table. Articles on the other hand does not lend itself well
>to either the modularity or simplicity concept. I can't think of a simpler
>way to build a module. Create your fields in dd, duplicate dyn_example and
>tie it in with your new "OBJECT NOT TABLE" (I struggled to understand what
>you were doing here), add your own functions and blocks to do whatever you
>want, modify your templates. You can even export your table structures out
>of dd and import them into your new module via the init function. I think
>you have the right idea. For my own purposes it is the right blend of
>functionality with a simple approach that even this aging brain can
>understand.
>
>Keep up the great work!
>Paul
>

Thanks :) DD is probably a bit too complex for beginning site designers,
but it does offer some interesting functionality for more advanced users
- at least that was the intention :)

Mike.