TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
Text.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Text.php 8/31/2012 11:06:09 scp@orilla $
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @package TeamSpeak3
23  * @version 1.1.16
24  * @author Sven 'ScP' Paulsen
25  * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
26  */
27 
28 /**
29  * @class TeamSpeak3_Viewer_Text
30  * @brief Renders nodes used in ASCII-based TeamSpeak 3 viewers.
31  */
33 {
34  /**
35  * A pre-defined pattern used to display a node in a TeamSpeak 3 viewer.
36  *
37  * @var string
38  */
39  protected $pattern = "%0%1 %2\n";
40 
41  /**
42  * Returns the code needed to display a node in a TeamSpeak 3 viewer.
43  *
44  * @param TeamSpeak3_Node_Abstract $node
45  * @param array $siblings
46  * @return string
47  */
48  public function fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings = array())
49  {
50  $this->currObj = $node;
51  $this->currSib = $siblings;
52 
53  $args = array(
54  $this->getPrefix(),
55  $this->getCorpusIcon(),
56  $this->getCorpusName(),
57  );
58 
59  return TeamSpeak3_Helper_String::factory($this->pattern)->arg($args);
60  }
61 
62  /**
63  * Returns the ASCII string to display the prefix of the current node.
64  *
65  * @return string
66  */
67  protected function getPrefix()
68  {
69  $prefix = "";
70 
71  if(count($this->currSib))
72  {
73  $last = array_pop($this->currSib);
74 
75  foreach($this->currSib as $sibling)
76  {
77  $prefix .= ($sibling) ? "| " : " ";
78  }
79 
80  $prefix .= ($last) ? "\\-" : "|-";
81  }
82 
83  return $prefix;
84  }
85 
86  /**
87  * Returns an ASCII string which can be used to display the status icon for a
88  * TeamSpeak_Node_Abstract object.
89  *
90  * @return string
91  */
92  protected function getCorpusIcon()
93  {
94  return $this->currObj->getSymbol();
95  }
96 
97  /**
98  * Returns a string for the current corpus element which contains the display name
99  * for the current TeamSpeak_Node_Abstract object.
100  *
101  * @return string
102  */
103  protected function getCorpusName()
104  {
105  return $this->currObj;
106  }
107 }