You are here

GalleryAssistPager.inc in Gallery Assist 7

File

libs/classes/GalleryAssistPager.inc
View source
<?php

/**
 * 
 */
class GalleryAssistPager {
  public function __construct($node) {

    #global $_DB, $_CONFIG;
    $this->node = $node;
    $this->total = count($node->ga_items_ids);
    $this->ids = $node->ga_items_ids;
    $this->conf = $node->ga_conf[$node->type];
    $this->quantity = $this->conf['pager_quantity'];
    $this->theme = variable_get('theme_default', FALSE);
    $this->pager_layout = $this->conf['pager_theme'];
    $this->max_visble = $this->conf['pager_quantity'] < $this->total ? $this->conf['pager_quantity'] : $this->total + 2;

    //    dsm($this->ids);
  }
  public function getPager($extras = NULL, $page = false) {
    global $base_path;
    if ($page) {
      $items = array();
      $pages = ceil($this->total / ($this->conf['page_items_per_row'] * $this->conf['page_rows_per_page']));
      for ($i = 0; $i < $pages; $i++) {
        $items[] = array(
          'class' => array(),
          'data' => l($i + 1, "node/{$this->node->nid}", array(
            'attributes' => array(),
            'query' => array(
              'page' => $i,
            ),
          )),
        );
      }
      $variables = array(
        'items' => $items,
        'title' => NULL,
        'type' => 'ul',
        'attributes' => array(
          'id' => "gallery-assist-pager-{$this->node->nid}",
          'class' => array(
            'gallery-assist-pager',
          ),
        ),
      );
      $output = theme('item_list', $variables);
    }
    else {
      $this->hellip = $this->first = $this->last = $this->next = $this->previous = $this->mini = $this->data = '';
      $this->before = $this->after = $this->links = array();
      if (count($this->ids) <= 1) {
        return '';
      }
      $i = 0;
      foreach ($this->ids as $k => $v) {
        ++$i;
        $this->data[$i] = $this->node->ga_items_ids[$k];
        $this->data[$i]->opath = $this->node->ga_items_ids[$k]->opath;
        $this->node->ga_items_ids[$k]->counter = $i;
      }
      $this->page = !empty($this->node->ga_items_ids[$this->node->pid]->counter) ? $this->node->ga_items_ids[$this->node->pid]->counter : 1;
      $this->quantity = $this->total > $this->quantity ? $this->max_visble : $this->total;
      $this->short = $this->total > $this->quantity - 2 ? 1 : 0;
      $this->odd = $this->quantity & 1;
      $this->n = $this->odd == 1 ? 0 : 1;
      $this->middle = ceil($this->quantity / 2);
      $my_attributes = array(
        'class' => array(
          $this->node->type,
          'pager',
        ),
      );

      //        if ($conf['gap_align'] !== 'node') {
      //            switch ($conf['gap_align']) {
      //                case 'left' :
      //                    $my_attributes['style'] = $conf['pager_align'] == 'left' ? 'text-align:left;' : 'text-align:'. $conf['pager_align'];
      //                    break;
      //
      //                case 'center' :
      //                    $my_attributes['style'] = $conf['pager_align'] == 'center' ? 'text-align:center;' : 'text-align:'. $conf['pager_align'];
      //                    break;
      //
      //                case 'right' :
      //                    $my_attributes['style'] = $conf['pager_align'] == 'right' ? 'text-align:right;' : 'text-align:'. $conf['pager_align'];
      //                    break;
      //            }
      //        }
      $my_active_opts = array(
        'attributes' => array(
          'class' => array(
            $this->node->type,
            'active',
          ),
        ),
        'html' => TRUE,
      );
      $my_grafic_previous_path = file_exists(drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/previous.png') ? $base_path . drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/previous.png' : $base_path . drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/previous.png';
      $my_grafic_previous = theme('image', array(
        'path' => file_create_url($my_grafic_previous_path, NULL),
        'title' => t('go to the previous'),
        'getsize' => TRUE,
      ));
      $my_grafic_next_path = file_exists(drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/next.png') ? $base_path . drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/next.png' : $base_path . drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/next.png';
      $my_grafic_next = theme('image', array(
        'path' => file_create_url($my_grafic_next_path, NULL),
        'title' => t('go to the next'),
        'getsize' => TRUE,
      ));
      if ($this->conf['pager_format'] == 0) {
        $my_grafic_first_path = file_exists(drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/first.png') ? $base_path . drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/first.png' : $base_path . drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/first.png';
        $my_grafic_first = theme('image', array(
          'path' => file_create_url($my_grafic_first_path, NULL),
          'title' => t('go to the first'),
          'getsize' => TRUE,
        ));
        $my_grafic_hellip_path = file_exists(drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/hellip.png') ? drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/hellip.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/hellip.png';
        $my_grafic_hellip = theme('image', array(
          'path' => file_create_url($my_grafic_hellip_path, NULL),
          'getsize' => TRUE,
        ));
        $my_grafic_last_path = file_exists(drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/last.png') ? drupal_get_path('theme', $this->theme) . '/ga_pager/' . $this->pager_layout . '/last.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/last.png';
        $my_grafic_last = theme('image', array(
          'path' => file_create_url($my_grafic_last_path, NULL),
          'title' => t('go to the last'),
          'getsize' => TRUE,
        ));
        $this->first = $this->conf['pager_type'] == 0 ? t('« first') : $my_grafic_first;
        $this->last = $this->conf['pager_type'] == 0 ? t('last »') : $my_grafic_last;
        $this->hellip = $this->conf['pager_type'] == 0 ? '&hellip;' : $my_grafic_hellip;
      }
      $this->previous = $this->conf['pager_type'] == 0 || $this->quantity == 0 ? t('‹ previous') : $my_grafic_previous;
      $this->next = $this->conf['pager_type'] == 0 || $this->quantity == 0 ? t('next ›') : $my_grafic_next;
      $link_helper = $this->node->type == 'gallery_assist' ? '' : '_' . $this->node->type;
      $my_pager_paths = $extras == 'edit-one' ? 'node/ga_edit_one' . $link_helper . '/' . $this->node->nid . '/item/' : 'node/' . $this->node->nid . '/item/';
      $get_values = array();
      $get_values = $_GET;
      unset($get_values['q']);
      $my_active_opts['query'] = $get_values;

      // $link = l('[edit]', 'node/ga_edit_one/'. $item->nid .'/'. $item->pid, array('query' => $get_values));
      if ($this->quantity > 0 && $this->conf['pager_format'] == 0) {
        $this->before[] = array(
          'class' => array(
            $this->node->type,
            'pager-first',
          ),
          'data' => $this->page > 1 ? l($this->first, $my_pager_paths . $this->data[1]->pid, $my_active_opts) : $this->first,
        );
      }
      $this->before[] = array(
        'class' => array(
          $this->node->type,
          'pager-previous',
        ),
        'data' => $this->page == 1 ? l($this->previous, $my_pager_paths . $this->data[$this->total]->pid, $my_active_opts) : l($this->previous, $my_pager_paths . $this->data[$this->page - 1]->pid, $my_active_opts),
      );
      if ($this->quantity > 0 && $this->conf['pager_format'] == 0) {
        $this->before[] = array(
          'class' => array(
            $this->node->type,
            'pager-ellipsis',
          ),
          'data' => $this->short == 1 && $this->page > $this->middle ? $this->hellip : '&nbsp;&nbsp;&nbsp;',
        );
      }
      $c = 1;
      foreach ($this->data as $k => $v) {
        if ($c == $this->page) {
          $my_clss = 'pager-current';
          $variables = array(
            'path' => $this->data[$c]->opath,
            #'alt' => $data[$c]->palt,
            'title' => $c . ' / ' . $this->total,
            'getsize' => FALSE,
            'style_name' => $this->node->ga_conf[$this->node->type]['icon_image_style'],
            'attributes' => array(
              'class' => array(
                'ga-pager-active-image',
              ),
              'height' => $this->conf['pager_thm_active_height'],
            ),
          );
          $this->mini = theme('image_style', $variables);
          $my_pager_layout_def = $extras == 'edit-one' ? 1 : $this->conf['pager_type'];
          $my_data = $my_pager_layout_def == 1 ? $this->mini : $c;
        }
        else {
          $my_clss = 'pager-item';
          if (module_exists('imagecache') && is_numeric($this->conf['pager_presetid'])) {
            $this->mini = theme('imagecache', $this->conf['pager_presetname'], $this->data[$c]->opath, '', $c . ' / ' . $this->total, array(
              'class' => array(
                $this->node->type,
                'pager-thumbnail ic-off',
              ),
            ), FALSE);
          }
          else {

            #$my_mini = theme('image', file_create_url($data[$c]->thmb_path), '', $c .' / '. $my_total, array('height' => $conf['pager_t_height'], 'id' => 'pager-icon', 'class' => array($node->type, ' gallery-assist-thumbnail')), FALSE);
            $variables = array(
              'path' => $this->data[$c]->opath,
              #'alt' => $data[$c]->palt,
              'title' => $c . ' / ' . $this->total,
              'getsize' => FALSE,
              'style_name' => $this->node->ga_conf[$this->node->type]['icon_image_style'],
              'attributes' => array(
                'class' => array(
                  'ga-pager-image',
                ),
                'height' => $this->conf['pager_thm_height'],
              ),
            );
            $this->mini = theme('image_style', $variables);
          }
          $my_pager_layout_def = $extras == 'edit-one' ? 1 : $this->conf['pager_type'];
          $my_symbol = $my_pager_layout_def == 1 ? $this->mini : $c;
          $my_data = l($my_symbol, $my_pager_paths . $this->data[$c]->pid, $my_active_opts);
        }
        $this->links[] = array(
          'class' => array(
            $this->node->type,
            $my_clss,
          ),
          'data' => $my_data,
        );
        $c++;
      }
      if ($this->short == 1 && $this->total > $this->quantity) {
        if ($this->page > $this->total - $this->quantity) {
          if ($this->page + $this->middle - $this->odd < $this->total) {
            $mysmall = array_slice($this->links, $this->page - $this->middle, $this->quantity, TRUE);
          }
          else {
            $mysmall = array_slice($this->links, $this->total - $this->quantity, $this->quantity, TRUE);
          }
        }
        elseif ($this->page <= $this->quantity) {
          if ($this->page >= $this->middle) {
            $mysmall = array_slice($this->links, $this->page - $this->middle, $this->quantity, TRUE);
          }
          else {
            $mysmall = array_slice($this->links, 0, $this->quantity, TRUE);
          }
        }
        else {
          $mysmall = array_slice($this->links, $this->page - $this->middle, $this->middle + $this->middle - $this->odd, TRUE);
        }
      }
      else {
        $mysmall = array(
          '',
        );
      }
      $my_after_data = $this->short == 1 && $this->page + $this->middle + $this->n <= $this->total ? $this->hellip : '&nbsp;&nbsp;&nbsp;';
      if ($this->quantity > 0 && $this->conf['pager_format'] == 0) {
        $this->after[] = array(
          'class' => array(
            $this->node->type,
            'pager-ellipsis',
          ),
          'data' => $my_after_data,
        );
      }
      $this->after[] = array(
        'class' => array(
          $this->node->type,
          'pager-next',
        ),
        'data' => $this->page == $this->total ? l($this->next, $my_pager_paths . $this->data[1]->pid, $my_active_opts) : l($this->next, $my_pager_paths . $this->data[$this->page + 1]->pid, $my_active_opts),
      );
      if ($this->quantity > 0 && $this->conf['pager_format'] == 0) {
        $this->after[] = array(
          'class' => array(
            $this->node->type,
            'pager-last',
          ),
          'data' => $this->page == count($this->node->ga_items_ids) ? $this->last : l($this->last, $my_pager_paths . $this->data[$this->total]->pid, $my_active_opts),
        );
      }
      if ($this->short == 1) {
        $this->links = $mysmall;
      }
      else {
        $this->links = $this->links;
      }
      $olinks = array_merge($this->before, $this->links, $this->after);
      $variables = array(
        'items' => $olinks,
        'title' => NULL,
        'type' => 'ul',
        'attributes' => array(
          'id' => "gallery-assist-pager-{$this->node->nid}",
          'class' => array(
            'gallery-assist-pager',
          ),
        ),
      );
      $output = theme('item_list', $variables);
    }
    return $output;
  }

}

Classes

Namesort descending Description
GalleryAssistPager