]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/lib/favcommand.php
cf5ca79218ed293377555b7213ea2d92c37748a7
[quix0rs-gnu-social.git] / plugins / Favorite / lib / favcommand.php
1 <?php
2
3 class FavCommand extends Command 
4
5     var $other = null; 
6  
7     function __construct($user, $other) 
8     { 
9         parent::__construct($user); 
10         $this->other = $other; 
11     } 
12  
13     function handle($channel) 
14     { 
15         $notice = $this->getNotice($this->other); 
16  
17         $fave            = new Fave(); 
18         $fave->user_id   = $this->user->id; 
19         $fave->notice_id = $notice->id; 
20         $fave->find(); 
21  
22         if ($fave->fetch()) { 
23             // TRANS: Error message text shown when a favorite could not be set because it has already been favorited. 
24             $channel->error($this->user, _('Could not create favorite: Already favorited.')); 
25             return; 
26         } 
27  
28         try {
29             $fave = Fave::addNew($this->user->getProfile(), $notice); 
30         } catch (Exception $e) {
31             $channel->error($this->user, $e->getMessage());
32             return;
33         }
34  
35         // TRANS: Text shown when a notice has been marked as favourite successfully. 
36         $channel->output($this->user, _('Notice marked as fave.')); 
37     } 
38 }