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();
18 private $writeable = false;
19 private $profile_owner = 0;
21 public function __construct($mode) {
22 $this->set_mode($mode);
26 * Set the mode we'll be displayed on
28 private function set_mode($mode) {
29 if($this->get_mode() == $mode)
32 $a = $this->get_app();
37 $this->profile_owner = local_user();
38 $this->writeable = true;
41 $this->profile_owner = $a->profile['profile_uid'];
42 $this->writeable = can_write_wall($a,$this->profile_owner);
45 $this->profile_owner = $a->profile['uid'];
46 $this->writeable = can_write_wall($a,$this->profile_owner);
49 logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
59 public function get_mode() {
64 * Check if page is writeable
66 public function is_writeable() {
67 return $this->writeable;
73 public function get_profile_owner() {
74 return $this->profile_owner;
78 * Add a thread to the conversation
81 * _ The inserted item on success
84 public function add_thread($item) {
85 $item_id = $item->get_id();
87 logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
90 if($this->get_thread($item->get_id())) {
91 logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
94 $item->set_conversation($this);
95 $this->threads[] = $item;
96 return end($this->threads);
100 * Get data in a form usable by a conversation template
102 * We should find a way to avoid using those arguments (at least most of them)
105 * _ The data requested on success
108 public function get_template_data($alike, $dlike) {
111 foreach($this->threads as $item) {
112 if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
114 $item_data = $item->get_template_data($alike, $dlike);
116 logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
119 $result[] = $item_data;
126 * Get a thread based on its item id
129 * _ The found item on success
132 private function get_thread($id) {
133 foreach($this->threads as $item) {
134 if($item->get_id() == $id)