Merged com.woltlab.wcf.message into WCF
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / message / quote / QuotedMessage.class.php
1 <?php
2 namespace wcf\system\message\quote;
3 use wcf\data\IMessage;
4
5 /**
6 * Wrapper class for quoted messages.
7 *
8 * @author Alexander Ebert
9 * @copyright 2001-2013 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package com.woltlab.wcf.message
12 * @subpackage system.message.quote
13 * @category Community Framework
14 */
15 class QuotedMessage implements \Countable, \Iterator {
16 /**
17 * list of full quotes for insertation
18 * @var array<string>
19 */
20 public $fullQuotes = array();
21
22 /**
23 * quotable database object
24 * @var wcf\data\IQuotableDatabaseObject
25 */
26 public $object = null;
27
28 /**
29 * list of quotes (shortend)
30 * @var array<string>
31 */
32 public $quotes = array();
33
34 /**
35 * current iterator index
36 * @var integer
37 */
38 protected $index = 0;
39
40 /**
41 * list of index to object relation
42 * @var array<integer>
43 */
44 protected $indexToObject = null;
45
46 /**
47 * Creates a new QuotedMessage object.
48 *
49 * @param wcf\data\IMessage $object
50 */
51 public function __construct(IMessage $object) {
52 $this->object = $object;
53 }
54
55 /**
56 * Adds a quote for this message.
57 *
58 * @param string $quoteID
59 * @param string $quote
60 * @param string $fullQuote
61 */
62 public function addQuote($quoteID, $quote, $fullQuote) {
63 $this->fullQuotes[$quoteID] = $fullQuote;
64 $this->quotes[$quoteID] = $quote;
65 $this->indexToObject[] = $quoteID;
66 }
67
68 /**
69 * @see wcf\data\ITitledObject::getTitle()
70 */
71 public function __toString() {
72 return $this->object->getTitle();
73 }
74
75 /**
76 * Forwards calls to the decorated object.
77 *
78 * @param string $name
79 * @param mixed $value
80 * @return mixed
81 */
82 public function __call($name, $value) {
83 return $this->object->$name();
84 }
85
86 /**
87 * Returns the full quote by quote id.
88 *
89 * @param string $quoteID
90 * @return string
91 */
92 public function getFullQuote($quoteID) {
93 if (isset($this->fullQuotes[$quoteID])) {
94 return $this->fullQuotes[$quoteID];
95 }
96
97 return null;
98 }
99
100 /**
101 * @see \Countable::count()
102 */
103 public function count() {
104 return count($this->quotes);
105 }
106
107 /**
108 * @see \Iterator::current()
109 */
110 public function current() {
111 $objectID = $this->indexToObject[$this->index];
112 return $this->quotes[$objectID];
113 }
114
115 /**
116 * CAUTION: This methods does not return the current iterator index,
117 * rather than the object key which maps to that index.
118 *
119 * @see \Iterator::key()
120 */
121 public function key() {
122 return $this->indexToObject[$this->index];
123 }
124
125 /**
126 * @see \Iterator::next()
127 */
128 public function next() {
129 ++$this->index;
130 }
131
132 /**
133 * @see \Iterator::rewind()
134 */
135 public function rewind() {
136 $this->index = 0;
137 }
138
139 /**
140 * @see \Iterator::valid()
141 */
142 public function valid() {
143 return isset($this->indexToObject[$this->index]);
144 }
145 }