2 if(class_exists('Conversation'))
5 require_once('boot.php');
6 require_once('object/BaseObject.php');
7 require_once('object/Item.php');
8 require_once('include/text.php');
13 * We should think about making this a SPL Iterator
15 class Conversation extends BaseObject {
16 private $threads = array();
19 public function __construct($mode) {
24 * Add a thread to the conversation
27 * _ The inserted item on success
30 public function add_thread($item) {
31 $item_id = $item->get_id();
33 logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
36 if($this->get_thread($item->get_id())) {
37 logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
40 $this->threads[] = $item;
41 return end($this->threads);
45 * Get data in a form usable by a conversation template
47 * We should find a way to avoid using those arguments (at least most of them)
50 * _ The data requested on success
53 public function get_template_data($cmnt_tpl, $alike, $dlike) {
56 foreach($this->threads as $item) {
57 if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
59 $item_data = $item->get_template_data($cmnt_tpl, $this->mode, $alike, $dlike);
61 logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
64 $result[] = $item_data;
71 * Get a thread based on its item id
74 * _ The found item on success
77 private function get_thread($id) {
78 foreach($this->threads as $item) {
79 if($item->get_id() == $id)