Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How to restrict a participants on the basic of survey attempts?

  • siddhantwankar
  • siddhantwankar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #147272 by siddhantwankar
Hi,

I have one query If any participants is in CPDB. We can add that participants to various survey to participate in survey, OK.

If I have for Ex. Mr. X is in my CPDB and he is enrolled in 5 different survey. But the condition is that, he can only attempts any 3 surveys out of 5 in one month. after one month he is able to attempt remaining survey.

So how can I restrict those participants according to above conditions to attempt surveys.

Thanks & Regards
Siddhant Wankar
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #147284 by DenisChenu
Not sure, maybe using beforeSurveyPage : test the number of allowed surveys for this participant, close the token if 3 is already used.
Need PHP development.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • siddhantwankar
  • siddhantwankar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #147297 by siddhantwankar
Thank you Denis

I know with the php development it can be solve but at the initial stage can we use CPDB Participant's survey information from where we can get the option for current no of submitted survey (completed survey). And from that it can be possible to avoid those participants in survey.

So, how do I link-up it with quota or using a logical condition for a first question to attempt in survey?
Thanks & Regards
Siddhant Wankar
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #147299 by DenisChenu
Link between token table and CPDB are done (don't remind exactly but can be found in code).
About "quota" : why not a new column 'maxSurvey' in CPDB ?

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • siddhantwankar
  • siddhantwankar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #147309 by siddhantwankar
Yes Denis,
But how can we link this CPDB with token table for attempts. I have share one of my participants with different survey and complete submission in one survey. So is that get any use.

Regards
Siddhant
Attachments:
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #147319 by DenisChenu

DenisChenu wrote: Link between token table and CPDB are done (don't remind exactly but can be found in code).

Maybe somewhere here : github.com/LimeSurvey/LimeSurvey/blob/ma...rticipantsaction.php or github.com/LimeSurvey/LimeSurvey/blob/ma...ers/admin/tokens.php

Look at the token DB : if i remind there are a column for cpdb

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: siddhantwankar
The topic has been locked.
  • siddhantwankar
  • siddhantwankar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #147373 by siddhantwankar
OK Denis,

I added one attribute in CPDB as "Max Survey" and set a value for a one participant who is added in 6 different surveys with one survey is in complete status. So with the help of attribute value (Max survey) and the no of completed surveys can we restrict this participants, from attempting a survey.
The topic has been locked.
  • siddhantwankar
  • siddhantwankar's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 3 months ago #147375 by siddhantwankar
In which function or file our token get validate for a survey participant table.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #147381 by DenisChenu
@siddhantwankar : you have to create your own code .... i'm not your dev.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: holch
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
7 years 3 months ago - 7 years 3 months ago #147388 by LouisGac

siddhantwankar wrote: In which function or file our token get validate for a survey participant table.


A quick how to:

1. You go to the page that interest you (token submission)
2. You look at the form submission URL ("index.php/{SID}")
3. The route doesn't indicate any controller, so it's the default controller.
4. You google "Yii Default controller", and you find that the params to define the default controller is: 'defaultController'
5. You grep 'defaultController' and find that is defined in application/config/internal.php
6. In internal config, you find out that default controller for front end is application/controllers/survey/index.php

That means that your Token form is submitted to that file:
github.com/LimeSurvey/LimeSurvey/blob/ma...ers/survey/index.php

7. You go back to the token form, and find that the token is submitted as a POST param.
9. You go application/controllers/survey/index.php and look for where the POST request is parsed. You find this line:
github.com/LimeSurvey/LimeSurvey/blob/ma...survey/index.php#L89
Code:
        $param = $this->_getParameters(func_get_args(), $_POST);

10. Now that you found that all the POST params are inside an array called $param, and that your token input in the token form is named 'token', you look for $param in application/controllers/survey/index.php. That lead you to that line:
github.com/LimeSurvey/LimeSurvey/blob/ma...survey/index.php#L95
Code:
        $clienttoken = trim($param['token']);


So now, you know that the token user submited is inside the variable $clienttoken.

11. From here, you look how it is used:
- as a param for _isClientTokenDifferentFromSessionToken() : clearly not what you are looking for.
- As a test inside inside a if statement testing that survey is finished : clearly not what you are looking for.
- To fill a variable called token in a statement commented as "// Get token" : that's what you're looking for.

12. So now, you look how this variable $token is used, and bingo, you find this statment:
github.com/LimeSurvey/LimeSurvey/blob/ma.../index.php#L383-L387
Code:
            if ($thissurvey['alloweditaftercompletion'] == 'Y' ) {
                $tokenInstance = Token::model($surveyid)->findByAttributes(array('token' => $token));
            } else {
                $tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
            }

It means there are two ways to validate token, depending if survey allow edition of a response. If yes, then :
Code:
$tokenInstance = Token::model($surveyid)->findByAttributes(array('token' => $token));

Only checks if the token exist in the Token model (see Yii documentation for findBytAttributes in an AR instance)

else:
Code:
 $tokenInstance = Token::model($surveyid)->usable()->incomplete()->findByAttributes(array('token' => $token));
call to the token model, and use is usable+incomplete scope:
github.com/LimeSurvey/LimeSurvey/blob/ma.../Token.php#L298-L305
which just add conditions to check that the survey has not been completed already, and that it's valid.


So, as you see, it's a long work. As Denis told you, we're not your personal programmers. If you can't do that kind of operations, you should consider hiring a LimeSurvey partner. Also, now that I helped you, you should considering making a donation to LimeSurvey ;-)
Last edit: 7 years 3 months ago by LouisGac.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 3 months ago #147389 by DenisChenu
@LouisGac : i think more on beforeSurvayPage evnt :
1st : test token
2nd : search the participant associated with this token
3rd : count the number of already done survey (this month for example)
4tth : redirect or show page with die if user survey > user max survey.
Some code example : framagit.org/SondagePro-LimeSurvey-plugi...rSurveyText.php#L175 or framagit.org/SondagePro-LimeSurvey-plugi...enByResponse.php#L93 or ....
But hacking code is a solution too ....

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
7 years 3 months ago #147392 by LouisGac
plugin for sure is the best way to do it. I was just answering his question:

siddhantwankar wrote: In which function or file our token get validate for a survey participant table.

The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose