Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
design_area_nest_content_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/designs/design_area/design_area_edit_fns.inc';
19 
32 {
33 
34 
39  function __construct()
40  {
41  parent::__construct();
42 
43  }//end constructor
44 
45 
57  {
58  $type_codes = $asset->attr('type_codes');
59  $paint_with = $asset->attr('paint_with');
60  $paint_layout = $asset->attr('paint_layout');
61  $type_code_restrictions = Array();
62  if (is_array($type_codes)) {
63  foreach ($type_codes as $type_code) {
64  $type_code_restrictions[$type_code] = 'D';
65  }
66  }
67  if ($asset->writeAccess('links')) {
68  ?>
69  <table class="sq-backend-table">
70  <tr>
71  <td class="sq-backend-table-cell-alt"><b><?php echo translate('nest_content_menu_nesting') ?></b></td>
72  </tr>
73  <tr>
74  <td class="sq-backend-table-cell">
75  <?php
76  asset_finder($prefix.'_assetid', $asset->_getNestAssetInfo('minorid'), $type_code_restrictions);
77  ?>
78  </td>
79  </tr>
80  <tr>
81  <td class="sq-backend-table-cell-alt"><b><?php echo translate('nest_content_menu_paint_with'); ?></b></td>
82  </tr>
83  <tr>
84  <td class="sq-backend-table-cell">
85  <input name="<?php echo $prefix ?>_paint_with" type="radio" value="raw" <?php if ($paint_with == 'raw') { ?>checked="checked"<?php } ?>> <?php echo translate('nest_content_menu_paint_raw'); ?><br />
86  <input name="<?php echo $prefix ?>_paint_with" type="radio" value="default" <?php if ($paint_with == 'default') { ?>checked="checked"<?php } ?>> <?php echo translate('nest_content_menu_paint_default'); ?><br />
87  <input name="<?php echo $prefix ?>_paint_with" type="radio" value="arbitrary" <?php if ($paint_with == 'arbitrary') { ?>checked="checked"<?php } ?>><?php
88  echo translate('nest_content_menu_paint_arbitrary');
89  asset_finder($prefix.'_paint_layout', $paint_layout, Array('paint_layout_page' => 'D'));
90  ?><br />
91  </td>
92  </tr>
93  </table>
94  <?php
95  } else if ($asset->_getNestAssetInfo('minorid')) {
96  $link_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($asset->_getNestAssetInfo('minorid'));
97  if (!is_null($link_asset)) {
98  echo get_asset_tag_line($link_asset->id);
99  }
100  }
101 
102  return TRUE;
103 
104  }//end paintAssetid()
105 
106 
117  public function processAssetid(Design_Area_Nest_Content $asset, Backend_Outputter $o, $prefix)
118  {
119  if (!isset($_POST[$prefix.'_assetid']['assetid'])) {
120  return FALSE;
121  }
122 
123  $assetid = (int) $_POST[$prefix.'_assetid']['assetid'];
124 
125  // open the transaction
126  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
127  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
128 
129  // Save the paint layout information
130  if (isset($_POST[$prefix.'_paint_layout']['assetid'])) {
131  $paint_layout = $_POST[$prefix.'_paint_layout']['assetid'];
132  $asset->setAttrValue('paint_layout', $paint_layout);
133  }//end if
134 
135  if (isset($_POST[$prefix.'_paint_with'])) {
136  $paint_with = $_POST[$prefix.'_paint_with'];
137  if (($paint_with != ('raw'||'default'||'arbitrary'))) {
138  // Something went very wrong, use the default
139  $paint_with = 'raw';
140  }
141  $asset->setAttrValue('paint_with', $paint_with);
142  }//end if
143 
144  // Update the nested content asset
145  if ($asset->_getNestAssetInfo('minorid') != $_POST[$prefix.'_assetid']['assetid']) {
146  // remove the old link first
147  if ($old_linkid = $asset->_getNestAssetInfo('linkid')) {
148  if (!$asset->deleteLink($old_linkid)) {
149  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
150  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
151  return FALSE;
152  }
153  }
154 
155  // now create the new link
156  if ($assetid) {
157  $link_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
158  if (is_null($link_asset)) {
159  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
160  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
161  return FALSE;
162  }
163  if (!$asset->createLink($link_asset, SQ_LINK_NOTICE, 'nest_content_asset')) {
164  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
165  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
166  return FALSE;
167  }
168  }
169  }//end if
170 
171  // If we get this far, then it's all OK
172  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
173  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
174 
175  return TRUE;
176 
177  }//end processAssetid()
178 
179 
180 }//end class
181 ?>