Permission to create, change, and delete notification preferences through the PREFERENCES endpoint.

@param bool $define_preferences

@throws \Moip\Exceptions\InvalidArgumentException

@return $this
355413
public function setDefinePreferences($define_preferences)
    {
        if (!is_bool($define_preferences)) {
            throw new InvalidArgumentException('$define_preferences deve ser boolean, foi passado '.gettype($define_preferences));
        }

        if ($define_preferences === true) {
            $this->setScope(self::DEFINE_PREFERENCES);
        }

        return $this;
    }
301741
public function setGrantableRolesAtHq($grantableRolesAtHq)
    {
        $allowedValues = $this->getGrantableRolesAtHqAllowableValues();
        if (!is_null($grantableRolesAtHq) && array_diff($grantableRolesAtHq, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'grantableRolesAtHq', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['grantableRolesAtHq'] = $grantableRolesAtHq;

        return $this;
    }
1247434
def users_set_preferences(self, user_id, data, **kwargs):
        """"""
        return self.__call_api_post('users.setPreferences', userId=user_id, data=data, kwargs=kwargs)
168299
public function setSelfAllowed(string $directive = '', bool $allow = false): self
    {
        if (!\in_array($directive, self::$directives)) {
            throw new \Exception('Directive ' . $directive . ' does not exist');
        }
        $this->policies[$directive]['self'] = $allow;
        return $this;
    }
808601
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('Garden.Users.Edit');
      
      if (!is_array($UserPrefs))
         $UserPrefs = array();
      $MetaPrefs = UserModel::GetMeta($this->User->UserID, 'Preferences.%', 'Preferences.');

      // Define the preferences to be managed
      $this->Preferences = array(
         '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.')
         )
      );
      
      // 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 = GetValue('0', $NameParts);
            $SubName = GetValue('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] = GetValue($Pref, $MetaPrefs, FALSE);
            else
               $CurrentPrefs[$Pref] = GetValue($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();
   }
787045
public static function setPreference($setting_name, $setting_value): void
    {
        // The database column is only this long.
        $setting_value = mb_substr($setting_value, 0, 2000);

        if (self::getPreference($setting_name) !== $setting_value) {
            DB::table('site_setting')->updateOrInsert([
                'setting_name' => $setting_name,
            ], [
                'setting_value' => $setting_value,
            ]);

            self::$preferences[$setting_name] = $setting_value;

            Log::addConfigurationLog('Site preference "' . $setting_name . '" set to "' . $setting_value . '"', null);
        }
    }
725203
protected function updateAdditionalConfiguration($extensionKey)
	{
        /**
         * Add Flashmessage that the configuration has to be checked
         */
        $flashMessage = GeneralUtility::makeInstance(
            'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
            'To enable the features you have to edit the extensions configuration in the Extension Manager. After the new configuration is saved please relogin to the backend to ensure the changes!',
            'Check your configuration',
            FlashMessage::NOTICE,
            true
        );
        $this->addFlashMessage($flashMessage);

        /**
         * Update configuration
         */
		$newLines = $this->getCleanAdditionalConfiguration($extensionKey);

		if (!empty(end($newLines))) {
			$newLines[] = '';
		}

		$newLines[] = '// Run configuration modifier for extension ' . $extensionKey . ' - added on ' . date(DATE_ATOM) . ' by ' . __CLASS__;
		$newLines[] = 'if (class_exists(\'Gilbertsoft\ProtectedConfig\Configuration\Modifier\')) {';
		$newLines[] = '	\Gilbertsoft\ProtectedConfig\Configuration\Modifier::processLocalConfiguration(\'' . $extensionKey . '\');';
		$newLines[] = '}';

		$this->getConfigurationManager()->writeAdditionalConfiguration($newLines);

        /**
         * Add Flashmessage that the configuration has written
         */
        $flashMessage = GeneralUtility::makeInstance(
            'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
            'Configuration successfully added to ' .
            $this->getConfigurationManager()->getAdditionalConfigurationFileLocation() .
            '.',
            'Configuration added',
            FlashMessage::OK,
            true
        );
        $this->addFlashMessage($flashMessage);
	}
17935
public function setPreferencesAttribute($preferences)
    {
        if (is_array($preferences)) {
            $preferences = json_encode($preferences);
        }

        $this->attributes['preferences'] = $preferences;
    }
727513
public function setOptions($options)
    {
        if (!is_int($options) && !is_null($options)) {
            throw new InvalidArgumentException('Invalid options.');
        }

        $this->options = $options ?: 0;

        $this->handleChangedParameters();

        return $this;
    }
496980
def notify_preference=(value)
      if value
        translated_value = "1"
      else
        translated_value = "0"
      end
      xml = Builder::XmlMarkup.new
      xml.instruct!
      xml.Request(:xmlns => "urn:sbx:apis:SbxBaseComponents") do |xml|
        connection.requester_credentials_block(xml)
        xml.SetBusinessCardNotifyPreferenceCall do |xml|
          xml.BusinessCardNotifyPreference(translated_value)
        end
      end
      response = connection.post_xml(xml)
      # TODO: Retrieve the new value to make sure it worked?
      value
    end
792871
function updatePreference(id, preference) {
    var callback = preConditions.getCallback(arguments[arguments.length - 1]);

    showWarning();

    // Add the id to the preferece object
    preference.id = id;

    return preferencesModule.update(preference, callback);
  }
66436
public function setPreference(string $setting_name, string $setting_value): UserInterface
    {
        if ($this->user_id !== 0 && $this->getPreference($setting_name) !== $setting_value) {
            DB::table('user_setting')->updateOrInsert([
                'user_id'      => $this->user_id,
                'setting_name' => $setting_name,
            ], [
                'setting_value' => $setting_value,
            ]);

            $this->preferences[$setting_name] = $setting_value;
        }

        app('cache.array')->forget('user_setting' . $this->user_id);

        return $this;
    }
809618
protected function _setdirpermiss() {
		$this->out(__d('cake_installer', 'Setting permissions'));
		$this->hr();

		$result = true;
		if ($this->InstallerCheck->isOsWindows()) {
			$this->out(__d('cake_installer', 'Server OS is Windows. Change permissions skipped.'));

			return $result;
		}

		$path = $this->path;
		$tempDir = $path . 'tmp';
		$mode = 0760;
		$dmode = decoct($mode);
		$fileConfig = $path . 'Config' . DS . 'config.php';
		if (!$this->_changeDirMode($tempDir, $mode)) {
			$this->out('<error>' . __d('cake_installer', 'Could not change the mode on \'%s\' to \'%s\'', $tempDir, $dmode) . '</error>');
			$this->out('<debug>chmod -R ' . $dmode . ' ' . $tempDir . '</debug>', 1, Shell::VERBOSE);
			$result = false;
		} else {
			$this->out('<success>' . __d('cake_installer', 'Access permissions on \'%s\' changed to \'%s\' successfully.', $tempDir, $dmode) . '</success>');
		}

		if (!chmod($fileConfig, $mode)) {
			$this->out('<error>' . __d('cake_installer', 'Could not change the mode on \'%s\' to \'%s\'', $fileConfig, $dmode) . '</error>');
			$this->out('<debug>chmod ' . $dmode . ' ' . $fileConfig . '</debug>', 1, Shell::VERBOSE);
			$result = false;
		} else {
			$this->out('<success>' . __d('cake_installer', 'Access permissions on \'%s\' changed to \'%s\' successfully.', $fileConfig, $dmode) . '</success>');
		}

		$apacheUser = $this->InstallerCheck->getWebSrvUser();
		if (empty($apacheUser)) {
			$this->out('<error>' . __d('cake_installer', 'Error getting the username of the web server process') . '</error>');

			return false;
		}

		if (!$this->_changeDirOwner($tempDir, $apacheUser)) {
			$this->out('<error>' . __d('cake_installer', 'Could not change owner on \'%s\' to \'%s\'', $tempDir . DS . '*.*', $apacheUser) . '</error>');
			$this->out('<debug>find ' . $tempDir . ' -type f | xargs chown ' . $apacheUser . '</debug>', 1, Shell::VERBOSE);
		} else {
			$this->out('<success>' . __d('cake_installer', 'Owner of \'%s\' changed to \'%s\' successfully.', $tempDir . DS . '*.*', $apacheUser) . '</success>');
		}

		/*$apacheUserGroup = $this->InstallerCheck->getWebSrvUserGroup($apacheUser);
		if (empty($apacheUserGroup)) {
			$this->out('<error>' . __d('cake_installer', 'Error getting the group of user the web server process') . '</error>');
			return false;
		}

		if (!$this->_changeDirGroupOwner($tempDir, $apacheUserGroup)) {
			$this->out('<error>' . __d('cake_installer', 'Could not change group on \'%s\' to \'%s\'', $tempDir . DS . '*.*', $apacheUserGroup) . '</error>');
			$this->out('<debug>chgrp -R ' . $apacheUserGroup . ' ' . $tempDir . '</debug>', 1, Shell::VERBOSE);
		} else {
			$this->out('<success>' . __d('cake_installer', 'Group of \'%s\' changed to \'%s\' successfully.', $tempDir . DS . '*.*', $apacheUserGroup) . '</success>');
		}

		//@codingStandardsIgnoreStart
		if (!@chgrp($fileConfig, $apacheUserGroup)) {
			//@codingStandardsIgnoreEnd
			$this->out('<error>' . __d('cake_installer', 'Could not change group on \'%s\' to \'%s\'', $fileConfig, $apacheUserGroup) . '</error>');
			$this->out('<debug>chgrp ' . $apacheUserGroup . ' ' . $fileConfig . '</debug>', 1, Shell::VERBOSE);
			$result = false;
		} else {
			$this->out('<success>' . __d('cake_installer', 'Group of \'%s\' changed to \'%s\' successfully.', $fileConfig, $apacheUserGroup) . '</success>');
		}*/

		//@codingStandardsIgnoreStart
		if (!@chown($fileConfig, $apacheUser)) {
			//@codingStandardsIgnoreEnd
			$this->out('<error>' . __d('cake_installer', 'Could not change owner on \'%s\' to \'%s\'', $fileConfig, $apacheUser) . '</error>');
			$this->out('<debug>chown ' . $apacheUser . ' ' . $fileConfig . '</debug>', 1, Shell::VERBOSE);
			$result = false;
		} else {
			$this->out('<success>' . __d('cake_installer', 'Owner of \'%s\' changed to \'%s\' successfully.', $fileConfig, $apacheUser) . '</success>');
		}

		return $result;
	}
69166
public static function set_user_preferences($preferences) {
        global $USER;

        $params = self::validate_parameters(self::set_user_preferences_parameters(), array('preferences' => $preferences));
        $warnings = array();
        $saved = array();

        $context = context_system::instance();
        self::validate_context($context);

        $userscache = array();
        foreach ($params['preferences'] as $pref) {
            // Check to which user set the preference.
            if (!empty($userscache[$pref['userid']])) {
                $user = $userscache[$pref['userid']];
            } else {
                try {
                    $user = core_user::get_user($pref['userid'], '*', MUST_EXIST);
                    core_user::require_active_user($user);
                    $userscache[$pref['userid']] = $user;
                } catch (Exception $e) {
                    $warnings[] = array(
                        'item' => 'user',
                        'itemid' => $pref['userid'],
                        'warningcode' => 'invaliduser',
                        'message' => $e->getMessage()
                    );
                    continue;
                }
            }

            try {
                if (core_user::can_edit_preference($pref['name'], $user)) {
                    $value = core_user::clean_preference($pref['value'], $pref['name']);
                    set_user_preference($pref['name'], $value, $user->id);
                    $saved[] = array(
                        'name' => $pref['name'],
                        'userid' => $user->id,
                    );
                } else {
                    $warnings[] = array(
                        'item' => 'user',
                        'itemid' => $user->id,
                        'warningcode' => 'nopermission',
                        'message' => 'You are not allowed to change the preference '.s($pref['name']).' for user '.$user->id
                    );
                }
            } catch (Exception $e) {
                $warnings[] = array(
                    'item' => 'user',
                    'itemid' => $user->id,
                    'warningcode' => 'errorsavingpreference',
                    'message' => $e->getMessage()
                );
            }
        }

        $result = array();
        $result['saved'] = $saved;
        $result['warnings'] = $warnings;
        return $result;
    }
425877
public function setPermissionsAttribute(array $permissions)
	{
		// Merge permissions
		$permissions = array_merge($this->getPermissions(), $permissions);

		// Loop through and adjust permissions as needed
		foreach ($permissions as $permission => &$value)
		{
			// Lets make sure their is a valid permission value
			if ( ! in_array($value = (int) $value, $this->allowedPermissionsValues))
			{
				throw new \InvalidArgumentException("Invalid value [$value] for permission [$permission] given.");
			}

			// If the value is 0, delete it
			if ($value === 0)
			{
				unset($permissions[$permission]);
			}
		}

		$this->attributes['permissions'] = ( ! empty($permissions)) ? $permissions : '';
	}
586452
public function ChangeReviewReportNotificationState()
    {
        $oGlobal = TGlobal::instance();
        $oMsgManager = TCMSMessageManager::GetInstance();
        if ($oGlobal->UserDataExists(TdbShopArticleReview::URL_PARAM_REVIEW_ID)) {
            $oReviewItem = TdbShopArticleReview::GetNewInstance();
            if ($oReviewItem->Load($oGlobal->GetUserData(TdbShopArticleReview::URL_PARAM_REVIEW_ID)) && $oReviewItem->IsOwner()) {
                $sReviewReportNotificationState = $oReviewItem->fieldSendCommentNotification;
                if ($sReviewReportNotificationState) {
                    $sReviewReportNotificationState = 0;
                } else {
                    $sReviewReportNotificationState = 1;
                }
                $oReviewItem->sqlData['send_comment_notification'] = $sReviewReportNotificationState;
                $oReviewItem->AllowEditByAll(true);
                $oReviewItem->Save();
                $oMsgManager->AddMessage(self::MSG_CONSUMER_NAME, 'ARTICLE-REVIEW-CHANGE-REPORT-NOTIFICATION-STATE-SUCCESS');
            } else {
                $oMsgManager->AddMessage(self::MSG_CONSUMER_NAME, 'ARTICLE-REVIEW-ACTION-REVIEW-NOT-FOUND');
            }
        } else {
            $oMsgManager->AddMessage(self::MSG_CONSUMER_NAME, 'ARTICLE-REVIEW-ACTION-MISSING-PARAMETER');
        }
        $this->RedirectToItemPage();
    }
692372
public function change()
    {
        $rolePermissionTable = $this->table('role_permission', ['signed' => false]);

        $rolePermissionTable->addColumn('role_id', 'integer', ['signed' => false])
            ->addColumn('permission_id', 'integer', ['signed' => false])
            ->addColumn('created_at', 'datetime')
            ->addIndex(['role_id', 'permission_id'], ['name' => 'idx_role_permission_unique', 'unique' => true])
            ->addForeignKey('role_id', 'role', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_permission_role'])
            ->addForeignKey('permission_id', 'permission', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_permission_permission'])
            ->create();
    }