Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_folder.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/interfaces/bridge/bridge.inc';
19 
31 class Search_Folder extends Asset implements Bridge
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  $this->_ser_attrs = TRUE;
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
59  protected function _getName($short_name=FALSE, $contextid=NULL)
60  {
61  // No context specified, using the current context
62  if ($contextid === NULL) {
63  $contextid = $GLOBALS['SQ_SYSTEM']->getContextId();
64  }//end if
65 
66  // Obtain the attribute value for Name from the specified Context
67  $values = $GLOBALS['SQ_SYSTEM']->am->getAttributeValuesByName('name', $this->type(), Array($this->id), $contextid);
68  if (empty($values) === TRUE) {
69  return parent::_getName($short_name, $contextid);
70  } else {
71  return $values[$this->id];
72  }
73 
74  }//end _getName()
75 
76 
91  function getAsset($shadowid, $type_code='', $mute_errors=FALSE)
92  {
93  $asset = NULL;
94 
95  $id_parts = explode(':', $shadowid);
96  if (isset($id_parts[1])) {
97  $shadowid = $id_parts[1];
98  } else {
99  return $asset;
100  }
101 
102  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($shadowid);
103  return $asset;
104 
105  }//end getAsset()
106 
107 
129  function getLinks($assetid, $link_types, $type_code='', $strict_type_code=TRUE, $side_of_link='major', $sort_by=NULL)
130  {
131  // It does not return any links from the search result so that asset map refresh wouldn't have
132  // a clue that what is underneath.
133  $links = Array();
134  $id_parts = explode(':', $assetid);
135  if (isset($id_parts[1])) return $links;
136 
137  assert_equals($assetid, $this->id, translate('sch_folder_only_own_links'));
138 
139  if (!isset($this->_tmp['getLinks'])) {
140 
141  $settings = $this->attr('settings');
142 
143  $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
144  $search_info = Array();
145  $search_info['limit'] = 100;
146  $search_info['requester'] = $this->id;
147  $search_info['field_logic'] = (isset($settings['logic'])) ? strtoupper($settings['logic']) : 'AND';
148 
149  if (empty($type_code)) {
150  $search_info['asset_types'] = (isset($settings['types'])) ? $settings['types'] : Array();
151  } else {
152  if (!is_array($type_code)) {
153  $type_code = Array($type_code);
154  }
155 
156  // handle new search manager 'inherited types' rules
157  $type_code = array_flip($type_code);
158  foreach ($type_code as $this_type_code => $value) {
159  $type_code[$this_type_code] = TRUE;
160  }
161  $search_info['asset_types'] = $type_code;
162  }
163  // if we have not selected to search any types, we are going to return no results
164  if (empty($search_info['asset_types'])) {
165  return Array();
166  }
167 
168  $search_info['statuses'] = (isset($settings['statuses'])) ? $settings['statuses'] : Array();
169  // if we have not selected to search any statuses, we are going to return no results
170  if (empty($search_info['statuses'])) return Array();
171 
172  $search_info['roots'] = Array();
173  if (!empty($settings['root'])) {
174  $search_info['roots'] = $settings['root'];
175  } else {
176  $search_info['roots'][] = $GLOBALS['SQ_SYSTEM']->am->getSystemAssetid('root_folder');
177  }
178 
179  if (!isset($settings['phrase']) || trim($settings['phrase']) == '') {
180  $search_results = $sm->processBasicSearch($search_info);
181  } else {
182  $search_info['fields'][$settings['phrase']]['words'] = $settings['phrase'];
183  $search_info['fields'][$settings['phrase']]['word_logic'] = (isset($settings['logic'])) ? strtoupper($settings['logic']) : 'AND';
184  $search_info['fields'][$settings['phrase']]['data_sources'] = Array(Array('type' => 'include_all'));
185  $search_results = $sm->processSearch($search_info);
186  }
187 
188  if (empty($search_results)) return $links;
189 
190  $assetids = array_keys($search_results);
191  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($assetids);
192 
193  $sort_order = 0;
194  foreach ($asset_info as $assetid => $info) {
195  $links[] = Array(
196  'linkid' => 0,
197  'minorid' => $assetid,
198  'value' => '',
199  'link_type' => SQ_LINK_TYPE_2,
200  'minor_type_code' => $info['type_code'],
201  'sort_order' => $sort_order,
202  'is_dependant' => '0',
203  'is_exclusive' => '0',
204  'locked' => 0,
205  );
206 
207  $sort_order++;
208  }
209 
210  $this->_tmp['getLinks'] = $links;
211 
212  }//end if not cached
213 
214  return $this->_tmp['getLinks'];
215 
216  }//end getLinks()
217 
218 
225  public function getAssetMapLinks()
226  {
227  if (!isset($this->_tmp['getAssetMapLinks'])) {
228 
229  $links = Array();
230  $settings = $this->attr('settings');
231 
232  $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
233  $search_info = Array();
234  $search_info['limit'] = 100;
235  $search_info['field_logic'] = (isset($settings['logic'])) ? strtoupper($settings['logic']) : 'AND';
236  $search_info['asset_types'] = (isset($settings['types'])) ? $settings['types'] : Array();
237  $search_info['statuses'] = (isset($settings['statuses'])) ? $settings['statuses'] : Array();
238 
239  $search_info['roots'] = Array();
240  if (!empty($settings['root'])) {
241  $search_info['roots'] = $settings['root'];
242  }
243 
244  $search_info['requester'] = $this->id;
245 
246  // if we have not selected to search any types or statuses, we are going to return no results
247  if (empty($search_info['asset_types'])) {
248  return Array();
249  }
250 
251  if (empty($search_info['statuses'])) return Array();
252 
253  if (!isset($settings['phrase']) || trim($settings['phrase']) == '') {
254  $search_results = $sm->processBasicSearch($search_info);
255  } else {
256  $search_info['fields'][$settings['phrase']]['words'] = $settings['phrase'];
257  $search_info['fields'][$settings['phrase']]['word_logic'] = (isset($settings['logic'])) ? strtoupper($settings['logic']) : 'AND';
258  $search_info['fields'][$settings['phrase']]['data_sources'] = Array(Array('type' => 'include_all'));
259  $search_results = $sm->processSearch($search_info);
260  }
261 
262  if (empty($search_results)) return $links;
263 
264  $assetids = array_keys($search_results);
265  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($assetids);
266 
267  $sort_order = 0;
268  foreach ($asset_info as $assetid => $info) {
269  $links[] = Array(
270  'assetid' => $this->id.':'.$assetid,
271  'short_name' => $info['short_name'],
272  'name' => $info['name'],
273  'accessible' => 1,
274  'type_code' => $info['type_code'],
275  'status' => $info['status'],
276  'linkid' => $this->id.':'.$assetid,
277  'link_type' => SQ_LINK_TYPE_2,
278  'num_kids' => 0,
279  'sort_order' => $sort_order,
280  'is_dependant' => 0,
281  'url' => '',
282  'path' => '',
283  );
284 
285  $sort_order++;
286  }
287 
288  $this->_tmp['getAssetMapLinks'] = $links;
289 
290  }//end if not cached
291 
292  return $this->_tmp['getAssetMapLinks'];
293 
294  }//end getAssetMapLinks()
295 
296 
305  function getAssetMapAssetInfo($assetid)
306  {
307  $attrs = Array();
308 
309  $id_parts = explode(':', $assetid);
310  if (isset($id_parts[1])) {
311  $assetid = $id_parts[1];
312  } else {
313  return $attrs;
314  }
315 
316  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
317 
318  if (!is_null($assetid)) {
319  $attrs = Array(
320  'assetid' => $assetid,
321  'name' => $asset->short_name,
322  'type_code' => $asset->type(),
323  'accessible' => 1,
324  'status' => $asset->status,
325  'url' => $asset->getURL(),
326  'web_path' => '',
327  'num_kids' => -1,
328  );
329  }
330  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($asset);
331 
332  $attrs['assetid'] = urlencode($attrs['assetid']);
333  $attrs['name'] = urlencode($attrs['name']);
334  if (isset($attrs['short_name'])) {
335  $attrs['short_name'] = urlencode($attrs['short_name']);
336  }
337 
338  return $attrs;
339 
340  }//end getAssetMapAssetInfo()
341 
342 
356  function getParents($assetid, $type_code='', $strict_type_code=TRUE)
357  {
358  assert_equals($assetid, $this->id, translate('sch_folder_only_own_links'));
359  return Array();
360 
361  }//end getParents()
362 
363 
384  function getChildren($assetid, $type_code='', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
385  {
386  assert_equals($assetid, $this->id, translate('sch_folder_only_own_links'));
387  return Array();
388 
389  }//end getChildren()
390 
391 
402  function getLineageFromURL($assetid, $protocol, $url)
403  {
404  return Array();
405 
406  }//end getLineageFromURL()
407 
408 
428  function countLinks($assetid, $side_of_link='major', $link_types=0, $type_code='', $strict_type_code=TRUE, $ignore_linkid=0)
429  {
430  return 0;
431 
432  }//end countLinks()
433 
434 
444  function deleteAssetLink($linkid, $moving=FALSE)
445  {
446  return FALSE;
447 
448  }//end deleteAssetLink()
449 
450 
451 }//end class
452 ?>