CMS  Version 3.9
image_gallery_view.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
40 {
41  var $grid;
42  var $id;
43 
44  var $images;
46  var $spacing = 0;
47  var $styles;
48  var $titleFormat = "{title}";
49 
50  function ImageGalleryView($images, $linkFormat, $id = "images", $size = 125)
51  {
52  $this->id = $id;
53  $this->grid = new ImageGrid($id . "_gallery", $size);
54  $this->images = $images;
55  $this->linkFormat = $linkFormat;
56  }
57 
58  function drawGallery()
59  {
60  foreach($this->images as $image)
61  {
62  $this->grid->addItem($image->image_id, $image->format($this->titleFormat), $image->caption, $image->format($this->linkFormat));
63  }
64 
65  global $script;
66 
67  $script .= $this->grid->writeScript();
68  $this->grid->drawView();
69  }
70 }
71 
72 
74 {
77  var $id;
79 
80  function ImageGalleryList($galleries, $linkFormat, $id = "galleries")
81  {
82  $this->galleries = $galleries;
83  $this->linkFormat = $linkFormat;
84 
85  $this->id = $id;
86  $this->galleryView = new ImageGalleryView($this->collateImages(), $this->linkFormat, $this->id);
87  $this->galleryView->titleFormat = "{Gallery.gallery_name}";
88  }
89 
90  function collateImages()
91  {
92  $this->images = array();
93 
94  if (count($this->galleries) == 0) return;
95 
96  $ids = formatItems($this->galleries, "{gallery_id}", ", ");
97  $groupedImages = GroupedQuery::create(ImageRecord, "WHERE gallery_id IN (". $ids .") AND published=1", "gallery_id")
98  ->execute();
99 
100  foreach($groupedImages as $gallery_id => $images)
101  {
102  $this->images[] = $images[0];
103  }
104 
105  return $this->images;
106  }
107 
108  function drawGallery()
109  {
110  if (count($this->images) == 0)
111  {
112  echo "<p>No photos have been published on this site.</p>";
113  return;
114  }
115 
116  $this->galleryView->drawGallery();
117  }
118 
119  function drawList()
120  {
121  if (count($this->images) == 0)
122  {
123  echo "<p>No photos have been published on this site.</p>";
124  return;
125  }
126 
127  $this->galleryView->drawGallery();
128  }
129 }
130  ?>
$gallery_id
Definition: image_form.inc:42
$image
Definition: image_form.inc:46
$images
Definition: images.inc:46
$size
Definition: download.inc:47