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.
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);
}
}
}