Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Overhaul FedoraObjectDetailedContent and Object helper.

FODC tab now uses theme functions to generate the DC content, datastream info,
and list of parents.  Only thing not really being generated is the tiny
(but repeated) form for downloading.  Also, make the convertQDC XSLT a little
simpler, even though it really won't need to be used anymore...
Refactored to use the new RI search methods as well.
  • Loading branch information...
commit f18ce11ba5076c3338af3b235de217c7a6dbe18f 1 parent 5ae0e46
Adam authored April 20, 2012
65  CollectionClass.inc
@@ -39,6 +39,36 @@ class CollectionClass {
39 39
       $this->pid = $pid;
40 40
     }
41 41
   }
  42
+  
  43
+  static function get_collection_query($pid) {
  44
+    if ($query = self::_get_collection_query_from_stream($pid)) {
  45
+      return $query;
  46
+    }
  47
+    else {
  48
+      return self::_get_default_collection_query($pid);
  49
+    }
  50
+  }
  51
+  
  52
+  static function _get_collection_query_from_stream($pid) {
  53
+    module_load_include('inc', 'fedora_repository', 'api/fedora_item');
  54
+    $item = new Fedora_Item($pid);
  55
+    if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
  56
+      return $item->get_datastream_dissemination('QUERY');
  57
+    }
  58
+    else {
  59
+      return FALSE;
  60
+    }
  61
+  }
  62
+  static function _get_default_collection_query($pid) {
  63
+    return 'select $object $title $content from <#ri>
  64
+             where ($object <fedora-model:label> $title
  65
+             and $object <fedora-model:hasModel> $content
  66
+             and ($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/' . $pid . '>
  67
+             or $object <fedora-rels-ext:isMemberOf> <info:fedora/' . $pid . '>)
  68
+             and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
  69
+             minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
  70
+             order by $title';
  71
+  }
42 72
 
43 73
   /**
44 74
    * gets objects related to this object.  must include offset and limit
@@ -49,15 +79,11 @@ class CollectionClass {
49 79
    * @param type $itqlquery
50 80
    * @return type 
51 81
    */
52  
-  function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) {
  82
+  static function getRelatedObjects($pid, $limit, $offset, $itqlquery=NULL) {
53 83
     if (!isset($itqlquery)) {
54  
-      module_load_include('inc', 'fedora_repository', 'api/fedora_item');
55  
-      $item = new Fedora_Item($pid);
56  
-      if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
57  
-        $itqlquery = $item->get_datastream_dissemination('QUERY');
58  
-      }
  84
+      $itqlquery = self::get_collection_query($pid);
59 85
     }
60  
-    return $this->getRelatedItems($pid, $itqlquery, $limit, $offset);
  86
+    return self::getRelatedItems($pid, $itqlquery, $limit, $offset);
61 87
   }
62 88
 
63 89
   /**
@@ -70,7 +96,7 @@ class CollectionClass {
70 96
    * @param int $offset
71 97
    * @return type 
72 98
    */
73  
-  function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) {
  99
+  static function getRelatedItems($pid, $itqlquery = NULL, $limit = NULL, $offset = NULL) {
74 100
     module_load_include('inc', 'fedora_repository', 'ObjectHelper');
75 101
     module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
76 102
     if (!isset($offset)) {
@@ -84,26 +110,11 @@ class CollectionClass {
84 110
     $objectHelper = new ObjectHelper();
85 111
     $query_string = $itqlquery;
86 112
     if (!isset($query_string)) {
87  
-      $query_string = NULL;
88  
-      $item = new Fedora_Item($pid);
89  
-      if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) {
90  
-        $query_string = $item->get_datastream_dissemination('QUERY');
91  
-      }
92  
-      if ($query_string == NULL) {
93  
-        $query_string = 'select $object $title $content from <#ri>
94  
-                             where ($object <fedora-model:label> $title
95  
-                             and $object <fedora-model:hasModel> $content
96  
-                             and ($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/' . $pid . '>
97  
-                             or $object <fedora-rels-ext:isMemberOf> <info:fedora/' . $pid . '>)
98  
-                             and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
99  
-                             minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
100  
-                             order by $title';
101  
-      }
102  
-    }
103  
-    else {
104  
-      // Replace %parent_collection% with the actual collection PID
105  
-      $query_string = preg_replace("/\%parent_collection\%/", "<info:fedora/$pid>", $query_string);
  113
+      $query_string = self::get_collection_query($pid);
106 114
     }
  115
+    
  116
+    // Replace %parent_collection% with the actual collection PID
  117
+    $query_string = preg_replace("/\%parent_collection\%/", "<info:fedora/$pid>", $query_string);
107 118
 
108 119
     $query_string = htmlentities(urlencode($query_string));
109 120
 
340  ObjectHelper.inc
@@ -313,36 +313,42 @@ class ObjectHelper {
313 313
   function create_link_for_ds($pid, $dataStreamValue) {
314 314
     global $base_url;
315 315
     $path = drupal_get_path('module', 'fedora_repository');
  316
+    module_load_include('inc', 'fedora_repository', 'api/fedora_item');
316 317
 
317  
-    require_once($path . '/api/fedora_item.inc');
318 318
     $item = new Fedora_Item($pid);
319 319
 
  320
+    $purge_image = '&nbsp;';
320 321
     if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
321 322
       $allow = TRUE;
322 323
       if (module_exists('fedora_fesl')) {
323 324
         $allow = fedora_fesl_check_roles($pid, 'write');
324 325
       }
325 326
       if ($allow) {
326  
-        $purgeImage = '<a title="purge datastream ' . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/purgeStream/' .
327  
-            $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path .
328  
-            '/images/purge.gif" alt="purge datastream" /></a>';
  327
+        $purge_text = t("purge datastream @label", array('@label' => $dataStreamValue->label));
  328
+        $purge_path = "fedora/repository/purgeStream/$pid/{$dataStreamValue->ID}/{$dataStreamValue->label}";
  329
+        $purge_image = l(theme('image', "$path/images/purge.gif", $purge_text, $purge_text, NULL, FALSE), $purge_path, array(
  330
+          'html' => TRUE,
  331
+        ));
329 332
       }
330 333
     }
331 334
     else {
332  
-      $purgeImage = '&nbsp;';
  335
+      $purge_image = '&nbsp;';
333 336
     }
334  
-    $fullPath = base_path() . $path;
335 337
 
336 338
     // Add an icon to replace a datastream
337 339
     // @TODO Note: using l(theme_image(..), ...); for these image links (and other links) may remove the need to have clean urls enabled.
338  
-    $replaceImage = '&nbsp;';
  340
+    $replace_image = '&nbsp;';
339 341
     if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
340 342
       $allow = TRUE;
341 343
       if (module_exists('fedora_fesl')) {
342 344
         $allow = fedora_fesl_check_roles($pid, 'write');
343 345
       }
344 346
       if ($allow) {
345  
-        $replaceImage = '<a title="' . t("Replace datastream") . " " . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/replaceStream/' . $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path . '/images/replace.png" alt="replace datastream" /></a>';
  347
+        $replace_text = t('Replace datastream "@label"', array('@label' => $dataStreamValue->label));
  348
+        $replace_path = "fedora/repository/replaceStream/$pid/{$dataStreamValue->ID}/{$dataStreamValue->label}";
  349
+        $replace_image = l(theme('image', "$path/images/replace.png", $replace_text, $replace_text, NULL, FALSE), $replace_path, array(
  350
+          'html' => TRUE,
  351
+        ));
346 352
       }
347 353
     }
348 354
 
@@ -350,13 +356,17 @@ class ObjectHelper {
350 356
     $id = $dataStreamValue->ID;
351 357
     $label = $dataStreamValue->label;
352 358
     $label = str_replace("_", " ", $label);
  359
+    $label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh.
353 360
     $mimeType = $dataStreamValue->MIMEType;
354 361
 
355  
-    $view = '<a href="' . $base_url . '/fedora/repository/' . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode($label) .
356  
-        '" target="_blank" >' . t('View') . '</a>';
357  
-    $action = "$base_url/fedora/repository/object_download/" . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode(preg_replace('/\//i', '${1}_', $label)); // Necessary to handle the case of Datastream labels that contain slashes. Ugh.
  362
+    $view = l(t('View'), "'fedora/repository/$pid/$id/$label_deslashed", array(
  363
+      'attributes' => array(
  364
+        'target' => '_blank',
  365
+      ),
  366
+    ));
  367
+    $action = url("fedora/repository/object_download/$pid/$id/$label_deslashed");
358 368
     $downloadVersion = '<form method="GET" action="' . $action . '"><input type="submit" value="' . t('Download') . '"></form>';
359  
-    if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) {
  369
+    if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) {
360 370
       $versions = $item->get_datastream_history($id);
361 371
       if (is_array($versions)) {
362 372
         $downloadVersion = '<form method="GET" action="' . $action . '" onsubmit="this.action=\'' . $action . '\' + \'/\'+this.version.value;">';
@@ -369,8 +379,23 @@ class ObjectHelper {
369 379
       }
370 380
     }
371 381
 
372  
-    $content .= "<tr><td>$label</td><td>&nbsp;$view</td><td>&nbsp;$downloadVersion</td><td>&nbsp;$mimeType</td><td>&nbsp;$replaceImage&nbsp;$purgeImage</td></tr>\n";
373  
-    return $content;
  382
+    return array(
  383
+      array(
  384
+        'data' => $label,
  385
+      ),
  386
+      array(
  387
+        'data' => $view,
  388
+      ),
  389
+      array(
  390
+        'data' => $downloadVersion,
  391
+      ),
  392
+      array(
  393
+        'data' => $mimeType
  394
+      ),
  395
+      array(
  396
+        'data' => $replace_image . $purge_image,
  397
+      ),
  398
+    );
374 399
   }
375 400
 
376 401
   /**
@@ -386,34 +411,37 @@ class ObjectHelper {
386 411
 
387 412
     $dsid = array_key_exists('QDC', $item->get_datastreams_list_as_array()) ? 'QDC' : 'DC';
388 413
     $xmlstr = $item->get_datastream_dissemination($dsid);
389  
-
390  
-
  414
+    
391 415
     if (empty($xmlstr)) {
392 416
       return '';
393 417
     }
  418
+    
  419
+    $simplexml = new SimpleXMLElement($xmlstr);
394 420
 
395  
-    try {
396  
-      $proc = new XsltProcessor();
397  
-    } catch (Exception $e) {
398  
-      drupal_set_message($e->getMessage(), 'error');
399  
-      return;
  421
+    $headers = array(
  422
+      array(
  423
+        'data' => t('Metadata'),
  424
+        'colspan' => 2,
  425
+      ),
  426
+    );
  427
+    $rows = array();
  428
+    dsm($xmlstr);
  429
+    foreach ($simplexml->getNamespaces(TRUE) as $ns) {
  430
+      foreach ($simplexml->children($ns) as $child) {
  431
+        $rows[] = array(
  432
+          array(
  433
+            'data' => $child->getName(),
  434
+            'class' => 'dc-tag-name',
  435
+          ),
  436
+          array(
  437
+            'data' => (string)$child,
  438
+            'class' => 'dc-content',
  439
+          ),
  440
+        );
  441
+      }
400 442
     }
401 443
 
402  
-    $proc->setParameter('', 'baseUrl', $base_url);
403  
-    $proc->setParameter('', 'path', $base_url . '/' . $path);
404  
-    $input = NULL;
405  
-    $xsl = new DomDocument();
406  
-    try {
407  
-      $xsl->load($path . '/xsl/convertQDC.xsl');
408  
-      $input = new DomDocument();
409  
-      $input->loadXML(trim($xmlstr));
410  
-    } catch (Exception $e) {
411  
-      watchdog('fedora_repository', "Problem loading XSL file: @e", array('@e' => $e->getMessage()), NULL, WATCHDOG_ERROR);
412  
-    }
413  
-    $xsl = $proc->importStylesheet($xsl);
414  
-    $newdom = $proc->transformToDoc($input);
415  
-    $output = $newdom->saveHTML();
416  
-    return $output;
  444
+    return theme('table', $headers, $rows, array('class' => 'dc-table'));
417 445
   }
418 446
 
419 447
   /**
@@ -432,16 +460,17 @@ class ObjectHelper {
432 460
     $dsid = array_key_exists('QDC', $ds_list) ? 'QDC' : 'DC';
433 461
     $path = drupal_get_path('module', 'fedora_repository');
434 462
 
435  
-    //$baseUrl=substr($baseUrl, 0, (strpos($baseUrl, "/")-1));
436 463
     if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) {
437 464
       $allow = TRUE;
438 465
       if (module_exists('fedora_fesl')) {
439 466
         $allow = fedora_fesl_check_roles($pid, 'write');
440 467
       }
441 468
       if ($allow) {
442  
-
443  
-        $output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' .
444  
-            $dsid . '"><img src="' . $base_url . '/' . $path . '/images/edit.gif" alt="' . t('Edit Meta Data') . '" /></a>';
  469
+        $link_image = theme('image', "$path/images/edit.gif", t('Edit Metadata'));
  470
+        $link = l($link_image, "fedora/repository/editmetadata/$pid", array(
  471
+          'html' => TRUE,
  472
+        ));
  473
+        $output .= '<br />' . $link;
445 474
       }
446 475
     }
447 476
     return $output;
@@ -461,7 +490,7 @@ class ObjectHelper {
461 490
    *
462 491
    */
463 492
   function get_formatted_datastream_list($object_pid, $contentModels, &$fedoraItem) {
464  
-    global $fedoraUser, $fedoraPass, $base_url, $user;
  493
+    global $base_url, $user;
465 494
     module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
466 495
     module_load_include('inc', 'fedora_repository', 'ObjectHelper');
467 496
     module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@@ -473,58 +502,42 @@ class ObjectHelper {
473 502
 
474 503
     if (user_access(ObjectHelper :: $VIEW_DETAILED_CONTENT_LIST)) {
475 504
       $availableDataStreamsText = 'Detailed List of Content';
476  
-      //$metaDataText='Description';
  505
+
477 506
       $mainStreamLabel = NULL;
478 507
       $object = $fedoraItem->get_datastreams_list_as_SimpleXML();
479 508
       if (!isset($object)) {
480 509
         drupal_set_message(t("No datastreams available"));
481 510
         return ' ';
482 511
       }
483  
-      $hasOBJStream = NULL;
484  
-      $hasTNStream = FALSE;
485  
-      $dataStreamBody = "<br /><table>\n";
486 512
 
487 513
       $cmDatastreams = array();
488 514
       if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE && ($cm = ContentModel::loadFromObject($object_pid)) !== FALSE) {
489 515
         $cmDatastreams = $cm->listDatastreams();
490 516
       }
491 517
 
492  
-      $dataStreamBody .= $this->get_parent_objects_asHTML($object_pid);
493  
-      $dataStreamBody .= '<tr><th colspan="4"><h3>' . t("!text", array('!text' => $availableDataStreamsText)) . '</h3></th></tr>';
  518
+      $headers = array(
  519
+        array(
  520
+          'data' => $availableDataStreamsText,
  521
+          'colspan' => 4,
  522
+        ),
  523
+      );
  524
+      $DSs = array();
494 525
       foreach ($object as $datastream) {
495 526
         foreach ($datastream as $datastreamValue) {
496  
-          if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) {
497  
-            if ($datastreamValue->ID == 'OBJ') {
498  
-              $hasOBJStream = '1';
499  
-              $mainStreamLabel = $datastreamValue->label;
500  
-              $mainStreamLabel = str_replace("_", " ", $mainStreamLabel);
501  
-            }
502  
-            if ($datastreamValue->ID == 'TN') {
503  
-              $hasTNStream = TRUE;
504  
-            }
  527
+          if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) {  
505 528
             //create the links to each datastream
506  
-            $dataStreamBody .= $this->create_link_for_ds($object_pid, $datastreamValue); //"<tr><td><b>$key :</b></td><td>$value</td></tr>\n";
  529
+            $DSs []= $this->create_link_for_ds($object_pid, $datastreamValue);
507 530
           }
508 531
         }
509 532
       }
510  
-      $dataStreamBody .= "</table>\n";
  533
+      
  534
+      $dataStreamBody = theme('table', $headers, $DSs);
511 535
       //if they have access let them add a datastream
512  
-      if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
513  
-        $allow = TRUE;
514  
-        if (module_exists('fedora_fesl')) {
515  
-          $allow = fedora_fesl_check_roles($object_pid, 'write');
516  
-        }
517  
-        if ($allow) {
518  
-          $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
519  
-        }
  536
+      if (user_access(ObjectHelper::$ADD_FEDORA_STREAMS) && //If allowed throw Drupal
  537
+        ((module_exists('fedora_fesl') && fedora_fesl_check_roles($object_pid, 'write')) || //And allowed throw FESL 
  538
+        !module_exists('fedora_fesl'))) { //Or not using FESL, draw the add datastream form.
  539
+        $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
520 540
       }
521  
-      $fieldset = array(
522  
-        '#title' => t("!text", array('!text' => $availableDataStreamsText)),
523  
-        '#collapsible' => TRUE,
524  
-        '#collapsed' => TRUE,
525  
-        '#value' => $dataStreamBody
526  
-      );
527  
-      $dataStreamBody = '<div class = "fedora_detailed_list">' . theme('fieldset', $fieldset) . '</div>';
528 541
 
529 542
       return $dataStreamBody;
530 543
     }
@@ -616,55 +629,44 @@ class ObjectHelper {
616 629
    * @param type $pid
617 630
    * @return type 
618 631
    */
619  
-  function fedora_repository_access($op, $pid) {
620  
-    global $user;
621  
-
  632
+  function fedora_repository_access($op, $pid = NULL, $as_user = NULL) {
622 633
     $returnValue = FALSE;
623  
-    $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
624  
-    if (!$isRestricted) {
625  
-      $namespaceAccess = TRUE;
626  
-    }
  634
+    
627 635
     if ($pid == NULL) {
628 636
       $pid = variable_get('fedora_repository_pid', 'islandora:root');
629 637
     }
630  
-    $nameSpaceAllowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
631  
-    $pos = NULL;
632  
-    foreach ($nameSpaceAllowed as $nameSpace) {
633  
-      $pos = stripos($pid, $nameSpace);
634  
-      if ($pos === 0) {
635  
-        $namespaceAccess = TRUE;
636  
-      }
637  
-    }
638  
-    if ($namespaceAccess) {
639  
-      $user_access = user_access($op);
640  
-      if ($user_access == NULL) {
641  
-        return FALSE;
642  
-      }
643  
-      return $user_access;
  638
+
  639
+    $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
  640
+    $namespace_access = NULL;
  641
+    if (!$isRestricted) {
  642
+      $namespace_access = TRUE;
644 643
     }
645  
-    else {
646  
-      return FALSE;
  644
+    else {    
  645
+      $pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); //Get the namespace (with colon)
  646
+      $allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
  647
+
  648
+      $namespace_access = in_array($pid_namespace, $allowed_namespaces);
647 649
     }
  650
+    
  651
+    return ($namespace_access && user_access($op, $as_user));
648 652
   }
649 653
 
650 654
   /**
651 655
    * internal function
652 656
    * uses an xsl to parse the sparql xml returned from the ITQL query
653  
-   *
654  
-   *
  657
+   * @deprecated
  658
+   *   This is only used in the fedora/repository/collection path, 
  659
+   *   which should probably be nuked.
655 660
    * @param $content String
656 661
    */
657 662
   function parseContent($content, $pid, $dsId, $collection, $pageNumber = NULL) {
658 663
     $path = drupal_get_path('module', 'fedora_repository');
659 664
     global $base_url;
660 665
     $collection_pid = $pid; //we will be changing the pid later maybe
661  
-    //module_load_include('php', ''Fedora_Repository'', 'ObjectHelper');
662 666
     $objectHelper = $this;
663 667
     $parsedContent = NULL;
664  
-    $contentModels = $objectHelper->get_content_models_list($pid);
  668
+    $contentModels = $this->get_content_models_list($pid);
665 669
     $isCollection = FALSE;
666  
-    //if this is a collection object store the $pid in the session as it will come in handy
667  
-    //after a purge or ingest to return to the correct collection.
668 670
 
669 671
     $fedoraItem = NULL;
670 672
     $datastreams = $this->get_formatted_datastream_list($pid, $contentModels, $fedoraItem);
@@ -672,6 +674,9 @@ class ObjectHelper {
672 674
     if (!empty($contentModels)) {
673 675
       foreach ($contentModels as $contentModel) {
674 676
         if ($contentModel == variable_get('fedora_collection_model_pid', 'islandora:collectionCModel')) {
  677
+          //if this is a collection object store the $pid in the session as it will come in handy
  678
+          //after a purge or ingest to return to the correct collection.
  679
+
675 680
           $_SESSION['fedora_collection'] = $pid;
676 681
           $isCollection = TRUE;
677 682
         }
@@ -689,8 +694,8 @@ class ObjectHelper {
689 694
     if ($results->length > 0 || $isCollection == TRUE) {
690 695
       //  if(strlen($objectList)>22||$contentModel=='Collection'||$contentModel=='Community')//length of empty dom still equals 22 because of <table/> etc
691 696
       module_load_include('inc', 'Fedora_Repository', 'CollectionPolicy');
692  
-      $collectionPolicyExists = $objectHelper->getMimeType($pid, CollectionPolicy::getDefaultDSID());
693  
-      if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
  697
+      $collectionPolicyExists = $this->getMimeType($pid, CollectionPolicy::getDefaultDSID());
  698
+      if (user_access(ObjectHelper::$INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
694 699
         if (!empty($collectionPolicyExists)) {
695 700
           $allow = TRUE;
696 701
           if (module_exists('fedora_fesl')) {
@@ -746,18 +751,33 @@ class ObjectHelper {
746 751
   }
747 752
 
748 753
   /**
  754
+   * Get the query to find parent objects.
  755
+   *
  756
+   * @param $pid string
  757
+   *   A string containing a Fedora PID to find the parents for.
  758
+   * @return string
  759
+   *   A string containing an iTQL query, selecting something into $object and $title 
  760
+   */
  761
+  static function _parent_query($pid) {
  762
+    return 'select $object $title from <#ri>
  763
+            where ($object <fedora-model:label> $title
  764
+              and <info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOfCollection> $object
  765
+              and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
  766
+            order by $title';
  767
+  }
  768
+  
  769
+  /**
749 770
    * Gets the parent objects that this object is related to
750 771
    *
751  
-   * @param unknown_type $pid
752  
-   * @return unknown
  772
+   * @param $pid string
  773
+   *   A string containing a Fedora PID to find the parents for.
  774
+   * @return string
  775
+   *   A string containing Sparql XML (the results of the self::_parent_query())
753 776
    */
754 777
   function get_parent_objects($pid) {
755  
-    $query_string = 'select $object $title from <#ri>
756  
-                            where ($object <fedora-model:label> $title
757  
-                              and <info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOfCollection> $object
758  
-                              and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
759  
-                            order by $title';
760  
-    $objects = $this->getCollectionInfo($pid, $query_string);
  778
+    $query_string = self::_parent_query();
  779
+    module_load_include('inc', 'fedora_repository', 'CollectionClass');
  780
+    $objects = CollectionClass::getRelatedItems($pid, $query_string);
761 781
     return $objects;
762 782
   }
763 783
 
@@ -768,31 +788,24 @@ class ObjectHelper {
768 788
    * @return string 
769 789
    */
770 790
   function get_parent_objects_asHTML($pid) {
771  
-    global $base_url;
772  
-    $parent_collections = $this->get_parent_objects($pid);
773  
-    try {
774  
-      $parent_collections = new SimpleXMLElement($parent_collections);
775  
-    } catch (exception $e) {
776  
-      drupal_set_message(t('Error getting parent objects @e', array('@e' => check_plain($e->getMessage()))));
777  
-      return;
778  
-    }
779  
-
780  
-    $parent_collections_HTML = '';
781  
-    foreach ($parent_collections->results->result as $result) {
782  
-      $collection_label = $result->title;
783  
-      foreach ($result->object->attributes() as $a => $b) {
784  
-        if ($a == 'uri') {
785  
-          $uri = (string) $b;
786  
-          $uri = $base_url . '/fedora/repository' . substr($uri, strpos($uri, '/')) . '/-/' . $collection_label;
787  
-        }
788  
-      }
789  
-      $parent_collections_HTML .= '<a href="' . $uri . '">' . $collection_label . '</a><br />';
  791
+    module_load_include('inc', 'fedora_repository', 'CollectionClass');
  792
+    $results = self::perform_itql_query(self::_parent_query($pid));
  793
+
  794
+    $parent_collections = array();
  795
+    foreach ($results as $result) {
  796
+      $collection_title = $result['title'];
  797
+      $collection_pid = $result['object'];
  798
+      $path = "fedora/repository/$collection_pid/-/$collection_title";
  799
+      $parent = array(
  800
+        'data' => l($collection_title, $path),
  801
+      );
  802
+      
  803
+      $parent_collections[] = $parent;
790 804
     }
791  
-    if (!empty($parent_collections_HTML)) {
792  
-      $parent_collections_HTML = '<tr><td><h3>' . t("Belongs to these collections:") . ' </h3></td><td colspan="4">' . $parent_collections_HTML . '</td></tr>';
  805
+    
  806
+    if (!empty($parent_collections)) {
  807
+      return theme('item_list', $parent_collections, t('Belongs to these collections'), 'ul');
793 808
     }
794  
-
795  
-    return $parent_collections_HTML;
796 809
   }
797 810
 
798 811
   /**
@@ -842,6 +855,8 @@ class ObjectHelper {
842 855
   /**
843 856
    * Get a tree of related pids - for the basket functionality
844 857
    *
  858
+   * FIXME:  This doesn't actually get a tree...
  859
+   *
845 860
    * @param type $pid
846 861
    * @return type 
847 862
    */
@@ -852,19 +867,18 @@ class ObjectHelper {
852 867
     module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
853 868
 
854 869
     // Get title and descriptions for $pid 
855  
-    $query_string = 'select $title $desc from <#ri> 
  870
+    $query_string = 'select $title $description from <#ri> 
856 871
       where $o <fedora-model:label> $title
857 872
       and $o <dc:description> $desc
858 873
       and $o <mulgara:is> <info:fedora/' . $pid . '>';
859  
-
860  
-    $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
861  
-    $url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query=";
862  
-    $content = do_curl($url . htmlentities(urlencode($query_string)));
863  
-
864  
-    $rows = explode("\n", $content);
865  
-    $fields = explode(',', $rows[1]);
866  
-
867  
-    $pids[$pid] = array('title' => $fields[0], 'description' => $fields[1]);
  874
+    
  875
+    $results = self::perform_itql_query($query_string);
  876
+    
  877
+    $pids = array();
  878
+    //There should only be one...  Anyway.
  879
+    foreach($results as $result) {
  880
+      $pids[$pid] = $result;
  881
+    }
868 882
 
869 883
 //    $pids += $this->get_child_pids(array($pid));
870 884
 
@@ -878,38 +892,24 @@ class ObjectHelper {
878 892
    * @return type 
879 893
    */
880 894
   function get_child_pids($pids) {
  895
+    //Build the parts which are used to filter to the list of input.
  896
+    $query_chunks = array();
  897
+    foreach ($pids as $pid) {
  898
+      $query_chunks[] = '$s <mulgara:is> <info:fedora/' . $pid . '>';
  899
+    }
881 900
     // Get pid, title and description for children of object $pid
882 901
     $query_string = 'select $o $title from <#ri> ' .
883  
-//    $query_string = 'select $o $title $desc from <#ri> '.
884 902
         'where $s <info:fedora/fedora-system:def/relations-external#hasMember> $o ' .
885 903
         'and $o <fedora-model:label> $title ' .
886  
-//    'and $o <dc:description> $desc '.
887  
-        'and ( ';
888  
-
889  
-    foreach ($pids as $pid) {
890  
-      $query_string .= '$s <mulgara:is> <info:fedora/' . $pid . '> or ';
891  
-    }
892  
-    $query_string = substr($query_string, 0, -3) . ' )';
893  
-
894  
-    $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
895  
-    $url .= "?type=tuples&flush=TRUE&format=csv&limit=1000&lang=itql&stream=on&query=";
896  
-    $url .= htmlentities(urlencode($query_string));
897  
-    $content = $this->doCurl($url);
898  
-
899  
-    $rows = explode("\n", $content);
900  
-    // Knock of the first heading row
901  
-    array_shift($rows);
  904
+        'and ( ' . implode(' or ', $query_chunks) . ' )';
  905
+    
  906
+    $results = self::perform_itql_query($query_string);
902 907
 
903 908
     $child_pids = array();
904  
-    if (count($rows)) {
  909
+    if ($results) {
905 910
       // iterate through each row
906  
-      foreach ($rows as $row) {
907  
-        if ($row == "") {
908  
-          continue;
909  
-        }
910  
-        $fields = explode(',', $row);
911  
-        $child_pid = substr($fields[0], 12);
912  
-        $child_pids[$child_pid] = array('title' => $fields[1], 'description' => $fields[2]);
  911
+      foreach ($results as $result) {
  912
+        $child_pids[$result['o']] = array('title' => $result['title']);
913 913
       }
914 914
       if (!empty($child_pids)) {
915 915
         $child_pids += $this->get_child_pids(array_keys($child_pids));
2  fedora_repository.module
@@ -869,7 +869,7 @@ function fedora_repository_perm() {
869 869
  * @param type $account
870 870
  * @return type 
871 871
  */
872  
-function fedora_repository_access($op, $node, $account) {
  872
+function fedora_repository_access($op, $node = NULL, $account = NULL) {
873 873
   module_load_include('inc', 'fedora_repository', 'ObjectHelper');
874 874
   $objectHelper = new ObjectHelper();
875 875
   return $objectHelper->fedora_repository_access($op, $node, $account);
5  formClass.inc
@@ -13,8 +13,8 @@
13 13
 class formClass {
14 14
 
15 15
   function formClass() {
16  
-    module_load_include('inc', 'formClass', '');
17 16
     drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  17
+    module_load_include('inc', 'fedora_repository', 'ObjectHelper');
18 18
   }
19 19
 
20 20
   /**
@@ -128,7 +128,8 @@ class formClass {
128 128
       'title' => t('Collection view'),
129 129
       'page callback' => 'fedora_collection_view',
130 130
       'type' => MENU_CALLBACK,
131  
-      'access argruments' => array('view fedora collection')
  131
+      'access callback' => 'fedora_repository_access',
  132
+      'access argruments' => array(OBJECTHELPER::$OBJECT_HELPER_VIEW_FEDORA),
132 133
     );
133 134
     
134 135
     //new for mnpl******************************************
24  plugins/FedoraObjectDetailedContent.inc
@@ -48,10 +48,9 @@ class FedoraObjectDetailedContent {
48 48
     $tabset['fedora_object_details']['tabset'] = array(
49 49
       '#type' => 'tabset',
50 50
     );
  51
+    
51 52
     $dc_html = $objectHelper->getFormattedDC($this->item);
52 53
 
53  
-    $ds_list = $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item);
54  
-
55 54
     $i = 0;
56 55
     if (fedora_repository_access(OBJECTHELPER :: $VIEW_DETAILED_CONTENT_LIST, $this->pid, $user)) {
57 56
       $tabset['fedora_object_details']['tabset']['view'] = array(
@@ -63,9 +62,24 @@ class FedoraObjectDetailedContent {
63 62
           '#weight' => $i++
64 63
         ),
65 64
         'list' => array(
66  
-          '#type' => 'markup',
67  
-          '#value' => $ds_list, //XXX:  The function called here could be cleaned up a fair bit as well...
68  
-          '#weight' => $i++
  65
+          '#type' => 'fieldset',
  66
+          '#title' => t('Detailed List of Content'),
  67
+          '#attributes' => array(
  68
+            'class' => 'fedora_detailed_list',
  69
+          ),
  70
+          '#collapsible' => TRUE,
  71
+          '#collapsed' => TRUE,
  72
+          '#weight' => $i++,
  73
+          'parents' => array(
  74
+            '#type' => 'markup',
  75
+            '#value' => $objectHelper->get_parent_objects_asHTML($this->pid),
  76
+            '#weight' => $i++,
  77
+          ),
  78
+          'datastreams' => array(
  79
+            '#type' => 'markup',
  80
+            '#value' => $objectHelper->get_formatted_datastream_list($this->pid, NULL, $this->item), //XXX:  The function called here could be cleaned up a fair bit as well...
  81
+            '#weight' => $i++,
  82
+          ),
69 83
         ),
70 84
         'purge' => array(
71 85
           '#type' => 'markup',
6  xsl/convertQDC.xsl
@@ -12,13 +12,13 @@
12 12
 <tr><th colspan="3"><h3>MetaData</h3></th></tr>
13 13
 <xsl:for-each select="/*/*">
14 14
 	<xsl:variable name="FULLFIELD" select="name()"/>
15  
-	<xsl:variable name="FIELD" select="substring-after(name(),':')"/>
  15
+	<xsl:variable name="FIELD" select="local-name()"/>
16 16
 	<xsl:variable name="DATA" select="text()"/>
17 17
 	<xsl:if test="$DATA != ' '">
18  
-	<tr><td><strong><xsl:value-of select="substring-after(name(),':')"/></strong></td><td><xsl:value-of select="text()"/>
  18
+	<tr><td><strong><xsl:value-of select="local-name()"/></strong></td><td><xsl:value-of select="text()"/>
19 19
 		<xsl:for-each select="*">
20 20
 		<div>
21  
-		<xsl:value-of select="substring-after(name(),':')"/> =  <xsl:value-of select="text()"/>
  21
+		<xsl:value-of select="local-name()"/> =  <xsl:value-of select="text()"/>
22 22
 		</div>
23 23
 		</xsl:for-each>
24 24
 	</td></tr>

0 notes on commit f18ce11

Please sign in to comment.
Something went wrong with that request. Please try again.