Creating a new survey from plugin

More
1 year 3 months ago #176443 by andre-cavalheiro
Hello everyone, i'm developing a new plugin and its objective is the following:

When receing a new request to a custom route, create a new default if the user has the permissions to do so. Bonus points for being able to pass a few parameters to the route in order to make the survey a little dynamic (such as the title for instance). The objective is just to create a very simple survey without any questions, just the default configurations.

I've created a new route with the API's createUrl and the event NewDirectRequest . I now would like to create the survey upon receiving the request but i have not find anything in the API that does that. I also have not been able to fully understand how to pass parameters for routes created with NewDirectRequest.


Any help is appreciated, thank you very much.

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
1 year 2 months ago #177166 by andre-cavalheiro
I was able to do this by using the API's newModel and adding the surveys to the database by hand. You need to add two rows. One to the lime_surveys' table and another to the lime_surveys_languagesettings table. I'm still having some problems receiving parameters with the createUrl and NewDirectRequest methods though :(

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago #177169 by DenisChenu
I have a non public (for one year …) plugin with "auto generate survey", but i copy a survey (more easy).

And i directly use Yii model and existing LimeSurvey function. Not API

API is really poor …
// $iBaseSurvey is id of the original survey
    // $oBaseSurveyLanguage is SurveyLanguageSettings for this survey and default language
    /* Copy the survey */
    $aExcludes = array();
    $sNewSurveyName = str_replace("[BASE] ","",$oBaseSurveyLanguage->surveyls_title)." - ".date("c");
    $aExcludes['dates'] = true;
    $btranslinksfields=true;
    Yii::app()->loadHelper('export');
    $copysurveydata = surveyGetXMLData($iBaseSurvey, $aExcludes);
    if($copysurveydata) {
        Yii::app()->loadHelper('admin/import');
        $aImportResults = XMLImportSurvey('', $copysurveydata, $sNewSurveyName,NULL,$btranslinksfields);
    }
    if(!empty($aImportResults['newsid'])) {
        // And here i update SurveyLanguageSettings and some question too
    }

For the other question : show your code.

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 .
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: andre-cavalheiro

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago - 1 year 2 months ago #177174 by andre-cavalheiro
Damn, thank you so very much. This was my original idea as well, but i wasn't able to implement it! I appreaciate the answer and specially the sharing of the code. Will try to replicate.

Another question though, do you know how i can create a POST request route? I've been searching Yii documentation but no luck, i've seen some stuff that should work, but it is not in the limesurevy envirnment. I'm not really that experienced with PHP and kind feel like a fish out of water. If you could just point me in the right direction it would be a huge help. I've only been able to create GET requests with:

public function afterPluginLoad()
    {
        $oController = Yii::app()->getController();
        if ($oController && $oController->getId() == "admin") {
            $requestUrl = $this->api->createUrl('plugins/direct', array('plugin' => get_class($this), 'function' => 'createSurvey', 'arg1' => 'value1'));
            // http://localhost/limesurvey/index.php/plugins/direct?plugin=TLAuth&function=createSurvey&arg1=value1
        }
    }
Last edit: 1 year 2 months ago by andre-cavalheiro.

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago - 1 year 2 months ago #177187 by DenisChenu
You can't create a POST request route : you must create a form (and submit)

If this form is out of plugin : you can use manual.limesurvey.org/NewUnsecureRequest event (no CSRF control with this event)

PS : if you really need $_POST value (why ?) you can set it using pĥp too …


Remind :
LimeSurvey is on Yii is on PHP

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 .
An error happen ? Before make a new topic : remind the Debug mode .
Last edit: 1 year 2 months ago by DenisChenu.
The following user(s) said Thank You: andre-cavalheiro

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago #177218 by andre-cavalheiro
Thank you very much, you've been quite helpful!

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!