name; $rest_connection->repository->purgeObject($pid); } /** * removes association of this object to this collection * @param string $pid */ function remove_collection_association($pid, $collection_pid) { module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection(); $fedora_object = new FedoraObject($pid, $rest_connection->repository); $fedora_object->relationships->remove(NULL, 'isMemberOfCollection', $collection_pid); } /** * returns content models associated with all objects in a collection * @param string $pid * @return array */ function get_represented_content_models($pid) { module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $query = "select \$model \$title from <#ri> where (\$object or \$object ) and \$object \$model and \$object \$title"; $model_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $represented_models = array(); foreach ($model_pids as $model_pid) { if ($model_pid['model']['value'] && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') { $fedora_object = new FedoraObject($model_pid['model']['value'], $rest_connection->repository); $content_model_title = $fedora_object->label; $represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $content_model_title; } } return $represented_models; } function get_child_collections($collection_pid) { module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $query = << where \$object and \$object EOD; $lines = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $collection_pids = array_values(array_filter($lines)); return $collection_pids; } function Islandora_collections_get_collection_from_pid($pid) { module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $query = 'select $parent from <#ri> where ($object $parent or $object $parent) and $object \'' . $pid . '\' order by $object'; $object_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $object_pids = array_values(array_filter($object_pids)); return $object_pids; } /** * Returns an array of pids that match the query contained in the collection * object's QUERY datastream or in the suppled $query parameter. * @param $collection_pid * @param $query * @param $query_format R */ function get_related_items_as_array($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; global $user; // if (!fedora_repository_access(OBJECTHELPER :: $OBJECT_HELPER_VIEW_FEDORA, $pid, $user)) { // drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error'); // return array(); // } $query_string = 'select $object $title $content from <#ri> where ($object $title and $object $content and ('; if (is_array($relationship)) { foreach ($relationship as $rel) { $query_string .= '$object '; if (next($relationship)) { $query_string .= ' OR '; } } } elseif (is_string($relationship)) { $query_string .= '$object '; } else { return ''; } $query_string .= ') '; $query_string .= $active_objects_only ? 'and $object ' : ''; if ($cmodel) { $query_string .= ' and $content '; } $query_string .= ') minus $content order by ' . $orderby; $results = $rest_connection->repository->ri->itqlQuery($query_string, $limit, $offset); return $results; } /** * gets the name of the content models for the specified object * this now returns an array of pids as in Fedora 3 we can have more then one Cmodel for an object * @param type $pid * @param type $include_fedora_system_content_models * @return array */ function get_content_models_list($pid, $include_fedora_system_content_models = FALSE) { module_load_include('inc', 'islandora', 'RestConnection'); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $rest_connection = new RestConnection(); $pids = array(); $query = 'select $object from <#ri> where $object and $object '; $content_models = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); if (empty($content_models)) { return $pids; } $cmodels = array(); foreach ($content_models as $content_model) { if (strpos($content_model['object']['uri'], 'fedora-system:FedoraObject-3.0') != FALSE && $include_fedora_system_content_models == FALSE) { continue; } $cmodels[] = substr(strstr($content_model['object']['uri'], '/'), 1); } return $cmodels; } /** * Function: get_content_models_as_option_array * * Description: Returns an associative array of all available content models in Fedora instance * * @return array */ function get_content_models_as_option_array() { module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); $allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); $namespaces = explode(':', $allowed_string); foreach ($namespaces as $namespace) { if ($namespace) { $allowed[] = trim($namespace); } } $query = 'select $object $title from <#ri> where ($object $title and ($object or $object ) and $object ) order by $title'; $list = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $options = array(); foreach ($list as $item) { //removes blanks if ($item) { $item_namespace = explode(':', $item['object']['value']); if (!$restricted || in_array($item_namespace[0], $allowed)) { if (!preg_match('/fedora-system/', $item['object']['value'])) { $options[$item['object']['value']] = $item['title']['value'] . ' ~ ' . $item['object']['value']; } } } } return $options; } function getContentModels($collection_pid, $showError = TRUE) { module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection(); $collection_stream = $this->getCollectionPolicyStream($collection_pid); $collection_object = new FedoraObject($collection_pid, $rest_connection->repository); $collection_stream = $collection_object->getDatastream('COLLECTION_POLICY'); try { $xml = new SimpleXMLElement($collection_stream); } catch (Exception $e) { if ($showError) { drupal_set_message(t('@e', array('@e' => check_plain($e->getMessage()))), 'error'); } return NULL; } foreach ($xml->contentmodels->contentmodel as $content_model) { $contentModel = new ContentModel(); $contentModel->contentModelDsid = $content_model->dsid; $contentModel->contentModelPid = $content_model->pid; $contentModel->pidNamespace = $content_model->pidNamespace; $contentModel->contentModelName = $content_model['name']; $models[] = $contentModel; } return $models; }