-
Notifications
You must be signed in to change notification settings - Fork 988
/
Condition.php
197 lines (173 loc) · 5.92 KB
/
Condition.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2013 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* Files Purpose: lots of common functions
*/
class Condition extends LSActiveRecord
{
/**
* Returns the static model of Settings table
*
* @static
* @access public
* @param string $class
* @return CActiveRecord
*/
public static function model($class = __CLASS__)
{
return parent::model($class);
}
/**
* Returns the setting's table name to be used by the model
*
* @access public
* @return string
*/
public function tableName()
{
return '{{conditions}}';
}
/**
* Returns the primary key of this table
*
* @access public
* @return string
*/
public function primaryKey()
{
return 'cid';
}
/**
* Defines the relations for this model
*
* @access public
* @return array
*/
public function relations()
{
$alias = $this->getTableAlias();
return array(
'questions' => array(self::HAS_ONE, 'Question', '',
'on' => "$alias.cqid = questions.qid",
),
);
}
public function deleteRecords($condition=FALSE)
{
$criteria = new CDbCriteria;
if( $condition != FALSE )
{
if( is_array($condition) )
{
foreach($condition as $column=>$value)
{
$criteria->addCondition("$column='$value'");
}
}
else
{
$criteria->addCondition($condition);
}
}
return $this->deleteAll($criteria);
}
/**
* Updates the group ID for all conditions
*
* @param integer $iSurveyID
* @param integer $iQuestionID
* @param integer $iOldGroupID
* @param integer $iNewGroupID
*/
public function updateCFieldName($iSurveyID, $iQuestionID, $iOldGroupID, $iNewGroupID)
{
$oResults=$this->findAllByAttributes(array('cqid'=>$iQuestionID));
foreach ($oResults as $oRow)
{
$cfnregs='';
if (preg_match('/(\S*?)'.$iSurveyID."X".$iOldGroupID."X".$iQuestionID."(.*)/", $oRow->cfieldname, $cfnregs) > 0)
{
$newcfn=$cfnregs[1].$iSurveyID."X".$iNewGroupID."X".$iQuestionID.$cfnregs[2];
$update = Yii::app()->db->createCommand()
->update($this->tableName(), array('cfieldname' => $newcfn),
'cid=:cid',array(':cid'=>$oRow->cid));
LimeExpressionManager::UpgradeConditionsToRelevance($iSurveyID,$oRow->qid);
}
}
}
public function insertRecords($data, $update=FALSE, $condition=FALSE)
{
$record = new self;
foreach ($data as $k => $v)
{
$v = str_replace(array("'", '"'), '', $v);
$record->$k = $v;
}
if( $update )
{
$criteria = new CdbCriteria;
if( is_array($condition) )
{
foreach($condition as $column=>$value)
{
$criteria->addCondition("$column='$value'");
}
}
else
{
$criteria->where = $condition;
}
return $record->updateAll($data,$criteria);
}
else
return $record->save();
}
function getScenarios($qid)
{
$scenarioquery = "SELECT DISTINCT scenario FROM ".$this->tableName()." WHERE qid=".$qid." ORDER BY scenario";
return Yii::app()->db->createCommand($scenarioquery)->query();
}
function getSomeConditions($fields, $condition, $order, $group){
$record = Yii::app()->db->createCommand()
->select($fields)
->from($this->tableName())
->where($condition);
if( $order != NULL )
{
$record->order($order);
}
if( $group != NULL )
{
$record->group($group);
}
return $record->query();
}
function getConditionsQuestions($distinctrow,$deqrow,$scenariorow,$surveyprintlang)
{
$conquery="SELECT cid, cqid, q.title, q.question, value, q.type, cfieldname "
."FROM {{conditions}} c, {{questions}} q "
."WHERE c.cqid=q.qid "
."AND c.cqid=:distinctrow "
."AND c.qid=:deqrow "
."AND c.scenario=:scenariorow "
."AND language=:surveyprintlang ";
return Yii::app()->db->createCommand($conquery)
->bindParam(":distinctrow", $distinctrow, PDO::PARAM_INT)
->bindParam(":deqrow", $deqrow, PDO::PARAM_INT)
->bindParam(":scenariorow", $scenariorow, PDO::PARAM_INT)
->bindParam(":surveyprintlang", $surveyprintlang, PDO::PARAM_STR)
->query();
}
}
?>