You are here

function permission_csv_export_file_logs in Permissions Csv Export 7

Menu callback for csv import file logs.

Return value

string Table formatted output in html.

1 string reference to 'permission_csv_export_file_logs'
permission_csv_export_menu in ./permission_csv_export.module
Implements hook_menu().

File

includes/permission_csv_export.inc, line 14
Menu callbacks and other related code.

Code

function permission_csv_export_file_logs() {
  $roles = user_roles();
  $header = [
    'S.N.',
    'Filename',
    'Imported By',
    'Status',
    'Processed on',
    'Import on',
    'Imported for',
    'Download',
  ];
  $data = [];
  $result = db_query("SELECT id, fid, uid, import_roles, status, created, updated FROM {permissions_csv_export_logs} order by updated")
    ->fetchAll();
  if (count($result)) {
    $i = 1;
    foreach ($result as $value) {
      $url = ($uri = permission_csv_export_get_file_uri_from_fid($value->fid)) && file_exists(drupal_realpath($uri)) ? urldecode(file_create_url($uri)) : '';
      $username = db_query("select name from {users} where uid = :uid", [
        ':uid' => $value->uid,
      ])
        ->fetchField();
      $status = permission_csv_export_get_file_status($value->status);
      $download = l(t('Download'), $url, [
        'attributes' => [
          'target' => '_blank',
        ],
      ]);
      $imported_for = unserialize($value->import_roles);
      foreach ($imported_for as $k => $rid) {
        $imported_for[$k] = $roles[$rid];
      }
      $data[] = [
        $i,
        basename($url),
        $username,
        $status,
        date('m-d-Y h:i:s', $value->created),
        date('m-d-Y h:i:s', $value->updated),
        implode("<br />", $imported_for),
        $download,
      ];
      $i++;
    }
    $output = '<div class="action-links"><p>' . l(t("Delete All Logs"), PERMISSION_CSV_EXPORT_DELETE_LOGS) . '</p></div>';
    $output .= theme('table', [
      'header' => $header,
      'rows' => $data,
    ]);
    return $output;
  }
  return "<h3>There is no import log available right now.</h3>";
}