CMS  Version 3.9
TaxonomyTermFieldRenderer Class Reference

Field renderer for handling taxonomy term relationships. More...

Inherits FieldRenderer.

Public Member Functions

 TaxonomyTermFieldRenderer (&$form, $taxonomy)
 
 setSize ($width, $height)
 
 groupBy ($groupBy, $format="")
 
 renderScript ($field)
 
 renderSearchScript ($field, $mode)
 
 getMatchingPK ($xref, $obj)
 
 renderField ($field="")
 
 renderCheckboxes ($field, $items, $selected, $mode=null)
 
 renderReadOnly ($field="")
 
 renderSearchField ($field, $mode)
 
 preProcess ($field="")
 
 postProcess ($field="")
 

Public Attributes

 $field
 
 $label
 
 $taxonomy
 
 $dropdown
 
 $dropdownMaxWidth = "340px"
 
 $dropdownMessage = "Click to Select Terms"
 
 $options
 
 $showSelectAll
 
 $resizable = true
 

Static Public Attributes

static $readOnlyTermSeparator = "<br>"
 

Detailed Description

Field renderer for handling taxonomy term relationships.

Definition at line 44 of file taxonomy_term_field_renderer.inc.

Member Function Documentation

◆ getMatchingPK()

TaxonomyTermFieldRenderer::getMatchingPK (   $xref,
  $obj 
)

Definition at line 151 of file taxonomy_term_field_renderer.inc.

152  {
153  $pks = $obj->getPrimaryKeyList();
154  foreach($pks as $pk)
155  {
156  if ($xref->hasField($pk)) return $pk;
157  }
158 
159  throw new DataItemException("No matching foreign key in xref table");
160  }

◆ groupBy()

TaxonomyTermFieldRenderer::groupBy (   $groupBy,
  $format = "" 
)

Definition at line 88 of file taxonomy_term_field_renderer.inc.

89  {
90  $this->groupBy = $groupBy;
91  $this->groupByFormat = $format;
92  }

◆ postProcess()

TaxonomyTermFieldRenderer::postProcess (   $field = "")

Definition at line 325 of file taxonomy_term_field_renderer.inc.

326  {
327  if (count($this->options) == 0) return;
328 
329  $obj = $this->parent->data;
330  $class = get_class($obj);
331  $pk = $obj->get($obj->getPrimaryKey());
332 
333  $assoc = new TaxonomyTermAssociation();
334  $assoc->delete("WHERE class='$class' AND taxonomy_id={$this->taxonomy->taxonomy_id} AND id=$pk");
335 
336  if (isset($_POST[$this->field]))
337  {
338  foreach($_POST[$this->field] as $term_id => $dummy)
339  {
340  $assoc = new TaxonomyTermAssociation();
341  $assoc->class = $class;
342  $assoc->taxonomy_id = $this->taxonomy->taxonomy_id;
343  $assoc->id = $pk;
344  $assoc->term_id = $term_id;
345  $assoc->save();
346  }
347  }
348  }
$_POST["owner_id"]
Definition: blog_form.inc:54
$dummy
Definition: data_import.inc:7
$openData field
$term_id
Definition: blog.inc:40

◆ preProcess()

TaxonomyTermFieldRenderer::preProcess (   $field = "")

Definition at line 305 of file taxonomy_term_field_renderer.inc.

306  {
307  if (count($this->options) == 0) return;
308 
309  $obj = $this->parent->data;
310  if ($obj->hasField($this->field) && is_array($_POST[$this->field]))
311  {
312  // If overriding a field, unpack the terms
313  $terms = array();
314  foreach($_POST[$this->field] as $term_id => $dummy)
315  {
316  $terms[] = new TaxonomyTerm($term_id);
317  }
318 
319  $obj->set($this->field, formatItems($terms, "{term}", ","));
320  }
321 
322  return true;
323  }

◆ renderCheckboxes()

TaxonomyTermFieldRenderer::renderCheckboxes (   $field,
  $items,
  $selected,
  $mode = null 
)

Definition at line 209 of file taxonomy_term_field_renderer.inc.

210  {
211  foreach($items as $item)
212  {
213  $p = $item->term_id;
214 
215  $name = $mode ? "{$field}:{$mode}" : $field;
216  $val = $mode ? $p : "1";
217 
218  echo "<label for='checkbox_{$field}_$p'><input type='checkbox' class='checkbox' name='{$name}[$p]' id='checkbox_{$field}_$p' value='{$val}'";
219  if (array_key_exists($p, $selected))
220  {
221  echo " checked";
222  }
223  echo ">";
224  echo $item->term."</label>";
225  }
226  }
$name
Definition: upload.inc:54
$mode

◆ renderField()

TaxonomyTermFieldRenderer::renderField (   $field = "")

Definition at line 162 of file taxonomy_term_field_renderer.inc.

163  {
164  if (count($this->options) == 0) return;
165 
167 
168  $this->_startField($field);
169 
170  $obj = $this->parent->data;
171 
172  if ($this->showSelectAll)
173  {
174  echo "<a href='#' onclick='return {$this->parent->id}_{$field}_toggleSelectAll(this);'>Select All</a><br/>";
175  }
176  if ($this->width && $this->height)
177  {
178  $width = is_numeric($this->width) ? "{$this->width}px" : $this->width;
179  $height = is_numeric($this->height) ? "{$this->height}px" : $this->height;
180  $padding = ($width == "auto") ? "padding-right: 20px; overflow-x: hidden" : "";
181 
182  $resizable = ($this->resizable && !$this->dropdown) ? " resizable": "";
183  $dropdown = $this->dropdown ? " multi_select_dropdown_list" : "";
184  echo "<div id='{$this->parent->id}_{$field}_container' class='scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height};overflow: auto; $padding'>\n";
185  }
186 
187  $countOptions = count($this->options);
188 
189  $class = get_class($obj);
190  $pk = $obj->get($obj->getPrimaryKey());
191 
192  $selected = IndexedQuery::create(TaxonomyTermAssociation, "WHERE taxonomy_id=:id AND class=:class AND id=:pk", "term_id")
193  ->bind(":id", $this->taxonomy->taxonomy_id, ":class", $class, ":pk", $pk)
194  ->execute();
195 
196  $this->renderCheckBoxes($field, $this->options, $selected);
197 
198  if ($this->width && $this->height)
199  {
200  echo "</div>\n";
201  }
202 
203  // Save this count to loop through checkboxes on required validation
204  echo "<input type=\"hidden\" name=\"count_{$field}\" value=\"$countOptions\">";
205 
206  $this->_endField($field);
207  }
$columnSelect dropdown
$helpTree width
Definition: tree.inc:45
$height
Definition: cover.inc:38
$width
Definition: cover.inc:37
$desc height
Definition: event_edit.inc:64

◆ renderReadOnly()

TaxonomyTermFieldRenderer::renderReadOnly (   $field = "")

Don't display the taxonomy if nothing selected

Definition at line 228 of file taxonomy_term_field_renderer.inc.

229  {
230  if (count($this->options) == 0) return;
231 
233 
234  $obj = $this->parent->data;
235 
236  $class = get_class($obj);
237  $pk = $obj->get($obj->getPrimaryKey());
238 
239  $selected = IndexedQuery::create(TaxonomyTermAssociation, "WHERE taxonomy_id=:id AND class=:class AND id=:pk", "term_id")
240  ->bind(":id", $this->taxonomy->taxonomy_id, ":class", $class, ":pk", $pk)
241  ->execute();
242 
243  foreach($this->options as $option)
244  {
245  $p = $option->term_id;
246 
247  if (array_key_exists($p, $selected))
248  {
249  $answers[] = $option->term;
250  }
251  }
252 
256  if(count($answers))
257  {
258  $this->_startField($field);
260  $this->_endField($field);
261  }
262  }
$answers

◆ renderScript()

TaxonomyTermFieldRenderer::renderScript (   $field)

Definition at line 94 of file taxonomy_term_field_renderer.inc.

95  {
96  if ($this->showSelectAll)
97  {
98 ?>
99 <script type="text/javascript">
100 
101 function <?echo $this->parent->id?>_<?echo $this->field ?>_toggleSelectAll(link)
102 {
103  link = document.id(link);
104 
105  var value = (link.innerHTML == "Select All");
106 
107  var container = document.id('<?echo $this->parent->id?>_<?echo $this->field?>_container');
108 
109  container.getElements("input[type=checkbox]").each(function(cbox)
110  {
111  cbox.set('checked', value);
112  });
113 
114  link.innerHTML = (value) ? "Deselect All" : "Select All";
115  if (container.multiSelect) container.multiSelect.selectionChanged();
116  return false;
117 }
118 
119 </script>
120 <?
121  }
122 
123  if ($this->dropdown)
124  {
125 ?>
126 <script type='text/javascript'>
127 window.addEvent('domready', function()
128 {
129  new MultiSelect('<?echo $this->parent->id?>_<?echo $this->field?>_container', {maxWidth: '<?echo $this->dropdownMaxWidth?>', message: '<?echo jsSafe($this->dropdownMessage)?>'});
130 });
131 </script>
132 <?
133  }
134  }
$email message

◆ renderSearchField()

TaxonomyTermFieldRenderer::renderSearchField (   $field,
  $mode 
)

Definition at line 265 of file taxonomy_term_field_renderer.inc.

266  {
267  $this->_startField($field);
268 
269 
270  $obj = $this->parent->data;
271 
272  if ($this->width && $this->height)
273  {
274  $width = is_numeric($this->width) ? "{$this->width}px" : $this->width;
275  $height = is_numeric($this->height) ? "{$this->height}px" : $this->height;
276  $padding = ($width == "auto") ? "padding-right: 20px; overflow-x: hidden" : "";
277 
278  $resizable = ($this->resizable && !$this->dropdown) ? " resizable": "";
279  $dropdown = $this->dropdown ? " multi_select_dropdown_list" : "";
280  echo "<div id='{$this->parent->id}_{$field}_container' class='scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height};overflow: auto; $padding'>\n";
281  }
282 
283  $countOptions = count($this->options);
284 
285  $class = get_class($obj);
286  $pk = $obj->get($obj->getPrimaryKey());
287 
288  $selected = IndexedQuery::create(TaxonomyTermAssociation, "WHERE taxonomy_id=:id AND class=:class AND id=:pk", "term_id")
289  ->bind(":id", $this->taxonomy->taxonomy_id, ":class", $class, ":pk", $pk)
290  ->execute();
291 
292  $this->renderCheckBoxes($field, $this->options, $selected, $mode);
293 
294  if ($this->width && $this->height)
295  {
296  echo "</div>\n";
297  }
298 
299  // Save this count to loop through checkboxes on required validation
300  echo "<input type=\"hidden\" name=\"count_{$field}\" value=\"$countOptions\">";
301 
302  $this->_endField($field);
303  }

◆ renderSearchScript()

TaxonomyTermFieldRenderer::renderSearchScript (   $field,
  $mode 
)

Definition at line 136 of file taxonomy_term_field_renderer.inc.

137  {
138 
139  if ($this->dropdown)
140  {
141  ?>
142  <script type='text/javascript'>
143  window.addEvent('domready', function()
144  {
145  new MultiSelect('<?echo $this->parent->id?>_<?echo $this->field?>_container', {maxWidth: '<?echo $this->dropdownMaxWidth?>', message: '<?echo jsSafe($this->dropdownMessage)?>'});
146  });
147  </script>
148  <?
149  }
150  }

◆ setSize()

TaxonomyTermFieldRenderer::setSize (   $width,
  $height 
)

Definition at line 82 of file taxonomy_term_field_renderer.inc.

83  {
84  $this->width = $width;
85  $this->height = $height;
86  }

◆ TaxonomyTermFieldRenderer()

TaxonomyTermFieldRenderer::TaxonomyTermFieldRenderer ( $form,
  $taxonomy 
)

Definition at line 58 of file taxonomy_term_field_renderer.inc.

59  {
60  $this->taxonomy = $taxonomy;
61  $this->field = $taxonomy->identifier;
62  $this->label = $taxonomy->taxonomy_name;
63  $this->options = $taxonomy->Terms("ORDER BY sort_order, term");
64  $this->dropdown = true;
65 
66  $this->showSelectAll = true;
67 
68  $this->FieldRenderer($form);
69 
70  // JDG 7/31/2011 - allow override
71  if ($form->data->hasField($this->field))
72  {
73  $form->override($this->field, $label, $this);
74  }
75  else
76  {
77  $form->add($this, $this->field);
78  $form->overrides[$this->field]['label'] = $label;
79  }
80  }
$form

Member Data Documentation

◆ $dropdown

TaxonomyTermFieldRenderer::$dropdown

Definition at line 49 of file taxonomy_term_field_renderer.inc.

◆ $dropdownMaxWidth

TaxonomyTermFieldRenderer::$dropdownMaxWidth = "340px"

Definition at line 50 of file taxonomy_term_field_renderer.inc.

◆ $dropdownMessage

TaxonomyTermFieldRenderer::$dropdownMessage = "Click to Select Terms"

Definition at line 51 of file taxonomy_term_field_renderer.inc.

◆ $field

TaxonomyTermFieldRenderer::$field

Definition at line 46 of file taxonomy_term_field_renderer.inc.

◆ $label

TaxonomyTermFieldRenderer::$label

Definition at line 47 of file taxonomy_term_field_renderer.inc.

◆ $options

TaxonomyTermFieldRenderer::$options

Definition at line 52 of file taxonomy_term_field_renderer.inc.

◆ $readOnlyTermSeparator

TaxonomyTermFieldRenderer::$readOnlyTermSeparator = "<br>"
static

Definition at line 56 of file taxonomy_term_field_renderer.inc.

◆ $resizable

TaxonomyTermFieldRenderer::$resizable = true

Definition at line 54 of file taxonomy_term_field_renderer.inc.

◆ $showSelectAll

TaxonomyTermFieldRenderer::$showSelectAll

Definition at line 53 of file taxonomy_term_field_renderer.inc.

◆ $taxonomy

TaxonomyTermFieldRenderer::$taxonomy

Definition at line 48 of file taxonomy_term_field_renderer.inc.


The documentation for this class was generated from the following file: