CMS  Version 3.9
image_grid.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::usingFeature("facet_manager");
8 
10 {
11  var $grid;
12  var $item;
13  var $id;
14  var $image_id;
15  var $title;
16  var $text;
17  var $onclick;
18  var $cssClass = null;
19 
20  function __construct($grid, $image_id, $title, $text, $onclick = "return false;")
21  {
22  $this->grid = $grid;
23  $this->image_id = $image_id;
24  $this->title = $title;
25  $this->text = $text;
26  $this->onclick = $onclick;
27  }
28 
29  function draw($size, $attrs)
30  {
31  $imageSize = $this->grid->retinaMode ? $size * 2 : $size;
32  $mode = $this->grid->useBackgroundImages ? "thumbnail" : "iconize";
33 
34  $src = $this->image_id ? "/action/image/{$mode}?image_id={$this->image_id}&size={$imageSize}" : "/fakoli/images/noimage.gif";
35 
36  $dataAttrs = "";
37  foreach($attrs as $name => $value)
38  {
39  $dataAttrs .= "$name='$value' ";
40  }
41 
42  $cssClass = $this->cssClass ? "class='{$this->cssClass}' " : "";
43 
44  if ($this->grid->useBackgroundImages)
45  {
46  $styles = $this->grid->inlineSizing ? "width: {$size}px; height: {$size}px; margin: 10px'" : "";
47 ?>
48  <li <?echo $cssClass?>data-details='<?echo $this->id?>' style='background-image: url(<?echo $src?>);background-size: cover;<?echo $styles?>' onclick='<?echo $this->onclick?>'><div class='title'><?echo $this->title?></div></li>
49 <?
50  }
51  else
52  {
53 ?>
54  <li <?echo $cssClass?>data-details='<?echo $this->id?>' <?echo $dataAttrs?>style='width: <?echo $size + 10?>px; height: <?echo $size + 40?>px; margin: 10px'><div onclick='<?echo $this->onclick?>' style='width: <?echo $size ?>px; height: <?echo $size + 40?>px'><img src="<?echo $src?>" alt="<?echo $this->title?>" style='width: <?echo $size?>px; height: <?echo $size?>px'></img><br/><?echo $this->title?></div></li>
55 <?
56  }
57  }
58 }
59 
60 class ImageGrid implements FacetFilterable
61 {
62  var $id;
63  var $items;
64  var $size;
65  var $tagItemCallbacks = array();
66  var $puff;
67  var $useBackgroundImages = false;
68  var $retinaMode = false;
69  var $cssClass = null;
70  var $inlineSizing = true;
71 
72  function __construct($id, $size = 200, $puff = true, $useBackgroundImages = false)
73  {
74  $this->id = $id;
75  $this->items = array();
76  $this->size = $size;
77  $this->puff = $puff;
78  $this->useBackgroundImages = $useBackgroundImages;
79  $this->retinaMode = Settings::getValue("image", "retina_mode");
80  }
81 
82  function getID()
83  {
84  return $this->id;
85  }
86 
87  function addItem($image_id, $title, $text, $onclick = "return false;")
88  {
89  $item = new ImageGridItem($this, $image_id, $title, $text, $onclick);
90  $this->items[] = $item;
91  return $item;
92  }
93 
99  {
100  $this->tagItemCallbacks[] = $handler;
101  }
102 
103 
104  function writeScript()
105  {
106  ob_start();
107 
108  $puff = $this->puff ? 'true' : 'false';
109 ?>
110 <script type="text/javascript">
111 window.addEvent('domready', function()
112 {
113  new ImageGrid('<?echo $this->id?>', <?echo $this->size?>, {puff: <?echo $puff?>});
114 });
115 </script>
116 <?
117  $script = ob_get_contents();
118  ob_end_clean();
119  return $script;
120  }
121 
122  function drawView()
123  {
124  $cssClass = $this->cssClass ? "image_grid {$this->cssClass}" : "image_grid";
125 ?>
126  <ul id="<?echo $this->id?>" class='<?echo $cssClass?>'>
127 <?
128  foreach($this->items as $item)
129  {
130  $attrs = array();
131 
132  foreach($this->tagItemCallbacks as $handler)
133  {
134  $attrs = call_user_func($handler, $item->item, $attrs);
135  }
136 
137  $item->draw($this->size, $attrs);
138  }
139 ?>
140  </ul>
141 <?
142  }
143 }?>
$table cssClass
$handler
Definition: event_form.inc:62
$src
Definition: page.inc:37
$helpTree style
Definition: tree.inc:46
$image_id
Definition: image_form.inc:41
$imageUpload size
Definition: image_form.inc:68
$size
Definition: download.inc:47
$name
Definition: upload.inc:54
$bookmark title
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
$useBackgroundImages
Definition: image_grid.inc:67
__construct($id, $size=200, $puff=true, $useBackgroundImages=false)
Definition: image_grid.inc:72
addItem($image_id, $title, $text, $onclick="return false;")
Definition: image_grid.inc:87
addFacetTaggingHandler($handler)
Adds a row tagging handler.
Definition: image_grid.inc:98
draw($size, $attrs)
Definition: image_grid.inc:29
__construct($grid, $image_id, $title, $text, $onclick="return false;")
Definition: image_grid.inc:20
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
$mode
$styles