Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
form_question_management.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_management.inc';
19 
31 {
32 
33 
38  function Form_Question_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  ),
48  'note' => Array(
49  'added' => '0.0.1',
50  'type' => 'text',
51  'default' => '',
52  ),
53  'rules' => Array(
54  'added' => '0.0.1',
55  'type' => 'serialise',
56  'default' => Array(),
57  ),
58  'is_required' => Array(
59  'added' => '0.3',
60  'type' => 'boolean',
61  'default' => FALSE,
62  ),
63  'cust_required_error' => Array(
64  'added' => '0.5',
65  'type' => 'text',
66  'default' => '',
67  ),
68  'sticky' => Array(
69  'added' => '0.7',
70  'type' => 'boolean',
71  'default' => 0,
72  'parameters' => Array(
73  'allow_empty' => FALSE,
74  ),
75  ),
76  'tabindex' => Array(
77  'added' => '0.8',
78  'type' => 'int',
79  'default' => '',
80  'parameters' => Array(
81  'allow_negative' => FALSE,
82  'allow_empty' => TRUE,
83  'range_upper' => 32767,
84  ),
85  ),
86  );
87 
88  }//end constructor
89 
90 
99  function _upgrade($current_version)
100  {
101  // first do things as normal
102  $res = parent::_upgrade($current_version);
103 
104  if (version_compare($current_version, '0.6', '<')) {
105  echo('UPGRADING FORM QUESTION FROM v < 0.6');
106  // Upgrade the 'is_required' attr. This didn't work in the 0.2 - 0.3 upgrade
107  // so we need to do some trickiness here to fix failed upgrades where appropriate,
108  // or do a first-time upgrade otherwise
109  if (version_compare($current_version, '0.3', '<')) {
110  // Simple case - just copy values from the old 'required' attrs to the new 'is_required' attr
111  $fixing_upgrade = FALSE;
112  } else {
113  // complex case - need to preserve non-default values of the 'is_required' attr
114  $fixing_upgrade = TRUE;
115  }
116 
117  // get all question assets
118  $form_ids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('form', FALSE, TRUE);
119  $question_assets = Array();
120  foreach ($form_ids as $form_id => $type) {
121  $form = $GLOBALS['SQ_SYSTEM']->am->getAsset($form_id, $type);
122  $question_assets += $form->getChildren($form->id, 'form_question', FALSE);
123  }
124  $section_ids = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids('form_section', FALSE, TRUE);
125  foreach ($section_ids as $section_id => $type) {
126  $section = $GLOBALS['SQ_SYSTEM']->am->getAsset($section_id, $type);
127  $question_assets += $section->getChildren($section->id, 'form_question', FALSE);
128  }
129 
130  // update them
131  $irrelevant_types = Array(); // these don't have a required attr
132  foreach ($question_assets as $id => $type) {
133  if (!isset($irrelevant_types[$type])) {
134  $q = $GLOBALS['SQ_SYSTEM']->am->getAsset($id, $type);
135  if (!isset($q->vars['required'])) {
136  $irrelevant_types[$type] = 1;
137  continue;
138  }
139  if ((!$fixing_upgrade) || ($q->attr('is_required') == FALSE)) {
140  // either we are doing a first-time upgrade, or we are fixing and
141  // the new attr's value is still the default
142  // therefore we'll copy the value from the old attr to the new
143  $q->setAttrValue('is_required', $q->attr('required'));
144  $q->saveAttributes();
145  }
146  }
147  }
148  }//end if
149  return TRUE;
150 
151  }//end _upgrade()
152 
153 
154 }//end class
155 ?>