Browse Source

Basic Entity support.

Expose a few fields, which can be substituted in for Tokens
(in Rules).
pull/248/head
Adam Vessey 12 years ago
parent
commit
d583e9f870
  1. 31
      includes/islandora_object.entity_controller.inc
  2. 1
      islandora.info
  3. 62
      islandora.module
  4. 115
      islandora.rules.inc

31
includes/islandora_object.entity_controller.inc

@ -0,0 +1,31 @@
<?php
/**
* Very basic entity controller...
*/
class IslandoraObjectEntityController implements DrupalEntityControllerInterface {
public function __construct($entityType) {
// No-op...
}
public function load($ids = array(), $conditions = array()) {
if (!empty($conditions)) {
throw new Exception('Conditions not implemented.');
}
$loaded = array();
foreach ($ids as $id) {
$load = islandora_object_load($id);
if ($load) {
$loaded[] = $load;
}
}
return $loaded;
}
public function resetCache(array $ids = NULL) {
// no-op
}
}

1
islandora.info

@ -10,6 +10,7 @@ files[] = includes/mime_detect.inc
files[] = includes/dublin_core.inc files[] = includes/dublin_core.inc
files[] = includes/islandora_tuque.inc files[] = includes/islandora_tuque.inc
files[] = includes/islandora_tuque_wrapper.inc files[] = includes/islandora_tuque_wrapper.inc
files[] = includes/islandora_object.entity_controller.inc
files[] = tests/islandora_web_test_case.inc files[] = tests/islandora_web_test_case.inc
files[] = tests/islandora_authtokens.test files[] = tests/islandora_authtokens.test
files[] = tests/islandora_hooks.test files[] = tests/islandora_hooks.test

62
islandora.module

@ -793,3 +793,65 @@ function islandora_cron() {
module_load_include('inc', 'islandora', 'includes/islandora_authtokens'); module_load_include('inc', 'islandora', 'includes/islandora_authtokens');
islandora_remove_expired_tokens(); islandora_remove_expired_tokens();
} }
/**
* Implements hook_entity_info().
*
* Some boiler-plate for Tokens (the module, not our authentication work-
* around).
*/
function islandora_entity_info() {
$entities = array();
$entities['islandora_object'] = array(
'label' => t('Islandora Object'),
'controller class' => 'IslandoraObjectEntityController',
'fieldable' => FALSE,
'entity keys' => array(
'id' => 'id',
'label' => 'label',
),
);
return $entities;
}
/**
* Implements hook_entity_property_info().
*
* Details the tokens which will be available on the given object.
*/
function islandora_entity_property_info() {
$info = array();
$p = &$info['islandora_object']['properties'];
$p['id'] = array(
'type' => 'text',
'label' => t('ID'),
'description' => t('The identifier of the object.'),
);
$p['label'] = array(
'type' => 'text',
'label' => t('Object Label'),
'description' => t('The label of the object.'),
);
$p['owner'] = array(
'type' => 'text',
'label' => t('Object Owner'),
'description' => t('The name of the owner of the object.'),
);
$p['state'] = array(
'type' => 'text',
'label' => t('Object State'),
'description' => t('An initial representing the state of the object.'),
);
$p['models'] = array(
'type' => 'list<text>',
'label' => t('Content Models'),
'description' => t('The list of content models which the object has.'),
);
return $info;
}

115
islandora.rules.inc

@ -0,0 +1,115 @@
<?php
/**
* Helper function to get reused "parameter" array.
*/
function islandora_rules_relationship_parameter_array() {
$to_return = array(
'subject' => array(
'type' => 'islandora_object',
'label' => t('Subject'),
'description' => t('An object of which we should check the ' .
'relationships (The "subject" of the relationship).'),
),
'pred_uri' => array(
'type' => 'text',
'label' => t('Predicate URI'),
'description' => t('The URI namespace to which the predicate belongs.'),
),
'pred' => array(
'type' => 'text',
'label' => t('Predicate'),
'description' => t('The predicate of the relationship.'),
),
'object' => array(
'type' => 'text',
'label' => t('Object'),
'description' => t('The object of the relationship.'),
'allow null' => TRUE,
'default value' => NULL,
),
'type' => array(
'type' => 'integer',
'label' => t('Object type in the relationship'),
'description' => t('0=URI, 1=plain literal'),
'default value' => 0,
),
);
return $to_return;
}
/**
* Implements hook_rules_condition_info().
*/
function islandora_rules_condition_info() {
$cond = array();
$cond['islandora_object_has_relationship'] = array(
'label' => t('Check object for a relationship'),
'group' => t('Islandora'),
'parameter' => islandora_rules_relationship_parameter_array(),
);
return $cond;
}
/**
* Implements hook_rules_action_info().
*/
function islandora_rules_action_info() {
$cond = array();
$cond['islandora_object_remove_relationship'] = array(
'label' => t('Remove a relationship from an object'),
'group' => t('Islandora'),
'parameter' => islandora_rules_relationship_parameter_array(),
);
$cond['islandora_object_add_relationship'] = array(
'label' => t('Add a relationship to an object'),
'group' => t('Islandora'),
'parameter' => islandora_rules_relationship_parameter_array(),
);
return $cond;
}
/**
* Checks that there is a relationship match on the given object.
*
* Takes a subject (either a FedoraObject or a FedoraDatastream), as well as
* the parameters for FedoraRelsExt::get() or FedoraRelsInt::get(), to try to
* find a match.
*
* @see FedoraRelsExt::get()
*/
function islandora_object_has_relationship($sub, $pred_uri, $pred, $object, $type) {
$relationships = $sub->relationships->get($pred_uri, $pred, $object, $type);
return !empty($relationships);
}
/**
* Remove a relationship from the given object.
*
* Takes a subject (either a FedoraObject or a FedoraDatastream), as well as
* the parameters for FedoraRelsExt::remove() or FedoraRelsInt::remove(), to
* try to find a match.
*
* @see FedoraRelsExt::get()
*/
function islandora_object_remove_relationship($sub, $pred_uri, $pred, $object, $type) {
$sub->relationships->remove($pred_uri, $pred, $object, $type);
}
/**
* Add a relationship to the given object.
*
* Takes a subject (either a FedoraObject or a FedoraDatastream), as well as
* the parameters for FedoraRelsExt::add() or FedoraRelsInt::add(), and adds
* the represented relationship.
*
* @see FedoraRelsExt::get()
*/
function islandora_object_add_relationship($sub, $pred_uri, $pred, $object, $type) {
$sub->relationships->add($pred_uri, $pred, $object, $type);
}
Loading…
Cancel
Save