Anonymous Login
2016-12-09 00:56 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
04895User patchesSurvey at runtimepublic2012-06-21 13:23
ReporterDenisChenu 
Assigned Toc_schmitz 
PrioritynormalSeverityminor 
StatusclosedResolutionfixed 
Product Version1.91 
Target Version1.91Fixed in Version1.91 
Summary04895: Allow multi Quota for List (radio) question type and other single select
DescriptionWith Quota we test if each arte equal of the quota question.

the test are
( questisXgidXqidA = QuotaValue1 ) AND ( questisXgidXqidB = QuotaValue2 )

It's OK for a lot of quota, but not for the same questisXgidXqid .

You can never have
( questisXgidXqidA = QuotaValue1 ) AND ( questisXgidXqidA = QuotaValue2 )

This patch offer the possibility to have OR condition in quota.
if questisXgidXqid are the same, then it put OR, else AND.

( questisXgidXqidA = QuotaValue1 OR questisXgidXqidA = QuotaValue2 ) AND ( questisXgidXqidB = QuotaValue2 )

Patch for 9710 svn version
Steps To ReproduceImport survey included, quota can't be accessed because there are for the same list radio question.
(sorry survey in french)
Additional InformationI can integrate for 1.91 or see for 1.92. But i think it can be good for 1.91.

:)
TagsNo tags attached.
Complete LimeSurvey version number (& build)9710
Attached Files
  • ? file icon limesurvey_survey_quota.lss (23,462 bytes) 2011-01-22 18:20
  • diff file icon patch_04895.diff (5,547 bytes) 2011-01-22 18:28 -
    diff -u limesurvey-svn/common_functions.php developpement-ls/common_functions.php
    --- limesurvey-svn/common_functions.php	2011-01-22 15:11:27.000000000 +0100
    +++ developpement-ls/common_functions.php	2011-01-22 17:38:49.000000000 +0100
    @@ -7095,26 +7095,27 @@
         count($quota['members']) > 0)
         {
             $fields_list = array(); // Keep a list of fields for easy reference
    +        // construct an array of value for each $quota['members']['fieldnames']
             unset($querycond);
    -
    +        $fields_query = array();
             foreach($quota['members'] as $member)
             {
    -            $fields_query = array();
    -            $select_query = " (";
                 foreach($member['fieldnames'] as $fieldname)
                 {
    -                $fields_list[] = $fieldname;
    -                $fields_query[] = db_quote_id($fieldname)." = '{$member['value']}'";
    -                // Incase of multiple fields for an answer - only needs to match once.
    -                $select_query.= implode(' OR ',$fields_query).' )';
    -                $querycond[] = $select_query;
    -                unset($fields_query);
    +                if (!in_array($fieldname,$fields_list)){
    +                    $fields_list[] = $fieldname;
    +                    $fields_query[$fieldname] = array();
    +                }
    +                $fields_query[$fieldname][]= db_quote_id($fieldname)." = '{$member['value']}'";
                 }
    -
             }
    -        //FOR MYSQL?
    -        $querysel = "SELECT count(id) as count FROM ".db_table_name('survey_'.$surveyid)." WHERE ".implode(' AND ',$querycond)." "." AND submitdate !=''";
    -        //FOR POSTGRES?
    +        
    +        foreach($fields_list as $fieldname)
    +        {
    +            $select_query = " ( ".implode(' OR ',$fields_query[$fieldname]).' )';
    +            $querycond[] = $select_query;
    +        }
    +
             $querysel = "SELECT count(id) as count FROM ".db_table_name('survey_'.$surveyid)." WHERE ".implode(' AND ',$querycond)." "." AND submitdate IS NOT NULL";
             $result = db_execute_assoc($querysel) or safe_die($connect->ErrorMsg()); //Checked
             $quota_check = $result->FetchRow();
    diff -u limesurvey-svn/index.php developpement-ls/index.php
    --- limesurvey-svn/index.php	2011-01-19 17:18:13.000000000 +0100
    +++ developpement-ls/index.php	2011-01-22 18:05:28.000000000 +0100
    @@ -3151,29 +3151,48 @@
                     $fields_list = array(); // Keep a list of fields for easy reference
                     $y=0;
                     // We need to make the conditions for the select statement here
    -                // I'm supporting more than one field for a question/answer, not sure if this is necessary.
                     unset($querycond);
    +                // fill the array of value and query for each fieldnames
    +                $fields_value_array = array();
    +                $fields_query_array = array();
                     foreach($quota['members'] as $member)
                     {
    -                    $fields_query = array();
    -                    $select_query = " (";
                         foreach($member['fieldnames'] as $fieldname)
                         {
    -                        $fields_list[] = $fieldname;
    -                        $fields_query[] = db_quote_id($fieldname)." = '{$member['value']}'";
    -                        // Check which quota fields and codes match in session, for later use.
    -                        // Incase of multiple fields for an answer - only needs to match once.
    -                        if (isset($_SESSION[$fieldname]) && $_SESSION[$fieldname] == $member['value'])
    +
    +                        if (!in_array($fieldname,$fields_list))
                             {
    -                            $quota_info[$x]['members'][$y]['insession'] = "true";
    +                            $fields_list[] = $fieldname;
    +                            $fields_value_array[$fieldname] = array();
    +                            $fields_query_array[$fieldname] = array();
                             }
    +                        $fields_value_array[$fieldname][]=$member['value'];
    +                        $fields_query_array[$fieldname][]= db_quote_id($fieldname)." = '{$member['value']}'";
                         }
    -                    $select_query.= implode(' OR ',$fields_query).' )';
    +
    +                }
    +                // fill the $querycond array with each fields_query grouped by fieldname
    +                foreach($fields_list as $fieldname)
    +                {
    +                    $select_query = " ( ".implode(' OR ',$fields_query_array[$fieldname]).' )';
                         $querycond[] = $select_query;
    -                    unset($fields_query);
    -                    $y++;
                     }
    -
    +                // Test if the fieldname is in the array of value in the session
    +                foreach($quota['members'] as $member)
    +                {
    +                    foreach($member['fieldnames'] as $fieldname)
    +                    {
    +                	if (isset($_SESSION[$fieldname]))
    +                        {
    +                        if (in_array($_SESSION[$fieldname],$fields_value_array[$fieldname])){
    +                            $quota_info[$x]['members'][$y]['insession'] = "true";
    +                            }
    +                        }
    +                    }
    +                   $y++;
    +                }
    +                unset($fields_query_array);unset($fields_value_array);
    +                
                     // Lets only continue if any of the quota fields is in the posted page
                     $matched_fields = false;
                     if (isset($_POST['fieldnames']))
    
    diff file icon patch_04895.diff (5,547 bytes) 2011-01-22 18:28 +

-Relationships
+Relationships

-Notes

~14571

c_schmitz (administrator)

Thank you!
+Notes

-Issue History
Date Modified Username Field Change
2011-01-22 18:20 DenisChenu New Issue
2011-01-22 18:20 DenisChenu File Added: limesurvey_survey_quota.lss
2011-01-22 18:22 DenisChenu File Added: patch_04895.diff
2011-01-22 18:28 DenisChenu File Deleted: patch_04895.diff
2011-01-22 18:28 DenisChenu File Added: patch_04895.diff
2011-03-28 02:00 c_schmitz Status new => resolved
2011-03-28 02:00 c_schmitz Fixed in Version => 1.91
2011-03-28 02:00 c_schmitz Resolution open => fixed
2011-03-28 02:00 c_schmitz Assigned To => c_schmitz
2011-03-28 02:00 c_schmitz Note Added: 14571
2012-06-21 13:23 c_schmitz Status resolved => closed
+Issue History