You are here

function photos_edit_sort_page in Album Photos 7.3

Grid drag and drop image sorting.

1 string reference to 'photos_edit_sort_page'
photos_menu in ./photos.module
Implements hook_menu().

File

inc/photos.edit.inc, line 306
Handles uploading and editing images.

Code

function photos_edit_sort_page($node) {
  $type = 'album';
  if (isset($node->subalbum)) {
    $type = 'sub_album';
  }
  $output = '';
  $update_button = '';
  if (isset($node->album['imageorder']) && $node->album['imageorder'] != 'weight|asc') {
    $update_button = ' ' . t('Update album image display order to "Weight - smallest first".');
  }
  $nid = $node->nid;
  drupal_add_library('system', 'ui');
  drupal_add_library('system', 'ui.draggable');
  drupal_add_library('system', 'ui.sortable');
  drupal_add_js(array(
    'photos' => array(
      'pid' => $nid,
    ),
  ), 'setting');
  $images = array();
  if ($type == 'album') {
    drupal_add_js(array(
      'photos' => array(
        'sort' => 'images',
      ),
    ), 'setting');
    $images = _photos_edit_page_album_images($nid, 50);
  }
  elseif ($type == 'sub_album') {
    drupal_add_js(array(
      'photos' => array(
        'sort' => 'sub_album',
      ),
    ), 'setting');
    $images = _photos_edit_page_sub_album_images($nid, 50);
  }
  $count = count($images);

  // @todo check album default sort - if not weight|asc show button to update album.
  $output .= t('Limit') . ': ' . l(100, 'node/' . $nid . '/photos-sort', array(
    'query' => array(
      'limit' => 100,
    ),
  ));
  $output .= ' - ' . l(500, 'node/' . $nid . '/photos-sort', array(
    'query' => array(
      'limit' => 500,
    ),
  ));
  $default_message = t('%img_count images to re-arrange.', array(
    '%img_count' => $count,
  ));
  $output .= '<div id="photos-sort-message">' . $default_message . $update_button . ' ' . '<span id="photos-sort-updates"></span></div>';
  $output .= '<ul id="photos-sortable">';
  foreach ($images as $image) {

    // $image->user = user_load($image->uid);
    // $image->href = 'photos/image/' . $image->fid;
    $item = array();
    $title = $image->title;

    // @todo set photos_sort_style variable for custom image style settings.
    $style_name = variable_get('photos_thumb_size', 'thumbnail');
    $output .= '<li id="photos_' . $image->fid . '" class="photos-sort-grid ui-state-default">';
    $output .= theme('image_style', array(
      'style_name' => $style_name,
      'path' => $image->uri,
      'alt' => $title,
      'title' => $title,
    ));
    $output .= '</li>';
  }
  $output .= '</ul>';
  $page_title = t('Re-arrange Photos: @title', array(
    '@title' => $node->title,
  ));
  drupal_set_title($page_title, PASS_THROUGH);
  return $output;
}