Skip to content

Commit

Permalink
Refactor models more, completely removed getSomeRecords
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11931 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Shitiz Garg committed Jan 5, 2012
1 parent 3280755 commit 21cb748
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 420 deletions.
44 changes: 24 additions & 20 deletions application/controllers/admin/translate.php
Expand Up @@ -798,17 +798,27 @@ private function _amTypeOptions($aData, $surveyid, $tolang, $baselang, $id1 = ""
break;

case 3 :
$result = Questions::model()->findAllByAttributes(array(
'sid' => $surveyid,
'language' => $baselang,
'parent_qid' => 0,
));
$rows_base = array();
foreach ($result as $r)
$rows_base[] = $r->attributes;

$result = Questions::model()->findAllByAttributes(array(
'sid' => $surveyid,
'language' => $tplang,
'parent_qid' => 0,
));
$rows_to = array();
foreach ($result as $r)
$rows_to[] = $r->attributes;

$amTypeOptions = array_merge($amTypeOptions, array(
"querybase" => Questions::model()->getSomeRecords(
'*',
"sid = '{$surveyid}' AND language = '{$baselang}' AND parent_qid = 0",
'qid', FALSE
),
"queryto" => Questions::model()->getSomeRecords(
'*',
"sid = '{$surveyid}' AND language = '{$tolang}' AND parent_qid = 0",
'qid', FALSE
),
"querybase" => $rows_base,
"queryto" => $rows_to,
"queryupdate" => Questions::model()->updateAll(
array(
$aData['dbColumn'] => $new
Expand All @@ -820,16 +830,10 @@ private function _amTypeOptions($aData, $surveyid, $tolang, $baselang, $id1 = ""

case 4 :
$amTypeOptions = array_merge($amTypeOptions, array(
"querybase" => Questions::model()->getSomeRecords(
'*',
"sid = '{$surveyid}' AND language = '{$baselang}' AND parent_qid > 0",
'parent_qid,qid', FALSE
),
"queryto" => Questions::model()->getSomeRecords(
'*',
"sid = '{$surveyid}' AND language = '{$tolang}' AND parent_qid > 0",
'parent_qid,qid', FALSE
),
"querybase" => Questions::model()->findAll("
sid = '{$surveyid}' AND language = '{$baselang}' AND parent_qid > 0"),
"queryto" => Questions::model()->findAll(
"sid = '{$surveyid}' AND language = '{$tolang}' AND parent_qid > 0"),
"queryupdate" => Questions::model()->updateAll(
array(
'question' => $new
Expand Down
2 changes: 1 addition & 1 deletion application/controllers/admin/useraction.php
Expand Up @@ -196,7 +196,7 @@ function deluser()
if (isset($_POST['uid'])) {
$sresultcount = 0; // 1 if I am parent of $postuserid
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] != 1) {
$sresult = User::model()->getSomeRecords(array('uid'), array('parent_id' => $postuserid, 'parent_id' => Yii::app()->session['loginID']));
$sresult = User::model()->findAllByAttributes(array('parent_id' => $postuserid, 'parent_id' => Yii::app()->session['loginID']));
$sresultcount = count($sresult);
}

Expand Down
8 changes: 5 additions & 3 deletions application/helpers/frontend_helper.php
Expand Up @@ -1866,9 +1866,11 @@ function buildsurveysession($surveyid)
$aRandomGroups=array();
$aGIDCompleteMap=array();
// first find all groups and their groups IDS
$oData=Groups::model()->getSomeRecords(array('gid','randomization_group'),
"sid={$surveyid} and language='{$_SESSION['s_lang']}' and randomization_group !=''");
foreach($oData->readAll() as $aGroup)
$criteria = new CDbCriteria;
$criteria->addColumnCondition(array('sid' => $surveyid, 'language' => $_SESSION['s_lang']));
$criteria->addCondition('randomization_group != ""');
$oData = Groups::model()->findAll($criteria);
foreach($oData as $aGroup)
{
$aRandomGroups[$aGroup['randomization_group']][] = $aGroup['gid'];
}
Expand Down
10 changes: 0 additions & 10 deletions application/models/Answers.php
Expand Up @@ -49,16 +49,6 @@ 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 getAnswers($qid)
{
return Yii::app()->db->createCommand()
Expand Down
20 changes: 0 additions & 20 deletions application/models/Conditions.php
Expand Up @@ -53,26 +53,6 @@ public function primaryKey()
return 'cid';
}

public function getSomeRecords($fields=FALSE, $conditions=FALSE)
{
$criteria = new CDbCriteria;

if( $fields != FALSE )
{
$criteria->select = $fields;
}

if( $conditions != FALSE )
{
foreach($conditions as $column=>$value)
{
$criteria->addCondition("$column='$value'");
}
}

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

public function deleteRecords($condition=FALSE)
{
$criteria = new CDbCriteria;
Expand Down
9 changes: 0 additions & 9 deletions application/models/Groups.php
Expand Up @@ -131,14 +131,5 @@ function getAllGroups($condition, $order=false)
}
return $command->query();
}

function getSomeRecords($fields, $condition=null)
{
return Yii::app()->db->createCommand()
->select($fields)
->from(self::tableName())
->where($condition)
->query();
}
}
?>
15 changes: 0 additions & 15 deletions application/models/Label.php
Expand Up @@ -70,21 +70,6 @@ function getAllRecords($condition=FALSE)
return $data;
}

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

$data = $this->findAll($criteria);

return $data;
}

function getLabelCodeInfo($lid)
{
return Yii::app()->db->createCommand()->select('code, title, sortorder, language, assessment_value')->order('language, sortorder, code')->where('lid='.$lid)->from(tableName())->query()->readAll();
Expand Down
15 changes: 0 additions & 15 deletions application/models/Labelsets.php
Expand Up @@ -64,21 +64,6 @@ function getAllRecords($condition=FALSE)
return $data;
}

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

$data = $this->findAll($criteria);

return $data;
}

function getLID()
{
return Yii::app()->db->createCommand()->select('lid')->order('lid asc')->from('{{labelsets}}')->query()->readAll();
Expand Down
15 changes: 0 additions & 15 deletions application/models/Questions.php
Expand Up @@ -195,21 +195,6 @@ function insertRecords($data)
return $questions->save();
}

function getSomeRecords($fields, $condition, $order=NULL, $return_query = TRUE)
{
$record = Yii::app()->db->createCommand()
->select($fields)
->from(self::tableName())
->where($condition);

if( $order != NULL )
{
$record->order($order);
}

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

public static function deleteAllById($questionsIds)
{
if ( !is_array($questionsIds) )
Expand Down
30 changes: 7 additions & 23 deletions application/models/Saved_control.php
Expand Up @@ -46,43 +46,27 @@ public static function model()
{
return parent::model(__CLASS__);
}

function getAllRecords($condition=FALSE)
{
if ($condition != FALSE)
{
$this->db->where($condition);
$this->db->where($condition);
}

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

return $data;
}

public static function getSomeRecords($condition=FALSE)
{
$record = new self;
$criteria = new CDbCriteria;

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

return $record->findAll($criteria);
}

public function getCountOfAll($sid)
{
$data = Yii::app()->db->createCommand("SELECT COUNT(*) AS countall FROM {{saved_control}} WHERE sid=$sid")->query();
$row = $data->read();

return $row['countall'];
}

/**
* Deletes some records meeting speicifed condition
*
Expand All @@ -108,7 +92,7 @@ public function deleteSomeRecords($condition)

function insertRecords($data)
{
return $this->db->insert('saved_control', $data);
return $this->db->insert('saved_control', $data);
}

}
46 changes: 1 addition & 45 deletions application/models/Survey_dynamic.php
Expand Up @@ -30,7 +30,7 @@ public static function model($sid = NULL)
{
if (!is_null($sid))
self::sid($sid);

return parent::model(__CLASS__);
}

Expand Down Expand Up @@ -89,50 +89,6 @@ public function insertRecords($data)
return $record->save();
}

/**
* Queries the database and returns some records or records count
* according to specified conditions
*
* @static
* @access public
* @param array $condition
* @param mixed $select
* @param boolean $return_count
* @return mixed
*/
public function getSomeRecords($condition=FALSE, $select=FALSE, $return_count=FALSE, $oneonly=FALSE)
{
$survey = new self;
$criteria = new CDbCriteria;

if( $select != FALSE ) $criteria->select = $select;

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

if( $return_count )
return $survey->count($criteria);
else
{
if($oneonly)
return $survey->find($criteria);
else
return $survey->findAll($criteria);
}
}

/**
* Deletes some records from survey's table
* according to specific condition
Expand Down
16 changes: 0 additions & 16 deletions application/models/Tokens_dynamic.php
Expand Up @@ -175,22 +175,6 @@ function createTokens($iSurveyID)
return $newtokencount;

}
public function getSomeRecords($fields,$condition=FALSE)
{
$criteria = new CDbCriteria;

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

$data = $this->findAll($criteria);

return $data;
}

public function search()
{
Expand Down
27 changes: 0 additions & 27 deletions application/models/User.php
Expand Up @@ -97,33 +97,6 @@ function parentAndUser($postuserid)
return $user;
}

/**
* Returns users meeting given condition
*
* @access public
* @return string
*/
public function getSomeRecords($fields=FALSE, $condition=FALSE)
{
$record = new self;
$criteria = new CDbCriteria;

if($fields != FALSE)
{
$criteria->select = $fields;
}

if ($condition != FALSE)
{
foreach ($condition as $item => $value)
{
$criteria->addCondition($item.'='.Yii::app()->db->quoteValue($value));
}
}

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

/**
* Returns onetime password
*
Expand Down

0 comments on commit 21cb748

Please sign in to comment.