Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
online_quiz_question_multichoice_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
31 {
32 
33 
39  {
40  $this->Asset_Management($pm);
41 
42  $this->vars = Array(
43  'response_form' => Array(
44  'added' => '0.1',
45  'type' => 'serialise',
46  'default' => Array(),
47  'description' => 'The options that control the response form',
48  ),
49  'max_option_selections' => Array(
50  'added' => '0.1',
51  'type' => 'int',
52  'default' => 1,
53  'parameters' => Array(
54  'allow_negative' => FALSE,
55  'allow_empty' => FALSE,
56  ),
57  'description' => 'The maximum number of options a user can select when answering this question without forfeiting points',
58  ),
59  'forfeit_penalty' => Array(
60  'added' => '0.1',
61  'type' => 'int',
62  'default' => 0,
63  'description' => 'The number of points a user will lose if they forfeit for whatever reason (eg. selected too many options, didn\'t answer the question)',
64  ),
65  'option_style' => Array(
66  'added' => '0.1',
67  'type' => 'selection',
68  'default' => 'radio',
69  'parameters' => Array(
70  'options' => Array(
71  'radio' => 'Radio Buttons / Checkboxes',
72  'list' => 'Dropdown List',
73  ),
74  'allow_empty' => FALSE,
75  ),
76  'description' => 'The options that control the response form',
77  ),
78  'use_html_options' => Array(
79  'added' => '0.3',
80  'type' => 'selection',
81  'default' => '0',
82  'parameters' => Array(
83  'options' => Array(
84  '0' => 'No',
85  '1' => 'Yes',
86  ),
87  ),
88  'multiple' => FALSE,
89  'allow_empty' => FALSE,
90  ),
91  );
92 
93  }//end constructor
94 
95 
104  function _upgrade($current_version)
105  {
106  // Add empty Response Supplements to existing question options
107  if (version_compare($current_version, '0.2', '<')) {
108  $children = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE);
109  pre_echo('STARTING ONLINE QUIZ QUESTION MULTI-CHOICE UPGRADE - VERSION 0.1 => 0.2');
110 
111  foreach ($children as $assetid) {
112  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
113 
114  // Build the Response Supplements (option_value => response_supplement)
115  $question_options = $asset->attr('response_form');
116 
117  foreach ($question_options as $option_key => $option) {
118  $question_options[$option_key]['response_supplement'] = '';
119  }
120 
121  if (!$asset->setAttrValue('response_form', $question_options)) {
122  trigger_localised_error('CMS0039', E_USER_WARNING, '0.2');
123  }
124 
125  if (!$asset->saveAttributes()) {
126  trigger_localised_error('CMS0026', E_USER_WARNING, '0.2');
127  return FALSE;
128  }
129 
130  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
131  }
132 
133  pre_echo('ONLINE QUIZ QUESTION MULTI-CHOICE UPGRADE COMPLETE - VERSION 0.1 => 0.2');
134  }
135 
136  return parent::_upgrade($current_version);
137 
138  }//end _upgrade()
139 
140 
141 }//end class
142 ?>