You are here

public function PermissionMatrix::printEmptyTable in Little helpers 7

File

src/c2c/PermissionMatrix.php, line 93

Class

PermissionMatrix

Namespace

Drupal\little_helpers\c2c

Code

public function printEmptyTable() {
  $module_info = system_get_info('module');
  $perm_padding = str_pad('', $this->width_perm + 10);
  $role_line = '';
  $rids = array();
  $i = 0;
  $perm_null_line = '';
  foreach ($this->roles as $rid => $role) {
    $rids[] = $rid;
    $role_line .= str_pad("'{$role}', ", $this->width_role[$i] + 4);
    $perm_null_line .= str_pad("NULL,", $this->width_role[$i++] + 4);
  }
  $lines = array();
  foreach ($this->perms as $module => $perms) {
    $lines[] = "  ),";
    $lines[] = "  // {$module_info[$module]['name']}";
    $lines[] = "  '{$module}' => array(";
    foreach ($perms as $i => $perm) {
      $p = str_pad("'{$perm}'", $this->width_perm + 2);
      $lines[] = "    {$p} => array({$perm_null_line}),";
    }
  }
  array_push($lines, array_shift($lines));
  $lines = implode("\n", $lines);
  echo "<?php\n\n";
  echo "\$roles = array(\n";
  echo "  {$perm_padding}    {$role_line}\n";
  echo ");\n";
  echo "\$matrix = array(\n";
  echo "{$lines}\n";
  echo ");\n";
}