summaryrefslogtreecommitdiff
path: root/plugins/UserFlag
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/UserFlag')
-rw-r--r--plugins/UserFlag/UserFlagPlugin.php60
-rw-r--r--plugins/UserFlag/User_flag_profile.php23
-rw-r--r--plugins/UserFlag/flagprofile.php15
3 files changed, 57 insertions, 41 deletions
diff --git a/plugins/UserFlag/UserFlagPlugin.php b/plugins/UserFlag/UserFlagPlugin.php
index e6ad3e37d..fc7698841 100644
--- a/plugins/UserFlag/UserFlagPlugin.php
+++ b/plugins/UserFlag/UserFlagPlugin.php
@@ -128,25 +128,9 @@ class UserFlagPlugin extends Plugin
*/
function onEndProfilePageActionsElements(&$action, $profile)
{
- $user = common_current_user();
-
- if (!empty($user) && ($user->id != $profile->id)) {
-
- $action->elementStart('li', 'entity_flag');
-
- if (User_flag_profile::exists($profile->id, $user->id)) {
- // @todo FIXME: Add a title explaining what 'flagged' means?
- // TRANS: Message added to a profile if it has been flagged for review.
- $action->element('p', 'flagged', _('Flagged'));
- } else {
- $form = new FlagProfileForm($action, $profile,
- array('action' => 'showstream',
- 'nickname' => $profile->nickname));
- $form->show();
- }
-
- $action->elementEnd('li');
- }
+ $this->showFlagButton($action, $profile,
+ array('action' => 'showstream',
+ 'nickname' => $profile->nickname));
return true;
}
@@ -160,22 +144,40 @@ class UserFlagPlugin extends Plugin
*/
function onEndProfileListItemActionElements($item)
{
- $user = common_current_user();
+ list($action, $args) = $item->action->returnToArgs();
+ $args['action'] = $action;
+ $this->showFlagButton($item->action, $item->profile, $args);
+
+ return true;
+ }
- if (!empty($user)) {
+ /**
+ * Actually output a flag button. If the target profile has already been
+ * flagged by the current user, a null-action faux button is shown.
+ *
+ * @param Action $action
+ * @param Profile $profile
+ * @param array $returnToArgs
+ */
+ protected function showFlagButton($action, $profile, $returnToArgs)
+ {
+ $user = common_current_user();
- list($action, $args) = $item->action->returnToArgs();
+ if (!empty($user) && ($user->id != $profile->id)) {
- $args['action'] = $action;
+ $action->elementStart('li', 'entity_flag');
- $form = new FlagProfileForm($item->action, $item->profile, $args);
+ if (User_flag_profile::exists($profile->id, $user->id)) {
+ // @todo FIXME: Add a title explaining what 'flagged' means?
+ // TRANS: Message added to a profile if it has been flagged for review.
+ $action->element('p', 'flagged', _m('Flagged'));
+ } else {
+ $form = new FlagProfileForm($action, $profile, $returnToArgs);
+ $form->show();
+ }
- $item->action->elementStart('li', 'entity_flag');
- $form->show();
- $item->action->elementEnd('li');
+ $action->elementEnd('li');
}
-
- return true;
}
/**
diff --git a/plugins/UserFlag/User_flag_profile.php b/plugins/UserFlag/User_flag_profile.php
index 69fe0f356..f4e9844df 100644
--- a/plugins/UserFlag/User_flag_profile.php
+++ b/plugins/UserFlag/User_flag_profile.php
@@ -79,21 +79,36 @@ class User_flag_profile extends Memcached_DataObject
/**
* return key definitions for DB_DataObject
*
- * @return array key definitions
+ * @return array of key names
*/
function keys()
{
- return array('profile_id' => 'K', 'user_id' => 'K');
+ return array_keys($this->keyTypes());
}
/**
* return key definitions for DB_DataObject
*
- * @return array key definitions
+ * @return array map of key definitions
*/
function keyTypes()
{
- return $this->keys();
+ return array('profile_id' => 'K', 'user_id' => 'K');
+ }
+
+ /**
+ * Magic formula for non-autoincrementing integer primary keys
+ *
+ * If a table has a single integer column as its primary key, DB_DataObject
+ * assumes that the column is auto-incrementing and makes a sequence table
+ * to do this incrementation. Since we don't need this for our class, we
+ * overload this method and return the magic formula that DB_DataObject needs.
+ *
+ * @return array magic three-false array that stops auto-incrementing.
+ */
+ function sequenceKey()
+ {
+ return array(false, false, false);
}
/**
diff --git a/plugins/UserFlag/flagprofile.php b/plugins/UserFlag/flagprofile.php
index 283eea40c..7096d3748 100644
--- a/plugins/UserFlag/flagprofile.php
+++ b/plugins/UserFlag/flagprofile.php
@@ -60,13 +60,6 @@ class FlagprofileAction extends ProfileFormAction
assert(!empty($user)); // checked above
assert(!empty($this->profile)); // checked above
- if (User_flag_profile::exists($this->profile->id,
- $user->id)) {
- // TRANS: Client error when setting flag that has already been set for a profile.
- $this->clientError(_m('Flag already exists.'));
- return false;
- }
-
return true;
}
@@ -104,7 +97,13 @@ class FlagprofileAction extends ProfileFormAction
// throws an exception on error
- User_flag_profile::create($user->id, $this->profile->id);
+ if (User_flag_profile::exists($this->profile->id,
+ $user->id)) {
+ // We'll return to the profile page (or return the updated AJAX form)
+ // showing the current state, so no harm done.
+ } else {
+ User_flag_profile::create($user->id, $this->profile->id);
+ }
if ($this->boolean('ajax')) {
$this->ajaxResults();