CMS  Version 3.9
survey_component_manager.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9 Copyright (c) 2007,2008 Sonjara, Inc
10 
11 Permission is hereby granted, free of charge, to any person
12 obtaining a copy of this software and associated documentation
13 files (the "Software"), to deal in the Software without
14 restriction, including without limitation the rights to use,
15 copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the
17 Software is furnished to do so, subject to the following
18 conditions:
19 
20 The above copyright notice and this permission notice shall be
21 included in all copies or substantial portions of the Software.
22 
23 Except as contained in this notice, the name(s) of the above
24 copyright holders shall not be used in advertising or otherwise
25 to promote the sale, use or other dealings in this Software
26 without prior written authorization.
27 
28 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35 OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
47 {
49  {
50 
51  }
52 
54  {
55  $classes[] = "SurveyAnswer";
56  $classes[] = "SurveyQuestion";
57  $classes[] = "SurveyResponse";
58  $classes[] = "Survey";
59 
60  return $classes;
61  }
62 
63  static function setDefaults()
64  {
65  trace("SurveyManager::setDefaults", 3);
66 
67  global $config;
68 
69  Settings::setDefaultValue("survey", "sender_email", "", "String", "The email address that will appear as the sender of the survey email", "Survey Emails");
70  Settings::setDefaultValue("survey", "email_subject", "Survey from ". $config["http_host"], "String", "The default or standard subject line for survey emails", "Survey Emails");
71  Settings::setDefaultValue("survey", "message_footer", "<br><br>Click the link below to access the survey:<br>[survey_link]<br><br>or go to<br>[survey_intro_link], click on [survey_title], and enter your access token [token] at the prompt.<br>", "Text", "The text to be included below the main
72  message in all surveys, providing users with a link to response.
73  The text within brackets represent codes that will be filled in with data
74  from the survey record when the survey is sent.", "Survey Emails");
75  Settings::setDefaultValue("survey", "interactive_graphs", false, Boolean, "Show interactive SVG graphs on the report screens, rather than static images");
76 
77  }
78 
80  {
81  $classes[] = "SurveyAnswer";
82  $classes[] = "SurveyQuestion";
83  $classes[] = "SurveyResponse";
84  $classes[] = "Survey";
85  $classes[] = "SurveyQuestionXref";
86 
87  return $classes;
88  }
89 
97  static function deleteUser($user)
98  {
99  $pk = $user->getPrimaryKey();
100  $user_id = $user->$pk;
101 
102  trace("Component survey is deleting objects dependent on user_id {$user_id}", 3);
103 
104  $tx = new DataTransaction();
105 
106  try
107  {
108  $surveys = Query::create(Survey, "WHERE user_id=:user_id")
109  ->bind(":user_id", $user_id)
110  ->execute();
111 
112  foreach($surveys as $survey)
113  {
114  $survey->joinTransaction($tx);
116  }
117 
118  $tx->commit();
119  }
120  catch(Exception $e)
121  {
122  $tx->rollback();
123  throw $e;
124  }
125 
126  return $user;
127  }
128 
129  static function deleteSurvey($survey)
130  {
131  $survey_id = $survey->survey_id;
132  $questions = $survey->Questions();
133 
134  $tx = new DataTransaction();
135 
136  try
137  {
138  $xref = new SurveyQuestionXref();
139  $xref->joinTransaction($tx);
140  $xref->delete("WHERE survey_id={$survey_id}");
141 
142  $responses = $survey->Responses();
143 
144  if(count($responses))
145  {
146  foreach($responses as $response)
147  {
148  $response->joinTransaction($tx);
150  }
151  }
152 
153  $tx->commit();
154  }
155  catch(Exception $e)
156  {
157  $tx->rollback();
158  throw $e;
159  }
160 
161  // Delete any questions that are now not linked to any survey
162  foreach($questions as $question)
163  {
164  $count = Query::create(SurveyQuestionXref, "WHERE survey_question_id=:survey_question_id")
165  ->bind(":survey_question_id", $question->survey_question_id)
166  ->executeValue("COUNT(1)");
167 
168  if($count == 0)
169  {
170  $question->delete();
171  }
172  }
173  }
174 
176  {
177  $tx = new DataTransaction();
178 
179  try
180  {
181  $response->joinTransaction($tx);
182 
183  $answer = new SurveyAnswer();
184  $answer->joinTransaction($tx);
185  $answer->delete("WHERE response_id={$response->response_id}");
186 
187  $tx->commit();
188  }
189  catch(Exception $e)
190  {
191  $tx->rollback();
192  throw $e;
193  }
194  }
195 
196  static function upgradeComponent($version)
197  {
198  $mgr = new SurveyUpgradeManager();
199  $mgr->upgrade($version);
200  }
201 }?>
$user_id
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
Definition: settings.inc:174
SurveyComponentManager - manages survey component; the class name SurveyManager is used for managemen...
static enumerateDataItemClasses($classes)
static enumerateContextHelpClasses($classes)
static deleteSurveyResponse($response)
static deleteUser($user)
Respond to fired event DeleteUser.
$survey_id
if(! $survey_id) $survey
global $user
global $config
Definition: import.inc:4
$question
if(! $user) if(! $response_id) $response