Skip to content

Commit

Permalink
Fixed issue #8387: Exporting participants from CPDB as CSV-file omits…
Browse files Browse the repository at this point in the history
… attribute fields
  • Loading branch information
c-schmitz committed Dec 18, 2013
1 parent 88e9769 commit 1185d59
Show file tree
Hide file tree
Showing 74 changed files with 11,059 additions and 552 deletions.
12 changes: 12 additions & 0 deletions application/config/third_party.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@
'jquery'
)
),
'bootstrap-multiselect' => array(
'baseUrl' => 'third_party/bootstrap-multiselect',
'js' => array(
'js/bootstrap-multiselect.js',
),
'css' => array(
'css/bootstrap-multiselect.css',
),
'depends' => array(
'jquery'
)
),
'ace' => array(
'baseUrl' => 'third_party/ace',
'js' => array(
Expand Down
2 changes: 1 addition & 1 deletion application/config/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

$config['versionnumber'] = "2.05+";
$config['dbversionnumber'] = 172;
$config['dbversionnumber'] = 173;
$config['buildnumber'] = '';
$config['updatable'] = true;

Expand Down
175 changes: 83 additions & 92 deletions application/controllers/admin/participantsaction.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion application/extensions/FlashMessage/FlashMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function run() {
elseif(is_array($message) && is_string($message['message']) )
$aMessage[]=array('message'=>$message['message']);
}
Yii::app()->clientScript->registerScript('notify-messages',"LS.messages=".json_encode($aMessage),CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScript('notify-messages',"LS.messages=".json_encode($aMessage).';',CClientScript::POS_HEAD);
$this->render('message', array('aMessage'=>$aMessage));
}
}
Expand Down
2 changes: 1 addition & 1 deletion application/extensions/LimeScript/LimeScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function run()
$data['adminImageUrl'] = Yii::app()->getConfig('adminimageurl');
$data['replacementFields']['path'] = App()->createUrl("admin/limereplacementfields/sa/index/");
$json = json_encode($data, JSON_FORCE_OBJECT);
$script = "LS.data = $json";
$script = "LS.data = $json;";
App()->getClientScript()->registerScript('LimeScript', $script, CClientScript::POS_HEAD);
}
}
Expand Down
24 changes: 22 additions & 2 deletions application/helpers/update/updatedb_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,8 @@ function db_upgrade_all($iOldDBVersion) {
// Add new column for question index options.
addColumn('{{surveys}}', 'questionindex', 'integer not null default "0"');
// Set values for existing surveys.
$oDB->createCommand('update {{surveys}} set `questionindex` = 0 where `allowjumps` = "Y"')->query();
$oDB->createCommand('update {{surveys}} set `questionindex` = 1 where `allowjumps` = "N"')->query();
$oDB->createCommand("update {{surveys}} set questionindex = 0 where allowjumps = 'Y'")->query();
$oDB->createCommand("update {{surveys}} set questionindex = 1 where allowjumps = 'N'")->query();

// Remove old column.
Yii::app()->getDb()->createCommand()->dropColumn('{{surveys}}', 'allowjumps');
Expand Down Expand Up @@ -1162,6 +1162,12 @@ function db_upgrade_all($iOldDBVersion) {
alterColumn('{{permissions}}', 'entity_id', "INTEGER", false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>172),"stg_name='DBVersion'");
}
if ($iOldDBVersion < 173)
{
addColumn('{{participant_attribute_names}}','defaultname',"{$sVarchar}(50) NOT NULL default ''");
upgradeCPDBAttributeDefaultNames173();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>173),"stg_name='DBVersion'");
}
$oTransaction->commit();
}
catch(Exception $e)
Expand All @@ -1175,6 +1181,20 @@ function db_upgrade_all($iOldDBVersion) {
return true;
}


function upgradeCPDBAttributeDefaultNames173()
{
$sQuery = "SELECT attribute_id,attribute_name,COALESCE (lang)
FROM {{participant_attribute_names_lang}}
group by attribute_id, attribute_name
order by attribute_id";
$oResult = Yii::app()->db->createCommand($sQuery)->queryAll();
foreach ( $oResult as $aAttribute )
{
Yii::app()->db->createCommand()->update('{{participant_attribute_names}}',array('defaultname'=>substr($aAttribute['attribute_name'],0,50)),"attribute_id={$aAttribute['attribute_id']}");
}
}

/**
* Converts global permissions from users table to the new permission system,
* and converts template permissions from template_rights to new permission table
Expand Down
195 changes: 103 additions & 92 deletions application/models/ParticipantAttributeName.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,86 +73,91 @@ public function tableName() {
return '{{participant_attribute_names}}';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('attribute_type, visible', 'required'),
array('attribute_type', 'length', 'max'=>4),
array('visible', 'length', 'max'=>5),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('attribute_id, attribute_type, visible', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('attribute_type, visible', 'required'),
array('attribute_type', 'length', 'max'=>4),
array('visible', 'length', 'max'=>5),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('attribute_id, attribute_type, visible', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'participant_attribute_names_lang'=>array(self::HAS_MANY, 'ParticipantAttributeNameLang', 'attribute_id'),
'participant_attribute'=>array(self::HAS_ONE, 'ParticipantAttribute', 'attribute_id')
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'attribute_id' => 'Attribute',
'attribute_type' => 'Attribute Type',
'visible' => 'Visible',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('attribute_id',$this->attribute_id);
$criteria->compare('attribute_type',$this->attribute_type,true);
$criteria->compare('visible',$this->visible,true);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'attribute_id' => 'Attribute',
'attribute_type' => 'Attribute Type',
'visible' => 'Visible',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('attribute_id',$this->attribute_id);
$criteria->compare('attribute_type',$this->attribute_type,true);
$criteria->compare('visible',$this->visible,true);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}


function getAllAttributes()
{
return Yii::app()->db->createCommand()->select('{{participant_attribute_names}}.*,{{participant_attribute_names}}_lang.*')
$aResult=Yii::app()->db->createCommand()->select('{{participant_attribute_names}}.*')
->from('{{participant_attribute_names}}')
->order('{{participant_attribute_names}}.attribute_id', 'desc')
->join('{{participant_attribute_names}}_lang', '{{participant_attribute_names}}_lang.attribute_id = {{participant_attribute_names}}.attribute_id')
->where("{{participant_attribute_names}}_lang.lang = '".Yii::app()->session['adminlang']."'")
->order('{{participant_attribute_names}}.attribute_id')
->queryAll();
return $aResult;
}

function getAllAttributesValues()
{
return Yii::app()->db->createCommand()->select('*')->from('{{participant_attribute_values}}')->queryAll();
}

function getVisibleAttributes()
/**
* Get an array of CPDB attributes
*
* @param mixed $sLanguageFilter
*/
function getVisibleAttributes($sLanguageFilter=null)
{
$currentlang=Yii::app()->session['adminlang'];
if ($sLanguageFilter==null) $sLanguageFilter=Yii::app()->session['adminlang'];
$output=array();
//First get all the distinct id's that are visible
$ids = ParticipantAttributeName::model()->findAll("visible = 'TRUE'");
Expand All @@ -162,7 +167,7 @@ function getVisibleAttributes()
$language=null;
foreach($langs as $lang) {
//If we can find a language match, set the language and exit
if($lang->lang == $currentlang) {
if($lang->lang == $sLanguageFilter) {
$language = $lang->lang;
$attribute_name = $lang->attribute_name;
break;
Expand Down Expand Up @@ -301,13 +306,13 @@ function getnotaddedAttributes($attributeid)
{
$output = array();
$notin=array();
foreach($attributeid as $row)
{
$notin[] = $row;
}
foreach($attributeid as $row)
{
$notin[] = $row;
}

$criteria = new CDbCriteria();
$alias = $this->getTableAlias();
$alias = $this->getTableAlias();
$criteria->addNotInCondition("$alias.attribute_id", $attributeid);
$records = ParticipantAttributeName::model()->with('participant_attribute_names_lang')->findAll($criteria);
foreach($records as $row) { //Iterate through each attribute
Expand All @@ -327,21 +332,25 @@ function getnotaddedAttributes($attributeid)

}

/**
* Adds the data for a new attribute
*
* @param mixed $data
*/
function storeAttribute($data)
{
{
$insertnames = array('attribute_type' => $data['attribute_type'],
'visible' => $data['visible']);
'defaultname'=> $data['attribute_name'],
'visible' => $data['visible']);
Yii::app()->db->createCommand()
->insert('{{participant_attribute_names}}',$insertnames);
->insert('{{participant_attribute_names}}',$insertnames);
$attribute_id = getLastInsertID($this->tableName());
$insertnameslang = array('attribute_id' => intval($attribute_id),
'attribute_name'=> $data['attribute_name'],
'lang' => Yii::app()->session['adminlang']);
'attribute_name'=> $data['attribute_name'],
'lang' => Yii::app()->session['adminlang']);
Yii::app()->db->createCommand()
->insert('{{participant_attribute_names_lang}}',$insertnameslang);

->insert('{{participant_attribute_names_lang}}',$insertnameslang);
return $attribute_id;

}

function editParticipantAttributeValue($data)
Expand All @@ -351,18 +360,18 @@ function editParticipantAttributeValue($data)
':attribute_id'=>$data['attribute_id'])
);
if(count($query) == 0)
{
{
Yii::app()->db->createCommand()
->insert('{{participant_attribute}}',$data);
}
else
{
}
else
{
Yii::app()->db->createCommand()
->update('{{participant_attribute}}',
$data,
'participant_id = :participant_id2 AND attribute_id = :attribute_id2',
array(':participant_id2' => $data['participant_id'], ':attribute_id2'=>$data['attribute_id']));
}
}

}

Expand Down Expand Up @@ -403,7 +412,6 @@ function saveAttribute($data)
{
return;
}

$insertnames = array();
if (!empty($data['attribute_type']))
{
Expand All @@ -413,11 +421,14 @@ function saveAttribute($data)
{
$insertnames['visible'] = $data['visible'];
}
if (!empty($data['defaultname']))
{
$insertnames['defaultname'] = $data['defaultname'];
}
if (!empty($insertnames))
{
self::model()->updateAll($insertnames, 'attribute_id = :id', array(':id' => $data['attribute_id']));
}

if (!empty($data['attribute_name']))
{
Yii::app()->db->createCommand()
Expand Down Expand Up @@ -453,21 +464,21 @@ function saveAttributeLanguages($data)
function storeAttributeValues($data)
{
foreach ($data as $record) {
Yii::app()->db->createCommand()->insert('{{participant_attribute_values}}',$record);
}
Yii::app()->db->createCommand()->insert('{{participant_attribute_values}}',$record);
}
}

function storeAttributeCSV($data)
{
$insertnames = array('attribute_type' => $data['attribute_type'],
'visible' => $data['visible']);
Yii::app()->db->createCommand()->insert('{{participant_attribute_names}}', $insertnames);
Yii::app()->db->createCommand()->insert('{{participant_attribute_names}}', $insertnames);

$insertid = getLastInsertID($this->tableName());
$insertnameslang = array('attribute_id' => $insertid,
'attribute_name'=>$data['attribute_name'],
'lang' => Yii::app()->session['adminlang']);
Yii::app()->db->createCommand()->insert('{{participant_attribute_names_lang}}', $insertnameslang);
Yii::app()->db->createCommand()->insert('{{participant_attribute_names_lang}}', $insertnameslang);
return $insertid;
}

Expand All @@ -493,13 +504,13 @@ function saveAttributeVisible($attid,$visiblecondition)

function getAttributeID()
{
$query = Yii::app()->db->createCommand()->select('attribute_id')->from('{{participant_attribute_names}}')->order('attribute_id','desc')->queryAll();
$query = Yii::app()->db->createCommand()->select('attribute_id')->from('{{participant_attribute_names}}')->order('attribute_id','desc')->queryAll();
return $query;
}


function saveParticipantAttributeValue($data)
{
Yii::app()->db->createCommand()->insert('{{participant_attribute}}', $data);
Yii::app()->db->createCommand()->insert('{{participant_attribute}}', $data);
}
}
Loading

0 comments on commit 1185d59

Please sign in to comment.