Skip to content

Commit

Permalink
Dev: Refactor the 'translate' admin controller in the LimeSurvey Yii …
Browse files Browse the repository at this point in the history
…port (GCI2011 By Georgi Kostadinov)

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11800 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Pieter Jan Speelmans committed Dec 29, 2011
1 parent e618998 commit 9887e8d
Show file tree
Hide file tree
Showing 11 changed files with 1,046 additions and 1,123 deletions.
1,877 changes: 882 additions & 995 deletions application/controllers/admin/translate.php

Large diffs are not rendered by default.

142 changes: 73 additions & 69 deletions application/models/Answers.php
Expand Up @@ -10,97 +10,91 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id: Admin_Controller.php 11256 2011-10-25 13:52:18Z c_schmitz $
* $Id: Admin_Controller.php 11256 2011-10-25 13:52:18Z c_schmitz $
*/

class Answers extends CActiveRecord
{
/**
* Returns the static model of Settings table
*
* @static
* @access public
* @return CActiveRecord
*/
public static function model()
{
return parent::model(__CLASS__);
}
/**
* Returns the static model of Settings table
*
* @static
* @access public
* @return CActiveRecord
*/
public static function model()
{
return parent::model(__CLASS__);
}

/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{answers}}';
}
/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{answers}}';
}

/**
* Returns the primary key of this table
*
* @access public
* @return array
*/
public function primaryKey()
{
return array('qid', 'code');
}
/**
* Returns the primary key of this table
*
* @access public
* @return array
*/
public function primaryKey()
{
return array('qid', 'code');
}

function getSomeRecords($fields, $condition=FALSE, $order='')
{
return Yii::app()->db->createCommand()
->select($fields)
->from(self::tableName())
->where($condition)
->order($order)
->queryAll();
}
function getSomeRecords($fields, $condition=FALSE, $order='')
{
return Yii::app()->db->createCommand()
->select($fields)
->from(self::tableName())
->where($condition)
->order($order)
->queryAll();
}

function getAnswers($qid)
{
return Yii::app()->db->createCommand()
->select()
->from(self::tableName())
->where(array('and', 'qid='.$qid))
->order('code asc')
->query();
return Yii::app()->db->createCommand()
->select()
->from(self::tableName())
->where(array('and', 'qid='.$qid))
->order('code asc')
->query();
}

function getAnswerCode($qid, $code, $lang)
{
return Yii::app()->db->createCommand()
->select(array('code', 'answer'))
->from(self::tableName())
->where(array('and', 'qid='.$qid, 'code="'.$code.'"', 'scale_id=0', 'language="'.$lang.'"'))
->query();
return Yii::app()->db->createCommand()
->select(array('code', 'answer'))
->from(self::tableName())
->where(array('and', 'qid='.$qid, 'code="'.$code.'"', 'scale_id=0', 'language="'.$lang.'"'))
->query();
}

public function oldNewInsertansTags($newsid,$oldsid)
{
$sql = "SELECT a.qid, a.language, a.code, a.answer from {{answers}} as a INNER JOIN {{questions}} as b ON a.qid=b.qid WHERE b.sid=".$newsid." AND a.answer LIKE '%{INSERTANS:".$oldsid."X%'";
return Yii::app()->db->createCommand($sql)->query();
}
public function oldNewInsertansTags($newsid,$oldsid)
{
$sql = "SELECT a.qid, a.language, a.code, a.answer from {{answers}} as a INNER JOIN {{questions}} as b ON a.qid=b.qid WHERE b.sid=".$newsid." AND a.answer LIKE '%{INSERTANS:".$oldsid."X%'";
return Yii::app()->db->createCommand($sql)->query();
}

public function update($data, $condition=FALSE)
public function update($data, $condition=FALSE)
{
if ($condition != FALSE)
{
$this->db->where($condition);
}

return $this->db->update('answers', $data);

return Yii::app()->db->createCommand()->update(self::tableName(), $data, $condition ? $condition : '');
}

function insertRecords($data)
function insertRecords($data)
{
$ans = new self;
foreach ($data as $k => $v)
$ans->$k = $v;
return $ans->save();
foreach ($data as $k => $v)
$ans->$k = $v;
return $ans->save();
}

/**
Expand All @@ -124,6 +118,16 @@ public static function updateSortOrder($qid, $lang)
}
}

public function getAnswerQuery($surveyid, $lang, $return_query = TRUE)
{
$query = Yii::app()->db->createCommand();
$query->select("{{answers}}.*, {{questions}}.gid");
$query->from("{{answers}}, {{questions}}");
$query->where("{{questions}}.sid = '{$surveyid}' AND {{questions}}.qid = {{answers}}.qid AND {{questions}}.language = {{answers}}.language AND {{questions}}.language = '{$lang}'");
$query->order('qid, code, sortorder');
return ( $return_query ) ? $query->queryAll() : $query;
}

function getAllRecords($condition, $order=FALSE)
{
$command=Yii::app()->db->createCommand()->select('*')->from($this->tableName())->where($condition);
Expand Down
21 changes: 19 additions & 2 deletions application/models/Groups.php
Expand Up @@ -50,6 +50,23 @@ public function primaryKey()
return 'gid';
}

function getAllRecords($condition=FALSE, $order=FALSE, $return_query = TRUE)
{
$query = Yii::app()->db->createCommand()->select('*')->from('{{groups}}');

if ($condition != FALSE)
{
$query->where($condition);
}

if($order != FALSE)
{
$query->order($order);
}

return ( $return_query ) ? $query->queryAll() : $query;
}

function updateGroupOrder($sid,$lang,$position=0)
{
$data=Yii::app()->db->createCommand()->select('gid')->where(array('and','sid='.$sid,'language="'.$lang.'"'))->order('group_order, group_name ASC')->from('{{groups}}')->query();
Expand Down Expand Up @@ -111,7 +128,7 @@ private static function getQuestionIdsInGroup($groupId) {
}
function getAllGroups($condition, $order=false)
{


$command = Yii::app()->db->createCommand()->where($condition)->select('*')->from($this->tableName());
if ($order != FALSE)
Expand All @@ -120,7 +137,7 @@ function getAllGroups($condition, $order=false)
}
return $command->query();
}

function getSomeRecords($fields, $condition=null)
{
return Yii::app()->db->createCommand()
Expand Down
11 changes: 9 additions & 2 deletions application/models/Questions.php
Expand Up @@ -196,7 +196,7 @@ function insertRecords($data)
return $questions->save();
}

function getSomeRecords($fields, $condition, $order=NULL)
function getSomeRecords($fields, $condition, $order=NULL, $return_query = TRUE)
{
$record = Yii::app()->db->createCommand()
->select($fields)
Expand All @@ -208,7 +208,14 @@ function getSomeRecords($fields, $condition, $order=NULL)
$record->order($order);
}

return $record->query();
return ( $return_query ) ? $record->queryAll() : $record;
}

function update($data, $condition=FALSE)
{

return Yii::app()->db->createCommand()->update('{{questions}}', $data, $condition);

}

public static function deleteAllById($questionsIds)
Expand Down
18 changes: 14 additions & 4 deletions application/models/Survey.php
Expand Up @@ -118,13 +118,13 @@ public function getOneRecord($condition=FALSE)
$criteria = new CDbCriteria;

if ($condition != FALSE)
{
{
foreach ($condition as $item => $value)
{
$criteria->addCondition($item.'="'.$value.'"');
}
}

return $this->find($criteria);
}

Expand Down Expand Up @@ -271,13 +271,23 @@ public function loadSurveys($is_superadmin)
$query = " SELECT a.*, c.*, u.users_name FROM {{surveys}} as a "
." INNER JOIN {{surveys_languagesettings}} as c ON ( surveyls_survey_id = a.sid AND surveyls_language = a.language ) AND surveyls_survey_id=a.sid AND surveyls_language=a.language "
." INNER JOIN {{users}} as u ON (u.uid=a.owner_id) ";

if($is_superadmin != 1)
{
$query .= "WHERE a.sid in (select sid from {{survey_permissions}} WHERE uid=".$this->yii->session['loginID']." AND permission='survey' AND read_p=1) ";
}
$query .= " ORDER BY surveyls_title";

return Yii::app()->db->createCommand($query)->query();
}

public function getDataJoinLanguageSettings($surveyid)
{
$query = Yii::app()->db->createCommand();
$query->select('*');
$query->from('{{surveys}}');
$query->join('{{surveys_languagesettings}}','{{surveys_languagesettings}}.surveyls_survey_id={{surveys}}.sid and {{surveys_languagesettings}}.surveyls_language={{surveys}}.language');
$query->where('{{surveys}}.sid = \''.$surveyid.'\'');
return $query->queryRow();
}
}
18 changes: 8 additions & 10 deletions application/models/Surveys_languagesettings.php
Expand Up @@ -63,18 +63,16 @@ public function relations()
);
}

function getAllRecords($condition=FALSE)
function getAllRecords($condition=FALSE, $return_query = TRUE)
{
$query = Yii::app()->db->createCommand()->select('*')->from('{{surveys_languagesettings}}');
if ($condition != FALSE)
{
$this->db->where($condition);
$query->where($condition);
}

$data = $this->db->get('surveys_languagesettings');

return $data;
return ( $return_query ) ? $query->queryAll() : $query;
}

function getDateFormat($surveyid,$languagecode)
{
$query=Yii::app()->db->createCommand();
Expand Down Expand Up @@ -104,13 +102,13 @@ function update($data, $condition=FALSE)
$criteria = new CDbCriteria;

if ($condition != FALSE)
{
{
foreach ($condition as $item => $value)
{
$criteria->addCondition($item.'="'.$value.'"');
}
}

$data = $this->updateAll($data, $criteria);
}

Expand Down Expand Up @@ -143,7 +141,7 @@ function updateRecords($data,$condition=FALSE)
{
return false;
}

return true;
}

Expand Down
23 changes: 10 additions & 13 deletions application/views/admin/translate/translatefields_view.php
@@ -1,16 +1,13 @@
<?php if (strlen(trim((string)$textfrom)) > 0)
<?php
if (strlen(trim((string)$textfrom)) > 0)
{
// Display translation fields
echo translate::displayTranslateFields($surveyid, $gid, $qid, $type,
$amTypeOptions, $baselangdesc, $tolangdesc, $textfrom, $textto, $i, $rowfrom, $evenRow);
if ($associated && strlen(trim((string)$textfrom2)) > 0)
{
$evenRow = !($evenRow);
echo translate::displayTranslateFields($surveyid, $gid, $qid, $type2,
$amTypeOptions2, $baselangdesc, $tolangdesc, $textfrom2, $textto2, $i, $rowfrom2, $evenRow);
}
// Display translation fields
echo $translateFields;
}
else
{ ?>
<input type='hidden' name='<?php echo $type;?>_newvalue[<?php echo $i;?>]' value='<?php echo $textto;?>' />
<?php } ?>
{
?>
<input type='hidden' name='<?php echo $type; ?>_newvalue[<?php echo $i; ?>]' value='<?php echo $textto; ?>' />
<?php
}
?>
@@ -1,4 +1,4 @@
<?php echo translate::displayTranslateFieldsFooter(); ?>
<?php echo $translateFieldsFooter; ?>
</div>
<?php if ($all_fields_empty) { ?>
<p><?php echo $clang->gT("Nothing to translate on this page");?></p><br />
Expand All @@ -7,4 +7,4 @@
<?php if ($associated) { ?>
<input type='hidden' name='<?php echo $type2;?>_size' value='<?php echo $i;?>' />
<?php } ?>
</div>
</div>

0 comments on commit 9887e8d

Please sign in to comment.