Text.php 2.5 KB

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