Page 1 of 1

Menu and News heirarchies

Posted: Mon May 08, 2006 6:11 pm
by Chris..S
Both the menu and news modules internally maintain heirarchies.  From what I could work out this information isn't available to the template, is there a reason for that?

I would like access to that information for styling purposes. 
- All news articles that belong to a category that is a member of a particular category have a similar style.
- Similarly the main content pages have a title that is retrieved from the page's parent menu item.

I have knocked together a parent plugin and hacked the news module to provide the parent category.

Is there are better way to get this information?

I presume the parent plugin will withstand CMS MS upgrades, but I guess the changes to the news module will need to be redone.  Its only something like 3 lines in one file and 2 in another. 
- Is it worth me submitting the changes for possible inclusion in CMS MS?
- Is there a recommended method for making code changes to CMS MS that is easy to redo after upgrading? I am not particularly familiar with SVN although I have used other version control software.

Re: Menu and News heirarchies

Posted: Mon May 08, 2006 10:07 pm
by Ted
There really isn't a better way to grab that information.  We can probably work something out, but I'd be interested in seeing your code before I got too far out of control coming up with my own solution.

SVN is very similar to CVS, in fact I take it to be a little easier on the brain.  Any patches should if at all possible be submitted against the latest svn for minimal amount of pain for me to test and/or include them.

Thanks!

Re: Menu and News heirarchies

Posted: Mon May 08, 2006 11:25 pm
by Chris..S
For news all I did was add an extra field to the SQL statement to get the long_name and then explode the resulting and take the first element as the parent - which suits me as when there is no parent I am happy to get the category name.

There are three SQL statements in action.default.php (2) and action.detail.php (1)

e.g.

Code: Select all

$query = "SELECT mn.*, mnc.news_category_name, mnc.long_name FROM "...
and then after all the other onerow assigns,

Code: Select all

list($onerow->parentcategory) = explode('|',$row['long_name'],2);
The parent plugin is a copy of one of the standard plugins, altered to make use of the data retrieval methods of other objects.

Code: Select all

function smarty_cms_function_parent($params, &$smarty)
{
	global $gCms;
	$pageinfo = &$gCms->variables['pageinfo'];
	
	if (isset($pageinfo) && $pageinfo->content_id == -1)
	{
		#We've a custom error message...  set a current timestamp
		return "404 Error";
	}
	else
	{
	  $thispage = new content();
	  $thispage->loadFromId($pageinfo->content_id);
		
	  $parent = new content();
	  $parent->loadFromId($thispage->ParentId());	
	
	  $result = cms_htmlentities($parent->Alias());

	  return $result;
	}
}
I'll look at grabbing an SVN version of CMS MS, I am currently working from your last release.