Welcome to the LimeSurvey Community Forum

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

Creating a new survey from plugin

  • andre-cavalheiro
  • andre-cavalheiro's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 4 months ago #176443 by andre-cavalheiro
Creating a new survey from plugin was created 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.
The topic has been locked.
  • andre-cavalheiro
  • andre-cavalheiro's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 3 months ago #177166 by andre-cavalheiro
Replied by andre-cavalheiro on topic Creating a new survey from plugin
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 :(
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago #177169 by DenisChenu
Replied by DenisChenu on topic Creating a new survey from plugin
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 …
Code:
// $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 .
I don't answer to private message.
The following user(s) said Thank You: andre-cavalheiro
The topic has been locked.
  • andre-cavalheiro
  • andre-cavalheiro's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 3 months ago - 5 years 3 months ago #177174 by andre-cavalheiro
Replied by andre-cavalheiro on topic Creating a new survey from plugin
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:

Code:
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: 5 years 3 months ago by andre-cavalheiro.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 months ago - 5 years 3 months ago #177187 by DenisChenu
Replied by DenisChenu on topic Creating a new survey from plugin
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 .
I don't answer to private message.
Last edit: 5 years 3 months ago by DenisChenu.
The following user(s) said Thank You: andre-cavalheiro
The topic has been locked.
  • andre-cavalheiro
  • andre-cavalheiro's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 3 months ago #177218 by andre-cavalheiro
Replied by andre-cavalheiro on topic Creating a new survey from plugin
Thank you very much, you've been quite helpful!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose