CMS  Version 3.9
context_help_list.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 /*
35  *
36  * Title: context_help_list.php
37  *
38  * Description: Displays a list of the features for which
39  * context help can be written.
40  *
41  * 1) Get all the valid files from the datamodel directory
42  *
43  * 2) Read each file line by line to gather the names of
44  * each class. Automatically eliminate classes we know are
45  * irrelevant for help: join classes and status forms. Check
46  * for a comment on the class declaration line, "// no help"
47  * and don't include those classes
48  *
49  * 3) Given an array of class names, create an instance of
50  * each class to get the following:
51  *
52  * a) the fields array for the list of fields for which
53  * help can be provided
54  *
55  * b) the "additionalFields" array which provides the list
56  * of supplemental or pseudo fields associated with a
57  * feature/script for which help can be created.
58  *
59  * c) the prettified class name which we want to display
60  * to the user when presenting classes for which help
61  * can be defined
62  *
63  * 4) Retrieve from the db, all the defined help, grouped
64  * by class name. Match the classes for which help is
65  * available with the classes array. If help is found,
66  * match the help field with the field in the array for
67  * that class.
68  *
69  * 5) Display a table with the list of classes, fields
70  * in the class and a checkbox to indicate if a help
71  * record exists for that class/field. The table
72  * enables the user to click on a class/field to
73  * edit help or create a help record.
74  *
75  * author: Janice Gallant for Sonjara, Inc.
76  *
77  * date: 5/09
78  *
79  */
80 
81 Fakoli::using("context_help");
82 Fakoli::usingFeature("auto_form", "grouped_data_view");
83 
84 $title = "Context-Sensitive Help";
85 
86 $menu_item = "Context Help";
87 
88 $classes = array();
89 $classes = ComponentManager::fireEvent("EnumerateContextHelpClasses", $classes);
90 
91 $savedHelp = groupedQuery(ContextHelp, "", "class_name");
92 $contextHelps = array();
93 
94 /*
95  * Build an array of context help objects grouped by class.
96  * If we have one saved, then use that; if not, create an
97  * new one and set the field and class name but don't save it.
98  * Help items are only saved when the user enters help on the form.
99  */
100 if(count($classes) > 0)
101 {
102  foreach($classes as $class)
103  {
104  $classObj = new $class();
105  $prettyClassName = $classObj->prettifyClassName();
106  $fields = $classObj->getFields();
107  $savedFields = $savedHelp[$class];
108  if(count($savedFields) == 0) $savedFields = array();
109  if(is_array($classObj->additionalFields))
110  $fields = array_merge($fields, array_combine($classObj->additionalFields, $classObj->additionalFields));
111 
112  $savedFields = reindexList($savedFields, "field");
113 
114  if(count($fields) > 0)
115  {
116  foreach($fields as $fieldName => $fieldType)
117  {
118  if(!array_key_exists($fieldName, $savedFields))
119  {
120  $contextHelp = new ContextHelp();
121  $contextHelp->class_name = $class;
122  $contextHelp->field = $fieldName;
123  }
124  else
125  {
126  $contextHelp = $savedFields[$fieldName];
127  }
128 
129  $contextHelp->pretty_class_name = $prettyClassName;
130  array_push($contextHelps, $contextHelp);
131  }
132  }
133  }
134 }
135 
136 $contextHelps = sortItems($contextHelps, "compareClasses");
137 $groupedHelps = regroupList($contextHelps, "pretty_class_name");
138 
139 $table = new GroupedDataListView($groupedHelps, "ContextHelp");
140 $table->column("Field", formatContextHelpFormLink)
141  ->column("Title", "{title}", true)
142  ->column("Help", "{help}", true)
143  ;
144 
145 $table->mode = "tree";
146 $table->cssStyle = "width: 90%";
147 
148 foreach(array_keys($groupedHelps) as $class_name)
149 {
150  $table->group($class_name, $class_name);
151 }
152 
153 $script = $table->writeScript();
154 
155 ?><p>Using the list below you can provide content-sensitive help and publication criteria
156 popup text for use on forms throughout the site.</p>
157 <?
158 $table->drawView();
159 
160 function formatContextHelpFormLink($contextHelp)
161 {
162  if($contextHelp->help_id)
163  $param = "help_id={$contextHelp->help_id}";
164  else
165  $param = "class_name={$contextHelp->class_name}&field={$contextHelp->field}";
166  $html = "<a href=\"/admin/context_help_form?$param\">{$contextHelp->field}</a>\n";
167 
168  return $html;
169 }
170 
171 /*
172  * compare
173  *
174  * Orders items by class name, case insensitive
175  *
176  * @param itemA 2-D array containing subject string
177  * @param itemB 2-D array containing subject string
178  */
179 function compareClasses($itemA, $itemB)
180 {
181  if (strcasecmp($itemA->pretty_class_name, $itemB->pretty_class_name) == 0)
182  return 1;
183  elseif (strcasecmp($itemA->pretty_class_name, $itemB->pretty_class_name) < 0)
184  return -1;
185  else
186  return 1;
187 }
188 
189 function sortItems($items, $compare)
190 {
191  if(is_array($items))
192  {
193  usort($items, $compare);
194  }
195  return $items;
196 }
197 
198 ?>
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
compareClasses($itemA, $itemB)
sortItems($items, $compare)
formatContextHelpFormLink($contextHelp)
foreach(array_keys($groupedHelps) as $class_name) $script
$contextHelps