]> git.mxchange.org Git - friendica.git/blob - object/Conversation.php
Got of the get_* function about data, use get_data_value instead (except for get_id...
[friendica.git] / object / Conversation.php
1 <?php
2 if(class_exists('Conversation'))
3         return;
4
5 require_once('boot.php');
6 require_once('object/BaseObject.php');
7 require_once('object/Item.php');
8 require_once('include/text.php');
9
10 /**
11  * A list of threads
12  *
13  * We should think about making this a SPL Iterator
14  */
15 class Conversation extends BaseObject {
16         private $threads = array();
17         private $mode = null;
18
19         public function __construct($mode) {
20                 $this->mode = $mode;
21         }
22
23         /**
24          * Add a thread to the conversation
25          *
26          * Returns:
27          *              _ The inserted item on success
28          *              _ false on failure
29          */
30         public function add_thread($item) {
31                 $item_id = $item->get_id();
32                 if(!$item_id) {
33                         logger('[ERROR] Conversation::add_thread : Item has no ID!!', LOGGER_DEBUG);
34                         return false;
35                 }
36                 if($this->get_thread($item->get_id())) {
37                         logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
38                         return false;
39                 }
40                 $this->threads[] = $item;
41                 return end($this->threads);
42         }
43
44         /**
45          * Get data in a form usable by a conversation template
46          *
47          * We should find a way to avoid using those arguments (at least most of them)
48          *
49          * Returns:
50          *              _ The data requested on success
51          *              _ false on failure
52          */
53         public function get_template_data($cmnt_tpl, $alike, $dlike) {
54                 $result = array();
55
56                 foreach($this->threads as $item) {
57                         if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
58                                 continue;
59                         $item_data = $item->get_template_data($cmnt_tpl, $this->mode, $alike, $dlike);
60                         if(!$item_data) {
61                                 logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
62                                 return false;
63                         }
64                         $result[] = $item_data;
65                 }
66
67                 return $result;
68         }
69
70         /**
71          * Get a thread based on its item id
72          *
73          * Returns:
74          *              _ The found item on success
75          *              _ false on failure
76          */
77         private function get_thread($id) {
78                 foreach($this->threads as $item) {
79                         if($item->get_id() == $id)
80                                 return $item;
81                 }
82
83                 return false;
84         }
85 }
86 ?>