Welcome to the LimeSurvey Community Forum

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

Can I create ActiveRecords for plugins?

  • allanzmn
  • allanzmn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 10 months ago #154988 by allanzmn
Can I create ActiveRecords for plugins? was created by allanzmn
I´m trying to build a plugin that, at first, will read a third party database somewhere else to fetch for user data to import to LimeSurveys central participants database.

I´m new into Yii and I´m new to LimeSurvey, even to the MVC concept. Anyway, I used Gii to create models and CRUD for the third party database. I moved the files to the plugin folder, following the folder structure for models/ and views/. Not sure if this is right move. Should I create a whole Yii app to use as plugin? If so, how can I use LS domain?
The topic has been locked.
  • ollehar
  • ollehar's Avatar
  • Offline
  • LimeSurvey GmbH Employee
  • LimeSurvey GmbH Employee
More
6 years 10 months ago #154994 by ollehar
Replied by ollehar on topic Can I create ActiveRecords for plugins?
Hi,

I suggest you look at some plugins to see how they are made:

github.com/olleharstedt/MassAction

github.com/olleharstedt/ExtraQuickMenuItems

github.com/olleharstedt/RightClickMenu

Yes, you can use models in your plugin, since Yii is available. It's definitely the right move. :) It will not be a Yii app, since there's no controller. The plugin main class will act as a controller in some sense, but it's a very good idea to split your other code into models and views.
The topic has been locked.
  • allanzmn
  • allanzmn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 10 months ago #155032 by allanzmn
Replied by allanzmn on topic Can I create ActiveRecords for plugins?
Thank you very much, Olle.

The MassAction plugin has a lot of useful info. I´m not going to pretend I fully undertand it yet, since I am still unraveling Yii. I´m stuck, actually. I´ll be glad if you or anyone can help.

I see you have some of what I would expect to see in a controller, on the plugin entry script. It looks like all the models you use in the plugin where already autoloaded so here comes the question. How should I load my models since they are on my plugin folder structure and out of the autoloading path? I could have the "use" statement but how to specify the path?

I want to use Grid/List view so I should use DataProviders, right?

Could you give a little exemple how to load the model and set a dataprovider? I know its basic, but it might help someone else.

Regards.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose