Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cGuiBackendHelpbox
  • cGuiFileOverview
  • cGuiFoldingRow
  • cGuiList
  • cGuiMenu
  • cGuiNavigation
  • cGuiNotification
  • cGuiObjectPager
  • cGuiPage
  • cGuiScrollList
  • cGuiSourceEditor
  • cGuiTableForm
  • cGuiTree
  • cPager
  • cTemplate
  • cTree
  • cTreeItem
  • NoteLink
  • NoteList
  • NoteListItem
  • NoteView
  • TODOLink
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the tree GUI class.
  5:  *
  6:  * @package          Core
  7:  * @subpackage       GUI
  8:  *
  9:  * @author           Mischa Holz
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * cGuiTree is a visual representation of a cTree. It supports folding,
 20:  * optional gridline marks and item icons.
 21:  *
 22:  * @package    Core
 23:  * @subpackage GUI
 24:  */
 25: class cGuiTree extends cTree {
 26: 
 27:     /**
 28:      *
 29:      * @var string
 30:      */
 31:     const TREEVIEW_GRIDLINE_SOLID = 'solid';
 32: 
 33:     /**
 34:      *
 35:      * @var string
 36:      */
 37:     const TREEVIEW_GRIDLINE_DASHED = 'dashed';
 38: 
 39:     /**
 40:      *
 41:      * @var string
 42:      */
 43:     const TREEVIEW_GRIDLINE_DOTTED = 'dotted';
 44: 
 45:     /**
 46:      *
 47:      * @var string
 48:      */
 49:     const TREEVIEW_GRIDLINE_NONE = 'none';
 50: 
 51:     /**
 52:      *
 53:      * @var string
 54:      * @deprecated [2015-05-21]
 55:      *    This constant is no longer supported (no replacement)
 56:      */
 57:     const TREEVIEW_BACKGROUND_NONE = 'none';
 58: 
 59:     /**
 60:      *
 61:      * @var string
 62:      * @deprecated [2015-05-21]
 63:      *         This constant is no longer supported (no replacement)
 64:      */
 65:     const TREEVIEW_BACKGROUND_SHADED = 'shaded';
 66: 
 67:     /**
 68:      *
 69:      * @var string
 70:      * @deprecated [2015-05-21]
 71:      *         This constant is no longer supported (no replacement)
 72:      */
 73:     const TREEVIEW_MOUSEOVER_NONE = 'none';
 74: 
 75:     /**
 76:      *
 77:      * @var string
 78:      * @deprecated [2015-05-21]
 79:      *         This constant is no longer supported (no replacement)
 80:      */
 81:     const TREEVIEW_MOUSEOVER_MARK = 'mark';
 82: 
 83:     /**
 84:      * @var cApiUser
 85:      */
 86:     protected $_user;
 87: 
 88:     /**
 89:      * @var string
 90:      */
 91:     protected $_uuid;
 92: 
 93:     /**
 94:      * @var string
 95:      */
 96:     protected $_gridlineMode;
 97: 
 98:     /**
 99:      * @var string
100:      */
101:     private $_baseLink;
102: 
103:     /**
104:      * Constructor to create an instance of this class.
105:      *
106:      * @param string $uuid
107:      * @param false|string $treename [optional]
108:      */
109:     public function __construct($uuid, $treename = false) {
110:         global $cfg, $auth;
111: 
112:         parent::__construct();
113: 
114:         $this->_uuid = $uuid;
115:         //$this->setGridlineMode(self::TREEVIEW_GRIDLINE_DOTTED);
116: 
117:         if ($treename != false) {
118:             $this->setTreeName($treename);
119:         }
120: 
121:         $this->_user = new cApiUser($auth->auth["uid"]);
122:     }
123: 
124:     /**
125:      * @throws cDbException
126:      * @throws cException
127:      * @throws cInvalidArgumentException
128:      */
129:     public function processParameters() {
130:         if (($items = $this->_user->getUserProperty("expandstate", $this->_uuid)) !== false) {
131:             $list = unserialize($items);
132: 
133:             foreach ($list as $litem) {
134:                 $this->setCollapsed($litem);
135:             }
136:         }
137: 
138:         if (!empty($this->_name)) {
139:             $treename = $this->_name . "_";
140:         }
141: 
142:         if (array_key_exists($treename . "collapse", $_GET)) {
143:             $this->setCollapsed($_GET[$treename . "collapse"]);
144:         }
145: 
146:         if (array_key_exists($treename . "expand", $_GET)) {
147:             $this->setExpanded($_GET[$treename . "expand"]);
148:         }
149: 
150:         $xlist = array(); // Define variable before using it by reference...
151:         $this->getCollapsedList($xlist);
152:         $slist = serialize($xlist);
153: 
154:         $this->_user->setUserProperty("expandstate", $this->_uuid, $slist);
155:     }
156: 
157:     /**
158:      * @param int $mode
159:      *         Sets the gridline mode to one of the following values:
160:      *         - cGuiTree::TREEVIEW_GRIDLINE_SOLID
161:      *         - cGuiTree::TREEVIEW_GRIDLINE_DASHED
162:      *         - cGuiTree::TREEVIEW_GRIDLINE_DOTTED
163:      *         - cGuiTree::TREEVIEW_GRIDLINE_NONE
164:      */
165:     public function setGridlineMode($mode) {
166:         $this->_gridlineMode = $mode;
167:     }
168: 
169:     /**
170:      *
171:      * @param unknown_type $mode
172:      * @deprecated [2015-05-21]
173:      *         This method is no longer supported (no replacement)
174:      */
175:     public function setBackgroundMode($mode) {
176:         cDeprecated('This method is deprecated and is not needed any longer');
177:         $this->_backgroundMode = $mode;
178:     }
179: 
180:     /**
181:      *
182:      * @param unknown_type $mode
183:      * @deprecated [2015-05-21]
184:      *         This method is no longer supported (no replacement)
185:      */
186:     public function setMouseoverMode($mode) {
187:         cDeprecated('This method is deprecated and is not needed any longer');
188:         $this->_mouseoverMode = $mode;
189:     }
190: 
191:     /**
192:      *
193:      * @param unknown_type $colors
194:      * @deprecated [2015-05-21]
195:      *         This method is no longer supported (no replacement)
196:      */
197:     public function setBackgroundColors($colors) {
198:         cDeprecated('This method is deprecated and is not needed any longer');
199:         $this->_backgroundColors = $colors;
200:     }
201: 
202:     /**
203:      *
204:      * @param bool $with_root [optional]
205:      * @return string
206:      */
207:     public function render($with_root = true) {
208: 
209:         /* @var $objects cTreeItem[] */
210:         $objects = $this->flatTraverse(0);
211: 
212:         if ($with_root == false) {
213:             unset($objects[0]);
214:         }
215: 
216:         $img = new cHTMLImage;
217:         $r_table = new cHTMLTable;
218:         $r_row = new cHTMLTableRow;
219:         $r_leftcell = new cHTMLTableData;
220:         $r_rightcell = new cHTMLTableData;
221:         $r_actioncell = new cHTMLTableData;
222: 
223:         $img_spacer = new cHTMLImage;
224:         $img_spacer->updateAttributes(array('width' => '16', 'height' => '20'));
225:         $img_spacer->setAlt("");
226:         $img_spacer->setSrc("images/spacer.gif");
227:         $img_spacer->advanceID();
228: 
229:         $r_table->setCellPadding(0);
230:         $r_table->setCellSpacing(0);
231:         $r_table->setWidth("100%");
232:         $r_rightcell->appendStyleDefinition("padding-left", "3px");
233:         $r_rightcell->setVerticalAlignment("middle");
234:         $r_leftcell->setVerticalAlignment("middle");
235:         $r_leftcell->updateAttributes(array("nowrap" => "nowrap"));
236:         $r_rightcell->updateAttributes(array("nowrap" => "nowrap"));
237:         $r_actioncell->updateAttributes(array("nowrap" => "nowrap"));
238:         $r_leftcell->setWidth("1%");
239:         $r_rightcell->setWidth("100%");
240:         $r_actioncell->setAlignment("right");
241:         $r_actioncell->setWidth("1%");
242: 
243:         if (!is_object($this->_baseLink)) {
244:             $this->_baseLink = new cHTMLLink();
245:         }
246: 
247:         $out = $result = '';
248: 
249:         $lastitem = array();
250:         foreach ($objects as $key => $object) {
251:             $img->setAlt("");
252:             $r_table->advanceID();
253:             $r_rightcell->advanceID();
254:             $r_leftcell->advanceID();
255:             $r_row->advanceID();
256:             $r_actioncell->advanceID();
257: 
258:             for ($level = 1; $level < $object->_level + 1; $level++) {
259:                 if ($object->_level == $level) {
260:                     if ($object->_next === false) {
261:                         if (count($object->_subitems) > 0) {
262:                             $link = $this->_setExpandCollapseLink($this->_baseLink, $object);
263:                             $link->advanceID();
264:                             $img->setSrc($this->_getExpandCollapseIcon($object));
265:                             $img->advanceID();
266:                             $link->setContent($img);
267:                             $out .= $link->render();
268:                         } else {
269:                             if ($level == 1 && $with_root == false) {
270:                                 $out .= $img_spacer->render();
271:                             } else {
272:                                 $img->setSrc($this->_buildImagePath("grid_linedownrightend.gif"));
273:                                 $img->advanceID();
274:                                 $out .= $img->render();
275:                             }
276:                         }
277:                         $lastitem[$level] = true;
278:                     } else {
279:                         if (count($object->_subitems) > 0) {
280:                             $link = $this->_setExpandCollapseLink($this->_baseLink, $object);
281:                             $link->advanceID();
282:                             $img->setSrc($this->_getExpandCollapseIcon($object));
283:                             $img->advanceID();
284:                             $link->setContent($img);
285:                             $out .= $link->render();
286:                         } else {
287:                             if ($level == 1 && $with_root == false) {
288:                                 $out .= $img_spacer->render();
289:                             } else {
290:                                 $img->setSrc($this->_buildImagePath("grid_linedownright.gif"));
291:                                 $out .= $img->render();
292:                             }
293:                         }
294: 
295:                         $lastitem[$level] = false;
296:                     }
297:                 } else {
298:                     if ($lastitem[$level] == true) {
299:                         $out .= $img_spacer->render();
300:                     } else {
301:                         if ($level == 1 && $with_root == false) {
302:                             $out .= $img_spacer->render();
303:                         } else {
304:                             $img->setSrc($this->_buildImagePath("/grid_linedown.gif"));
305:                             $img->advanceID();
306:                             $out .= $img->render();
307:                         }
308:                     }
309:                 }
310:             }
311: 
312:             // Fetch Render icon from the meta object
313:             if (is_object($object->payload)) {
314:                 // Fetch payload object
315:                 $meta = $object->payload->getMetaObject();
316: 
317:                 if (is_object($meta)) {
318:                     $icon = $meta->getIcon();
319:                     $actions = $meta->getActions();
320: 
321:                     $r_actioncell->setContent($actions);
322: 
323:                     $img->setAlt($meta->getDescription());
324:                     $img->advanceID();
325: 
326:                     // Check if we've got an edit link
327:                     if (count($meta->_editAction) > 0) {
328:                         $meta->defineActions();
329: 
330:                         $edit = $meta->getAction($meta->_editAction);
331: 
332:                         $edit->setIcon($icon);
333: 
334:                         $renderedIcon = $edit->render();
335: 
336:                         $edit->_link->setContent($object->getName());
337:                         $edit->_link->advanceID();
338:                         $renderedName = $edit->_link->render();
339:                     } else {
340:                         $img->setSrc($icon);
341:                         $renderedIcon = $img->render();
342:                         $renderedName = $object->getName();
343:                     }
344:                 }
345:             } else {
346:                 if (isset($object->_attributes["icon"])) {
347:                     $img->setSrc($object->_attributes["icon"]);
348:                     $renderedIcon = $img->render();
349:                     $renderedName = $object->getName();
350:                 } else {
351:                     // Fetch tree icon
352:                     if ($object->getId() == 0) {
353:                         $icon = $object->getTreeIcon();
354:                         $img->setSrc($icon);
355:                         $renderedIcon = $img->render();
356:                         $renderedName = $object->getName();
357:                     } else {
358:                         $icon = $object->getTreeIcon();
359:                         $img->setSrc($icon);
360:                         $renderedIcon = $img->render();
361:                         $renderedName = $object->getName();
362:                     }
363:                 }
364:             }
365: 
366:             $img->setSrc($icon);
367:             $r_leftcell->setContent($out . $renderedIcon);
368:             $r_rightcell->setContent($renderedName);
369: 
370:             $r_row->setContent(array($r_leftcell, $r_rightcell, $r_actioncell));
371: 
372:             $r_table->setContent($r_row);
373: 
374:             $result .= $r_table->render();
375: 
376:             unset($out);
377:         }
378: 
379:         return '<table cellspacing="0" cellpadding="0" width="100%" border="0"><tr><td>' . $result . '</td></tr></table>';
380:     }
381: 
382:     /**
383:      *
384:      * @param cTreeItem $object
385:      * @return string
386:      */
387:     public function _getExpandCollapseIcon($object) {
388: 
389:         $img = $object->getCollapsed() ? "grid_expand.gif" : "grid_collapse.gif";
390: 
391:         return $this->_buildImagePath($img);
392:     }
393: 
394:     /**
395:      * Sets collapsed state.
396:      *
397:      * @param cHTMLLink  $link
398:      * @param cTreeItem  $object
399:      * @return cHTMLLink
400:      */
401:     public function _setExpandCollapseLink($link, $object) {
402:         if (!empty($this->_name)) {
403:             $treename = $this->_name . "_";
404:         }
405: 
406:         $link->unsetCustom($treename . "expand");
407:         $link->unsetCustom($treename . "collapse");
408: 
409:         if ($object->getCollapsed() == true) {
410:             $link->setCustom($treename . "expand", $object->getId());
411:         } else {
412:             $link->setCustom($treename . "collapse", $object->getId());
413:         }
414: 
415:         return $link;
416:     }
417: 
418:     /**
419:      *
420:      * @param string $image
421:      * @return string
422:      */
423:     public function _buildImagePath($image) {
424:         return "./images/" . $this->_gridlineMode . "/" . $image;
425:     }
426: 
427:     /**
428:      *
429:      * @param string $link
430:      */
431:     public function setBaseLink($link) {
432:         $this->_baseLink = $link;
433:     }
434: 
435: }
436: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0