setMeta() public static method

public static setMeta ( integer $UserID, array $Meta, string $Prefix = '' )
$UserID integer
$Meta array
$Prefix string
 /**
  * Webhook for Teamwork.
  *
  * POST data looks like this:
  * [  'event' => 'TASK.COMPLETED',
  *    'objectId' => '000',
  *    'accountId' => '000',
  *    'userId' => '000',
  * ]
  *
  * @see http://developer.teamwork.com/todolistitems
  *
  * @param Gdn_Controller $sender
  * @param $secret
  * @throws Exception
  */
 public function utilityController_teamworkTaskCompleted_create($sender, $secret)
 {
     if ($secret != c('SprintNotifier.Teamwork.Secret')) {
         throw new Exception('Invalid token.');
     }
     // Get data
     $data = Gdn::request()->post();
     // Sanity check we set up webhooks right.
     if (val('event', $data) != 'TASK.COMPLETED') {
         return;
     }
     // Cheat by storing some data in the config.
     $users = c('SprintNotifier.Teamwork.Users', []);
     $projects = c('SprintNotifier.Teamwork.Projects', []);
     // Get full task data via Teamwork's *ahem* "API".
     $task = self::teamworkTask(val('objectId', $data));
     // DEBUG
     UserModel::setMeta(0, array('TaskAPI' => var_export($task, true)), 'SprintNotifier.Debug.');
     // Respect project whitelist if we're using one.
     if (count($projects) && !in_array($task['project-name'], $projects)) {
         return;
     }
     // Build data for the chat message.
     $teamworkUserID = val('userId', $data);
     $userName = val($teamworkUserID, $users, 'User ' . val('userId', $data));
     $taskUrl = sprintf('https://%1$s.teamwork.com/tasks/%2$s', c('Teamwork.Account'), val('objectId', $data));
     $message = sprintf('%1$s completed %2$s task: <a href="%3$s">%4$s</a>', $userName, strtolower($task['project-name']), $taskUrl, $task['content']);
     // Override HipChat plugin's default token & room.
     saveToConfig('HipChat.Room', c('SprintNotifier.HipChat.RoomID'), false);
     saveToConfig('HipChat.Token', c('SprintNotifier.HipChat.Token'), false);
     // DEBUG
     UserModel::setMeta(0, array('Message' => var_export($message, true)), 'SprintNotifier.Debug.');
     // Say it! Bust it!
     if (class_exists('HipChat')) {
         HipChat::say($message);
     }
     self::bustCache();
     // 200 OK
     $sender->render('blank', 'utility', 'dashboard');
 }
Esempio n. 2
0
 public function updateColumnsShow($description_show, $slug_show, $tours_show)
 {
     $user_id = Session::get("user_id");
     $meta_key = "manage_internalflights_columns_show";
     $meta_value = new stdClass();
     $meta_value->description_show = $description_show;
     $meta_value->slug_show = $slug_show;
     $meta_value->tours_show = $tours_show;
     $meta_value = json_encode($meta_value);
     Model::autoloadModel('user');
     $userModel = new UserModel($this->db);
     $userModel->setMeta($user_id, $meta_key, $meta_value);
 }
Esempio n. 3
0
 /**
  * Adds email notification options to profiles.
  *
  * @since 2.0.0
  * @package Vanilla
  *
  * @param ProfileController $Sender
  */
 public function profileController_afterPreferencesDefined_handler($Sender)
 {
     $Sender->Preferences['Notifications']['Email.DiscussionComment'] = t('Notify me when people comment on my discussions.');
     $Sender->Preferences['Notifications']['Email.BookmarkComment'] = t('Notify me when people comment on my bookmarked discussions.');
     $Sender->Preferences['Notifications']['Email.Mention'] = t('Notify me when people mention me.');
     $Sender->Preferences['Notifications']['Email.ParticipateComment'] = t('Notify me when people comment on discussions I\'ve participated in.');
     $Sender->Preferences['Notifications']['Popup.DiscussionComment'] = t('Notify me when people comment on my discussions.');
     $Sender->Preferences['Notifications']['Popup.BookmarkComment'] = t('Notify me when people comment on my bookmarked discussions.');
     $Sender->Preferences['Notifications']['Popup.Mention'] = t('Notify me when people mention me.');
     $Sender->Preferences['Notifications']['Popup.ParticipateComment'] = t('Notify me when people comment on discussions I\'ve participated in.');
     if (Gdn::session()->checkPermission('Garden.AdvancedNotifications.Allow')) {
         $PostBack = $Sender->Form->authenticatedPostBack();
         $Set = array();
         // Add the category definitions to for the view to pick up.
         $DoHeadings = c('Vanilla.Categories.DoHeadings');
         // Grab all of the categories.
         $Categories = array();
         $Prefixes = array('Email.NewDiscussion', 'Popup.NewDiscussion', 'Email.NewComment', 'Popup.NewComment');
         foreach (CategoryModel::categories() as $Category) {
             if (!$Category['PermsDiscussionsView'] || $Category['Depth'] <= 0 || $Category['Depth'] > 2 || $Category['Archived']) {
                 continue;
             }
             $Category['Heading'] = $DoHeadings && $Category['Depth'] <= 1;
             $Categories[] = $Category;
             if ($PostBack) {
                 foreach ($Prefixes as $Prefix) {
                     $FieldName = "{$Prefix}.{$Category['CategoryID']}";
                     $Value = $Sender->Form->getFormValue($FieldName, null);
                     if (!$Value) {
                         $Value = null;
                     }
                     $Set[$FieldName] = $Value;
                 }
             }
         }
         $Sender->setData('CategoryNotifications', $Categories);
         if ($PostBack) {
             UserModel::setMeta($Sender->User->UserID, $Set, 'Preferences.');
         }
     }
 }
 /**
  * Edit user's preferences (mostly notification settings).
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Unique identifier, possibly username or ID.
  * @param string $Username .
  * @param int $UserID Unique identifier.
  */
 public function preferences($UserReference = '', $Username = '', $UserID = '')
 {
     $this->addJsFile('profile.js');
     $Session = Gdn::session();
     $this->permission('Garden.SignIn.Allow');
     // Get user data
     $this->getUserInfo($UserReference, $Username, $UserID, true);
     $UserPrefs = Gdn_Format::unserialize($this->User->Preferences);
     if ($this->User->UserID != $Session->UserID) {
         $this->permission(array('Garden.Users.Edit', 'Moderation.Profiles.Edit'), false);
     }
     if (!is_array($UserPrefs)) {
         $UserPrefs = array();
     }
     $MetaPrefs = UserModel::GetMeta($this->User->UserID, 'Preferences.%', 'Preferences.');
     // Define the preferences to be managed
     $Notifications = array();
     if (c('Garden.Profile.ShowActivities', true)) {
         $Notifications = array('Email.WallComment' => t('Notify me when people write on my wall.'), 'Email.ActivityComment' => t('Notify me when people reply to my wall comments.'), 'Popup.WallComment' => t('Notify me when people write on my wall.'), 'Popup.ActivityComment' => t('Notify me when people reply to my wall comments.'));
     }
     $this->Preferences = array('Notifications' => $Notifications);
     // Allow email notification of applicants (if they have permission & are using approval registration)
     if (checkPermission('Garden.Users.Approve') && c('Garden.Registration.Method') == 'Approval') {
         $this->Preferences['Notifications']['Email.Applicant'] = array(t('NotifyApplicant', 'Notify me when anyone applies for membership.'), 'Meta');
     }
     $this->fireEvent('AfterPreferencesDefined');
     // Loop through the preferences looking for duplicates, and merge into a single row
     $this->PreferenceGroups = array();
     $this->PreferenceTypes = array();
     foreach ($this->Preferences as $PreferenceGroup => $Preferences) {
         $this->PreferenceGroups[$PreferenceGroup] = array();
         $this->PreferenceTypes[$PreferenceGroup] = array();
         foreach ($Preferences as $Name => $Description) {
             $Location = 'Prefs';
             if (is_array($Description)) {
                 list($Description, $Location) = $Description;
             }
             $NameParts = explode('.', $Name);
             $PrefType = val('0', $NameParts);
             $SubName = val('1', $NameParts);
             if ($SubName != false) {
                 // Save an array of all the different types for this group
                 if (!in_array($PrefType, $this->PreferenceTypes[$PreferenceGroup])) {
                     $this->PreferenceTypes[$PreferenceGroup][] = $PrefType;
                 }
                 // Store all the different subnames for the group
                 if (!array_key_exists($SubName, $this->PreferenceGroups[$PreferenceGroup])) {
                     $this->PreferenceGroups[$PreferenceGroup][$SubName] = array($Name);
                 } else {
                     $this->PreferenceGroups[$PreferenceGroup][$SubName][] = $Name;
                 }
             } else {
                 $this->PreferenceGroups[$PreferenceGroup][$Name] = array($Name);
             }
         }
     }
     // Loop the preferences, setting defaults from the configuration.
     $CurrentPrefs = array();
     foreach ($this->Preferences as $PrefGroup => $Prefs) {
         foreach ($Prefs as $Pref => $Desc) {
             $Location = 'Prefs';
             if (is_array($Desc)) {
                 list($Desc, $Location) = $Desc;
             }
             if ($Location == 'Meta') {
                 $CurrentPrefs[$Pref] = val($Pref, $MetaPrefs, false);
             } else {
                 $CurrentPrefs[$Pref] = val($Pref, $UserPrefs, c('Preferences.' . $Pref, '0'));
             }
             unset($MetaPrefs[$Pref]);
         }
     }
     $CurrentPrefs = array_merge($CurrentPrefs, $MetaPrefs);
     $CurrentPrefs = array_map('intval', $CurrentPrefs);
     $this->setData('Preferences', $CurrentPrefs);
     if (UserModel::noEmail()) {
         $this->PreferenceGroups = self::_removeEmailPreferences($this->PreferenceGroups);
         $this->PreferenceTypes = self::_removeEmailPreferences($this->PreferenceTypes);
         $this->setData('NoEmail', true);
     }
     $this->setData('PreferenceGroups', $this->PreferenceGroups);
     $this->setData('PreferenceTypes', $this->PreferenceTypes);
     $this->setData('PreferenceList', $this->Preferences);
     if ($this->Form->authenticatedPostBack()) {
         // Get, assign, and save the preferences.
         $NewMetaPrefs = array();
         foreach ($this->Preferences as $PrefGroup => $Prefs) {
             foreach ($Prefs as $Pref => $Desc) {
                 $Location = 'Prefs';
                 if (is_array($Desc)) {
                     list($Desc, $Location) = $Desc;
                 }
                 $Value = $this->Form->getValue($Pref, null);
                 if (is_null($Value)) {
                     continue;
                 }
                 if ($Location == 'Meta') {
                     $NewMetaPrefs[$Pref] = $Value ? $Value : null;
                     if ($Value) {
                         $UserPrefs[$Pref] = $Value;
                         // dup for notifications code.
                     }
                 } else {
                     if (!$CurrentPrefs[$Pref] && !$Value) {
                         unset($UserPrefs[$Pref]);
                         // save some space
                     } else {
                         $UserPrefs[$Pref] = $Value;
                     }
                 }
             }
         }
         $this->UserModel->savePreference($this->User->UserID, $UserPrefs);
         UserModel::setMeta($this->User->UserID, $NewMetaPrefs, 'Preferences.');
         $this->setData('Preferences', array_merge($this->data('Preferences', array()), $UserPrefs, $NewMetaPrefs));
         if (count($this->Form->errors() == 0)) {
             $this->informMessage(sprite('Check', 'InformSprite') . t('Your preferences have been saved.'), 'Dismissable AutoDismiss HasSprite');
         }
     } else {
         $this->Form->setData($CurrentPrefs);
     }
     $this->title(t('Notification Preferences'));
     $this->_setBreadcrumbs($this->data('Title'), $this->canonicalUrl());
     $this->render();
 }