Skip to content

Commit 17603a2

Browse files
committed
[smarcet] - #13374
* added merge surveys feature
1 parent 4faae44 commit 17603a2

32 files changed

Lines changed: 441 additions & 271 deletions

sangria/code/SangriaPageSurveyBuilderStatisticsExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,9 @@ public function SurveyBuilderDeploymentCompanyList($back_url = '')
500500
I.TemplateID = $template->ID AND I.IsTest = 0
501501
AND SQUEST.ClassName = 'SurveyOrganizationQuestionTemplate'
502502
{$mandatory_filter}
503-
{$filters_where} GROUP BY SANS.`Value` ORDER BY SANS.`Value`;";
503+
{$filters_where}
504+
GROUP BY SANS.`Value`, I.ID
505+
ORDER BY SANS.`Value`;";
504506

505507

506508
$companies = new ArrayList();

survey_builder/code/infrastructure/active_records/instances/EntitySurvey.php

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,28 @@
1818
class EntitySurvey extends Survey implements IEntitySurvey
1919
{
2020

21-
static $db = array
22-
();
21+
static $db = [];
2322

24-
static $indexes = array
25-
();
23+
static $indexes = [];
2624

27-
static $has_one = array
28-
(
25+
static $has_one = [
2926
'Template' => 'EntitySurveyTemplate',
3027
'Parent' => 'Survey',
3128
'Owner' => 'SurveyDynamicEntityStep',
3229
'EditedBy' => 'Member'
33-
);
30+
];
3431

35-
static $many_many = array
36-
(
32+
static $many_many = [
3733
'EditorTeam' => 'Member'
38-
);
34+
];
3935

4036
static $many_many_extraFields = [
4137
'EditorTeam' => ['EntitySurveyTeamMemberMailed' => 'Boolean']
4238
];
4339

44-
static $has_many = array
45-
();
40+
static $has_many = [];
4641

47-
private static $defaults = array
48-
();
42+
static $defaults = [];
4943

5044

5145
/**
@@ -62,15 +56,15 @@ public function hasTeamPermissions(Member $member){
6256
*/
6357
public function parent()
6458
{
65-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'Parent')->getTarget();
59+
return $this->getComponent('Parent');
6660
}
6761

6862
/**
6963
* @return ISurveyDynamicEntityStep
7064
*/
7165
public function owner()
7266
{
73-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'Owner')->getTarget();
67+
return $this->getComponent('Owner');
7468
}
7569

7670
protected function onBeforeDelete()
@@ -137,7 +131,7 @@ public function isTeamEditionAllowed()
137131
*/
138132
public function addTeamMember(ICommunityMember $member, $extraFields = null)
139133
{
140-
AssociationFactory::getInstance()->getMany2ManyAssociation($this, 'EditorTeam')->add($member, $extraFields);
134+
$this->EditorTeam()->add($member, $extraFields);
141135
}
142136

143137
/**
@@ -146,23 +140,23 @@ public function addTeamMember(ICommunityMember $member, $extraFields = null)
146140
*/
147141
public function removeTeamMember(ICommunityMember $member)
148142
{
149-
AssociationFactory::getInstance()->getMany2ManyAssociation($this, 'EditorTeam')->remove($member);
143+
$this->EditorTeam()->remove($member);
150144
}
151145

152146
/**
153147
* @return ICommunityMember
154148
*/
155149
public function getUpdateBy()
156150
{
157-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'EditedBy')->getTarget();
151+
return $this->getComponent('EditedBy');
158152
}
159153

160154
/**
161155
* @return ICommunityMember[]
162156
*/
163157
public function getTeamMembers()
164158
{
165-
return AssociationFactory::getInstance()->getMany2ManyAssociation($this, 'EditorTeam')->toArray();
159+
return $this->EditorTeam()->toArray();
166160
}
167161

168162
protected function onBeforeWrite()

survey_builder/code/infrastructure/active_records/instances/Survey.php

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,48 @@ class Survey extends DataObject implements ISurvey
1919
{
2020
const SurveyTestersGroupSlug = 'survey-testers';
2121

22-
static $db = array
23-
(
22+
static $db = [
2423
'BeenEmailed' => 'Boolean',
2524
'IsTest' => 'Boolean',
2625
'State' => "Enum('INCOMPLETE,SAVED,COMPLETE','INCOMPLETE')",
2726
'Lang' => 'Varchar(10)'
28-
);
27+
];
2928

30-
static $indexes = array();
29+
static $indexes = [];
3130

32-
static $has_one = array
33-
(
31+
static $has_one = [
3432
'Template' => 'SurveyTemplate',
3533
'CreatedBy' => 'Member',
3634
'CurrentStep' => 'SurveyStep',
3735
'MaxAllowedStep' => 'SurveyStep',
38-
);
36+
];
3937

40-
static $many_many = array();
38+
static $many_many = [];
4139

42-
static $has_many = array(
40+
static $has_many = [
4341
'Steps' => 'SurveyStep',
44-
);
42+
];
4543

46-
private static $defaults = array(
44+
static $defaults = [
4745
'BeenEmailed' => false,
4846
'IsTest' => false,
49-
);
47+
];
5048

51-
52-
private static $searchable_fields = array
53-
(
49+
static $searchable_fields = [
5450
'ID',
5551
'Created',
5652
'IsTest',
57-
);
53+
];
54+
55+
static $summary_fields = [
5856

59-
private static $summary_fields = array
60-
(
6157
'ID' => 'ID',
6258
'Created' => 'Created',
6359
'CreatedBy.Email' => 'CreatedBy',
6460
'CurrentStep.Template.Name' => 'CurrentStep',
6561
'EntitiesSurveys.Count' => '# Deployments',
6662
'IsTest' => 'Is Test ?'
67-
);
63+
];
6864

6965
protected function onBeforeWrite()
7066
{
@@ -139,48 +135,41 @@ public function getIdentifier()
139135
*/
140136
public function allowedMaxStep()
141137
{
142-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'MaxAllowedStep')->getTarget();
138+
return $this->getComponent('MaxAllowedStep');
143139
}
144140

145141
/**
146142
* @return ISurveyStep
147143
*/
148144
public function currentStep()
149145
{
150-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'CurrentStep')->getTarget();
146+
return $this->getComponent('CurrentStep');
151147
}
152148

153149
/**
154150
* @return ISurveyStep[]
155151
*/
156152
public function getSteps()
157153
{
158-
$query = new QueryObject(new SurveyStep);
159-
$query->addAlias(QueryAlias::create('Template'));
160-
$query->addOrder(QueryOrder::asc('Template.Order'));
161-
162-
$list = new ArrayList
163-
(
164-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'Steps',$query)->toArray()
165-
);
166-
167-
return $list;
154+
return $this->Steps()
155+
->innerJoin('SurveyStepTemplate', 'SurveyStepTemplate.ID = SurveyStep.TemplateID')
156+
->sort('SurveyStepTemplate.Order', 'ASC');
168157
}
169158

170159
/**
171160
* @return ISurveyTemplate
172161
*/
173162
public function template()
174163
{
175-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'Template')->getTarget();
164+
return $this->getComponent('Template');
176165
}
177166

178167
/**
179168
* @return ICommunityMember
180169
*/
181170
public function createdBy()
182171
{
183-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'CreatedBy')->getTarget();
172+
return $this->getComponent('CreatedBy');
184173
}
185174

186175
/**
@@ -189,7 +178,7 @@ public function createdBy()
189178
*/
190179
public function registerAllowedMaxStep(ISurveyStep $max_step)
191180
{
192-
AssociationFactory::getInstance()->getMany2OneAssociation($this, 'MaxAllowedStep')->setTarget($max_step);
181+
$this->MaxAllowedStepID = $max_step->ID;
193182
}
194183

195184
/**
@@ -198,7 +187,9 @@ public function registerAllowedMaxStep(ISurveyStep $max_step)
198187
*/
199188
public function registerCurrentStep(ISurveyStep $current_step)
200189
{
201-
AssociationFactory::getInstance()->getMany2OneAssociation($this, 'CurrentStep')->setTarget($current_step);
190+
SS_Log::log(sprintf("registering current step %s", $current_step->Template()->Name), SS_Log::DEBUG);
191+
$this->CurrentStepID = $current_step->ID;
192+
$this->write();
202193
}
203194

204195
/**
@@ -207,7 +198,8 @@ public function registerCurrentStep(ISurveyStep $current_step)
207198
*/
208199
public function addStep(ISurveyStep $step)
209200
{
210-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'Steps')->add($step);
201+
$this->Steps()->add($step);
202+
$step->SurveyID = $this->ID;
211203
}
212204

213205
/**
@@ -480,7 +472,6 @@ public function findAnswerByQuestion(ISurveyQuestionTemplate $question)
480472
}
481473
}
482474
}
483-
484475
return null;
485476
}
486477

@@ -491,7 +482,7 @@ public function findAnswerByQuestion(ISurveyQuestionTemplate $question)
491482
public function removeStep(ISurveyStep $step)
492483
{
493484
$step->clear();
494-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'Steps')->remove($step);
485+
$this->Steps()->remove($step);
495486
}
496487

497488
protected function onBeforeDelete()

survey_builder/code/infrastructure/active_records/instances/SurveyAnswer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public function value()
6060
*/
6161
public function question()
6262
{
63-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'Question')->getTarget();
63+
return $this->getComponent('Question');
6464
}
6565

6666
/**
6767
* @return ISurveyStep
6868
*/
6969
public function step()
7070
{
71-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'Step')->getTarget();
71+
return $this->getComponent('Step');
7272
}
7373

7474
/**

survey_builder/code/infrastructure/active_records/instances/SurveyDynamicEntityStep.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function getAnswers()
5252
* @return ISurveyDynamicEntityStepTemplate
5353
*/
5454
public function template(){
55-
return AssociationFactory::getInstance()->getMany2OneAssociation($this, 'Template')->getTarget();
55+
return $this->getComponent('Template');
5656
}
5757

5858
/**
5959
* @return IEntitySurvey[]
6060
*/
6161
public function getEntitySurveys()
6262
{
63-
return AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'EntitySurveys')->toArray();
63+
return $this->EntitySurveys()->toArray();
6464
}
6565

6666
/**
@@ -69,7 +69,8 @@ public function getEntitySurveys()
6969
*/
7070
public function addEntitySurvey(IEntitySurvey $entity_survey)
7171
{
72-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'EntitySurveys')->add($entity_survey);
72+
$this->EntitySurveys()->add($entity_survey);
73+
$entity_survey->OwnerID = $this->ID;
7374
}
7475

7576
/**
@@ -100,7 +101,7 @@ public function clear()
100101
*/
101102
public function clearEntitiesSurvey()
102103
{
103-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'EntitySurveys')->removeAll();
104+
$this->EntitySurveys()->removeAll();
104105
}
105106

106107
/**
@@ -109,9 +110,7 @@ public function clearEntitiesSurvey()
109110
*/
110111
public function removeEntitySurveyById($entity_survey_id)
111112
{
112-
$entity_survey = $this->getEntitySurvey($entity_survey_id);
113-
if($entity_survey)
114-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'EntitySurveys')->remove($entity_survey);
113+
$this->EntitySurveys()->remove($entity_survey_id);
115114
}
116115

117116
protected function onBeforeDelete() {

survey_builder/code/infrastructure/active_records/instances/SurveyRegularStep.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SurveyRegularStep
2929
*/
3030
public function getAnswers()
3131
{
32-
return AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'Answers')->toArray();
32+
return $this->Answers()->toArray();
3333
}
3434

3535
/**
@@ -38,7 +38,7 @@ public function getAnswers()
3838
*/
3939
public function addAnswer(ISurveyAnswer $new_answer)
4040
{
41-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'Answers')->add($new_answer);
41+
return $this->Answers()->add($new_answer);
4242
}
4343

4444
/**
@@ -72,7 +72,7 @@ public function getAnswerByName($name)
7272
*/
7373
public function clearAnswers()
7474
{
75-
AssociationFactory::getInstance()->getOne2ManyAssociation($this, 'Answers')->removeAll();
75+
$this->Answers()->removeAll();
7676
}
7777

7878
/**

0 commit comments

Comments
 (0)