Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
data_source_json_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/data_source/data_source/data_source_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
56  public function paintJsonRootObject(Data_Source_Json $asset, Backend_Outputter $o, $prefix)
57  {
58  if (isset($asset->vars['root_object']['value'])) {
59  echo '<pre>' . $asset->vars['root_object']['value'] . '</pre>';
60  }
61 
62  }//end paintJsonUserDefinedNodes()
63 
74  public function paintJsonUserDefinedNodes(Data_Source_Json $asset, Backend_Outputter $o, $prefix)
75  {
76 
77  $nodes = $asset->getUserDefinedJsNodes();
78  if (!empty($nodes)) {
79  echo '<pre>';
80  foreach ($nodes as $node) {
81  echo $node . "\n";
82  }
83  echo '</pre>';
84  }
85 
86  }//end paintJsonUserDefinedNodes()
87 
88 
99  public function paintJsonData(Data_Source_Json $asset, Backend_Outputter $o, $prefix)
100  {
101 
102  echo "<pre>";
103  print_r($asset->getItems());
104  echo "</pre>";
105 
106  }//end paintJsonData()
107 
108 
119  public function paintJsonDataSource(Data_Source_Json $asset, Backend_Outputter $o, $prefix)
120  {
121 
122  echo "<pre>";
123  print_r($asset->getRawSourceData());
124  echo "</pre>";
125 
126  }//end paintJsonData()
127 
128 
139  function paintConnectorLink(&$asset, &$o, $prefix)
140  {
141  // get root links
142  $connector_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, 'json_data_source');
143  if (empty($connector_link)) {
144  $connector_asset_id = NULL;
145  } else {
146  $connector_asset_id = $connector_link['minorid'];
147  }
148 
149  if ($asset->writeAccess('links')) {
150  asset_finder($prefix.'_connector_node', $connector_asset_id, Array(
151  'page_rest_resource' => 'D',
152  'page_standard' => 'I',
153  'page_asset_listing' => 'I',
154  'search_page' => 'I',
155  'file' => 'I',
156  'text_file' => 'I',
157  'js_file' => 'I',
158  )
159  );
160  } else {
161  if (empty($connector_asset_id)) {
162  echo 'No source asset selected.';
163  } else {
164  echo get_asset_tag_line($connector_asset_id);
165  }
166  }
167  return TRUE;
168 
169  }//end paintConnectorLink()
170 
181  function processConnectorLink(&$asset, &$o, $prefix)
182  {
183  $new_connector_id = @$_REQUEST[$prefix.'_connector_node']['assetid'];
184 
185  if (!$asset->writeAccess('links')) {
186  trigger_error('You do not have write access to change the JSON source link', E_USER_WARNING);
187  return FALSE;
188  }
189 
190  $current_connector_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, 'json_data_source');
191  $current_connector_asset_id = @$current_connector_link['minorid'];
192 
193  if (!empty($current_connector_link)) {
194  // if the new connector id is not null and is equal to the current
195  // connector asset id then return
196  if ((!empty($new_connector_id)) && ($current_connector_asset_id === $new_connector_id)) {
197  return TRUE;
198  } else {
199  // else means that we want to create a new link or we want to
200  // clear the link
201  $GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_connector_link['linkid']);
202 
203  // if the new connector id is empty means we want to clear the
204  // link we got nothing else to do so return TRUE
205  if (empty($new_connector_id))return TRUE;
206  }
207  }
208 
209  if (!empty($new_connector_id)) {
210  $new_connector_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_connector_id);
211  $result_id = $GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $new_connector_asset, SQ_LINK_NOTICE, 'json_data_source');
212 
213  if (empty($result_id)) {
214  trigger_error('Could not link asset as JSON source asset', E_USER_WARNING);
215  return FALSE;
216  }
217 
218  }
219 
220  return TRUE;
221 
222  }//end processConnectorLink()
223 
224 }//end class
225 ?>