Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
ac365767
Commit
ac365767
authored
Nov 24, 2015
by
Robert Lyon
Committed by
Gerrit Code Review
Nov 24, 2015
Browse files
Merge "Base institution.name value on the institution's display name"
parents
12fb5df1
8a1c897a
Changes
2
Hide whitespace changes
Inline
Side-by-side
htdocs/admin/users/institutions.php
View file @
ac365767
...
...
@@ -653,26 +653,9 @@ EOF;
exit
;
}
// Generate random lower-case alpha-only institution name.
function
generate_institution_name
()
{
$i
=
substr
(
str_shuffle
(
"abcdefghijklmnopqrstuvwxyz"
),
0
,
6
);
if
(
$institution
=
get_record
(
'institution'
,
'name'
,
$i
))
{
// try again
generate_institution_name
();
}
else
{
return
$i
;
}
}
function
institution_validate
(
Pieform
$form
,
$values
)
{
global
$USER
,
$institution
,
$add
;
// Automatically generate institution name when adding new institution
if
(
$add
)
{
$institution
=
generate_institution_name
();
}
if
(
$USER
->
get
(
'admin'
)
||
get_config_plugin
(
'artefact'
,
'file'
,
'institutionaloverride'
))
{
if
(
get_config_plugin
(
'artefact'
,
'file'
,
'maxquotaenabled'
)
&&
get_config_plugin
(
'artefact'
,
'file'
,
'maxquota'
)
<
$values
[
'defaultquota'
])
{
$form
->
set_error
(
'defaultquota'
,
get_string
(
'maxquotatoolow'
,
'artefact.file'
));
...
...
@@ -724,6 +707,7 @@ function institution_submit(Pieform $form, $values) {
db_begin
();
// Update the basic institution record...
if
(
$add
)
{
$institution
=
generate_institution_name
(
$values
[
'displayname'
]);
$newinstitution
=
new
Institution
();
$newinstitution
->
initialise
(
$institution
,
$values
[
'displayname'
]);
$institution
=
$newinstitution
->
name
;
...
...
htdocs/lib/web.php
View file @
ac365767
...
...
@@ -4432,6 +4432,41 @@ function generate_urlid($dirty, $default, $minlength=3, $maxlength=100) {
return
$s
;
}
/**
* Generate a valid name for the institution.name column, based on the specified display name
*
* @param string $displayname
* @return string
*/
function
generate_institution_name
(
$displayname
)
{
// iconv can crash on strings that are too long, so truncate before converting
$basename
=
mb_substr
(
$displayname
,
0
,
255
);
$basename
=
iconv
(
'UTF-8'
,
'ASCII//TRANSLIT'
,
$displayname
);
$basename
=
strtolower
(
$basename
);
$basename
=
preg_replace
(
'/[^a-z]/'
,
''
,
$basename
);
if
(
strlen
(
$basename
)
<
2
)
{
$basename
=
'inst'
.
$basename
;
}
else
{
$basename
=
substr
(
$basename
,
0
,
255
);
}
// Make sure the name is unique. If it is not, add a suffix and see if
// that makes it unique
$finalname
=
$basename
;
$suffix
=
'a'
;
while
(
record_exists
(
'institution'
,
'name'
,
$finalname
))
{
// Add the suffix but make sure the name length doesn't go over 255
$finalname
=
substr
(
$basename
,
0
,
255
-
strlen
(
$suffix
))
.
$suffix
;
// Will iterate a-z, aa-az, ba-bz, etc.
// See: http://php.net/manual/en/language.operators.increment.php
$suffix
++
;
}
return
$finalname
;
}
/**
* Sorts an array by one of the value fields
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment