Skip to content

Commit

Permalink
Fixed issue #6508 - Central Participant Database: Cannot edit more th…
Browse files Browse the repository at this point in the history
…an 20 attributes per participant (also fixed sorting, and added paging and filtering options)
  • Loading branch information
jcleeland committed Aug 25, 2012
1 parent 812cb7c commit adc1b0e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 22 deletions.
59 changes: 43 additions & 16 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -1154,24 +1154,40 @@ function subval_sort($a, $subkey, $order)
*/
function getAttribute_json()
{
function subval_sort($a, $subkey, $order)
{
foreach ($a as $k => $v)
{
$b[$k] = strtolower($v[$subkey]);
}
if ($order == "asc")
{
asort($b, SORT_REGULAR);
}
else
{
arsort($b, SORT_REGULAR);
}
foreach ($b as $key => $val)
{
$c[] = $a[$key];
}
return $c;
}

$iParticipantId = Yii::app()->request->getQuery('pid');
$records = ParticipantAttributeNames::model()->getParticipantVisibleAttribute($iParticipantId);
//$getallattributes = ParticipantAttributeNames::model()->with('participant_attribute_names_lang')->findAll();
$aData = new stdClass();
$aData->page = 1;
$aData->records = count($records);
$aData->total = ceil($aData->records / 10);
$aData->rows[0]['id'] = $iParticipantId;
$aData->rows[0]['cell'] = array();
$records = subval_sort($records, "attribute_name", "asc");

$i = 0;

$doneattributes = array(); //If the user has any actual attribute values, they'll be stored here

/* Iterate through each attribute owned by this user */
foreach ($records as $row)
{
$aData->rows[$i]['id'] = $row['participant_id'] . "_" . $row['attribute_id'];
$aData->rows[$i]['cell'] = array("", $row['participant_id'], $row['attribute_type'], $row['attribute_name'], $row['value']);
$outputs[$i] = array("", $row['participant_id'], $row['attribute_type'], $row['attribute_name'], $row['value']);
/* Collect allowed values for a DropDown attribute */
if ($row['attribute_type'] == "DD")
{
Expand All @@ -1185,16 +1201,16 @@ function getAttribute_json()
$attval .= ";";
}
$attval = substr($attval, 0, -1);
array_push($aData->rows[$i]['cell'], $attval);
array_push($outputs[$i], $attval);
}
else
{
array_push($aData->rows[$i]['cell'], "");
array_push($outputs[$i], "");
}
}
else
{
array_push($aData->rows[$i]['cell'], "");
array_push($output[$i], "");
}
array_push($doneattributes, $row['attribute_id']);
$i++;
Expand All @@ -1216,8 +1232,7 @@ function getAttribute_json()
/* Go through the empty attributes and build an entry in the output for them */
foreach ($attributenotdone as $row)
{
$aData->rows[$i]['id'] = $iParticipantId . "_" . $row['attribute_id'];
$aData->rows[$i]['cell'] = array("", $iParticipantId, $row['attribute_type'], $row['attribute_name'], "");
$outputs[$i] = array("", $iParticipantId, $row['attribute_type'], $row['attribute_name'], "");
if ($row['attribute_type'] == "DD")
{
$attvalues = ParticipantAttributeNames::model()->getAttributesValues($row['attribute_id']);
Expand All @@ -1230,19 +1245,31 @@ function getAttribute_json()
$attval .= ";";
}
$attval = substr($attval, 0, -1);
array_push($aData->rows[$i]['cell'], $attval);
array_push($outputs[$i], $attval);
}
else
{
array_push($aData->rows[$i]['cell'], "");
array_push($outputs[$i], "");
}
}
else
{
array_push($aData->rows[$i]['cell'], "");
array_push($outputs[$i], "");
}
$i++;
}
$outputs=subval_sort($outputs, 3, "asc");

$aData = new stdClass();
$aData->page = 1;
$aData->rows[0]['id'] = $iParticipantId;
$aData->rows[0]['cell'] = array();
$aData->records = count($outputs);
$aData->total = ceil($aData->records / 10);
foreach($outputs as $key=>$output) {
$aData->rows[$key]['id']=$output[1];
$aData->rows[$key]['cell']=$output;
}
/* TODO: It'd be nice to do a natural sort on the attribute list at some point.
Currently they're returned in order of attributes WITH values, then WITHOUT values
*/
Expand Down
3 changes: 2 additions & 1 deletion application/models/ParticipantAttributeNames.php
Expand Up @@ -155,7 +155,8 @@ function getParticipantVisibleAttribute($participant_id)
$findCriteria=new CDbCriteria();
$findCriteria->addCondition('participant_id = :participant_id');
$findCriteria->params = array(':participant_id'=>$participant_id);
$records=ParticipantAttributeNames::model()->with('participant_attribute_names_lang', 'participant_attribute')->findAll($findCriteria);
$records=ParticipantAttributeNames::model()->with('participant_attribute_names_lang', 'participant_attribute')
->findAll($findCriteria);
foreach($records as $row) { //Iterate through each attribute
$thisname="";
$thislang="";
Expand Down
20 changes: 15 additions & 5 deletions scripts/admin/displayParticipant.js
Expand Up @@ -216,14 +216,11 @@ $(document).ready(function() {
editurl:editAttributevalue,
datatype: "json",
mtype: "post",
pgbuttons:false,
recordtext:'',
pgtext:'',
caption: attributesHeadingTxt,
editable: true,
loadonce : true,
colNames: [actionsColTxt,participantIdColTxt,attributeTypeColTxt,attributeNameColTxt,attributeValueColTxt,attributePosValColTxt],
colModel: [ { name:'act',index:'act',width:55,align:'center',sortable:false,formatter:'actions',formatoptions : { keys:true,onEdit:function(id){
colModel: [ { name:'act',index:'act',width:55,align:'center',search: false,sortable:false,formatter:'actions',formatoptions : { keys:true,onEdit:function(id){
var iRow = $('#' + $.jgrid.jqID(id))[0].rowIndex;
editModifier(id,iRow, method='edit');
}}},
Expand All @@ -232,8 +229,17 @@ $(document).ready(function() {
{ name:'attname',index:'attname', width:150, sorttype:"string",align:"center",editable:false},
{ name:'attvalue',index:'attvalue', width:150, sorttype:"string",align:"center",editable:true},
{ name:'attpvalues',index:'attpvalues', width:150, sorttype:"string",align:"center",editable:false,hidden:true}],
rowNum:20,
sortname: attributeNameColTxt,
sortorder: 'asc',
sortable: true,
pager: pager_id,
viewrecords: true,
pgbuttons: true,
pginput: true,
recordtext:'',
pgtext:'',
rowNum:10,
rowList:[10,25,50,100000],
gridComplete: function () {
/* Removes the delete icon from the actions bar */
$('div.ui-inline-del').html('');
Expand All @@ -244,6 +250,10 @@ $(document).ready(function() {
},
height: '100%'
});

/* Pager for attribute subgrid */
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{refresh: false, edit:false,add:false,del:false,search:false})
jQuery("#"+subgrid_table_id).jqGrid('filterToolbar', {searchOnEnter : false,defaultSearch: 'cn'});
}
});

Expand Down

0 comments on commit adc1b0e

Please sign in to comment.