GOAL: To set a permission to edit a specific page (NOT a pagetype) by Member Groups.
I've been toying around with this for the past couple of days, and going back to the drawing board each time. (Partly due to my relatively new experience with SilverStripe.) Perhaps some guidance and advice might help.
-----------------------
INITIAL IDEA & OVERVIEW
-----------------------
Basically, I'd like to be able to designate edit permissions by member groups and/or members for a specific page. To make it easy, I first want to start with Groups.
The way it would work: On each page (viewd in the CMS) there will be an "Authors" tab. In the tab, there will be a dropdown displaying all the available Groups. You would select the group, click an "Add" button next to dropdown, and the Group name gets added to a list displayed below - which shows all the groups that have the ability to edit that page.
I'm having trouble with even the first step: getting a dropdown listing all the available Groups.
-----------------------
CODE
-----------------------
Since this will be a feature for every single page in the CMS, I am adding this code to mysite\code\Page.php. The code below is throwing me an error of: "Fatal error: Class name must be a valid object or a string in /home/.keewer/hani79/ss.mmbarn.com/mysite/code/Page.php on line 26" - which tells me that I have something wrong in my "GroupDD" function.
**********************
mysite\code\Page.php
**********************
[code php]
<?
class Page extends SiteTree {
static $db = array(
);
static $has_one = array(
);
static $has_many = array(
"Authors" => "Authors_By_Group"
);
public function GroupDD() {
$groups = DataObject::get('Group');
$Groups_Array = array();
foreach( $groups as $group ) {
$Groups_Array[$group->ID] = $group->Title;
}
return new DropdownField('Group',$groupArray);
}
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Authors", new $this->GroupDD());
return $fields;
}
}
class Authors_By_Group extends DataObject {
static $db = array(
// This would refer back to the ID of the page
"ParentID" => "Int"
);
static $has_one = array(
'Group' => 'Group'
);
}
class Page_Controller extends ContentController {
// Gets the Project Name
function project() {
global $project;
return $project;
}
}
?>
**********************
I tried looking at the source code of Newsletter and Security, the documentation, and forums to figure out the relationship between Members/Groups to Pages, but to no avail. Can someone give me some guidance or advice? (Even if it is simply guidance on the first step of getting the dropdown to display properly.)
-----------------------
FUTURE STEPS
-----------------------
1. To actually have the "Add" button for inserting the Group ID and the Page ID to the Authors_By_Group table in the database via AJAX.
2. Allow the "Authors" tab only to display for members in the "Administrators" group.
3. Only display the pages in the CMS's SiteTree that the current user can edit
-----------------------
Thanks in advance for ANY help!