/home/coolpkct/www/websites/cake3.cool.rocks/admin/classes/galleryindex.php
<?php
/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2013, SimpleViewer Inc.
 */
defined('SK_ACCESS')||die('<h1>403: Forbidden</h1>');
$ds = DIRECTORY_SEPARATOR;
require_once "classes{$ds}gallerylink.php";

class GalleryIndex
{
  /**
   * @var array gallery index data
   */
  private $galleryIndexData = array();
  
  /**
   * Constructor
   *
   * @param object instance of PageSet
   * @return void
   */
  public function __construct(PageSet $pageSet)
  {
    $config = SkConfig::getInstance();
    $pagesData = $pageSet->getPagesData();
    $weights = array();
    foreach ($pagesData as $key=>$pageData)
    {
      // Skip gallery index pages to avoid danger of infinite loop
      if (
          $pageData['pageType'] == 'galleryindex'
          || !$pageData['isGallery']
      ) continue;
      $this->galleryIndexData[$key] = $pageData;
      $this->galleryIndexData[$key]['parentPage'] =
          isset($pageData['parentPage'])
              ? $pageData['parentPage']
              : 0;
      $this->galleryIndexData[$key]['galleryUrl']  = 
          $config->getContentUrl()
          .'/'
          .str_replace('\\', '/', basename($pageData['path']))
          .'/';
      $this->galleryIndexData[$key]['thumbUrl'] = 
          $config->getThumbCacheUrl()
          .'/'
          .INDEX_THUMB_PREFIX
          .$pageData['pageRef']
          .'.jpg';
      $weights[$key] = isset($pageData['navWeight']) ? $pageData['navWeight'] : 0;
    }
    array_multisort($weights, $this->galleryIndexData);
  }
   
  /**
   * Get array of gallery link objects
   *
   * @return array
   * @param object instance of Page
   * @param boolean return page group links only
   */
   public function getGalleryLinks(Page $page, $group=false)
   {
        $theme = $page->getTheme();
        $size = $theme->getIndexThumbSize();
        $indexThumbFormat =
            $size['width'] == 0
            ? 100
            : 100*$size['height']/$size['width'];
        $galleryLinks = array();
        foreach ($this->galleryIndexData as $key=>&$data) {
           if ($group && ($data['parentPage'] != $page->getRef())) continue;
           if (isset($data['indexShow']) && strtolower($data['indexShow']) == 'false') continue;
           if (isset($data['supported']) && strtolower($data['supported']) == 'false') continue;
           $data['thumbWidth']  = $size['width'];
           $data['thumbHeight'] = $size['height'];
           $data['thumbFormat'] = $indexThumbFormat;
           $galleryLinks[$key]  = new GalleryLink($data);
        }
        unset($data);
        return $galleryLinks;
   }
}