xoops forums

zyspec

Module Developer
Posted on: 2010/4/30 23:41
zyspec
zyspec (Show more)
Module Developer
Posts: 1077
Since: 2004/9/21
#1

Object getByLink usage - setting table_link variable

I should probably be able to figure this out but... I'm clearly not understanding how to use this method correctly... When I look at the code in XoopsModelJoint it appears I need to somehow be able to set the handler table_link table directly, but I'm not sure how to accomplish that...

Here's what I think I want to do:
$cat_handler =& xoops_getmodulehandler('category'$mydir);
$catFields = array ('o.cid''o.lid''l.lid''l.title');
$criteria = new CriteriaCompo(new Criteria('status'1'='));
$criteria $cat_handler->getByLink($criteria$catFieldsFALSE'lid''link_table')


Is that how it's suppose to work to get back an array of 'objects' with the following indexes?

array( 0=> array( [cid]=> {cid_value}, [lid] = > {lid_value}, [title]=>{lid_title}), 1=> array( [cid]=> {cid_value1}, [lid] = > {lid_value1}, [title]=>{lid_title1} ), etc... );



iHackCode

Module Developer
Posted on: 2010/5/1 2:39
iHackCode
iHackCode (Show more)
Module Developer
Posts: 1037
Since: 2004/6/29
#2

Re: Object getByLink usage - setting table_link variable

$cat_handler->table_link $xoopsDB->prefix('the link table');



Question: is link_table a field in 'the link table'?
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

zyspec

Module Developer
Posted on: 2010/5/1 3:25
zyspec
zyspec (Show more)
Module Developer
Posts: 1077
Since: 2004/9/21
#3

Re: Object getByLink usage - setting table_link variable

Yes, link_table is a table in the database, sorry I should have used something like my_link_table_name or something to make the example more clear...

iHackCode

Module Developer
Posted on: 2010/5/1 3:28
iHackCode
iHackCode (Show more)
Module Developer
Posts: 1037
Since: 2004/6/29
#4

Re: Object getByLink usage - setting table_link variable

link_table has to be the field name from 'the link table' that is the relation to the object table.


an example from publisher module (the other way to do it. since we wanted all the fields and wanted it to be an object we did it this way) a lot of the code was for the criteria.
$itemhandler $publisher->getHandler('item');
    
$itemhandler->table_link $xoopsDB->prefix('publisher_categories');
    
$itemhandler->field_link 'categoryid';
    
$itemhandler->field_object 'categoryid';
    
// Categories for which user has access
    
$categoriesGranted $publisher->getHandler('permission')->getGrantedItems('category_read');
    
$grantedCategories = new Criteria('l.categoryid'"(" implode(','$categoriesGranted) . ")"'IN');
    
$criteria = new CriteriaCompo();
    
$criteria->add($grantedCategories'AND');
    
$criteria->add(new Criteria('o.status',2), 'AND');
    
$critdatesub = new CriteriaCompo();
    
$critdatesub->add(new Criteria('o.datesub'$monthstart'>'), 'AND');
    
$critdatesub->add(new Criteria('o.datesub'$monthend'<='), 'AND');
    
$criteria->add($critdatesub);
    
$criteria->setSort('o.datesub');
    
$criteria->setOrder('DESC');
    
$storyarray $itemhandler->getByLink($criteria);


changing it this way should work too.
$itemhandler $publisher->getHandler('item');
    
$itemhandler->table_link $xoopsDB->prefix('publisher_categories');

    
// Categories for which user has access
    
$categoriesGranted $publisher->getHandler('permission')->getGrantedItems('category_read');
    
$grantedCategories = new Criteria('l.categoryid'"(" implode(','$categoriesGranted) . ")"'IN');
    
$criteria = new CriteriaCompo();
    
$criteria->add($grantedCategories'AND');
    
$criteria->add(new Criteria('o.status',2), 'AND');
    
$critdatesub = new CriteriaCompo();
    
$critdatesub->add(new Criteria('o.datesub'$monthstart'>'), 'AND');
    
$critdatesub->add(new Criteria('o.datesub'$monthend'<='), 'AND');
    
$criteria->add($critdatesub);
    
$criteria->setSort('o.datesub');
    
$criteria->setOrder('DESC');
    
$storyarray $itemhandler->getByLink($criteria,null,true,'categoryid','categoryid');
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

zyspec

Module Developer
Posted on: 2010/5/1 3:36
zyspec
zyspec (Show more)
Module Developer
Posts: 1077
Since: 2004/9/21
#5

Re: Object getByLink usage - setting table_link variable

Thanks Bandit-X but in the XoopsModel class the definition for the getByLink method is:

getByLink($criteria null$fields null$asObject true$field_link null$field_object null)


So shouldn't the 4th argument be the field name (in this case 'lid') and the 5th argument be 'the link table'?

iHackCode

Module Developer
Posted on: 2010/5/1 3:38
iHackCode
iHackCode (Show more)
Module Developer
Posts: 1037
Since: 2004/6/29
#6

Re: Object getByLink usage - setting table_link variable

i edited the post #4 with some code.
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

zyspec

Module Developer
Posted on: 2010/5/1 12:45
zyspec
zyspec (Show more)
Module Developer
Posts: 1077
Since: 2004/9/21
#7

Re: Object getByLink usage - setting table_link variable

Thanks BÁNÐÍT-X - The code in post #4 makes more sense... I'll go study Publisher a little to make sure I understand what's getting set by the $publisher class and to make sure I do something similar.

The piece that I knew I needed, but was missing how to set is
$itemhandler->table_link $xoopsDB->prefix('publisher_categories');

iHackCode

Module Developer
Posted on: 2010/5/1 13:10
iHackCode
iHackCode (Show more)
Module Developer
Posts: 1037
Since: 2004/6/29
#8

Re: Object getByLink usage - setting table_link variable

i know its used in the archive, but not sure if it is used elsewhere. http://code.google.com/p/xuups/source ... les/publisher/archive.php
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

Catzwolf

Home away from home
Posted on: 2010/5/11 22:03
Catzwolf
Catzwolf (Show more)
Home away from home
Posts: 1392
Since: 2007/9/30
#9

Re: Object getByLink usage - setting table_link variable

Did you get an answer to this?

zyspec

Module Developer
Posted on: 2010/5/12 2:05
zyspec
zyspec (Show more)
Module Developer
Posts: 1077
Since: 2004/9/21
#10

Re: Object getByLink usage - setting table_link variable

I've coded it in but it's part of a much bigger rewrite so I haven't tested it yet. As Bandit-X indicates it is used in archive.php in the Publisher module so I guess I could go load that module and try it to make sure the snippet above does what I think it's doing...

I'll post back once I get it working to let you know what I find.