From: Steve Sutton Date: Mon, 8 Feb 2010 19:54:30 +0000 (+0000) Subject: adding Photo Gallery X-Git-Tag: v1.0.0~112 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=f8356d57d9be5bdd26e4c49a910349acfe460c10;p=web%2FTroutCreek.git adding Photo Gallery --- diff --git a/Toolkit/Photos/Display.php b/Toolkit/Photos/Display.php new file mode 100755 index 0000000..0159542 --- /dev/null +++ b/Toolkit/Photos/Display.php @@ -0,0 +1,255 @@ + + * @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 + * @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(); + } + } + + // }}} +} +?> diff --git a/Toolkit/Photos/assets/.keepme b/Toolkit/Photos/assets/.keepme new file mode 100644 index 0000000..e69de29 diff --git a/Toolkit/Photos/templates/compiled/.cvsignore b/Toolkit/Photos/templates/compiled/.cvsignore new file mode 100755 index 0000000..65fb5e5 --- /dev/null +++ b/Toolkit/Photos/templates/compiled/.cvsignore @@ -0,0 +1 @@ +* *.* diff --git a/Toolkit/Photos/templates/compiled/.keepme b/Toolkit/Photos/templates/compiled/.keepme new file mode 100644 index 0000000..e69de29 diff --git a/Toolkit/Photos/templates/compiled/photoCats.html.en.php b/Toolkit/Photos/templates/compiled/photoCats.html.en.php new file mode 100755 index 0000000..db6cfd2 --- /dev/null +++ b/Toolkit/Photos/templates/compiled/photoCats.html.en.php @@ -0,0 +1,8 @@ + + diff --git a/Toolkit/Photos/templates/compiled/photoCats.html.gettext.serial b/Toolkit/Photos/templates/compiled/photoCats.html.gettext.serial new file mode 100644 index 0000000..febccfc --- /dev/null +++ b/Toolkit/Photos/templates/compiled/photoCats.html.gettext.serial @@ -0,0 +1 @@ +a:1:{i:0;s:37:"Click an image to enter a Photo Album";} \ No newline at end of file diff --git a/Toolkit/Photos/templates/compiled/photos.html.en.php b/Toolkit/Photos/templates/compiled/photos.html.en.php new file mode 100755 index 0000000..75b0fd7 --- /dev/null +++ b/Toolkit/Photos/templates/compiled/photos.html.en.php @@ -0,0 +1,15 @@ + diff --git a/Toolkit/Photos/templates/photoCats.html b/Toolkit/Photos/templates/photoCats.html new file mode 100755 index 0000000..e877442 --- /dev/null +++ b/Toolkit/Photos/templates/photoCats.html @@ -0,0 +1,8 @@ + + diff --git a/Toolkit/Photos/templates/photos.html b/Toolkit/Photos/templates/photos.html new file mode 100755 index 0000000..fdd861d --- /dev/null +++ b/Toolkit/Photos/templates/photos.html @@ -0,0 +1,15 @@ +