-
Notifications
You must be signed in to change notification settings - Fork 988
/
SurveysGroupsettings.php
457 lines (425 loc) · 19.7 KB
/
SurveysGroupsettings.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<?php
/**
* This is the model class for table "{{surveys_groupsettings}}".
*
* The followings are the available columns in table '{{surveys_groupsettings}}':
* @property integer $gsid
* @property integer $owner_id
* @property string $admin
* @property string $expires
* @property string $startdate
* @property string $adminemail
* @property string $anonymized
* @property string $format
* @property string $savetimings
* @property string $template
* @property string $datestamp
* @property string $usecookie
* @property string $allowregister
* @property string $allowsave
* @property integer $autonumber_start
* @property string $autoredirect
* @property string $allowprev
* @property string $printanswers
* @property string $ipaddr
* @property string $refurl
* @property string $datecreated
* @property integer $showsurveypolicynotice
* @property string $publicstatistics
* @property string $publicgraphs
* @property string $listpublic
* @property string $htmlemail
* @property string $sendconfirmation
* @property string $tokenanswerspersistence
* @property string $assessments
* @property string $usecaptcha
* @property string $bounce_email
* @property string $attributedescriptions
* @property string $emailresponseto
* @property string $emailnotificationto
* @property integer $tokenlength
* @property string $showxquestions
* @property string $showgroupinfo
* @property string $shownoanswer
* @property string $showqnumcode
* @property string $showwelcome
* @property string $showprogress
* @property integer $questionindex
* @property integer $navigationdelay
* @property string $nokeyboard
* @property string $alloweditaftercompletion
* @property string $ipanonymize
*/
class SurveysGroupsettings extends LSActiveRecord
{
// survey options
public $oOptions;
public $oOptionLabels;
// used for twig files, same content as $oOptions, but in array format
public $aOptions = array();
// attribute names from surveys_groupsettings table definition
protected $optionAttributes = array();
// attributes separated by column datatype, used by setToInherit method
protected $optionAttributesInteger = array('owner_id', 'tokenlength', 'questionindex', 'navigationdelay');
protected $optionAttributesChar = array('anonymized', 'savetimings', 'datestamp', 'usecookie', 'allowregister', 'allowsave', 'autoredirect', 'allowprev', 'printanswers',
'ipaddr','ipanonymize', 'refurl', 'publicstatistics', 'publicgraphs', 'listpublic', 'htmlemail', 'sendconfirmation', 'tokenanswerspersistence',
'assessments', 'showxquestions', 'showgroupinfo', 'shownoanswer', 'showqnumcode', 'showwelcome', 'showprogress', 'nokeyboard',
'alloweditaftercompletion');
protected $optionAttributesText = array('admin', 'adminemail', 'template', 'bounce_email', 'emailresponseto', 'emailnotificationto');
public $showInherited = 1;
public $active;
public $additional_languages;
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{surveys_groupsettings}}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
$validator = new LSYii_Validators;
return array(
array('autonumber_start, showsurveypolicynotice, tokenlength, questionindex, navigationdelay, owner_id', 'numerical', 'integerOnly'=>true),
array('admin', 'length', 'max'=>50),
array('anonymized, format, savetimings, datestamp, usecookie, allowregister, allowsave, autoredirect, allowprev, printanswers, ipaddr, refurl, publicstatistics, publicgraphs, listpublic, htmlemail, sendconfirmation, tokenanswerspersistence, assessments, usecaptcha, showxquestions, showgroupinfo, shownoanswer, showqnumcode, showwelcome, showprogress, nokeyboard, alloweditaftercompletion, ipanonymize', 'length', 'max'=>1),
array('adminemail, bounce_email', 'length', 'max'=>255),
array('template', 'length', 'max'=>100),
array('expires, startdate, datecreated, attributedescriptions, emailresponseto, emailnotificationto', 'safe'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('gsid, owner_id, admin, expires, startdate, adminemail, anonymized, format,
savetimings, template, datestamp, usecookie, allowregister, allowsave, autonumber_start,
autoredirect, allowprev, printanswers, ipaddr, refurl, datecreated, showsurveypolicynotice,
publicstatistics, publicgraphs, listpublic, htmlemail, sendconfirmation, tokenanswerspersistence,
assessments, usecaptcha, bounce_email, attributedescriptions, emailresponseto, emailnotificationto,
tokenlength, showxquestions, showgroupinfo, shownoanswer, showqnumcode, showwelcome, showprogress,
questionindex, navigationdelay, nokeyboard, alloweditaftercompletion', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'Survey' => array(self::HAS_MANY, 'Survey', 'gsid'),
'SurveysGroups' => array(self::HAS_ONE, 'SurveysGroups', 'gsid'),
'owner' => array(self::BELONGS_TO, 'User', 'owner_id'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'gsid' => 'Gsid',
'owner_id' => 'OwnerId',
'admin' => 'Admin',
'expires' => 'Expires',
'startdate' => 'Startdate',
'adminemail' => 'Adminemail',
'anonymized' => 'Anonymized',
'format' => 'Format',
'savetimings' => 'Savetimings',
'template' => 'Template',
'datestamp' => 'Datestamp',
'usecookie' => 'Usecookie',
'allowregister' => 'Allowregister',
'allowsave' => 'Allowsave',
'autonumber_start' => 'Autonumber Start',
'autoredirect' => 'Autoredirect',
'allowprev' => 'Allowprev',
'printanswers' => 'Printanswers',
'ipaddr' => 'Ipaddr',
'refurl' => 'Refurl',
'datecreated' => 'Datecreated',
'showsurveypolicynotice' => 'Showsurveypolicynotice',
'publicstatistics' => 'Publicstatistics',
'publicgraphs' => 'Publicgraphs',
'listpublic' => 'Listpublic',
'htmlemail' => 'Htmlemail',
'sendconfirmation' => 'Sendconfirmation',
'tokenanswerspersistence' => 'Tokenanswerspersistence',
'assessments' => 'Assessments',
'usecaptcha' => 'Usecaptcha',
'bounce_email' => 'Bounce Email',
'attributedescriptions' => 'Attributedescriptions',
'emailresponseto' => 'Emailresponseto',
'emailnotificationto' => 'Emailnotificationto',
'tokenlength' => 'Tokenlength',
'showxquestions' => 'Showxquestions',
'showgroupinfo' => 'Showgroupinfo',
'shownoanswer' => 'Shownoanswer',
'showqnumcode' => 'Showqnumcode',
'showwelcome' => 'Showwelcome',
'showprogress' => 'Showprogress',
'questionindex' => 'Questionindex',
'navigationdelay' => 'Navigationdelay',
'nokeyboard' => 'Nokeyboard',
'alloweditaftercompletion' => 'Alloweditaftercompletion',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('gsid',$this->gsid);
$criteria->compare('owner_id',$this->owner_id);
$criteria->compare('admin',$this->admin,true);
$criteria->compare('expires',$this->expires,true);
$criteria->compare('startdate',$this->startdate,true);
$criteria->compare('adminemail',$this->adminemail,true);
$criteria->compare('anonymized',$this->anonymized,true);
$criteria->compare('format',$this->format,true);
$criteria->compare('savetimings',$this->savetimings,true);
$criteria->compare('template',$this->template,true);
$criteria->compare('datestamp',$this->datestamp,true);
$criteria->compare('usecookie',$this->usecookie,true);
$criteria->compare('allowregister',$this->allowregister,true);
$criteria->compare('allowsave',$this->allowsave,true);
$criteria->compare('autonumber_start',$this->autonumber_start);
$criteria->compare('autoredirect',$this->autoredirect,true);
$criteria->compare('allowprev',$this->allowprev,true);
$criteria->compare('printanswers',$this->printanswers,true);
$criteria->compare('ipaddr',$this->ipaddr,true);
$criteria->compare('refurl',$this->refurl,true);
$criteria->compare('datecreated',$this->datecreated,true);
$criteria->compare('showsurveypolicynotice',$this->showsurveypolicynotice);
$criteria->compare('publicstatistics',$this->publicstatistics,true);
$criteria->compare('publicgraphs',$this->publicgraphs,true);
$criteria->compare('listpublic',$this->listpublic,true);
$criteria->compare('htmlemail',$this->htmlemail,true);
$criteria->compare('sendconfirmation',$this->sendconfirmation,true);
$criteria->compare('tokenanswerspersistence',$this->tokenanswerspersistence,true);
$criteria->compare('assessments',$this->assessments,true);
$criteria->compare('usecaptcha',$this->usecaptcha,true);
$criteria->compare('bounce_email',$this->bounce_email,true);
$criteria->compare('attributedescriptions',$this->attributedescriptions,true);
$criteria->compare('emailresponseto',$this->emailresponseto,true);
$criteria->compare('emailnotificationto',$this->emailnotificationto,true);
$criteria->compare('tokenlength',$this->tokenlength);
$criteria->compare('showxquestions',$this->showxquestions,true);
$criteria->compare('showgroupinfo',$this->showgroupinfo,true);
$criteria->compare('shownoanswer',$this->shownoanswer,true);
$criteria->compare('showqnumcode',$this->showqnumcode,true);
$criteria->compare('showwelcome',$this->showwelcome,true);
$criteria->compare('showprogress',$this->showprogress,true);
$criteria->compare('questionindex',$this->questionindex);
$criteria->compare('navigationdelay',$this->navigationdelay);
$criteria->compare('nokeyboard',$this->nokeyboard,true);
$criteria->compare('alloweditaftercompletion',$this->alloweditaftercompletion,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return SurveysGroupsettings the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return bool
*/
public function getIsActive()
{
if (is_object($this->Survey)){
return ($this->Survey->active === 'Y');
} else {
return false;
}
}
/**
* @return bool
*/
public function getIsAnonymized()
{
if (is_object($this->Survey)){
return ($this->Survey->anonymized === 'Y');
} else {
return false;
}
}
/**
* Recursive function
*
* Gets the real values for a group.
* A group could inherit from a group, this one could inherit from a group ...
* It steps up (see param $iStep) until it has found the real settings ...
*
* @param int $iSurveyGroupId
* @param null $oSurvey
* @param null $instance
* @param int $iStep this is inheritance step (recursive step) (parent, parentParent, parentParentParent ?)
* @param bool $bRealValues
* @return SurveysGroupsettings instance
*/
public static function getInstance($iSurveyGroupId = 0, $oSurvey = null, $instance = null, $iStep = 1, $bRealValues = false){
if ($iSurveyGroupId > 0){
$model = SurveysGroupsettings::model()->with('SurveysGroups')->findByPk($iSurveyGroupId);
} else {
//this is the default group setting with gsid=0 !!!
$model = SurveysGroupsettings::model()->findByPk($iSurveyGroupId);
}
// set initial values to instance on first run
if ($instance === null){
if ($model === null){
$instance = new SurveysGroupsettings();
$instance->optionAttributes = new stdClass();
} else {
$instance = $model;
$instance->optionAttributes = array_keys($model->attributes);
// unset gsid
unset($instance->optionAttributes[array_search('gsid', $instance->optionAttributes)]);
}
$instance->oOptions = new stdClass();
$instance->oOptionLabels = new stdClass();
// set visibility of 'inherit' options on buttons
if ($iSurveyGroupId == 0){
$instance->showInherited = 0;
} else {
$instance->showInherited = 1;
}
// set instance options from survey model, used for frontend redering
if (($oSurvey !== null && $bRealValues)){
foreach($instance->optionAttributes as $key=>$attribute){
$instance->oOptions->{$attribute} = $oSurvey->$attribute;
$instance->oOptionLabels->{$attribute} = self::translateOptionLabels($instance, $attribute, $oSurvey->$attribute);
}
}
// set instance options from global model
if ($iSurveyGroupId == 0){
foreach($instance->optionAttributes as $key=>$attribute){
$instance->oOptions->{$attribute} = $model->$attribute;
$instance->oOptionLabels->{$attribute} = self::translateOptionLabels($instance, $attribute, $model->$attribute);
}
}
}
// set instance options only if option needs to be inherited
if ($oSurvey !== null || ($oSurvey === null && $iStep > 1)){
foreach($instance->optionAttributes as $key=>$attribute){
if ((empty($instance->oOptions->{$attribute})) || (!empty($instance->oOptions->{$attribute}) && ($instance->oOptions->{$attribute} === 'inherit' || $instance->oOptions->{$attribute} === 'I' || $instance->oOptions->{$attribute} === '-1'))){
$instance->oOptions->{$attribute} = $model->$attribute;
$instance->oOptionLabels->{$attribute} = self::translateOptionLabels($instance, $attribute, $model->$attribute);
}
}
}
// fetch parent instance only if parent_id exists
if ($iSurveyGroupId > 0 && !empty($model->SurveysGroups) && $model->SurveysGroups->parent_id !== null){
self::getInstance($model->SurveysGroups->parent_id, null, $instance, $iStep + 1);
}
// fetch global instance
if ($iSurveyGroupId > 0 && !empty($model->SurveysGroups) && $model->SurveysGroups->parent_id === null){
self::getInstance(0, null, $instance, $iStep + 1); // calling global settings
}
return $instance;
}
/**
* @return string
*/
protected static function translateOptionLabels($instance, $attribute, $value){
// replace option labels on forms
if ($attribute == 'usecaptcha'){
$usecap = $value;
if ($usecap === 'A' || $usecap === 'B' || $usecap === 'C' || $usecap === 'X' || $usecap === 'F' || $usecap === 'H' || $usecap === 'K' || $usecap === '0'){
$instance->oOptionLabels->useCaptchaSurveyAccess = gT("On");
} else {
$instance->oOptionLabels->useCaptchaSurveyAccess = gT("Off");
}
if ($usecap === 'A' || $usecap === 'B' || $usecap === 'D' || $usecap === 'R' || $usecap === 'F' || $usecap === 'G' || $usecap === 'I' || $usecap === 'M'){
$instance->oOptionLabels->useCaptchaRegistration = gT("On");
} else {
$instance->oOptionLabels->useCaptchaRegistration = gT("Off");
}
if ($usecap === 'A' || $usecap === 'C' || $usecap === 'D' || $usecap === 'S' || $usecap === 'G' || $usecap === 'H' || $usecap === 'J' || $usecap === 'L'){
$instance->oOptionLabels->useCaptchaSaveAndLoad = gT("On");
} else {
$instance->oOptionLabels->useCaptchaSaveAndLoad = gT("Off");
}
} elseif ($attribute == 'owner_id' && $value != -1){
$instance->oOptions->owner = "";
$instance->oOptions->ownerLabel = "";
$oUser = User::model()->findByPk($instance->oOptions->{$attribute});
if(!empty($oUser)) {
$instance->oOptions->owner = $oUser->attributes;
$instance->oOptions->ownerLabel = $oUser->users_name.($oUser->full_name ? " - ".$oUser->full_name : "");
}
} elseif ($attribute == 'format' && $value != -1){
return str_replace(array('S', 'G', 'A'), array(gT("Question by question"), gT("Group by group"), gT("All in one")), $value);
} elseif ($attribute == 'questionindex' && $value != -1){
return str_replace(array('0', '1', '2'), array(gT("Disabled"), gT("Incremental"), gT("Full")), $value);
} elseif ($attribute == 'showgroupinfo'){
return str_replace(array('B', 'D', 'N', 'X'), array(gT("Show both"), gT("Show group description only"), gT("Show group name only"), gT("Hide both")), $value);
} elseif ($attribute == 'showqnumcode'){
return str_replace(array('B', 'C', 'N', 'X'), array(gT("Show both"), gT("Show question code only"), gT("Show question number only"), gT("Hide both")), $value);
} else {
return str_replace(array('Y', 'N'), array(gT("On"), gT("Off")), $value);
}
}
/**
* Gets the "values" from the group that inherits to this group and ...
*
* ... sets the variables (not DB attributes) of "oOptions", "oOptionLabels", "aOptions"
* and "showInherited" (most of them used for frontend i think)
*
*/
public function setOptions()
{
$instance = SurveysGroupsettings::getInstance($this->gsid);
// set SurveysGroupsettings properties from $instance
$this->oOptions = $instance->oOptions;
$this->oOptionLabels = $instance->oOptionLabels;
$this->aOptions = (array) $instance->oOptions;
$this->showInherited = $instance->showInherited;
}
public function setToInherit()
{
// set attribute values to inherit, used only when creating new Survey instance
$this->usecaptcha = 'E';
$this->format = 'I';
foreach ($this->optionAttributesInteger as $attribute){
$this->$attribute = -1;
}
foreach ($this->optionAttributesChar as $attribute){
$this->$attribute = 'I';
}
foreach ($this->optionAttributesText as $attribute){
$this->$attribute = 'inherit';
}
}
public function setToDefault()
{
// set attribute values to default values, used only when creating new top level SurveysGroupsettings instance
$this->owner_id = 1;
$this->usecaptcha = 'N';
$this->format = 'G';
$this->admin = App()->getConfig('siteadminname');
$this->adminemail = App()->getConfig('siteadminemail');
$this->template = Template::templateNameFilter(App()->getConfig('defaulttheme'));
}
}