Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_section_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
31 {
32 
33 
38  function Form_Section_Management(&$pm)
39  {
40  $this->Asset_Management($pm);
41 
42  $this->vars = Array(
43  'name' => Array(
44  'added' => '0.0.1',
45  'type' => 'text',
46  'default' => '',
47  'is_admin' => FALSE,
48  'is_contextable'=> TRUE,
49  ),
50  'sort_order' => Array(
51  'added' => '0.0.1',
52  'type' => 'serialise',
53  'default' => Array(),
54  ),
55  'questions' => Array(
56  'added' => '0.0.1',
57  'type' => 'serialise',
58  'default' => Array(),
59  ),
60  'question_col_width' => Array(
61  'added' => '0.0.1',
62  'type' => 'html_width',
63  'default' => '40%',
64  ),
65  'answer_col_width' => Array(
66  'added' => '0.0.1',
67  'type' => 'html_width',
68  'default' => '60%',
69  ),
70  'section_width' => Array(
71  'added' => '0.0.1',
72  'type' => 'html_width',
73  'default' => '100%',
74  ),
75  'next_questionid' => Array(
76  'added' => '0.3',
77  'type' => 'int',
78  'default' => 0,
79  ),
80  'actions' => Array(
81  'added' => '0.3',
82  'type' => 'serialise',
83  'default' => Array(),
84  ),
85  );
86 
87  }//end constructor
88 
89 
96  function getEventList()
97  {
98  return Array(
99  Array(
100  'event_name' => 'requestKeywords',
101  'broadcast_type_code' => 'content_type',
102  'broadcast_strict_type_code' => FALSE,
103  'options' => Array(
104  'side_of_link' => 'major',
105  'indirect' => TRUE,
106  'is_exclusive' => NULL,
107  'is_dependant' => 1,
108  'value' => 'format',
109  'link_type' => SQ_LINK_TYPE_2 | SQ_LINK_TYPE_1,
110  ),
111  ),
112  );
113 
114  }//end getEventList()
115 
116 
125  function _upgrade($current_version)
126  {
127  if (!parent::_upgrade($current_version)) return FALSE;
128 
129  $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(), 'name'));
130 
131  if (version_compare($current_version, '0.6', '<')) {
132  // version 0.3 -> 0.5 (0.4 was a botched version)
133  // escaping of "<?php", "<?", etc. now happens in content_type::paint(), but we need to
134  // regenerate each bodycopy_container's content file so that we catch any nasties that might
135  // already be present that we need to get rid of.
136  // ignore cases where <?php has already been escaped to &lt;?php
137  pre_echo('STARTING '.$asset_name.' UPGRADE - TO VERSION 0.6');
138  // get all 'bodycopy_container' assets (or their descendants)
139 
140  $form_sections = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetIds($this->getAssetType(), FALSE);
141 
142  pre_echo('Upgrading '.count($form_sections).' assets...');
143  foreach ($form_sections as $assetid) {
144  $form_section = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
145 
146  // reasonably critical upgrade - report any assets that didn't make it
147  if (is_null($form_section)) {
148  pre_echo('Could get asset #'.$assetid);
149  continue;
150  }
151 
152  // regenerate the bodycopy_container's content file
153  $form_section_edit_fns = $form_section->getEditFns();
154  if (!$form_section_edit_fns->generateContentFile($form_section)) {
155  pre_echo('Could not generate content file for asset #'.$assetid);
156  }
157 
158  unset($form_section_edit_fns);
159  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($form_section);
160  }
161  pre_echo($asset_name.' UPGRADE COMPLETE - FROM VERSION '.$current_version.' TO 0.6');
162 
163  }//end version 0.5 upgrade
164 
165  // attribute clean up following bugfix #2461 and #2462
166  if (version_compare($current_version, '0.7', '<')) {
167  $form_section_ids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE);
168  foreach ($form_section_ids as $id) {
169  $form_section_ = $GLOBALS['SQ_SYSTEM']->am->getAsset($id);
170  // remove questions that are not present in the sort order array
171  $sort_order = $form_section_->attr('sort_order');
172  $questions = $form_section_->attr('questions');
173  $new_questions = Array();
174  foreach ($sort_order as $shadowid) {
175  $id_parts = explode(':q', $shadowid);
176  $new_questions[$id_parts[1]] = $questions[$id_parts[1]];
177  }
178  $form_section_->setAttrValue('questions', $new_questions);
179  $form_section_->saveAttributes();
180  }
181  pre_echo(count($form_section_ids).' FORM_SECTIONS UPDATED');
182  }
183 
184  return TRUE;
185 
186  }//end _upgrade()
187 
188 
189 
190 }//end class
191 ?>