I had to do a 360 degree survey for a client - and I've modified the lastest version of lime survey to provide me with some basic functionality.
Its a pretty quick and dirty hack (ie: You have to change settings in the database and names have to be correct - theres no admin or automation ) - but I'm hoping someone can use the idea as a basis for integrating the functionality into Lime Survey properly in future versions (I don't like hacking software that I upgrade often - but my hands were tied)
Step 1 - Create the survey
- Create a group for the responses required (eg: if there are 5 people in a peer group - create 4 question groups in Lime Survey)
- At the start of each question group - create a drop down list with all the names of the people to select from
- Create tokens for each person
Step 2- Create the peer group table
CREATE TABLE IF NOT EXISTS `peer_group` (
`peer_id` int(11) unsigned NOT NULL auto_increment,
`sid` int(11) NOT NULL,
`group_number` int(11) NOT NULL,
`title` varchar(50) collate utf8_unicode_ci NOT NULL,
`first_name` varchar(100) collate utf8_unicode_ci NOT NULL,
`last_name` varchar(100) collate utf8_unicode_ci NOT NULL,
PRIMARY KEY (`peer_id`),
KEY `group_number` (`group_number`),
KEY `first_name` (`first_name`),
KEY `last_name` (`last_name`),
KEY `title` (`title`),
KEY `sid` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='PHP Surveyor Modification to allow 360 surveys for council m' AUTO_INCREMENT=20 ;
--
-- Dumping data for table `peer_group`
--
INSERT INTO `peer_group` (`peer_id`, `sid`, `group_number`, `title`, `first_name`, `last_name`) VALUES
(1, 68692, 1, 'Mr', 'Dale', 'Aaaa'),
(2, 68692, 1, 'Ms', 'Dianne', 'Bbbbb'),
(3, 68692, 1, 'Ms', 'Kay', 'Ccccc'),
(4, 68692, 1, 'Mrs', 'Maria', 'Ddddd'),
(5, 68692, 1, 'Dr', 'Dimitri', 'Eeeee'),
(7, 68692, 2, 'Mrs', 'Karen', 'Iiiiii'),
(10, 68692, 2, 'Dr', 'Paul', 'Ffffff'),
(11, 68692, 2, 'Mrs', 'Tracey', 'Ggggg'),
(13, 68692, 2, 'Mr', 'Peter', 'Hhhhhh'),
(14, 68692, 3, 'Dr', 'Charlynn', 'Iiiiii'),
(16, 68692, 3, 'Mr', 'John', 'Kkkkkk'),
(17, 68692, 3, 'Mr', 'Kevin', 'Lllllll'),
(18, 68692, 3, 'Ms', 'Jodie', 'Mmmmmm'),
(19, 68692, 3, 'Sgt', 'Todd', 'Nnnnnn');
Each member of a group number will have to complete an assessment of each other member in that group - eg: All group 3 members, All group 4 members etc
Note: This is currently flawed as lookup is on exact first and last name match (So identical names would cause issues) - this needs to be changed to lookup on token id instead
Other database changes
- Add peer_group_survey setting to lime_surveys table
ALTER TABLE `lime_surveys` ADD `peer_group_survey` TINYINT NOT NULL DEFAULT '0'
Set this to 1 for the survey id you need it for
- Add "peer_number" to the lime questions table (Should probably use lime question attributes table instead)
ALTER TABLE `lime_questions` ADD `peer_number` TINYINT NOT NULL DEFAULT '0'
Edit this value for each question at the start of the question group.
eg: The first group will be the first peer assessment, the 2nd will be the 2nd peer assessment...
Code changes
index.php - Line 86
Retreive from the database a list of all the other names in the current users group (Based on the token the used)
if ($surveyid)
{
$issurveyactive=false;
$aRow=$connect->GetRow("SELECT * FROM ".db_table_name('surveys')." WHERE sid=$surveyid");
if (isset($aRow['active']))
{
$surveyexists=true;
if($aRow['active']=='Y')
{
$issurveyactive=true;
}
/******PEER ASSESSMENT CODE***************/
$this_survey = $aRow;
if($this_survey["peer_group_survey"]==1){
$peer_group_survey = true;
// Get peer groups for the specified token
if($_GET["token"] || $_SESSION["token"]){
if($_GET["token"]){
$token = mysql_real_escape_string($_GET["token"]);
}else{
$token = mysql_real_escape_string($_SESSION["token"]);
}
$table_name = "lime_tokens_".(int)$surveyid;
$sql = "SELECT peers.*
FROM $table_name
LEFT JOIN peer_group ON ($table_name.firstname = peer_group.first_name AND $table_name.lastname = peer_group.last_name AND peer_group.sid = '$surveyid')
LEFT JOIN peer_group as peers ON (peer_group.group_number = peers.group_number AND peer_group.peer_id != peers.peer_id AND peers.sid = '$surveyid')
WHERE token = '$token'
ORDER BY last_name
";
$peer_groups = db_execute_assoc($sql);
$peer_group_count=0;
while($peer_group = $peer_groups->FetchRow()){
$peer_group_count++;
$_SESSION["peer_{$peer_group_count}"] = $peer_group["first_name"]." ".$peer_group["last_name"];
}
}
}
/******END PEER ASSESSMENT CODE***************/
}
else
{
$surveyexists=false;
}
}
qanda.php - function do_list_dropdown - 1786
Limit the dropdown to appropriate person.
eg: If this is the 2nd question group- only show the 2nd person from this users assessment group as an option - then auto select this option
function do_list_dropdown($ia)
{
global $dbprefix, $dropdownthreshold, $lwcdropdowns, $connect;
global $shownoanswer, $clang;
/******PEER ASSESSMENT CODE***************/
global $peer_group_survey;
if($peer_group_survey){
//Get any peer group questions
$sql = "SELECT peer_number FROM {$dbprefix}questions WHERE qid = '{$ia[0]}'";
$result = db_execute_assoc($sql);
$peer_group = $result->FetchRow();
}
/******END PEER ASSESSMENT CODE***************/
....
while ($ansrow = $ansresult->FetchRow())
{
$opt_select = '';
/******PEER ASSESSMENT CODE***************/
if($peer_group_survey && $peer_group["peer_number"] > 0 ){
if($ansrow['answer'] != $_SESSION["peer_{$peer_group["peer_number"]}"]){
$peer_group_selected = false;
continue; //Eliminate this user from the assessment list
}else{
$peer_group_selected = true; //Show and select this user as an option
}
//END 360 survey alteration
}
/******END PEER ASSESSMENT CODE***************/
if ($_SESSION[$ia[1]] == $ansrow['code'] || $peer_group_selected/) //IF STATEMENT CHANGED
{
$opt_select = SELECTED;
}
$answer .= "<option value='{$ansrow['code']}' {$opt_select}>{$ansrow['answer']}</option>\n";
}
}
....
What would be great is if this could be integrated into the token management- so Lime Survey would automatically create the appropriate number of question groups (Currently if the group sizes are uneven the last group has to be non-mandatory) and put in the correct values for the peer selector at the top of each group.
Hopefully this helps out someone - as this question seems to appear a lot - and I don't think the solution has to be too complicated.