filterField = $filterField; $this->managedClass = $managedClass; if(is_a($records, 'DataObjectSet')) { $this->records = $records; } elseif(is_a($records, 'DataObject')) { $this->records = new DataObjectSet($records); } elseif($records) { throw new InvalidArgumentException('$record should be either a Group record, or a DataObjectSet 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 */ function setHiddenPermissions($codes) { $this->hiddenPermissions = $codes; } /** * @return Array */ function getHiddenPermissions() { return $this->hiddenPermissions; } function Field() { Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js'); $uninheritedCodes = array(); $inheritedCodes = array(); $records = ($this->records) ? $this->records : new DataObjectSet(); // 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][] = sprintf( _t('PermissionCheckboxSetField.AssignedTo', 'assigned to "%s"'), $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][] = sprintf( _t( 'PermissionCheckboxSetField.FromRole', 'inherited from role "%s"', PR_MEDIUM, 'A permission inherited from a certain permission role' ), $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][] = sprintf( _t( 'PermissionCheckboxSetField.FromRoleOnGroup', 'inherited from role "%s" on group "%s"', PR_MEDIUM, 'A permission inherited from a role on a certain group' ), $role->Title, $parent->Title ); } } } if ($parent->Permissions()->Count()) { foreach($parent->Permissions() as $permission) { if (!isset($inheritedCodes[$permission->Code])) $inheritedCodes[$permission->Code] = array(); $inheritedCodes[$permission->Code][] = sprintf( _t( 'PermissionCheckboxSetField.FromGroup', 'inherited from group "%s"', PR_MEDIUM, 'A permission inherited from a certain group' ), $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 .= "