CMS  Version 3.9
taxonomy_facet_filter.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9 Copyright (c) 2013 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 
39 Fakoli::usingFeature("facet_manager");
40 
41 class TaxonomyFacetFilter extends AbstractFacetFilter
42 {
43  var $taxonomy;
44 
45  var $width = "200px";
46  var $height = "100px";
47  var $dropdown = true;
48  var $dropdownMaxWidth = "200px";
49  var $dropdownMessage = "Click to Select Terms";
50 
52  {
53  $this->taxonomy = $taxonomy;
54  }
55 
56  function getID()
57  {
58  return $this->taxonomy->identifier;
59  }
60 
61  function onTagItem($item, $attrs)
62  {
63  // Need to work with underlying object if passed is a search result container
64  if ($item instanceof AbstractSearchResult) $item = $item->item;
65 
66  $term_ids = $this->taxonomy->getAssociatedTermIds($item);
67  if ($term_ids)
68  {
69  $attrs["data-taxonomy-{$this->taxonomy->identifier}"] = $term_ids;
70  }
71 
72  return $attrs;
73  }
74 
75  function writeScript()
76  {
77  ob_start();
78 
79  if ($this->dropdown)
80  {
81 ?>
82  var <?echo $this->taxonomy->identifier?>_select = new MultiSelect('<?echo $this->taxonomy->identifier?>_container', {maxWidth: '<?echo $this->dropdownMaxWidth?>', message: '<?echo jsSafe($this->dropdownMessage)?>'});
83  var <?echo $this->taxonomy->identifier?>_handler = new TaxonomyFacetHandler('<?echo $this->taxonomy->identifier?>', <?echo $this->taxonomy->identifier?>_select, <?echo $this->manager->target->getID()?>_facet_manager);
84 <?
85  }
86 
87  $script = ob_get_contents();
88  ob_end_clean();
89  return $script;
90  }
91 
92  function drawFacet()
93  {
94  $items = $this->getTerms();
95 
96  if (count($items) == 0) return;
97 
98  if ($this->width && $this->height)
99  {
100  $width = is_numeric($this->width) ? "{$this->width}px" : $this->width;
101  $height = is_numeric($this->height) ? "{$this->height}px" : $this->height;
102 
103  $padding = ($width == "auto") ? "padding-right: 20px; overflow-x: hidden" : "";
104 
105  $resizable = (!$this->dropdown && $this->resizable) ? " resizable": "";
106  $dropdown = $this->dropdown ? " multi_select_dropdown_list" : "";
107  echo "<div id='{$this->taxonomy->identifier}_container' class='scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height};overflow: auto; $padding'>\n";
108  }
109 
110  $this->renderCheckBoxes($items);
111 
112  if ($this->width && $this->height)
113  {
114  echo "</div>\n";
115  }
116 
117  }
118 
119  function getTerms()
120  {
121  return $this->taxonomy->Terms("ORDER BY sort_order, term");
122  }
123 
125  {
126  foreach($items as $item)
127  {
128  $p = $item->term_id;
129 
130  echo "<label for='checkbox_{$this->taxonomy->identifier}_$p'><input type='checkbox' class='checkbox' name='{$this->taxonomy->identifier}[$p]' id='checkbox_{$this->taxonomy->identifier}_$p' value='$p'";
131  if (array_key_exists($p, $selected))
132  {
133  echo " checked";
134  }
135  echo ">".$item->term."";
136  echo "</label>";
137  }
138  }
139 }
140 
141 
142 
143 
144 class BindingTargetFacetFilter extends AbstractFacetFilter
145 {
147 
148  var $width = "200px";
149  var $height = "100px";
150  var $dropdown = true;
151  var $dropdownMaxWidth = "200px";
152  var $dropdownMessage = "Click to Select Terms";
153 
155  {
156  $this->bindingTarget = $bindingTarget;
157  }
158 
159  function getID()
160  {
161  return $this->bindingTarget->target_class;
162  }
163 
164  function onTagItem($item, $attrs)
165  {
166  // Need to work with underlying object if passed is a search result container
167  if ($item instanceof AbstractSearchResult) $item = $item->item;
168 
169  $target_ids = $this->bindingTarget->getBoundItemIds($item);
170  if ($target_ids)
171  {
172  $attrs["data-taxonomy-{$this->bindingTarget->target_class}"] = $target_ids;
173  }
174 
175  return $attrs;
176  }
177 
178  function writeScript()
179  {
180  ob_start();
181 
182  if ($this->dropdown)
183  {
184  ?>
185  var <?echo $this->bindingTarget->target_class?>_select = new MultiSelect('<?echo $this->bindingTarget->target_class?>_container', {maxWidth: '<?echo $this->dropdownMaxWidth?>', message: '<?echo jsSafe($this->dropdownMessage)?>'});
186  var <?echo $this->bindingTarget->target_class?>_handler = new TaxonomyFacetHandler('<?echo $this->bindingTarget->target_class?>', <?echo $this->bindingTarget->target_class?>_select, <?echo $this->manager->target->getID()?>_facet_manager);
187 <?
188  }
189 
190  $script = ob_get_contents();
191  ob_end_clean();
192  return $script;
193  }
194 
195  function drawFacet()
196  {
197  $items = TaxonomyManager::getBindingOptions($this->bindingTarget->target_class);
198 
199  if (count($items) == 0)
200  {
201  trace("## No items found for bound facet - {$this->bindingTarget->target_class}", 2);
202  return;
203  }
204 
205  if ($this->width && $this->height)
206  {
207  $width = is_numeric($this->width) ? "{$this->width}px" : $this->width;
208  $height = is_numeric($this->height) ? "{$this->height}px" : $this->height;
209 
210  $padding = ($width == "auto") ? "padding-right: 20px; overflow-x: hidden" : "";
211 
212  $resizable = (!$this->dropdown && $this->resizable) ? " resizable": "";
213  $dropdown = $this->dropdown ? " multi_select_dropdown_list" : "";
214  echo "<div id='{$this->bindingTarget->target_class}_container' class='scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height};overflow: auto; $padding'>\n";
215  }
216 
217  $this->renderCheckBoxes($items);
218 
219  if ($this->width && $this->height)
220  {
221  echo "</div>\n";
222  }
223 
224  }
225 
227  {
228  $format = TaxonomyManager::getBindingOptionFormat($this->bindingTarget);
229 
230  foreach($items as $item)
231  {
232  $p = $item->get($item->getPrimaryKey());
233 
234  echo "<label for='checkbox_{$this->bindingTarget->target_class}_$p'><input type='checkbox' class='checkbox' name='{$this->bindingTarget->target_class}[$p]' id='checkbox_{$this->bindingTarget->target_class}_$p' value='$p'";
235  if (array_key_exists($p, $selected))
236  {
237  echo " checked";
238  }
239  echo ">".$item->format($format)."";
240  echo "</label>";
241  }
242  }
243 }?>
$columnSelect dropdown
$helpTree width
Definition: tree.inc:45
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static getBindingOptionFormat($bindingTarget)
static getBindingOptions($bindingTarget)
$desc height
Definition: event_edit.inc:64
$email message