]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/actions/disfavor.php
A bunch of FormAction and ManagedAction synchronization
[quix0rs-gnu-social.git] / plugins / Favorite / actions / disfavor.php
1 <?php
2 /**
3  * Disfavor action.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  GNUsocial
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @author   Mikael Nordfeldth <mmn@hethane.se>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://www.gnu.org/software/social/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('GNUSOCIAL')) { exit(1); }
33
34 /**
35  * DisfavorAction class.
36  *
37  * @category Action
38  * @package  GNUsocial
39  * @author   Evan Prodromou <evan@status.net>
40  * @author   Robin Millette <millette@status.net>
41  * @author   Mikael Nordfeldth <mmn@hethane.se>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://www.gnu.org/software/social/
44  */
45 class DisfavorAction extends FormAction
46 {
47     protected $needPost = true;
48
49     protected function doPreparation()
50     {
51         $this->target = Notice::getKV($this->trimmed('notice'));
52         if (!$this->target instanceof Notice) {
53             throw new ServerException(_m('No such notice.'));
54         }
55     }
56
57     protected function doPost()
58     {
59         $fave            = new Fave();
60         $fave->user_id   = $this->scoped->getID();
61         $fave->notice_id = $this->target->getID();
62         if (!$fave->find(true)) {
63             // TRANS: Client error displayed when trying to remove a 'favor' when there is none in the first place.
64             throw new AlreadyFulfilledException(_('This is already not favorited.'));
65         }
66         $result = $fave->delete();
67         if ($result === false) {
68             common_log_db_error($fave, 'DELETE', __FILE__);
69             // TRANS: Server error displayed when removing a favorite from the database fails.
70             throw new ServerException(_('Could not delete favorite.'));
71         }
72         Fave::blowCacheForProfileId($this->scoped->getID());
73
74         // TRANS: Message when a disfavor action has been taken for a notice.
75         return _('Disfavored the notice.');
76     }
77
78     protected function showContent()
79     {
80         // We show the 'Favor' form because right now all calls to Disfavor will directly disfavor a notice.
81         $disfavor = new FavorForm($this, $this->target);
82         $disfavor->show();
83     }
84 }