Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_calendar_rolling_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  'duration_from' => Array(
44  'type' => 'int',
45  'default' => 0,
46  'parameters' => Array(
47  'allow_negative' => TRUE,
48  ),
49  ),
50  'duration_to' => Array(
51  'type' => 'int',
52  'default' => 6,
53  'parameters' => Array(
54  'allow_negative' => TRUE,
55  ),
56  ),
57  'day_filter' => Array(
58  'type' => 'selection',
59  'default' => Array(
60  'Sun',
61  'Mon',
62  'Tue',
63  'Wed',
64  'Thu',
65  'Fri',
66  'Sat',
67  ),
68  'parameters' => Array(
69  'options' => Array(
70  'Sun' => translate('sunday'),
71  'Mon' => translate('monday'),
72  'Tue' => translate('tuesday'),
73  'Wed' => translate('wednesday'),
74  'Thu' => translate('thursday'),
75  'Fri' => translate('friday'),
76  'Sat' => translate('saturday'),
77  ),
78  'multiple' => TRUE,
79  'allow_empty' => FALSE,
80  ),
81  ),
82  'time_unit' => Array(
83  'type' => 'selection',
84  'default' => 'days',
85  'parameters' => Array(
86  'options' => Array(
87  'days' => translate('days'),
88  'weeks' => translate('weeks'),
89  'months' => translate('months'),
90  ),
91  'allow_empty' => FALSE,
92  ),
93  ),
94  'root_nodes' => Array(
95  'type' => 'serialise',
96  'default' => Array(),
97  ),
98  'types' => Array(
99  'added' => '0.4',
100  'type' => 'serialise',
101  'default' => Array(
102  'calendar_event_single' => 0,
103  'calendar_event_recurring' => 0,
104  ),
105  ),
106  );
107 
108  $this->components = Array(
109  'short_name' => Array(
110  'description' => 'Short Name',
111  'default_weighting' => '1',
112  ),
113  );
114 
115  }//end constructor
116 
117 
124  function getEventList()
125  {
126  return Array(
127  Array(
128  'event_name' => 'requestKeywords',
129  'broadcast_type_code' => 'content_type',
130  'broadcast_strict_type_code' => FALSE,
131  'options' => Array(
132  'side_of_link' => 'major',
133  'indirect' => TRUE,
134  'is_exclusive' => NULL,
135  'is_dependant' => 1,
136  'value' => '',
137  'link_type' => SQ_LINK_TYPE_2 | SQ_LINK_TYPE_1,
138  ),
139  ),
140  );
141 
142  }//end getEventList()
143 
144 
153  function _upgrade($current_version)
154  {
155  if (!parent::_upgrade($current_version)) return FALSE;
156 
157  $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(), 'name'));
158  $am =& $GLOBALS['SQ_SYSTEM']->am;
159 
160 
161  if (version_compare($current_version, '0.2', '<')) {
162  // version 0.1 -> 0.2
163  pre_echo('STARTING '.$asset_name.' UPGRADE - FROM VERSION 0.1');
164  $pages = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE, TRUE);
165  foreach ($pages as $assetid => $type_code) {
166  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type_code);
167  if (is_null($asset)) continue;
168 
169  // convert the old days_past and days_future, and convert them into the new days_from and days_to
170  // days_from/to use negative numbers to represent days before the current date
171  if (!$asset->setAttrValue('days_from', ($asset->attr('days_past') * -1)) || !$asset->setAttrValue('days_to', $asset->attr('days_future'))) {
172  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to convert old past and/or future values', "\n";
173  continue;
174  }
175 
176  if (!$asset->saveAttributes()) {
177  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to save attributes', "\n";
178  continue;
179  }
180  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
181  unset($asset);
182  }//end foreach
183  pre_echo($asset_name.' UPGRADE COMPLETE - FROM VERSION 0.1');
184 
185  }//end if - upgrade to version 0.2
186 
187 
188  if (version_compare($current_version, '0.3', '<')) {
189  // version 0.2 -> 0.3
190  pre_echo('STARTING '.$asset_name.' UPGRADE - FROM VERSION '.$current_version);
191 
192  $am->includeAsset('bodycopy');
193 
194  $pages = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), TRUE, TRUE);
195  foreach ($pages as $assetid => $type_code) {
196  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type_code);
197  if (is_null($asset)) continue;
198 
199  echo 'Upgrading Asset #'.$assetid."...\n";
200 
201  // switch the old days_* over to the new attributes
202  if (!$asset->setAttrValue('duration_from', $asset->attr('days_from')) || !$asset->setAttrValue('duration_to', $asset->attr('days_to'))) {
203  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to convert old days_from and/or days_to values', "\n";
204  continue;
205  }
206 
207  // Take the old attribute 'date_format' (default value "l jS F"), and turn it into a series of keywords
208  $date_format = $asset->attr('day_heading_format');
209  $heading_date = '';
210  for ($ii = 0; $ii < strlen($date_format); $ii++) {
211  if (preg_match('/[[:alpha:]]/', $date_format[$ii]) && ($ii == 0 || $date_format[$ii - 1] != '\\')) {
212  $heading_date .= '%time_unit_start_datetime_'.$date_format[$ii].'%';
213  } else if ($date_format[$ii] != '\\') {
214  $heading_date .= $date_format[$ii];
215  }
216  }
217  $heading = $asset->attr('day_heading_tag');
218  $unit_format = '<'.$heading.'>'.$heading_date.'</'.$heading.'>'."\n".'%time_unit_event_list%';
219 
220 
221 
222  // set up a new Time Unit bodycopy to mimic the current formatting settings
223  $link = Array(
224  'asset' => &$asset,
225  'link_type' => SQ_LINK_TYPE_2,
226  'is_dependant' => 1,
227  'is_exclusive' => 1,
228  'value' => 'time_unit',
229  );
230  $bodycopy = new Bodycopy();
231  $time_unit_details = array_get_index($asset->bodycopies, 'time_unit', Array());
232  $bodycopy->setAttrValue('name', array_get_index($time_unit_details, 'name'));
233  if (!$bodycopy->create($link, Array('content' => $unit_format))) {
234  echo 'Asset #', $asset->id, ' (', $asset->name, ') Could not create Time Unit bodycopy', "\n";
235  continue;
236  }
237 
238  if (!$asset->saveAttributes()) {
239  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to save attributes', "\n";
240  continue;
241  }
242  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
243  unset($asset);
244  }//end foreach
245 
246  // unfortunate but necessary flag to tell the restricted-period
247  // calendar page to upgrade itself too
248  $GLOBALS['ROLLING_CAL_PAGE_UPGRADED_TO_03'] = 1;
249 
250  pre_echo($asset_name.' UPGRADE COMPLETE - FROM VERSION 0.2');
251 
252  }//end if - upgrade to version 0.3
253 
254  if (version_compare($current_version, '0.4', '<')) {
255  // version 0.3 -> 0.4
256  pre_echo('STARTING '.$asset_name.' UPGRADE - FROM VERSION '.$current_version);
257 
258  // Give the "Type Formats" folder link a name
259  $pages = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), FALSE, TRUE);
260  foreach ($pages as $assetid => $type_code) {
261  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type_code);
262  if (is_null($asset)) continue;
263 
264  $tf_folder_link = $GLOBALS['SQ_SYSTEM']->am->getLink($assetid, SQ_LINK_TYPE_2, 'folder', TRUE, '', 'major', TRUE);
265  if ($tf_folder_link['value'] != 'type_formats') {
266  $GLOBALS['SQ_SYSTEM']->am->updateLink($tf_folder_link['linkid'], SQ_LINK_TYPE_2, 'type_formats');
267  }
268 
269  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
270  }
271 
272  pre_echo($asset_name.' UPGRADE COMPLETE - FROM VERSION 0.3');
273  }
274 
275  return TRUE;
276 
277  }//end _upgrade()
278 
279 
280 }//end class
281 
282 ?>