本文整理汇总了PHP中UserGroup::setRoleId方法的典型用法代码示例。如果您正苦于以下问题:PHP UserGroup::setRoleId方法的具体用法?PHP UserGroup::setRoleId怎么用?PHP UserGroup::setRoleId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserGroup
的用法示例。
在下文中一共展示了UserGroup::setRoleId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mockEffect
/**
* Callback method that will be called in place of the effect()
* method of a mock policy.
* @return integer AUTHORIZATION_PERMIT
*/
public function mockEffect()
{
// Add a user group to the authorized context
// of the authorization context manipulation policy.
$policy = $this->getAuthorizationContextManipulationPolicy();
$userGroup = new UserGroup();
$userGroup->setRoleId(ROLE_ID_TEST);
$policy->addAuthorizedContextObject(ASSOC_TYPE_USER_GROUP, $userGroup);
return AUTHORIZATION_PERMIT;
}
示例2: createData
/**
* Create initial required data.
* @return boolean
*/
function createData()
{
if ($this->getParam('manualInstall')) {
// Add insert statements for default data
// FIXME use ADODB data dictionary?
$this->executeSQL(sprintf('INSERT INTO site (primary_locale, installed_locales) VALUES (\'%s\', \'%s\')', $this->getParam('locale'), join(':', $this->installedLocales)));
$this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'title', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
$this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactName', 'string', addslashes(Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), $this->getParam('locale')));
$this->executeSQL(sprintf('INSERT INTO site_settings (setting_name, setting_type, setting_value, locale) VALUES (\'%s\', \'%s\', \'%s\', \'%s\')', 'contactEmail', 'string', addslashes($this->getParam('adminEmail')), $this->getParam('locale')));
$this->executeSQL(sprintf('INSERT INTO users (user_id, username, first_name, last_name, password, email, date_registered, date_last_login) VALUES (%d, \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')', 1, $this->getParam('adminUsername'), $this->getParam('adminUsername'), $this->getParam('adminUsername'), Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')), $this->getParam('adminEmail'), Core::getCurrentDate(), Core::getCurrentDate()));
$this->executeSQL(sprintf('INSERT INTO roles (press_id, user_id, role_id) VALUES (%d, %d, %d)', 0, 1, ROLE_ID_SITE_ADMIN));
// Install email template list and data for each locale
$emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
foreach ($emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename(), true) as $sql) {
$this->executeSQL($sql);
}
foreach ($this->installedLocales as $locale) {
foreach ($emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale), true) as $sql) {
$this->executeSQL($sql);
}
}
} else {
// Add initial site data
$locale = $this->getParam('locale');
$siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
$site = new Site();
$site->setRedirect(0);
$site->setMinPasswordLength(INSTALLER_DEFAULT_MIN_PASSWORD_LENGTH);
$site->setPrimaryLocale($locale);
$site->setInstalledLocales($this->installedLocales);
$site->setSupportedLocales($this->installedLocales);
if (!$siteDao->insertSite($site)) {
$this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
return false;
}
// Install email template list and data for each locale
$emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
$emailTemplateDao->installEmailTemplates($emailTemplateDao->getMainEmailTemplatesFilename());
foreach ($this->installedLocales as $locale) {
$emailTemplateDao->installEmailTemplateData($emailTemplateDao->getMainEmailTemplateDataFilename($locale));
}
$siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
$siteSettingsDao->updateSetting('title', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
$siteSettingsDao->updateSetting('contactName', array($locale => Locale::translate(INSTALLER_DEFAULT_SITE_TITLE)), null, true);
$siteSettingsDao->updateSetting('contactEmail', array($locale => $this->getParam('adminEmail')), null, true);
// Add initial site administrator user
$userDao =& DAORegistry::getDAO('UserDAO', $this->dbconn);
$user = new User();
$user->setUsername($this->getParam('adminUsername'));
$user->setPassword(Validation::encryptCredentials($this->getParam('adminUsername'), $this->getParam('adminPassword'), $this->getParam('encryption')));
$user->setFirstName($user->getUsername());
$user->setLastName('');
$user->setEmail($this->getParam('adminEmail'));
if (!$userDao->insertUser($user)) {
$this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
return false;
}
// Create an admin user group
Locale::requireComponents(array(LOCALE_COMPONENT_OMP_DEFAULT_SETTINGS));
$userGroupDao =& DAORegistry::getDao('UserGroupDAO', $this->dbconn);
$adminUserGroup = new UserGroup();
$adminUserGroup->setRoleId(ROLE_ID_SITE_ADMIN);
$adminUserGroup->setContextId(0);
$adminUserGroup->setPath(ROLE_PATH_SITE_ADMIN);
$adminUserGroup->setDefault(true);
foreach ($this->installedLocales as $locale) {
$name = Locale::translate('default.groups.name.siteAdmin', array(), $locale);
$namePlural = Locale::translate('default.groups.plural.siteAdmin', array(), $locale);
$adminUserGroup->setData('name', $name, $locale);
$adminUserGroup->setData('namePlural', $namePlural, $locale);
}
if (!$userGroupDao->insertUserGroup($adminUserGroup)) {
$this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
return false;
}
// put the installer into this user group
if (!$userGroupDao->assignUserToGroup($user->getId(), $adminUserGroup->getId())) {
$this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
return false;
}
}
return true;
}