CMS  Version 3.9
image_list_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 $id;
42  var $images;
44  var $spacing = 0;
45  var $styles;
46  var $titleFormat = "{title}";
47 
48  function ImageListView($images, $linkFormat, $id = "images", $titleFormat = "")
49  {
50  $this->id = $id;
51  $this->images = $images;
52  $this->linkFormat = $linkFormat;
53  $this->titleFormat = ($titleFormat) ? $titleFormat : "{title}";
54  }
55 
56  function writeScript()
57  {
58 // global $script;
59 // $script .= <<<ENDSCRIPT
60 // <script type="text/javascript">
61 // window.addEvent('domready', function()
62 // {
63 // $$(".imageGrid a").each(function(elt)
64 // {
65 // elt.addEvents(
66 // {
67 // 'mouseover': function()
68 // {
69 // this.morph({'background-color': '#A9CDED', 'border-color': '#666666'});
70 // }.bind(elt),
71 // 'mouseout': function()
72 // {
73 // this.morph({'background-color': '#eeeeff', 'border-color': '#cccccc'});
74 // }.bind(elt)
75 // });
76 // });
77 // });
78 // </script>
79 // ENDSCRIPT;
80 
81 // return $script;
82  }
83 
84  function drawGrid()
85  {
86  $imgMgr = new ImageManager();
87 
88  $this->writeScript();
89 ?>
90  <ul class="imageGrid" id="<?echo $this->id?>"<?if ($this->styles) echo " style='{$this->styles}'";?>>
91  <?
92 
93  foreach($this->images as $image)
94  {
95  $thumb = $imgMgr->thumbnailLink($image->get("image_id"), 125, true);
96  $link = $image->format($this->linkFormat);
97 
98  if (is_callable($this->titleFormat))
99  $caption = call_user_func($this->titleFormat, $image);
100  else
101  $caption = $image->format($this->titleFormat);
102 
103  ?>
104  <li><div class="imageLink"<?if ($this->spacing) echo " style='margin: {$this->spacing}'";?>><a href="<?echo $link?>">
105  <span class="wrapImage"><img src="<?echo $thumb ?> " alt="Small version of image"/></span>
106  <span class="caption"><?echo ellipsis($caption, 40, false) ?></span></a>
107  </div></li>
108  <?
109  }
110  ?>
111  </ul>
112  <?
113  }
114 
115  static function writeResizeScript()
116  {
117 
118  $script .= <<<ENDSCRIPT
119 <script type="text/javascript">
120 window.addEvent('domready', function() { document.id('images_box').resizable(); });
121 </script>
122 ENDSCRIPT;
123 
124  return $script;
125  }
126 
127 }
128 
129 
130 
132 {
133  var $table;
134  var $link;
135 
136  function ImageGalleryListView($gallery, $link = "image_form?image_id={image_id}")
137  {
138  $images = $gallery->Images("ORDER BY title");
139  $this->link = $link;
140 
141  $this->table = $this->buildTable($images);
142  }
143 
144  function buildTable($images)
145  {
146 
147  $table = new DataListView($images, "images");
148  $table->column("Title", "<a href='{$this->link}'>{title}</a>", true, "width: 40%")
149  ->column("Image File", "{image_file}", true, "width: 40%")
150  ->column("Date Taken", "{date_taken}", true, "width: 20%");
151  $table->emptyMessage = "No images have been added to this gallery";
152  $table->pageSize = 20;
153  $table->sortable = true;
154  $table->filter = true;
155 
156  return $table;
157  }
158 
159  function writeScript()
160  {
161  return $this->table->writeScript();
162  }
163 
164  function drawView()
165  {
166  $this->table->drawView();
167  }
168 }
169 
171 {
172  var $table;
173 
174  function ImageGalleriesView($showHidden = false)
175  {
176  if (!$showHidden) $constraint = "WHERE hidden=0";
177 
178  $galleries = Query::create(ImageGallery, "$constraint ORDER BY gallery_name")->execute();
179 
180  $this->table = $this->buildTable($galleries);
181  }
182 
184  {
185  $table = new DataListView($galleries, "galleries");
186  $table->column("Image Gallery", array($this, formatTitleLink), true, "width: 45%")
187  ->column("Identifier", "{identifier}", true, "width: 15%")
188  ->column("Owner", "{getOwnerName()}", true, "width: 25%")
189  ->column("# Images", "{countImages()}", true, "width: 15%;text-align: right")
190  ->column("Published", array($this, showPublished), false, "text-align: center");
191 
192  $table->sortable = true;
193  $table->filter = true;
194  $table->pageSize = 10;
195  $table->emptyMessage = "No Image Galleries have been created.";
196 
197  return $table;
198  }
199 
200  function writeScript()
201  {
202  return $this->table->writeScript();
203  }
204 
205  function drawView()
206  {
207  $this->table->drawView();
208  }
209 
211  {
212  return $gallery->format("<a href='image_gallery_form?gallery_id={gallery_id}'>{gallery_name}</a>");
213  }
214 
216  {
217  $img = $gallery->published ? "on.png" : "off.png";
218  $alt = $gallery->published ? "Enabled" : "Disabled";
219 
220  return "<img src='/fakoli/images/$img' alt='$alt' onclick='toggleGalleryPublished(this, {$gallery->gallery_id})' style='display: inline-block; vertical-align: middle; border: none; cursor: pointer'/>";
221  }
222 }
223 
225 {
226  function AdminImageGalleriesView($showHidden = false)
227  {
228  parent::ImageGalleriesView($showHidden);
229  }
230 
232  {
233  return $gallery->format("<a href='/admin/image_gallery_form?gallery_id={gallery_id}'>{gallery_name}</a>");
234  }
235 
236 }
237  ?>
$constraint
$image
Definition: image_form.inc:46
$images
Definition: images.inc:46
AdminImageGalleriesView($showHidden=false)
ImageGalleriesView($showHidden=false)
static writeResizeScript()
ImageListView($images, $linkFormat, $id="images", $titleFormat="")
The ImageManager class provides basic Image manipulation functions that are useful when working with ...
$galleries
$view styles
$view spacing