Framework  3.9
status_tree.inc
Go to the documentation of this file.
1 <?php
5 /**************************************************************
6 
7  Copyright (c) 2010 Sonjara, Inc
8 
9  Permission is hereby granted, free of charge, to any person
10  obtaining a copy of this software and associated documentation
11  files (the "Software"), to deal in the Software without
12  restriction, including without limitation the rights to use,
13  copy, modify, merge, publish, distribute, sublicense, and/or sell
14  copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following
16  conditions:
17 
18  The above copyright notice and this permission notice shall be
19  included in all copies or substantial portions of the Software.
20 
21  Except as contained in this notice, the name(s) of the above
22  copyright holders shall not be used in advertising or otherwise
23  to promote the sale, use or other dealings in this Software
24  without prior written authorization.
25 
26  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
28  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
30  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
31  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33  OTHER DEALINGS IN THE SOFTWARE.
34 
35 *****************************************************************/
36 
37 /**************************************************************
38  *
39  * Title: status_tree.inc
40  *
41  * Description: Classes for status trees and status
42  * blocks for item list pages.
43  *
44  * author: Janice Gallant for Sonjara, Inc.
45  *
46  * date: 5/17/10
47  *
48  ***************************************************************/
49 
50 Fakoli::usingFeature("tree");
51 
52 /*
53  * Generic class for presenting items in status trees
54  *
55  * $items: groupedQuery results of items to display in status trees
56  * $statusCategories: array e.g., array(In Progress => 1, In Review => 2, etc)
57  * $fragmentUrl: the url of the status block fragment, e.g., "/portfolio/students/student_work_fragment.php/";
58  *
59  * The items dataitem class must have function getTitle to get the title to
60  * display in the status tree line
61  *
62  * The noneText should be set in the calling script. For example, "There are not
63  * Crop It! activities in your portfolio."
64  */
66 {
67  var $items;
68  var $trees;
70  var $emptyMessage = ""; // You do not have any...
71  var $width = 500;
72  var $statusBlockView; // class that inherits from StatusBlockView and displays the status block contents
73  var $statusBlockHandler; // if not using callback class above, set to call action handler for view
74 
75  function StatusTrees($items, $statusCategories, $statusBlock)
76  {
77  $this->items = $items;
78  $this->statusCategories = $statusCategories;
79  $this->statusBlockView = $statusBlockView;
80  if(preg_match('/\//', $statusBlock))
81  $this->statusBlockHandler = $statusBlock;
82  else
83  $this->statusBlockView = $statusBlock;
84  }
85 
86  function buildStatusTrees()
87  {
88  if(count($this->items) == 0) return;
89 
90  $trees = array();
91 
92  foreach($this->statusCategories as $statusTitle => $status)
93  {
94  if (array_key_exists($status, $this->items))
95  {
96  $tree = new TreeControl("statusTree$status", "", "tree", false, $this->width);
97  $tree->height = "";
98  $tree->indent = "0px";
99 
100  $category = $this->items[$status];
101 
102  foreach($category as $item)
103  {
104  $pkName = $item->getPrimaryKey();
105 
106  $node = $this->getNode($item, $pkName);
107 
108  if($this->statusBlockView)
109  {
110  $statusBlockView = new $this->statusBlockView($item);
111  $block = $statusBlockView->getViewHTML();
112  }
113 
114  $subNode = new TreeNode("block_{$item->$pkName}",
115  $block, "",
116  false);
117  $subNode->leafStyle = "";
118  if($this->statusBlockHandler)
119  {
120  $subNode->onDemand = "{$this->statusBlockHandler}?$pkName={$item->$pkName}";
121  }
122  $node->add($subNode);
123 
124  $tree->add($node);
125  }
126 
127  $trees[$status] = $tree;
128  }
129  }
130  return $trees;
131  }
132 
133  /*
134  * Enables inheriting classes to override this function and set their own title
135  */
136  function getNode($item, $pkName)
137  {
138  $node = new TreeNode("status_{$item->$pkName}", $item->getTitle(),
139  null, false, "tree_list_closed", "tree_list_open");
140  $node->leafStyle = "tree_list_open";
141 
142  return $node;
143  }
144 
145 
146  function writeScript()
147  {
148 
149  }
150 
151 
152  function drawView()
153  {
154  $this->trees = $this->buildStatusTrees();
155  echo "<br/>\n";
156 
157  if (count($this->items) > 0)
158  {
159  foreach($this->statusCategories as $statusTitle => $status)
160  {
161  if (array_key_exists($status, $this->items))
162  {
163  echo "<h3>$statusTitle</h3>\n";
164  $this->trees[$status]->writeHTML();
165  }
166  }
167  }
168  else
169  {
170  echo "<br/><em>$this->emptyMessage</em><br/>";
171  }
172 
173  }
174 }
175 
176 
177 /*
178  * StatusBlockView
179  *
180  * Description: Handles display of assignment in the status fragments.
181  *
182  */
183 abstract class StatusBlockView
184 {
185  var $item;
192 
194  {
195  $this->item = $item;
196  }
197 
198  // formats the layout for inheriting class
199  function drawView()
200  {
201  // begin status block
202  echo "<div class=\"status_block\">";
203 
204  echo "<div id=\"col2\"><br/>";
205 
206  $this->drawLinks();
207 
208  echo "</div>";
209 
210  $this->writeSummary();
211 
212  echo "</div>";
213  }
214 
215  /* When status fragment is not loaded on demand */
216  function getViewHTML()
217  {
218  global $user;
219 
220  $html = "<div class=\"status_block\">";
221 
222  $html .= "<div id=\"col2\" style=\"float: right\"><br/>\n";
223  $html .= $this->getLinksHTML();
224  $html .= "</div>\n<br/>\n";
225  $html .= $this->getSummaryHTML();
226  $html .= "</div>\n";
227 
228  return $html;
229  }
230 
231  function writeSummary()
232  {
233  // handled by inheriting class
234  }
235 
236  function getSummaryHTML()
237  {
238  // handled by inheriting class
239  }
240 
241  function drawLinks()
242  {
243  // handled by inheriting class - buttons linking to
244  // submit, edit, view, etc.
245  }
246 
247  function getLinksHTML()
248  {
249  // handled by inheriting class - buttons linking to
250  // submit, edit, view, etc.
251  }
252 
253  // generic button
254  function writeButton($url, $icon, $text, $newWindow = false, $class = "")
255  {
256  echo $this->getButtonHTML($url, $icon, $text, $newWindow, $class);
257  }
258 
259  function getButtonHTML($url, $icon, $text, $newWindow = false, $class = "")
260  {
261  if($newWindow)
262  $target = "target='_blank'";
263 
264  $class = (!$class) ? "button" : $class;
265  $img = ($icon) ? "<img src='$icon' style='border: none'>" : "";
266 
267  $html = "<p><a $target class=\"$class\" href=\"$url\">
268  $img&nbsp;$text&nbsp;</a></p>";
269 
270  return $html;
271  }
272 
273  function writeViewButton()
274  {
275  $this->writeButton($this->item->getViewUrl(), $this->iconView, "View this {$this->activityName}", false);
276  }
277 
278  function writeEditButton()
279  {
280  $this->writeButton($this->item->getEditUrl(), $this->iconEdit, "Edit this {$this->activityName}", false);
281  }
282 
283  function writeDeleteButton($class = "")
284  {
285  echo $this->getDeleteButtonHTML($class);
286  }
287 
289  {
290  $url = $this->item->getViewUrl();
291 
292  echo "<a class=\"button\" href=\"$url\" onclick=\"popup('$url', '_blank', 750, 600); return false;\">
293  <img src=\"$this->iconView\" alt=\"View\"/>&nbsp;View this $this->activityName&nbsp;</a><br/>";
294  }
295 
296 
297  function getDeleteButton($class = "")
298  {
299  $class = (!$class) ? "button" : $class;
300  $icon = ($this->iconDelete) ? "<img src=\"$this->iconDelete\"/>\n" : "";
301 
302  $message = "Are you sure you want to delete this {$this->activityName}?";
303 
304  $html = "<p><a href=\"$this->deleteUrl\" class=\"$class\"
305  onclick=\"return confirm('$message');\">
306  $icon&nbsp;Delete this $this->activityName</a></p>";
307 
308  return $html;
309 
310  }
311 
312  function getEditButton($class = "", $newWindow = false)
313  {
314  $html = $this->getButtonHTML($this->item->getEditUrl(), $this->iconEdit, "Edit this {$this->activityName}", $newWindow);
315 
316  return $html;
317  }
318 
319  function getViewButton($class = "")
320  {
321  $html = $this->getButtonHTML($this->item->getViewUrl(), $this->iconView, "View this {$this->activityName}", $newWindow);
322 
323  return $html;
324 
325  }
326 
327 } // end class StatusBlockView
328 
329 ?>
getButtonHTML($url, $icon, $text, $newWindow=false, $class="")
getViewButton($class="")
StatusBlockView($item)
getDeleteButton($class="")
writeDeleteButton($class="")
writeButton($url, $icon, $text, $newWindow=false, $class="")
getEditButton($class="", $newWindow=false)
StatusTrees($items, $statusCategories, $statusBlock)
Definition: status_tree.inc:75
getNode($item, $pkName)
The TreeControl provides a class that can be used to generate dynamic tree controls for use in PHP fo...
Definition: tree.inc:322
TreeNode represents a node in the tree.
Definition: tree.inc:62