public function pivotPermissions($Data, $Overrides = null)
{
// Get all of the columns in the permissions table.
$Schema = $this->SQL->get('Permission', '', '', 1)->firstRow(DATASET_TYPE_ARRAY);
foreach ($Schema as $Key => $Value) {
if (strpos($Key, '.') !== false) {
$Schema[$Key] = 0;
}
}
unset($Schema['PermissionID']);
$Schema['RoleID'] = 0;
$Schema['JunctionTable'] = null;
$Schema['JunctionColumn'] = null;
$Schema['JunctionID'] = null;
$Result = array();
if (is_array($Data)) {
foreach ($Data as $SetPermission) {
// Get the parts out of the permission.
$Parts = explode('//', $SetPermission);
if (count($Parts) > 1) {
// This is a junction permission.
$PermissionName = $Parts[1];
$Key = $Parts[0];
$Parts = explode('/', $Key);
$JunctionTable = $Parts[0];
$JunctionColumn = $Parts[1];
$JunctionID = val('JunctionID', $Overrides, $Parts[2]);
if (count($Parts) >= 4) {
$RoleID = $Parts[3];
} else {
$RoleID = val('RoleID', $Overrides, null);
}
} else {
// This is a global permission.
$PermissionName = $Parts[0];
$Key = 'Global';
$JunctionTable = null;
$JunctionColumn = null;
$JunctionID = null;
$RoleID = val('RoleID', $Overrides, null);
}
// Check for a row in the result for these permissions.
if (!array_key_exists($Key, $Result)) {
$NewRow = $Schema;
$NewRow['RoleID'] = $RoleID;
$NewRow['JunctionTable'] = $JunctionTable;
$NewRow['JunctionColumn'] = $JunctionColumn;
$NewRow['JunctionID'] = $JunctionID;
$Result[$Key] = $NewRow;
}
$Result[$Key][$PermissionName] = 1;
}
}
return $Result;
}