Skip to content

Commit

Permalink
Dev: cleaning models
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Aug 9, 2018
1 parent 22d43c5 commit 30d9d67
Show file tree
Hide file tree
Showing 30 changed files with 352 additions and 352 deletions.
2 changes: 1 addition & 1 deletion application/models/Assessment.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function search()
$criteria->compare('maximum', $this->maximum);
$criteria->compare('message', $this->message, true);
$criteria->compare('language', $survey->language);

$pageSize = Yii::app()->user->getState('pageSizeParticipantView', Yii::app()->params['defaultPageSize']);
return new CActiveDataProvider(
$this,
Expand Down
2 changes: 1 addition & 1 deletion application/models/DefaultValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function rules()
'message'=>'{attribute} "{value}" is already in use.'),
);
}

public function insertRecords($data)
{
$oRecord = new self;
Expand Down
2 changes: 1 addition & 1 deletion application/models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ protected static function getCriteria($surveyId = null)
$criteria->params = $params;
$criteria->order = 'id DESC';
$criteria->limit = 50;

return $criteria;
}

Expand Down
26 changes: 13 additions & 13 deletions application/models/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function attributeLabels()
$returnArray[$name] = $attribute['defaultname'];
}
return $returnArray;

}

/**
Expand Down Expand Up @@ -307,7 +307,7 @@ public function getParticipantAttribute($attributeTextId, $attribute_id = false)
$participantAttributes = ParticipantAttribute::model()->getAttributeInfo($this->participant_id);
foreach ($participantAttributes as $singleAttribute) {
if ($singleAttribute['attribute_id'] == $attribute_id) {
return $singleAttribute['value'];
return $singleAttribute['value'];
}
}
return "";
Expand Down Expand Up @@ -407,7 +407,7 @@ public function getColumns()
"id" => $name,
"header" => $attribute['defaultname'],
"type" => "raw",

);
//textbox
if ($attribute['attribute_type'] == "TB") {
Expand Down Expand Up @@ -534,7 +534,7 @@ public function search()
$criteria->addCondition('t.owner_uid = '.Yii::app()->user->id.' OR '.Yii::app()->user->id.' = shares.share_uid OR shares.share_uid = -1');
}

$pageSize = Yii::app()->user->getState('pageSizeParticipantView', Yii::app()->params['defaultPageSize']);
$pageSize = Yii::app()->user->getState('pageSizeParticipantView', Yii::app()->params['defaultPageSize']);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort' => $sort,
Expand All @@ -561,7 +561,7 @@ public function getOwnersList($selected)
$ownerList[$id['owner_uid']] = $oUser->full_name;
}
return TbHtml::dropDownList('Participant[owner_uid]', $selected, $ownerList);

}

public function addSurveyFilter($conditions)
Expand Down Expand Up @@ -1342,7 +1342,7 @@ public function getParticipantsSearchMultipleCondition($condition)
'owner_name');
if (!in_array($sFieldname, $aSafeFieldNames)) {
// Skip invalid fieldname
continue;
continue;
}
$command->addCondition(Yii::app()->db->quoteColumnName($sFieldname).' '.$operator.' '.$param, $booloperator);
}
Expand Down Expand Up @@ -1694,7 +1694,7 @@ private function writeParticipantsToTokenTable(
} catch (Exception $e) {
throw new Exception(gT("Could not update token attribute value: ".$e->getMessage()));
}

//If there are new attributes created, add those values to the token entry for this participant
if (!empty($newAttributes)) {
$numberofattributes = count($addedAttributes);
Expand Down Expand Up @@ -1911,34 +1911,34 @@ public function copyToCentral($surveyid, $aAttributesToBeCreated, $aMapped, $ove
* $value is the 'friendly name' for the attribute (ie "Gender")
*/
$insertnames = array(
'attribute_type' => 'TB',
'visible' => 'Y',
'attribute_type' => 'TB',
'visible' => 'Y',
'defaultname' => $value
);
$oParticipantAttributeNames = new ParticipantAttributeName();
$oParticipantAttributeNames->setAttributes($insertnames, false);
$oParticipantAttributeNames->save(false);
$attid[$key] = $oParticipantAttributeNames->getPrimaryKey();

$insertnameslang = array(
'attribute_id' => $attid[$key],
'attribute_name' => urldecode($value),
'lang' => Yii::app()->session['adminlang']
);
$oParticipantAttributeNamesLang = new ParticipantAttributeNameLang();
$oParticipantAttributeNamesLang->setAttributes($insertnameslang, false);
$oParticipantAttributeNamesLang->save(false);
$oParticipantAttributeNamesLang->save(false);

}
}

/* Add the participants to the CPDB = Iterate through each $tokenid and create the new CPDB id*/
if (!is_array($tokenids)) { $tokenids = (array) $tokenids; }
if (!is_array($tokenids)) { $tokenids = (array) $tokenids; }
foreach ($tokenids as $tid) {
if (is_numeric($tid) && $tid != "") {
/* Get the data for this participant from the tokens table */
$oTokenDynamic = TokenDynamic::model($survey->sid)->findByPk($tid);

/* See if there are any existing CPDB entries that match on firstname,lastname and email */
$participantCriteria = new CDbCriteria();
$participantCriteria->addCondition('firstname = :firstname');
Expand Down
6 changes: 3 additions & 3 deletions application/models/ParticipantAttributeName.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @property string $visible
* @property ParticipantAttributeNameLang[] $participant_attribute_names_lang
* @property ParticipantAttribute $participant_attribute
* @property array $AttributeTypeDropdownArray
* @property array $AttributeTypeDropdownArray
*
*/
class ParticipantAttributeName extends LSActiveRecord
Expand Down Expand Up @@ -100,7 +100,7 @@ public function getButtons()
. "</button>";
$buttons = "";
//DELETE attribute
//Edit-button
//Edit-button
$editData = array(
'action_attributeNames_editModal',
'',
Expand Down Expand Up @@ -640,7 +640,7 @@ public function saveAttributeLanguages($data)
$oParticipantAttributeNameLang->save();
} else {
$oParticipantAttributeNameLang = ParticipantAttributeNameLang::model()->findByPk(array(
'attribute_id' => $data['attribute_id'],
'attribute_id' => $data['attribute_id'],
'lang' => $data['lang']
));
$oParticipantAttributeNameLang->attribute_name = $data['attribute_name'];
Expand Down
4 changes: 2 additions & 2 deletions application/models/ParticipantShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ 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' => array(self::HAS_ONE, 'Participant', array('participant_id' => 'participant_id')),
'participant' => array(self::HAS_ONE, 'Participant', array('participant_id' => 'participant_id')),
'shared_by' => array(self::HAS_ONE, 'User', array('uid' => 'share_uid')),
'surveylinks' => array(self::HAS_ONE, 'SurveyLink', 'participant_id'),
'participantAttributes' => array(self::HAS_MANY, 'ParticipantAttribute', 'participant_id', 'with'=>'participant_attribute_names', 'joinType'=> 'LEFT JOIN')
Expand Down Expand Up @@ -350,7 +350,7 @@ public function updateShare($data)
$criteria->addCondition("share_uid = '{$data['share_uid']}' ");
ParticipantShare::model()->updateAll($data, $criteria);
}

/**
* @param string $rows Comma-separated list of something
* @return void
Expand Down
8 changes: 4 additions & 4 deletions application/models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static function updateSortOrder($gid, $surveyid)
array('gid' => $gid, 'sid' => $surveyid, 'parent_qid'=>0, 'language' => Survey::model()->findByPk($surveyid)->language),
array('order'=>'question_order')
);

$p = 0;
foreach ($questions as $question) {
$question->question_order = $p;
Expand Down Expand Up @@ -305,7 +305,7 @@ public static function getQuestionTemplateAttributes($aAttributeNames, $aAttribu

public function getTypeGroup()
{

}

/**
Expand Down Expand Up @@ -827,7 +827,7 @@ public function getbuttons()
." onclick='$.bsconfirm(\"".gT("Deleting will also delete any answer options and subquestions it includes. Are you sure you want to continue?","js")
."\", {\"confirm_ok\": \"".gT("Yes")."\", \"confirm_cancel\": \"".gT("No")."\"}, function() {"
. convertGETtoPOST(Yii::app()->createUrl("admin/questions/sa/delete/", ["surveyid" => $this->sid, "qid" => $this->qid, "gid" => $gid_search]))
."});'>"
."});'>"
.' <i class="text-danger fa fa-trash"></i>
</a>';
}
Expand Down Expand Up @@ -881,7 +881,7 @@ public function getOrderedSubQuestions($random = 0, $exclude_all_others = '')
if (($answer['title'] == trim($exclude_all_others))) {
if ($position == $answer['question_order'] - 1) {
//already in the right position
break;
break;
}
$tmp = array_splice($ansresult, $position, 1);
array_splice($ansresult, $answer['question_order'] - 1, 0, $tmp);
Expand Down
8 changes: 4 additions & 4 deletions application/models/QuestionGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ public function updateGroupOrder($sid, $lang, $position = 0)
$position++;
}
}

public function cleanOrder($surveyid){
$iSurveyId = (int) $surveyid;
$oSurvey = Survey::model()->findByPk($iSurveyId);

$aSurveyLanguages = array_merge([$oSurvey->language], explode(" ", $oSurvey->additional_languages));

foreach ($aSurveyLanguages as $sSurveyLanguage) {
$oCriteria=new CDbCriteria;
$oCriteria->compare('sid',$iSurveyId);
Expand Down Expand Up @@ -331,7 +331,7 @@ public function getbuttons()
$condarray = getGroupDepsForConditions($this->sid, "all", $this->gid, "by-targgid");
if (is_null($condarray)) {
$sDeleteUrl = Yii::app()->createUrl("admin/questiongroups/sa/delete/surveyid/$this->sid/gid/$this->gid");

$button .= '<span data-toggle="tooltip" title="'.gT('Delete survey group').'">'
.'<a class="btn btn-default" href="#" '
.' data-href="'.$sDeleteUrl.'" '
Expand Down
2 changes: 1 addition & 1 deletion application/models/QuotaLanguageSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function insertRecords($data)
} else {
$settings->$k = $v;
}
}
}
return $settings->save();
}
}
6 changes: 3 additions & 3 deletions application/models/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public function afterFind()
$sDatabasetype = Yii::app()->db->getDriverName();
// MSSQL delivers hex data (except for dblib driver)
if ($sDatabasetype == 'sqlsrv' || $sDatabasetype == 'mssql') {
$this->data = $this->hexToStr($this->data);
$this->data = $this->hexToStr($this->data);
}
// Postgres delivers a stream pointer
if (gettype($this->data) == 'resource') {
$this->data = stream_get_contents($this->data, -1, 0);
}
$this->data = stream_get_contents($this->data, -1, 0);
}
return parent::afterFind();
}

Expand Down
10 changes: 5 additions & 5 deletions application/models/SettingsUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function attributeLabels()

public static function setUserSetting($stg_name, $stg_value, $uid = null, $entity = null, $entity_id = null)
{
if ($uid === null) { $uid = Yii::app()->user->getId(); }
if ($uid === null) { $uid = Yii::app()->user->getId(); }

$setting = self::getUserSetting($stg_name, $uid, $entity, $entity_id);

Expand All @@ -91,7 +91,7 @@ public static function setUserSetting($stg_name, $stg_value, $uid = null, $entit
'uid' => $uid,
'entity' => $entity,
'entity_id' => $entity_id
]);
]);
}
$setting->setAttribute('stg_value', $stg_value);

Expand All @@ -109,14 +109,14 @@ public static function setUserSetting($stg_name, $stg_value, $uid = null, $entit
*/
public static function getUserSetting($stg_name, $uid = null, $entity = null, $entity_id = null)
{
if ($uid === null) { $uid = Yii::app()->user->getId(); }
if ($uid === null) { $uid = Yii::app()->user->getId(); }
$searchCriteria = new CDbCriteria;
$searchParams = [];

$searchCriteria->addCondition('uid=:uid');
$searchParams[':uid'] = $uid;
$searchCriteria->addCondition('stg_name=:stg_name');
$searchParams[':stg_name'] = $stg_name;
$searchParams[':stg_name'] = $stg_name;
if ($entity != null) {
$searchCriteria->addCondition('entity=:entity');
$searchParams[':entity'] = $entity;
Expand All @@ -131,7 +131,7 @@ public static function getUserSetting($stg_name, $uid = null, $entity = null, $e
}

$searchCriteria->params = $searchParams;

$setting = self::model()->find($searchCriteria);

return $setting;
Expand Down
22 changes: 11 additions & 11 deletions application/models/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class Survey extends LSActiveRecord


public $searched_value;
public $showsurveypolicynotice = 0;

public $showsurveypolicynotice = 0;


private $sSurveyUrl;
Expand Down Expand Up @@ -792,7 +792,7 @@ private function _createSurveymenuArray($oSurveyMenuObjects, $collapsed=false)
if ($collapsed && $aEntry['showincollapse'] == 0 ) {
continue;
}

//Skip menu if no permission
if ((!empty($aEntry['permission']) && !empty($aEntry['permission_grade'])
&& !Permission::model()->hasSurveyPermission($this->sid, $aEntry['permission'], $aEntry['permission_grade']))
Expand Down Expand Up @@ -867,18 +867,18 @@ private function _getDefaultSurveyMenus($position = '')
$criteria = new CDbCriteria;
$criteria->condition = 'survey_id IS NULL AND parent_id IS NULL';
$collapsed = $position==='collapsed';

if ($position != '' && !$collapsed) {
$criteria->condition .= ' AND position=:position';
$criteria->params = array(':position'=>$position);
}

if ($collapsed) {
$criteria->condition .= ' AND (position=:position OR showincollapse=1 )';
$criteria->params = array(':position'=>$position);
$collapsed = true;
}

$oDefaultMenus = Surveymenu::model()->findAll($criteria);
$aResultCollected = $this->_createSurveymenuArray($oDefaultMenus, $collapsed);

Expand Down Expand Up @@ -1901,27 +1901,27 @@ public function hasQuestionType($type, $includeSubquestions = false)
}

public static function replacePolicyLink($dataSecurityNoticeLabel, $surveyId) {

$STARTPOLICYLINK = "";
$ENDPOLICYLINK = "";

if(self::model()->findByPk($surveyId)->showsurveypolicynotice == 2){
$STARTPOLICYLINK = "<a href='#data-security-modal-".$surveyId."' data-toggle='collapse'>";
$ENDPOLICYLINK = "</a>";
if(!preg_match('/(\{STARTPOLICYLINK\}|\{ENDPOLICYLINK\})/', $dataSecurityNoticeLabel)){
$dataSecurityNoticeLabel.= "<br/> {STARTPOLICYLINK}".gT("Show policy")."{ENDPOLICYLINK}";
}
}



$dataSecurityNoticeLabel = preg_replace('/\{STARTPOLICYLINK\}/', $STARTPOLICYLINK ,$dataSecurityNoticeLabel);

$countEndLabel = 0;
$dataSecurityNoticeLabel = preg_replace('/\{ENDPOLICYLINK\}/', $ENDPOLICYLINK ,$dataSecurityNoticeLabel, -1, $countEndLabel);
if($countEndLabel == 0){
$dataSecurityNoticeLabel .= '</a>';
}
}

return $dataSecurityNoticeLabel;

Expand Down

0 comments on commit 30d9d67

Please sign in to comment.