/
Assessment.php
205 lines (186 loc) · 5.95 KB
/
Assessment.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
<?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 Assessment
*
* @property integer $id Primary key
* @property integer $sid Survey id
* @property integer $gid Group id
* @property string $scope
* @property string $name
* @property string $minimum
* @property string $maximum
* @property string $message
* @property string $language
*/
class Assessment extends LSActiveRecord
{
/**
* @inheritdoc
* @return Assessment
*/
public static function model($class = __CLASS__)
{
/** @var self $model */
$model = parent::model($class);
return $model;
}
/** @inheritdoc */
public function rules()
{
return array(
array('name,message', 'LSYii_Validators'),
);
}
/** @inheritdoc */
public function tableName()
{
return '{{assessments}}';
}
/** @inheritdoc */
public function primaryKey()
{
return array('id', 'language');
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'scope' => gT("Scope"),
'name' => gT("Name"),
'minimum' => gT("Minimum"),
'maximum' => gT("Maximum"),
'message' => gT("Message"),
'language' => gT("Language"),
);
}
public function getButtons()
{
$buttons = "<div style='white-space: nowrap'>";
$raw_button_template = ""
. "<button class='btn btn-default btn-xs %s %s' role='button' data-toggle='tooltip' title='%s' onclick='return false;'>" //extra class //title
. "<i class='fa fa-%s' ></i>" //icon class
. "</button>";
if (Permission::model()->hasGlobalPermission('assessements', 'update')) {
$editData = array(
'action_assessements_editModal',
'text-danger',
gT("Edit this assessement rule"),
'edit'
);
$deleteData = array(
'action_assessements_deleteModal',
'text-danger',
gT("Delete this assessement rule"),
'trash text-danger'
);
$buttons .= vsprintf($raw_button_template, $deleteData);
$buttons .= vsprintf($raw_button_template, $editData);
}
$buttons .= '</div>';
return $buttons;
}
public function getColumns(){
return array(
array(
'name' => 'id',
'filter' => false
),
array(
"name" => 'buttons',
"type" => 'raw',
"header" => gT("Action"),
"filter" => false
),
array(
'name' => 'scope',
'value' => '$data->scope == "G" ? eT("Global") : eT("Total")',
'htmlOptions' => ['class' => 'col-sm-1'],
'filter' => TbHtml::dropDownList('Assessement["scope"]', 'scope', [ '' => gT('All'), 'T' => gT('Total'), 'G' => gT("Global")])
),
array(
'name' => 'name',
'htmlOptions' => ['class' => 'col-sm-2']
),
array(
'name' => 'minimum',
'htmlOptions' => ['class' => 'col-sm-1']
),
array(
'name' => 'maximum',
'htmlOptions' => ['class' => 'col-sm-1']
),
array(
'name' => 'message',
'htmlOptions' => ['class' => 'col-sm-5']
),
array(
'name' => 'language',
'value' => 'getLanguageNameFromCode($data->language, false)',
'htmlOptions' => ['class' => 'col-sm-1']
),
);
}
public function search(){
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('sid', $this->sid);
$criteria->compare('gid', $this->gid);
$criteria->compare('scope', $this->scope);
$criteria->compare('name', $this->name, true);
$criteria->compare('minimum', $this->minimum);
$criteria->compare('maximum', $this->maximum);
$criteria->compare('message', $this->message, true);
$criteria->compare('language', $this->language);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* @param array $data
* @return Assessment
*/
public static function insertRecords($data)
{
$assessment = new self;
foreach ($data as $k => $v) {
$assessment->$k = $v;
}
$assessment->save();
return $assessment;
}
/**
* @param integer $id
* @param integer $iSurveyID
* @param string $language
* @param array $data
*/
public static function updateAssessment($id, $iSurveyID, $language, array $data)
{
$assessment = self::model()->findByAttributes(array('id' => $id, 'sid'=> $iSurveyID, 'language' => $language));
if (!is_null($assessment)) {
foreach ($data as $k => $v) {
$assessment->$k = $v;
}
$assessment->save();
}
}
}