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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: /**
  3:  * This file contains the tree item class.
  4:  *
  5:  * @package    Core
  6:  * @subpackage GUI
  7:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Bjoern Behrens
 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:  * Tree item class
 20:  *
 21:  * @package    Core
 22:  * @subpackage GUI
 23:  */
 24: class cTreeItem {
 25: 
 26:     /**
 27:      * Sub Items for this tree item
 28:      *
 29:      * @var array
 30:      */
 31:     var $_subitems = array();
 32: 
 33:     /**
 34:      * Determinates if this tree item is collapsed
 35:      *
 36:      * @var boolean
 37:      */
 38:     var $_collapsed;
 39: 
 40:     /**
 41:      * ID for this item
 42:      *
 43:      * @var string
 44:      */
 45:     var $_id;
 46: 
 47:     /**
 48:      * Name for this item
 49:      *
 50:      * @var string
 51:      */
 52:     var $_name;
 53: 
 54:     /**
 55:      * Contains the level of this item
 56:      *
 57:      * @var integer
 58:      */
 59:     var $_level;
 60: 
 61:     /**
 62:      * Contains custom entries
 63:      *
 64:      * @var array
 65:      */
 66:     var $_attributes = array();
 67: 
 68:     /**
 69:      * Contains the parent of this item
 70:      *
 71:      * @var array
 72:      */
 73:     var $_parent = false;
 74: 
 75:     /**
 76:      * Contains the next item
 77:      *
 78:      * @var array
 79:      */
 80:     var $_next = false;
 81: 
 82:     /**
 83:      * Contains the previous item
 84:      *
 85:      * @var array
 86:      */
 87:     var $_previous = false;
 88: 
 89:     public function __construct($id = "", $name = "", $collapsed = false) {
 90:         $this->_id = $id;
 91:         $this->_name = $name;
 92:         $this->_collapsed = $collapsed;
 93:     }
 94: 
 95:     /**
 96:      * Id getter
 97:      *
 98:      * @return string
 99:      */
100:     public function getId() {
101:         return $this->_id;
102:     }
103: 
104:     /**
105:      * Name getter
106:      *
107:      * @return string
108:      */
109:     public function getName() {
110:         return $this->_name;
111:     }
112: 
113:     /**
114:      * Collapsed state getter
115:      *
116:      * @return bool
117:      */
118:     public function getCollapsed() {
119:         return $this->_collapsed;
120:     }
121: 
122:     /**
123:      * Imports a table from an array of arrays.
124:      * Array format:
125:      * array(
126:      * array("id" => "Item ID", "name" => "Item name", "level" => 1, "collapsed"
127:      * => true|false, "attributes" => array("attr_name" => "attr_value"))
128:      * );
129:      *
130:      * The entries "collapsed" and "attributes" are optional!
131:      *
132:      * @param array $flat_array See above
133:      */
134:     public function importTable($flat_array) {
135:         $lastobj[0] = $this->_id;
136:         $currentlevel = 1;
137: 
138:         if (!is_array($flat_array)) {
139:             return false;
140:         }
141: 
142:         foreach ($flat_array as $item) {
143:             $mitem[$item["id"]] = new cTreeItem($item["id"], $item["name"]);
144: 
145:             if ($item["level"] > $currentlevel) {
146:                 $currentlevel++;
147:             }
148: 
149:             if ($item["level"] < $currentlevel) {
150:                 $currentlevel = $item["level"];
151:             }
152: 
153:             if (is_array($item["attributes"])) {
154:                 $mitem[$item["id"]]->setAttributes($item["attributes"]);
155:             }
156: 
157:             if (array_key_exists("collapsed", $item)) {
158:                 $mitem[$item["id"]]->setCollapsed($item["collapsed"]);
159:             }
160: 
161:             /* Set payload object */
162:             if (array_key_exists("payload", $item)) {
163:                 $mitem[$item["id"]]->setPayloadObject($item["payload"]);
164:             }
165: 
166:             if (is_object($mitem[$lastobj[$currentlevel - 1]])) {
167:                 $mitem[$lastobj[$currentlevel - 1]]->addItem($mitem[$item["id"]]);
168:             } else {
169:                 $this->addItemToID($lastobj[$currentlevel - 1], $mitem[$item["id"]]);
170:             }
171: 
172:             $lastobj[$currentlevel] = $item["id"];
173:         }
174:     }
175: 
176:     public function importStructuredArray($array) {
177:         $i = array();
178: 
179:         $lastid = 1;
180:         $level = 1;
181: 
182:         $this->_flattenArray($array, $i, $lastid, $level);
183: 
184:         $this->importTable($i);
185:     }
186: 
187:     protected function _flattenArray($sourcearray, &$destarray, &$lastid, &$level) {
188:         if ($lastid == false) {
189:             $lastid = 1;
190:         }
191: 
192:         if ($level == false) {
193:             $level = 1;
194:         }
195: 
196:         if (!is_array($sourcearray)) {
197:             return false;
198:         }
199: 
200:         foreach ($sourcearray as $id => $item) {
201:             $lastid++;
202:             $destarray[$lastid]["id"] = $item["class"] . "." . $id;
203: 
204:             // Name should be fetched via the meta object
205:             $meta = $item["object"]->getMetaObject();
206: 
207:             if (is_object($meta)) {
208:                 $destarray[$lastid]["name"] = $meta->getName();
209:             }
210: 
211:             $destarray[$lastid]["level"] = $level;
212:             $destarray[$lastid]["payload"] = $item["object"];
213: 
214:             if (count($item["items"]) > 0) {
215:                 $level++;
216:                 $this->_flattenArray($item["items"], $destarray, $lastid, $level);
217:                 $level--;
218:             }
219:         }
220:     }
221: 
222:     /**
223:      * adds an item as a subitem to the current item
224:      *
225:      * @param cTreeItem item item object to add
226:      */
227:     public function addItem(&$item) {
228:         // Update last item
229:         if (($lastitem = end($this->_subitems)) !== false) {
230:             $this->_subitems[key($this->_subitems)]->_next = $item->_id;
231:         }
232: 
233:         $this->_subitems[count($this->_subitems)] = &$item;
234:         $item->_parent = $this->_id;
235:         $item->_previous = $lastitem->_id;
236:     }
237: 
238:     /**
239:      * adds an item to a specific ID
240:      *
241:      * @param string $id ID to add the item to
242:      * @param cTreeItem $item Item to add
243:      */
244:     public function addItemToID($id, &$item) {
245:         if ($this->_id == $id) {
246:             // Update last item
247:             if ($lastitem = end($this->_subitems) !== false) {
248:                 $this->_subitems[key($this->_subitems)]->_next = $item->_id;
249:             }
250: 
251:             $this->_subitems[count($this->_subitems)] = &$item;
252:             $item->_parent = $this->_id;
253:             $item->_previous = $lastitem->_id;
254:             return true;
255:         } else {
256:             foreach (array_keys($this->_subitems) as $key) {
257:                 $result = $this->_subitems[$key]->addItemToID($id, $item);
258:                 if ($result == true) {
259:                     return true;
260:                 }
261:             }
262:         }
263: 
264:         return false;
265:     }
266: 
267:     /**
268:      * moves an item to another object
269:      *
270:      * @param cTreeItem targetItem Item to move the subitem to
271:      * @param mixed itemToMove cTreeItem-Object or id of object to move
272:      */
273:     public function moveItem($targetItem, $itemToMove) {
274:     }
275: 
276:     /**
277:      * deletes a subitem
278:      *
279:      * @param mixed item object or ID to delete
280:      * @return deleted object
281:      */
282:     public function deleteItem($id) {
283:         foreach (array_keys($this->_subitems) as $key) {
284:             if ($this->_subitems[$key]->_id == $id) {
285:                 // Fetch next item, reset to current item
286:                 $nextitem = next($this->_subitems);
287:                 $nkey = key($this->_subitems);
288:                 prev($this->_subitems);
289: 
290:                 $previtem = &prev($this->_subitems);
291:                 $pkey = key($this->_subitems);
292:                 next($this->_subitems);
293: 
294:                 if ($nextitem !== false) {
295:                     if ($previtem !== false) {
296:                         $this->_subitems[$nkey]->_previous = $this->_subitems[$pkey]->_id;
297:                     }
298:                 }
299: 
300:                 if ($previtem !== false) {
301:                     if ($nextitem !== false) {
302:                         $this->_subitems[$pkey]->_next = $this->_subitems[$nkey]->_id;
303:                     }
304:                 }
305: 
306:                 $itemcopy = $this->_subitems[$key];
307:                 unset($this->_subitems[$key]);
308: 
309:                 return ($itemcopy);
310:             } else {
311:                 $this->_subitems[$key]->deleteItem($id);
312:             }
313:         }
314:     }
315: 
316:     /**
317:      * Retrieves a specific item by its ID.
318:      * Note that this
319:      * function traverses all subitems to find the correct item.
320:      *
321:      * @param string id ID to retrieve
322:      * @return cTreeItem
323:      */
324:     public function &getItemByID($id) {
325:         if ($this->_id == $id) {
326:             return $this;
327:         } else {
328:             foreach (array_keys($this->_subitems) as $key) {
329:                 $retObj = &$this->_subitems[$key]->getItemByID($id);
330:                 if ($retObj->_id == $id) {
331:                     return $retObj;
332:                 }
333:             }
334:         }
335: 
336:         return false;
337:     }
338: 
339:     /**
340:      * sets a custom attribute for this TreeItem
341:      *
342:      * @param string attributeName
343:      * @param array attributeValue The value(s) of the attribute
344:      */
345:     public function setAttribute($attributeName, $attributeValue) {
346:         $this->_attributes[$attributeName] = $attributeValue;
347:     }
348: 
349:     /**
350:      * sets a bunch of attributes
351:      *
352:      * @param string attributeName
353:      * @param array attributeValue The value(s) of the attribute
354:      */
355:     public function setAttributes($aAttributeArray) {
356:         $this->_attributes = array_merge($aAttributeArray, $this->_attributes);
357:     }
358: 
359:     /**
360:      * returns an attribute
361:      *
362:      * @param string attributeName
363:      * @return mixed
364:      */
365:     public function getAttribute($attributeName) {
366:         if (array_key_exists($attributeName, $this->_attributes)) {
367:             return ($this->_attributes[$attributeName]);
368:         } else {
369:             return false;
370:         }
371:     }
372: 
373:     /**
374:      * deletes an attribute
375:      *
376:      * @param string attributeName
377:      */
378:     public function deleteAttribute($attributeName) {
379:         if (array_key_exists($attributeName, $this->_attributes)) {
380:             unset($this->_attributes[$attributeName]);
381:             return true;
382:         } else {
383:             return false;
384:         }
385:     }
386: 
387:     public function hasAttribute($attributeName, $bRecursive = false) {
388:         if (array_key_exists($attributeName, $this->_attributes)) {
389:             return true;
390:         } else {
391:             if ($bRecursive == true) {
392:                 if (count($this->_subitems) > 0) {
393:                     foreach ($this->_subitems as $oSubitem) {
394:                         $bFound = $oSubitem->hasAttribute($attributeName, true);
395:                         if ($bFound == true) {
396:                             return true;
397:                         }
398:                     }
399:                 }
400: 
401:                 return false;
402:             } else {
403:                 return false;
404:             }
405:         }
406:     }
407: 
408:     /**
409:      *
410:      * @param mixed expand ID of item to expand or array of item ID's to expand
411:      */
412:     public function setExpanded($id) {
413:         if (is_array($id)) {
414:             if (in_array($this->_id, $id, true)) {
415:                 $this->_collapsed = false;
416:             }
417: 
418:             foreach (array_keys($this->_subitems) as $key) {
419:                 $this->_subitems[$key]->setExpanded($id);
420:             }
421:         } else {
422:             if ($this->_id === $id) {
423:                 $this->_collapsed = false;
424:                 return true;
425:             } else {
426:                 foreach (array_keys($this->_subitems) as $key) {
427:                     $this->_subitems[$key]->setExpanded($id);
428:                 }
429:             }
430:         }
431:     }
432: 
433:     /**
434:      *
435:      * @param mixed collapse ID to collapse or an array with items to collapse
436:      */
437:     public function setCollapsed($id) {
438:         if (is_array($id)) {
439:             if (in_array($this->_id, $id, true)) {
440:                 $this->_collapsed = true;
441:             }
442: 
443:             foreach (array_keys($this->_subitems) as $key) {
444:                 $this->_subitems[$key]->setCollapsed($id);
445:             }
446:         } else {
447:             if ($this->_id === $id) {
448:                 $this->_collapsed = true;
449:                 return true;
450:             } else {
451:                 foreach (array_keys($this->_subitems) as $key) {
452:                     $this->_subitems[$key]->setCollapsed($id);
453:                 }
454:             }
455:         }
456:     }
457: 
458:     /**
459:      *
460:      * @param int leveloffset Level offset. Ignores all expand operations below
461:      *        the offset.
462:      */
463:     protected function _expandBelowLevel($leveloffset) {
464:         if ($leveloffset > 0) {
465:             $leveloffset--;
466:         } else {
467:             $this->_collapsed = false;
468:         }
469: 
470:         foreach (array_keys($this->_subitems) as $key) {
471:             $this->_subitems[$key]->expandBelowLevel($leveloffset);
472:         }
473:     }
474: 
475:     /**
476:      *
477:      * @param int leveloffset Level offset. Ignores all expand operations below
478:      *        the offset.
479:      */
480:     protected function _collapseBelowLevel($leveloffset) {
481:         if ($leveloffset > 0) {
482:             $leveloffset--;
483:         } else {
484:             $this->_collapsed = true;
485:         }
486: 
487:         foreach (array_keys($this->_subitems) as $key) {
488:             $this->_subitems[$key]->collapseBelowLevel($leveloffset);
489:         }
490:     }
491: 
492:     /**
493:      *
494:      * @param int leveloffset Level offset. Ignores all expand operations below
495:      *        the offset.
496:      */
497:     protected function _expandBelowID($id, $found = false) {
498:         if ($found === true) {
499:             $this->_collapsed = false;
500:         }
501: 
502:         if ($this->_id == $id) {
503:             $found = true;
504:             $this->_collapsed = false;
505:         }
506: 
507:         foreach (array_keys($this->_subitems) as $key) {
508:             $this->_subitems[$key]->expandBelowID($id, $found);
509:         }
510:     }
511: 
512:     /**
513:      *
514:      * @param int leveloffset Level offset. Ignores all expand operations below
515:      *        the offset.
516:      */
517:     protected function _collapseBelowID($id, $found = false) {
518:         if ($found === true) {
519:             $this->_collapsed = true;
520:         }
521: 
522:         if ($this->_id == $id) {
523:             $found = true;
524:             $this->_collapsed = true;
525:         }
526: 
527:         foreach (array_keys($this->_subitems) as $key) {
528:             $this->_subitems[$key]->collapseBelowID($id, $found);
529:         }
530:     }
531: 
532:     /**
533:      * getCollapsedList
534:      * Returns all items (as ID array) which are collapsed.
535:      *
536:      * @param array $list Contains the list with all collapsed items
537:      */
538:     public function getCollapsedList(&$list) {
539:         if (!is_array($list)) {
540:             $list = array();
541:         }
542: 
543:         if ($this->_collapsed == true) {
544:             $list[] = $this->_id;
545:         }
546: 
547:         foreach (array_keys($this->_subitems) as $key) {
548:             $this->_subitems[$key]->getCollapsedList($list);
549:         }
550:     }
551: 
552:     /**
553:      * getExpandedList
554:      * Returns all items (as ID array) which are expanded.
555:      *
556:      * @param array $list Contains the list with all expanded items
557:      */
558:     public function getExpandedList(&$list) {
559:         if (!is_array($list)) {
560:             $list = array();
561:         }
562: 
563:         if ($this->_collapsed == false && !in_array($this->_id, $list)) {
564:             $list[] = $this->_id;
565:         }
566: 
567:         foreach (array_keys($this->_subitems) as $key) {
568:             $this->_subitems[$key]->getExpandedList($list);
569:         }
570:     }
571: 
572:     /**
573:      * sets a payload object for later reference
574:      *
575:      * @param object payload The object to payload
576:      */
577:     public function setPayloadObject($payload) {
578:         $this->payload = $payload;
579:     }
580: 
581:     /**
582:      * unsets a payload object
583:      *
584:      * @return object
585:      */
586:     public function unsetPayloadObject() {
587:         // @todo implement!
588:     }
589: 
590:     /**
591:      * traverse
592:      * traverses the tree starting from this item, and returning
593:      * all objects as $objects in a nested array.
594:      *
595:      * @param object $objects all found objects
596:      * @param int $level Level to start on
597:      */
598:     public function traverse(&$objects, $level = 0) {
599:         $objects[count($objects)] = &$this;
600:         $this->_level = $level;
601: 
602:         if ($this->_collapsed == false) {
603:             foreach (array_keys($this->_subitems) as $key) {
604:                 $this->_subitems[$key]->traverse($objects, $level + 1);
605:             }
606:         }
607:     }
608: 
609:     /**
610:      * flatTraverse
611:      * traverses the tree starting from this item, and returning
612:      * all objects as $objects in a flat array.
613:      *
614:      * @param object $objects all found objects
615:      * @param int $level Level to start on
616:      */
617:     public function flatTraverse($level = 0) {
618:         $objects[] = &$this;
619:         $this->_level = $level;
620: 
621:         if ($this->_collapsed == false) {
622:             foreach (array_keys($this->_subitems) as $key) {
623:                 $objects = array_merge($objects, $this->_subitems[$key]->flatTraverse($level + 1));
624:             }
625:         }
626: 
627:         return $objects;
628:     }
629: 
630:     /**
631:      * setName
632:      * sets the Name for this item.
633:      *
634:      * @param string $name New name for this item
635:      * @return none
636:      */
637:     public function setName($name) {
638:         $this->_name = $name;
639:     }
640: 
641: }
642: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen