Load subcatagory information into object in com_content

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
beaudoiin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Fri Jan 30, 2015 6:01 am

Load subcatagory information into object in com_content

Post by beaudoiin » Sun Feb 21, 2016 8:56 am

Hi, I am messing around with the com_content/view/article component in joomla 2.5
I am trying to add all subdirectories to the class for view.html.php, I can't seem to get the information out of the database. I've been successful at getting The article category and parent category. I tried editing model/article.php I added a loop that would query->select and query->join but I was not sure how to check if the database had more subcategories.

The model gets the article info. uses catID to join the category, then it joins the subcategory and that's it. I want to try and loop through until each subcategory loaded has 0 or null as their parent_id.

The reason why I am doing this is because I want to have opengraph information for each category. In my view.html.php I have a code that sets opengraph description to the article, if there is none in database, it goes to category, if there is none there it loads it from the menu, (not sure if I have that working properly yet), if not then from configuration.php. Well I would like to add in their before menu, subcategories.

Any one have any ideas?
Last edited by toivo on Sun Feb 21, 2016 9:13 am, edited 2 times in total.
Reason: mod note: moved to 2.5 Coding

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 10079
Joined: Thu Feb 15, 2007 5:48 am
Location: Oxford, UK
Contact:

Re: Load subcatagory information into object in com_content

Post by toivo » Sun Feb 21, 2016 10:09 am

I want to try and loop through until each subcategory loaded has 0 or null as their parent_id.
Each subcategory has a parent, the category above in the tree.

The function _countItemsInChildren() in plugins/content/joomla/joomla.php shows how to process all subcategories of a category. It uses the method getTree(), defined in libraries/joomla/table/nested.php.

BTW, modifying core code is not a good idea. There are other ways like overriding views in the html folder of your template and content plugins, which allow you to do almost everything to articles and forms at different stages.
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla

beaudoiin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Fri Jan 30, 2015 6:01 am

Re: Load subcatagory information into object in com_content

Post by beaudoiin » Sun Feb 21, 2016 5:13 pm

Thank you so much for your reply! Very happpy.
This is a good lead I am going to look into it!
Also I have a plugin which overrides all the files.
The module files, the view.html.php files and for now regular template overrides for tmpl/default.php and so on!

beaudoiin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Fri Jan 30, 2015 6:01 am

Re: Load subcatagory information into object in com_content

Post by beaudoiin » Sun Feb 21, 2016 5:24 pm

now this checker a category, but what if I want to work backwards.
News > Web news > Functionality | And find all the parents of functionality.
> Global News > France | but not show all the categories of news.
Is there a build in function for that,

also I couldn't get this to work.

jimport('joomla.database.table');
jimport('joomla.database.tablenested');
print_r( JTableNested::getTree('43'));

Code: Select all

[21-Feb-2016 12:52:58 America/New_York] PHP Notice:  Undefined property: ContentViewArticle::$_tbl_key in /libraries/joomla/database/tablenested.php on line 171
[21-Feb-2016 12:52:58 America/New_York] PHP Notice:  Undefined property: ContentViewArticle::$_db in /libraries/joomla/database/tablenested.php on line 175
[21-Feb-2016 12:52:58 America/New_York] PHP Fatal error:  Call to a member function getQuery() on a non-object in /libraries/joomla/database/tablenested.php on line 175

beaudoiin
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Fri Jan 30, 2015 6:01 am

Re: Load subcatagory information into object in com_content

Post by beaudoiin » Sun Feb 21, 2016 6:54 pm

I tried this code but i get errores

Code: Select all

$db - > setQuery($query);
$datafinal = $db - > loadObject();

$query2 = $db - > getQuery(true);
$query2 - > select('parent.id AS parent0_id, parent.parent_id AS parent_parent0_id, parent.metadesc AS parent0_metadesc');
$query2 - > from('#__content AS a');
$query2 - > join('LEFT', '#__categories AS parent ON parent.id = a.catid');
$db - > setQuery($query2);
$datafinal = (object) array_merge((array) $db - > loadObject(), (array) $datafinal);

for ($i = 1; $i > 0; $i++) {
    $query2 = $db - > getQuery(true);

    $query2 - > select('parent.id AS parent'.$i.
        '_id, parent.parent_id AS parent_parent'.$i.
        '_id, parent.metadesc AS parent'.$i.
        '_metadesc');
    $query2 - > from('#__categories AS parent WHERE parent'.$i.
        '.id = parent_parent'.($i - 1).
        '_id');

    $db - > setQuery($query2);
    $datafinal = (object) array_merge((array) $db - > loadObject(), (array) $datafinal);
}
where this was
$db->setQuery($query);
$data= $db->loadObject();

I get errors still


Locked

Return to “Joomla! 2.5 Coding”