Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_index_page.inc
1 <?php
15 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
16 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
17 
30 {
31 
32 
51  public static function execute($settings, &$state)
52  {
53 
54  if (!isset($settings['index_page'])) return FALSE;
55  if ($settings['index_page'] == '') return FALSE;
56 
57  $selected_asset_id = array_get_index($settings, 'index_page', 0);
58 
59  if (empty($state['asset'])) {
60  // grab the asset if assetid is given, but not the asset.
61  if (empty($state['assetid'])) {
62  return FALSE;
63  } else {
64  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
65  }
66  }
67  if (is_null($state['asset'])) return FALSE;
68 
69  $link_value = 'index';
70  $field_name = $state['asset']->getPrefix().'_'.str_replace(' ', '_', strtolower($link_value));
71 
72  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($state['asset']->id, SQ_LINK_NOTICE, '', FALSE, $link_value);
73 
74  // if there has been no change, then there is nothing to do
75  if (!empty($link) && $link['minorid'] == $selected_asset_id) {
76  return FALSE;
77  }
78 
79  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
80  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
81  $success = TRUE;
82 
83  // if there is a current link, we need to delete it
84  if (!empty($link)) {
85  $success = (bool) $asset->deleteLink($link['linkid']);
86  }
87 
88  if ($success && !empty($selected_asset_id)) {
89  $selected_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($selected_asset_id);
90  if (!is_null($selected_asset)) {
91  $success = (bool) $state['asset']->createLink($selected_asset, SQ_LINK_NOTICE, $link_value);
92  }
93  } else {
94  return FALSE;
95  }
96 
97  $GLOBALS['SQ_SYSTEM']->doTransaction($success ? 'COMMIT' : 'ROLLBACK');
98  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
99 
100  return Array(
101  'assetid' => $state['asset']->id,
102  'index_page' => $settings['index_page'],
103  );
104 
105  }//end execute()
106 
107 
118  public static function getInterface($settings, $prefix, $write_access=FALSE)
119  {
120 
121  if (empty($settings['index_page'])) {
122  // set to default
123  $selected_assetid = '0';
124  } else {
125  $selected_assetid = $settings['index_page'];
126  }
127 
128  // check if the selected asset is valid
129  if ($selected_assetid && !$GLOBALS['SQ_SYSTEM']->am->assetExists($selected_assetid)) {
130  $selected_assetid = 0;
131  }
132 
133  if (!$write_access) {
134  $form_element_extras = 'disabled="disabled"';
135  } else {
136  $form_element_extras = '';
137  }
138 
139  ob_start();
140  if ($write_access) {
141  asset_finder($prefix.'[index_page]', $selected_assetid, Array('page_standard' => 'P'));
142  echo translate('trigger_set_index_page_select');
143 
144  } else {
145  if ($selected_assetid) {
146  $selected_assetname = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($selected_assetid), Array(), TRUE, 'name');
147  text_box($prefix.'[index_page]', $selected_assetname[$selected_assetid].' (#'.$selected_assetid.')', '', '', FALSE, $form_element_extras);
148  } else {
149  text_box($prefix.'[index_page]', '', '', '', FALSE, $form_element_extras);
150  }
151  }
152 
153  $basic_part_1 = ob_get_contents();
154  ob_end_clean();
155 
156  return translate('trigger_set_index_page_basic', $basic_part_1);
157 
158  }//end getInterface()
159 
160 
172  public static function processInterface(&$settings, $request_data)
173  {
174 
175  // make sure the assetid isn't blank
176  if (empty($request_data['index_page']['assetid'])) {
177  return 'Index page is not specified';
178  }
179 
180  // check if the status is valid
181  $settings['index_page'] = $request_data['index_page']['assetid'];
182 
183  return FALSE;
184 
185  }//end processInterface()
186 
187 
197  public static function getLocks($settings, &$state)
198  {
199 
200  return Array(
201  $state['assetid'] => Array('all'),
202  );
203 
204  }//end getLocks()
205 
206 
207 }//end class