[REPOST] Search DD

"Michael Cortez" <[email protected]> Sat, 25 Oct 2003 09:08:02 -0700
Newsgroups gmane.comp.cms.xaraya.knowledge-base
Message-ID <001501c39b12$2b188650$0601a8c0@paxtera>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf
>> Of mikespub
>> Sent: Saturday, October 25, 2003 3:40 AM
>> To: [email protected]
>> Subject: Re: [Xaraya_dev] Search DD

In article <mailman.1374.1067065328.851.xaraya_developer-n5IRV0TL0hwRxVAL8JNkPw@public.gmane.org>,
Xaraya Developer List <[email protected]> wrote:
>I've got a PubType (#8) with 2 attached DD fields, a "PublisherID"
>(Textbox) and a "ProductLineID" (Textbox).
>
>I'm looking for an API call that lets me specify:
>* module      = Articles
>* pubtype     = 8
>* field/label = PublisherID | ProductLineID
>* value       = 123
>
>And get back all Article IDs for any matches.
>
>I've poked through the various DD_userapi_get* functions, but they all
>seem to assume you already know the AID/ItemID and want to get the DD
fields.
>
>So, of course, my case is backwards.
>
>Help, Suggestions?
>

Did you play with the Query utility in DD yet ? That allows you to build a
query and get an example of the corresponding BL tag that would show the
same data in a template.

Use the same arguments in your getitems call as you see in that tag, adapt
the where clauses to use OR instead of AND if necessary, and you're all set
:-)

Example :

$items = xarModAPIFunc('dynamicdata','user','getitems',
            array('module' => 'articles',
                  'itemtype' => 8,
                  //'fieldlist' => array('publisherid', 'productlineid',
'more_stuff', ...),
                  'where' => 'publisherid eq 123 or productlineid eq 123'));

That gives you an array of itemid (= article id) => (the fields & values),
which should be enough to retrieve the other article information you want
via articles API functions.


Somewhat more advanced would be to retrieve the article fields at the same
time as your DD fields. For that, you can join your DD object with the
xar_articles table. Unfortunately, the 'join' stuff doesn't support WHERE
clauses in the DD part yet, so you can't simply use 'join' =>
'xar_articles' as extra argument in getitems() here yet. (you could use it
if your where clauses were in the articles part)

But you can do the following via OO methods now :

// 1. get a DD object list with the where clauses you want in there $object
= new Dynamic_Object_List(array(
                  'moduleid' => xarModGetIDFromName('articles'),
                  'itemtype' => 8,
                  'where' => 'publisherid eq 123 or productlineid eq 123'));

// 2. join the xar_articles table to it, based on the aid field
$object->joinTable(array('table' => 'xar_articles',
                         // optional key to join with (for 1-to-1 joins)
                         'key' => 'aid',
                         'fields' => array('aid','title','authorid'),
                         // optional where clauses in this table, or for
                         // child-parent relationship between object and
table
                         'where' => '',
                         // fixed when the object is stored in dynamic_data
                         'andor' => 'and'));
// 3. get the joined items
$items = $object->getItems();
// show them or whatever
//echo $object->showView();

There are some limitations as to what queries you can combine when the DD
object is stored in the dynamic_data table (e.g. no OR-ing of WHERE clauses
between the DD ones and the table ones), but for the rest, it should be able
to handle many common join situations.

Note : the joinTable() method is pretty recent, so bug reports are welcome
:-)

Mike.
_______________________________________________
Xaraya_developer mailing list
[email protected]
http://lists.xaraya.com/mailman/listinfo/xaraya_developer