Hello all, I have an issue that's probably very simple to solve, but has been driving me mad for weeks.
I have a Staff section with the following elements:
StaffProfile (Page - displays individual staff member details)
StaffHolder (Page - list all the staff profiles)
StaffDepartment (Dataobject - staff member departments, functioning as DataObject as page)
I call the method StaffMembers in the various templates to loop the StaffProfiles and this works as I want.
Called on StaffHolder I get all profiles, called on StaffDepartment (StaffHolder_show.ss) I get the profile from that Department.
However, I'm stretching the limits of template-based filtering/sorting and want to manipulate the data in the ORM.
No matter what I've tried, I can't re-produce what I'm able to do template-side.
I.e. if I create a simple function to get StaffMembers on StaffHolder, it will work on the holder page but the StaffMembers will not filter by their departments on StaffDepartment/StaffHolder_show.ss.
If I put the function on StaffDepartment, it does filter staff members on StaffHolder_show.ss. Only if I loop StaffDepartments on Staffholder, then StaffMembers do I get all the departments with their staff, which I don't want - as I don't want them broken down into departments on this page, and it retrieves duplicates where staff have multiple departments. I'm using the DataObjectAsPage module, but got the same results when I coded the page functionality from scratch from UncleCheese's video.
Any pointers on where I'm going wrong would be greatly appreciated.
Class/Controller Structure below:
StaffHolder.php
class StaffHolder extends DataObjectAsPageHolder {
private static $allowed_children = array (
'StaffProfile',
);
private static $has_many = array (
'Departments' => 'StaffDepartment',
'StaffMembers' => 'StaffProfile'
);
private static $has_one = array (
'StaffPlaceHolder' => 'Image'
);
...........
}
class StaffHolder_Controller extends DataObjectAsPageHolder_Controller {
public static $item_class = 'StaffDepartment';
...........
}
StaffProfile.php
class StaffProfile extends Page {
private static $belongs_many_many = array (
'Departments' => 'StaffDepartment',
);
// I have tried the reverse relationship to StaffProfile and produces same results
........
}
StaffDepartment.php
class StaffDepartment extends DataObjectAsPage {
public static $listing_page_class = 'StaffHolder';
public static $item_sort = 'Title ASC';
public static $plural_name = 'Departments';
public static $singular_name = 'Department';
private static $has_one = array (
'StaffHolder' => 'StaffHolder'
);
private static $belongs_many = array (
'StaffHolder' => 'StaffHolder'
);
private static $many_many = array (
'StaffMembers' => 'StaffProfile'
);
.........