Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Admin changing a preference for all users?
matt
✭✭
Hi,
Is it possible for a forum admin to change a preference for all users? For example, I'd like to switch on whisper notification for all users.
I'd ideally like to do this without getting knee deep in SQL. Any ideas?
Thanks,
matt
Is it possible for a forum admin to change a preference for all users? For example, I'd like to switch on whisper notification for all users.
I'd ideally like to do this without getting knee deep in SQL. Any ideas?
Thanks,
matt
0
This discussion has been closed.
Comments
mysql_query("UPDATE `LUM_User` SET `Preferences` = 'a:1:{s:18:\"NotifyOnNewWhisper\";i:1;}' ");
>This would really be a good extension.
I'd love to see an extension for this.
a:1:{s:18:\"NotifyOnNewWhisper\";i:1;} means:
array of length 1. first item: string of length 18, named "NotifyOnNewWhisper", with a value of integer:1
another:
a:5:{s:14:"ShowActivePoll";i:0;s:13:"ShowBookmarks";i:1;s:21:"ShowRecentDiscussions";i:1; s:23:"AUDIOSCROBBLER_USERNAME";s:8:"msephton";s:19:"ShowLargeCommentBox";i:1;}
array of length 5
string of length 14, string name "ShowActivePoll", string value (here integer of value 0),
string of length 13, string name "ShowBookmarks", string value (here integer of value 1),
string of length 21, string name "ShowRecentDiscussions", string value (here integer of value 1),
string of length 23, string name "AUDIOSCROBBLER_USERNAME", string value (here string of length 8, value "msephton"),
string of length 19, string name "ShowLargeCommentBox", string value (here integer of value 1),
// Select all users and their preferences from the db $s = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder'); $s->SetMainTable('User', 'u'); $s->AddSelect(array('UserID', 'Preferences'), 'u'); $ResultSet = $Context->Database->Select($s, 'YourAddOnName', 'SetPreferenceMethodName', 'An error occurred while retrieving user information.'); while ($Row = $Context->Database->GetRow($ResultSet)) { $CurrentUserID = ForceInt($Row['UserID'], 0); $SerializedPreferences = ForceString($Row['Preferences'], ''); $Preferences = UnserializeAssociativeArray($SerializedPreferences); if ($UserID > 0 && is_array($Preferences)) { // $PreferenceToChange is the name of the preference you want to change. The $Switch value can be 1 or 0. $Preferences[$PreferenceToChange] = $Switch; // Now reserialize and save to the db. $SerializedPreferences = SerializeArray($Preferences); $s->Clear(); $s->SetMainTable('User', 'u'); $s->AddFieldNameValue('Preferences', $SerializedPreferences); $s->AddWhere('u', 'UserID', '', $CurrentUserID, '='); $Context->Database->Update($s, 'YourAddOnName', 'SetPreferenceMethodName', 'An error occurred while manipulating user preferences.'); } }
Keep in mind that your extension should pay very close attention to who is allowed to perform this change. You might want to create and add a new role permission.
are they listed somewhere, or i can pick one by myself
$s->SetMainTable('User', 'u');
This references the user table by the "u" alias and pulls any columns from that table - in this case UserID and Preferences.
$s->AddSelect(array('UserID', 'Preferences'), 'u');
It'd be my first extension.
Constructive criticism very welcome!
I'm checking out ur extension cause i need similar functionality
I want to save two parameters in the database in the Discussion Table. one param is a bool, another is a url
1) Create 2 columns for both parameters
2) One column but use comma separated fields (Param1,Parm2)
3) One column and use Serialize and UnSerialize array
this column will be checked for every single discussion list. So speed is important. Which of the above options is better.
Serialization is used to avoid changing the db tables.
It's worth starting your own topic as you'll stand a better chance of getting your question answered. Or you could try all three of your proposed methods and see which is fastest?