function readable($text, $altered = false, $class = false, $to_class = false)
{
    $relationshipText = $text;
    $defaultText = sentenceCase($text);
    $text = trim(strtolower($text));
    if (gettype($altered) == 'string') {
        return format_relationship($class, $relationshipText, $altered, $to_class);
    }
    switch ($text) {
        case "all":
            return 'All';
            break;
        case "draft":
            return $altered ? 'Draft' : 'Drafts';
            break;
        case "submitted_for_assessment":
            return 'Submitted for Assessment';
            break;
        case "assessment_in_progress":
            return 'Assessment In Progress';
            break;
        case "approved":
            return $altered ? 'Approved' : 'Approved Records';
            break;
        case "published":
            return $altered ? 'Published' : 'Published Records';
            break;
        case "more_work_required":
            return 'More Work Required';
            break;
        case "collection":
            return 'Collections';
            break;
        case "party":
            return 'Parties';
            break;
        case "service":
            return 'Services';
            break;
        case "activity":
            return 'Activities';
            break;
        case "role_user":
            return 'User';
            break;
        case "role_organisational":
            return 'Organisation';
            break;
        case "role_functional":
            return 'Functional';
            break;
        case "role_doi_appid":
            return 'DOI Application Identifier';
            break;
        case "t":
            return "<i class='icon icon-ok'></i>";
            break;
        case "f":
            return "<i class='icon icon-remove'></i>";
            break;
        case "1":
            return "<i class='icon icon-ok'></i>";
            break;
        case "0":
            return "<i class='icon icon-remove'></i>";
            break;
        case "authentication_built_in":
            return "Built-in";
            break;
        case "authentication_ldap":
            return "LDAP";
            break;
        case "authentication_shibboleth":
            return "Shibboleth";
            break;
        case "pmhharvester":
            return "OAI-PMH Harvester";
            break;
        case "getharvester":
            return "GET Harvester";
            break;
        case "cswharvester":
            return "CSW Harvester";
            break;
        case "ckanharvester":
            return "CKAN Harvester";
            break;
        case 'licence':
            return 'Licence';
            break;
        case 'rights':
            return 'Rights';
            break;
        case 'accessrights':
            return 'Access rights';
            break;
        case 'rightsstatement':
            return 'Rights Statement';
            break;
        case 'full':
            return 'Full description';
            break;
        case 'brief':
            return 'Brief description';
            break;
        case 'note':
            return 'Notes';
            break;
        case 'lineage':
            return 'Lineage';
            break;
        case 'addsvalueto':
            return 'Adds value to';
            break;
        case 'describes':
            return 'Describes';
            break;
        case 'enriches':
            return 'Enriches';
            break;
        case 'fundingamount':
            return 'Funding Amount';
            break;
        case 'deliverymethod':
            return 'Delivery method';
            break;
        case 'researchers':
            return 'Researchers';
            break;
        case 'fundingscheme':
            return 'Funding Scheme';
            break;
        case 'leadinvestigator':
            return 'Lead investigator';
            break;
        case 'principalinvestigator':
            return 'Principal investigator';
            break;
        case 'coinvestigator':
            return 'Co investigator';
            break;
        default:
            return $defaultText;
    }
}
 function addRelationships()
 {
     $this->_CI->load->model('registry/data_source/data_sources', 'ds');
     $this->_CI->load->model('registry/registry_object/registry_objects', 'ro');
     $ds = $this->_CI->ds->getByID($this->ro->data_source_id);
     $sxml = $this->ro->getSimpleXml();
     /* Explicit relationships */
     $sxml->registerXPathNamespace("ro", RIFCS_NAMESPACE);
     $explicit_keys = array();
     // related objects (from past)
     $existing_relatinships = $this->getExistingRelationships();
     $new_relationships = array();
     foreach ($sxml->xpath('//ro:relatedObject') as $related_object) {
         $explicit_keys[] = (string) $related_object->key;
         $class = $this->getRelatedObjectClass((string) $related_object->key);
         foreach ($related_object->relation as $arelation) {
             $relationship = array("registry_object_id" => (string) $this->ro->id, "related_object_key" => (string) $related_object->key, "related_object_class" => (string) $class, "relation_type" => (string) $arelation['type'], "relation_description" => (string) $arelation->description, "relation_url" => (string) $arelation->url, "origin" => 'EXPLICIT');
             $new_relationships[] = json_encode($relationship);
         }
     }
     if ($ds->create_primary_relationships == DB_TRUE) {
         if ($ds->primary_key_1 && $ds->primary_key_1 != $this->ro->key && !in_array($ds->primary_key_1, $explicit_keys)) {
             $explicit_keys[] = (string) $ds->primary_key_1;
             $relatedClass = (string) $this->getRelatedObjectClass((string) $ds->primary_key_1);
             $this_relationship = format_relationship($this->ro->class, $ds->{strtolower($this->ro->class) . "_rel_1"}, PRIMARY_RELATIONSHIP, $relatedClass);
             $relationship = array("registry_object_id" => (string) $this->ro->id, "related_object_key" => (string) $ds->primary_key_1, "related_object_class" => (string) $this->getRelatedObjectClass((string) $ds->primary_key_1), "relation_type" => (string) $this_relationship, "relation_description" => "", "relation_url" => "", "origin" => PRIMARY_RELATIONSHIP);
             $new_relationships[] = json_encode($relationship);
         }
         if ($ds->primary_key_2 && $ds->primary_key_2 != $this->ro->key && !in_array($ds->primary_key_2, $explicit_keys)) {
             $explicit_keys[] = (string) $ds->primary_key_2;
             $relatedClass = (string) $this->getRelatedObjectClass((string) $ds->primary_key_2);
             $this_relationship = format_relationship($this->ro->class, $ds->{strtolower($this->ro->class) . "_rel_2"}, PRIMARY_RELATIONSHIP, $relatedClass);
             $relationship = array("registry_object_id" => $this->ro->id, "related_object_key" => (string) $ds->primary_key_2, "related_object_class" => (string) $this->getRelatedObjectClass((string) $ds->primary_key_2), "relation_type" => (string) $this_relationship, "relation_description" => "", "relation_url" => "", "origin" => PRIMARY_RELATIONSHIP);
             $new_relationships[] = json_encode($relationship);
         }
         if ($ds->primary_key_1 && $ds->primary_key_1 == $this->ro->key && !in_array($ds->primary_key_1, $explicit_keys)) {
             $explicit_keys[] = (string) $ds->primary_key_1;
             $all = $this->_CI->ro->getIDsByDataSourceID($ds->id, true);
             foreach ($all as $r) {
                 if ($r->key != $this->ro->key) {
                     $this_relationship = $ds->{strtolower($this->ro->class) . "_rel_1"};
                     $relationship = array("registry_object_id" => $this->ro->id, "related_object_key" => (string) $r->key, "related_object_class" => (string) $r->class, "relation_type" => (string) $this_relationship, "relation_description" => "", "relation_url" => "", "origin" => PRIMARY_RELATIONSHIP);
                     $new_relationships[] = json_encode($relationship);
                 }
             }
         }
         if ($ds->primary_key_2 && $ds->primary_key_2 == $this->ro->key && !in_array($ds->primary_key_2, $explicit_keys)) {
             $explicit_keys[] = (string) $ds->primary_key_2;
             $all = $this->_CI->ro->getIDsByDataSourceID($ds->id, true);
             foreach ($all as $r) {
                 if ($r->key != $this->ro->key) {
                     $this_relationship = $ds->{strtolower($this->ro->class) . "_rel_2"};
                     $relationship = array("registry_object_id" => $this->ro->id, "related_object_key" => (string) $r->key, "related_object_class" => (string) $r->class, "relation_type" => (string) $this_relationship, "relation_description" => "", "relation_url" => "", "origin" => PRIMARY_RELATIONSHIP);
                     $new_relationships[] = json_encode($relationship);
                 }
             }
         }
     }
     $processedTypesArray = array('collection', 'party', 'service', 'activity');
     $this->db->where(array('registry_object_id' => $this->ro->id));
     $this->db->delete('registry_object_identifier_relationships');
     foreach ($sxml->xpath('//ro:relatedInfo') as $related_info) {
         $related_info_type = (string) $related_info['type'];
         if (in_array($related_info_type, $processedTypesArray)) {
             $related_info_title = (string) $related_info->title;
             $relation_type = "";
             $related_description = "";
             $related_url = "";
             $relation_type_disp = "";
             $connections_preview_div = "";
             if ($related_info->relation) {
                 foreach ($related_info->relation as $r) {
                     $relation_type .= (string) $r['type'] . ", ";
                     $relation_type_disp .= format_relationship($this->ro->class, (string) $r['type'], 'IDENTIFIER', $related_info_type) . ", ";
                     $relateddescription = (string) $r->description . "<br/>";
                     if ($related_url == '' && (string) $r->url != '') {
                         $related_url = (string) $r->url;
                     }
                     $urlStr = trim((string) $r->url);
                     if ((string) $r->description != '' && (string) $r->url != '') {
                         $connections_preview_div .= "<div class='description'><p>" . (string) $r->description . '<br/><a href="' . $urlStr . '">' . (string) $r->url . "</a></p></div>";
                     }
                 }
                 $relation_type = substr($relation_type, 0, strlen($relation_type) - 2);
                 $relation_type_disp = substr($relation_type_disp, 0, strlen($relation_type_disp) - 2);
                 //$connections_preview_div .= '<p>('.$relation_type.')</p>';
             }
             $identifiers_div = "";
             $identifier_count = 0;
             foreach ($related_info->identifier as $i) {
                 $identifiers_div .= $this->getResolvedLinkForIdentifier((string) $i['type'], trim((string) $i));
                 $identifier_count++;
             }
             $identifiers_div = "<h5>Identifier" . ($identifier_count > 1 ? 's' : '') . ": </h5>" . $identifiers_div;
             if ($related_info->notes) {
                 $connections_preview_div .= '<p>Notes: ' . (string) $related_info->notes . '</p>';
             }
             $imgUrl = asset_url('img/' . $related_info_type . '.png', 'base');
             $classImg = '<img class="icon-heading" src="' . $imgUrl . '" alt="' . $related_info_type . '" style="width:24px; float:right;">';
             $connections_preview_div = '<div class="previewItemHeader">' . $relation_type_disp . '</div>' . $classImg . '<h4>' . $related_info_title . '</h4><div class="post">' . $identifiers_div . "<br/>" . $connections_preview_div . '</div>';
             foreach ($related_info->identifier as $i) {
                 if (trim((string) $i) != '') {
                     $this->db->insert('registry_object_identifier_relationships', array("registry_object_id" => $this->ro->id, "related_object_identifier" => trim((string) $i), "related_info_type" => $related_info_type, "related_object_identifier_type" => (string) $i['type'], "relation_type" => $relation_type, "related_title" => $related_info_title, "related_description" => $related_description, "related_url" => $related_url, "connections_preview_div" => $connections_preview_div));
                 }
             }
         }
     }
     $unchanged_relationships = array_intersect($existing_relatinships, $new_relationships);
     // leave them
     $removed_relationships = array_diff($existing_relatinships, $new_relationships);
     $new_or_changed_relationships = array_diff($new_relationships, $existing_relatinships);
     //
     $inserted_keys = $this->insertNewRelationships($new_or_changed_relationships);
     $deleted_keys = $this->removeNonRenewedRelationships($removed_relationships);
     if (is_array($inserted_keys) && is_array($deleted_keys)) {
         return array_merge($inserted_keys, $deleted_keys);
     } elseif (is_array($deleted_keys)) {
         return $deleted_keys;
     } elseif (is_array($inserted_keys)) {
         return $inserted_keys;
     } else {
         return array();
     }
 }
Beispiel #3
0
 private function getAuthors($authorList)
 {
     $seq = 0;
     $tempered = false;
     if (isset($this->xml->{$this->ro->class}->citationInfo->citationMetadata->contributor)) {
         foreach ($this->xml->{$this->ro->class}->citationInfo->citationMetadata->contributor as $contributor) {
             $nameParts = array();
             foreach ($contributor->namePart as $namePart) {
                 $nameParts[] = array('namePart_type' => (string) $namePart['type'], 'name' => (string) $namePart);
             }
             $eAuthor = $authorList->addChild("Author");
             $cSeq = intval((string) $contributor['seq']);
             if ($cSeq == 0 || $cSeq == '') {
                 $cSeq = ++$seq;
                 $tempered = true;
                 // was dirty so we're fixin it
             } elseif ($cSeq <= $seq && $tempered == true) {
                 $cSeq = ++$seq;
             }
             if ($cSeq > $seq) {
                 $seq = $cSeq;
                 //store the largest current sequence number
             }
             $eAuthor['seq'] = $cSeq;
             $eAuthor['AuthorRole'] = "Contributor";
             $eAuthor->addChild('AuthorName', formatName($nameParts));
         }
     } else {
         $forDCI = true;
         $relationshipTypeArray = array('hasAssociationWith', 'hasPrincipalInvestigator', 'principalInvestigator', 'author', 'coInvestigator', 'isOwnedBy', 'hasCollector');
         $classArray = array('party');
         $authors = $this->ro->getRelatedObjectsByClassAndRelationshipType($classArray, $relationshipTypeArray, $forDCI);
         if ($authors) {
             $seq = 1;
             foreach ($authors as $author) {
                 $eAuthor = $authorList->addChild("Author");
                 $eAuthor['seq'] = $seq++;
                 //return format_relationship($class, $relationshipText, $altered,$to_class);
                 $eAuthor['AuthorRole'] = format_relationship("collection", (string) $author["relation_type"], (string) $author['origin'], 'party');
                 $eAuthor->addChild('AuthorName', $author['title']);
                 if (isset($author['addresses'])) {
                     $authorAddress = $eAuthor->addChild('AuthorAddress');
                     foreach ($author['addresses'] as $addr) {
                         $authorAddress->addChild('AddressString', (string) $addr);
                         break;
                     }
                 }
                 if (isset($author['electronic_addresses'])) {
                     foreach ($author['electronic_addresses'] as $addr) {
                         $eAuthor->addChild('AuthorEmail', (string) $addr);
                         break;
                     }
                 }
                 if (isset($author['identifiers']) && sizeof($author['identifiers'] > 0)) {
                     foreach ($author['identifiers'] as $id) {
                         $authorId = $eAuthor->addChild('AuthorID', trim($id[0]));
                         $authorId['type'] = $id[1];
                     }
                 }
             }
         } else {
             $eAuthor = $authorList->addChild("Author");
             $eAuthor['seq'] = '1';
             $eAuthor->addChild('AuthorName', $this->ro->group);
         }
     }
 }
 public function getConnections($ro_id, $limit = null)
 {
     $connections = array();
     $status = array();
     if ($limit && (int) $limit > 0) {
         $party_conn_limit = $limit;
     } else {
         $party_conn_limit = 20;
     }
     $this->load->model('registry_object/registry_objects', 'ro');
     $ro = $this->ro->getByID($ro_id);
     if ($ro) {
         //$connections = $ro->getConnections();
         if ($ro->class == 'party') {
             $connections = $ro->getAllRelatedObjects(true, false, false, $party_conn_limit);
         } else {
             $connections = $ro->getAllRelatedObjects(true);
         }
         foreach ($connections as &$link) {
             // Reverse the relationship description (note: this reverses to the "readable" version (i.e. not camelcase))
             if ($link['registry_object_id'] && in_array($link['origin'], array('REVERSE_EXT', 'REVERSE_INT'))) {
                 $link['relation_type'] = format_relationship($link['class'], $link['relation_type'], $link['origin'], $ro->class);
             }
             if ($link['status']) {
                 $link['readable_status'] = readable($link['status']);
             }
         }
     }
     $status['count'] = sizeof($connections);
     echo json_encode(array("status" => $status, "connections" => $connections));
 }