Skip to content

Commit

Permalink
Dev: Factor out views for participant attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 26, 2016
1 parent 3296f12 commit 75e8016
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 47 deletions.
17 changes: 12 additions & 5 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -450,11 +450,18 @@ public function openeditparticipant()
}
//Generate HTML for extra Attributes

$extraAttributes = [];
foreach($model->allExtraAttributes as $name=>$extraAttribute){
$value = $model->getParticipantAttribute("",$extraAttribute['attribute_id']);

$extraAttributes[] = $this->generateExtraAttributeEditHtml($name, $value, $extraAttribute, $model);
$extraAttributes = array();
foreach($model->allExtraAttributes as $name => $extraAttribute) {
$value = $model->getParticipantAttribute("", $extraAttribute['attribute_id']);
$extraAttribute['value'] = $value;
$extraAttribute['name'] = $name;

if ($extraAttribute['attribute_type'] == 'DD') {
$extraAttribute['options'] = $model->getOptionsForAttribute($extraAttribute['attribute_id']);
}

$extraAttributes[$name] = $extraAttribute;
//$extraAttributes[] = $this->generateExtraAttributeEditHtml($name, $value, $extraAttribute, $model);
}
$aData = array(
'model' => $model,
Expand Down
29 changes: 26 additions & 3 deletions application/models/Participant.php
Expand Up @@ -179,6 +179,9 @@ public function attributeLabels()

}

/**
* @return array
*/
public function getAllExtraAttributes(){
$allAttributes = ParticipantAttributeName::model()->getAllAttributes();
$extraAttributes = array();
Expand All @@ -188,11 +191,25 @@ public function getAllExtraAttributes(){
return $extraAttributes;
}

/**
* Get options for a drop-down attribute
* @return array
*/
public function getOptionsForAttribute($attribute_id) {
$result = Yii::app()->db->createCommand()
->select('*')->from('{{participant_attribute_values}}')->where('attribute_id=:attribute_id', array( 'attribute_id' => $attribute_id))->queryAll();
return $result;

//if ($this->attribute_type != 'DD') {
//throw new \CInvalidArgumentException('Only drop-down attributes have options');
//}

//$attribute_id = $this->attribute_id;
$result = Yii::app()->db->createCommand()
->select('*')
->from('{{participant_attribute_values}}')
->where('attribute_id=:attribute_id', array('attribute_id' => $attribute_id))
->queryAll();
return $result;
}

public function getAllUsedLanguagesWithRealName(){
$lang_array = array();
$languages = $this->findAll(array(
Expand All @@ -205,6 +222,12 @@ public function getAllUsedLanguagesWithRealName(){
}
return $lang_array;
}

/**
* @param string $attribute_textid
* @param mixed $attribute_id
* @return
*/
public function getParticipantAttribute($attribute_textid, $attribute_id=false){
if($attribute_id == false)
{
Expand Down
20 changes: 15 additions & 5 deletions application/models/ParticipantAttribute.php
Expand Up @@ -62,13 +62,25 @@ public function relations()
);
}

function getAttributeInfo($participantid)
/**
* ?
*/
public function getAttributeInfo($participantid)
{
return self::model()->findAllByAttributes(array('participant_id' => $participantid));
}
function updateParticipantAttributeValue($data)

/**
* @param array $data
* @return void
*/
public function updateParticipantAttributeValue($data)
{
$query = Yii::app()->db->createCommand()->select('*')->where("participant_id='".$data['participant_id']."' AND attribute_id = ".$data['attribute_id'])->from('{{participant_attribute}}')->queryAll();
$query = Yii::app()->db->createCommand()
->select('*')
->where("participant_id='".$data['participant_id']."' AND attribute_id = ".$data['attribute_id'])
->from('{{participant_attribute}}')
->queryAll();
if (count($query) > 0)
{
Yii::app()->db->createCommand()
Expand All @@ -80,5 +92,3 @@ function updateParticipantAttributeValue($data)
}

}

?>
@@ -1,6 +1,6 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="participant_edit_modal"><?php echo $model->firstname."&nbsp;".$model->lastname; ?></h4>
<h4 class="modal-title" id="participant_edit_modal"><?php eT('Edit participant'); ?></h4>
</div>
<div class="modal-body form-horizontal">
<?php
Expand All @@ -22,35 +22,57 @@
'class' => 'col-sm-8',
'required' => 'required'
);
echo $form->textFieldControlGroup($model,'firstname', $baseControlGroupHtmlOptions);
echo $form->textFieldControlGroup($model,'lastname',$baseControlGroupHtmlOptions);
echo $form->textFieldControlGroup($model,'email',$baseControlGroupHtmlOptions);
echo
"<div class='form-group'>
<label class='control-label col-sm-4'>".gT("Should this user be blacklisted?")."</label>
<div class='col-sm-8'>
&nbsp;
<label class='radio-inline'>"
. "<input name=\"Participant[blacklisted]\" id=\"Participant_blacklisted\" type=\"radio\" value=\"Y\" "
.($model->blacklisted == "Y" ? "checked" : "")." />"
. gT("Yes")."
?>
<div class='form-group'>
<label class='control-label col-sm-2'>
<?php eT('First name:'); ?>
</label>
<label class='radio-inline'>"
. "<input name=\"Participant[blacklisted]\" id=\"Participant_blacklisted\" type=\"radio\" value=\"N\" "
.(($model->blacklisted == "N" || empty($model->blacklisted)) ? "checked" : "")." />"
. gT("No")."
<div class='col-sm-4'>
<input class='form-control' name='firstname' value='<?php echo $model->firstname; ?>' />
</div>
<label class='control-label col-sm-2'>
<?php eT('Last name:'); ?>
</label>
<div class='col-sm-4'>
<input class='form-control' name='lastname' value='<?php echo $model->lastname; ?>' />
</div>
</div>";
echo "<br/>";
echo "<br/>";
echo "<legend>".gT("Custom attributes")."</legend>";

foreach($extraAttributes as $extraAttribute){
echo $extraAttribute;
}
?>
<p>&nbsp;</p>
</div>
<div class='form-group'>
<label class='control-label col-sm-2'>
<?php eT('E-mail:'); ?>
</label>
<div class='col-sm-10'>
<input class='form-control' name='email' value='<?php echo $model->firstname; ?>' />
</div>
</div>
<div class='form-group'>
<label class='control-label col-sm-4'><?php eT("Should this user be blacklisted?"); ?></label>
<div class='col-sm-8'>
&nbsp;
<input name='Participant[blacklisted]' type='checkbox' data-size='small' data-on-color='warning' data-off-color='primary' data-off-text='<?php eT('No'); ?>' data-on-text='<?php eT('Yes'); ?>' class='action_changeBlacklistStatus bootstrap-switch' />
</div>
</div>
<legend><?php eT("Custom attributes"); ?></legend>
<?php foreach($extraAttributes as $name => $attribute): ?>
<?php switch ($attribute['attribute_type']):

// Text box
case 'TB': ?>
<?php $this->renderPartial('/admin/participants/modal_subviews/attributes/textbox', $attribute); ?>
<?php break; ?>

<!-- Drop down -->
<?php case 'DD': ?>
<?php $this->renderPartial('/admin/participants/modal_subviews/attributes/dropdown', $attribute); ?>
<?php break; ?>

<!-- Date -->
<?php case 'DP': ?>
<?php $this->renderPartial('/admin/participants/modal_subviews/attributes/date', $attribute); ?>
<?php break; ?>

<?php endswitch; ?>
<?php endforeach; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><?php eT('Close') ?></button>
Expand Down
@@ -0,0 +1,17 @@
<div class="form-horizontal form-group">
<label class="col-sm-4 control-label" for="datepickerInputField_[<?php echo $name; ?>]"><?php echo $defaultname; ?></label>
<div>
<div class='col-sm-8'>
<input class="form-control" name="datepickerInputField_<?php echo $name; ?>" id="datepickerInputField_<?php echo $name; ?>" type="text" value="<?php echo $value; ?>">
<input name="Attributes[<?php echo $name; ?>]" id="Attributes_<?php echo $name; ?>" type="hidden" value="<?php echo $value; ?>">
<script type="text/javascript">
$(function () {
$('#datepickerInputField_<?php echo $name; ?>').datetimepicker(datepickerConfig.initDatePickerObject);
$('#datepickerInputField_<?php echo $name; ?>').on("dp.change", function(e){
$("#Attributes_<?php echo $name; ?>").val(e.date.format(datepickerConfig.dateformatdetailsjs));
})
});
</script>
</div>
</div>
</div>
@@ -0,0 +1,18 @@
<div class="form-horizontal form-group">
<label class="col-sm-4 control-label" for="datepickerInputField_[<?php echo $name; ?>]"><?php echo $defaultname; ?></label>
<div>
<div class='col-sm-8'>
<select class="form-control" name="Attributes[<?php echo $name; ?>]" id="Attributes_<?php echo $name; ?>">
<option></option> <!-- Nothing selected -->
<?php foreach ($options as $option): ?>
<option
<?php if ($option['value'] == $value): echo 'selected'; endif; ?>
value='<?php echo $option['value']; ?>'
>
<?php echo $option['value']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
@@ -0,0 +1,8 @@
<div class="form-group">
<label class="col-sm-4 control-label" for="Attributes[<?php echo $name; ?>]"><?php echo $defaultname; ?></label>
<div>
<div class='col-sm-8'>
<input class="form-control" name="Attributes[<?php echo $name; ?>]" id="Attributes_<?php echo $name; ?>" type="text" maxlength="254" value="<?php echo $value; ?>">
</div>
</div>
</div>
17 changes: 10 additions & 7 deletions scripts/admin/participantpanel.js
Expand Up @@ -60,7 +60,7 @@ LS.CPDB = (function() {

$(baseModal).modal('show');

jQuery.ajax({
return jQuery.ajax({
url: url,
data: data,
method: 'POST',
Expand Down Expand Up @@ -170,13 +170,16 @@ LS.CPDB = (function() {
var data = {modalTarget: 'editparticipant', 'participant_id' : $(this).closest('tr').data('participant_id')};
//url, data, idString, actionButtonClass, formId, gridViewId
runBaseModal(
openModalParticipantPanel,
data,
'action_save_modal_editParticipant',
'editPartcipantActiveForm',
'list_central_participants'
);
openModalParticipantPanel,
data,
'action_save_modal_editParticipant',
'editPartcipantActiveForm',
'list_central_participants'
).done(function() {
$('.bootstrap-switch').bootstrapSwitch();
});
});

$('.action_participant_deleteModal').on('click', function(e){
e.preventDefault();
var data = {modalTarget: 'showdeleteparticipant', 'participant_id' : $(this).closest('tr').data('participant_id')};
Expand Down

0 comments on commit 75e8016

Please sign in to comment.