|
|
|
@ -130,12 +130,20 @@ function islandora_rules_relationship_parameter_array() {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Helper function; get default parameters for the XPath condition and action. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_base_xpath_parameters() { |
|
|
|
|
return array( |
|
|
|
|
'datastream' => array( |
|
|
|
|
'type' => 'islandora_datastream', |
|
|
|
|
'object' => array( |
|
|
|
|
'type' => 'islandora_object', |
|
|
|
|
'label' => t('Object'), |
|
|
|
|
'description' => t('The object containing the datastream to check.'), |
|
|
|
|
), |
|
|
|
|
'datastream_id' => array( |
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('Datastream'), |
|
|
|
|
'description' => t('The XML datastream to check.'), |
|
|
|
|
'description' => t('The identifier of the XML datastream to check.'), |
|
|
|
|
), |
|
|
|
|
'xpath' => array( |
|
|
|
|
'type' => 'text', |
|
|
|
@ -145,7 +153,7 @@ function islandora_rules_base_xpath_parameters() {
|
|
|
|
|
'xpath_namespaces' => array( |
|
|
|
|
'type' => 'taxonomy_vocabulary', |
|
|
|
|
'label' => t('XPath Namespace Taxonomy'), |
|
|
|
|
'description' => t('A flat taxonomy of which the terms are namespace prefixes and the description contains the URI for the namespace.') |
|
|
|
|
'description' => t('A flat taxonomy of which the terms are namespace prefixes and the description contains the URI for the namespace.'), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
@ -162,6 +170,22 @@ function islandora_rules_condition_info() {
|
|
|
|
|
'group' => t('Islandora'), |
|
|
|
|
'parameter' => islandora_rules_relationship_parameter_array(), |
|
|
|
|
); |
|
|
|
|
$cond['islandora_object_has_datastream'] = array( |
|
|
|
|
'label' => t('Check object for existence of a datastream'), |
|
|
|
|
'group' => t('Islandora'), |
|
|
|
|
'parameter' => array( |
|
|
|
|
'object' => array( |
|
|
|
|
'type' => 'islandora_object', |
|
|
|
|
'label' => t('Object'), |
|
|
|
|
'description' => t('The object containing the datastream to check.'), |
|
|
|
|
), |
|
|
|
|
'datastream_id' => array( |
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('Datastream'), |
|
|
|
|
'description' => t('The identifier of the datastream to check.'), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
$cond['islandora_rules_datastream_has_xpath'] = array( |
|
|
|
|
'label' => t('Check for an XPath match in an XML datastream'), |
|
|
|
|
'group' => t('Islandora'), |
|
|
|
@ -189,11 +213,33 @@ function islandora_rules_action_info() {
|
|
|
|
|
'parameter' => islandora_rules_relationship_parameter_array(), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$cond['islandora_rules_datastream_load'] = array( |
|
|
|
|
'label' => t('Load a datastream from an object.'), |
|
|
|
|
'group' => t('Islandora'), |
|
|
|
|
'parameter' => array( |
|
|
|
|
'object' => array( |
|
|
|
|
'type' => 'islandora_object', |
|
|
|
|
'label' => t('Object'), |
|
|
|
|
'description' => t('A Tuque object for the Fedora object from which to load the datastream, as an entity.'), |
|
|
|
|
), |
|
|
|
|
'datastream_id' => array( |
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('Datastream ID'), |
|
|
|
|
'description' => t('A string containing the identity of the datastream to load from the object.'), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
'provides' => array( |
|
|
|
|
'datastream' => array( |
|
|
|
|
'type' => 'islandora_datastream', |
|
|
|
|
'label' => t('Loaded datastream instance'), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
$cond['islandora_rules_datastream_load_domxpath'] = array( |
|
|
|
|
'label' => t('Load a DOMXPath for a given XML.'), |
|
|
|
|
'group' => t('Islandora DOMXPath'), |
|
|
|
|
'parameter' => array( |
|
|
|
|
'datastrea,' => array( |
|
|
|
|
'datastream' => array( |
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('XML'), |
|
|
|
|
'description' => t('A string containing the XML to load.'), |
|
|
|
@ -235,7 +281,7 @@ function islandora_rules_action_info() {
|
|
|
|
|
'xpath_namespaces' => array( |
|
|
|
|
'type' => 'taxonomy_vocabulary', |
|
|
|
|
'label' => t('XPath Namespace Taxonomy'), |
|
|
|
|
'description' => t('A flat taxonomy of which the terms are namespace prefixes and the description contains the URI for the namespace.') |
|
|
|
|
'description' => t('A flat taxonomy of which the terms are namespace prefixes and the description contains the URI for the namespace.'), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
@ -251,7 +297,7 @@ function islandora_rules_action_info() {
|
|
|
|
|
'query' => array( |
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('XPath query'), |
|
|
|
|
'description' => t('The XPath query to perform.') |
|
|
|
|
'description' => t('The XPath query to perform.'), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
'provides' => array( |
|
|
|
@ -277,6 +323,13 @@ function islandora_rules_action_info() {
|
|
|
|
|
return $cond; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Rules action callback; grab a datastream from an object. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_datastream_load(AbstractObject $object, $datastream_id) { |
|
|
|
|
return array('datastream' => $object[$datastream_id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Checks that there is a relationship match on the given object. |
|
|
|
|
* |
|
|
|
@ -317,6 +370,9 @@ function islandora_object_add_relationship($sub, $pred_uri, $pred, $object, $typ
|
|
|
|
|
$sub->relationships->add($pred_uri, $pred, $object, $type); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Rules Action callback; instantiate a DOMXPath with some XML. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_datastream_load_domxpath($string) { |
|
|
|
|
$doc = new DOMDocument(); |
|
|
|
|
$doc->loadXML($string); |
|
|
|
@ -324,6 +380,15 @@ function islandora_rules_datastream_load_domxpath($string) {
|
|
|
|
|
return array('islandora_domxpath' => $xpath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Rules Action callback; load namespaces onto a DOMXPath instance. |
|
|
|
|
* |
|
|
|
|
* @param DOMXPath $xpath |
|
|
|
|
* A DOMXPath instance. |
|
|
|
|
* @param object $xpath_vocab |
|
|
|
|
* A loaded Drupal taxonomy vocabulary object, in which terms are understood |
|
|
|
|
* to be namespace prefixes and descriptions are the namespace URIs. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_datastream_load_namespace_vocab($xpath, $xpath_vocab) { |
|
|
|
|
foreach (taxonomy_get_tree($xpath_vocab->vid, 0, 1, FALSE) as $term) { |
|
|
|
|
$xpath->registerNamespace($term->name, $term->description); |
|
|
|
@ -339,13 +404,21 @@ function islandora_rules_datastream_load_xpath(AbstractDatastream $datastream, $
|
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function islandora_rules_datastream_has_xpath(AbstractDatastream $datastream, $search_xpath, $xpath_vocab) { |
|
|
|
|
/** |
|
|
|
|
* Rules Condition callback; test that an XPath returns a non-empty result set. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_datastream_has_xpath(AbstractObject $object, $datastream_id, $search_xpath, $xpath_vocab) { |
|
|
|
|
$datastream = $object[$datastream_id]; |
|
|
|
|
$xpath = islandora_rules_datastream_load_xpath($datastream, $xpath_vocab); |
|
|
|
|
$result = $xpath['islandora_domxpath']->query($search_xpath); |
|
|
|
|
return $result->length > 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function islandora_rules_datastream_set_xpath(AbstractDatastream $datastream, $search_xpath, $xpath_vocab, $value) { |
|
|
|
|
/** |
|
|
|
|
* Rules Action callback; set the value of all matched nodes. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_datastream_set_xpath(AbstractObject $object, $datastream_id, $search_xpath, $xpath_vocab, $value) { |
|
|
|
|
$datastream = $object[$datastream_id]; |
|
|
|
|
$xpath = islandora_rules_datastream_load_xpath($datastream, $xpath_vocab); |
|
|
|
|
$result = $xpath['islandora_domxpath']->query($search_xpath); |
|
|
|
|
foreach ($result as $node) { |
|
|
|
@ -364,12 +437,12 @@ function islandora_rules_data_info() {
|
|
|
|
|
'group' => t('Islandora'), |
|
|
|
|
'property info' => array( |
|
|
|
|
'content' => array( |
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('XML Content'), |
|
|
|
|
'computed' => TRUE, |
|
|
|
|
'getter callback' => 'islandora_rules_get_domxpath_document_content', |
|
|
|
|
'token type' => 'string', |
|
|
|
|
), |
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('XML Content'), |
|
|
|
|
'computed' => TRUE, |
|
|
|
|
'getter callback' => 'islandora_rules_get_domxpath_document_content', |
|
|
|
|
'token type' => 'string', |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
'wrap' => TRUE, |
|
|
|
|
), |
|
|
|
@ -381,8 +454,8 @@ function islandora_rules_data_info() {
|
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('Node value'), |
|
|
|
|
'computed' => TRUE, |
|
|
|
|
'getter callback' => 'islandora_rules_domnode_get', |
|
|
|
|
'setter callback' => 'islandora_rules_domnode_set', |
|
|
|
|
'getter callback' => 'islandora_rules_property_get', |
|
|
|
|
'setter callback' => 'islandora_rules_property_set', |
|
|
|
|
'property' => 'nodeValue', |
|
|
|
|
'token type' => 'string', |
|
|
|
|
), |
|
|
|
@ -390,7 +463,7 @@ function islandora_rules_data_info() {
|
|
|
|
|
'type' => 'text', |
|
|
|
|
'label' => t('Text content'), |
|
|
|
|
'computed' => TRUE, |
|
|
|
|
'getter callback' => 'islandora_rules_domnode_get', |
|
|
|
|
'getter callback' => 'islandora_rules_property_get', |
|
|
|
|
'property' => 'textContent', |
|
|
|
|
'token type' => 'string', |
|
|
|
|
), |
|
|
|
@ -406,18 +479,89 @@ function islandora_rules_data_info() {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function islandora_rules_domnode_get($data, $options, $name, $type, $info) { |
|
|
|
|
/** |
|
|
|
|
* Property setter helper; set a property on an object. |
|
|
|
|
* |
|
|
|
|
* In Rules, properties can contain lowercase and numeric characters. Since |
|
|
|
|
* we want to refer to "nodeValue", we have to step around the Rules constraint. |
|
|
|
|
* |
|
|
|
|
* @param object $data |
|
|
|
|
* The object on which to set the property, described by $info['property']. |
|
|
|
|
* @param array $options |
|
|
|
|
* An array of options... Not sure how it's used? Not touched by us, in any |
|
|
|
|
* case. :P |
|
|
|
|
* @param string $name |
|
|
|
|
* The name of the property to set, as used by Rules. |
|
|
|
|
* @param string $type |
|
|
|
|
* The type of object on which the property is being set, as used by Rules. |
|
|
|
|
* @param array $info |
|
|
|
|
* An associative array describing this property. In addition to that |
|
|
|
|
* required by Rules/the Entity API, should contain: |
|
|
|
|
* - property: A string indicate the actual property on the $data we wish to |
|
|
|
|
* set. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_property_get($data, array $options, $name, $type, $info) { |
|
|
|
|
return $data->$info['property']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function islandora_rules_domnode_set(&$data, $name, $value, $langcode, $type, $info) { |
|
|
|
|
/** |
|
|
|
|
* Property setter helper; set a property on an object. |
|
|
|
|
* |
|
|
|
|
* In Rules, properties can contain lowercase and numeric characters. Since |
|
|
|
|
* we want to refer to "nodeValue", we have to step around the Rules constraint. |
|
|
|
|
* |
|
|
|
|
* @param object $data |
|
|
|
|
* The object on which to set the property, described by $info['property']. |
|
|
|
|
* @param string $name |
|
|
|
|
* The name of the property to set, as used by Rules. |
|
|
|
|
* @param mixed $value |
|
|
|
|
* The value to set on the property. |
|
|
|
|
* @param string $langcode |
|
|
|
|
* A string indicating the language being set, or NULL. |
|
|
|
|
* @param string $type |
|
|
|
|
* The type of object on which the property is being set, as used by Rules. |
|
|
|
|
* @param array $info |
|
|
|
|
* An associative array describing this property. In addition to that |
|
|
|
|
* required by Rules/the Entity API, should contain: |
|
|
|
|
* - property: A string indicate the actual property on the $data we wish to |
|
|
|
|
* set. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_property_set(&$data, $name, $value, $langcode, $type, $info) { |
|
|
|
|
$data->$info['property'] = $value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Rules property "get" callback; get XML contained in a DOMXPath instance. |
|
|
|
|
* |
|
|
|
|
* @param DOMXPath $xpath |
|
|
|
|
* A DOMXPath instance. |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
* The XML contained inside of the DOMXPath instance. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_get_domxpath_document_content(DOMXPath $xpath) { |
|
|
|
|
return $xpath->document->saveXML(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Rules action callback; perform a query on a DOMXPath instance. |
|
|
|
|
* |
|
|
|
|
* @param DOMXPath $xpath |
|
|
|
|
* A DOMXPath instance. |
|
|
|
|
* @param string $query |
|
|
|
|
* An XPath query. |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
* An array containing: |
|
|
|
|
* - nodes: An array containing the results of the query. |
|
|
|
|
*/ |
|
|
|
|
function islandora_rules_datastream_query_xpath(DOMXPath $xpath, $query) { |
|
|
|
|
return array('nodes' => iterator_to_array($xpath->query($query))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Rules condition callback; check for the datastream on an object. |
|
|
|
|
*/ |
|
|
|
|
function islandora_object_has_datastream(AbstractObject $object, $datastream_id) { |
|
|
|
|
return isset($object[$datastream_id]); |
|
|
|
|
} |
|
|
|
|