Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_calendar_restricted_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  'start_date' => Array(
44  'added' => '0.0.1',
45  'type' => 'datetime',
46  'default' => '---------- --:--:--',
47  'parameters' => Array(
48  'allow_null' => FALSE,
49  ),
50  'description' => 'The starting date and/or time of the event',
51  'update_fn' => '',
52  ),
53  'end_date' => Array(
54  'added' => '0.0.1',
55  'type' => 'datetime',
56  'default' => '---------- --:--:--',
57  'parameters' => Array('allow_null' => FALSE),
58  'description' => 'The ending date and/or time of the event',
59  'update_fn' => '',
60  ),
61  'days_per_page' => Array(
62  'type' => 'int',
63  'default' => 1,
64  'parameters' => Array('allow_negative' => FALSE),
65  ),
66  'next_text' => Array(
67  'type' => 'text',
68  'default' => 'Next %n% Days >>',
69  'is_contextable' => TRUE,
70  ),
71  'prev_text' => Array(
72  'type' => 'text',
73  'default' => '<< Previous %n% days',
74  'is_contextable' => TRUE,
75  ),
76  );
77 
78  $this->components = Array(
79  'short_name' => Array(
80  'description' => 'Short Name',
81  'default_weighting' => '1',
82  ),
83  );
84 
85  }//end constructor
86 
87 
94  function getEventList()
95  {
96  return Array(
97  Array(
98  'event_name' => 'requestKeywords',
99  'broadcast_type_code' => 'content_type',
100  'broadcast_strict_type_code' => FALSE,
101  'options' => Array(
102  'side_of_link' => 'major',
103  'indirect' => TRUE,
104  'is_exclusive' => NULL,
105  'is_dependant' => 1,
106  'value' => '',
107  'link_type' => SQ_LINK_TYPE_2 | SQ_LINK_TYPE_1,
108  ),
109  ),
110  );
111 
112  }//end getEventList()
113 
114 
123  function _upgrade($current_version)
124  {
125  if (!parent::_upgrade($current_version)) return FALSE;
126 
127  $asset_name = strtoupper($this->_pm->getTypeInfo($this->getAssetType(), 'name'));
128  $am =& $GLOBALS['SQ_SYSTEM']->am;
129 
130 
131  if (version_compare($current_version, '0.3', '<') && !empty($GLOBALS['ROLLING_CAL_PAGE_UPGRADED_TO_03'])) {
132  // version 0.2 -> 0.3
133  pre_echo('STARTING '.$asset_name.' UPGRADE - TO VERSION 0.3');
134 
135  $am->includeAsset('bodycopy');
136 
137  $pages = $GLOBALS['SQ_SYSTEM']->am->getTypeAssetids($this->getAssetType(), TRUE, TRUE);
138  foreach ($pages as $assetid => $type_code) {
139  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid, $type_code);
140  if (is_null($asset)) continue;
141  echo 'Upgrading Asset #'.$assetid."...\n";
142 
143  // switch the old days_* over to the new attributes
144  if (!$asset->setAttrValue('duration_from', $asset->attr('days_from')) || !$asset->setAttrValue('duration_to', $asset->attr('days_to'))) {
145  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to convert old days_from and/or days_to values', "\n";
146  continue;
147  }
148 
149  // Take the old attribute 'date_format' (default value "l jS F"), and turn it into a series of keywords
150  $date_format = $asset->attr('day_heading_format');
151  $heading_date = '';
152  for ($ii = 0; $ii < strlen($date_format); $ii++) {
153  if (preg_match('/[[:alpha:]]/', $date_format[$ii]) && ($ii == 0 || $date_format[$ii - 1] != '\\')) {
154  $heading_date .= '%time_unit_start_datetime_'.$date_format[$ii].'%';
155  } else if ($date_format[$ii] != '\\') {
156  $heading_date .= $date_format[$ii];
157  }
158  }
159  $heading = $asset->attr('day_heading_tag');
160  $unit_format = '<'.$heading.'>'.$heading_date.'</'.$heading.'>'."\n".'%time_unit_event_list%';
161 
162 
163 
164  // set up a new Time Unit bodycopy to mimic the current formatting settings
165  $link = Array(
166  'asset' => &$asset,
167  'link_type' => SQ_LINK_TYPE_2,
168  'is_dependant' => 1,
169  'is_exclusive' => 1,
170  'value' => 'time_unit',
171  );
172  $bodycopy = new Bodycopy();
173  $time_unit_details = array_get_index($asset->bodycopies, 'time_unit', Array());
174  $bodycopy->setAttrValue('name', array_get_index($time_unit_details, 'name'));
175  if (!$bodycopy->create($link, Array('content' => $unit_format))) {
176  echo 'Asset #', $asset->id, ' (', $asset->name, ') Could not create Time Unit bodycopy', "\n";
177  continue;
178  }
179 
180  if (!$asset->saveAttributes()) {
181  echo 'Asset #', $asset->id, ' (', $asset->name,') Unable to save attributes', "\n";
182  continue;
183  }
184  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
185  unset($asset);
186  }//end foreach
187  pre_echo($asset_name.' UPGRADE COMPLETE - TO VERSION 0.3');
188 
189  }//end if - upgrade to version 0.3
190 
191 
192  return TRUE;
193 
194  }//end _upgrade()
195 
196 }//end class
197 
198 ?>