]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Message.php
Added the new pinghandler to the stopdaemons script and improved the behaviour and...
[quix0rs-gnu-social.git] / classes / Message.php
1 <?php
2 /**
3  * Table Definition for message
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Message extends Memcached_DataObject 
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'message';                         // table name
13     public $id;                              // int(4)  primary_key not_null
14     public $uri;                             // varchar(255)  unique_key
15     public $from_profile;                    // int(4)   not_null
16     public $to_profile;                      // int(4)   not_null
17     public $content;                         // varchar(140)  
18     public $rendered;                        // text()  
19     public $url;                             // varchar(255)  
20     public $created;                         // datetime()   not_null
21     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
22     public $source;                          // varchar(32)  
23
24     /* Static get */
25     function staticGet($k,$v=null)
26     { return Memcached_DataObject::staticGet('Message',$k,$v); }
27
28     /* the code above is auto generated do not remove the tag below */
29     ###END_AUTOCODE
30     
31     function getFrom()
32     {
33         return Profile::staticGet('id', $this->from_profile);
34     }
35     
36     function getTo()
37     {
38         return Profile::staticGet('id', $this->to_profile);
39     }
40     
41     static function saveNew($from, $to, $content, $source) {
42         
43         $msg = new Message();
44         
45         $msg->from_profile = $from;
46         $msg->to_profile = $to;
47         $msg->content = common_shorten_links($content);
48         $msg->rendered = common_render_text($content);
49         $msg->created = common_sql_now();
50         $msg->source = $source;
51         
52         $result = $msg->insert();
53         
54         if (!$result) {
55             common_log_db_error($msg, 'INSERT', __FILE__);
56             return _('Could not insert message.');
57         }
58         
59         $orig = clone($msg);
60         $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
61         
62         $result = $msg->update($orig);
63         
64         if (!$result) {
65             common_log_db_error($msg, 'UPDATE', __FILE__);
66             return _('Could not update message with new URI.');
67         }
68         
69         return $msg;
70     }
71 }