You are here

function ___gallery_assist_list_galleries in Gallery Assist 6

File

./gallery_assist.module, line 749
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' => 'counter',
      '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';
  }

  // Get db data.
  $query = "SELECT\n              g.nid,\n              g.gref,\n              g.ga_public_status,\n              g.data,\n              g.items AS counter,\n              (SELECT pid FROM {gallery_assist_item} where gref = g.gref order by cover desc limit 1) pid,\n              p.tpath,\n              n.title,\n              n.uid,\n              n.type,\n              n.created,\n              n.changed\n            FROM\n              {gallery_assist_item} p,\n              {gallery_assist} g,\n              {node} n\n            WHERE\n              g.uid = %d\n              {$check_profile}\n              AND n.nid = g.nid\n              AND n.nid = p.nid\n            GROUP BY\n              g.gref" . 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->counter,
          '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 '';
}