Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_related_asset_listing.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/page_templates/page_asset_listing/page_asset_listing.inc';
19 
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
65  function getAssetList()
66  {
67  $assets_to_list = NULL;
68  $group_by = $this->attr('group_by');
69 
70  $logic = $this->attr('all_root_nodes') ? 'AND' : 'OR';
71 
72  // this is the list of all type codes that we are going to show
73  // we pass this list to the getLinks and getChildren functions (below) to narrow
74  // the query down a bit
75  // if there are no types to list, we cant list anything
76  $wanted_types = $this->attr('types');
77  if (empty($wanted_types)) {
78  trigger_localised_error('CMS0019', E_USER_NOTICE);
79  return Array();
80  }
81 
82  // get the root assets whose sub-assets/children we are displaying
83  // This may come from the parameter map, but the dynamic value must be a child of the static value
84  // if there are no root assets, we will use ourselves and print our children
85  $root_asset_ids = $this->getRootNodes();
86 
87  $sort_info = $this->getSortInfo();
88 
89  // get all the assets that would be listed in a normal asset listing in this case WITHOUT sorting
90  // Let's sort the result after tag filtering is done. Big performance improvement.
91  $unfiltered_assets_to_list = parent::_getAssetList($group_by, $logic, $wanted_types, $root_asset_ids, $sort_info);
92 
93  // get all the assets related to any of the relators
94  $relator_ids = $this->getRelators();
95  $tag_manager = $GLOBALS['SQ_SYSTEM']->getTagManager();
96  $related_assets = $tag_manager->getRelatedAssets($relator_ids, $this->_getThesaurusFilters());
97  $related_ids = array_keys($related_assets);
98  $related_ids = array_diff($related_ids, $relator_ids);
99 
100  // get all the elements of the unfiltered list that are on the related list
101  $assets_to_list = Array();
102  foreach ($related_ids as $related_id) {
103  $asset_to_list = array_get_index($unfiltered_assets_to_list, $related_id);
104  if (!is_null($asset_to_list)) {
105  $assets_to_list[$related_id] = $asset_to_list;
106  }
107  }
108 
109  // Sort the final result set
110  if ($group_by == 'number') {
111  $assets_to_list = parent::_getSortedAssetLists($assets_to_list, $sort_info);
112  }
113 
114  return $assets_to_list;
115 
116  }//end getAssetList()
117 
118 
125  function getRelators()
126  {
127  if (!isset($this->_tmp['relator_asset_ids'])) {
128  $relator_ids = Array();
129  $relator_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_NOTICE, '', FALSE, 'major', 'relator');
130  foreach ($relator_links as $relator_link) {
131  if (strstr($relator_link['minorid'], ':') !== FALSE) {
132  // The link minor is a shadow asset
133  $relator_ids[] = $relator_link['minorid'];
134  } else {
135  $relator_ids[] = (int)$relator_link['minorid'];
136  }
137  }
138  $parameter_map = $this->getAttribute('parameter_map');
139 
140  $raw_dynamic_relators = $parameter_map->getParameterValue('relator_node');
141 
142  // check if we have a dynamic parameter -- if so, let's do some security checks
143  if (!empty($raw_dynamic_relators)) {
144 
145  // note that dynamic relators can be supplied as an array of asset ids or
146  // as a comma delimited string of asset ids
147  if (!is_array($raw_dynamic_relators)) {
148  $dynamic_relators = explode(',', $raw_dynamic_relators);
149  }
150 
151  // if there are dynamic relators, they should override the static relators
152  if (!empty($dynamic_relators)) {
153  $relator_ids = $dynamic_relators;
154  }
155 
156  }//end if
157 
158  // if no relators have been set anywhere, use this asset as the default
159  if (empty($relator_ids)) {
160  $relator_ids = Array($this->id);
161  }
162 
163  $this->_tmp['relator_ids'] = $relator_ids;
164 
165  }//end if
166 
167  return $this->_tmp['relator_ids'];
168 
169  }//end getRelators()
170 
171 
178  function getStaticRelators()
179  {
180  $relator_ids = Array();
181  $relator_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_NOTICE, '', FALSE, 'major', 'relator');
182  foreach ($relator_links as $relator_link) {
183  $relator_ids[$relator_link['minorid']] = $relator_link['minorid'];
184  }
185 
186  return $relator_ids;
187 
188  }//end getStaticRelators()
189 
190 
198  {
199  if (empty($this->id)) return Array();
200  $thesaurus_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($this->id, SQ_LINK_NOTICE, 'thesaurus', FALSE, 'major', 'thesaurus_filter');
201  $res = Array();
202  foreach ($thesaurus_links as $link) {
203  $res[] = $link['minorid'];
204  }
205  return $res;
206 
207  }//end _getThesaurusFilters()
208 
209 
217  function _getCacheKey()
218  {
219  return parent::_getCacheKey().'-REL:'.join(',', $this->getRelators());
220 
221  }//end _getCacheKey()
222 
223 
224 }//end class
225 ?>