3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 870 Views |
-
Is it possible to filter ChildrenOf() pages ?

5 September 2009 at 8:42am
Hello guys,
I'm a newbie to SS and I'm trying hard to understand, so I'm sorry if my question makes no sense.
So here it is : Is it possible to filter the ChildreOf() of a page, for example to only show children of with a specific $author ?
Thanks
G. -
Re: Is it possible to filter ChildrenOf() pages ?

5 September 2009 at 11:29am
In a template file or in the php? Also is Author a Database Field or a has_one relationship?
In the template its a bit tricky as you cannot quote arguments so you couldn't say <% if Author != Joe Smith %>. That will not work. It will if you are doing it in php as you can compare the strings. If you want to do it from the template file you are going to have to write a function in your custom page type which returns true or false based on the authors name.
-
Re: Is it possible to filter ChildrenOf() pages ?

5 September 2009 at 9:18pm
Hi,
my fist idea was to do it in the template. I have a staff section with a page for each person with their name in the $Title.
Somewhere else I've got a publication section where they put they papers (it's a scientific website) and each publication is a child of PublicationHolder. The trick is that a same paper can have multiple authors.And of course I would like each staff page to list all the papers in which the person is listed as author.
So far, I use a trick, each staff page has virtual pages redirecting to the right papers and I use <%control childrem%>. But I would like to make it automatic.
What would be the best way to do it ? What's your opinion ?
P.S. Sorry if I make mistakes english is not my mothertongue
-
Re: Is it possible to filter ChildrenOf() pages ?

5 September 2009 at 9:28pm
And of course I would like each staff page to list all the papers in which the person is listed as author
This would be defined as a many_many join. So on your Paper Pagetype you would have a
// PaperPage class...
static $many_many = array(
'Authors' => 'StaffPage'
);And the corresponding code on the Staff Page Class
// StaffPage class..
static $belongs_many_many = array(
'Papers' => 'PaperPage'
);Then on the Staff page you can just do <% control Papers %> to get all the papers which the staff member is attached to.
For a more complete example see the 5th tutorial.
-
Re: Is it possible to filter ChildrenOf() pages ?

5 September 2009 at 10:49pm
Hi,
great ! Now I've got a tab in each paper edit-part in wich I can see all the staff I inputed in the staff part. But I can't select the one I want to set as authors.
Here's my code : Article.php
class Article extends Page {
static $db = array(
'Date1' => 'Date',
'Author1' => 'Text'
);static $has_one = array(
'ImageArticle'=>'Image',
'FileArticle'=>'File'
);static $many_many = array(
'Authors' => 'StaffPage'
);function getCMSFields() {
$fields = parent::getCMSFields();$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date1'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new ImageField('ImageArticle'),'Content');
$fields->addFieldToTab('Root.Content.Main', new FileIFrameField('FileArticle'),'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author1'),'Content');$tablefield = new HasManyComplexTableField(
$this,
'Authors',
'StaffPage'
);
$tablefield->setAddTitle( 'Authors' );$fields->addFieldToTab( 'Root.Content.Authors', $tablefield );
return $fields;
}
}class Article_Controller extends Page_Controller {
}
and I've just add the
to the staffPage.phpstatic $belongs_many_many = array(
'Papers' => 'PaperPage'
);
| 870 Views | ||
|
Page:
1
|
Go to Top |


