1
zyspec
Object getByLink usage - setting table_link variable
  • 2010/4/30 23:41

  • zyspec

  • Module Developer

  • Posts: 1093

  • Since: 2004/9/21


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... );




2
iHackCode
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

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

3
zyspec
Re: Object getByLink usage - setting table_link variable
  • 2010/5/1 3:25

  • zyspec

  • Module Developer

  • Posts: 1093

  • Since: 2004/9/21


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...

4
iHackCode
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

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

5
zyspec
Re: Object getByLink usage - setting table_link variable
  • 2010/5/1 3:36

  • zyspec

  • Module Developer

  • Posts: 1093

  • Since: 2004/9/21


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'?

6
iHackCode
Re: Object getByLink usage - setting table_link variable

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

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

7
zyspec
Re: Object getByLink usage - setting table_link variable
  • 2010/5/1 12:45

  • zyspec

  • Module Developer

  • Posts: 1093

  • Since: 2004/9/21


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');

8
iHackCode
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

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

9
Catzwolf
Re: Object getByLink usage - setting table_link variable
  • 2010/5/11 22:03

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Did you get an answer to this?

10
zyspec
Re: Object getByLink usage - setting table_link variable
  • 2010/5/12 2:05

  • zyspec

  • Module Developer

  • Posts: 1093

  • Since: 2004/9/21


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.

Login

Username:
Password:

Lost Password? Register now!

Who's Online

58 user(s) are online (38 user(s) are browsing Support Forums)


Members: 0


Guests: 58


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits