You are here

function gallery_assist_list_galleries in Gallery Assist 6

Gallery list in user profile. A owner see all the own galleries, visitors only the selected to be displayed.

Parameters

$u: A string containing the user object of the node owner.

Return value

An string containing the galleries as list formated in a table.

1 string reference to 'gallery_assist_list_galleries'
gallery_assist_menu in ./gallery_assist.module
Implementation of hook_menu().

File

./gallery_assist.module, line 660
Drupal content type with gallery functionality.

Code

function gallery_assist_list_galleries($u) {
  global $user;

  // Build table header.
  $head = array(
    array(
      'data' => t('Count'),
      'field' => 'items',
      'class' => 'ga-align-right ga-no-wrap',
    ),
    array(
      'data' => t('Cover'),
      'class' => 'ga-align-center',
    ),
    array(
      'data' => t('Created'),
      'field' => 'created',
      'sort' => 'desc',
      'class' => 'ga_created ga-no-wrap',
    ),
    array(
      'data' => t('Updated'),
      'field' => 'changed',
      'class' => 'ga_created ga-no-wrap',
    ),
    array(
      'data' => t('Title'),
      'field' => 'title',
      'class' => 'ga_titles ga-no-wrap',
    ),
  );
  if ($user->uid == 1 || $user->uid == $u->uid) {
    $head[] = array(
      'data' => t('Operations'),
      'class' => 'ga-profile-edit-link',
    );
  }
  else {
    $check_profile = 'AND g.in_profile = 1';
  }
  $query = "SELECT\n      g.*,\n      n.title, n.type, n.created, n.changed,\n      p.pid, p.tpath, t.ptitle\n    FROM\n      {gallery_assist} g,\n      {node} n,\n      {gallery_assist_item} p,\n      {gallery_assist_translated} t\n    WHERE\n      g.uid = %d\n      AND g.nid = n.nid\n      AND g.gref = p.gref\n      AND p.pid = t.pid\n      AND p.cover = 1" . tablesort_sql($head);
  $result = db_query($query, $u->uid);
  $c = array();
  $edit = 0;
  while ($r = db_fetch_object($result)) {
    $r->gallconf[$r->type] = unserialize($r->data);
    if ($user->uid == 1 || $user->uid == $u->uid || $r->ga_public_status != 1) {
      if (gallery_assist_check_access($node)) {
        $c[] = $r;
      }
      if (gallery_assist_check_access($r, 'edit')) {
        $edit = $edit + 1;
      }
    }
  }
  if (count($c)) {
    if ($edit > 0 && ($user->uid == 1 || $user->uid == $u->uid)) {
      $head[] = array(
        'data' => t('Type'),
        'field' => 'type',
        'class' => 'ga-profile-type ga-no-wrap',
      );
    }
    $df = t('Y/m/d');
    $pstatus = array(
      0 => t('public'),
      1 => t('privat'),
      2 => t('public for all'),
    );
    foreach ($c as $id => $r) {
      $ipath = preg_replace('/thm\\//', 'img/', $r->tpath);
      $image = theme('image', $ipath, '', '');
      $title = l($r->title, 'node/' . $r->nid) . ($user->uid == 1 || $user->uid == $u->uid ? "<br />({$pstatus[$r->ga_public_status]})" : "");
      $rows[$id] = array(
        array(
          'data' => $r->items,
          'class' => 'ga-align-right',
        ),
        //array('data' => l($image, 'node/'. $r->nid .'/'. $r->pid, array('html' => TRUE)), 'class' => 'ga-align-center'),
        array(
          'data' => l($image, 'node/' . $r->nid, array(
            'html' => TRUE,
          )),
          'class' => 'ga-align-center',
        ),
        array(
          'data' => format_date($r->created, 'custom', $df),
        ),
        array(
          'data' => format_date($r->changed, 'custom', $df),
        ),
        array(
          'data' => $title,
        ),
      );
      if ($user->uid == 1 || $user->uid == $u->uid) {
        $rows[$id][] = array(
          'data' => l(t('edit'), 'node/' . $r->nid . '/edit', array(
            'query' => array(
              'destination' => 'user/' . $u->uid . '/user_galleries',
            ),
          )),
        );
        $rows[$id][] = array(
          'data' => node_get_types('name', $r->type),
        );
      }
    }
  }
  $output = theme('table', $head, $rows);
  $output .= theme('pager', NULL, 5, $u->uid, NULL, 5);
  return count($c) ? $output : t('No galleries');
  return '';
}