Skip to content

Commit

Permalink
Fixed issue #10187: added table alias for "like" research
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 28, 2015
1 parent 943a141 commit d313353
Showing 1 changed file with 119 additions and 121 deletions.
240 changes: 119 additions & 121 deletions application/models/Survey.php
Expand Up @@ -27,8 +27,8 @@ class Survey extends LSActiveRecord
protected $findByPkCache = array();
/* Set some setting not by default database */
public $format = 'G';
public $full_answers_account=null;
public $partial_answers_account=null;
public $full_answers_account=null;
public $partial_answers_account=null;
public $searched_value;

private $fac;
Expand Down Expand Up @@ -136,7 +136,7 @@ public function relations()
'owner' => array(self::BELONGS_TO, 'User', 'owner_id'),
'groups' => array(self::HAS_MANY, 'QuestionGroup', 'sid'),
// ????????
// 'owner' => array(self::BELONGS_TO, 'User', '', 'on' => "$alias.owner_id = owner.uid"),
// 'owner' => array(self::BELONGS_TO, 'User', '', 'on' => "$alias.owner_id = owner.uid"),

);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ public function fixSurveyAttribute($event)
}

/**
* filterTemplateSave to fix some template name
* filterTemplateSave to fix some template name
*/
public function filterTemplateSave($sTemplateName)
{
Expand Down Expand Up @@ -541,88 +541,88 @@ public function setAllowjumps($value)
}
}

public function getSurveyinfo()
{
$iSurveyID = $this->sid;
$baselang = $this->language;
public function getSurveyinfo()
{
$iSurveyID = $this->sid;
$baselang = $this->language;

$condition = array('sid' => $iSurveyID, 'language' => $baselang);
$condition = array('sid' => $iSurveyID, 'language' => $baselang);

//// TODO : replace this with a HAS MANY relation !
$sumresult1 = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->find('sid = :surveyid', array(':surveyid' => $iSurveyID)); //$sumquery1, 1) ; //Checked
if (is_null($sumresult1))
{
Yii::app()->session['flashmessage'] = gT("Invalid survey ID");
$this->getController()->redirect(array("admin/index"));
} // if surveyid is invalid then die to prevent errors at a later time
$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_merge($surveyinfo, $sumresult1->defaultlanguage->attributes);
$surveyinfo = array_map('flattenText', $surveyinfo);
//// TODO : replace this with a HAS MANY relation !
$sumresult1 = Survey::model()->with(array('languagesettings'=>array('condition'=>'surveyls_language=language')))->find('sid = :surveyid', array(':surveyid' => $iSurveyID)); //$sumquery1, 1) ; //Checked
if (is_null($sumresult1))
{
Yii::app()->session['flashmessage'] = gT("Invalid survey ID");
$this->getController()->redirect(array("admin/index"));
} // if surveyid is invalid then die to prevent errors at a later time
$surveyinfo = $sumresult1->attributes;
$surveyinfo = array_merge($surveyinfo, $sumresult1->defaultlanguage->attributes);
$surveyinfo = array_map('flattenText', $surveyinfo);
//$surveyinfo["groups"] = $this->groups;
return $surveyinfo;
}


public function getCreationDate()
{
$dateformatdata=getDateFormatData(Yii::app()->session['dateformat']);
return convertDateTimeFormat($this->datecreated, 'Y-m-d', $dateformatdata['phpdate']);
}

public function getAnonymizedResponses()
{
$anonymizedResponses = ($this->anonymized == 'Y')?gT('Yes'):gT('No');
return $anonymizedResponses;
}

public function getActiveWord()
{
$activeword = ($this->active == 'Y')?gT('Yes'):gT('No');
return $activeword;
}

public function getPartialAnswers()
{
$table = '{{survey_' . $this->sid . '}}';
return $surveyinfo;
}


public function getCreationDate()
{
$dateformatdata=getDateFormatData(Yii::app()->session['dateformat']);
return convertDateTimeFormat($this->datecreated, 'Y-m-d', $dateformatdata['phpdate']);
}

public function getAnonymizedResponses()
{
$anonymizedResponses = ($this->anonymized == 'Y')?gT('Yes'):gT('No');
return $anonymizedResponses;
}

public function getActiveWord()
{
$activeword = ($this->active == 'Y')?gT('Yes'):gT('No');
return $activeword;
}

public function getPartialAnswers()
{
$table = '{{survey_' . $this->sid . '}}';
Yii::app()->cache->flush();
if (!Yii::app()->db->schema->getTable($table))
{
return null;
}
else
{
$answers = Yii::app()->db->createCommand()
->select('*')
->from($table)
->where('submitdate IS NULL')
->queryAll();

return $answers;
}
}

public function getFullAnswers()
{
$table = '{{survey_' . $this->sid . '}}';
if (!Yii::app()->db->schema->getTable($table))
{
return null;
}
else
{
$answers = Yii::app()->db->createCommand()
->select('*')
->from($table)
->where('submitdate IS NULL')
->queryAll();

return $answers;
}
}

public function getFullAnswers()
{
$table = '{{survey_' . $this->sid . '}}';
Yii::app()->cache->flush();
if (!Yii::app()->db->schema->getTable($table))
{
return null;
}
else
{
$answers = Yii::app()->db->createCommand()
->select('*')
->from($table)
->where('submitdate IS NOT NULL')
->queryAll();

return $answers;
}
}

public function getCountFullAnswers()
{
if (!Yii::app()->db->schema->getTable($table))
{
return null;
}
else
{
$answers = Yii::app()->db->createCommand()
->select('*')
->from($table)
->where('submitdate IS NOT NULL')
->queryAll();

return $answers;
}
}

public function getCountFullAnswers()
{
if($this->fac!==null)
{
return $this->fac;
Expand All @@ -631,22 +631,22 @@ public function getCountFullAnswers()
{
$table = '{{survey_' . $this->sid . '}}';
Yii::app()->cache->flush();
if (!Yii::app()->db->schema->getTable($table))
{
if (!Yii::app()->db->schema->getTable($table))
{
$this->fac = 0;
return '0';
}
else
{
return '0';
}
else
{
$answers = Yii::app()->db->createCommand('select count(*) from '.$table.' where submitdate IS NOT NULL')->queryScalar();
$this->fac = $answers;
return $answers;
}
return $answers;
}
}
}
}

public function getCountPartialAnswers()
{
public function getCountPartialAnswers()
{
if($this->pac!==null)
{
return $this->pac;
Expand All @@ -655,47 +655,47 @@ public function getCountPartialAnswers()
{
$table = '{{survey_' . $this->sid . '}}';
Yii::app()->cache->flush();
if (!Yii::app()->db->schema->getTable($table))
{
if (!Yii::app()->db->schema->getTable($table))
{
$this->pac = 0;
return 0;
}
else
{
return 0;
}
else
{
$answers = Yii::app()->db->createCommand('select count(*) from '.$table.' where submitdate IS NULL')->queryScalar();
$this->pac = $answers;
return $answers;
}
return $answers;
}
}
}
}

public function getCountTotalAnswers()
{
public function getCountTotalAnswers()
{
if ($this->pac!==null && $this->fac!==null)
{
return ($this->pac + $this->fac);
}
else
{
return ($this->countFullAnswers + $this->countPartialAnswers);
return ($this->countFullAnswers + $this->countPartialAnswers);
}
}
}

public function getbuttons()
{
public function getbuttons()
{


$url = Yii::app()->createUrl("/admin/survey/sa/view/surveyid/");
$url .= '/'.$this->sid;
$button = '<a class="btn btn-default" href="'.$url.'" role="button"><span class="glyphicon glyphicon-pencil" ></span></a>';
$url = Yii::app()->createUrl("/admin/survey/sa/view/surveyid/");
$url .= '/'.$this->sid;
$button = '<a class="btn btn-default" href="'.$url.'" role="button"><span class="glyphicon glyphicon-pencil" ></span></a>';

$previewUrl = Yii::app()->createUrl("survey/index/sid/");
$previewUrl .= '/'.$this->sid;
$previewUrl = Yii::app()->createUrl("survey/index/sid/");
$previewUrl .= '/'.$this->sid;

//$button = '<a class="btn btn-default open-preview" aria-data-url="'.$previewUrl.'" aria-data-language="'.$this->language.'" href="# role="button" ><span class="glyphicon glyphicon-eye-open" ></span></a> ';
$button = '<a class="btn btn-default" href="'.$url.'" role="button"><span class="glyphicon glyphicon-pencil" ></span></a>';
return $button;
}
//$button = '<a class="btn btn-default open-preview" aria-data-url="'.$previewUrl.'" aria-data-language="'.$this->language.'" href="# role="button" ><span class="glyphicon glyphicon-eye-open" ></span></a> ';
$button = '<a class="btn btn-default" href="'.$url.'" role="button"><span class="glyphicon glyphicon-pencil" ></span></a>';
return $button;
}

public function search()
{
Expand Down Expand Up @@ -746,17 +746,15 @@ public function search()

$criteria->join ='LEFT JOIN {{surveys_languagesettings}} AS surveys_languagesettings ON ( surveys_languagesettings.surveyls_language = t.language AND t.sid = surveys_languagesettings.surveyls_survey_id )';
$criteria->join .='LEFT JOIN {{users}} AS users ON ( users.uid = t.owner_id )';
$criteria->compare('active', $this->active, true, 'AND');
$criteria->compare('t.active', $this->active, true, 'AND');
$criteria->compare('surveys_languagesettings.surveyls_title', $this->searched_value, true, 'AND');
$criteria->compare('sid', $this->searched_value, true, 'OR');
$criteria->compare('admin', $this->searched_value, true, 'OR');
$criteria->compare('t.sid', $this->searched_value, true, 'OR');
$criteria->compare('t.admin', $this->searched_value, true, 'OR');


$dataProvider=new CActiveDataProvider('Survey', array(

'sort'=>$sort,
'criteria'=>$criteria,

'pagination'=>array(
'pageSize'=>$pageSize,
),
Expand Down

0 comments on commit d313353

Please sign in to comment.