/
SavedControl.php
216 lines (198 loc) · 7.11 KB
/
SavedControl.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/*
* LimeSurvey
* Copyright (C) 2007-2011 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.
*
*/
/**
* Class SavedControl
* @property integer $scid Primary key
* @property integer $sid Survey id
* @property integer $srid
* @property string $identifier
* @property string $access_code
* @property string $email
* @property string $ip
* @property string $saved_thisstep
* @property string $status
* @property string $saved_date
* @property string $refurl
*/
class SavedControl extends LSActiveRecord
{
/**
* Set defaults
* @inheritdoc
*/
public function init()
{
$this->ip = "";
}
/** @inheritdoc */
public function tableName()
{
return '{{saved_control}}';
}
/** @inheritdoc */
public function primaryKey()
{
return 'scid';
}
/**
* @inheritdoc
* @return CActiveRecord
*/
public static function model($className = __CLASS__)
{
return parent::model($className);
}
public function getAllRecords($condition = false)
{
if ($condition != false) {
$this->db->where($condition);
}
$data = $this->db->get('saved_control');
return $data;
}
/**
* @param int $sid
* @return mixed
*/
public function getCountOfAll($sid)
{
$data = Yii::app()->db->createCommand("SELECT COUNT(*) AS countall FROM {{saved_control}} WHERE sid=:sid")->bindParam(":sid", $sid, PDO::PARAM_INT)->query();
$row = $data->read();
return $row['countall'];
}
/**
* Deletes some records meeting specified condition
*
* @access public
* @param array $condition
* @return int (rows deleted)
*/
public function deleteSomeRecords($condition)
{
$record = new self();
$criteria = new CDbCriteria();
if ($condition != false) {
foreach ($condition as $column => $value) {
$criteria->addCondition("$column='$value'");
}
}
return $record->deleteAll($criteria);
}
/**
* @param $data
* @return mixed
* @deprecated at 2018-02-03 use $model->attributes = $data && $model->save()
*/
public function insertRecords($data)
{
return $this->db->insert('saved_control', $data);
}
public function getGridButtons()
{
$gridButtons = array();
$gridButtons['editresponse'] = array(
'label' => '<span class="sr-only">' . gT("Edit") . '</span><span class="fa fa-pencil" aria-hidden="true"></span>',
'imageUrl' => false,
'url' => 'App()->createUrl("admin/dataentry/sa/editdata/subaction/edit",array("surveyid"=>$data->sid,"id"=>$data->srid));',
'options' => array(
'class' => "btn btn-default btn-sm btn-edit",
'data-toggle' => "tooltip",
'title' => gT("Edit response"),
),
'visible' => 'boolval(' . Permission::model()->hasSurveyPermission($this->sid, 'responses', 'update') . ')',
);
$gridButtons['resend_accesscode'] = array(
'label' => '<span class="sr-only">' . gT("Edit") . '</span><span class="fa fa-refresh" aria-hidden="true"></span>',
'imageUrl' => false,
'url' => 'App()->createUrl("admin/saved/sa/resend_accesscode",array("surveyid"=>$data->sid,"id"=>$data->srid));',
'options' => array(
'class' => "btn btn-default btn-sm btn-edit",
'data-toggle' => "tooltip",
'title' => gT("Resend access code"),
),
// 'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'update').')',
'visible' => false,
);
$gridButtons['delete'] = array(
'label' => '<span class="sr-only">' . gT("Delete") . '</span><span class="fa fa-trash text-danger" aria-hidden="true"></span>',
'imageUrl' => false,
'icon' => false,
'url' => 'App()->createUrl("admin/saved/sa/actionDelete",array("surveyid"=>$data->sid,"scid"=>$data->scid,"srid"=>$data->srid));',
'options' => array(
'class' => "btn btn-default btn-sm btn-delete",
'data-toggle' => "tooltip",
'title' => gT("Delete this entry and related response"),
),
'visible' => 'boolval(' . Permission::model()->hasSurveyPermission($this->sid, 'responses', 'delete') . ')',
'click' => 'function(event){ window.LS.gridButton.confirmGridAction(event,$(this)); }',
);
return $gridButtons;
}
public function getColumns()
{
return array(
array(
'header' => gT('Action'),
'class' => 'bootstrap.widgets.TbButtonColumn',
'template' => '{editresponse}{delete}',
'htmlOptions' => array('class' => 'icon-btn-row'),
'buttons' => $this->gridButtons,
),
array(
'header' => gT("ID"),
'name' => 'scid',
'filter' => false,
),
array(
'header' => gT("Identifier"),
'name' => 'identifier',
),
array(
'header' => gT("IP address"),
'name' => 'ip',
),
array(
'header' => gT("Date saved"),
'name' => 'saved_date',
),
array(
'header' => gT("Email address"),
'name' => 'email',
),
);
}
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria();
$criteria->compare('sid', $this->sid, false); //will not be searchable
$criteria->compare('srid', $this->srid, true);
$criteria->compare('access_code', $this->access_code, true);
$criteria->compare('scid', $this->scid);
$criteria->compare('identifier', $this->identifier, true);
$criteria->compare('email', $this->email, true);
$criteria->compare('ip', $this->ip, true);
$criteria->compare('saved_thisstep', $this->saved_thisstep, true);
$criteria->compare('status', $this->status, true);
$criteria->compare('saved_date', $this->saved_date, true);
$criteria->compare('refurl', $this->refurl, true);
$pageSize = Yii::app()->user->getState('savedResponsesPageSize', Yii::app()->params['defaultPageSize']);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => $pageSize,
),
));
}
}