filterField = $filterField; $this->managedClass = $managedClass; if($records instanceof SS_List) { $this->records = $records; } elseif($records instanceof Group) { $this->records = new ArrayList(array($records)); } elseif($records) { throw new InvalidArgumentException('$record should be either a Group record, or a SS_List of Group records'); } // Get all available codes in the system as a categorized nested array $this->source = Permission::get_codes(true); parent::__construct($name, $title); } /** * @param Array $codes */ public function setHiddenPermissions($codes) { $this->hiddenPermissions = $codes; } /** * @return Array */ public function getHiddenPermissions() { return $this->hiddenPermissions; } public function Field($properties = array()) { Requirements::css(FRAMEWORK_DIR . '/css/CheckboxSetField.css'); Requirements::javascript(FRAMEWORK_DIR . '/javascript/PermissionCheckboxSetField.js'); $uninheritedCodes = array(); $inheritedCodes = array(); $records = ($this->records) ? $this->records : new ArrayList(); // Get existing values from the form record (assuming the formfield name is a join field on the record) if(is_object($this->form)) { $record = $this->form->getRecord(); if( $record && (is_a($record, 'Group') || is_a($record, 'PermissionRole')) && !$records->find('ID', $record->ID) ) { $records->push($record); } } // Get all 'inherited' codes not directly assigned to the group (which is stored in $values) foreach($records as $record) { // Get all uninherited permissions $relationMethod = $this->name; foreach($record->$relationMethod() as $permission) { if(!isset($uninheritedCodes[$permission->Code])) $uninheritedCodes[$permission->Code] = array(); $uninheritedCodes[$permission->Code][] = _t( 'PermissionCheckboxSetField.AssignedTo', 'assigned to "{title}"', array('title' => $record->Title) ); } // Special case for Group records (not PermissionRole): // Determine inherited assignments if(is_a($record, 'Group')) { // Get all permissions from roles if ($record->Roles()->Count()) { foreach($record->Roles() as $role) { foreach($role->Codes() as $code) { if (!isset($inheritedCodes[$code->Code])) $inheritedCodes[$code->Code] = array(); $inheritedCodes[$code->Code][] = _t( 'PermissionCheckboxSetField.FromRole', 'inherited from role "{title}"', 'A permission inherited from a certain permission role', array('title' => $role->Title) ); } } } // Get from parent groups $parentGroups = $record->getAncestors(); if ($parentGroups) { foreach ($parentGroups as $parent) { if (!$parent->Roles()->Count()) continue; foreach($parent->Roles() as $role) { if ($role->Codes()) { foreach($role->Codes() as $code) { if (!isset($inheritedCodes[$code->Code])) $inheritedCodes[$code->Code] = array(); $inheritedCodes[$code->Code][] = _t( 'PermissionCheckboxSetField.FromRoleOnGroup', 'inherited from role "%s" on group "%s"', 'A permission inherited from a role on a certain group', array('roletitle' => $role->Title, 'grouptitle' => $parent->Title) ); } } } if ($parent->Permissions()->Count()) { foreach($parent->Permissions() as $permission) { if (!isset($inheritedCodes[$permission->Code])) $inheritedCodes[$permission->Code] = array(); $inheritedCodes[$permission->Code][] = _t( 'PermissionCheckboxSetField.FromGroup', 'inherited from group "{title}"', 'A permission inherited from a certain group', array('title' => $parent->Title) ); } } } } } } $odd = 0; $options = ''; if($this->source) { // loop through all available categorized permissions and see if they're assigned for the given groups foreach($this->source as $categoryName => $permissions) { $options .= "