Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
data_source_record_set.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset.inc';
19 
20 
33 {
34 
40  protected $_data_sourceid = 0;
41 
42 
50  function __construct($data_sourceid=0, Array $data=Array())
51  {
52  $this->_ser_attrs = TRUE;
53  $this->_loadVars();
54 
55  if (!$data_sourceid || empty($data)) {
56  return;
57  }
58 
59  $data_source = $GLOBALS['SQ_SYSTEM']->am->getAsset($data_sourceid);
60  if (is_null($data_source)) return;
61 
62  $this->_data_sourceid = $data_sourceid;
63 
64  // set general object properties
65  $this->id = $data_source->id.':'.$data['shadow_asset_id'];
66  unset($data['shadow_asset_id']);
67 
68 
69  $this->status = $data_source->status;
70  $this->version = '0.1';
71 
72  foreach ($data as $key => $value) {
73  $this->vars[$key] = $value;
74  }
75  // if the name has keywords in it then we get the string with replacements
76  if (!empty($data['shadow_asset_name'])) {
77  $this->name = $this->replaceKeywordsInString($data['shadow_asset_name']);
78  } else {
79  if (isset($data['title'])) {
80  $this->name = $data['title'];
81  } else {
82  $this->name = 'Data Source Record Set '.$this->id;
83  }
84  }
85  $this->short_name = $this->name;
86 
87  }//end constructor
88 
89 
97  public function _getAllowedLinks()
98  {
99  return Array();
100 
101  }//end _getAllowedLinks()
102 
103 
113  protected function _getName($short_name=FALSE)
114  {
115  return $this->name;
116 
117  }//end _getName()
118 
119 
134  public function getAvailableKeywords()
135  {
136  $keywords = Array();
137  if (empty($this->vars)) {
138  $keywords = parent::getAvailableKeywords();
139  return $keywords;
140  }
141  $columns = array_keys($this->vars);
142  $keywords['asset_assetid'] = translate('record_set_id');
143  $keywords['asset_version'] = translate('record_set_version');
144  $keywords['asset_status'] = translate('record_set_status');
145  $keywords['asset_name'] = translate('record_set_name');
146  $keywords['asset_short_name'] = translate('record_set_short_name');
147  $keywords['asset_data_source_id'] = translate('data_source_id');
148 
149  $attr_string = translate('record_set_attribute');
150  foreach ($columns as $column) {
151  $keywords['data_source_record_set_'.$column] = $attr_string.' : '.$column;
152  $keywords['ds__'.$column] = $attr_string.' : '.$column;
153  }
154  return $keywords;
155 
156  }//end getAvailableKeywords()
157 
158 
167  public function getKeywordReplacement($keyword)
168  {
169  $replacement = NULL;
170 
171  // Remove any modifiers from keyword
172  $full_keyword = $keyword;
173  $keyword = parse_keyword($keyword, $modifiers);
174  $contextid = extract_context_modifier($modifiers);
175 
176  if ($contextid !== NULL) {
177  // If we were able to extract a context ID to change to, and it's
178  // different to our current one, then change and then reload a copy
179  // of the asset in that context (as we would need to do anyway)
180 
181  if ((int)$contextid !== $GLOBALS['SQ_SYSTEM']->getContextId()) {
182  $GLOBALS['SQ_SYSTEM']->changeContext($contextid);
183  $contexted_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->id);
184 
185  // Get the keyword without any modifiers
186  $replacement = $contexted_asset->getKeywordReplacement($keyword);
187 
188  // Then apply the ones we had remaining, then return it
189  apply_keyword_modifiers($replacement, $modifiers, Array('assetid' => $contexted_asset->id));
190 
191  unset($contexted_asset);
192  $GLOBALS['SQ_SYSTEM']->restoreContext();
193  return $replacement;
194 
195  }//end if contextid is not the currently active context
196 
197  }//end if contextid is not NULL
198 
199 
200  if (strpos($keyword, 'data_source_record_set_') !== FALSE) {
201  $keyword = substr($keyword, strlen('data_source_record_set_'));
202  $replacement = array_get_index($this->vars, $keyword, '');
203  } else if (strpos($keyword, 'ds__') !== FALSE) {
204  // this does the same thing as 'data_source_record_set_' but is much shorter
205  $keyword = substr($keyword, strlen('ds__'));
206  $replacement = array_get_index($this->vars, $keyword, '');
207  } else if (strpos($keyword, 'asset_') !== FALSE) {
208  $key = substr($keyword, strlen('asset_'));
209 
210  switch ($key) {
211  case 'name':
212  case 'short_name':
213  $replacement = $this->name;
214  break;
215 
216  case 'assetid':
217  $replacement = $this->id;
218  break;
219 
220  case 'version':
221  $replacement = $this->version;
222  break;
223 
224  case 'status':
225  $replacement = $this->status;
226  break;
227 
228  case 'data_source_id':
229  $replacement = $this->_data_sourceid;
230  break;
231 
232  default:
233  // Full keyword not wanted here, since modifiers still
234  // applied afterward
235  $replacement = parent::getKeywordReplacement($keyword);
236  break;
237  }
238  }
239 
240  if (count($modifiers) > 0) {
241  apply_keyword_modifiers($replacement, $modifiers, Array('assetid' => $this->id));
242  }
243 
244  return $replacement;
245 
246  }//end getKeywordReplacement()
247 
248 
258  public function readAccess($assetids=Array())
259  {
260  $parent = $this->_getBridge();
261  if (!is_null($parent)) {
262  $result = $parent->readAccess($assetids);
263  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($parent);
264  return $result;
265  }
266 
267  return FALSE;
268 
269  }//end readAccess()
270 
271 
290  public function writeAccess($lock_type='', $assetids=Array(), $only_workflow=TRUE)
291  {
292  $parent = $this->_getBridge();
293  if (!is_null($parent)) {
294  $result = $parent->writeAccess($lock_type, $assetids, $only_workflow);
295  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($parent);
296  return $result;
297  }
298 
299  return FALSE;
300 
301  }//end writeAccess()
302 
303 
310  protected function _getBridge()
311  {
312  list($bridgeid, $childid) = explode(':', $this->id);
313  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($bridgeid);
314  return $asset;
315 
316  }//end _getBridge()
317 
318 
319 }//end class
320 
321 ?>