Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
online_quiz_question_group_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/folder/folder_edit_fns.inc';
19 require_once SQ_ATTRIBUTES_PATH.'/wysiwyg/wysiwyg.inc';
20 
35 {
36 
37 
43  {
44  $this->Folder_Edit_Fns();
45 
46  $this->static_screens['details']['force_unlock'] = FALSE;
47 
48  }//end constructor
49 
50 
61  function paintScoreCategories(&$asset, &$o, $prefix)
62  {
63  $write_access = $asset->writeAccess('attributes');
64 
65  $o->openField(translate('online_quiz_question_group_score_categories'));
66 
67  $score_categories = $asset->getScoreCategories();
68 
69  if (empty($score_categories)) {
70  echo translate('online_quiz_question_group_empty_score_categories');
71  } else {
72 
73  ?>
74  <table class="sq-backend-table">
75  <tr>
76  <th><?php echo translate('online_quiz_question_group_score_category'); ?></th>
77  <th><?php echo translate('online_quiz_question_group_minimum_score'); ?></th>
78  <th><?php echo translate('online_quiz_question_group_maximum_score'); ?></th>
79  <?php
80  if ($write_access) {
81  ?>
82  <th><?php echo translate('online_quiz_question_group_delete_category'); ?></th>
83  <?php
84  }
85  ?>
86  </tr>
87  <?php
88  foreach ($score_categories as $key => $score_category) {
89  ?>
90  <tr>
91  <td><?php
92  if ($write_access) {
93  text_box($prefix.'_score_category['.$key.'][name]', $score_category['name'], 60);
94  } else {
95  echo $score_category['name'];
96  }
97  ?></td>
98 
99  <td><?php
100  if ($write_access) {
101  int_text_box($prefix.'_score_category['.$key.'][min_score]', $score_category['min_score'], TRUE, 5);
102  } else {
103  echo $score_category['min_score'];
104  }
105  ?></td>
106 
107  <td><?php
108  if ($write_access) {
109  int_text_box($prefix.'_score_category['.$key.'][max_score]', $score_category['max_score'], TRUE, 5);
110  } else {
111  echo $score_category['max_score'];
112  }
113  ?></td>
114 
115  <?php
116  if ($write_access) {
117  ?><td><?php check_box($prefix.'_score_category['.$key.'][delete]'); ?></td><?php
118  }
119  ?></td>
120  </tr>
121 
122  <?php
123  }//end foreach ($score_categories)
124 
125  ?>
126  </table>
127  <?php
128 
129  }//end else empty($score_categories)
130  $o->closeField();
131 
132  if ($write_access) {
133  $o->openField(translate('online_quiz_question_group_new_score_category'));
134  text_box($prefix.'_new_score_category', '', 60);
135  $o->closeField();
136  }
137 
138  return $write_access;
139 
140  }//end paintScoreCategories()
141 
142 
153  function processScoreCategories(&$asset, &$o, $prefix)
154  {
155  $write_access = $asset->writeAccess('attributes');
156 
157  if ($write_access) {
158 
159  // delete & edit
160  $score_categories = Array();
161  $to_edit = array_get_index($_REQUEST, $prefix.'_score_category', Array());
162 
163  $option_key_counter = 0;
164 
165  foreach ($to_edit as $option_key => $option) {
166  // if we're deleting, just omit this option from the entire process
167  if (!array_get_index($option, 'delete')) {
168  $name = trim(array_get_index($option, 'name'));
169  $min_score = array_get_index($option, 'min_score', NULL);
170  $max_score = array_get_index($option, 'max_score', NULL);
171  $content = $_REQUEST[$prefix.'_supplement_'.$option_key];
172 
173  if (!empty($name)) {
174  $score_categories[$option_key_counter]['name'] = $name;
175  $score_categories[$option_key_counter]['min_score'] = '';
176  $score_categories[$option_key_counter]['max_score'] = '';
177  $score_categories[$option_key_counter]['content'] = $content;
178 
179  if ($min_score != '') {
180  $score_categories[$option_key_counter]['min_score'] = (int)$min_score;
181  }
182  if ($max_score != '') {
183  $score_categories[$option_key_counter]['max_score'] = (int)$max_score;
184  }
185 
186  $option_key_counter++;
187  }
188  }
189  }
190 
191  // add
192  $new_score_category = trim(array_get_index($_REQUEST, $prefix.'_new_score_category'));
193  if (!empty($new_score_category)) {
194  $score_categories[$option_key_counter] = Array(
195  'name' => $new_score_category,
196  'min_score' => '',
197  'max_score' => '',
198  'content' => '',
199  );
200 
201  $option_key_counter++;
202  }
203 
204  $asset->setAttrValue('score_categories', $score_categories);
205 
206  }//end if ($write_access)
207 
208  return $write_access;
209 
210  }//end processScoreCategories()
211 
212 
223  function paintScoreCategoriesContent(&$asset, &$o, $prefix)
224  {
225  $write_access = $asset->writeAccess('attributes');
226 
227  $o->openField(translate('online_quiz_question_group_score_categories'));
228 
229  $score_categories = $asset->getScoreCategories();
230 
231  if (empty($score_categories)) {
232  echo translate('online_quiz_question_group_empty_score_categories');
233  } else {
234 
235  ?>
236  <table class="sq-backend-table">
237  <tr>
238  <th><?php echo translate('online_quiz_question_group_score_category'); ?></th>
239  <th><?php echo translate('online_quiz_question_group_supplementary_content'); ?></th>
240  </tr>
241  <?php
242 
243  foreach ($score_categories as $option_key => $option) {
244  ?>
245  <tr>
246  <td><?php
247  echo $option['name'];
248  ?></td>
249 
250  <td>
251  <table border="0" width="100%">
252  <tr>
253  <td>
254  <?php
255  $wysiwyg_prefix = $prefix.'_supplement_'.$option_key;
256  $wysiwyg = new Asset_Attribute_WYSIWYG();
257  if (isset($option['content'])) {
258  $wysiwyg->value = $option['content'];
259  }
260  $wysiwyg->paint($wysiwyg_prefix, !$write_access);
261  ?>
262  </td>
263  </tr>
264  </table>
265  </td>
266  </tr>
267 
268  <?php
269  }//end foreach ($options)
270 
271  ?>
272  </table>
273  <?php
274 
275  }//end else empty($options)
276  $o->closeField();
277 
278  return $write_access;
279 
280  }//end paintScoreCategoriesContent()
281 
282 
283 }//end class
284 ?>