Welcome to the LimeSurvey Community Forum

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

Adding Custom Fields to Survey Admin

  • marcgold
  • marcgold's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
5 years 2 months ago #189675 by marcgold
Adding Custom Fields to Survey Admin was created by marcgold
Hi

Wondering if anyone can provide some guidance if this is going to be possible and if so how would I adjust the plugin that is listed below to achieve this.

What I am trying to achieve is the ability to add 3 custom fields to a survey admin the fields are, Client Name, Project Manager and Telephone Number.

Once they are added I need to be able to use this data in two places. 1. Columns on the Survey List Page - After Survey Name and 2. Above the Welcome Text on the Survey Display Page: (they are not publically available just internal).

I would also like the Custom fields to be editable / viewable on either the General Settings or better Still the Text Elements menu item on the left.

With the plugin (Which is based on the exampleSettings plugin by Denis Chenu - ameded to work with LS 3.17) I am able to get the fields to display and are editable on the Simple Plugins tabs - but cannot figure out what needs to change to get it to work the way I want to.

Any help greatly appreciated, Im not a coder but really enjoying learning the plugin system (albeit slowly) so be gentle please.

This is the Plugin Code I have edited to get it to where it is:
Code:
class AddAdminFields extends PluginBase {
 
    protected $storage = 'DbStorage';
    static protected $name = 'Add Fields to Admin';
    static protected $description = 'Add Fields to Admin Screens on surveys';
 
    protected $settings = array(
        'ClientName' => array(
            'type' => 'text',
            'content' => 'Add the Client Name',
 
        ),
        'ProjectManager' => array(
            'type' => 'text',
            'content' => 'Add the Project Manager Name',
 
        ),
        'Tel' => array(
            'type' => 'text',
            'content' => 'Add the Managers Tel:',
 
        ),
    );
 
    public function init()        
      {
      $this->subscribe('beforeSurveySettings');
        $this->subscribe('newSurveySettings');
    }
 
    /**
     * This event is fired by the administration panel to gather extra settings
     * available for a survey.
     * The plugin should return setting meta data.
     * @param PluginEvent $event
     */
    public function beforeSurveySettings()
    {
        $event = $this->event;
        $event->set("surveysettings.{$this->id}", array(
            'name' => get_class($this),
            'settings' => array(
                    'ClientName'=>array(
                    'type'=>'text',
                    'label'=>'Client Name',
                    'help'=>'Enter the Client Name.',
                    'current' => $this->get('ClientName', 'Survey', $event->get('survey'),$this->get('ClientName',null,null,$this->settings['ClientName']['default'])),
                ),
                'ProjectManager'=>array(
                    'type'=>'text',
                    'label'=>'Project Manager',
                    'help'=>'Project Managers Name',
                    'current' => $this->get('ProjectManger', 'Survey', $event->get('survey'),$this->get('ProjectManager',null,null,$this->settings['ProjectManager']['default'])),
                ),
                'Tel'=>array(
                    'type'=>'text',
                    'label'=>'Telephone',
                    'help'=>'Enter Telephone No..',
                    'current' => $this->get('Tel', 'Survey', $event->get('survey'),$this->get('Tel',null,null,$this->settings['Tel']['default'])),
                )
 
                )
         ));
    }
 
    public function newSurveySettings()
    {
        $event = $this->event;
        foreach ($event->get('settings') as $name => $value)
        {
            /* In order use survey setting, if not set, use global, if not set use default */
            $default=$event->get($name,null,null,isset($this->settings[$name]['default'])?$this->settings[$name]['default']:NULL);
            $this->set($name, $value, 'Survey', $event->get('survey'),$default);
        }
    }
 
  }
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
5 years 2 months ago #189707 by DenisChenu
Replied by DenisChenu on topic Adding Custom Fields to Survey Admin
Hi,

1. Columns on the Survey List Page - After Survey Name

I'm not able to offer a good solution …

2. Above the Welcome Text on the Survey Display Page: (they are not publically available just internal).

'm not able to offer a good solution …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose