CMS  Version 3.9
context_help.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 {
42  {
43  }
44 
45  function export()
46  {
47  return SerializationManager::serialize(ContextHelp, "ORDER BY help_id");
48  }
49 
50  function import($doc, $tx)
51  {
53  }
54 }
55 
57 {
58  static $_instance;
59 
60  var $classes;
62 
63  static function getInstance()
64  {
66  {
68  }
69 
71  }
72 
73  static function setDefaults()
74  {
75  Settings::setDefaultValue("context_help", "context_help_label", "(?)", String, "Text to display for context help links (HTML is ok)");
76  Settings::setDefaultValue("context_help", "criteria_help_label", "(criteria)", String, "Text to display for criteria help links (HTML is ok)");
77  Settings::setDefaultValue("context_help", "show_title", true, Boolean, "Show the title heading in context help popups");
78  }
79 
80  function ContextHelpManager()
81  {
82  $this->classes = array();
83  $this->nonmatches = array();
84  $this->contextHelpLabel = Settings::getValue("context_help", "context_help_label");
85  $this->criteriaHelpLabel = Settings::getValue("context_help", "criterial_help_label");
86  $this->showTitle = Settings::getValue("context_help", "show_title");
87  }
88 
89  function getHelp($form, $field)
90  {
91  $obj = $form->data;
92  $records = $this->getContextHelpRecords($obj);
93  if (!$records) return null;
94 
95  if (array_key_exists($field, $records))
96  {
97  return $records[$field]->help;
98  }
99 
100  return null;
101  }
102 
104  {
105  $obj = $form->data;
106  $records = $this->getContextHelpRecords($obj);
107  if (!$records) return null;
108 
109  if (array_key_exists($field, $records))
110  {
111  return $records[$field]->criteria;
112  }
113 
114  return null;
115  }
116 
117  function getTitle($form, $field)
118  {
119  $title = null;
120  $obj = $form->data;
121  $records = $this->getContextHelpRecords($obj);
122  if (!$records) return null;
123 
124  if (array_key_exists($field, $records))
125  {
126  $title = $records[$field]->title;
127  }
128 
129  if (!$title)
130  {
131  $title = $form->prettifyFieldName($field);
132  }
133 
134  return $title;
135  }
136 
138  {
139  $cl = $obj->contextHelpProxy ? $obj->contextHelpProxy : get_class($obj);
140 
141  if ($this->nonmatches[$cl]) return null;
142 
143  if ($this->classes[$cl])
144  {
145  return $this->classes[$cl];
146  }
147 
148  $records = indexedQuery(ContextHelp, "WHERE class_name='$cl'", "field");
149  if ($records)
150  {
151  $this->classes[$cl] = $records;
152  }
153  else
154  {
155  $this->nonmatches[$cl] = true;
156  }
157  return $records;
158  }
159 
161  {
162  $help = $this->getHelp($form, $field);
163  $criteria = $this->getCriteria($form, $field);
164  $title = $this->getTitle($form, $field);
165 
166  $links = "";
167  $text = "";
168 
169  if ($help)
170  {
171  $links .= "<a class=\"context_link\" href=\"javascript:toggleContextHelp('help-{$field}');\" onmouseover=\"showContextHelp('help-{$field}');\" onmouseout=\"hideContextHelp('help-{$field}');\">{$this->contextHelpLabel}</a>&nbsp;";
172  $text .= "<div id=\"help-$field\" class=\"contexthelp\">\n";
173  if ($this->showTitle)
174  {
175  $text .= "<p id=\"heading-$field\">$title Help</p>\n";
176  }
177  $text .= $help;
178  $text .= "</div>\n";
179  }
180 
181  if ($criteria)
182  {
183  $links .= "<a class=\"context_link\" href=\"javascript:toggleContextHelp('criteria-{$field}');\" onmouseover=\"showContextHelp('criteria-{$field}');\" onmouseout=\"hideContextHelp('criteria-{$field}');\">{$this->criteriaHelpLabel}</a>";
184  $text .= "<div id=\"criteria-$field\" class=\"contexthelp\">\n";
185  if ($this->showTitle)
186  {
187  $text .= "<h2 id=\"heading-$field\">$title Criteria</h2>\n";
188  }
189  $text .= $criteria;
190  $text .= "</div>\n";
191  }
192 
193  return "{$links}\n{$text}";
194  }
195 
196  static function upgradeComponent($version)
197  {
199  $mgr->upgrade($version);
200  }
201 
202  static function onInitialize()
203  {
204  global $auto_form_defaults;
205 
206  $auto_form_defaults["onFormatLabel"] = "addContextHelp";
207  }
208 
210  {
211  SerializationManager::registerHandler("context_help", "Context Help", new ContextHelpSerializationHandler());
212  return true;
213  }
214 }
215 
216 function addContextHelp($form, $field, $label)
217 {
218  $contextHelpMgr = ContextHelpManager::getInstance();
219  $label .= "&nbsp;".$contextHelpMgr->formatLinks($form, $field);
220 
221  return $label;
222 }?>
$form
static registerSerializationHandler()
formatLinks($form, $field)
static upgradeComponent($version)
getTitle($form, $field)
getCriteria($form, $field)
getHelp($form, $field)
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174
addContextHelp($form, $field, $label)