Skip to content

Commit

Permalink
Dev: Updated participant panel mass editing option
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Sep 10, 2018
1 parent 70b8ec3 commit 1371cf5
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 0 deletions.
55 changes: 55 additions & 0 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -557,6 +557,61 @@ public function editParticipant()
}
}

public function batchEdit() {
if (!Permission::model()->hasGlobalPermission('participantpanel', 'update')) {
Yii::app()->user->setFlash('error', gT("Access denied"));
$this->getController()->redirect(Yii::app()->createUrl('/admin'));
return;
}

$aParticipantIds = json_decode(Yii::app()->request->getPost('sItems'));
$aResults = array();
$oBaseModel = Surveymenu::model();
// First we create the array of fields to update
$aData = array();
$aResults['global']['result'] = true;

// Core Fields
$aCoreTokenFields = array('language', 'owner_uid','blacklisted');
foreach ($aCoreTokenFields as $sCoreTokenField) {
if (trim(Yii::app()->request->getPost($sCoreTokenField, 'lskeep')) != 'lskeep') {
$aData[$sCoreTokenField] = flattenText(Yii::app()->request->getPost($sCoreTokenField));
}
}


if (count($aData) > 0) {
foreach ($aParticipantIds as $sParticipantId) {
$oParticipant = Participant::model()->findByPk($sParticipantId);



foreach ($aData as $key => $value) {
// Make sure no-one hacks owner_uid into form
if (!$oParticipant->isOwnerOrSuperAdmin() && $key=='owner_uid') {
continue;
}
$oParticipant->$key = $value;
}

$bUpdateSuccess = $oParticipant->save();
if ($bUpdateSuccess) {
$aResults[$sParticipantId]['status'] = true;
$aResults[$sParticipantId]['message'] = gT('Updated');
} else {
$aResults[$sParticipantId]['status'] = false;
$aResults[$sParticipantId]['message'] = $oParticipant->error;
}
}
} else {
$aResults['global']['result'] = false;
$aResults['global']['message'] = gT('Nothing to update');
}

Yii::app()->getController()->renderPartial('/admin/surveymenu/massive_action/_update_results', array('aResults'=>$aResults));

}

/**
* Update participant
* Outputs Ajax result
Expand Down
19 changes: 19 additions & 0 deletions application/models/Participant.php
Expand Up @@ -2134,4 +2134,23 @@ public function getCreatedFormatted()
return '';
}
}

public function getLanguageOptions(){
$allLanguages = getLanguageData();
$restrictToLanguages = Yii::app()->getConfig('restrictToLanguages');
if(empty($restrictToLanguages))
{
return array_map(function($lngArr){ return $lngArr['description'];}, $allLanguages);
}
$usedLanguages = explode(' ',$restrictToLanguages);
$returner = [];
array_walk($usedLanguages, function($lngKey) use(&$returner, $allLanguages){
$returner[$lngKey] = $allLanguages[$lngKey]['description'];
});
return $returner;
}
public function getOwnerOptions(){

return [];
}
}
17 changes: 17 additions & 0 deletions application/views/admin/participants/massive_actions/_selector.php
Expand Up @@ -44,6 +44,23 @@
// Separator
array('type' => 'separator'),

// Mass Edit
array(
'type' => 'action',
'action' => 'batchEdit',
'url' => App()->createUrl('/admin/participants/sa/batchEdit/'),
'iconClasses' => 'fa fa-pencil',
'text' => gT('Batch edit'),
'grid-reload' => 'yes',
//modal
'actionType' => 'modal',
'modalType' => 'yes-no',
'keepopen' => 'yes',
'yes' => gT('Apply'),
'no' => gT('Cancel'),
'sModalTitle' => gT('Batch edit the participants'),
'htmlModalBody' => $this->renderPartial('./participants/massive_actions/_update', [], true)
),
// Export
array(
'type' => 'action',
Expand Down
85 changes: 85 additions & 0 deletions application/views/admin/participants/massive_actions/_update.php
@@ -0,0 +1,85 @@
<?php
/**
* Render the selector for surveys massive actions.
*
*/
?>
<?php
$model = Participant::model();
?>

<form class="custom-modal-datas form form-horizontal">
<div class="container-fluid">
<div class="form-group">
<div class="col-sm-1">
<label class="" >
<?php eT("Modify"); ?>
</label>
</div>
<div class="col-sm-11"></div>
</div>
<?php
if (Permission::model()->hasGlobalPermission('superadmin', 'read')
|| $this->uid == Yii::app()->session['loginID']
|| (Permission::model()->hasGlobalPermission('users', 'update')
&& $this->parent_id == Yii::app()->session['loginID']
)
) {
?>
<div class="form-group">
<div class="col-sm-1">
<label class="" >
<input type="checkbox" class="action_check_to_keep_old_value" />
</label>
</div>
<label class="col-sm-3 control-label" for='owner_uid'><?php eT("Owner?"); ?></label>
<div class="col-sm-8">
<?php echo TbHtml::dropDownList('owner_uid', 'lskeep', array_merge(['lskeep' => gT('Keep old value')], $model->getOwnerOptions()), ['disabled'=>'disabled','class'=>'custom-data selector_submitField'] );?>
</div>
</div>
<?php } ?>
<div class="form-group">
<div class="col-sm-1">
<label class="" >
<input type="checkbox" class="action_check_to_keep_old_value" />
</label>
</div>
<label class="col-sm-3 control-label" for='language'><?php eT("Language?"); ?></label>
<div class="col-sm-8">
<?php echo TbHtml::dropDownList('language', 'lskeep', array_merge(['lskeep' => gT('Keep old value')], $model->getLanguageOptions()), ['disabled'=>'disabled','class'=>'custom-data selector_submitField'] );?>
</div>
</div>

<div class="form-group">
<div class="col-sm-1">
<label class="" >
<input type="checkbox" class="action_check_to_keep_old_value" />
</label>
</div>
<label class="col-sm-3 control-label" for='blacklisted'><?php eT("Blacklisted?"); ?></label>
<div class="col-sm-8">
<?php echo TbHtml::dropDownList('blacklisted', 'lskeep', ['lskeep' => gT('Keep old value'), 'Y' => gT('Yes'), 'N' => gT('No')], ['disabled'=>'disabled','class'=>'custom-data selector_submitField'] );?>
</div>
</div>
<?php echo TbHtml::hiddenField('changed_by', Yii::app()->user->id, ['class'=>'custom-data']);?>
<?php echo TbHtml::hiddenField('changed_at', date('Y-m-d H:i:s'), ['class'=>'custom-data']);?>

</div>
</form>
<!-- form -->
<script>
$('.action_check_to_keep_old_value').on('click', function(){
var currentValue = !$(this).prop('checked');
var myFormGroup = $(this).closest('.form-group');

$(this).closest('.form-group').find('input:not(.action_check_to_keep_old_value)').prop('disabled', currentValue)
$(this).closest('.form-group').find('select').prop('disabled', currentValue)

if(currentValue){
$(this).closest('.form-group').find('.selector_submitField').val('lskeep');
} else {
$(this).closest('.form-group').find('input.selector_submitField').val('');
}

});
</script>
@@ -0,0 +1,39 @@
<?php
/**
* This view display the result of multiple update action. It's rendered via ajax for the confirmation modal
*
* @var $aResults The array containing the result of each surveymenu entry action
*/
?>

<?php if (!$aResults['global']['result']):?>
<strong>
<?php echo $aResults['global']['message'] ;?>
</strong>
<?php else: ?>
<?php unset($aResults['global']); ?>
<table class="table table-striped">
<thead>
<th><?php eT('Survey menu entry ID');?></th>
<th><?php eT('Status');?></th>
</thead>
<tbody>
<?php foreach($aResults as $sParticipantToken => $result):?>
<tr>
<td>
<?php echo $sParticipantToken;?>
</td>
<?php if ($result['status'] === true):?>
<td class="text-success">
<?php echo $result['message']; ?>
</td>
<?php else: ?>
<td class="text-warning">
<?php echo $result['message']; ?>
</td>
<?php endif;?>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php endif;?>
Expand Up @@ -45,6 +45,20 @@
<input class='form-control' name='Participant[email]' value='<?php echo $model->email; ?>' />
</div>
</div>
<div class='form-group'>
<label class='control-label '><?php eT("Language:"); ?></label>
<div class=''>
&nbsp;
<select name='Participant[language]' class='action_changeLanguage'>
<?php foreach($model->languageOptions as $language) {
?>
<option value="<?=$language['code']?>" <?=($model->language == $language['code']?' selected=true ':'')?>>
<?=$language['name']?>
</option>
<?php } ?>
</select>
</div>
</div>
<div class='form-group'>
<label class='control-label '><?php eT("Blacklist user:"); ?></label>
<div class=''>
Expand Down

1 comment on commit 1371cf5

@LouisGac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

Please sign in to comment.