--- /dev/null
+<?php
+
+/**
+ * Display.php
+ *
+ * PHP version 5
+ *
+ * @category Photos
+ * @package Toolkit_Photos
+ * @author Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2009 Gaslight Media
+ * @license Gaslight Media
+ * @version CVS: $Id: Display.php,v 1.8 2010/01/15 01:13:01 jamie Exp $
+ * @link <>
+ */
+
+/**
+ * Toolkit_Photos_Display
+ *
+ * Display the Photo Gallery assoc to a toolbox page
+ *
+ * @category Photos
+ * @package Toolkit_Photos
+ * @author Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2009 Gaslight Media
+ * @license Gaslight Media
+ * @link <>
+ */
+class Toolkit_Photos_Display
+{
+ // {{{ Properties
+
+ /**
+ * Options for Flexy Templates
+ * @var array
+ * @access protected
+ */
+ protected $flexyOptions = array(
+ 'templateDir' => '/templates',
+ 'compileDir' => '/templates/compiled',
+ 'forceCompile' => false,
+ 'allowPHP' => true,
+ );
+
+ /**
+ * page name for form action and links
+ * @var unknown
+ * @access protected
+ */
+ protected $pageName;
+
+ /**
+ * Photo Table Name
+ * @var string
+ * @access protected
+ */
+ protected $photoTable = 'photo';
+
+ /**
+ * Photo Category Table Name
+ * @var string
+ * @access protected
+ */
+ protected $categoryTable = 'photo_category';
+
+ /**
+ * rowCount
+ *
+ * @var float
+ * @access protected
+ */
+ protected $rowCount = 3;
+ // }}}
+ // {{{ __construct()
+
+ /**
+ * __construct()
+ *
+ * @return void
+ * @access public
+ */
+ function __construct()
+ {
+ // assign the global dbh to $this->dbh;
+ $this->dbh = Toolkit_Database::getInstance();
+ // set paths for templates
+ $this->flexyOptions['templateDir'] = dirname(__FILE__)
+ .$this->flexyOptions['templateDir'];
+ $this->flexyOptions['compileDir'] = dirname(__FILE__)
+ .$this->flexyOptions['compileDir'];
+ // the main display page for events to link to
+ $this->pageName = BASE_URL.'index.php?catid='.$_REQUEST['catid'];
+ }
+
+ // }}}
+ // {{{ listPhotoCategories()
+
+ /**
+ * listPhotoCategories()
+ *
+ * Display Photo Categories
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ function listPhotoCategories()
+ {
+ $sql = "
+ SELECT pc.*
+ FROM photo_category pc, photo_category_bus pcb
+ WHERE pcb.photocat_id = pc.id
+ AND pcb.buscat_id = {$_REQUEST['catid']}
+ AND pc.id IN (
+ SELECT distinct(catid)
+ FROM photo)
+ ORDER BY pcb.pos;";
+ try {
+ $data = $this->dbh->query($sql)->fetchAll();
+ if (is_array($data)) {
+ $i = 0;
+ foreach ($data as &$row) {
+ unset($row['image']);
+ // use the first one from its photos
+ $sql = "
+ SELECT image
+ FROM photo
+ WHERE catid = {$row['id']}
+ AND image != ''";
+ try {
+ $row2 = $this->dbh->query($sql)->fetch();
+ $data[$i]['image'] = $row2['image'];
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ ++$i;
+ }
+ $template = new HTML_Template_Flexy($this->flexyOptions);
+ $page = new stdClass;
+ $page->appbase = GLM_APP_BASE_URL;
+ $page->page = BASE_URL.'index.php?catid='.$_REQUEST['catid'].'&photo_catid=';
+ $page->cats = $data;
+ $page->imgPath = PHOTO_SMALL_URL;
+ $template->compile('photoCats.html');
+ return $template->bufferedOutputObject($page);
+ } else {
+ return '';
+ }
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ listPhotos()
+
+ /**
+ * listPhotos()
+ *
+ * Display Photos
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ function listPhotos()
+ {
+ // where clauses
+ if ($_REQUEST['photo_catid']) {
+ // grab photo album name for display
+ try {
+ $sql = "
+ SELECT category
+ FROM photo_category
+ WHERE id = :id";
+ $stmt1 = $this->dbh->prepare($sql);
+ $stmt1->bindParam(":id", $_REQUEST['photo_catid'], PDO::PARAM_INT);
+ $stmt1->execute();
+ $albumName = $stmt1->fetchColumn();
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ $where[] = "catid = {$_REQUEST['photo_catid']}";
+ }
+ // query
+ $sql = "
+ SELECT *
+ FROM {$this->photoTable}";
+ if (is_array($where)) {
+ $sql .= " WHERE ".implode(" AND ", $where);
+ }
+ $sql .= " ORDER BY pos";
+ try {
+ $data = $this->dbh->query($sql)->fetchAll();
+ $count = 1;
+ $trueCount = 1;
+ $num = count($data);
+ foreach ($data as &$row) {
+ if ($count == 1) {
+ $row['firstInRow'] = true;
+ } else {
+ $row['firstInRow'] = false;
+ }
+ if ($count == $this->rowCount || $trueCount == $num) {
+ $row['lastInRow'] = true;
+ $count = 0;
+ } else {
+ $row['lastInRow'] = false;
+ }
+ ++$count;
+ ++$trueCount;
+ }
+ if (is_array($data)) {
+ $template = new HTML_Template_Flexy($this->flexyOptions);
+ $page = new stdClass;
+ $page->album = ($albumName) ? $albumName: 'Photo Gallery';
+ $page->appbase = GLM_APP_BASE_URL;
+ $page->photos = $data;
+ $page->imgPath = PHOTO_SMALL_URL;
+ $page->orgPath = PHOTO_LARGE_URL;
+ $template->compile('photos.html');
+ return $template->bufferedOutputObject($page);
+ } else {
+ return '';
+ }
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ toHTML()
+
+ /**
+ * toHTML()
+ *
+ * call to listPhotos function for display of Photos
+ *
+ * @return void
+ * @access public
+ */
+ function toHTML()
+ {
+ $GLOBALS['scripts'][] = GLM_APP_BASE_URL . 'gallery/thickbox-3.1.1.js';
+ $GLOBALS['styleSheets'][] = GLM_APP_BASE_URL . 'gallery/gallery.css';
+ $GLOBALS['styleSheets'][] = GLM_APP_BASE_URL . 'gallery/thickbox.css';
+
+ if (is_array($_REQUEST['photo_catid'])) {
+ return $this->listPhotoCategories();
+ } elseif ($_REQUEST['photo_catid']) {
+ return $this->listPhotos();
+ }
+ }
+
+ // }}}
+}
+?>