Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_related_asset_listing_edit_fns.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/page_templates/page_asset_listing/page_asset_listing_edit_fns.inc';
19 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
20 
34 {
35 
36 
41  function __construct()
42  {
43  parent::__construct();
44 
45  }//end constructor
46 
47 
58  function paintRelator(&$asset, &$o, $prefix)
59  {
60  // get relator links
61  // we need them indexed numerically for getAssetInfo.
62  $relator_asset_ids = $asset->getStaticRelators();
63  sort($relator_asset_ids);
64 
65  if ($asset->writeAccess('links')) {
66  multiple_asset_finder($prefix.'_relator_nodes', $relator_asset_ids);
67  } else {
68  $infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($relator_asset_ids);
69  ?><ul style="margin: 1px 15px;"><?php
70  foreach ($infos as $assetid => $info) {
71  echo '<li>'.get_asset_tag_line($assetid).'</li>';
72  }
73  ?></ul><?php
74  }
75  return TRUE;
76 
77  }//end paintRelator()
78 
79 
90  function processRelator(&$asset, &$o, $prefix)
91  {
92  if (!isset($_POST[$prefix.'_relator_nodes'])) {
93  return FALSE;
94  }
95  $new_relator_nodes = $_POST[$prefix.'_relator_nodes'];
96  foreach ($new_relator_nodes as $new_relator_node) {
97  $new_relator_node_ids[] = $new_relator_node['assetid'];
98  }
99 
100  // get existing relator links
101  $relator_asset_ids = $asset->getStaticRelators();
102 
103  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
104  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
105 
106  // lets delete the relator nodes that have been removed
107  foreach ($relator_asset_ids as $relator_asset_id) {
108  if (!in_array($relator_asset_id, $new_relator_node_ids)) {
109  $link = $GLOBALS['SQ_SYSTEM']->am->getLinkByAsset($asset->id, $relator_asset_id, SQ_LINK_NOTICE, 'relator', $side_of_link='major');
110  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($link['linkid'])) {
111  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
112  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
113  return FALSE;
114  }
115  }
116  }
117 
118  // now, create the new node links
119  foreach ($new_relator_nodes as $index => $node) {
120  // first test to see if the node already exists -- if so, ignore it
121  if (isset($relator_asset_ids[$node['assetid']])) {
122  continue;
123  }
124  // otherwise, create the appropriate notice link
125  if (!empty($node['assetid'])) {
126  $new_relator = $GLOBALS['SQ_SYSTEM']->am->getAsset($node['assetid']);
127  if (!$asset->createLink($new_relator, SQ_LINK_NOTICE, 'relator')) {
128  trigger_localised_error('CMS0016', E_USER_WARNING, $new_relator->name, $new_relator->id);
129  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
130  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
131  return FALSE;
132 
133  }
134  }
135  }
136 
137  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
138  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
139  return TRUE;
140 
141  }//end processRelator()
142 
143 
154  function paintThesaurusFilters(&$asset, &$o, $prefix)
155  {
156  return $this->paintNoticeLinkedAsset($asset, 'thesaurus_filter', Array('thesaurus' => 'D'), $prefix.'thesaurus_filters', TRUE);
157 
158  }//end paintThesaurusFilter()
159 
160 
171  function processThesaurusFilters(&$asset, &$o, $prefix)
172  {
173  if ($asset->writeAccess('links')) {
174  $this->processNoticeLinkedAsset($asset, 'thesaurus_filter', $prefix.'thesaurus_filters', TRUE);
175  }
176  return FALSE; // no need to save attrs, it's only links
177 
178  }//end processThesaurusFilter()
179 
180 }//end class
181 
182 ?>