3 * Clear all flags for a profile
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * Action to clear flags for a profile
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
43 class ClearflagAction extends ProfileFormAction
46 * Take arguments for running
48 * @param array $args $_REQUEST args
50 * @return boolean success flag
52 function prepare(array $args = array())
54 if (!parent::prepare($args)) {
58 $user = common_current_user();
60 assert(!empty($user)); // checked above
61 assert(!empty($this->profile)); // checked above
69 * Overriding the base Action's handle() here to deal check
70 * for Ajax and return an HXR response if necessary
72 * @param array $args $_REQUEST args; handled in prepare()
78 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
80 if (!$this->boolean('ajax')) {
81 $this->returnToPrevious();
89 * Executes the actions; deletes all flags
95 $ufp = new User_flag_profile();
97 $result = $ufp->query('UPDATE user_flag_profile ' .
98 'SET cleared = now() ' .
99 'WHERE cleared is null ' .
100 'AND profile_id = ' . $this->profile->id);
102 if ($result == false) {
103 // TRANS: Server exception given when flags could not be cleared.
104 // TRANS: %s is a profile nickname.
105 $msg = sprintf(_m('Could not clear flags for profile "%s".'),
106 $this->profile->nickname);
107 throw new ServerException($msg);
112 if ($this->boolean('ajax')) {
113 $this->ajaxResults();
118 * Return results in ajax form
122 function ajaxResults()
124 $this->startHTML('text/xml;charset=utf-8');
125 $this->elementStart('head');
126 // TRANS: Title for AJAX form to indicated that flags were removed.
127 $this->element('title', null, _m('Flags cleared'));
128 $this->elementEnd('head');
129 $this->elementStart('body');
130 // TRANS: Body element for "flags cleared" form.
131 $this->element('p', 'cleared', _m('Cleared'));
132 $this->elementEnd('body');