Skip to content

Commit

Permalink
Dev: Add global participant to survey (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 22, 2016
1 parent a027a09 commit 1bf95b5
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 121 deletions.
76 changes: 49 additions & 27 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -121,8 +121,11 @@ public function openModalParticipantPanel(){
case "editattribute":
$this->openeditattributenames();
break;
case "addToSurvey":
$this->openAddToSurvey();
break;
default:
echo "";
throw new \CException('Unsupported modal target: ' . $target);
break;
}
}
Expand Down Expand Up @@ -1308,14 +1311,33 @@ public function openeditattributenames(){
}

/**
* Method to edit a global Attribute
* Requires POST
* 'ParticipantAttributeName' (array),
* 'ParticipantAttributeNameLanguages' (array),
* 'ParticipantAttributeNamesDropdown' (array|null),
* 'oper' (string) ['edit'|'new']
* @return json-encoded array 'success' (array), 'successMessage' (string)
*/
* Open modal to add participant(s) to survey
* @return void
*/
public function openAddToSurvey()
{
// This is in fact a comma-separated list
$participant_id = Yii::app()->request->getPost('participant_id');

$data = array();
$data['participant_id'] = $participant_id;
$data['count'] = substr_count($participant_id, ',') + 1;

$surveys = Survey::getSurveysWithTokenTable();
$data['surveys'] = $surveys;

$this->getController()->renderPartial('/admin/participants/modal_subviews/_addToSurvey', $data);
}

/**
* Method to edit a global Attribute
* Requires POST
* 'ParticipantAttributeName' (array),
* 'ParticipantAttributeNameLanguages' (array),
* 'ParticipantAttributeNamesDropdown' (array|null),
* 'oper' (string) ['edit'|'new']
* @return json-encoded array 'success' (array), 'successMessage' (string)
*/
public function editAttributeName(){
$AttributeNameAttributes = Yii::app()->request->getPost('ParticipantAttributeName');
$AttributeNameLanguages = Yii::app()->request->getPost('ParticipantAttributeNameLanguages');
Expand All @@ -1331,7 +1353,7 @@ public function editAttributeName(){
$ParticipantAttributNamesModel = new ParticipantAttributeName;
$ParticipantAttributNamesModel->setAttributes($AttributeNameAttributes);
$success[] = $ParticipantAttributNamesModel->save();

}
if(is_array($ParticipantAttributeNamesDropdown)){
$ParticipantAttributNamesModel->clearAttributeValues();
Expand Down Expand Up @@ -1360,17 +1382,17 @@ public function editAttributeName(){
}
}
echo json_encode(array(
"success" => $success,
"successMessage" => gT("Attribute successfully updated")
));
"success" => $success,
"successMessage" => gT("Attribute successfully updated")
));
die();
}

/**
* Deletes a translation from an Attribute, if it has at least one translation
* Requires POST 'attribute_id' (int), 'lang' (string) [language-code]
* @return 'success' (boolean), 'successMessage' (string|null), 'errorMessage' (string|null)
*/
* Deletes a translation from an Attribute, if it has at least one translation
* Requires POST 'attribute_id' (int), 'lang' (string) [language-code]
* @return 'success' (boolean), 'successMessage' (string|null), 'errorMessage' (string|null)
*/
public function deleteLanguageFromAttribute(){
$attribute_id = Yii::app()->request->getPost('attribute_id');
$lang = Yii::app()->request->getPost('lang');
Expand All @@ -1394,10 +1416,10 @@ public function deleteLanguageFromAttribute(){
}
}
/**
* Deletes a single Attribute via AJAX-call
* Requires POST 'attribute_id' (int)
* @return json-encoded array 'success' (boolean), successMessage (string)
*/
* Deletes a single Attribute via AJAX-call
* Requires POST 'attribute_id' (int)
* @return json-encoded array 'success' (boolean), successMessage (string)
*/
public function deleteSingleAttribute(){
$attribute_id = Yii::app()->request->getPost('attribute_id');
$success = ParticipantAttributeName::model()->delAttribute($attribute_id);
Expand Down Expand Up @@ -1453,7 +1475,7 @@ public function editAttributeInfo()
}


/*
/**
* Fetches the attributes of a participant to be displayed in the attribute subgrid
*/
public function getAttribute_json()
Expand Down Expand Up @@ -1654,7 +1676,7 @@ public function saveAttribute()
Yii::app()->getController()->redirect(array('admin/participants/sa/attributeControl'));
}

/*
/**
* Responsible for deleting the additional attribute values in case of drop down.
*/
public function delAttributeValues()
Expand All @@ -1665,7 +1687,7 @@ public function delAttributeValues()
Yii::app()->getController()->redirect(array('/admin/participants/sa/viewAttribute/aid/' . $iAttributeId));
}

/*
/**
* Responsible for editing the additional attributes values
*/
public function editAttributevalue()
Expand Down Expand Up @@ -2062,9 +2084,9 @@ public function getParticipants_json($search = null)
}

/**
* Seems to be a method to show the uploadsummary
* @TODO investigate this more
*/
* Seems to be a method to show the uploadsummary
* @TODO investigate this more
*/
public function summaryview()
{
$this->_renderWrappedTemplate('participants', array('participantsPanel', 'uploadSummary'),array('aAttributes' => ParticipantAttributeName::model()->getAllAttributes()));
Expand Down
78 changes: 45 additions & 33 deletions application/models/Participant.php
Expand Up @@ -103,39 +103,51 @@ public function getButtons(){
. "<button class='btn btn-default btn-xs %s %s' role='button' data-toggle='tooltip' title='%s' onclick='return false;'>" //extra class //title
. "<span class='fa fa-%s' ></span>" //icon class
. "</button>";
//Edit-button
$editData = array(
'action_participant_editModal',
'',
gT("Edit this participant"),
'edit'
);
$buttons .= vsprintf($raw_button_template, $editData);

//delete-button
$deleteData = array(
'action_participant_deleteModal',
'text-danger',
gT("Delete this participant"),
'trash text-danger'
);
$buttons .= vsprintf($raw_button_template, $deleteData);
//survey information
$infoData = array(
'action_participant_infoModal',
'',
gT("List active surveys"),
'search'
);
$buttons .= vsprintf($raw_button_template, $infoData);
//share this participant
$infoData = array(
'action_participant_shareParticipant',
'',
gT("Share this participant"),
'share'
);
$buttons .= vsprintf($raw_button_template, $infoData);

// Edit button
$editData = array(
'action_participant_editModal',
'',
gT("Edit this participant"),
'edit'
);
$buttons .= vsprintf($raw_button_template, $editData);

// Delete button
$deleteData = array(
'action_participant_deleteModal',
'text-danger',
gT("Delete this participant"),
'trash text-danger'
);
$buttons .= vsprintf($raw_button_template, $deleteData);

// Survey information
$infoData = array(
'action_participant_infoModal',
'',
gT("List active surveys"),
'search'
);
$buttons .= vsprintf($raw_button_template, $infoData);

// Share this participant
$infoData = array(
'action_participant_shareParticipant',
'',
gT("Share this participant"),
'share'
);
$buttons .= vsprintf($raw_button_template, $infoData);

// Add participant to survey
$infoData = array(
'action_participant_addToSurvey',
'',
gT("Add participant to survey"),
'user-plus'
);
$buttons .= vsprintf($raw_button_template, $infoData);

$buttons .= "</div>";
return $buttons;
Expand Down
11 changes: 11 additions & 0 deletions application/models/Survey.php
Expand Up @@ -1150,4 +1150,15 @@ public function calculateEstimatedTime ()
$subQuestions = $subQuestions < 0 ? 0 : $subQuestions;
return ceil(($subQuestions + $baseQuestions)*$time_per_question);
}

/**
* Get all surveys that has participant table
* @return Survey[]
*/
public static function getSurveysWithTokenTable()
{
$surveys = self::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language'), 'owner'))->findAll();
$surveys = array_filter($surveys, function($s) { return tableExists('{{tokens_' . $s->sid); });
return $surveys;
}
}
18 changes: 18 additions & 0 deletions scripts/admin/participantpanel.js
Expand Up @@ -226,6 +226,24 @@ LS.CPDB = (function() {
);
});

/**
* Small icon, add participant to a survey
*/
$('.action_participant_addToSurvey').on('click', function(e) {
var data = {
modalTarget: 'addToSurvey',
participant_id: $(this).closest('tr').data('participant_id')
};
//url, data, idString, actionButtonClass, formId, gridViewId
runBaseModal(
openModalParticipantPanel,
data,
'action_save_modal_addToSurvey',
'addToSurveyActiveForm',
'list_central_participants'
);
});

$('#action_toggleAllParticipant').on('click', function(){
$('.selector_participantCheckbox').prop('checked',$('#action_toggleAllParticipant').prop('checked'));
});
Expand Down
61 changes: 0 additions & 61 deletions tmp/t7yebscxibk9zu7r2ain

This file was deleted.

0 comments on commit 1bf95b5

Please sign in to comment.