Commit f28a0514 authored by theo lem's avatar theo lem
Browse files

Merge branch 'form-per-user-limitation' into 'master'

Form per user limitation

See merge request framasoft/framaforms!63
parents a8121241 85cd9439
......@@ -57,7 +57,7 @@ function framaforms_install () {
variable_set('framaforms_deletion_period_value', 9); // default expiration-deletion time interval
variable_set('framaforms_notification_period_value', 2); // default notification-expiration time interval
variable_set('site_contact_url', 'https://contact.framasoft.org/#framaforms');
variable_set('framaforms_forms_per_user_limit', 200);
/* various other custom manipulation */
/* Hide Drupal default banner */
$theme_settings = variable_get('theme_settings');
......
......@@ -45,6 +45,47 @@ function framaforms_menu () {
return $items;
}
/**
* Implements hook_menu_alter
*
* @param $items : menu items
* @return void
*/
function framaforms_menu_alter (&$items) {
$items['node/add/form1']['access callback'] = 'framaforms_check_users_forms';
}
/**
* Acess callback for /node/add/form1 : forbids a user to create over a given number of forms.
*
* @return void
*/
function framaforms_check_users_forms () {
global $user; // the current user
// if the user is not logged in, deny access
if($user->uid === 0){
return FALSE;
}
// If the user is admin, grant access (admin is master here)
if($user->uid === 1){
return TRUE;
}
// Get the user's total number of forms
$results = db_select('node', 'n')
->fields('n')
->condition('type', 'form1')
->condition('uid', $user->uid)
->countQuery()
->execute()
->fetchField();
if($results >= variable_get('framaforms_forms_per_user_limit')){
drupal_set_message(t("Your account has reached this site's maximum number of forms. Please delete some of your unused forms in 'My forms' before trying to create a new one."), 'warning');
drupal_set_message(t("This site's allows to create the maximum following number of forms : "). variable_get('framaforms_forms_per_user_limit'), 'warning');
return FALSE;
}
return TRUE;
}
/**
* Implements hook_block_info : defines Framaforms-specific blocks.
*
......
......@@ -146,6 +146,18 @@ function framaforms_config_form ($form, &$form_state) {
'#description' => t('Lien vers une éventuelle page de support pour vos utilisateurs. Cette URL sera reprise dans les messages d\'aide à la création des formulaires.'),
'#required' => TRUE,
);
$form['limitations_intertitle'] = array(
'#type' => 'item',
'#markup' => t('<h3>Limitations</h3>'),
);
$form['framaforms_forms_per_user_limit'] = array(
'#type' => 'textfield',
'#title' => t('Maximum number of form per user'),
'#default_value' => variable_get('framaforms_forms_per_user_limit'),
'#size' => 11,
'#maxlength' => 11,
'#required' => TRUE,
);
$form['expiration_intertitle'] = array(
'#type' => 'item',
'#markup' => t('<h3>Expiration des formulaires</h3>'),
......@@ -191,7 +203,7 @@ function framaforms_config_form ($form, &$form_state) {
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Enregistrer'),
'#value' => t('Submit'),
'#submit' => array('system_settings_form_submit'),
);
return $form;
......@@ -223,6 +235,11 @@ function framaforms_config_form_validate ($form, &$form_state) {
drupal_set_message(t("Erreur dans les valeurs administratives de Framaforms."));
form_set_error('framaforms_expiration_period_default_value', t("La période d'expiration doit être numérique."));
}
if(!is_numeric($values['framaforms_forms_per_user_limit'])){
drupal_set_message(t("Erreur dans les valeurs administratives de Framaforms."));
form_set_error('framaforms_forms_per_user_limit', t("The number of form per user must be numeric."));
}
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment