Skip to content

Commit

Permalink
Dev: CPDB; add arrow to mapped attributes; indentation; error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 1, 2016
1 parent 0a31e67 commit 23fffcb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 31 deletions.
26 changes: 16 additions & 10 deletions application/models/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ private function writeParticipantsToTokenTable(
}
catch (Exception $e)
{
throw new Exception(gT("Could not update token attribute value" . $e->getMessage()));
throw new Exception(gT("Could not update token attribute value: " . $e->getMessage()));
}
}
$successful++;
Expand Down Expand Up @@ -1320,30 +1320,36 @@ public function copyCPDBAttributesToTokens($surveyId, array $participantIds, arr
* Updates a field in the token table with a value from the participant attributes table
*
* @param int $surveyId Survey ID number
* @param int $participantId unique key for the participant
* @param string $participantId unique key for the participant
* @param int $participantAttributeId the unique key for the participant_attribute table
* @param int $tokenFieldName fieldname in the token table
*
* @return bool true/false
*/
function updateTokenAttributeValue($surveyId, $participantId, $participantAttributeId, $tokenFieldname) {

if (intval($participantAttributeId) === 0) // OBS: intval returns 0 at fail, but also at intval("0"). lolphp.
{
throw new InvalidArgumentException(sprintf('$participantAttributeId has to be an integer. Given: %s (%s)', gettype($participantAttributeId), $participantAttributeId));
}

//Get the value from the participant_attribute field
$val = Yii::app()->db
->createCommand()
->select('value')
->where('participant_id = :participant_id AND attribute_id = :attrid')
->from('{{participant_attribute}}')
->bindParam("participant_id", $participantId, PDO::PARAM_STR)
->bindParam("attrid", $participantAttributeId, PDO::PARAM_INT);
->createCommand()
->select('value')
->where('participant_id = :participant_id AND attribute_id = :attrid')
->from('{{participant_attribute}}')
->bindParam("participant_id", $participantId, PDO::PARAM_STR)
->bindParam("attrid", $participantAttributeId, PDO::PARAM_INT);
$value = $val->queryRow();

//Update the token entry with those values
if (isset($value['value']))
{
$data = array($tokenFieldname => $value['value']);
Yii::app()->db
->createCommand()
->update("{{tokens_$surveyId}}", $data, "participant_id = '$participantId'");
->createCommand()
->update("{{tokens_$surveyId}}", $data, "participant_id = '$participantId'");
}
return true;
}
Expand Down
51 changes: 32 additions & 19 deletions application/views/admin/participants/attributeMap_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,38 @@
</div>
<div class='panel-body'>
<div class="tokenatt ui-sortable" style="min-height: 200px;">
<?php
foreach ($selectedtokenattribute as $id => $name)
{
if (isset($automaticallyMappedAttributes[$id]))
{
$autoAttr = $automaticallyMappedAttributes[$id];
echo "<div class='tokenatt-container col-sm-12'>";
echo "<div class='col-sm-6'><div class='panel panel-default ui-state-disabled token-attribute' id='t_" . $id . "'><div class='panel-body'>" . $name . "</div></div></div>";
echo "<div class='col-sm-6'><div class='panel panel-default ui-state-disabled cpdb-attribute' id='c_" . $autoAttr['cpdbAttribute']['attribute_id'] . "'><div class='panel-body'>" . $autoAttr['cpdbAttribute']['attribute_name'] . "</div></div></div>";
echo "</div>";
}
else
{
echo "<div class='tokenatt-container col-sm-12'>";
echo "<div class='col-sm-6'><div class='panel panel-default ui-state-disabled token-attribute' id='t_" . $id . "'><div class='panel-body'>" . $name . "</div></div></div>";
echo "</div>";
}
}
?>
<?php foreach ($selectedtokenattribute as $id => $name): ?>
<?php if (isset($automaticallyMappedAttributes[$id])): ?>
<?php $autoAttr = $automaticallyMappedAttributes[$id]; // Short-hand... ?>
<div class='tokenatt-container col-sm-12'>
<div class='col-sm-6'>
<div class='panel panel-default ui-state-disabled token-attribute' id='t_<?php echo $id; ?>'>
<div class='panel-body'>
<?php echo $name; ?>
<span class='fa fa-arrows-h tokenatt-arrow'></span>
</div>
</div>
</div>
<div class='col-sm-6'>
<div class='panel panel-default ui-state-disabled cpdb-attribute' id='c_<?php echo $autoAttr['cpdbAttribute']['attribute_id']; ?>'>
<div class='panel-body'>
<?php echo $autoAttr['cpdbAttribute']['attribute_name']; ?>
</div>
</div>
</div>
</div>
<?php else: ?>
<div class='tokenatt-container col-sm-12'>
<div class='col-sm-6'>
<div class='panel panel-default ui-state-disabled token-attribute' id='t_<?php echo $id; ?>'>
<div class='panel-body'>
<?php echo $name; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>

<?php if(!empty($selectedtokenattribute)): ?>
Expand Down
11 changes: 9 additions & 2 deletions scripts/admin/attributeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ $(document).ready(function(){
$(ui.sender).sortable('cancel');
}
else {
// Change CSS
$(ui.item).removeClass('col-sm-12');
$(ui.item).addClass('cpdb-attribute');
$(ui.item).wrap('<div class="col-sm-6"></div>');

// Insert nice arrows
//var t = $(ui.item).parent('.tokenatt-container'); // Does not work.
var t = $(ui.item).parent('div').parent('div'); // TODO: Bad, should not rely on DOM structure
t = t.find('.token-attribute .panel-body');
t.append('<span class="fa fa-arrows-h tokenatt-arrow"></span>');
}
}
});
Expand Down Expand Up @@ -150,12 +157,12 @@ $(document).ready(function(){
}, function(msg){
$('#attribute-map-participant-modal .modal-body').html(msg);
$('#attribute-map-participant-modal').on('hide.bs.modal' , function (e) {
$(location).attr('href',redUrl);
//$(location).attr('href',redUrl);
});
$('#attribute-map-participant-modal').modal();
});
});

$('.tokenatt .panel-default').disableSelection();
$('.tokenatt .panel-default .tokenAttributeId').disableSelection();
tokencurrentarray = $('.tokenatt').sortable('toArray');
});
5 changes: 5 additions & 0 deletions styles/Sea_Green/css/lime-admin-misc.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ iframe#dialog {
margin-right: 1em;
}

.tokenatt-arrow {
position: absolute;
right: 0;
}

#labelsetpreview {
overflow-x: hidden;
}
Expand Down

0 comments on commit 23fffcb

Please sign in to comment.